blob: 27eb3907e4a1e12515cc2844e41226e33a59281d [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 Moolenaar9964e462007-05-05 17:54:07 +00008" Last Change: 2007 Apr 13 - Added highlighting of nativeints (MM)
9" 2006 Oct 09 - More highlighting improvements to numbers (MM)
10" 2006 Sep 19 - Improved highlighting of numbers (Florent Monnier)
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
27" Script headers highlighted like comments
28syn match ocamlComment "^#!.*"
29
30" Scripting directives
Bram Moolenaar202795b2005-10-11 20:29:39 +000031syn match ocamlScript "^#\<\(quit\|labels\|warnings\|directory\|cd\|load\|use\|install_printer\|remove_printer\|require\|thread\|trace\|untrace\|untrace_all\|print_depth\|print_length\)\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +000032
Bram Moolenaar9964e462007-05-05 17:54:07 +000033" Script headers highlighted like comments
34syn match ocamlComment "^#!.*"
35
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
72syn cluster ocamlContained contains=ocamlTodo,ocamlPreDef,ocamlModParam,ocamlModParam1,ocamlPreMPRestr,ocamlMPRestr,ocamlMPRestr1,ocamlMPRestr2,ocamlMPRestr3,ocamlModRHS,ocamlFuncWith,ocamlFuncStruct,ocamlModTypeRestr,ocamlModTRWith,ocamlWith,ocamlWithRest,ocamlModType,ocamlFullMod
73
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
83syn region ocamlComment start="(\*" end="\*)" contains=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
112" "struct"
113syn region ocamlStruct matchgroup=ocamlModule start="\<struct\>" matchgroup=ocamlModule end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr
114
115" "sig"
116syn region ocamlSig matchgroup=ocamlModule start="\<sig\>" matchgroup=ocamlModule end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr,ocamlModule
117syn region ocamlModSpec matchgroup=ocamlKeyword start="\<module\>" matchgroup=ocamlModule end="\<\u\(\w\|'\)*\>" contained contains=@ocamlAllErrs,ocamlComment skipwhite skipempty nextgroup=ocamlModTRWith,ocamlMPRestr
118
119" "open"
120syn region ocamlNone matchgroup=ocamlKeyword start="\<open\>" matchgroup=ocamlModule end="\<\u\(\w\|'\)*\(\.\u\(\w\|'\)*\)*\>" contains=@ocamlAllErrs,ocamlComment
121
122" "include"
Bram Moolenaar202795b2005-10-11 20:29:39 +0000123syn match ocamlKeyword "\<include\>" skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod
Bram Moolenaar071d4272004-06-13 20:20:40 +0000124
125" "module" - somewhat complicated stuff ;-)
126syn region ocamlModule matchgroup=ocamlKeyword start="\<module\>" matchgroup=ocamlModule end="\<\u\(\w\|'\)*\>" contains=@ocamlAllErrs,ocamlComment skipwhite skipempty nextgroup=ocamlPreDef
127syn region ocamlPreDef start="."me=e-1 matchgroup=ocamlKeyword end="\l\|="me=e-1 contained contains=@ocamlAllErrs,ocamlComment,ocamlModParam,ocamlModTypeRestr,ocamlModTRWith nextgroup=ocamlModPreRHS
128syn region ocamlModParam start="([^*]" end=")" contained contains=@ocamlAENoParen,ocamlModParam1
129syn match ocamlModParam1 "\<\u\(\w\|'\)*\>" contained skipwhite skipempty nextgroup=ocamlPreMPRestr
130
131syn region ocamlPreMPRestr start="."me=e-1 end=")"me=e-1 contained contains=@ocamlAllErrs,ocamlComment,ocamlMPRestr,ocamlModTypeRestr
132
133syn region ocamlMPRestr start=":" end="."me=e-1 contained contains=@ocamlComment skipwhite skipempty nextgroup=ocamlMPRestr1,ocamlMPRestr2,ocamlMPRestr3
134syn region ocamlMPRestr1 matchgroup=ocamlModule start="\ssig\s\=" matchgroup=ocamlModule end="\<end\>" contained contains=ALLBUT,@ocamlContained,ocamlEndErr,ocamlModule
135syn region ocamlMPRestr2 start="\sfunctor\(\s\|(\)\="me=e-1 matchgroup=ocamlKeyword end="->" contained contains=@ocamlAllErrs,ocamlComment,ocamlModParam skipwhite skipempty nextgroup=ocamlFuncWith,ocamlMPRestr2
136syn match ocamlMPRestr3 "\w\(\w\|'\)*\(\.\w\(\w\|'\)*\)*" contained
137syn match ocamlModPreRHS "=" contained skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod
138syn region ocamlModRHS start="." end=".\w\|([^*]"me=e-2 contained contains=ocamlComment skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod
139syn match ocamlFullMod "\<\u\(\w\|'\)*\(\.\u\(\w\|'\)*\)*" contained skipwhite skipempty nextgroup=ocamlFuncWith
140
141syn region ocamlFuncWith start="([^*]"me=e-1 end=")" contained contains=ocamlComment,ocamlWith,ocamlFuncStruct skipwhite skipempty nextgroup=ocamlFuncWith
142syn region ocamlFuncStruct matchgroup=ocamlModule start="[^a-zA-Z]struct\>"hs=s+1 matchgroup=ocamlModule end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr
143
144syn match ocamlModTypeRestr "\<\w\(\w\|'\)*\(\.\w\(\w\|'\)*\)*\>" contained
145syn region ocamlModTRWith start=":\s*("hs=s+1 end=")" contained contains=@ocamlAENoParen,ocamlWith
146syn match ocamlWith "\<\(\u\(\w\|'\)*\.\)*\w\(\w\|'\)*\>" contained skipwhite skipempty nextgroup=ocamlWithRest
147syn region ocamlWithRest start="[^)]" end=")"me=e-1 contained contains=ALLBUT,@ocamlContained
148
149" "module type"
150syn region ocamlKeyword start="\<module\>\s*\<type\>" matchgroup=ocamlModule end="\<\w\(\w\|'\)*\>" contains=ocamlComment skipwhite skipempty nextgroup=ocamlMTDef
151syn match ocamlMTDef "=\s*\w\(\w\|'\)*\>"hs=s+1,me=s
152
153syn keyword ocamlKeyword and as assert class
154syn keyword ocamlKeyword constraint else
155syn keyword ocamlKeyword exception external fun
156
157syn keyword ocamlKeyword in inherit initializer
158syn keyword ocamlKeyword land lazy let match
159syn keyword ocamlKeyword method mutable new of
160syn keyword ocamlKeyword parser private raise rec
161syn keyword ocamlKeyword try type
162syn keyword ocamlKeyword val virtual when while with
163
164if exists("ocaml_revised")
165 syn keyword ocamlKeyword do value
166 syn keyword ocamlBoolean True False
167else
168 syn keyword ocamlKeyword function
169 syn keyword ocamlBoolean true false
170 syn match ocamlKeyChar "!"
171endif
172
Bram Moolenaar202795b2005-10-11 20:29:39 +0000173syn keyword ocamlType array bool char exn float format format4
174syn keyword ocamlType int int32 int64 lazy_t list nativeint option
175syn keyword ocamlType string unit
Bram Moolenaar071d4272004-06-13 20:20:40 +0000176
177syn keyword ocamlOperator asr lor lsl lsr lxor mod not
178
179syn match ocamlConstructor "(\s*)"
180syn match ocamlConstructor "\[\s*\]"
181syn match ocamlConstructor "\[|\s*>|]"
182syn match ocamlConstructor "\[<\s*>\]"
183syn match ocamlConstructor "\u\(\w\|'\)*\>"
184
185" Polymorphic variants
186syn match ocamlConstructor "`\w\(\w\|'\)*\>"
187
188" Module prefix
189syn match ocamlModPath "\u\(\w\|'\)*\."he=e-1
190
191syn match ocamlCharacter "'\\\d\d\d'\|'\\[\'ntbr]'\|'.'"
192syn match ocamlCharErr "'\\\d\d'\|'\\\d'"
193syn match ocamlCharErr "'\\[^\'ntbr]'"
194syn region ocamlString start=+"+ skip=+\\\\\|\\"+ end=+"+
195
196syn match ocamlFunDef "->"
197syn match ocamlRefAssign ":="
198syn match ocamlTopStop ";;"
199syn match ocamlOperator "\^"
200syn match ocamlOperator "::"
201
202syn match ocamlOperator "&&"
203syn match ocamlOperator "<"
204syn match ocamlOperator ">"
205syn match ocamlAnyVar "\<_\>"
206syn match ocamlKeyChar "|[^\]]"me=e-1
207syn match ocamlKeyChar ";"
208syn match ocamlKeyChar "\~"
209syn match ocamlKeyChar "?"
210syn match ocamlKeyChar "\*"
211syn match ocamlKeyChar "="
212
213if exists("ocaml_revised")
Bram Moolenaar202795b2005-10-11 20:29:39 +0000214 syn match ocamlErr "<-"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000215else
Bram Moolenaar202795b2005-10-11 20:29:39 +0000216 syn match ocamlOperator "<-"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000217endif
218
Bram Moolenaar9964e462007-05-05 17:54:07 +0000219syn match ocamlNumber "\<-\=\d\(_\|\d\)*[l|L|n]\?\>"
220syn match ocamlNumber "\<-\=0[x|X]\(\x\|_\)\+[l|L|n]\?\>"
221syn match ocamlNumber "\<-\=0[o|O]\(\o\|_\)\+[l|L|n]\?\>"
222syn match ocamlNumber "\<-\=0[b|B]\([01]\|_\)\+[l|L|n]\?\>"
223syn match ocamlFloat "\<-\=\d\(_\|\d\)*\.\(_\|\d\)*\([eE][-+]\=\d\(_\|\d\)*\)\=\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000224
225" Labels
Bram Moolenaar202795b2005-10-11 20:29:39 +0000226syn match ocamlLabel "\~\(\l\|_\)\(\w\|'\)*"lc=1
227syn match ocamlLabel "?\(\l\|_\)\(\w\|'\)*"lc=1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000228syn region ocamlLabel transparent matchgroup=ocamlLabel start="?(\(\l\|_\)\(\w\|'\)*"lc=2 end=")"me=e-1 contains=ALLBUT,@ocamlContained,ocamlParenErr
229
230
231" Synchronization
232syn sync minlines=50
233syn sync maxlines=500
234
235if !exists("ocaml_revised")
236 syn sync match ocamlDoSync grouphere ocamlDo "\<do\>"
237 syn sync match ocamlDoSync groupthere ocamlDo "\<done\>"
238endif
239
240if exists("ocaml_revised")
241 syn sync match ocamlEndSync grouphere ocamlEnd "\<\(object\)\>"
242else
243 syn sync match ocamlEndSync grouphere ocamlEnd "\<\(begin\|object\)\>"
244endif
245
246syn sync match ocamlEndSync groupthere ocamlEnd "\<end\>"
247syn sync match ocamlStructSync grouphere ocamlStruct "\<struct\>"
248syn sync match ocamlStructSync groupthere ocamlStruct "\<end\>"
249syn sync match ocamlSigSync grouphere ocamlSig "\<sig\>"
250syn sync match ocamlSigSync groupthere ocamlSig "\<end\>"
251
252" Define the default highlighting.
253" For version 5.7 and earlier: only when not done already
254" For version 5.8 and later: only when an item doesn't have highlighting yet
255if version >= 508 || !exists("did_ocaml_syntax_inits")
256 if version < 508
257 let did_ocaml_syntax_inits = 1
258 command -nargs=+ HiLink hi link <args>
259 else
260 command -nargs=+ HiLink hi def link <args>
261 endif
262
263 HiLink ocamlBraceErr Error
264 HiLink ocamlBrackErr Error
265 HiLink ocamlParenErr Error
266 HiLink ocamlArrErr Error
267
268 HiLink ocamlCommentErr Error
269
270 HiLink ocamlCountErr Error
271 HiLink ocamlDoErr Error
272 HiLink ocamlDoneErr Error
273 HiLink ocamlEndErr Error
274 HiLink ocamlThenErr Error
275
276 HiLink ocamlCharErr Error
277
278 HiLink ocamlErr Error
279
280 HiLink ocamlComment Comment
281
282 HiLink ocamlModPath Include
Bram Moolenaar202795b2005-10-11 20:29:39 +0000283 HiLink ocamlObject Include
Bram Moolenaar071d4272004-06-13 20:20:40 +0000284 HiLink ocamlModule Include
285 HiLink ocamlModParam1 Include
286 HiLink ocamlModType Include
287 HiLink ocamlMPRestr3 Include
288 HiLink ocamlFullMod Include
289 HiLink ocamlModTypeRestr Include
290 HiLink ocamlWith Include
291 HiLink ocamlMTDef Include
292
293 HiLink ocamlScript Include
294
295 HiLink ocamlConstructor Constant
296
297 HiLink ocamlModPreRHS Keyword
298 HiLink ocamlMPRestr2 Keyword
299 HiLink ocamlKeyword Keyword
Bram Moolenaar9964e462007-05-05 17:54:07 +0000300 HiLink ocamlMethod Include
Bram Moolenaar071d4272004-06-13 20:20:40 +0000301 HiLink ocamlFunDef Keyword
302 HiLink ocamlRefAssign Keyword
303 HiLink ocamlKeyChar Keyword
304 HiLink ocamlAnyVar Keyword
305 HiLink ocamlTopStop Keyword
306 HiLink ocamlOperator Keyword
307
308 HiLink ocamlBoolean Boolean
309 HiLink ocamlCharacter Character
310 HiLink ocamlNumber Number
311 HiLink ocamlFloat Float
312 HiLink ocamlString String
313
314 HiLink ocamlLabel Identifier
315
316 HiLink ocamlType Type
317
318 HiLink ocamlTodo Todo
319
320 HiLink ocamlEncl Keyword
321
322 delcommand HiLink
323endif
324
325let b:current_syntax = "ocaml"
326
327" vim: ts=8