1" Vim syntax file 2" Language: OCaml 3" Filenames: *.ml *.mli *.mll *.mly 4" Maintainers: Markus Mottl <[email protected]> 5" Karl-Heinz Sylla <[email protected]> 6" Issac Trotts <[email protected]> 7" URL: http://www.ocaml.info/vim/syntax/ocaml.vim 8" Last Change: 2005 May 18 - Added 'NOTE' to highlighted comment words (MM) 9" 2005 Apr 14 - Fixed a small bug concerning 'include' (MM) 10" 2005 Mar 15 - Added a patch from David Baelde (MM) 11 12" A minor patch was applied to the official version so that object/end 13" can be distinguished from begin/end, which is used for indentation, 14" and folding. (David Baelde) 15 16" For version 5.x: Clear all syntax items 17" For version 6.x: Quit when a syntax file was already loaded 18if version < 600 19 syntax clear 20elseif exists("b:current_syntax") && b:current_syntax != "ocaml" 21 finish 22endif 23 24" OCaml is case sensitive. 25syn case match 26 27" Script headers highlighted like comments 28syn match ocamlComment "^#!.*" 29 30" Scripting directives 31syn match ocamlScript "^#\<\(quit\|labels\|warnings\|directory\|cd\|load\|use\|install_printer\|remove_printer\|require\|thread\|trace\|untrace\|untrace_all\|print_depth\|print_length\)\>" 32 33" lowercase identifier - the standard way to match 34syn match ocamlLCIdentifier /\<\(\l\|_\)\(\w\|'\)*\>/ 35 36syn match ocamlKeyChar "|" 37 38" Errors 39syn match ocamlBraceErr "}" 40syn match ocamlBrackErr "\]" 41syn match ocamlParenErr ")" 42syn match ocamlArrErr "|]" 43 44syn match ocamlCommentErr "\*)" 45 46syn match ocamlCountErr "\<downto\>" 47syn match ocamlCountErr "\<to\>" 48 49if !exists("ocaml_revised") 50 syn match ocamlDoErr "\<do\>" 51endif 52 53syn match ocamlDoneErr "\<done\>" 54syn match ocamlThenErr "\<then\>" 55 56" Error-highlighting of "end" without synchronization: 57" as keyword or as error (default) 58if exists("ocaml_noend_error") 59 syn match ocamlKeyword "\<end\>" 60else 61 syn match ocamlEndErr "\<end\>" 62endif 63 64" Some convenient clusters 65syn cluster ocamlAllErrs contains=ocamlBraceErr,ocamlBrackErr,ocamlParenErr,ocamlCommentErr,ocamlCountErr,ocamlDoErr,ocamlDoneErr,ocamlEndErr,ocamlThenErr 66 67syn cluster ocamlAENoParen contains=ocamlBraceErr,ocamlBrackErr,ocamlCommentErr,ocamlCountErr,ocamlDoErr,ocamlDoneErr,ocamlEndErr,ocamlThenErr 68 69syn cluster ocamlContained contains=ocamlTodo,ocamlPreDef,ocamlModParam,ocamlModParam1,ocamlPreMPRestr,ocamlMPRestr,ocamlMPRestr1,ocamlMPRestr2,ocamlMPRestr3,ocamlModRHS,ocamlFuncWith,ocamlFuncStruct,ocamlModTypeRestr,ocamlModTRWith,ocamlWith,ocamlWithRest,ocamlModType,ocamlFullMod 70 71 72" Enclosing delimiters 73syn region ocamlEncl transparent matchgroup=ocamlKeyword start="(" matchgroup=ocamlKeyword end=")" contains=ALLBUT,@ocamlContained,ocamlParenErr 74syn region ocamlEncl transparent matchgroup=ocamlKeyword start="{" matchgroup=ocamlKeyword end="}" contains=ALLBUT,@ocamlContained,ocamlBraceErr 75syn region ocamlEncl transparent matchgroup=ocamlKeyword start="\[" matchgroup=ocamlKeyword end="\]" contains=ALLBUT,@ocamlContained,ocamlBrackErr 76syn region ocamlEncl transparent matchgroup=ocamlKeyword start="\[|" matchgroup=ocamlKeyword end="|\]" contains=ALLBUT,@ocamlContained,ocamlArrErr 77 78 79" Comments 80syn region ocamlComment start="(\*" end="\*)" contains=ocamlComment,ocamlTodo 81syn keyword ocamlTodo contained TODO FIXME XXX NOTE 82 83 84" Objects 85syn region ocamlEnd matchgroup=ocamlObject start="\<object\>" matchgroup=ocamlObject end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr 86 87 88" Blocks 89if !exists("ocaml_revised") 90 syn region ocamlEnd matchgroup=ocamlKeyword start="\<begin\>" matchgroup=ocamlKeyword end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr 91endif 92 93 94" "for" 95syn region ocamlNone matchgroup=ocamlKeyword start="\<for\>" matchgroup=ocamlKeyword end="\<\(to\|downto\)\>" contains=ALLBUT,@ocamlContained,ocamlCountErr 96 97 98" "do" 99if !exists("ocaml_revised") 100 syn region ocamlDo matchgroup=ocamlKeyword start="\<do\>" matchgroup=ocamlKeyword end="\<done\>" contains=ALLBUT,@ocamlContained,ocamlDoneErr 101endif 102 103" "if" 104syn region ocamlNone matchgroup=ocamlKeyword start="\<if\>" matchgroup=ocamlKeyword end="\<then\>" contains=ALLBUT,@ocamlContained,ocamlThenErr 105 106 107"" Modules 108 109" "struct" 110syn region ocamlStruct matchgroup=ocamlModule start="\<struct\>" matchgroup=ocamlModule end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr 111 112" "sig" 113syn region ocamlSig matchgroup=ocamlModule start="\<sig\>" matchgroup=ocamlModule end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr,ocamlModule 114syn region ocamlModSpec matchgroup=ocamlKeyword start="\<module\>" matchgroup=ocamlModule end="\<\u\(\w\|'\)*\>" contained contains=@ocamlAllErrs,ocamlComment skipwhite skipempty nextgroup=ocamlModTRWith,ocamlMPRestr 115 116" "open" 117syn region ocamlNone matchgroup=ocamlKeyword start="\<open\>" matchgroup=ocamlModule end="\<\u\(\w\|'\)*\(\.\u\(\w\|'\)*\)*\>" contains=@ocamlAllErrs,ocamlComment 118 119" "include" 120syn match ocamlKeyword "\<include\>" skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod 121 122" "module" - somewhat complicated stuff ;-) 123syn region ocamlModule matchgroup=ocamlKeyword start="\<module\>" matchgroup=ocamlModule end="\<\u\(\w\|'\)*\>" contains=@ocamlAllErrs,ocamlComment skipwhite skipempty nextgroup=ocamlPreDef 124syn region ocamlPreDef start="."me=e-1 matchgroup=ocamlKeyword end="\l\|="me=e-1 contained contains=@ocamlAllErrs,ocamlComment,ocamlModParam,ocamlModTypeRestr,ocamlModTRWith nextgroup=ocamlModPreRHS 125syn region ocamlModParam start="([^*]" end=")" contained contains=@ocamlAENoParen,ocamlModParam1 126syn match ocamlModParam1 "\<\u\(\w\|'\)*\>" contained skipwhite skipempty nextgroup=ocamlPreMPRestr 127 128syn region ocamlPreMPRestr start="."me=e-1 end=")"me=e-1 contained contains=@ocamlAllErrs,ocamlComment,ocamlMPRestr,ocamlModTypeRestr 129 130syn region ocamlMPRestr start=":" end="."me=e-1 contained contains=@ocamlComment skipwhite skipempty nextgroup=ocamlMPRestr1,ocamlMPRestr2,ocamlMPRestr3 131syn region ocamlMPRestr1 matchgroup=ocamlModule start="\ssig\s\=" matchgroup=ocamlModule end="\<end\>" contained contains=ALLBUT,@ocamlContained,ocamlEndErr,ocamlModule 132syn region ocamlMPRestr2 start="\sfunctor\(\s\|(\)\="me=e-1 matchgroup=ocamlKeyword end="->" contained contains=@ocamlAllErrs,ocamlComment,ocamlModParam skipwhite skipempty nextgroup=ocamlFuncWith,ocamlMPRestr2 133syn match ocamlMPRestr3 "\w\(\w\|'\)*\(\.\w\(\w\|'\)*\)*" contained 134syn match ocamlModPreRHS "=" contained skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod 135syn region ocamlModRHS start="." end=".\w\|([^*]"me=e-2 contained contains=ocamlComment skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod 136syn match ocamlFullMod "\<\u\(\w\|'\)*\(\.\u\(\w\|'\)*\)*" contained skipwhite skipempty nextgroup=ocamlFuncWith 137 138syn region ocamlFuncWith start="([^*]"me=e-1 end=")" contained contains=ocamlComment,ocamlWith,ocamlFuncStruct skipwhite skipempty nextgroup=ocamlFuncWith 139syn region ocamlFuncStruct matchgroup=ocamlModule start="[^a-zA-Z]struct\>"hs=s+1 matchgroup=ocamlModule end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr 140 141syn match ocamlModTypeRestr "\<\w\(\w\|'\)*\(\.\w\(\w\|'\)*\)*\>" contained 142syn region ocamlModTRWith start=":\s*("hs=s+1 end=")" contained contains=@ocamlAENoParen,ocamlWith 143syn match ocamlWith "\<\(\u\(\w\|'\)*\.\)*\w\(\w\|'\)*\>" contained skipwhite skipempty nextgroup=ocamlWithRest 144syn region ocamlWithRest start="[^)]" end=")"me=e-1 contained contains=ALLBUT,@ocamlContained 145 146" "module type" 147syn region ocamlKeyword start="\<module\>\s*\<type\>" matchgroup=ocamlModule end="\<\w\(\w\|'\)*\>" contains=ocamlComment skipwhite skipempty nextgroup=ocamlMTDef 148syn match ocamlMTDef "=\s*\w\(\w\|'\)*\>"hs=s+1,me=s 149 150syn keyword ocamlKeyword and as assert class 151syn keyword ocamlKeyword constraint else 152syn keyword ocamlKeyword exception external fun 153 154syn keyword ocamlKeyword in inherit initializer 155syn keyword ocamlKeyword land lazy let match 156syn keyword ocamlKeyword method mutable new of 157syn keyword ocamlKeyword parser private raise rec 158syn keyword ocamlKeyword try type 159syn keyword ocamlKeyword val virtual when while with 160 161if exists("ocaml_revised") 162 syn keyword ocamlKeyword do value 163 syn keyword ocamlBoolean True False 164else 165 syn keyword ocamlKeyword function 166 syn keyword ocamlBoolean true false 167 syn match ocamlKeyChar "!" 168endif 169 170syn keyword ocamlType array bool char exn float format format4 171syn keyword ocamlType int int32 int64 lazy_t list nativeint option 172syn keyword ocamlType string unit 173 174syn keyword ocamlOperator asr lor lsl lsr lxor mod not 175 176syn match ocamlConstructor "(\s*)" 177syn match ocamlConstructor "\[\s*\]" 178syn match ocamlConstructor "\[|\s*>|]" 179syn match ocamlConstructor "\[<\s*>\]" 180syn match ocamlConstructor "\u\(\w\|'\)*\>" 181 182" Polymorphic variants 183syn match ocamlConstructor "`\w\(\w\|'\)*\>" 184 185" Module prefix 186syn match ocamlModPath "\u\(\w\|'\)*\."he=e-1 187 188syn match ocamlCharacter "'\\\d\d\d'\|'\\[\'ntbr]'\|'.'" 189syn match ocamlCharErr "'\\\d\d'\|'\\\d'" 190syn match ocamlCharErr "'\\[^\'ntbr]'" 191syn region ocamlString start=+"+ skip=+\\\\\|\\"+ end=+"+ 192 193syn match ocamlFunDef "->" 194syn match ocamlRefAssign ":=" 195syn match ocamlTopStop ";;" 196syn match ocamlOperator "\^" 197syn match ocamlOperator "::" 198 199syn match ocamlOperator "&&" 200syn match ocamlOperator "<" 201syn match ocamlOperator ">" 202syn match ocamlAnyVar "\<_\>" 203syn match ocamlKeyChar "|[^\]]"me=e-1 204syn match ocamlKeyChar ";" 205syn match ocamlKeyChar "\~" 206syn match ocamlKeyChar "?" 207syn match ocamlKeyChar "\*" 208syn match ocamlKeyChar "=" 209 210if exists("ocaml_revised") 211 syn match ocamlErr "<-" 212else 213 syn match ocamlOperator "<-" 214endif 215 216syn match ocamlNumber "\<-\=\d\+[l|L]\?\>" 217syn match ocamlNumber "\<-\=0[x|X]\x\+[l|L]\?\>" 218syn match ocamlNumber "\<-\=0[o|O]\o\+[l|L]\?\>" 219syn match ocamlNumber "\<-\=0[b|B][01]\+[l|L]\?\>" 220syn match ocamlFloat "\<-\=\d\+\.\d*\([eE][-+]\=\d\+\)\=[fl]\=\>" 221 222" Labels 223syn match ocamlLabel "\~\(\l\|_\)\(\w\|'\)*"lc=1 224syn match ocamlLabel "?\(\l\|_\)\(\w\|'\)*"lc=1 225syn region ocamlLabel transparent matchgroup=ocamlLabel start="?(\(\l\|_\)\(\w\|'\)*"lc=2 end=")"me=e-1 contains=ALLBUT,@ocamlContained,ocamlParenErr 226 227 228" Synchronization 229syn sync minlines=50 230syn sync maxlines=500 231 232if !exists("ocaml_revised") 233 syn sync match ocamlDoSync grouphere ocamlDo "\<do\>" 234 syn sync match ocamlDoSync groupthere ocamlDo "\<done\>" 235endif 236 237if exists("ocaml_revised") 238 syn sync match ocamlEndSync grouphere ocamlEnd "\<\(object\)\>" 239else 240 syn sync match ocamlEndSync grouphere ocamlEnd "\<\(begin\|object\)\>" 241endif 242 243syn sync match ocamlEndSync groupthere ocamlEnd "\<end\>" 244syn sync match ocamlStructSync grouphere ocamlStruct "\<struct\>" 245syn sync match ocamlStructSync groupthere ocamlStruct "\<end\>" 246syn sync match ocamlSigSync grouphere ocamlSig "\<sig\>" 247syn sync match ocamlSigSync groupthere ocamlSig "\<end\>" 248 249" Define the default highlighting. 250" For version 5.7 and earlier: only when not done already 251" For version 5.8 and later: only when an item doesn't have highlighting yet 252if version >= 508 || !exists("did_ocaml_syntax_inits") 253 if version < 508 254 let did_ocaml_syntax_inits = 1 255 command -nargs=+ HiLink hi link <args> 256 else 257 command -nargs=+ HiLink hi def link <args> 258 endif 259 260 HiLink ocamlBraceErr Error 261 HiLink ocamlBrackErr Error 262 HiLink ocamlParenErr Error 263 HiLink ocamlArrErr Error 264 265 HiLink ocamlCommentErr Error 266 267 HiLink ocamlCountErr Error 268 HiLink ocamlDoErr Error 269 HiLink ocamlDoneErr Error 270 HiLink ocamlEndErr Error 271 HiLink ocamlThenErr Error 272 273 HiLink ocamlCharErr Error 274 275 HiLink ocamlErr Error 276 277 HiLink ocamlComment Comment 278 279 HiLink ocamlModPath Include 280 HiLink ocamlObject Include 281 HiLink ocamlModule Include 282 HiLink ocamlModParam1 Include 283 HiLink ocamlModType Include 284 HiLink ocamlMPRestr3 Include 285 HiLink ocamlFullMod Include 286 HiLink ocamlModTypeRestr Include 287 HiLink ocamlWith Include 288 HiLink ocamlMTDef Include 289 290 HiLink ocamlScript Include 291 292 HiLink ocamlConstructor Constant 293 294 HiLink ocamlModPreRHS Keyword 295 HiLink ocamlMPRestr2 Keyword 296 HiLink ocamlKeyword Keyword 297 HiLink ocamlFunDef Keyword 298 HiLink ocamlRefAssign Keyword 299 HiLink ocamlKeyChar Keyword 300 HiLink ocamlAnyVar Keyword 301 HiLink ocamlTopStop Keyword 302 HiLink ocamlOperator Keyword 303 304 HiLink ocamlBoolean Boolean 305 HiLink ocamlCharacter Character 306 HiLink ocamlNumber Number 307 HiLink ocamlFloat Float 308 HiLink ocamlString String 309 310 HiLink ocamlLabel Identifier 311 312 HiLink ocamlType Type 313 314 HiLink ocamlTodo Todo 315 316 HiLink ocamlEncl Keyword 317 318 delcommand HiLink 319endif 320 321let b:current_syntax = "ocaml" 322 323" vim: ts=8 324