3 " Filenames: *.sml *.sig
4 " Maintainers: Markus Mottl <markus.mottl@gmail.com>
5 " Fabrizio Zeno Cornelli <zeno@filibusta.crema.unimi.it>
6 " URL: http://www.ocaml.info/vim/syntax/sml.vim
7 " Last Change: 2006 Oct 23 - Fixed character highlighting bug (MM)
8 " 2002 Jun 02 - Fixed small typo (MM)
9 " 2001 Nov 20 - Fixed small highlighting bug with modules (MM)
11 " For version 5.x: Clear all syntax items
12 " For version 6.x: Quit when a syntax file was already loaded
15 elseif exists("b:current_syntax")
19 " SML is case sensitive.
22 " lowercase identifier - the standard way to match
23 syn match smlLCIdentifier /\<\(\l\|_\)\(\w\|'\)*\>/
25 syn match smlKeyChar "|"
28 syn match smlBraceErr "}"
29 syn match smlBrackErr "\]"
30 syn match smlParenErr ")"
31 syn match smlCommentErr "\*)"
32 syn match smlThenErr "\<then\>"
34 " Error-highlighting of "end" without synchronization:
35 " as keyword or as error (default)
36 if exists("sml_noend_error")
37 syn match smlKeyword "\<end\>"
39 syn match smlEndErr "\<end\>"
42 " Some convenient clusters
43 syn cluster smlAllErrs contains=smlBraceErr,smlBrackErr,smlParenErr,smlCommentErr,smlEndErr,smlThenErr
45 syn cluster smlAENoParen contains=smlBraceErr,smlBrackErr,smlCommentErr,smlEndErr,smlThenErr
47 syn cluster smlContained contains=smlTodo,smlPreDef,smlModParam,smlModParam1,smlPreMPRestr,smlMPRestr,smlMPRestr1,smlMPRestr2,smlMPRestr3,smlModRHS,smlFuncWith,smlFuncStruct,smlModTypeRestr,smlModTRWith,smlWith,smlWithRest,smlModType,smlFullMod
50 " Enclosing delimiters
51 syn region smlEncl transparent matchgroup=smlKeyword start="(" matchgroup=smlKeyword end=")" contains=ALLBUT,@smlContained,smlParenErr
52 syn region smlEncl transparent matchgroup=smlKeyword start="{" matchgroup=smlKeyword end="}" contains=ALLBUT,@smlContained,smlBraceErr
53 syn region smlEncl transparent matchgroup=smlKeyword start="\[" matchgroup=smlKeyword end="\]" contains=ALLBUT,@smlContained,smlBrackErr
54 syn region smlEncl transparent matchgroup=smlKeyword start="#\[" matchgroup=smlKeyword end="\]" contains=ALLBUT,@smlContained,smlBrackErr
58 syn region smlComment start="(\*" end="\*)" contains=smlComment,smlTodo
59 syn keyword smlTodo contained TODO FIXME XXX
63 syn region smlEnd matchgroup=smlKeyword start="\<let\>" matchgroup=smlKeyword end="\<end\>" contains=ALLBUT,@smlContained,smlEndErr
66 syn region smlEnd matchgroup=smlKeyword start="\<local\>" matchgroup=smlKeyword end="\<end\>" contains=ALLBUT,@smlContained,smlEndErr
69 syn region smlNone matchgroup=smlKeyword start="\<abstype\>" matchgroup=smlKeyword end="\<end\>" contains=ALLBUT,@smlContained,smlEndErr
72 syn region smlEnd matchgroup=smlKeyword start="\<begin\>" matchgroup=smlKeyword end="\<end\>" contains=ALLBUT,@smlContained,smlEndErr
75 syn region smlNone matchgroup=smlKeyword start="\<if\>" matchgroup=smlKeyword end="\<then\>" contains=ALLBUT,@smlContained,smlThenErr
81 syn region smlStruct matchgroup=smlModule start="\<struct\>" matchgroup=smlModule end="\<end\>" contains=ALLBUT,@smlContained,smlEndErr
84 syn region smlSig matchgroup=smlModule start="\<sig\>" matchgroup=smlModule end="\<end\>" contains=ALLBUT,@smlContained,smlEndErr,smlModule
85 syn region smlModSpec matchgroup=smlKeyword start="\<structure\>" matchgroup=smlModule end="\<\u\(\w\|'\)*\>" contained contains=@smlAllErrs,smlComment skipwhite skipempty nextgroup=smlModTRWith,smlMPRestr
88 syn region smlNone matchgroup=smlKeyword start="\<open\>" matchgroup=smlModule end="\<\u\(\w\|'\)*\(\.\u\(\w\|'\)*\)*\>" contains=@smlAllErrs,smlComment
90 " "structure" - somewhat complicated stuff ;-)
91 syn region smlModule matchgroup=smlKeyword start="\<\(structure\|functor\)\>" matchgroup=smlModule end="\<\u\(\w\|'\)*\>" contains=@smlAllErrs,smlComment skipwhite skipempty nextgroup=smlPreDef
92 syn region smlPreDef start="."me=e-1 matchgroup=smlKeyword end="\l\|="me=e-1 contained contains=@smlAllErrs,smlComment,smlModParam,smlModTypeRestr,smlModTRWith nextgroup=smlModPreRHS
93 syn region smlModParam start="([^*]" end=")" contained contains=@smlAENoParen,smlModParam1
94 syn match smlModParam1 "\<\u\(\w\|'\)*\>" contained skipwhite skipempty nextgroup=smlPreMPRestr
96 syn region smlPreMPRestr start="."me=e-1 end=")"me=e-1 contained contains=@smlAllErrs,smlComment,smlMPRestr,smlModTypeRestr
98 syn region smlMPRestr start=":" end="."me=e-1 contained contains=@smlComment skipwhite skipempty nextgroup=smlMPRestr1,smlMPRestr2,smlMPRestr3
99 syn region smlMPRestr1 matchgroup=smlModule start="\ssig\s\=" matchgroup=smlModule end="\<end\>" contained contains=ALLBUT,@smlContained,smlEndErr,smlModule
100 syn region smlMPRestr2 start="\sfunctor\(\s\|(\)\="me=e-1 matchgroup=smlKeyword end="->" contained contains=@smlAllErrs,smlComment,smlModParam skipwhite skipempty nextgroup=smlFuncWith
101 syn match smlMPRestr3 "\w\(\w\|'\)*\(\.\w\(\w\|'\)*\)*" contained
102 syn match smlModPreRHS "=" contained skipwhite skipempty nextgroup=smlModParam,smlFullMod
103 syn region smlModRHS start="." end=".\w\|([^*]"me=e-2 contained contains=smlComment skipwhite skipempty nextgroup=smlModParam,smlFullMod
104 syn match smlFullMod "\<\u\(\w\|'\)*\(\.\u\(\w\|'\)*\)*" contained skipwhite skipempty nextgroup=smlFuncWith
106 syn region smlFuncWith start="([^*]"me=e-1 end=")" contained contains=smlComment,smlWith,smlFuncStruct
107 syn region smlFuncStruct matchgroup=smlModule start="[^a-zA-Z]struct\>"hs=s+1 matchgroup=smlModule end="\<end\>" contains=ALLBUT,@smlContained,smlEndErr
109 syn match smlModTypeRestr "\<\w\(\w\|'\)*\(\.\w\(\w\|'\)*\)*\>" contained
110 syn region smlModTRWith start=":\s*("hs=s+1 end=")" contained contains=@smlAENoParen,smlWith
111 syn match smlWith "\<\(\u\(\w\|'\)*\.\)*\w\(\w\|'\)*\>" contained skipwhite skipempty nextgroup=smlWithRest
112 syn region smlWithRest start="[^)]" end=")"me=e-1 contained contains=ALLBUT,@smlContained
115 syn region smlKeyword start="\<signature\>" matchgroup=smlModule end="\<\w\(\w\|'\)*\>" contains=smlComment skipwhite skipempty nextgroup=smlMTDef
116 syn match smlMTDef "=\s*\w\(\w\|'\)*\>"hs=s+1,me=s
118 syn keyword smlKeyword and andalso case
119 syn keyword smlKeyword datatype else eqtype
120 syn keyword smlKeyword exception fn fun handle
121 syn keyword smlKeyword in infix infixl infixr
122 syn keyword smlKeyword match nonfix of orelse
123 syn keyword smlKeyword raise handle type
124 syn keyword smlKeyword val where while with withtype
126 syn keyword smlType bool char exn int list option
127 syn keyword smlType real string unit
129 syn keyword smlOperator div mod not or quot rem
131 syn keyword smlBoolean true false
132 syn match smlConstructor "(\s*)"
133 syn match smlConstructor "\[\s*\]"
134 syn match smlConstructor "#\[\s*\]"
135 syn match smlConstructor "\u\(\w\|'\)*\>"
138 syn match smlModPath "\u\(\w\|'\)*\."he=e-1
140 syn match smlCharacter +#"\\""\|#"."\|#"\\\d\d\d"+
141 syn match smlCharErr +#"\\\d\d"\|#"\\\d"+
142 syn region smlString start=+"+ skip=+\\\\\|\\"+ end=+"+
144 syn match smlFunDef "=>"
145 syn match smlRefAssign ":="
146 syn match smlTopStop ";;"
147 syn match smlOperator "\^"
148 syn match smlOperator "::"
149 syn match smlAnyVar "\<_\>"
150 syn match smlKeyChar "!"
151 syn match smlKeyChar ";"
152 syn match smlKeyChar "\*"
153 syn match smlKeyChar "="
155 syn match smlNumber "\<-\=\d\+\>"
156 syn match smlNumber "\<-\=0[x|X]\x\+\>"
157 syn match smlReal "\<-\=\d\+\.\d*\([eE][-+]\=\d\+\)\=[fl]\=\>"
161 syn sync maxlines=500
163 syn sync match smlEndSync grouphere smlEnd "\<begin\>"
164 syn sync match smlEndSync groupthere smlEnd "\<end\>"
165 syn sync match smlStructSync grouphere smlStruct "\<struct\>"
166 syn sync match smlStructSync groupthere smlStruct "\<end\>"
167 syn sync match smlSigSync grouphere smlSig "\<sig\>"
168 syn sync match smlSigSync groupthere smlSig "\<end\>"
170 " Define the default highlighting.
171 " For version 5.7 and earlier: only when not done already
172 " For version 5.8 and later: only when an item doesn't have highlighting yet
173 if version >= 508 || !exists("did_sml_syntax_inits")
175 let did_sml_syntax_inits = 1
176 command -nargs=+ HiLink hi link <args>
178 command -nargs=+ HiLink hi def link <args>
181 HiLink smlBraceErr Error
182 HiLink smlBrackErr Error
183 HiLink smlParenErr Error
185 HiLink smlCommentErr Error
187 HiLink smlEndErr Error
188 HiLink smlThenErr Error
190 HiLink smlCharErr Error
192 HiLink smlComment Comment
194 HiLink smlModPath Include
195 HiLink smlModule Include
196 HiLink smlModParam1 Include
197 HiLink smlModType Include
198 HiLink smlMPRestr3 Include
199 HiLink smlFullMod Include
200 HiLink smlModTypeRestr Include
201 HiLink smlWith Include
202 HiLink smlMTDef Include
204 HiLink smlConstructor Constant
206 HiLink smlModPreRHS Keyword
207 HiLink smlMPRestr2 Keyword
208 HiLink smlKeyword Keyword
209 HiLink smlFunDef Keyword
210 HiLink smlRefAssign Keyword
211 HiLink smlKeyChar Keyword
212 HiLink smlAnyVar Keyword
213 HiLink smlTopStop Keyword
214 HiLink smlOperator Keyword
216 HiLink smlBoolean Boolean
217 HiLink smlCharacter Character
218 HiLink smlNumber Number
220 HiLink smlString String
223 HiLink smlEncl Keyword
228 let b:current_syntax = "sml"