comparison runtime/syntax/ocaml.vim @ 0:76efa0be13f1

Initial revision
author atsuki
date Sat, 10 Nov 2007 15:07:22 +0900
parents
children 67300faee616
comparison
equal deleted inserted replaced
-1:000000000000 0:76efa0be13f1
1 " Vim syntax file
2 " Language: OCaml
3 " Filenames: *.ml *.mli *.mll *.mly
4 " Maintainers: Markus Mottl <markus.mottl@gmail.com>
5 " Karl-Heinz Sylla <Karl-Heinz.Sylla@gmd.de>
6 " Issac Trotts <ijtrotts@ucdavis.edu>
7 " URL: http://www.ocaml.info/vim/syntax/ocaml.vim
8 " 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)
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)
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
20 elseif exists("b:current_syntax") && b:current_syntax == "ocaml"
21 finish
22 endif
23
24 " OCaml is case sensitive.
25 syn case match
26
27 " Script headers highlighted like comments
28 syn match ocamlComment "^#!.*"
29
30 " Scripting directives
31 syn match ocamlScript "^#\<\(quit\|labels\|warnings\|directory\|cd\|load\|use\|install_printer\|remove_printer\|require\|thread\|trace\|untrace\|untrace_all\|print_depth\|print_length\)\>"
32
33 " Script headers highlighted like comments
34 syn match ocamlComment "^#!.*"
35
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
72 syn 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
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
83 syn region ocamlComment start="(\*" end="\*)" contains=ocamlComment,ocamlTodo
84 syn keyword ocamlTodo contained TODO FIXME XXX NOTE
85
86
87 " Objects
88 syn region ocamlEnd matchgroup=ocamlObject start="\<object\>" matchgroup=ocamlObject end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr
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 " "struct"
113 syn region ocamlStruct matchgroup=ocamlModule start="\<struct\>" matchgroup=ocamlModule end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr
114
115 " "sig"
116 syn region ocamlSig matchgroup=ocamlModule start="\<sig\>" matchgroup=ocamlModule end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr,ocamlModule
117 syn region ocamlModSpec matchgroup=ocamlKeyword start="\<module\>" matchgroup=ocamlModule end="\<\u\(\w\|'\)*\>" contained contains=@ocamlAllErrs,ocamlComment skipwhite skipempty nextgroup=ocamlModTRWith,ocamlMPRestr
118
119 " "open"
120 syn region ocamlNone matchgroup=ocamlKeyword start="\<open\>" matchgroup=ocamlModule end="\<\u\(\w\|'\)*\(\.\u\(\w\|'\)*\)*\>" contains=@ocamlAllErrs,ocamlComment
121
122 " "include"
123 syn match ocamlKeyword "\<include\>" skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod
124
125 " "module" - somewhat complicated stuff ;-)
126 syn region ocamlModule matchgroup=ocamlKeyword start="\<module\>" matchgroup=ocamlModule end="\<\u\(\w\|'\)*\>" contains=@ocamlAllErrs,ocamlComment skipwhite skipempty nextgroup=ocamlPreDef
127 syn region ocamlPreDef start="."me=e-1 matchgroup=ocamlKeyword end="\l\|="me=e-1 contained contains=@ocamlAllErrs,ocamlComment,ocamlModParam,ocamlModTypeRestr,ocamlModTRWith nextgroup=ocamlModPreRHS
128 syn region ocamlModParam start="([^*]" end=")" contained contains=@ocamlAENoParen,ocamlModParam1
129 syn match ocamlModParam1 "\<\u\(\w\|'\)*\>" contained skipwhite skipempty nextgroup=ocamlPreMPRestr
130
131 syn region ocamlPreMPRestr start="."me=e-1 end=")"me=e-1 contained contains=@ocamlAllErrs,ocamlComment,ocamlMPRestr,ocamlModTypeRestr
132
133 syn region ocamlMPRestr start=":" end="."me=e-1 contained contains=@ocamlComment skipwhite skipempty nextgroup=ocamlMPRestr1,ocamlMPRestr2,ocamlMPRestr3
134 syn region ocamlMPRestr1 matchgroup=ocamlModule start="\ssig\s\=" matchgroup=ocamlModule end="\<end\>" contained contains=ALLBUT,@ocamlContained,ocamlEndErr,ocamlModule
135 syn region ocamlMPRestr2 start="\sfunctor\(\s\|(\)\="me=e-1 matchgroup=ocamlKeyword end="->" contained contains=@ocamlAllErrs,ocamlComment,ocamlModParam skipwhite skipempty nextgroup=ocamlFuncWith,ocamlMPRestr2
136 syn match ocamlMPRestr3 "\w\(\w\|'\)*\(\.\w\(\w\|'\)*\)*" contained
137 syn match ocamlModPreRHS "=" contained skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod
138 syn region ocamlModRHS start="." end=".\w\|([^*]"me=e-2 contained contains=ocamlComment skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod
139 syn match ocamlFullMod "\<\u\(\w\|'\)*\(\.\u\(\w\|'\)*\)*" contained skipwhite skipempty nextgroup=ocamlFuncWith
140
141 syn region ocamlFuncWith start="([^*]"me=e-1 end=")" contained contains=ocamlComment,ocamlWith,ocamlFuncStruct skipwhite skipempty nextgroup=ocamlFuncWith
142 syn region ocamlFuncStruct matchgroup=ocamlModule start="[^a-zA-Z]struct\>"hs=s+1 matchgroup=ocamlModule end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr
143
144 syn match ocamlModTypeRestr "\<\w\(\w\|'\)*\(\.\w\(\w\|'\)*\)*\>" contained
145 syn region ocamlModTRWith start=":\s*("hs=s+1 end=")" contained contains=@ocamlAENoParen,ocamlWith
146 syn match ocamlWith "\<\(\u\(\w\|'\)*\.\)*\w\(\w\|'\)*\>" contained skipwhite skipempty nextgroup=ocamlWithRest
147 syn region ocamlWithRest start="[^)]" end=")"me=e-1 contained contains=ALLBUT,@ocamlContained
148
149 " "module type"
150 syn region ocamlKeyword start="\<module\>\s*\<type\>" matchgroup=ocamlModule end="\<\w\(\w\|'\)*\>" contains=ocamlComment skipwhite skipempty nextgroup=ocamlMTDef
151 syn match ocamlMTDef "=\s*\w\(\w\|'\)*\>"hs=s+1,me=s
152
153 syn keyword ocamlKeyword and as assert class
154 syn keyword ocamlKeyword constraint else
155 syn keyword ocamlKeyword exception external fun
156
157 syn keyword ocamlKeyword in inherit initializer
158 syn keyword ocamlKeyword land lazy let match
159 syn keyword ocamlKeyword method mutable new of
160 syn keyword ocamlKeyword parser private raise rec
161 syn keyword ocamlKeyword try type
162 syn keyword ocamlKeyword val virtual when while with
163
164 if exists("ocaml_revised")
165 syn keyword ocamlKeyword do value
166 syn keyword ocamlBoolean True False
167 else
168 syn keyword ocamlKeyword function
169 syn keyword ocamlBoolean true false
170 syn match ocamlKeyChar "!"
171 endif
172
173 syn keyword ocamlType array bool char exn float format format4
174 syn keyword ocamlType int int32 int64 lazy_t list nativeint option
175 syn keyword ocamlType string unit
176
177 syn keyword ocamlOperator asr lor lsl lsr lxor mod not
178
179 syn match ocamlConstructor "(\s*)"
180 syn match ocamlConstructor "\[\s*\]"
181 syn match ocamlConstructor "\[|\s*>|]"
182 syn match ocamlConstructor "\[<\s*>\]"
183 syn match ocamlConstructor "\u\(\w\|'\)*\>"
184
185 " Polymorphic variants
186 syn match ocamlConstructor "`\w\(\w\|'\)*\>"
187
188 " Module prefix
189 syn match ocamlModPath "\u\(\w\|'\)*\."he=e-1
190
191 syn match ocamlCharacter "'\\\d\d\d'\|'\\[\'ntbr]'\|'.'"
192 syn match ocamlCharErr "'\\\d\d'\|'\\\d'"
193 syn match ocamlCharErr "'\\[^\'ntbr]'"
194 syn region ocamlString start=+"+ skip=+\\\\\|\\"+ end=+"+
195
196 syn match ocamlFunDef "->"
197 syn match ocamlRefAssign ":="
198 syn match ocamlTopStop ";;"
199 syn match ocamlOperator "\^"
200 syn match ocamlOperator "::"
201
202 syn match ocamlOperator "&&"
203 syn match ocamlOperator "<"
204 syn match ocamlOperator ">"
205 syn match ocamlAnyVar "\<_\>"
206 syn match ocamlKeyChar "|[^\]]"me=e-1
207 syn match ocamlKeyChar ";"
208 syn match ocamlKeyChar "\~"
209 syn match ocamlKeyChar "?"
210 syn match ocamlKeyChar "\*"
211 syn match ocamlKeyChar "="
212
213 if exists("ocaml_revised")
214 syn match ocamlErr "<-"
215 else
216 syn match ocamlOperator "<-"
217 endif
218
219 syn match ocamlNumber "\<-\=\d\(_\|\d\)*[l|L|n]\?\>"
220 syn match ocamlNumber "\<-\=0[x|X]\(\x\|_\)\+[l|L|n]\?\>"
221 syn match ocamlNumber "\<-\=0[o|O]\(\o\|_\)\+[l|L|n]\?\>"
222 syn match ocamlNumber "\<-\=0[b|B]\([01]\|_\)\+[l|L|n]\?\>"
223 syn match ocamlFloat "\<-\=\d\(_\|\d\)*\.\(_\|\d\)*\([eE][-+]\=\d\(_\|\d\)*\)\=\>"
224
225 " Labels
226 syn match ocamlLabel "\~\(\l\|_\)\(\w\|'\)*"lc=1
227 syn match ocamlLabel "?\(\l\|_\)\(\w\|'\)*"lc=1
228 syn region ocamlLabel transparent matchgroup=ocamlLabel start="?(\(\l\|_\)\(\w\|'\)*"lc=2 end=")"me=e-1 contains=ALLBUT,@ocamlContained,ocamlParenErr
229
230
231 " Synchronization
232 syn sync minlines=50
233 syn sync maxlines=500
234
235 if !exists("ocaml_revised")
236 syn sync match ocamlDoSync grouphere ocamlDo "\<do\>"
237 syn sync match ocamlDoSync groupthere ocamlDo "\<done\>"
238 endif
239
240 if exists("ocaml_revised")
241 syn sync match ocamlEndSync grouphere ocamlEnd "\<\(object\)\>"
242 else
243 syn sync match ocamlEndSync grouphere ocamlEnd "\<\(begin\|object\)\>"
244 endif
245
246 syn sync match ocamlEndSync groupthere ocamlEnd "\<end\>"
247 syn sync match ocamlStructSync grouphere ocamlStruct "\<struct\>"
248 syn sync match ocamlStructSync groupthere ocamlStruct "\<end\>"
249 syn sync match ocamlSigSync grouphere ocamlSig "\<sig\>"
250 syn 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
255 if 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
283 HiLink ocamlObject Include
284 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
300 HiLink ocamlMethod Include
301 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
323 endif
324
325 let b:current_syntax = "ocaml"
326
327 " vim: ts=8