3 " Filenames: *.sml *.sig
4 " Maintainers: Markus Mottl <mottl@miss.wu-wien.ac.at>
5 " Fabrizio Zeno Cornelli <zeno@filibusta.crema.unimi.it>
6 " URL: http://miss.wu-wien.ac.at/~mottl/vim/syntax/sml.vim
7 " Last Change: 2001 May 10
8 " 2000 Oct 01 - integrated Fabrizio's syntax file and
9 " cleaned up for distribution
10 " 2000 Feb 24 - structures and signatures improved
12 " For version 5.x: Clear all syntax items
13 " For version 6.x: Quit when a syntax file was already loaded
16 elseif exists("b:current_syntax")
20 " SML is case sensitive.
23 " lowercase identifier - the standard way to match
24 syn match smlLCIdentifier /\<\(\l\|_\)\(\w\|'\)*\>/
26 syn match smlKeyChar "|"
29 syn match smlBraceErr "}"
30 syn match smlBrackErr "\]"
31 syn match smlParenErr ")"
32 syn match smlCommentErr "\*)"
33 syn match smlThenErr "\<then\>"
35 " Error-highlighting of "end" without synchronization:
36 " as keyword or as error (default)
37 if exists("sml_noend_error")
38 syn match smlKeyword "\<end\>"
40 syn match smlEndErr "\<end\>"
43 " Some convenient clusters
44 syn cluster smlAllErrs contains=smlBraceErr,smlBrackErr,smlParenErr,smlCommentErr,smlEndErr,smlThenErr
46 syn cluster smlAENoParen contains=smlBraceErr,smlBrackErr,smlCommentErr,smlEndErr,smlThenErr
48 syn cluster smlContained contains=smlTodo,smlPreDef,smlModParam,smlModParam1,smlPreMPRestr,smlMPRestr,smlMPRestr1,smlMPRestr2,smlMPRestr3,smlModRHS,smlFuncWith,smlFuncStruct,smlModTypeRestr,smlModTRWith,smlWith,smlWithRest,smlModType,smlFullMod
51 " Enclosing delimiters
52 syn region smlEncl transparent matchgroup=smlKeyword start="(" matchgroup=smlKeyword end=")" contains=ALLBUT,@smlContained,smlParenErr
53 syn region smlEncl transparent matchgroup=smlKeyword start="{" matchgroup=smlKeyword end="}" contains=ALLBUT,@smlContained,smlBraceErr
54 syn region smlEncl transparent matchgroup=smlKeyword start="\[" matchgroup=smlKeyword end="\]" contains=ALLBUT,@smlContained,smlBrackErr
55 syn region smlEncl transparent matchgroup=smlKeyword start="#\[" matchgroup=smlKeyword end="\]" contains=ALLBUT,@smlContained,smlBrackErr
59 syn region smlComment start="(\*" end="\*)" contains=smlComment,smlTodo
60 syn keyword smlTodo contained TODO FIXME XXX
64 syn region smlEnd matchgroup=smlKeyword start="\<let\>" matchgroup=smlKeyword end="\<end\>" contains=ALLBUT,@smlContained,smlEndErr
68 syn region smlEnd matchgroup=smlKeyword start="\<local\>" 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 abstype 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 infixl
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"