blob: 53ff12a8593ee5e43929b3120821d5fd07c6eb14 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim syntax file
2" Language: SML
3" Filenames: *.sml *.sig
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00004" Maintainers: Markus Mottl <markus.mottl@gmail.com>
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00005" Fabrizio Zeno Cornelli <zeno@filibusta.crema.unimi.it>
Bram Moolenaar6e649222021-10-04 21:32:54 +01006" Last Change: 2021 Oct 04
Bram Moolenaar7e6a5152021-01-02 16:39:53 +01007" 2015 Aug 31 - Fixed opening of modules (Ramana Kumar)
8" 2006 Oct 23 - Fixed character highlighting bug (MM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009
Bram Moolenaar89bcfda2016-08-30 23:26:57 +020010" quit when a syntax file was already loaded
11if exists("b:current_syntax")
Bram Moolenaar6e649222021-10-04 21:32:54 +010012 finish
13endif
Bram Moolenaar7e6a5152021-01-02 16:39:53 +010014
15" Disable spell checking of syntax.
16syn spell notoplevel
17
Bram Moolenaar071d4272004-06-13 20:20:40 +000018" SML is case sensitive.
19syn case match
20
21" lowercase identifier - the standard way to match
22syn match smlLCIdentifier /\<\(\l\|_\)\(\w\|'\)*\>/
23
24syn match smlKeyChar "|"
25
26" Errors
27syn match smlBraceErr "}"
28syn match smlBrackErr "\]"
29syn match smlParenErr ")"
30syn match smlCommentErr "\*)"
31syn match smlThenErr "\<then\>"
32
33" Error-highlighting of "end" without synchronization:
34" as keyword or as error (default)
35if exists("sml_noend_error")
36 syn match smlKeyword "\<end\>"
37else
38 syn match smlEndErr "\<end\>"
39endif
40
41" Some convenient clusters
42syn cluster smlAllErrs contains=smlBraceErr,smlBrackErr,smlParenErr,smlCommentErr,smlEndErr,smlThenErr
43
44syn cluster smlAENoParen contains=smlBraceErr,smlBrackErr,smlCommentErr,smlEndErr,smlThenErr
45
46syn cluster smlContained contains=smlTodo,smlPreDef,smlModParam,smlModParam1,smlPreMPRestr,smlMPRestr,smlMPRestr1,smlMPRestr2,smlMPRestr3,smlModRHS,smlFuncWith,smlFuncStruct,smlModTypeRestr,smlModTRWith,smlWith,smlWithRest,smlModType,smlFullMod
47
48
49" Enclosing delimiters
50syn region smlEncl transparent matchgroup=smlKeyword start="(" matchgroup=smlKeyword end=")" contains=ALLBUT,@smlContained,smlParenErr
51syn region smlEncl transparent matchgroup=smlKeyword start="{" matchgroup=smlKeyword end="}" contains=ALLBUT,@smlContained,smlBraceErr
52syn region smlEncl transparent matchgroup=smlKeyword start="\[" matchgroup=smlKeyword end="\]" contains=ALLBUT,@smlContained,smlBrackErr
53syn region smlEncl transparent matchgroup=smlKeyword start="#\[" matchgroup=smlKeyword end="\]" contains=ALLBUT,@smlContained,smlBrackErr
54
55
56" Comments
Bram Moolenaar7e6a5152021-01-02 16:39:53 +010057syn region smlComment start="(\*" end="\*)" contains=smlComment,smlTodo,@Spell
Bram Moolenaar071d4272004-06-13 20:20:40 +000058syn keyword smlTodo contained TODO FIXME XXX
59
60
61" let
62syn region smlEnd matchgroup=smlKeyword start="\<let\>" matchgroup=smlKeyword end="\<end\>" contains=ALLBUT,@smlContained,smlEndErr
63
64" local
65syn region smlEnd matchgroup=smlKeyword start="\<local\>" matchgroup=smlKeyword end="\<end\>" contains=ALLBUT,@smlContained,smlEndErr
66
67" abstype
68syn region smlNone matchgroup=smlKeyword start="\<abstype\>" matchgroup=smlKeyword end="\<end\>" contains=ALLBUT,@smlContained,smlEndErr
69
70" begin
71syn region smlEnd matchgroup=smlKeyword start="\<begin\>" matchgroup=smlKeyword end="\<end\>" contains=ALLBUT,@smlContained,smlEndErr
72
73" if
74syn region smlNone matchgroup=smlKeyword start="\<if\>" matchgroup=smlKeyword end="\<then\>" contains=ALLBUT,@smlContained,smlThenErr
75
76
77"" Modules
78
79" "struct"
80syn region smlStruct matchgroup=smlModule start="\<struct\>" matchgroup=smlModule end="\<end\>" contains=ALLBUT,@smlContained,smlEndErr
81
82" "sig"
83syn region smlSig matchgroup=smlModule start="\<sig\>" matchgroup=smlModule end="\<end\>" contains=ALLBUT,@smlContained,smlEndErr,smlModule
84syn region smlModSpec matchgroup=smlKeyword start="\<structure\>" matchgroup=smlModule end="\<\u\(\w\|'\)*\>" contained contains=@smlAllErrs,smlComment skipwhite skipempty nextgroup=smlModTRWith,smlMPRestr
85
86" "open"
Bram Moolenaar7e6a5152021-01-02 16:39:53 +010087syn region smlNone matchgroup=smlKeyword start="\<open\>" matchgroup=smlModule end="\<\w\(\w\|'\)*\(\.\w\(\w\|'\)*\)*\>" contains=@smlAllErrs,smlComment
Bram Moolenaar071d4272004-06-13 20:20:40 +000088
89" "structure" - somewhat complicated stuff ;-)
90syn region smlModule matchgroup=smlKeyword start="\<\(structure\|functor\)\>" matchgroup=smlModule end="\<\u\(\w\|'\)*\>" contains=@smlAllErrs,smlComment skipwhite skipempty nextgroup=smlPreDef
91syn region smlPreDef start="."me=e-1 matchgroup=smlKeyword end="\l\|="me=e-1 contained contains=@smlAllErrs,smlComment,smlModParam,smlModTypeRestr,smlModTRWith nextgroup=smlModPreRHS
92syn region smlModParam start="([^*]" end=")" contained contains=@smlAENoParen,smlModParam1
93syn match smlModParam1 "\<\u\(\w\|'\)*\>" contained skipwhite skipempty nextgroup=smlPreMPRestr
94
95syn region smlPreMPRestr start="."me=e-1 end=")"me=e-1 contained contains=@smlAllErrs,smlComment,smlMPRestr,smlModTypeRestr
96
97syn region smlMPRestr start=":" end="."me=e-1 contained contains=@smlComment skipwhite skipempty nextgroup=smlMPRestr1,smlMPRestr2,smlMPRestr3
98syn region smlMPRestr1 matchgroup=smlModule start="\ssig\s\=" matchgroup=smlModule end="\<end\>" contained contains=ALLBUT,@smlContained,smlEndErr,smlModule
99syn region smlMPRestr2 start="\sfunctor\(\s\|(\)\="me=e-1 matchgroup=smlKeyword end="->" contained contains=@smlAllErrs,smlComment,smlModParam skipwhite skipempty nextgroup=smlFuncWith
100syn match smlMPRestr3 "\w\(\w\|'\)*\(\.\w\(\w\|'\)*\)*" contained
101syn match smlModPreRHS "=" contained skipwhite skipempty nextgroup=smlModParam,smlFullMod
102syn region smlModRHS start="." end=".\w\|([^*]"me=e-2 contained contains=smlComment skipwhite skipempty nextgroup=smlModParam,smlFullMod
103syn match smlFullMod "\<\u\(\w\|'\)*\(\.\u\(\w\|'\)*\)*" contained skipwhite skipempty nextgroup=smlFuncWith
104
105syn region smlFuncWith start="([^*]"me=e-1 end=")" contained contains=smlComment,smlWith,smlFuncStruct
106syn region smlFuncStruct matchgroup=smlModule start="[^a-zA-Z]struct\>"hs=s+1 matchgroup=smlModule end="\<end\>" contains=ALLBUT,@smlContained,smlEndErr
107
108syn match smlModTypeRestr "\<\w\(\w\|'\)*\(\.\w\(\w\|'\)*\)*\>" contained
109syn region smlModTRWith start=":\s*("hs=s+1 end=")" contained contains=@smlAENoParen,smlWith
110syn match smlWith "\<\(\u\(\w\|'\)*\.\)*\w\(\w\|'\)*\>" contained skipwhite skipempty nextgroup=smlWithRest
111syn region smlWithRest start="[^)]" end=")"me=e-1 contained contains=ALLBUT,@smlContained
112
113" "signature"
114syn region smlKeyword start="\<signature\>" matchgroup=smlModule end="\<\w\(\w\|'\)*\>" contains=smlComment skipwhite skipempty nextgroup=smlMTDef
115syn match smlMTDef "=\s*\w\(\w\|'\)*\>"hs=s+1,me=s
116
117syn keyword smlKeyword and andalso case
118syn keyword smlKeyword datatype else eqtype
119syn keyword smlKeyword exception fn fun handle
120syn keyword smlKeyword in infix infixl infixr
121syn keyword smlKeyword match nonfix of orelse
122syn keyword smlKeyword raise handle type
123syn keyword smlKeyword val where while with withtype
124
125syn keyword smlType bool char exn int list option
126syn keyword smlType real string unit
127
128syn keyword smlOperator div mod not or quot rem
129
130syn keyword smlBoolean true false
131syn match smlConstructor "(\s*)"
132syn match smlConstructor "\[\s*\]"
133syn match smlConstructor "#\[\s*\]"
134syn match smlConstructor "\u\(\w\|'\)*\>"
135
136" Module prefix
137syn match smlModPath "\u\(\w\|'\)*\."he=e-1
138
Bram Moolenaard5ab34b2007-05-05 17:15:44 +0000139syn match smlCharacter +#"\\""\|#"."\|#"\\\d\d\d"+
Bram Moolenaar071d4272004-06-13 20:20:40 +0000140syn match smlCharErr +#"\\\d\d"\|#"\\\d"+
Bram Moolenaar7e6a5152021-01-02 16:39:53 +0100141syn region smlString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@Spell
Bram Moolenaar071d4272004-06-13 20:20:40 +0000142
143syn match smlFunDef "=>"
144syn match smlRefAssign ":="
145syn match smlTopStop ";;"
146syn match smlOperator "\^"
147syn match smlOperator "::"
148syn match smlAnyVar "\<_\>"
149syn match smlKeyChar "!"
150syn match smlKeyChar ";"
151syn match smlKeyChar "\*"
152syn match smlKeyChar "="
153
Bram Moolenaar7e6a5152021-01-02 16:39:53 +0100154syn match smlNumber "\<-\=\d\+\>"
155syn match smlNumber "\<-\=0[x|X]\x\+\>"
156syn match smlReal "\<-\=\d\+\.\d*\([eE][-+]\=\d\+\)\=[fl]\=\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000157
158" Synchronization
159syn sync minlines=20
160syn sync maxlines=500
161
162syn sync match smlEndSync grouphere smlEnd "\<begin\>"
163syn sync match smlEndSync groupthere smlEnd "\<end\>"
164syn sync match smlStructSync grouphere smlStruct "\<struct\>"
165syn sync match smlStructSync groupthere smlStruct "\<end\>"
166syn sync match smlSigSync grouphere smlSig "\<sig\>"
167syn sync match smlSigSync groupthere smlSig "\<end\>"
168
169" Define the default highlighting.
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200170" Only when an item doesn't have highlighting yet
Bram Moolenaar071d4272004-06-13 20:20:40 +0000171
Bram Moolenaar7e6a5152021-01-02 16:39:53 +0100172hi def link smlBraceErr Error
173hi def link smlBrackErr Error
174hi def link smlParenErr Error
Bram Moolenaar071d4272004-06-13 20:20:40 +0000175
Bram Moolenaar7e6a5152021-01-02 16:39:53 +0100176hi def link smlCommentErr Error
Bram Moolenaar071d4272004-06-13 20:20:40 +0000177
Bram Moolenaar7e6a5152021-01-02 16:39:53 +0100178hi def link smlEndErr Error
179hi def link smlThenErr Error
Bram Moolenaar071d4272004-06-13 20:20:40 +0000180
Bram Moolenaar7e6a5152021-01-02 16:39:53 +0100181hi def link smlCharErr Error
Bram Moolenaar071d4272004-06-13 20:20:40 +0000182
Bram Moolenaar7e6a5152021-01-02 16:39:53 +0100183hi def link smlComment Comment
Bram Moolenaar071d4272004-06-13 20:20:40 +0000184
Bram Moolenaar7e6a5152021-01-02 16:39:53 +0100185hi def link smlModPath Include
186hi def link smlModule Include
187hi def link smlModParam1 Include
188hi def link smlModType Include
189hi def link smlMPRestr3 Include
190hi def link smlFullMod Include
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200191hi def link smlModTypeRestr Include
Bram Moolenaar7e6a5152021-01-02 16:39:53 +0100192hi def link smlWith Include
193hi def link smlMTDef Include
Bram Moolenaar071d4272004-06-13 20:20:40 +0000194
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200195hi def link smlConstructor Constant
Bram Moolenaar071d4272004-06-13 20:20:40 +0000196
Bram Moolenaar7e6a5152021-01-02 16:39:53 +0100197hi def link smlModPreRHS Keyword
198hi def link smlMPRestr2 Keyword
199hi def link smlKeyword Keyword
200hi def link smlFunDef Keyword
201hi def link smlRefAssign Keyword
202hi def link smlKeyChar Keyword
203hi def link smlAnyVar Keyword
204hi def link smlTopStop Keyword
205hi def link smlOperator Keyword
Bram Moolenaar071d4272004-06-13 20:20:40 +0000206
Bram Moolenaar7e6a5152021-01-02 16:39:53 +0100207hi def link smlBoolean Boolean
208hi def link smlCharacter Character
209hi def link smlNumber Number
210hi def link smlReal Float
211hi def link smlString String
212hi def link smlType Type
213hi def link smlTodo Todo
214hi def link smlEncl Keyword
Bram Moolenaar071d4272004-06-13 20:20:40 +0000215
Bram Moolenaar071d4272004-06-13 20:20:40 +0000216
217let b:current_syntax = "sml"
218
219" vim: ts=8