6
6
" Issac Trotts <[email protected] >
7
7
" URL: https://github.com/ocaml/vim-ocaml
8
8
" Last Change:
9
+ " 2024 Jan 25 - Add OCamldoc/Odoc highlighting (Samuel Hym, Nicolas Osborne)
9
10
" 2019 Nov 05 - Accurate type highlighting (Maëlan)
10
11
" 2018 Nov 08 - Improved highlighting of operators (Maëlan)
11
12
" 2018 Apr 22 - Improved support for PPX (Andrey Popp)
@@ -86,11 +87,19 @@ syn region ocamlNone transparent matchgroup=ocamlEncl start="{" matchgroup=oca
86
87
syn region ocamlNone transparent matchgroup =ocamlEncl start =" \[ " matchgroup =ocamlEncl end =" \] " contains =ALLBUT,@ocamlContained,ocamlBrackErr
87
88
syn region ocamlNone transparent matchgroup =ocamlEncl start =" \[ |" matchgroup =ocamlEncl end =" |\] " contains =ALLBUT,@ocamlContained,ocamlArrErr
88
89
89
-
90
- " Comments
91
- syn region ocamlComment start =" (\* " end =" \* )" contains =@Spell,ocamlComment,ocamlTodo
90
+ " Comments and documentation
92
91
syn keyword ocamlTodo contained TODO FIXME XXX NOTE
93
92
93
+ syn cluster ocamlCommentLike contains =ocamlComment,ocamlCommentInDoc,ocamlDocumentation
94
+
95
+ if ! exists (' odoc_syntax_loading' )
96
+ " Load odoc syntax only when we are not in a *.mld file
97
+ syn region ocamlComment start =" (\* " end =" \* )" contains =@Spell,ocamlComment,ocamlTodo
98
+ syn include @ocamlOdoc syntax/odoc.vim
99
+ syn region ocamlDocumentation matchgroup =ocamlComment start =" (\*\* " end =" \* )" contains =@ocamlOdoc
100
+ else
101
+ syn region ocamlCommentInDoc start =" (\* " end =" \* )" contains =@Spell,ocamlTodo,ocamlCommentInDoc
102
+ endif
94
103
95
104
" Objects
96
105
syn region ocamlEnd matchgroup =ocamlObject start =" \< object\> " matchgroup =ocamlObject end =" \< end\> " contains =ALLBUT,@ocamlContained,ocamlEndErr
@@ -129,8 +138,8 @@ syn match ocamlKeyword "\<include\>" skipwhite skipempty nextgroup=ocamlModPa
129
138
130
139
" "module" - somewhat complicated stuff ;-)
131
140
" 2022-10: please document it?
132
- syn region ocamlModule matchgroup =ocamlKeyword start =" \< module\> " matchgroup =ocamlModule end =" \< _\|\u\(\w\| '\) *\> " contains =@ocamlAllErrs,ocamlComment skipwhite skipempty nextgroup =ocamlPreDef
133
- syn region ocamlPreDef start =" ." me =e - 1 end =" [a-z:=)]\@ =" contained contains =@ocamlAllErrs,ocamlComment ,ocamlModParam,ocamlGenMod,ocamlModTypeRestr nextgroup =ocamlModTypePre,ocamlModPreRHS
141
+ syn region ocamlModule matchgroup =ocamlKeyword start =" \< module\> " matchgroup =ocamlModule end =" \< _\|\u\(\w\| '\) *\> " contains =@ocamlAllErrs,@ocamlCommentLike skipwhite skipempty nextgroup =ocamlPreDef
142
+ syn region ocamlPreDef start =" ." me =e - 1 end =" [a-z:=)]\@ =" contained contains =@ocamlAllErrs,@ocamlCommentLike ,ocamlModParam,ocamlGenMod,ocamlModTypeRestr nextgroup =ocamlModTypePre,ocamlModPreRHS
134
143
syn region ocamlModParam start =" (\*\@ !" end =" )" contained contains =ocamlGenMod,ocamlModParam,ocamlModParam1,ocamlSig,ocamlVal
135
144
syn match ocamlModParam1 " \<\u\(\w\| '\) *\> " contained skipwhite skipempty
136
145
syn match ocamlGenMod " ()" contained skipwhite skipempty
@@ -140,11 +149,11 @@ syn match ocamlModTypeRestr "\<\w\(\w\|'\)*\( *\. *\w\(\w\|'\)*\)*\>" contain
140
149
141
150
syn match ocamlModPreRHS " =" contained skipwhite skipempty nextgroup =ocamlModParam,ocamlFullMod
142
151
syn keyword ocamlKeyword val
143
- syn region ocamlVal matchgroup =ocamlKeyword start =" \< val\> " matchgroup =ocamlLCIdentifier end =" \<\l\(\w\| '\) *\> " contains =@ocamlAllErrs,ocamlComment ,ocamlFullMod skipwhite skipempty nextgroup =ocamlModTypePre
144
- syn region ocamlModRHS start =" ." end =" . *\w\| ([^*]" me =e - 2 contained contains =ocamlComment skipwhite skipempty nextgroup =ocamlModParam,ocamlFullMod
152
+ syn region ocamlVal matchgroup =ocamlKeyword start =" \< val\> " matchgroup =ocamlLCIdentifier end =" \<\l\(\w\| '\) *\> " contains =@ocamlAllErrs,@ocamlCommentLike ,ocamlFullMod skipwhite skipempty nextgroup =ocamlModTypePre
153
+ syn region ocamlModRHS start =" ." end =" . *\w\| ([^*]" me =e - 2 contained contains =@ocamlCommentLike skipwhite skipempty nextgroup =ocamlModParam,ocamlFullMod
145
154
syn match ocamlFullMod " \<\u\(\w\| '\) *\( *\. *\u\(\w\| '\) *\) *" contained skipwhite skipempty nextgroup =ocamlFuncWith
146
155
147
- syn region ocamlFuncWith start =" ([*)]\@ !" end =" )" contained contains =ocamlComment ,ocamlWith,ocamlStruct skipwhite skipempty nextgroup =ocamlFuncWith
156
+ syn region ocamlFuncWith start =" ([*)]\@ !" end =" )" contained contains =@ocamlCommentLike ,ocamlWith,ocamlStruct skipwhite skipempty nextgroup =ocamlFuncWith
148
157
149
158
syn region ocamlModTRWith start =" (\*\@ !" end =" )" contained contains =@ocamlAENoParen,ocamlWith
150
159
syn match ocamlWith " \<\(\u\(\w\| '\) * *\. *\) *\w\(\w\| '\) *\> " contained skipwhite skipempty nextgroup =ocamlWithRest
@@ -157,10 +166,10 @@ syn region ocamlStruct matchgroup=ocamlStructEncl start="\<\(module\s\+\)\=str
157
166
syn region ocamlSig matchgroup =ocamlSigEncl start =" \< sig\> " matchgroup =ocamlSigEncl end =" \< end\> " contains =ALLBUT,@ocamlContained,ocamlEndErr
158
167
159
168
" "functor"
160
- syn region ocamlFunctor start =" \< functor\> " matchgroup =ocamlKeyword end =" ->" contains =@ocamlAllErrs,ocamlComment ,ocamlModParam,ocamlGenMod skipwhite skipempty nextgroup =ocamlStruct,ocamlSig,ocamlFuncWith,ocamlFunctor
169
+ syn region ocamlFunctor start =" \< functor\> " matchgroup =ocamlKeyword end =" ->" contains =@ocamlAllErrs,@ocamlCommentLike ,ocamlModParam,ocamlGenMod skipwhite skipempty nextgroup =ocamlStruct,ocamlSig,ocamlFuncWith,ocamlFunctor
161
170
162
171
" "module type"
163
- syn region ocamlModTypeOf start =" \< module\s\+ type\(\s\+ of\)\=\> " matchgroup =ocamlModule end =" \<\w\(\w\| '\) *\> " contains =ocamlComment skipwhite skipempty nextgroup =ocamlMTDef
172
+ syn region ocamlModTypeOf start =" \< module\s\+ type\(\s\+ of\)\=\> " matchgroup =ocamlModule end =" \<\w\(\w\| '\) *\> " contains =@ocamlCommentLike skipwhite skipempty nextgroup =ocamlMTDef
164
173
syn match ocamlMTDef " =\s *\w\(\w\| '\) *\> " hs =s + 1 ,me =s + 1 skipwhite skipempty nextgroup =ocamlFullMod
165
174
166
175
" Quoted strings
@@ -386,7 +395,7 @@ syn cluster ocamlTypeExpr add=ocamlTypeObject
386
395
syn region ocamlTypeObject contained
387
396
\ matchgroup= ocamlEncl start = " <"
388
397
\ matchgroup= ocamlEncl end = " >"
389
- \ contains= ocamlTypeObjectDots,ocamlLCIdentifier,ocamlTypeObjectAnnot,ocamlTypeBlank,ocamlComment ,ocamlPpx
398
+ \ contains= ocamlTypeObjectDots,ocamlLCIdentifier,ocamlTypeObjectAnnot,ocamlTypeBlank,@o camlCommentLike ,ocamlPpx
390
399
hi link ocamlTypeObject ocamlTypeCatchAll
391
400
syn cluster ocamlTypeContained add =ocamlTypeObjectDots
392
401
syn match ocamlTypeObjectDots contained " \.\. "
@@ -395,15 +404,15 @@ syn cluster ocamlTypeContained add=ocamlTypeObjectAnnot
395
404
syn region ocamlTypeObjectAnnot contained
396
405
\ matchgroup= ocamlKeyChar start = " :"
397
406
\ matchgroup= ocamlKeyChar end = " ;\| >\@ ="
398
- \ contains= @o camlTypeExpr,ocamlComment ,ocamlPpx
407
+ \ contains= @o camlTypeExpr,@o camlCommentLike ,ocamlPpx
399
408
hi link ocamlTypeObjectAnnot ocamlTypeCatchAll
400
409
401
410
" Record type definition
402
411
syn cluster ocamlTypeContained add =ocamlTypeRecordDecl
403
412
syn region ocamlTypeRecordDecl contained
404
413
\ matchgroup= ocamlEncl start = " {"
405
414
\ matchgroup= ocamlEncl end = " }"
406
- \ contains= ocamlTypeMutable,ocamlLCIdentifier,ocamlTypeRecordAnnot,ocamlTypeBlank,ocamlComment ,ocamlPpx
415
+ \ contains= ocamlTypeMutable,ocamlLCIdentifier,ocamlTypeRecordAnnot,ocamlTypeBlank,@o camlCommentLike ,ocamlPpx
407
416
hi link ocamlTypeRecordDecl ocamlTypeCatchAll
408
417
syn cluster ocamlTypeContained add =ocamlTypeMutable
409
418
syn keyword ocamlTypeMutable contained mutable
@@ -412,7 +421,7 @@ syn cluster ocamlTypeContained add=ocamlTypeRecordAnnot
412
421
syn region ocamlTypeRecordAnnot contained
413
422
\ matchgroup= ocamlKeyChar start = " :"
414
423
\ matchgroup= ocamlKeyChar end = " ;\| }\@ ="
415
- \ contains= @o camlTypeExpr,ocamlComment ,ocamlPpx
424
+ \ contains= @o camlTypeExpr,@o camlCommentLike ,ocamlPpx
416
425
hi link ocamlTypeRecordAnnot ocamlTypeCatchAll
417
426
418
427
" Polymorphic variant types
@@ -421,7 +430,7 @@ syn cluster ocamlTypeExpr add=ocamlTypeVariant
421
430
syn region ocamlTypeVariant contained
422
431
\ matchgroup= ocamlEncl start = " \[ >" start = " \[ <" start = " \[ @\@ !"
423
432
\ matchgroup= ocamlEncl end = " \] "
424
- \ contains= ocamlTypeVariantKeyChar,ocamlTypeVariantConstr,ocamlTypeVariantAnnot,ocamlTypeBlank,ocamlComment ,ocamlPpx
433
+ \ contains= ocamlTypeVariantKeyChar,ocamlTypeVariantConstr,ocamlTypeVariantAnnot,ocamlTypeBlank,@o camlCommentLike ,ocamlPpx
425
434
hi link ocamlTypeVariant ocamlTypeCatchAll
426
435
syn cluster ocamlTypeContained add =ocamlTypeVariantKeyChar
427
436
syn match ocamlTypeVariantKeyChar contained " |"
@@ -434,7 +443,7 @@ syn cluster ocamlTypeContained add=ocamlTypeVariantAnnot
434
443
syn region ocamlTypeVariantAnnot contained
435
444
\ matchgroup= ocamlKeyword start = " \< of\> "
436
445
\ matchgroup= ocamlKeyChar end = " |\| >\|\]\@ ="
437
- \ contains= @o camlTypeExpr,ocamlTypeAmp,ocamlComment ,ocamlPpx
446
+ \ contains= @o camlTypeExpr,ocamlTypeAmp,@o camlCommentLike ,ocamlPpx
438
447
hi link ocamlTypeVariantAnnot ocamlTypeCatchAll
439
448
syn cluster ocamlTypeContained add =ocamlTypeAmp
440
449
syn match ocamlTypeAmp contained " &"
@@ -449,7 +458,7 @@ syn region ocamlTypeSumDecl contained
449
458
\ matchgroup= ocamlTypeSumConstr start = " (\_ s*)" start = " \[\_ s*]" start = " (\_ s*::\_ s*)"
450
459
\ matchgroup= NONE end = " \(\< type\>\|\< exception\>\|\< val\>\|\< module\>\|\< class\>\|\< method\>\|\< constraint\>\|\< inherit\>\|\< object\>\|\< struct\>\|\< open\>\|\< include\>\|\< let\>\|\< external\>\|\< in\>\|\< end\>\| )\| ]\| }\| ;\| ;;\| =\)\@ ="
451
460
\ matchgroup= NONE end = " \(\< and\>\)\@ ="
452
- \ contains= ocamlTypeSumBar,ocamlTypeSumConstr,ocamlTypeSumAnnot,ocamlTypeBlank,ocamlComment ,ocamlPpx
461
+ \ contains= ocamlTypeSumBar,ocamlTypeSumConstr,ocamlTypeSumAnnot,ocamlTypeBlank,@o camlCommentLike ,ocamlPpx
453
462
hi link ocamlTypeSumDecl ocamlTypeCatchAll
454
463
syn cluster ocamlTypeContained add =ocamlTypeSumBar
455
464
syn match ocamlTypeSumBar contained " |"
@@ -469,15 +478,15 @@ syn region ocamlTypeSumAnnot contained
469
478
\ matchgroup= NONE end = " |\@ ="
470
479
\ matchgroup= NONE end = " \(\< type\>\|\< exception\>\|\< val\>\|\< module\>\|\< class\>\|\< method\>\|\< constraint\>\|\< inherit\>\|\< object\>\|\< struct\>\|\< open\>\|\< include\>\|\< let\>\|\< external\>\|\< in\>\|\< end\>\| )\| ]\| }\| ;\| ;;\)\@ ="
471
480
\ matchgroup= NONE end = " \(\< and\>\)\@ ="
472
- \ contains= @o camlTypeExpr,ocamlTypeRecordDecl,ocamlComment ,ocamlPpx
481
+ \ contains= @o camlTypeExpr,ocamlTypeRecordDecl,@o camlCommentLike ,ocamlPpx
473
482
hi link ocamlTypeSumAnnot ocamlTypeCatchAll
474
483
475
484
" Type context opened by “type” (type definition), “constraint” (type
476
485
" constraint) and “exception” (exception definition)
477
486
syn region ocamlTypeDef
478
487
\ matchgroup= ocamlKeyword start = " \< type\>\(\_ s\+\< nonrec\>\)\?\|\< constraint\>\|\< exception\> "
479
488
\ matchgroup= NONE end = " \(\< type\>\|\< exception\>\|\< val\>\|\< module\>\|\< class\>\|\< method\>\|\< constraint\>\|\< inherit\>\|\< object\>\|\< struct\>\|\< open\>\|\< include\>\|\< let\>\|\< external\>\|\< in\>\|\< end\>\| )\| ]\| }\| ;\| ;;\)\@ ="
480
- \ contains= @o camlTypeExpr,ocamlTypeEq,ocamlTypePrivate,ocamlTypeDefDots,ocamlTypeRecordDecl,ocamlTypeSumDecl,ocamlTypeDefAnd,ocamlComment ,ocamlPpx
489
+ \ contains= @o camlTypeExpr,ocamlTypeEq,ocamlTypePrivate,ocamlTypeDefDots,ocamlTypeRecordDecl,ocamlTypeSumDecl,ocamlTypeDefAnd,@o camlCommentLike ,ocamlPpx
481
490
hi link ocamlTypeDef ocamlTypeCatchAll
482
491
syn cluster ocamlTypeContained add =ocamlTypePrivate
483
492
syn keyword ocamlTypePrivate contained private
@@ -503,7 +512,7 @@ syn region ocamlTypeAnnot matchgroup=ocamlKeyChar start=":\(>\|\_s*type\>\|[>:=]
503
512
\ matchgroup= NONE end = " \(\< type\>\|\< exception\>\|\< val\>\|\< module\>\|\< class\>\|\< method\>\|\< constraint\>\|\< inherit\>\|\< object\>\|\< struct\>\|\< open\>\|\< include\>\|\< let\>\|\< external\>\|\< in\>\|\< end\>\| )\| ]\| }\| ;\| ;;\)\@ ="
504
513
\ matchgroup= NONE end = " \( ;\| }\)\@ ="
505
514
\ matchgroup= NONE end = " \( =\| :>\)\@ ="
506
- \ contains= @o camlTypeExpr,ocamlComment ,ocamlPpx
515
+ \ contains= @o camlTypeExpr,@o camlCommentLike ,ocamlPpx
507
516
hi link ocamlTypeAnnot ocamlTypeCatchAll
508
517
509
518
" Type annotation that gives the return type of a `fun` keyword
@@ -512,7 +521,7 @@ syn cluster ocamlTypeContained add=ocamlFunTypeAnnot
512
521
syn region ocamlFunTypeAnnot contained containedin =ocamlFun
513
522
\ matchgroup= ocamlKeyChar start = " :"
514
523
\ matchgroup= NONE end = " \( ->\)\@ ="
515
- \ contains= @o camlTypeExpr,ocamlComment ,ocamlPpx
524
+ \ contains= @o camlTypeExpr,@o camlCommentLike ,ocamlPpx
516
525
hi link ocamlFunTypeAnnot ocamlTypeCatchAll
517
526
518
527
" Module paths (including functors) in types.
@@ -525,14 +534,14 @@ syn match ocamlTypeModPath contained "\<\u\(\w\|'\)*\_s*\."
525
534
syn region ocamlTypeModPath contained transparent
526
535
\ matchgroup= ocamlModPath start = " \<\u\(\w\| '\) *\_ s*(\*\@ !"
527
536
\ matchgroup= ocamlModPath end = " )\_ s*\. "
528
- \ contains= ocamlTypeDotlessModPath,ocamlTypeBlank,ocamlComment ,ocamlPpx
537
+ \ contains= ocamlTypeDotlessModPath,ocamlTypeBlank,@o camlCommentLike ,ocamlPpx
529
538
hi link ocamlTypeModPath ocamlModPath
530
539
syn cluster ocamlTypeContained add =ocamlTypeDotlessModPath
531
540
syn match ocamlTypeDotlessModPath contained " \<\u\(\w\| '\) *\_ s*\.\? "
532
541
syn region ocamlTypeDotlessModPath contained transparent
533
542
\ matchgroup= ocamlModPath start = " \<\u\(\w\| '\) *\_ s*(\*\@ !"
534
543
\ matchgroup= ocamlModPath end = " )\_ s*\.\? "
535
- \ contains= ocamlTypeDotlessModPath,ocamlTypeBlank,ocamlComment ,ocamlPpx
544
+ \ contains= ocamlTypeDotlessModPath,ocamlTypeBlank,@o camlCommentLike ,ocamlPpx
536
545
hi link ocamlTypeDotlessModPath ocamlTypeModPath
537
546
538
547
" """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
@@ -577,6 +586,7 @@ hi def link ocamlCharErr Error
577
586
hi def link ocamlErr Error
578
587
579
588
hi def link ocamlComment Comment
589
+ hi def link ocamlCommentInDoc ocamlComment
580
590
hi def link ocamlShebang ocamlComment
581
591
582
592
hi def link ocamlModPath Include
@@ -662,7 +672,11 @@ hi def link ocamlPpxEncl ocamlEncl
662
672
663
673
let b: current_syntax = " ocaml"
664
674
665
- let &cpo = s: keepcpo
666
- unlet s: keepcpo
675
+ " Because of the nesting (ocaml in odoc in ocaml), s:keepcpo might have been
676
+ " unlet already
677
+ if exists (' s:keepcpo' )
678
+ let &cpo = s: keepcpo
679
+ unlet s: keepcpo
680
+ endif
667
681
668
682
" vim: ts = 8
0 commit comments