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