blob: 24116f0e02c5a9e21d62ceffb530578dbc9af9ff [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim syntax file
2" Language: OCaml
3" Filenames: *.ml *.mli *.mll *.mly
Bram Moolenaar202795b2005-10-11 20:29:39 +00004" Maintainers: Markus Mottl <markus.mottl@gmail.com>
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00005" Karl-Heinz Sylla <Karl-Heinz.Sylla@gmd.de>
6" Issac Trotts <ijtrotts@ucdavis.edu>
Bram Moolenaar202795b2005-10-11 20:29:39 +00007" URL: http://www.ocaml.info/vim/syntax/ocaml.vim
Bram Moolenaar16ea3672013-07-28 16:02:18 +02008" Last Change: 2012 May 12 - Added Dominique Pellé's spell checking patch (MM)
9" 2012 Feb 01 - Improved module path highlighting (MM)
10" 2010 Oct 11 - Added highlighting of lnot (MM, thanks to Erick Matsen)
Bram Moolenaar202795b2005-10-11 20:29:39 +000011
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 Moolenaar071d4272004-06-13 20:20:40 +000015
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
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000020elseif exists("b:current_syntax") && b:current_syntax == "ocaml"
Bram Moolenaar071d4272004-06-13 20:20:40 +000021 finish
22endif
23
24" OCaml is case sensitive.
25syn case match
26
Bram Moolenaar20f90cf2011-05-19 12:22:51 +020027" Access to the method of an object
28syn match ocamlMethod "#"
29
Bram Moolenaar071d4272004-06-13 20:20:40 +000030" Script headers highlighted like comments
Bram Moolenaar16ea3672013-07-28 16:02:18 +020031syn match ocamlComment "^#!.*" contains=@Spell
Bram Moolenaar071d4272004-06-13 20:20:40 +000032
33" Scripting directives
Bram Moolenaar20f90cf2011-05-19 12:22:51 +020034syn match ocamlScript "^#\<\(quit\|labels\|warnings\|directory\|cd\|load\|use\|install_printer\|remove_printer\|require\|thread\|trace\|untrace\|untrace_all\|print_depth\|print_length\|camlp4o\)\>"
Bram Moolenaar9964e462007-05-05 17:54:07 +000035
Bram Moolenaar071d4272004-06-13 20:20:40 +000036" lowercase identifier - the standard way to match
37syn match ocamlLCIdentifier /\<\(\l\|_\)\(\w\|'\)*\>/
38
39syn match ocamlKeyChar "|"
40
41" Errors
42syn match ocamlBraceErr "}"
43syn match ocamlBrackErr "\]"
44syn match ocamlParenErr ")"
45syn match ocamlArrErr "|]"
46
47syn match ocamlCommentErr "\*)"
48
49syn match ocamlCountErr "\<downto\>"
50syn match ocamlCountErr "\<to\>"
51
52if !exists("ocaml_revised")
53 syn match ocamlDoErr "\<do\>"
54endif
55
56syn match ocamlDoneErr "\<done\>"
57syn match ocamlThenErr "\<then\>"
58
59" Error-highlighting of "end" without synchronization:
60" as keyword or as error (default)
61if exists("ocaml_noend_error")
62 syn match ocamlKeyword "\<end\>"
63else
64 syn match ocamlEndErr "\<end\>"
65endif
66
67" Some convenient clusters
68syn cluster ocamlAllErrs contains=ocamlBraceErr,ocamlBrackErr,ocamlParenErr,ocamlCommentErr,ocamlCountErr,ocamlDoErr,ocamlDoneErr,ocamlEndErr,ocamlThenErr
69
70syn cluster ocamlAENoParen contains=ocamlBraceErr,ocamlBrackErr,ocamlCommentErr,ocamlCountErr,ocamlDoErr,ocamlDoneErr,ocamlEndErr,ocamlThenErr
71
Bram Moolenaar20f90cf2011-05-19 12:22:51 +020072syn cluster ocamlContained contains=ocamlTodo,ocamlPreDef,ocamlModParam,ocamlModParam1,ocamlPreMPRestr,ocamlMPRestr,ocamlMPRestr1,ocamlMPRestr2,ocamlMPRestr3,ocamlModRHS,ocamlFuncWith,ocamlFuncStruct,ocamlModTypeRestr,ocamlModTRWith,ocamlWith,ocamlWithRest,ocamlModType,ocamlFullMod,ocamlVal
Bram Moolenaar071d4272004-06-13 20:20:40 +000073
74
75" Enclosing delimiters
76syn region ocamlEncl transparent matchgroup=ocamlKeyword start="(" matchgroup=ocamlKeyword end=")" contains=ALLBUT,@ocamlContained,ocamlParenErr
77syn region ocamlEncl transparent matchgroup=ocamlKeyword start="{" matchgroup=ocamlKeyword end="}" contains=ALLBUT,@ocamlContained,ocamlBraceErr
78syn region ocamlEncl transparent matchgroup=ocamlKeyword start="\[" matchgroup=ocamlKeyword end="\]" contains=ALLBUT,@ocamlContained,ocamlBrackErr
79syn region ocamlEncl transparent matchgroup=ocamlKeyword start="\[|" matchgroup=ocamlKeyword end="|\]" contains=ALLBUT,@ocamlContained,ocamlArrErr
80
81
82" Comments
Bram Moolenaar16ea3672013-07-28 16:02:18 +020083syn region ocamlComment start="(\*" end="\*)" contains=@Spell,ocamlComment,ocamlTodo
Bram Moolenaar202795b2005-10-11 20:29:39 +000084syn keyword ocamlTodo contained TODO FIXME XXX NOTE
Bram Moolenaar071d4272004-06-13 20:20:40 +000085
86
87" Objects
Bram Moolenaar202795b2005-10-11 20:29:39 +000088syn region ocamlEnd matchgroup=ocamlObject start="\<object\>" matchgroup=ocamlObject end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr
Bram Moolenaar071d4272004-06-13 20:20:40 +000089
90
91" Blocks
92if !exists("ocaml_revised")
93 syn region ocamlEnd matchgroup=ocamlKeyword start="\<begin\>" matchgroup=ocamlKeyword end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr
94endif
95
96
97" "for"
98syn region ocamlNone matchgroup=ocamlKeyword start="\<for\>" matchgroup=ocamlKeyword end="\<\(to\|downto\)\>" contains=ALLBUT,@ocamlContained,ocamlCountErr
99
100
101" "do"
102if !exists("ocaml_revised")
103 syn region ocamlDo matchgroup=ocamlKeyword start="\<do\>" matchgroup=ocamlKeyword end="\<done\>" contains=ALLBUT,@ocamlContained,ocamlDoneErr
104endif
105
106" "if"
107syn region ocamlNone matchgroup=ocamlKeyword start="\<if\>" matchgroup=ocamlKeyword end="\<then\>" contains=ALLBUT,@ocamlContained,ocamlThenErr
108
109
110"" Modules
111
Bram Moolenaar071d4272004-06-13 20:20:40 +0000112" "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"
Bram Moolenaar16ea3672013-07-28 16:02:18 +0200117syn region ocamlNone matchgroup=ocamlKeyword start="\<open\>" matchgroup=ocamlModule end="\<\u\(\w\|'\)*\( *\. *\u\(\w\|'\)*\)*\>" contains=@ocamlAllErrs,ocamlComment
Bram Moolenaar071d4272004-06-13 20:20:40 +0000118
119" "include"
Bram Moolenaar202795b2005-10-11 20:29:39 +0000120syn match ocamlKeyword "\<include\>" skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod
Bram Moolenaar071d4272004-06-13 20:20:40 +0000121
122" "module" - somewhat complicated stuff ;-)
123syn region ocamlModule matchgroup=ocamlKeyword start="\<module\>" matchgroup=ocamlModule end="\<\u\(\w\|'\)*\>" contains=@ocamlAllErrs,ocamlComment skipwhite skipempty nextgroup=ocamlPreDef
Bram Moolenaar20f90cf2011-05-19 12:22:51 +0200124syn 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,ocamlVal
Bram Moolenaar071d4272004-06-13 20:20:40 +0000126syn 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
Bram Moolenaar16ea3672013-07-28 16:02:18 +0200133syn match ocamlMPRestr3 "\w\(\w\|'\)*\( *\. *\w\(\w\|'\)*\)*" contained
Bram Moolenaar071d4272004-06-13 20:20:40 +0000134syn match ocamlModPreRHS "=" contained skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod
Bram Moolenaar20f90cf2011-05-19 12:22:51 +0200135syn keyword ocamlKeyword val
Bram Moolenaar16ea3672013-07-28 16:02:18 +0200136syn region ocamlVal matchgroup=ocamlKeyword start="\<val\>" matchgroup=ocamlLCIdentifier end="\<\l\(\w\|'\)*\>" contains=@ocamlAllErrs,ocamlComment,ocamlFullMod skipwhite skipempty nextgroup=ocamlMPRestr
137syn region ocamlModRHS start="." end=". *\w\|([^*]"me=e-2 contained contains=ocamlComment skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod
138syn match ocamlFullMod "\<\u\(\w\|'\)*\( *\. *\u\(\w\|'\)*\)*" contained skipwhite skipempty nextgroup=ocamlFuncWith
Bram Moolenaar071d4272004-06-13 20:20:40 +0000139
140syn region ocamlFuncWith start="([^*]"me=e-1 end=")" contained contains=ocamlComment,ocamlWith,ocamlFuncStruct skipwhite skipempty nextgroup=ocamlFuncWith
141syn region ocamlFuncStruct matchgroup=ocamlModule start="[^a-zA-Z]struct\>"hs=s+1 matchgroup=ocamlModule end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr
142
Bram Moolenaar16ea3672013-07-28 16:02:18 +0200143syn match ocamlModTypeRestr "\<\w\(\w\|'\)*\( *\. *\w\(\w\|'\)*\)*\>" contained
Bram Moolenaar071d4272004-06-13 20:20:40 +0000144syn region ocamlModTRWith start=":\s*("hs=s+1 end=")" contained contains=@ocamlAENoParen,ocamlWith
Bram Moolenaar16ea3672013-07-28 16:02:18 +0200145syn match ocamlWith "\<\(\u\(\w\|'\)* *\. *\)*\w\(\w\|'\)*\>" contained skipwhite skipempty nextgroup=ocamlWithRest
Bram Moolenaar071d4272004-06-13 20:20:40 +0000146syn region ocamlWithRest start="[^)]" end=")"me=e-1 contained contains=ALLBUT,@ocamlContained
147
Bram Moolenaar20f90cf2011-05-19 12:22:51 +0200148" "struct"
149syn region ocamlStruct matchgroup=ocamlModule start="\<\(module\s\+\)\=struct\>" matchgroup=ocamlModule end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr
150
Bram Moolenaar071d4272004-06-13 20:20:40 +0000151" "module type"
Bram Moolenaar20f90cf2011-05-19 12:22:51 +0200152syn region ocamlKeyword start="\<module\>\s*\<type\>\(\s*\<of\>\)\=" matchgroup=ocamlModule end="\<\w\(\w\|'\)*\>" contains=ocamlComment skipwhite skipempty nextgroup=ocamlMTDef
Bram Moolenaar16ea3672013-07-28 16:02:18 +0200153syn match ocamlMTDef "=\s*\w\(\w\|'\)*\>"hs=s+1,me=s+1 skipwhite skipempty nextgroup=ocamlFullMod
Bram Moolenaar071d4272004-06-13 20:20:40 +0000154
155syn keyword ocamlKeyword and as assert class
156syn keyword ocamlKeyword constraint else
157syn keyword ocamlKeyword exception external fun
158
159syn keyword ocamlKeyword in inherit initializer
160syn keyword ocamlKeyword land lazy let match
161syn keyword ocamlKeyword method mutable new of
162syn keyword ocamlKeyword parser private raise rec
163syn keyword ocamlKeyword try type
Bram Moolenaar20f90cf2011-05-19 12:22:51 +0200164syn keyword ocamlKeyword virtual when while with
Bram Moolenaar071d4272004-06-13 20:20:40 +0000165
166if exists("ocaml_revised")
167 syn keyword ocamlKeyword do value
168 syn keyword ocamlBoolean True False
169else
170 syn keyword ocamlKeyword function
171 syn keyword ocamlBoolean true false
172 syn match ocamlKeyChar "!"
173endif
174
Bram Moolenaar202795b2005-10-11 20:29:39 +0000175syn keyword ocamlType array bool char exn float format format4
176syn keyword ocamlType int int32 int64 lazy_t list nativeint option
177syn keyword ocamlType string unit
Bram Moolenaar071d4272004-06-13 20:20:40 +0000178
Bram Moolenaar20f90cf2011-05-19 12:22:51 +0200179syn keyword ocamlOperator asr lnot lor lsl lsr lxor mod not
Bram Moolenaar071d4272004-06-13 20:20:40 +0000180
181syn match ocamlConstructor "(\s*)"
182syn match ocamlConstructor "\[\s*\]"
183syn match ocamlConstructor "\[|\s*>|]"
184syn match ocamlConstructor "\[<\s*>\]"
185syn match ocamlConstructor "\u\(\w\|'\)*\>"
186
187" Polymorphic variants
188syn match ocamlConstructor "`\w\(\w\|'\)*\>"
189
190" Module prefix
Bram Moolenaar16ea3672013-07-28 16:02:18 +0200191syn match ocamlModPath "\u\(\w\|'\)* *\."he=e-1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000192
193syn match ocamlCharacter "'\\\d\d\d'\|'\\[\'ntbr]'\|'.'"
Bram Moolenaar20f90cf2011-05-19 12:22:51 +0200194syn match ocamlCharacter "'\\x\x\x'"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000195syn match ocamlCharErr "'\\\d\d'\|'\\\d'"
196syn match ocamlCharErr "'\\[^\'ntbr]'"
Bram Moolenaar16ea3672013-07-28 16:02:18 +0200197syn region ocamlString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@Spell
Bram Moolenaar071d4272004-06-13 20:20:40 +0000198
199syn match ocamlFunDef "->"
200syn match ocamlRefAssign ":="
201syn match ocamlTopStop ";;"
202syn match ocamlOperator "\^"
203syn match ocamlOperator "::"
204
205syn match ocamlOperator "&&"
206syn match ocamlOperator "<"
207syn match ocamlOperator ">"
208syn match ocamlAnyVar "\<_\>"
209syn match ocamlKeyChar "|[^\]]"me=e-1
210syn match ocamlKeyChar ";"
211syn match ocamlKeyChar "\~"
212syn match ocamlKeyChar "?"
213syn match ocamlKeyChar "\*"
214syn match ocamlKeyChar "="
215
216if exists("ocaml_revised")
Bram Moolenaar202795b2005-10-11 20:29:39 +0000217 syn match ocamlErr "<-"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000218else
Bram Moolenaar202795b2005-10-11 20:29:39 +0000219 syn match ocamlOperator "<-"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000220endif
221
Bram Moolenaar9964e462007-05-05 17:54:07 +0000222syn match ocamlNumber "\<-\=\d\(_\|\d\)*[l|L|n]\?\>"
223syn match ocamlNumber "\<-\=0[x|X]\(\x\|_\)\+[l|L|n]\?\>"
224syn match ocamlNumber "\<-\=0[o|O]\(\o\|_\)\+[l|L|n]\?\>"
225syn match ocamlNumber "\<-\=0[b|B]\([01]\|_\)\+[l|L|n]\?\>"
Bram Moolenaar20f90cf2011-05-19 12:22:51 +0200226syn match ocamlFloat "\<-\=\d\(_\|\d\)*\.\?\(_\|\d\)*\([eE][-+]\=\d\(_\|\d\)*\)\=\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000227
228" Labels
Bram Moolenaar202795b2005-10-11 20:29:39 +0000229syn match ocamlLabel "\~\(\l\|_\)\(\w\|'\)*"lc=1
230syn match ocamlLabel "?\(\l\|_\)\(\w\|'\)*"lc=1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000231syn region ocamlLabel transparent matchgroup=ocamlLabel start="?(\(\l\|_\)\(\w\|'\)*"lc=2 end=")"me=e-1 contains=ALLBUT,@ocamlContained,ocamlParenErr
232
233
234" Synchronization
235syn sync minlines=50
236syn sync maxlines=500
237
238if !exists("ocaml_revised")
239 syn sync match ocamlDoSync grouphere ocamlDo "\<do\>"
240 syn sync match ocamlDoSync groupthere ocamlDo "\<done\>"
241endif
242
243if exists("ocaml_revised")
244 syn sync match ocamlEndSync grouphere ocamlEnd "\<\(object\)\>"
245else
246 syn sync match ocamlEndSync grouphere ocamlEnd "\<\(begin\|object\)\>"
247endif
248
249syn sync match ocamlEndSync groupthere ocamlEnd "\<end\>"
250syn sync match ocamlStructSync grouphere ocamlStruct "\<struct\>"
251syn sync match ocamlStructSync groupthere ocamlStruct "\<end\>"
252syn sync match ocamlSigSync grouphere ocamlSig "\<sig\>"
253syn sync match ocamlSigSync groupthere ocamlSig "\<end\>"
254
255" Define the default highlighting.
256" For version 5.7 and earlier: only when not done already
257" For version 5.8 and later: only when an item doesn't have highlighting yet
258if version >= 508 || !exists("did_ocaml_syntax_inits")
259 if version < 508
260 let did_ocaml_syntax_inits = 1
261 command -nargs=+ HiLink hi link <args>
262 else
263 command -nargs=+ HiLink hi def link <args>
264 endif
265
266 HiLink ocamlBraceErr Error
267 HiLink ocamlBrackErr Error
268 HiLink ocamlParenErr Error
269 HiLink ocamlArrErr Error
270
271 HiLink ocamlCommentErr Error
272
273 HiLink ocamlCountErr Error
274 HiLink ocamlDoErr Error
275 HiLink ocamlDoneErr Error
276 HiLink ocamlEndErr Error
277 HiLink ocamlThenErr Error
278
279 HiLink ocamlCharErr Error
280
281 HiLink ocamlErr Error
282
283 HiLink ocamlComment Comment
284
285 HiLink ocamlModPath Include
Bram Moolenaar202795b2005-10-11 20:29:39 +0000286 HiLink ocamlObject Include
Bram Moolenaar071d4272004-06-13 20:20:40 +0000287 HiLink ocamlModule Include
288 HiLink ocamlModParam1 Include
289 HiLink ocamlModType Include
290 HiLink ocamlMPRestr3 Include
291 HiLink ocamlFullMod Include
292 HiLink ocamlModTypeRestr Include
293 HiLink ocamlWith Include
294 HiLink ocamlMTDef Include
295
296 HiLink ocamlScript Include
297
298 HiLink ocamlConstructor Constant
299
Bram Moolenaar20f90cf2011-05-19 12:22:51 +0200300 HiLink ocamlVal Keyword
Bram Moolenaar071d4272004-06-13 20:20:40 +0000301 HiLink ocamlModPreRHS Keyword
302 HiLink ocamlMPRestr2 Keyword
303 HiLink ocamlKeyword Keyword
Bram Moolenaar9964e462007-05-05 17:54:07 +0000304 HiLink ocamlMethod Include
Bram Moolenaar071d4272004-06-13 20:20:40 +0000305 HiLink ocamlFunDef Keyword
306 HiLink ocamlRefAssign Keyword
307 HiLink ocamlKeyChar Keyword
308 HiLink ocamlAnyVar Keyword
309 HiLink ocamlTopStop Keyword
310 HiLink ocamlOperator Keyword
311
312 HiLink ocamlBoolean Boolean
313 HiLink ocamlCharacter Character
314 HiLink ocamlNumber Number
315 HiLink ocamlFloat Float
316 HiLink ocamlString String
317
318 HiLink ocamlLabel Identifier
319
320 HiLink ocamlType Type
321
322 HiLink ocamlTodo Todo
323
324 HiLink ocamlEncl Keyword
325
326 delcommand HiLink
327endif
328
329let b:current_syntax = "ocaml"
330
331" vim: ts=8