robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
79130c0fd3
master
1" Vim syntax file 2" Language: OCaml 3" Filenames: *.ml *.mli *.mll *.mly 4" Maintainers: Markus Mottl <markus.mottl@gmail.com> 5" Karl-Heinz Sylla <Karl-Heinz.Sylla@gmd.de> 6" Issac Trotts <ijtrotts@ucdavis.edu> 7" URL: https://github.com/ocaml/vim-ocaml 8" Last Change: 9" 2019 Nov 05 - Accurate type highlighting (Maëlan) 10" 2018 Nov 08 - Improved highlighting of operators (Maëlan) 11" 2018 Apr 22 - Improved support for PPX (Andrey Popp) 12" 2018 Mar 16 - Remove raise, lnot and not from keywords (Étienne Millon, "copy") 13" 2017 Apr 11 - Improved matching of negative numbers (MM) 14" 2016 Mar 11 - Improved support for quoted strings (Glen Mével) 15" 2015 Aug 13 - Allow apostrophes in identifiers (Jonathan Chan, Einar Lielmanis) 16" 2015 Jun 17 - Added new "nonrec" keyword (MM) 17 18" A minor patch was applied to the official version so that object/end 19" can be distinguished from begin/end, which is used for indentation, 20" and folding. (David Baelde) 21 22" Quit when a syntax file was already loaded 23if exists ( "b:current_syntax" ) && b: current_syntax == "ocaml" 24finish 25endif 26 27let s: keepcpo = & cpo 28set cpo & vim 29 30" ' can be used in OCaml identifiers 31setlocal iskeyword += ' 32 33" ` is part of the name of polymorphic variants 34setlocal iskeyword += ` 35 36" OCaml is case sensitive. 37syn case match 38 39" Access to the method of an object 40syn match ocamlMethod "# " 41 42" Scripting directives 43syn match ocamlScript "^#\<\(quit\|labels\|warnings\|warn_error\|directory\|remove_directory\|cd\|load\|load_rec\|use\|mod_use\|install_printer\|remove_printer\|require\|list\|ppx\|principal\|predicates\|rectypes\|thread\|trace\|untrace\|untrace_all\|print_depth\|print_length\|camlp4o\|camlp4r\|topfind_log\|topfind_verbose\)\> " 44 45" lowercase identifier - the standard way to match 46syn match ocamlLCIdentifier /\<\(\l\|_\)\(\w\|'\) * \> / 47 48" Errors 49syn match ocamlBraceErr "} " 50syn match ocamlBrackErr "\] " 51syn match ocamlParenErr ") " 52syn match ocamlArrErr "|] " 53 54syn match ocamlCountErr "\<downto\> " 55syn match ocamlCountErr "\<to\> " 56 57if ! exists ( "ocaml_revised" ) 58syn match ocamlDoErr "\<do\> " 59endif 60 61syn match ocamlDoneErr "\<done\> " 62syn match ocamlThenErr "\<then\> " 63 64" Error-highlighting of "end" without synchronization: 65" as keyword or as error (default) 66if exists ( "ocaml_noend_error" ) 67syn match ocamlKeyword "\<end\> " 68else 69syn match ocamlEndErr "\<end\> " 70endif 71 72" These keywords are only expected nested in constructions that are handled by 73" the type linter, so outside of type contexts we highlight them as errors: 74syn match ocamlKwErr "\<\(mutable\|nonrec\|of\|private\)\> " 75 76" Some convenient clusters 77syn cluster ocamlAllErrs contains = @ocamlAENoParen , ocamlParenErr 78syn cluster ocamlAENoParen contains = ocamlBraceErr , ocamlBrackErr , ocamlCountErr , ocamlDoErr , ocamlDoneErr , ocamlEndErr , ocamlThenErr , ocamlKwErr 79 80syn cluster ocamlContained contains = ocamlTodo , ocamlPreDef , ocamlModParam , ocamlModParam1 , ocamlModTypePre , ocamlModRHS , ocamlFuncWith , ocamlModTypeRestr , ocamlModTRWith , ocamlWith , ocamlWithRest , ocamlFullMod , ocamlVal 81 82 83" Enclosing delimiters 84syn region ocamlNone transparent matchgroup = ocamlEncl start = "( "matchgroup = ocamlEncl end = ") "contains = ALLBUT , @ocamlContained , ocamlParenErr 85syn region ocamlNone transparent matchgroup = ocamlEncl start = "{ "matchgroup = ocamlEncl end = "} "contains = ALLBUT , @ocamlContained , ocamlBraceErr 86syn region ocamlNone transparent matchgroup = ocamlEncl start = "\[ "matchgroup = ocamlEncl end = "\] "contains = ALLBUT , @ocamlContained , ocamlBrackErr 87syn region ocamlNone transparent matchgroup = ocamlEncl start = "\[| "matchgroup = ocamlEncl end = "|\] "contains = ALLBUT , @ocamlContained , ocamlArrErr 88 89 90" Comments 91syn region ocamlComment start = "(\* "end = "\*) "contains = @Spell , ocamlComment , ocamlTodo 92syn keyword ocamlTodo contained TODO FIXME XXX NOTE 93 94 95" Objects 96syn region ocamlEnd matchgroup = ocamlObject start = "\<object\> "matchgroup = ocamlObject end = "\<end\> "contains = ALLBUT , @ocamlContained , ocamlEndErr 97 98 99" Blocks 100if ! exists ( "ocaml_revised" ) 101syn region ocamlEnd matchgroup = ocamlKeyword start = "\<begin\> "matchgroup = ocamlKeyword end = "\<end\> "contains = ALLBUT , @ocamlContained , ocamlEndErr 102endif 103 104 105" "for" 106syn region ocamlNone matchgroup = ocamlKeyword start = "\<for\> "matchgroup = ocamlKeyword end = "\<\(to\|downto\)\> "contains = ALLBUT , @ocamlContained , ocamlCountErr 107 108 109" "do" 110if ! exists ( "ocaml_revised" ) 111syn region ocamlDo matchgroup = ocamlKeyword start = "\<do\> "matchgroup = ocamlKeyword end = "\<done\> "contains = ALLBUT , @ocamlContained , ocamlDoneErr 112endif 113 114" "if" 115syn region ocamlNone matchgroup = ocamlKeyword start = "\<if\> "matchgroup = ocamlKeyword end = "\<then\> "contains = ALLBUT , @ocamlContained , ocamlThenErr 116 117"" PPX nodes 118 119syn match ocamlPpxIdentifier /\(\[@\{1,3\}\)\@<=\w\+\(\.\w\+\) * / 120syn region ocamlPpx matchgroup = ocamlPpxEncl start = "\[@\{1,3\} "contains = TOP end = "\] " 121 122"" Modules 123 124" "open" 125syn match ocamlKeyword "\<open\> "skipwhite skipempty nextgroup = ocamlFullMod 126 127" "include" 128syn match ocamlKeyword "\<include\> "skipwhite skipempty nextgroup = ocamlModParam , ocamlFullMod 129 130" "module" - somewhat complicated stuff ;-) 131" 2022-10: please document it? 132syn region ocamlModule matchgroup = ocamlKeyword start = "\<module\> "matchgroup = ocamlModule end = "\<_\|\u\(\w\|'\) * \> "contains = @ocamlAllErrs , ocamlComment skipwhite skipempty nextgroup = ocamlPreDef 133syn region ocamlPreDef start = ". "me= e-1end = "[ a-z:=) ] \@= "contained contains = @ocamlAllErrs , ocamlComment , ocamlModParam , ocamlGenMod , ocamlModTypeRestr nextgroup = ocamlModTypePre , ocamlModPreRHS 134syn region ocamlModParam start = "(\*\@! "end = ") "contained contains = ocamlGenMod , ocamlModParam , ocamlModParam1 , ocamlSig , ocamlVal 135syn match ocamlModParam1 "\<\u\(\w\|'\) * \> "contained skipwhite skipempty 136syn match ocamlGenMod "() "contained skipwhite skipempty 137 138syn match ocamlModTypePre ": "contained skipwhite skipempty nextgroup = ocamlModTRWith , ocamlSig , ocamlFunctor , ocamlModTypeRestr , ocamlModTypeOf 139syn match ocamlModTypeRestr "\<\w\(\w\|'\) * \( *\. * \w\(\w\|'\) * \) * \> "contained 140 141syn match ocamlModPreRHS "= "contained skipwhite skipempty nextgroup = ocamlModParam , ocamlFullMod 142syn keyword ocamlKeyword val 143syn region ocamlVal matchgroup = ocamlKeyword start = "\<val\> "matchgroup = ocamlLCIdentifier end = "\<\l\(\w\|'\) * \> "contains = @ocamlAllErrs , ocamlComment , ocamlFullMod skipwhite skipempty nextgroup = ocamlModTypePre 144syn region ocamlModRHS start = ". "end = ". * \w\|( [ ^* ] "me= e-2contained contains = ocamlComment skipwhite skipempty nextgroup = ocamlModParam , ocamlFullMod 145syn match ocamlFullMod "\<\u\(\w\|'\) * \( *\. * \u\(\w\|'\) * \) * "contained skipwhite skipempty nextgroup = ocamlFuncWith 146 147syn region ocamlFuncWith start = "( [ *) ] \@! "end = ") "contained contains = ocamlComment , ocamlWith , ocamlStruct skipwhite skipempty nextgroup = ocamlFuncWith 148 149syn region ocamlModTRWith start = "(\*\@! "end = ") "contained contains = @ocamlAENoParen , ocamlWith 150syn match ocamlWith "\<\(\u\(\w\|'\) * *\. * \) * \w\(\w\|'\) * \> "contained skipwhite skipempty nextgroup = ocamlWithRest 151syn region ocamlWithRest start = "[ ^) ] "end = ") "me= e-1contained contains = ALLBUT , @ocamlContained 152 153" "struct" 154syn region ocamlStruct matchgroup = ocamlStructEncl start = "\<\(module\s\+\)\=struct\> "matchgroup = ocamlStructEncl end = "\<end\> "contains = ALLBUT , @ocamlContained , ocamlEndErr 155 156" "sig" 157syn region ocamlSig matchgroup = ocamlSigEncl start = "\<sig\> "matchgroup = ocamlSigEncl end = "\<end\> "contains = ALLBUT , @ocamlContained , ocamlEndErr 158 159" "functor" 160syn region ocamlFunctor start = "\<functor\> "matchgroup = ocamlKeyword end = "-> "contains = @ocamlAllErrs , ocamlComment , ocamlModParam , ocamlGenMod skipwhite skipempty nextgroup = ocamlStruct , ocamlSig , ocamlFuncWith , ocamlFunctor 161 162" "module type" 163syn region ocamlModTypeOf start = "\<module\s\+type\(\s\+of\)\=\> "matchgroup = ocamlModule end = "\<\w\(\w\|'\) * \> "contains = ocamlComment skipwhite skipempty nextgroup = ocamlMTDef 164syn match ocamlMTDef "=\s * \w\(\w\|'\) * \> "hs= s+1, me= s+1skipwhite skipempty nextgroup = ocamlFullMod 165 166" Quoted strings 167syn region ocamlString matchgroup = ocamlQuotedStringDelim start = "{\z\( [ a-z_ ] * \)| "end = "|\z1} "contains = @Spell 168syn region ocamlString matchgroup = ocamlQuotedStringDelim start = "{% [ a-z_ ] \+\(\. [ a-z_ ] \+\)\?\( \z\( [ a-z_ ] \+\)\)\?| "end = "|\z1} "contains = @Spell 169 170syn keyword ocamlKeyword and as assert class 171syn keyword ocamlKeyword else 172syn keyword ocamlKeyword external 173syn keyword ocamlKeyword in inherit initializer 174syn keyword ocamlKeyword lazy let match 175syn keyword ocamlKeyword method new 176syn keyword ocamlKeyword parser rec 177syn keyword ocamlKeyword try 178syn keyword ocamlKeyword virtual when while with 179 180" Keywords which are handled by the type linter: 181" as (within a type equation) 182" constraint exception mutable nonrec of private type 183 184" The `fun` keyword has special treatment because of the syntax `fun … : t -> e` 185" where `->` ends the type context rather than being part of it; to handle that, 186" we blacklist the ocamlTypeAnnot matchgroup, and we plug ocamlFunTypeAnnot 187" instead (later in this file, by using containedin=ocamlFun): 188syn region ocamlFun matchgroup = ocamlKeyword start = '\<fun\> 'matchgroup = ocamlArrow end = '-> ' 189\contains = ALLBUT , @ocamlContained , ocamlArrow , ocamlInfixOp , ocamlTypeAnnot 190 191if exists ( "ocaml_revised" ) 192syn keyword ocamlKeyword do value 193syn keyword ocamlBoolean True False 194else 195syn keyword ocamlKeyword function 196syn keyword ocamlBoolean true false 197endif 198 199syn match ocamlEmptyConstructor "(\s * ) " 200syn match ocamlEmptyConstructor "\[\s * \] " 201syn match ocamlEmptyConstructor "\[|\s * >|] " 202syn match ocamlEmptyConstructor "\[<\s * >\] " 203syn match ocamlConstructor "\u\(\w\|'\) * \> " 204 205" Polymorphic variants 206syn match ocamlConstructor "`\w\(\w\|'\) * \> " 207 208" Module prefix 209syn match ocamlModPath "\u\(\w\|'\) * *\. "he= e-1 210 211syn match ocamlCharacter "'\\\d\d\d'\|'\\ [ \'ntbr ] '\|'.' " 212syn match ocamlCharacter "'\\x\x\x' " 213syn match ocamlCharErr "'\\\d\d'\|'\\\d' " 214syn match ocamlCharErr "'\\ [ ^\'ntbr ] ' " 215syn region ocamlString start = +" +skip = +\\\\\|\\" +end = +" +contains = @Spell 216 217syn match ocamlAnyVar "\<_\> " 218syn match ocamlKeyChar "|]\@! " 219syn match ocamlKeyChar "; " 220syn match ocamlKeyChar "\~ " 221syn match ocamlKeyChar "? " 222 223" NOTE: for correct precedence, the rule for ";;" must come after that for ";" 224syn match ocamlTopStop ";; " 225 226"" Operators 227 228" The grammar of operators is found there: 229" https://caml.inria.fr/pub/docs/manual-ocaml/names.html#operator-name 230" https://caml.inria.fr/pub/docs/manual-ocaml/extn.html#s:ext-ops 231" https://caml.inria.fr/pub/docs/manual-ocaml/extn.html#s:index-operators 232" = is both an operator name and a keyword, we let the user choose how 233" to display it (has to be declared before regular infix operators): 234syn match ocamlEqual "= " 235" Custom indexing operators: 236syn region ocamlIndexing matchgroup = ocamlIndexingOp 237 \start = "\. [ ~?!:|&$%=>@^/*+- ][ ~?!.:|&$%<=>@^*/+- ] * \_s * ( " 238 \end = ")\(\_s * <-\)\? " 239 \contains = ALLBUT , @ocamlContained , ocamlParenErr 240syn region ocamlIndexing matchgroup = ocamlIndexingOp 241 \start = "\. [ ~?!:|&$%=>@^/*+- ][ ~?!.:|&$%<=>@^*/+- ] * \_s * \[ " 242 \end = "]\(\_s * <-\)\? " 243 \contains = ALLBUT , @ocamlContained , ocamlBrackErr 244syn region ocamlIndexing matchgroup = ocamlIndexingOp 245 \start = "\. [ ~?!:|&$%=>@^/*+- ][ ~?!.:|&$%<=>@^*/+- ] * \_s * { " 246 \end = "}\(\_s * <-\)\? " 247 \contains = ALLBUT , @ocamlContained , ocamlBraceErr 248" Extension operators (has to be declared before regular infix operators): 249syn match ocamlExtensionOp "# [ #~?!.:|&$%<=>@^*/+- ] \+ " 250" Infix and prefix operators: 251syn match ocamlPrefixOp "! [ ~?!.:|&$%<=>@^*/+- ] * " 252syn match ocamlPrefixOp "[ ~? ][ ~?!.:|&$%<=>@^*/+- ] \+ " 253syn match ocamlInfixOp "[ &$%<>@^*/+- ][ ~?!.:|&$%<=>@^*/+- ] * " 254syn match ocamlInfixOp "[ |= ][ ~?!.:|&$%<=>@^*/+- ] \+ " 255syn match ocamlInfixOp "# [ ~?!.:|&$%<=>@^*/+- ] \+#\@! " 256syn match ocamlInfixOp "!= [ ~?!.:|&$%<=>@^*/+- ] \@! " 257syn keyword ocamlInfixOpKeyword asr land lor lsl lsr lxor mod or 258" := is technically an infix operator, but we may want to show it as a keyword 259" (somewhat analogously to = for let‐bindings and <- for assignations): 260syn match ocamlRefAssign ":= " 261" :: is technically not an operator, but we may want to show it as such: 262syn match ocamlCons ":: " 263" -> and <- are keywords, not operators (but can appear in longer operators): 264syn match ocamlArrow "-> [ ~?!.:|&$%<=>@^*/+- ] \@! " 265if exists ( "ocaml_revised" ) 266syn match ocamlErr "<- [ ~?!.:|&$%<=>@^*/+- ] \@! " 267else 268syn match ocamlKeyChar "<- [ ~?!.:|&$%<=>@^*/+- ] \@! " 269endif 270 271" Script shebang (has to be declared after operators) 272syn match ocamlShebang "\%1l^#!. * $ " 273 274syn match ocamlNumber "-\=\<\d\(_\|\d\) * [ l|L|n ] \?\> " 275syn match ocamlNumber "-\=\<0 [ x|X ] \(\x\|_\)\+ [ l|L|n ] \?\> " 276syn match ocamlNumber "-\=\<0 [ o|O ] \(\o\|_\)\+ [ l|L|n ] \?\> " 277syn match ocamlNumber "-\=\<0 [ b|B ] \( [ 01 ] \|_\)\+ [ l|L|n ] \?\> " 278syn match ocamlFloat "-\=\<\d\(_\|\d\) * \.\?\(_\|\d\) * \( [ eE ][ -+ ] \=\d\(_\|\d\) * \)\=\> " 279 280" Labels 281syn match ocamlLabel "[ ~? ] \(\l\|_\)\(\w\|'\) * :\? " 282syn region ocamlLabel transparent matchgroup = ocamlLabel start = "[ ~? ] (\(\l\|_\)\(\w\|'\) * "lc= 2end = ") "me= e-1contains = ALLBUT , @ocamlContained , ocamlParenErr 283 284"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 285 286"" Type contexts 287 288" How we recognize type contexts is explained in `type-linter-notes.md` 289" and a test suite is found in `type-linter-test.ml`. 290" 291" ocamlTypeExpr is the cluster of things that can make up a type expression 292" (in a loose sense, e.g. the “as” keyword and universal quantification are 293" included). Regions containing a type expression use it like this: 294" 295" contains=@ocamlTypeExpr,... 296" 297" ocamlTypeContained is the cluster of things that can be found in a type 298" expression or a type definition. It is not expected to be used in any region, 299" it exists solely for throwing things in it that should not pollute the main 300" linter. 301" 302" Both clusters are filled in incrementally. Every match group that is not to be 303" found at the main level must be declared as “contained” and added to either 304" ocamlTypeExpr or ocamlTypeContained. 305" 306" In these clusters we don’t put generic things that can also be found elswhere, 307" i.e. ocamlComment and ocamlPpx, because everything that is in these clusters 308" is also put in ocamlContained and thus ignored by the main linter. 309 310"syn cluster ocamlTypeExpr contains= 311syn cluster ocamlTypeContained contains = @ocamlTypeExpr 312syn cluster ocamlContained add = @ocamlTypeContained 313 314" We’ll use a “catch-all” highlighting group to show as error anything that is 315" not matched more specifically; we don’t want spaces to be reported as errors 316" (different background color), so we just catch them here: 317syn cluster ocamlTypeExpr add = ocamlTypeBlank 318syn match ocamlTypeBlank contained "\_s\+ " 319hi link ocamlTypeBlank NONE 320 321" NOTE: Carefully avoid catching "(*" here. 322syn cluster ocamlTypeExpr add = ocamlTypeParen 323syn region ocamlTypeParen contained transparent 324\matchgroup = ocamlEncl start = "(\*\@! " 325\matchgroup = ocamlEncl end = ") " 326\contains = @ocamlTypeExpr , ocamlComment , ocamlPpx 327 328syn cluster ocamlTypeExpr add = ocamlTypeKeyChar , ocamlTypeAs 329syn match ocamlTypeKeyChar contained "-> " 330syn match ocamlTypeKeyChar contained "\* " 331syn match ocamlTypeKeyChar contained "# " 332syn match ocamlTypeKeyChar contained ", " 333syn match ocamlTypeKeyChar contained "\. " 334syn keyword ocamlTypeAs contained as 335hi link ocamlTypeAs ocamlKeyword 336 337syn cluster ocamlTypeExpr add = ocamlTypeVariance 338syn match ocamlTypeVariance contained "[ -+! ] \ze * \('\|\<_\>\) " 339syn match ocamlTypeVariance contained "[ -+ ] * !\+\ze * \('\|\<_\>\) " 340syn match ocamlTypeVariance contained "! * [ -+ ] \+\ze * \('\|\<_\>\) " 341 342syn cluster ocamlTypeContained add = ocamlTypeEq 343syn match ocamlTypeEq contained "[ +: ] \?= " 344hi link ocamlTypeEq ocamlKeyChar 345 346syn cluster ocamlTypeExpr add = ocamlTypeVar , ocamlTypeConstr , ocamlTypeAnyVar , ocamlTypeBuiltin 347syn match ocamlTypeVar contained "'\(\l\|_\)\(\w\|'\) * \> " 348syn match ocamlTypeConstr contained "\<\(\l\|_\)\(\w\|'\) * \> " 349" NOTE: for correct precedence, the rule for the wildcard (ocamlTypeAnyVar) 350" must come after the rule for type constructors (ocamlTypeConstr). 351syn match ocamlTypeAnyVar contained "\<_\> " 352" NOTE: For correct precedence, these builtin names must occur after the rule 353" for type constructors (ocamlTypeConstr) but before the rule for non-optional 354" labeled arguments (ocamlTypeLabel). For the latter to take precedence over 355" these builtin names, we use “syn match” here instead of “syn keyword”. 356syn match ocamlTypeBuiltin contained "\<array\> " 357syn match ocamlTypeBuiltin contained "\<bool\> " 358syn match ocamlTypeBuiltin contained "\<bytes\> " 359syn match ocamlTypeBuiltin contained "\<char\> " 360syn match ocamlTypeBuiltin contained "\<exn\> " 361syn match ocamlTypeBuiltin contained "\<float\> " 362syn match ocamlTypeBuiltin contained "\<format\> " 363syn match ocamlTypeBuiltin contained "\<format4\> " 364syn match ocamlTypeBuiltin contained "\<format6\> " 365syn match ocamlTypeBuiltin contained "\<in_channel\> " 366syn match ocamlTypeBuiltin contained "\<int\> " 367syn match ocamlTypeBuiltin contained "\<int32\> " 368syn match ocamlTypeBuiltin contained "\<int64\> " 369syn match ocamlTypeBuiltin contained "\<lazy_t\> " 370syn match ocamlTypeBuiltin contained "\<list\> " 371syn match ocamlTypeBuiltin contained "\<nativeint\> " 372syn match ocamlTypeBuiltin contained "\<option\> " 373syn match ocamlTypeBuiltin contained "\<out_channel\> " 374syn match ocamlTypeBuiltin contained "\<ref\> " 375syn match ocamlTypeBuiltin contained "\<result\> " 376syn match ocamlTypeBuiltin contained "\<scanner\> " 377syn match ocamlTypeBuiltin contained "\<string\> " 378syn match ocamlTypeBuiltin contained "\<unit\> " 379 380syn cluster ocamlTypeExpr add = ocamlTypeLabel 381syn match ocamlTypeLabel contained "?\?\(\l\|_\)\(\w\|'\) * \_s * : [ >= ] \@! " 382hi link ocamlTypeLabel ocamlLabel 383 384" Object type 385syn cluster ocamlTypeExpr add = ocamlTypeObject 386syn region ocamlTypeObject contained 387\matchgroup = ocamlEncl start = "< " 388\matchgroup = ocamlEncl end = "> " 389\contains = ocamlTypeObjectDots , ocamlLCIdentifier , ocamlTypeObjectAnnot , ocamlTypeBlank , ocamlComment , ocamlPpx 390hi link ocamlTypeObject ocamlTypeCatchAll 391syn cluster ocamlTypeContained add = ocamlTypeObjectDots 392syn match ocamlTypeObjectDots contained "\.\. " 393hi link ocamlTypeObjectDots ocamlKeyChar 394syn cluster ocamlTypeContained add = ocamlTypeObjectAnnot 395syn region ocamlTypeObjectAnnot contained 396\matchgroup = ocamlKeyChar start = ": " 397\matchgroup = ocamlKeyChar end = ";\|>\@= " 398\contains = @ocamlTypeExpr , ocamlComment , ocamlPpx 399hi link ocamlTypeObjectAnnot ocamlTypeCatchAll 400 401" Record type definition 402syn cluster ocamlTypeContained add = ocamlTypeRecordDecl 403syn region ocamlTypeRecordDecl contained 404\matchgroup = ocamlEncl start = "{ " 405\matchgroup = ocamlEncl end = "} " 406\contains = ocamlTypeMutable , ocamlLCIdentifier , ocamlTypeRecordAnnot , ocamlTypeBlank , ocamlComment , ocamlPpx 407hi link ocamlTypeRecordDecl ocamlTypeCatchAll 408syn cluster ocamlTypeContained add = ocamlTypeMutable 409syn keyword ocamlTypeMutable contained mutable 410hi link ocamlTypeMutable ocamlKeyword 411syn cluster ocamlTypeContained add = ocamlTypeRecordAnnot 412syn region ocamlTypeRecordAnnot contained 413\matchgroup = ocamlKeyChar start = ": " 414\matchgroup = ocamlKeyChar end = ";\|}\@= " 415\contains = @ocamlTypeExpr , ocamlComment , ocamlPpx 416hi link ocamlTypeRecordAnnot ocamlTypeCatchAll 417 418" Polymorphic variant types 419" NOTE: Carefully avoid catching "[@" here. 420syn cluster ocamlTypeExpr add = ocamlTypeVariant 421syn region ocamlTypeVariant contained 422\matchgroup = ocamlEncl start = "\[> " start="\[<" start ="\[@\@! " 423\matchgroup = ocamlEncl end = "\] " 424\contains = ocamlTypeVariantKeyChar , ocamlTypeVariantConstr , ocamlTypeVariantAnnot , ocamlTypeBlank , ocamlComment , ocamlPpx 425hi link ocamlTypeVariant ocamlTypeCatchAll 426syn cluster ocamlTypeContained add = ocamlTypeVariantKeyChar 427syn match ocamlTypeVariantKeyChar contained "| " 428syn match ocamlTypeVariantKeyChar contained "> " 429hi link ocamlTypeVariantKeyChar ocamlKeyChar 430syn cluster ocamlTypeContained add = ocamlTypeVariantConstr 431syn match ocamlTypeVariantConstr contained "`\w\(\w\|'\) * \> " 432hi link ocamlTypeVariantConstr ocamlConstructor 433syn cluster ocamlTypeContained add = ocamlTypeVariantAnnot 434syn region ocamlTypeVariantAnnot contained 435\matchgroup = ocamlKeyword start = "\<of\> " 436\matchgroup = ocamlKeyChar end = "|\|>\|\]\@= " 437\contains = @ocamlTypeExpr , ocamlTypeAmp , ocamlComment , ocamlPpx 438hi link ocamlTypeVariantAnnot ocamlTypeCatchAll 439syn cluster ocamlTypeContained add = ocamlTypeAmp 440syn match ocamlTypeAmp contained "& " 441hi link ocamlTypeAmp ocamlTypeKeyChar 442 443" Sum type definition 444syn cluster ocamlTypeContained add = ocamlTypeSumDecl 445syn regionocamlTypeSumDecl contained 446\matchgroup = ocamlTypeSumBar start = "| " 447\matchgroup = ocamlTypeSumConstr start = "\<\u\(\w\|'\) * \> " 448\matchgroup = ocamlTypeSumConstr start= "\<false\> " start="\<true\>" 449\ matchgroup =ocamlTypeSumConstr start="(\_s * )" start ="\[\_s * ] " start="(\_s * ::\_s * )" 450\ matchgroup =NONE end="\(\<type\>\|\<exception\>\|\<val\>\|\<module\>\|\<class\>\|\<method\>\|\<constraint\>\|\<inherit\>\|\<object\>\|\<struct\>\|\<open\>\|\<include\>\|\<let\>\|\<external\>\|\<in\>\|\<end\>\|)\|]\|}\|;\|;;\|=\)\@=" 451\ matchgroup =NONE end="\(\<and\>\)\@=" 452\ contains =ocamlTypeSumBar,ocamlTypeSumConstr ,ocamlTypeSumAnnot,ocamlTypeBlank ,ocamlComment,ocamlPpx 453hi link ocamlTypeSumDecl ocamlTypeCatchAll 454syn cluster ocamlTypeContained add = ocamlTypeSumBar 455syn match ocamlTypeSumBar contained "| " 456hi link ocamlTypeSumBar ocamlKeyChar 457syn cluster ocamlTypeContained add = ocamlTypeSumConstr 458syn match ocamlTypeSumConstr contained "\<\u\(\w\|'\) * \> " 459syn match ocamlTypeSumConstr contained "\<false\> " 460syn match ocamlTypeSumConstr contained "\<true\> " 461syn match ocamlTypeSumConstr contained "(\_s * ) " 462syn match ocamlTypeSumConstr contained "\[\_s * ] " 463syn match ocamlTypeSumConstr contained "(\_s * ::\_s * ) " 464hi link ocamlTypeSumConstr ocamlConstructor 465syn cluster ocamlTypeContained add = ocamlTypeSumAnnot 466syn region ocamlTypeSumAnnot contained 467\matchgroup = ocamlKeyword start = "\<of\> " 468\matchgroup = ocamlKeyChar start = ": " 469\matchgroup = NONE end = "|\@= " 470\matchgroup = NONE end = "\(\<type\>\|\<exception\>\|\<val\>\|\<module\>\|\<class\>\|\<method\>\|\<constraint\>\|\<inherit\>\|\<object\>\|\<struct\>\|\<open\>\|\<include\>\|\<let\>\|\<external\>\|\<in\>\|\<end\>\|)\|]\|}\|;\|;;\)\@= " 471\matchgroup = NONE end = "\(\<and\>\)\@= " 472\contains = @ocamlTypeExpr , ocamlTypeRecordDecl , ocamlComment , ocamlPpx 473hi link ocamlTypeSumAnnot ocamlTypeCatchAll 474 475" Type context opened by “type” (type definition), “constraint” (type 476" constraint) and “exception” (exception definition) 477syn region ocamlTypeDef 478\matchgroup = ocamlKeyword start = "\<type\>\(\_s\+\<nonrec\>\)\?\|\<constraint\>\|\<exception\> " 479\matchgroup = NONE end = "\(\<type\>\|\<exception\>\|\<val\>\|\<module\>\|\<class\>\|\<method\>\|\<constraint\>\|\<inherit\>\|\<object\>\|\<struct\>\|\<open\>\|\<include\>\|\<let\>\|\<external\>\|\<in\>\|\<end\>\|)\|]\|}\|;\|;;\)\@= " 480\contains = @ocamlTypeExpr , ocamlTypeEq , ocamlTypePrivate , ocamlTypeDefDots , ocamlTypeRecordDecl , ocamlTypeSumDecl , ocamlTypeDefAnd , ocamlComment , ocamlPpx 481hi link ocamlTypeDef ocamlTypeCatchAll 482syn cluster ocamlTypeContained add = ocamlTypePrivate 483syn keyword ocamlTypePrivate contained private 484hi link ocamlTypePrivate ocamlKeyword 485syn cluster ocamlTypeContained add = ocamlTypeDefAnd 486syn keyword ocamlTypeDefAnd contained and 487hi link ocamlTypeDefAnd ocamlKeyword 488syn cluster ocamlTypeContained add = ocamlTypeDefDots 489syn match ocamlTypeDefDots contained "\.\. " 490hi link ocamlTypeDefDots ocamlKeyChar 491 492" When "exception" is preceded by "with", "|" or "(", that’s not an exception 493" definition but an exception pattern; we simply highlight the keyword without 494" starting a type context. 495" NOTE: These rules must occur after that for "exception". 496syn match ocamlKeyword "\<with\_s\+exception\> "lc= 4 497syn match ocamlKeyword "|\_s * exception\> "lc= 1 498syn match ocamlKeyword "(\_s * exception\> "lc= 1 499 500" Type context opened by “:” (countless kinds of type annotations) and “:>” 501" (type coercions) 502syn region ocamlTypeAnnot matchgroup = ocamlKeyChar start = ":\(>\|\_s * type\>\| [ >:= ] \@!\) " 503\matchgroup = NONE end = "\(\<type\>\|\<exception\>\|\<val\>\|\<module\>\|\<class\>\|\<method\>\|\<constraint\>\|\<inherit\>\|\<object\>\|\<struct\>\|\<open\>\|\<include\>\|\<let\>\|\<external\>\|\<in\>\|\<end\>\|)\|]\|}\|;\|;;\)\@= " 504\matchgroup = NONE end = "\(;\|}\)\@= " 505\matchgroup = NONE end = "\(=\|:>\)\@= " 506\contains = @ocamlTypeExpr , ocamlComment , ocamlPpx 507hi link ocamlTypeAnnot ocamlTypeCatchAll 508 509" Type annotation that gives the return type of a `fun` keyword 510" (the type context is ended by `->`) 511syn cluster ocamlTypeContained add = ocamlFunTypeAnnot 512syn region ocamlFunTypeAnnot contained containedin = ocamlFun 513\matchgroup = ocamlKeyChar start = ": " 514\matchgroup = NONE end = "\(->\)\@= " 515\contains = @ocamlTypeExpr , ocamlComment , ocamlPpx 516hi link ocamlFunTypeAnnot ocamlTypeCatchAll 517 518" Module paths (including functors) in types. 519" NOTE: This rule must occur after the rule for ocamlTypeSumDecl as it must take 520" precedence over it (otherwise the module name would be mistakenly highlighted 521" as a constructor). 522" NOTE: Carefully avoid catching "(*" here. 523syn cluster ocamlTypeExpr add = ocamlTypeModPath 524syn match ocamlTypeModPath contained "\<\u\(\w\|'\) * \_s * \. " 525syn region ocamlTypeModPath contained transparent 526\matchgroup = ocamlModPath start = "\<\u\(\w\|'\) * \_s * (\*\@! " 527\matchgroup = ocamlModPath end = ")\_s * \. " 528\contains = ocamlTypeDotlessModPath , ocamlTypeBlank , ocamlComment , ocamlPpx 529hi link ocamlTypeModPath ocamlModPath 530syn cluster ocamlTypeContained add = ocamlTypeDotlessModPath 531syn match ocamlTypeDotlessModPath contained "\<\u\(\w\|'\) * \_s * \.\? " 532syn region ocamlTypeDotlessModPath contained transparent 533\matchgroup = ocamlModPath start = "\<\u\(\w\|'\) * \_s * (\*\@! " 534\matchgroup = ocamlModPath end = ")\_s * \.\? " 535\contains = ocamlTypeDotlessModPath , ocamlTypeBlank , ocamlComment , ocamlPpx 536hi link ocamlTypeDotlessModPath ocamlTypeModPath 537 538"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 539 540" Synchronization 541syn sync minlines= 50 542syn sync maxlines= 500 543 544if ! exists ( "ocaml_revised" ) 545syn syncmatch ocamlDoSync grouphereocamlDo "\<do\> " 546syn syncmatch ocamlDoSync groupthereocamlDo "\<done\> " 547endif 548 549if exists ( "ocaml_revised" ) 550syn syncmatch ocamlEndSync grouphereocamlEnd "\<\(object\)\> " 551else 552syn syncmatch ocamlEndSync grouphereocamlEnd "\<\(begin\|object\)\> " 553endif 554 555syn syncmatch ocamlEndSync groupthereocamlEnd "\<end\> " 556syn syncmatch ocamlStructSync grouphereocamlStruct "\<struct\> " 557syn syncmatch ocamlStructSync groupthereocamlStruct "\<end\> " 558syn syncmatch ocamlSigSync grouphereocamlSig "\<sig\> " 559syn syncmatch ocamlSigSync groupthereocamlSig "\<end\> " 560 561" Define the default highlighting. 562 563hi def link ocamlBraceErr Error 564hi def link ocamlBrackErr Error 565hi def link ocamlParenErr Error 566hi def link ocamlArrErr Error 567 568hi def link ocamlCountErr Error 569hi def link ocamlDoErr Error 570hi def link ocamlDoneErr Error 571hi def link ocamlEndErr Error 572hi def link ocamlThenErr Error 573hi def link ocamlKwErr Error 574 575hi def link ocamlCharErr Error 576 577hi def link ocamlErr Error 578 579hi def link ocamlComment Comment 580hi def link ocamlShebang ocamlComment 581 582hi def link ocamlModPath Include 583hi def link ocamlObject Include 584hi def link ocamlModule Include 585hi def link ocamlModParam1 Include 586hi def link ocamlGenMod Include 587hi def link ocamlFullMod Include 588hi def link ocamlFuncWith Include 589hi def link ocamlModParam Include 590hi def link ocamlModTypeRestr Include 591hi def link ocamlWith Include 592hi def link ocamlMTDef Include 593hi def link ocamlSigEncl ocamlModule 594hi def link ocamlStructEncl ocamlModule 595 596hi def link ocamlScript Include 597 598hi def link ocamlConstructor Constant 599hi def link ocamlEmptyConstructor ocamlConstructor 600 601hi def link ocamlVal Keyword 602hi def link ocamlModTypePre Keyword 603hi def link ocamlModPreRHS Keyword 604hi def link ocamlFunctor Keyword 605hi def link ocamlModTypeOf Keyword 606hi def link ocamlKeyword Keyword 607hi def link ocamlMethod Include 608hi def link ocamlArrow Keyword 609hi def link ocamlKeyChar Keyword 610hi def link ocamlAnyVar Keyword 611hi def link ocamlTopStop Keyword 612 613hi def link ocamlRefAssign ocamlKeyChar 614hi def link ocamlEqual ocamlKeyChar 615hi def link ocamlCons ocamlInfixOp 616 617hi def link ocamlPrefixOp ocamlOperator 618hi def link ocamlInfixOp ocamlOperator 619hi def link ocamlExtensionOp ocamlOperator 620hi def link ocamlIndexingOp ocamlOperator 621 622if exists ( "ocaml_highlight_operators" ) 623hi def link ocamlInfixOpKeyword ocamlOperator 624hi def link ocamlOperator Operator 625else 626hi def link ocamlInfixOpKeyword Keyword 627endif 628 629hi def link ocamlBoolean Boolean 630hi def link ocamlCharacter Character 631hi def link ocamlNumber Number 632hi def link ocamlFloat Float 633hi def link ocamlString String 634hi def link ocamlQuotedStringDelim Identifier 635 636hi def link ocamlLabel Identifier 637 638" Type linting groups that the user can customize: 639" - ocamlTypeCatchAll: anything in a type context that is not caught by more 640" specific rules (in principle, this should only match syntax errors) 641" - ocamlTypeConstr: type constructors 642" - ocamlTypeBuiltin: builtin type constructors (like int or list) 643" - ocamlTypeVar: type variables ('a) 644" - ocamlTypeAnyVar: wildcard (_) 645" - ocamlTypeVariance: variance and injectivity indications (+'a, !'a) 646" - ocamlTypeKeyChar: symbols such as -> and * 647" Default values below mimick the behavior before the type linter was 648" implemented, but now we can do better. :-) 649hi def link ocamlTypeCatchAll Error 650hi def link ocamlTypeConstr NONE 651hi def link ocamlTypeBuiltin Type 652hi def link ocamlTypeVar NONE 653hi def link ocamlTypeAnyVar NONE 654hi def link ocamlTypeVariance ocamlKeyChar 655hi def link ocamlTypeKeyChar ocamlKeyChar 656 657hi def link ocamlTodo Todo 658 659hi def link ocamlEncl Keyword 660 661hi def link ocamlPpxEncl ocamlEncl 662 663let b: current_syntax = "ocaml" 664 665let & cpo = s: keepcpo 666unlet s: keepcpo 667 668" vim: ts=8