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