Skip to content

Commit 0f91255

Browse files
committed
Syntax: Fixes to type declarations
Fix tupled type params, += and whitespaces around keywords. Add examples to the test file.
1 parent 6dce805 commit 0f91255

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

syntax/ocaml.vim

+6-5
Original file line numberDiff line numberDiff line change
@@ -475,13 +475,14 @@ hi link ocamlTypeSumAnnot ocamlTypeCatchAll
475475
syn region ocamlTypeDefImpl
476476
\ matchgroup=ocamlKeyword start="\<of\>"
477477
\ matchgroup=ocamlKeyChar start=":="
478+
\ matchgroup=ocamlKeyChar start="+="
478479
\ matchgroup=ocamlKeyChar start=":"
479480
\ matchgroup=ocamlKeyChar start="="
480-
\ matchgroup=NONE end="\(\<type\>\|\<exception\>\|\<val\>\|\<module\>\|\<class\>\|\<method\>\|\<constraint\>\|\<inherit\>\|\<object\>\|\<struct\>\|\<open\>\|\<include\>\|\<let\>\|\<external\>\|\<in\>\|\<end\>\|)\|]\|}\|;\|;;\)\@="
481+
\ matchgroup=NONE end="\(\<type\>\|\<exception\>\|\<val\>\|\<module\>\|\<class\>\|\<method\>\|\<constraint\>\|\<inherit\>\|\<object\>\|\<struct\>\|\<open\>\|\<include\>\|\<let\>\|\<external\>\|\<in\>\|\<end\>\|)\|]\|}\|;\|;;\|=\)\@="
481482
\ matchgroup=NONE end="\(\<and\>\)\@="
482483
\ contained skipwhite skipempty
483484
\ contains=@ocamlTypeExpr,ocamlTypePrivate,ocamlTypeDefDots,ocamlTypeRecordDecl,ocamlTypeSumDecl,ocamlComment,ocamlPpx
484-
\ nextgroup=ocamlTypeDefAnd
485+
\ nextgroup=ocamlTypeDefImpl,ocamlTypeDefAnd
485486
hi link ocamlTypeDefImpl ocamlTypeCatchAll
486487

487488
" Type context opened by “type” (type definition) and “constraint” (type
@@ -491,7 +492,7 @@ hi link ocamlTypeDefImpl ocamlTypeCatchAll
491492
syn region ocamlTypeDef
492493
\ matchgroup=ocamlKeyword start="\<type\>\(\_s\+\<nonrec\>\)\?\|\<constraint\>"
493494
\ matchgroup=ocamlTypeIdentifier end="\<\l\(\w\|'\)*\>"
494-
\ contains=@ocamlAllErrs,ocamlComment,ocamlTypeVariance,ocamlTypeVar,ocamlWhite
495+
\ contains=@ocamlTypeExpr,@ocamlAllErrs,ocamlComment,ocamlTypeVariance,ocamlTypeVar,ocamlPpx,ocamlWhite
495496
\ skipwhite skipempty
496497
\ nextgroup=ocamlTypeDefImpl,ocamlTypeDefAnd
497498

@@ -502,15 +503,15 @@ syn region ocamlTypeDef
502503
syn region ocamlTypeDefAnd
503504
\ matchgroup=ocamlKeyword start="\<and\>"
504505
\ matchgroup=ocamlTypeIdentifier end="\<\l\(\w\|'\)*\>"
505-
\ contains=@ocamlAllErrs,ocamlComment,ocamlTypeVariance,ocamlTypeVar,ocamlWhite
506+
\ contains=@ocamlTypeExpr,@ocamlAllErrs,ocamlComment,ocamlTypeVariance,ocamlTypeVar,ocamlPpx,ocamlWhite
506507
\ skipwhite skipempty
507508
\ nextgroup=ocamlTypeDefImpl,ocamlTypeDefAnd
508509

509510
" Exception definitions. Like ocamlTypeDef, jump into ocamlTypeDefImpl.
510511
syn region ocamlExceptionDef
511512
\ matchgroup=ocamlKeyword start="\<exception\>"
512513
\ matchgroup=ocamlConstructor end="\u\(\w\|'\)*\>"
513-
\ contains=@ocamlAllErrs,ocamlComment,ocamlTypeVariance,ocamlTypeVar
514+
\ contains=@ocamlAllErrs,ocamlComment,ocamlTypeVariance,ocamlTypeVar,ocamlPpx
514515
\ skipwhite skipempty
515516
\ nextgroup=ocamlTypeDefImpl
516517

type-linter-test.ml

+23
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
type u = char
2424
type v = string
2525
type w = bytes
26+
type abstract
27+
type !+_ abstract'
2628

2729
(* type expressions with arrows, tuples, 0-ary type constructors *)
2830
type t = t0 * t0 -> t0
@@ -166,6 +168,24 @@
166168
(* definition of an empty type *)
167169
type t = |
168170

171+
(* Constraints *)
172+
type 'a foo := 'a bar
173+
174+
(* RECURSION *)
175+
176+
type foo = bar
177+
and bar
178+
and baz = foo
179+
180+
;;
181+
let foo = 1
182+
and bar = 2 in
183+
()
184+
185+
(* FIXME: 'and' part not matched by module decl (maybe matched by types decl ?). *)
186+
module rec Foo : sig end = struct end
187+
and Bar : sig end = struct end
188+
169189
(* TYPE ANNOTATIONS *)
170190

171191
(* annotations on let binders *)
@@ -318,6 +338,9 @@
318338
end
319339
end
320340

341+
(* FIXME: ':=' not recognized and RHS highlighted as constructor. *)
342+
module Foo := Bar
343+
321344
(* ATTRIBUTES AND COMMENTS *)
322345

323346
exception[@my.attr "payld"] (*c*) E [@my.attr "payld"] (*c*)

0 commit comments

Comments
 (0)