blob: 68c1feddae3292462bdc2ace709c2b73faebdee3 [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
Bram Moolenaar89bcfda2016-08-30 23:26:57 +020016" quit when a syntax file was already loaded
17if exists("b:current_syntax") && b:current_syntax == "ocaml"
Bram Moolenaar071d4272004-06-13 20:20:40 +000018 finish
19endif
20
21" OCaml is case sensitive.
22syn case match
23
Bram Moolenaar20f90cf2011-05-19 12:22:51 +020024" Access to the method of an object
25syn match ocamlMethod "#"
26
Bram Moolenaar071d4272004-06-13 20:20:40 +000027" Script headers highlighted like comments
Bram Moolenaar16ea3672013-07-28 16:02:18 +020028syn match ocamlComment "^#!.*" contains=@Spell
Bram Moolenaar071d4272004-06-13 20:20:40 +000029
30" Scripting directives
Bram Moolenaar20f90cf2011-05-19 12:22:51 +020031syn 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 +000032
Bram Moolenaar071d4272004-06-13 20:20:40 +000033" 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
Bram Moolenaar20f90cf2011-05-19 12:22:51 +020069syn 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 +000070
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
Bram Moolenaar16ea3672013-07-28 16:02:18 +020080syn region ocamlComment start="(\*" end="\*)" contains=@Spell,ocamlComment,ocamlTodo
Bram Moolenaar202795b2005-10-11 20:29:39 +000081syn keyword ocamlTodo contained TODO FIXME XXX NOTE
Bram Moolenaar071d4272004-06-13 20:20:40 +000082
83
84" Objects
Bram Moolenaar202795b2005-10-11 20:29:39 +000085syn region ocamlEnd matchgroup=ocamlObject start="\<object\>" matchgroup=ocamlObject end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr
Bram Moolenaar071d4272004-06-13 20:20:40 +000086
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
Bram Moolenaar071d4272004-06-13 20:20:40 +0000109" "sig"
110syn region ocamlSig matchgroup=ocamlModule start="\<sig\>" matchgroup=ocamlModule end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr,ocamlModule
111syn region ocamlModSpec matchgroup=ocamlKeyword start="\<module\>" matchgroup=ocamlModule end="\<\u\(\w\|'\)*\>" contained contains=@ocamlAllErrs,ocamlComment skipwhite skipempty nextgroup=ocamlModTRWith,ocamlMPRestr
112
113" "open"
Bram Moolenaar16ea3672013-07-28 16:02:18 +0200114syn region ocamlNone matchgroup=ocamlKeyword start="\<open\>" matchgroup=ocamlModule end="\<\u\(\w\|'\)*\( *\. *\u\(\w\|'\)*\)*\>" contains=@ocamlAllErrs,ocamlComment
Bram Moolenaar071d4272004-06-13 20:20:40 +0000115
116" "include"
Bram Moolenaar202795b2005-10-11 20:29:39 +0000117syn match ocamlKeyword "\<include\>" skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod
Bram Moolenaar071d4272004-06-13 20:20:40 +0000118
119" "module" - somewhat complicated stuff ;-)
120syn 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 +0200121syn region ocamlPreDef start="."me=e-1 matchgroup=ocamlKeyword end="\l\|=\|)"me=e-1 contained contains=@ocamlAllErrs,ocamlComment,ocamlModParam,ocamlModTypeRestr,ocamlModTRWith nextgroup=ocamlModPreRHS
122syn region ocamlModParam start="([^*]" end=")" contained contains=@ocamlAENoParen,ocamlModParam1,ocamlVal
Bram Moolenaar071d4272004-06-13 20:20:40 +0000123syn match ocamlModParam1 "\<\u\(\w\|'\)*\>" contained skipwhite skipempty nextgroup=ocamlPreMPRestr
124
125syn region ocamlPreMPRestr start="."me=e-1 end=")"me=e-1 contained contains=@ocamlAllErrs,ocamlComment,ocamlMPRestr,ocamlModTypeRestr
126
127syn region ocamlMPRestr start=":" end="."me=e-1 contained contains=@ocamlComment skipwhite skipempty nextgroup=ocamlMPRestr1,ocamlMPRestr2,ocamlMPRestr3
128syn region ocamlMPRestr1 matchgroup=ocamlModule start="\ssig\s\=" matchgroup=ocamlModule end="\<end\>" contained contains=ALLBUT,@ocamlContained,ocamlEndErr,ocamlModule
129syn 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 +0200130syn match ocamlMPRestr3 "\w\(\w\|'\)*\( *\. *\w\(\w\|'\)*\)*" contained
Bram Moolenaar071d4272004-06-13 20:20:40 +0000131syn match ocamlModPreRHS "=" contained skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod
Bram Moolenaar20f90cf2011-05-19 12:22:51 +0200132syn keyword ocamlKeyword val
Bram Moolenaar16ea3672013-07-28 16:02:18 +0200133syn region ocamlVal matchgroup=ocamlKeyword start="\<val\>" matchgroup=ocamlLCIdentifier end="\<\l\(\w\|'\)*\>" contains=@ocamlAllErrs,ocamlComment,ocamlFullMod skipwhite skipempty nextgroup=ocamlMPRestr
134syn region ocamlModRHS start="." end=". *\w\|([^*]"me=e-2 contained contains=ocamlComment skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod
135syn match ocamlFullMod "\<\u\(\w\|'\)*\( *\. *\u\(\w\|'\)*\)*" contained skipwhite skipempty nextgroup=ocamlFuncWith
Bram Moolenaar071d4272004-06-13 20:20:40 +0000136
137syn region ocamlFuncWith start="([^*]"me=e-1 end=")" contained contains=ocamlComment,ocamlWith,ocamlFuncStruct skipwhite skipempty nextgroup=ocamlFuncWith
138syn region ocamlFuncStruct matchgroup=ocamlModule start="[^a-zA-Z]struct\>"hs=s+1 matchgroup=ocamlModule end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr
139
Bram Moolenaar16ea3672013-07-28 16:02:18 +0200140syn match ocamlModTypeRestr "\<\w\(\w\|'\)*\( *\. *\w\(\w\|'\)*\)*\>" contained
Bram Moolenaar071d4272004-06-13 20:20:40 +0000141syn region ocamlModTRWith start=":\s*("hs=s+1 end=")" contained contains=@ocamlAENoParen,ocamlWith
Bram Moolenaar16ea3672013-07-28 16:02:18 +0200142syn match ocamlWith "\<\(\u\(\w\|'\)* *\. *\)*\w\(\w\|'\)*\>" contained skipwhite skipempty nextgroup=ocamlWithRest
Bram Moolenaar071d4272004-06-13 20:20:40 +0000143syn region ocamlWithRest start="[^)]" end=")"me=e-1 contained contains=ALLBUT,@ocamlContained
144
Bram Moolenaar20f90cf2011-05-19 12:22:51 +0200145" "struct"
146syn region ocamlStruct matchgroup=ocamlModule start="\<\(module\s\+\)\=struct\>" matchgroup=ocamlModule end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr
147
Bram Moolenaar071d4272004-06-13 20:20:40 +0000148" "module type"
Bram Moolenaar20f90cf2011-05-19 12:22:51 +0200149syn 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 +0200150syn match ocamlMTDef "=\s*\w\(\w\|'\)*\>"hs=s+1,me=s+1 skipwhite skipempty nextgroup=ocamlFullMod
Bram Moolenaar071d4272004-06-13 20:20:40 +0000151
152syn keyword ocamlKeyword and as assert class
153syn keyword ocamlKeyword constraint else
154syn keyword ocamlKeyword exception external fun
155
156syn keyword ocamlKeyword in inherit initializer
157syn keyword ocamlKeyword land lazy let match
158syn keyword ocamlKeyword method mutable new of
159syn keyword ocamlKeyword parser private raise rec
160syn keyword ocamlKeyword try type
Bram Moolenaar20f90cf2011-05-19 12:22:51 +0200161syn keyword ocamlKeyword virtual when while with
Bram Moolenaar071d4272004-06-13 20:20:40 +0000162
163if exists("ocaml_revised")
164 syn keyword ocamlKeyword do value
165 syn keyword ocamlBoolean True False
166else
167 syn keyword ocamlKeyword function
168 syn keyword ocamlBoolean true false
169 syn match ocamlKeyChar "!"
170endif
171
Bram Moolenaar202795b2005-10-11 20:29:39 +0000172syn keyword ocamlType array bool char exn float format format4
173syn keyword ocamlType int int32 int64 lazy_t list nativeint option
174syn keyword ocamlType string unit
Bram Moolenaar071d4272004-06-13 20:20:40 +0000175
Bram Moolenaar20f90cf2011-05-19 12:22:51 +0200176syn keyword ocamlOperator asr lnot lor lsl lsr lxor mod not
Bram Moolenaar071d4272004-06-13 20:20:40 +0000177
178syn match ocamlConstructor "(\s*)"
179syn match ocamlConstructor "\[\s*\]"
180syn match ocamlConstructor "\[|\s*>|]"
181syn match ocamlConstructor "\[<\s*>\]"
182syn match ocamlConstructor "\u\(\w\|'\)*\>"
183
184" Polymorphic variants
185syn match ocamlConstructor "`\w\(\w\|'\)*\>"
186
187" Module prefix
Bram Moolenaar16ea3672013-07-28 16:02:18 +0200188syn match ocamlModPath "\u\(\w\|'\)* *\."he=e-1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000189
190syn match ocamlCharacter "'\\\d\d\d'\|'\\[\'ntbr]'\|'.'"
Bram Moolenaar20f90cf2011-05-19 12:22:51 +0200191syn match ocamlCharacter "'\\x\x\x'"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000192syn match ocamlCharErr "'\\\d\d'\|'\\\d'"
193syn match ocamlCharErr "'\\[^\'ntbr]'"
Bram Moolenaar16ea3672013-07-28 16:02:18 +0200194syn region ocamlString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@Spell
Bram Moolenaar071d4272004-06-13 20:20:40 +0000195
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]\?\>"
Bram Moolenaar20f90cf2011-05-19 12:22:51 +0200223syn 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.
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200253" Only when an item doesn't have highlighting yet
Bram Moolenaar071d4272004-06-13 20:20:40 +0000254
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200255hi def link ocamlBraceErr Error
256hi def link ocamlBrackErr Error
257hi def link ocamlParenErr Error
258hi def link ocamlArrErr Error
Bram Moolenaar071d4272004-06-13 20:20:40 +0000259
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200260hi def link ocamlCommentErr Error
Bram Moolenaar071d4272004-06-13 20:20:40 +0000261
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200262hi def link ocamlCountErr Error
263hi def link ocamlDoErr Error
264hi def link ocamlDoneErr Error
265hi def link ocamlEndErr Error
266hi def link ocamlThenErr Error
Bram Moolenaar071d4272004-06-13 20:20:40 +0000267
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200268hi def link ocamlCharErr Error
Bram Moolenaar071d4272004-06-13 20:20:40 +0000269
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200270hi def link ocamlErr Error
Bram Moolenaar071d4272004-06-13 20:20:40 +0000271
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200272hi def link ocamlComment Comment
Bram Moolenaar071d4272004-06-13 20:20:40 +0000273
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200274hi def link ocamlModPath Include
275hi def link ocamlObject Include
276hi def link ocamlModule Include
277hi def link ocamlModParam1 Include
278hi def link ocamlModType Include
279hi def link ocamlMPRestr3 Include
280hi def link ocamlFullMod Include
281hi def link ocamlModTypeRestr Include
282hi def link ocamlWith Include
283hi def link ocamlMTDef Include
Bram Moolenaar071d4272004-06-13 20:20:40 +0000284
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200285hi def link ocamlScript Include
Bram Moolenaar071d4272004-06-13 20:20:40 +0000286
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200287hi def link ocamlConstructor Constant
Bram Moolenaar071d4272004-06-13 20:20:40 +0000288
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200289hi def link ocamlVal Keyword
290hi def link ocamlModPreRHS Keyword
291hi def link ocamlMPRestr2 Keyword
292hi def link ocamlKeyword Keyword
293hi def link ocamlMethod Include
294hi def link ocamlFunDef Keyword
295hi def link ocamlRefAssign Keyword
296hi def link ocamlKeyChar Keyword
297hi def link ocamlAnyVar Keyword
298hi def link ocamlTopStop Keyword
299hi def link ocamlOperator Keyword
Bram Moolenaar071d4272004-06-13 20:20:40 +0000300
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200301hi def link ocamlBoolean Boolean
302hi def link ocamlCharacter Character
303hi def link ocamlNumber Number
304hi def link ocamlFloat Float
305hi def link ocamlString String
Bram Moolenaar071d4272004-06-13 20:20:40 +0000306
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200307hi def link ocamlLabel Identifier
Bram Moolenaar071d4272004-06-13 20:20:40 +0000308
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200309hi def link ocamlType Type
Bram Moolenaar071d4272004-06-13 20:20:40 +0000310
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200311hi def link ocamlTodo Todo
Bram Moolenaar071d4272004-06-13 20:20:40 +0000312
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200313hi def link ocamlEncl Keyword
Bram Moolenaar071d4272004-06-13 20:20:40 +0000314
Bram Moolenaar071d4272004-06-13 20:20:40 +0000315
316let b:current_syntax = "ocaml"
317
318" vim: ts=8