Skip to content

Commit ca867b7

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

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

syntax/ocaml.vim

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -468,13 +468,14 @@ hi link ocamlTypeSumAnnot ocamlTypeCatchAll
468468
syn region ocamlTypeDefImpl
469469
\ matchgroup=ocamlKeyword start="\<of\>"
470470
\ matchgroup=ocamlKeyChar start=":="
471+
\ matchgroup=ocamlKeyChar start="+="
471472
\ matchgroup=ocamlKeyChar start=":"
472473
\ matchgroup=ocamlKeyChar start="="
473-
\ matchgroup=NONE end="\(\<type\>\|\<exception\>\|\<val\>\|\<module\>\|\<class\>\|\<method\>\|\<constraint\>\|\<inherit\>\|\<object\>\|\<struct\>\|\<open\>\|\<include\>\|\<let\>\|\<external\>\|\<in\>\|\<end\>\|)\|]\|}\|;\|;;\)\@="
474+
\ matchgroup=NONE end="\(\<type\>\|\<exception\>\|\<val\>\|\<module\>\|\<class\>\|\<method\>\|\<constraint\>\|\<inherit\>\|\<object\>\|\<struct\>\|\<open\>\|\<include\>\|\<let\>\|\<external\>\|\<in\>\|\<end\>\|)\|]\|}\|;\|;;\|=\)\@="
474475
\ matchgroup=NONE end="\(\<and\>\)\@="
475476
\ contained skipwhite skipempty
476477
\ contains=@ocamlTypeExpr,ocamlTypePrivate,ocamlTypeDefDots,ocamlTypeRecordDecl,ocamlTypeSumDecl,ocamlComment,ocamlPpx
477-
\ nextgroup=ocamlTypeDefAnd
478+
\ nextgroup=ocamlTypeDefImpl,ocamlTypeDefAnd
478479
hi link ocamlTypeDefImpl ocamlTypeCatchAll
479480

480481
" Type context opened by “type” (type definition) and “constraint” (type
@@ -484,7 +485,7 @@ hi link ocamlTypeDefImpl ocamlTypeCatchAll
484485
syn region ocamlTypeDef
485486
\ matchgroup=ocamlKeyword start="\<type\>\(\_s\+\<nonrec\>\)\?\|\<constraint\>"
486487
\ matchgroup=ocamlTypeIdentifier end="\<\l\(\w\|'\)*\>"
487-
\ contains=@ocamlAllErrs,ocamlComment,ocamlTypeVariance,ocamlTypeVar,ocamlWhite
488+
\ contains=@ocamlTypeExpr,@ocamlAllErrs,ocamlComment,ocamlTypeVariance,ocamlTypeVar,ocamlPpx,ocamlWhite
488489
\ skipwhite skipempty
489490
\ nextgroup=ocamlTypeDefImpl,ocamlTypeDefAnd
490491

@@ -495,15 +496,15 @@ syn region ocamlTypeDef
495496
syn region ocamlTypeDefAnd
496497
\ matchgroup=ocamlKeyword start="\<and\>"
497498
\ matchgroup=ocamlTypeIdentifier end="\<\l\(\w\|'\)*\>"
498-
\ contains=@ocamlAllErrs,ocamlComment,ocamlTypeVariance,ocamlTypeVar,ocamlWhite
499+
\ contains=@ocamlTypeExpr,@ocamlAllErrs,ocamlComment,ocamlTypeVariance,ocamlTypeVar,ocamlPpx,ocamlWhite
499500
\ skipwhite skipempty
500501
\ nextgroup=ocamlTypeDefImpl,ocamlTypeDefAnd
501502

502503
" Exception definitions. Like ocamlTypeDef, jump into ocamlTypeDefImpl.
503504
syn region ocamlExceptionDef
504505
\ matchgroup=ocamlKeyword start="\<exception\>"
505506
\ matchgroup=ocamlConstructor end="\u\(\w\|'\)*\>"
506-
\ contains=@ocamlAllErrs,ocamlComment,ocamlTypeVariance,ocamlTypeVar
507+
\ contains=@ocamlAllErrs,ocamlComment,ocamlTypeVariance,ocamlTypeVar,ocamlPpx
507508
\ skipwhite skipempty
508509
\ nextgroup=ocamlTypeDefImpl
509510

type-linter-test.ml

Lines changed: 24 additions & 1 deletion
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
@@ -139,7 +141,7 @@
139141
exception E
140142
exception E of int
141143
exception E : int -> exn
142-
exception E' = E (* FIXME *)
144+
exception E' = E
143145
(* local exceptions *)
144146
let _ = let exception E in ()
145147
let _ = let exception E of int * int in ()
@@ -165,6 +167,24 @@
165167
(* definition of an empty type *)
166168
type t = |
167169

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

170190
(* annotations on let binders *)
@@ -317,6 +337,9 @@
317337
end
318338
end
319339

340+
(* FIXME: ':=' not recognized and RHS highlighted as constructor. *)
341+
module Foo := Bar
342+
320343
(* ATTRIBUTES *)
321344

322345
exception[@my.attr "my payload"] E [@my.attr "my payload"]

0 commit comments

Comments
 (0)