Skip to content

Commit 1e61347

Browse files
committed
Fix highlighting of and-types
A new region is used to avoid matching the 'and' keyword too often (that would interfere with let-and and module-rec-and.
1 parent d623ae5 commit 1e61347

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

syntax/ocaml.vim

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
" Issac Trotts <[email protected]>
77
" URL: https://github.com/ocaml/vim-ocaml
88
" Last Change:
9+
" 2022 Jul 20 - Improved highlighting of type decl (Jules Aguillon)
910
" 2019 Nov 05 - Accurate type highlighting (Maëlan)
1011
" 2018 Nov 08 - Improved highlighting of operators (Maëlan)
1112
" 2018 Apr 22 - Improved support for PPX (Andrey Popp)
@@ -332,10 +333,6 @@ syn match ocamlTypeVariance contained "[-+!]\ze *\('\|\<_\>\)"
332333
syn match ocamlTypeVariance contained "[-+] *!\+\ze *\('\|\<_\>\)"
333334
syn match ocamlTypeVariance contained "! *[-+]\+\ze *\('\|\<_\>\)"
334335

335-
syn cluster ocamlTypeContained add=ocamlTypeEq
336-
syn match ocamlTypeEq contained "[+:]\?="
337-
hi link ocamlTypeEq ocamlKeyChar
338-
339336
syn cluster ocamlTypeExpr add=ocamlTypeVar,ocamlTypeConstr,ocamlTypeAnyVar,ocamlTypeBuiltin
340337
syn match ocamlTypeVar contained "'\(\l\|_\)\(\w\|'\)*\>"
341338
syn match ocamlTypeConstr contained "\<\(\l\|_\)\(\w\|'\)*\>"
@@ -467,10 +464,15 @@ hi link ocamlTypeSumAnnot ocamlTypeCatchAll
467464

468465
" RHS of a ocamlTypeDef
469466
syn region ocamlTypeDefImpl
470-
\ matchgroup=ocamlKeyword start="\(=\|:\|of\)"
467+
\ matchgroup=ocamlKeyword start="\<of\>"
468+
\ matchgroup=ocamlKeyChar start=":="
469+
\ matchgroup=ocamlKeyChar start=":"
470+
\ matchgroup=ocamlKeyChar start="="
471471
\ matchgroup=NONE end="\(\<type\>\|\<exception\>\|\<val\>\|\<module\>\|\<class\>\|\<method\>\|\<constraint\>\|\<inherit\>\|\<object\>\|\<struct\>\|\<open\>\|\<include\>\|\<let\>\|\<external\>\|\<in\>\|\<end\>\|)\|]\|}\|;\|;;\)\@="
472+
\ matchgroup=NONE end="\(\<and\>\)\@="
472473
\ contained skipwhite skipempty
473-
\ contains=@ocamlTypeExpr,ocamlTypeEq,ocamlTypePrivate,ocamlTypeDefDots,ocamlTypeRecordDecl,ocamlTypeSumDecl,ocamlTypeDefAnd,ocamlComment,ocamlPpx
474+
\ contains=@ocamlTypeExpr,ocamlTypePrivate,ocamlTypeDefDots,ocamlTypeRecordDecl,ocamlTypeSumDecl,ocamlComment,ocamlPpx
475+
\ nextgroup=ocamlTypeDefAnd
474476
hi link ocamlTypeDefImpl ocamlTypeCatchAll
475477

476478
" Type context opened by “type” (type definition) and “constraint” (type
@@ -482,7 +484,18 @@ syn region ocamlTypeDef
482484
\ matchgroup=ocamlLCIdentifier end="\<\l\(\w\|'\)*\>"
483485
\ contains=@ocamlAllErrs,ocamlComment,ocamlTypeVariance,ocamlTypeVar
484486
\ skipwhite skipempty
485-
\ nextgroup=ocamlTypeDefImpl
487+
\ nextgroup=ocamlTypeDefImpl,ocamlTypeDefAnd
488+
489+
" Type context opened by “type” (type definition) and “constraint” (type
490+
" constraint).
491+
" Match the opening keyword and the identifier then jump into
492+
" ocamlTypeDefImpl.
493+
syn region ocamlTypeDefAnd
494+
\ matchgroup=ocamlKeyword start="\<and\>"
495+
\ matchgroup=ocamlLCIdentifier end="\<\l\(\w\|'\)*\>"
496+
\ contains=@ocamlAllErrs,ocamlComment,ocamlTypeVariance,ocamlTypeVar
497+
\ skipwhite skipempty
498+
\ nextgroup=ocamlTypeDefImpl,ocamlTypeDefAnd
486499

487500
" Exception definitions. Like ocamlTypeDef, jump into ocamlTypeDefImpl.
488501
syn region ocamlExceptionDef
@@ -495,9 +508,6 @@ syn region ocamlExceptionDef
495508
syn cluster ocamlTypeContained add=ocamlTypePrivate
496509
syn keyword ocamlTypePrivate contained private
497510
hi link ocamlTypePrivate ocamlKeyword
498-
syn cluster ocamlTypeContained add=ocamlTypeDefAnd
499-
syn keyword ocamlTypeDefAnd contained and
500-
hi link ocamlTypeDefAnd ocamlKeyword
501511
syn cluster ocamlTypeContained add=ocamlTypeDefDots
502512
syn match ocamlTypeDefDots contained "\.\."
503513
hi link ocamlTypeDefDots ocamlKeyChar
@@ -513,7 +523,7 @@ syn match ocamlKeyword "(\_s*exception\>"lc=1
513523
" Type context opened by “:” (countless kinds of type annotations) and “:>”
514524
" (type coercions)
515525
syn region ocamlTypeAnnot matchgroup=ocamlKeyChar start=":\(>\|\_s*type\>\|[>:=]\@!\)"
516-
\ matchgroup=NONE end="\(\<type\>\|\<exception\>\|\<val\>\|\<module\>\|\<class\>\|\<method\>\|\<constraint\>\|\<inherit\>\|\<object\>\|\<struct\>\|\<open\>\|\<include\>\|\<let\>\|\<external\>\|\<in\>\|\<end\>\|)\|]\|}\|;\|;;\)\@="
526+
\ matchgroup=NONE end="\(\<type\>\|\<exception\>\|\<val\>\|\<module\>\|\<class\>\|\<method\>\|\<constraint\>\|\<inherit\>\|\<object\>\|\<struct\>\|\<open\>\|\<include\>\|\<let\>\|\<external\>\|\<in\>\|\<end\>\|\<and\>\|)\|]\|}\|;\|;;\)\@="
517527
\ matchgroup=NONE end="\(;\|}\)\@="
518528
\ matchgroup=NONE end="\(=\|:>\)\@="
519529
\ contains=@ocamlTypeExpr,ocamlComment,ocamlPpx

0 commit comments

Comments
 (0)