Skip to content

Commit af6060b

Browse files
committed
Syntax: Don't highlight the LHS of type decl as types
I would expect 'ocamlTypeConstr' to apply only to type constructors within type expressions, not to the identifier after 'type' in: type foo = 'a bar list This makes the LHS of types, exceptions and constraints be matched as 'ocamlTypedef', which is not highlighted by default. Variance and type variables on the LHS remain highlighted as before.
1 parent 6dcd9ef commit af6060b

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

syntax/ocaml.vim

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,13 +465,23 @@ syn region ocamlTypeSumAnnot contained
465465
\ contains=@ocamlTypeExpr,ocamlTypeRecordDecl,ocamlComment,ocamlPpx
466466
hi link ocamlTypeSumAnnot ocamlTypeCatchAll
467467

468+
" RHS of a ocamlTypeDef
469+
syn region ocamlTypeDefImpl
470+
\ matchgroup=ocamlKeyword start="\(=\|:\|of\)"
471+
\ matchgroup=NONE end="\(\<type\>\|\<exception\>\|\<val\>\|\<module\>\|\<class\>\|\<method\>\|\<constraint\>\|\<inherit\>\|\<object\>\|\<struct\>\|\<open\>\|\<include\>\|\<let\>\|\<external\>\|\<in\>\|\<end\>\|)\|]\|}\|;\|;;\)\@="
472+
\ contained skipwhite skipempty
473+
\ contains=@ocamlTypeExpr,ocamlTypeEq,ocamlTypePrivate,ocamlTypeDefDots,ocamlTypeRecordDecl,ocamlTypeSumDecl,ocamlTypeDefAnd,ocamlComment,ocamlPpx
474+
hi link ocamlTypeDefImpl ocamlTypeCatchAll
475+
468476
" Type context opened by “type” (type definition), “constraint” (type
469477
" constraint) and “exception” (exception definition)
470478
syn region ocamlTypeDef
471479
\ matchgroup=ocamlKeyword start="\<type\>\(\_s\+\<nonrec\>\)\?\|\<constraint\>\|\<exception\>"
472-
\ matchgroup=NONE end="\(\<type\>\|\<exception\>\|\<val\>\|\<module\>\|\<class\>\|\<method\>\|\<constraint\>\|\<inherit\>\|\<object\>\|\<struct\>\|\<open\>\|\<include\>\|\<let\>\|\<external\>\|\<in\>\|\<end\>\|)\|]\|}\|;\|;;\)\@="
473-
\ contains=@ocamlTypeExpr,ocamlTypeEq,ocamlTypePrivate,ocamlTypeDefDots,ocamlTypeRecordDecl,ocamlTypeSumDecl,ocamlTypeDefAnd,ocamlComment,ocamlPpx
474-
hi link ocamlTypeDef ocamlTypeCatchAll
480+
\ matchgroup=ocamlTypedef end="\<\(\w\|'\)*\>"
481+
\ contains=@ocamlAllErrs,ocamlComment,ocamlTypeVariance,ocamlTypeVar
482+
\ skipwhite skipempty
483+
\ nextgroup=ocamlTypeDefImpl
484+
475485
syn cluster ocamlTypeContained add=ocamlTypePrivate
476486
syn keyword ocamlTypePrivate contained private
477487
hi link ocamlTypePrivate ocamlKeyword

0 commit comments

Comments
 (0)