Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim syntax file |
| 2 | " Language: OCaml |
| 3 | " Filenames: *.ml *.mli *.mll *.mly |
Bram Moolenaar | 202795b | 2005-10-11 20:29:39 +0000 | [diff] [blame] | 4 | " Maintainers: Markus Mottl <markus.mottl@gmail.com> |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 5 | " Karl-Heinz Sylla <Karl-Heinz.Sylla@gmd.de> |
| 6 | " Issac Trotts <ijtrotts@ucdavis.edu> |
Bram Moolenaar | 202795b | 2005-10-11 20:29:39 +0000 | [diff] [blame] | 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) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 15 | |
| 16 | " For version 5.x: Clear all syntax items |
| 17 | " For version 6.x: Quit when a syntax file was already loaded |
| 18 | if version < 600 |
| 19 | syntax clear |
Bram Moolenaar | 202795b | 2005-10-11 20:29:39 +0000 | [diff] [blame] | 20 | elseif exists("b:current_syntax") && b:current_syntax != "ocaml" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 21 | finish |
| 22 | endif |
| 23 | |
| 24 | " OCaml is case sensitive. |
| 25 | syn case match |
| 26 | |
| 27 | " Script headers highlighted like comments |
| 28 | syn match ocamlComment "^#!.*" |
| 29 | |
| 30 | " Scripting directives |
Bram Moolenaar | 202795b | 2005-10-11 20:29:39 +0000 | [diff] [blame] | 31 | syn match ocamlScript "^#\<\(quit\|labels\|warnings\|directory\|cd\|load\|use\|install_printer\|remove_printer\|require\|thread\|trace\|untrace\|untrace_all\|print_depth\|print_length\)\>" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 32 | |
| 33 | " lowercase identifier - the standard way to match |
| 34 | syn match ocamlLCIdentifier /\<\(\l\|_\)\(\w\|'\)*\>/ |
| 35 | |
| 36 | syn match ocamlKeyChar "|" |
| 37 | |
| 38 | " Errors |
| 39 | syn match ocamlBraceErr "}" |
| 40 | syn match ocamlBrackErr "\]" |
| 41 | syn match ocamlParenErr ")" |
| 42 | syn match ocamlArrErr "|]" |
| 43 | |
| 44 | syn match ocamlCommentErr "\*)" |
| 45 | |
| 46 | syn match ocamlCountErr "\<downto\>" |
| 47 | syn match ocamlCountErr "\<to\>" |
| 48 | |
| 49 | if !exists("ocaml_revised") |
| 50 | syn match ocamlDoErr "\<do\>" |
| 51 | endif |
| 52 | |
| 53 | syn match ocamlDoneErr "\<done\>" |
| 54 | syn match ocamlThenErr "\<then\>" |
| 55 | |
| 56 | " Error-highlighting of "end" without synchronization: |
| 57 | " as keyword or as error (default) |
| 58 | if exists("ocaml_noend_error") |
| 59 | syn match ocamlKeyword "\<end\>" |
| 60 | else |
| 61 | syn match ocamlEndErr "\<end\>" |
| 62 | endif |
| 63 | |
| 64 | " Some convenient clusters |
| 65 | syn cluster ocamlAllErrs contains=ocamlBraceErr,ocamlBrackErr,ocamlParenErr,ocamlCommentErr,ocamlCountErr,ocamlDoErr,ocamlDoneErr,ocamlEndErr,ocamlThenErr |
| 66 | |
| 67 | syn cluster ocamlAENoParen contains=ocamlBraceErr,ocamlBrackErr,ocamlCommentErr,ocamlCountErr,ocamlDoErr,ocamlDoneErr,ocamlEndErr,ocamlThenErr |
| 68 | |
| 69 | syn 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 |
| 73 | syn region ocamlEncl transparent matchgroup=ocamlKeyword start="(" matchgroup=ocamlKeyword end=")" contains=ALLBUT,@ocamlContained,ocamlParenErr |
| 74 | syn region ocamlEncl transparent matchgroup=ocamlKeyword start="{" matchgroup=ocamlKeyword end="}" contains=ALLBUT,@ocamlContained,ocamlBraceErr |
| 75 | syn region ocamlEncl transparent matchgroup=ocamlKeyword start="\[" matchgroup=ocamlKeyword end="\]" contains=ALLBUT,@ocamlContained,ocamlBrackErr |
| 76 | syn region ocamlEncl transparent matchgroup=ocamlKeyword start="\[|" matchgroup=ocamlKeyword end="|\]" contains=ALLBUT,@ocamlContained,ocamlArrErr |
| 77 | |
| 78 | |
| 79 | " Comments |
| 80 | syn region ocamlComment start="(\*" end="\*)" contains=ocamlComment,ocamlTodo |
Bram Moolenaar | 202795b | 2005-10-11 20:29:39 +0000 | [diff] [blame] | 81 | syn keyword ocamlTodo contained TODO FIXME XXX NOTE |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 82 | |
| 83 | |
| 84 | " Objects |
Bram Moolenaar | 202795b | 2005-10-11 20:29:39 +0000 | [diff] [blame] | 85 | syn region ocamlEnd matchgroup=ocamlObject start="\<object\>" matchgroup=ocamlObject end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 86 | |
| 87 | |
| 88 | " Blocks |
| 89 | if !exists("ocaml_revised") |
| 90 | syn region ocamlEnd matchgroup=ocamlKeyword start="\<begin\>" matchgroup=ocamlKeyword end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr |
| 91 | endif |
| 92 | |
| 93 | |
| 94 | " "for" |
| 95 | syn region ocamlNone matchgroup=ocamlKeyword start="\<for\>" matchgroup=ocamlKeyword end="\<\(to\|downto\)\>" contains=ALLBUT,@ocamlContained,ocamlCountErr |
| 96 | |
| 97 | |
| 98 | " "do" |
| 99 | if !exists("ocaml_revised") |
| 100 | syn region ocamlDo matchgroup=ocamlKeyword start="\<do\>" matchgroup=ocamlKeyword end="\<done\>" contains=ALLBUT,@ocamlContained,ocamlDoneErr |
| 101 | endif |
| 102 | |
| 103 | " "if" |
| 104 | syn region ocamlNone matchgroup=ocamlKeyword start="\<if\>" matchgroup=ocamlKeyword end="\<then\>" contains=ALLBUT,@ocamlContained,ocamlThenErr |
| 105 | |
| 106 | |
| 107 | "" Modules |
| 108 | |
| 109 | " "struct" |
| 110 | syn region ocamlStruct matchgroup=ocamlModule start="\<struct\>" matchgroup=ocamlModule end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr |
| 111 | |
| 112 | " "sig" |
| 113 | syn region ocamlSig matchgroup=ocamlModule start="\<sig\>" matchgroup=ocamlModule end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr,ocamlModule |
| 114 | syn region ocamlModSpec matchgroup=ocamlKeyword start="\<module\>" matchgroup=ocamlModule end="\<\u\(\w\|'\)*\>" contained contains=@ocamlAllErrs,ocamlComment skipwhite skipempty nextgroup=ocamlModTRWith,ocamlMPRestr |
| 115 | |
| 116 | " "open" |
| 117 | syn region ocamlNone matchgroup=ocamlKeyword start="\<open\>" matchgroup=ocamlModule end="\<\u\(\w\|'\)*\(\.\u\(\w\|'\)*\)*\>" contains=@ocamlAllErrs,ocamlComment |
| 118 | |
| 119 | " "include" |
Bram Moolenaar | 202795b | 2005-10-11 20:29:39 +0000 | [diff] [blame] | 120 | syn match ocamlKeyword "\<include\>" skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 121 | |
| 122 | " "module" - somewhat complicated stuff ;-) |
| 123 | syn region ocamlModule matchgroup=ocamlKeyword start="\<module\>" matchgroup=ocamlModule end="\<\u\(\w\|'\)*\>" contains=@ocamlAllErrs,ocamlComment skipwhite skipempty nextgroup=ocamlPreDef |
| 124 | syn region ocamlPreDef start="."me=e-1 matchgroup=ocamlKeyword end="\l\|="me=e-1 contained contains=@ocamlAllErrs,ocamlComment,ocamlModParam,ocamlModTypeRestr,ocamlModTRWith nextgroup=ocamlModPreRHS |
| 125 | syn region ocamlModParam start="([^*]" end=")" contained contains=@ocamlAENoParen,ocamlModParam1 |
| 126 | syn match ocamlModParam1 "\<\u\(\w\|'\)*\>" contained skipwhite skipempty nextgroup=ocamlPreMPRestr |
| 127 | |
| 128 | syn region ocamlPreMPRestr start="."me=e-1 end=")"me=e-1 contained contains=@ocamlAllErrs,ocamlComment,ocamlMPRestr,ocamlModTypeRestr |
| 129 | |
| 130 | syn region ocamlMPRestr start=":" end="."me=e-1 contained contains=@ocamlComment skipwhite skipempty nextgroup=ocamlMPRestr1,ocamlMPRestr2,ocamlMPRestr3 |
| 131 | syn region ocamlMPRestr1 matchgroup=ocamlModule start="\ssig\s\=" matchgroup=ocamlModule end="\<end\>" contained contains=ALLBUT,@ocamlContained,ocamlEndErr,ocamlModule |
| 132 | syn region ocamlMPRestr2 start="\sfunctor\(\s\|(\)\="me=e-1 matchgroup=ocamlKeyword end="->" contained contains=@ocamlAllErrs,ocamlComment,ocamlModParam skipwhite skipempty nextgroup=ocamlFuncWith,ocamlMPRestr2 |
| 133 | syn match ocamlMPRestr3 "\w\(\w\|'\)*\(\.\w\(\w\|'\)*\)*" contained |
| 134 | syn match ocamlModPreRHS "=" contained skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod |
| 135 | syn region ocamlModRHS start="." end=".\w\|([^*]"me=e-2 contained contains=ocamlComment skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod |
| 136 | syn match ocamlFullMod "\<\u\(\w\|'\)*\(\.\u\(\w\|'\)*\)*" contained skipwhite skipempty nextgroup=ocamlFuncWith |
| 137 | |
| 138 | syn region ocamlFuncWith start="([^*]"me=e-1 end=")" contained contains=ocamlComment,ocamlWith,ocamlFuncStruct skipwhite skipempty nextgroup=ocamlFuncWith |
| 139 | syn region ocamlFuncStruct matchgroup=ocamlModule start="[^a-zA-Z]struct\>"hs=s+1 matchgroup=ocamlModule end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr |
| 140 | |
| 141 | syn match ocamlModTypeRestr "\<\w\(\w\|'\)*\(\.\w\(\w\|'\)*\)*\>" contained |
| 142 | syn region ocamlModTRWith start=":\s*("hs=s+1 end=")" contained contains=@ocamlAENoParen,ocamlWith |
| 143 | syn match ocamlWith "\<\(\u\(\w\|'\)*\.\)*\w\(\w\|'\)*\>" contained skipwhite skipempty nextgroup=ocamlWithRest |
| 144 | syn region ocamlWithRest start="[^)]" end=")"me=e-1 contained contains=ALLBUT,@ocamlContained |
| 145 | |
| 146 | " "module type" |
| 147 | syn region ocamlKeyword start="\<module\>\s*\<type\>" matchgroup=ocamlModule end="\<\w\(\w\|'\)*\>" contains=ocamlComment skipwhite skipempty nextgroup=ocamlMTDef |
| 148 | syn match ocamlMTDef "=\s*\w\(\w\|'\)*\>"hs=s+1,me=s |
| 149 | |
| 150 | syn keyword ocamlKeyword and as assert class |
| 151 | syn keyword ocamlKeyword constraint else |
| 152 | syn keyword ocamlKeyword exception external fun |
| 153 | |
| 154 | syn keyword ocamlKeyword in inherit initializer |
| 155 | syn keyword ocamlKeyword land lazy let match |
| 156 | syn keyword ocamlKeyword method mutable new of |
| 157 | syn keyword ocamlKeyword parser private raise rec |
| 158 | syn keyword ocamlKeyword try type |
| 159 | syn keyword ocamlKeyword val virtual when while with |
| 160 | |
| 161 | if exists("ocaml_revised") |
| 162 | syn keyword ocamlKeyword do value |
| 163 | syn keyword ocamlBoolean True False |
| 164 | else |
| 165 | syn keyword ocamlKeyword function |
| 166 | syn keyword ocamlBoolean true false |
| 167 | syn match ocamlKeyChar "!" |
| 168 | endif |
| 169 | |
Bram Moolenaar | 202795b | 2005-10-11 20:29:39 +0000 | [diff] [blame] | 170 | syn keyword ocamlType array bool char exn float format format4 |
| 171 | syn keyword ocamlType int int32 int64 lazy_t list nativeint option |
| 172 | syn keyword ocamlType string unit |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 173 | |
| 174 | syn keyword ocamlOperator asr lor lsl lsr lxor mod not |
| 175 | |
| 176 | syn match ocamlConstructor "(\s*)" |
| 177 | syn match ocamlConstructor "\[\s*\]" |
| 178 | syn match ocamlConstructor "\[|\s*>|]" |
| 179 | syn match ocamlConstructor "\[<\s*>\]" |
| 180 | syn match ocamlConstructor "\u\(\w\|'\)*\>" |
| 181 | |
| 182 | " Polymorphic variants |
| 183 | syn match ocamlConstructor "`\w\(\w\|'\)*\>" |
| 184 | |
| 185 | " Module prefix |
| 186 | syn match ocamlModPath "\u\(\w\|'\)*\."he=e-1 |
| 187 | |
| 188 | syn match ocamlCharacter "'\\\d\d\d'\|'\\[\'ntbr]'\|'.'" |
| 189 | syn match ocamlCharErr "'\\\d\d'\|'\\\d'" |
| 190 | syn match ocamlCharErr "'\\[^\'ntbr]'" |
| 191 | syn region ocamlString start=+"+ skip=+\\\\\|\\"+ end=+"+ |
| 192 | |
| 193 | syn match ocamlFunDef "->" |
| 194 | syn match ocamlRefAssign ":=" |
| 195 | syn match ocamlTopStop ";;" |
| 196 | syn match ocamlOperator "\^" |
| 197 | syn match ocamlOperator "::" |
| 198 | |
| 199 | syn match ocamlOperator "&&" |
| 200 | syn match ocamlOperator "<" |
| 201 | syn match ocamlOperator ">" |
| 202 | syn match ocamlAnyVar "\<_\>" |
| 203 | syn match ocamlKeyChar "|[^\]]"me=e-1 |
| 204 | syn match ocamlKeyChar ";" |
| 205 | syn match ocamlKeyChar "\~" |
| 206 | syn match ocamlKeyChar "?" |
| 207 | syn match ocamlKeyChar "\*" |
| 208 | syn match ocamlKeyChar "=" |
| 209 | |
| 210 | if exists("ocaml_revised") |
Bram Moolenaar | 202795b | 2005-10-11 20:29:39 +0000 | [diff] [blame] | 211 | syn match ocamlErr "<-" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 212 | else |
Bram Moolenaar | 202795b | 2005-10-11 20:29:39 +0000 | [diff] [blame] | 213 | syn match ocamlOperator "<-" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 214 | endif |
| 215 | |
Bram Moolenaar | 202795b | 2005-10-11 20:29:39 +0000 | [diff] [blame] | 216 | syn match ocamlNumber "\<-\=\d\+[l|L]\?\>" |
| 217 | syn match ocamlNumber "\<-\=0[x|X]\x\+[l|L]\?\>" |
| 218 | syn match ocamlNumber "\<-\=0[o|O]\o\+[l|L]\?\>" |
| 219 | syn match ocamlNumber "\<-\=0[b|B][01]\+[l|L]\?\>" |
| 220 | syn match ocamlFloat "\<-\=\d\+\.\d*\([eE][-+]\=\d\+\)\=[fl]\=\>" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 221 | |
| 222 | " Labels |
Bram Moolenaar | 202795b | 2005-10-11 20:29:39 +0000 | [diff] [blame] | 223 | syn match ocamlLabel "\~\(\l\|_\)\(\w\|'\)*"lc=1 |
| 224 | syn match ocamlLabel "?\(\l\|_\)\(\w\|'\)*"lc=1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 225 | syn region ocamlLabel transparent matchgroup=ocamlLabel start="?(\(\l\|_\)\(\w\|'\)*"lc=2 end=")"me=e-1 contains=ALLBUT,@ocamlContained,ocamlParenErr |
| 226 | |
| 227 | |
| 228 | " Synchronization |
| 229 | syn sync minlines=50 |
| 230 | syn sync maxlines=500 |
| 231 | |
| 232 | if !exists("ocaml_revised") |
| 233 | syn sync match ocamlDoSync grouphere ocamlDo "\<do\>" |
| 234 | syn sync match ocamlDoSync groupthere ocamlDo "\<done\>" |
| 235 | endif |
| 236 | |
| 237 | if exists("ocaml_revised") |
| 238 | syn sync match ocamlEndSync grouphere ocamlEnd "\<\(object\)\>" |
| 239 | else |
| 240 | syn sync match ocamlEndSync grouphere ocamlEnd "\<\(begin\|object\)\>" |
| 241 | endif |
| 242 | |
| 243 | syn sync match ocamlEndSync groupthere ocamlEnd "\<end\>" |
| 244 | syn sync match ocamlStructSync grouphere ocamlStruct "\<struct\>" |
| 245 | syn sync match ocamlStructSync groupthere ocamlStruct "\<end\>" |
| 246 | syn sync match ocamlSigSync grouphere ocamlSig "\<sig\>" |
| 247 | syn 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 |
| 252 | if 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 |
Bram Moolenaar | 202795b | 2005-10-11 20:29:39 +0000 | [diff] [blame] | 280 | HiLink ocamlObject Include |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 |
| 319 | endif |
| 320 | |
| 321 | let b:current_syntax = "ocaml" |
| 322 | |
| 323 | " vim: ts=8 |