xref: /vim-8.2.3635/runtime/syntax/sml.vim (revision 56994d21)
1" Vim syntax file
2" Language:     SML
3" Filenames:    *.sml *.sig
4" Maintainers:  Markus Mottl            <[email protected]>
5"               Fabrizio Zeno Cornelli  <[email protected]>
6" Last Change:  2019 Oct 01 - Only spell check strings & comments (Chuan Wei Foo)
7"               2015 Aug 31 - Fixed opening of modules (Ramana Kumar)
8"               2006 Oct 23 - Fixed character highlighting bug (MM)
9
10" quit when a syntax file was already loaded
11if exists("b:current_syntax")
12
13" Disable spell checking of syntax.
14syn spell notoplevel
15
16  finish
17endif
18
19" SML is case sensitive.
20syn case match
21
22" lowercase identifier - the standard way to match
23syn match    smlLCIdentifier /\<\(\l\|_\)\(\w\|'\)*\>/
24
25syn match    smlKeyChar    "|"
26
27" Errors
28syn match    smlBraceErr   "}"
29syn match    smlBrackErr   "\]"
30syn match    smlParenErr   ")"
31syn match    smlCommentErr "\*)"
32syn match    smlThenErr    "\<then\>"
33
34" Error-highlighting of "end" without synchronization:
35" as keyword or as error (default)
36if exists("sml_noend_error")
37  syn match    smlKeyword    "\<end\>"
38else
39  syn match    smlEndErr     "\<end\>"
40endif
41
42" Some convenient clusters
43syn cluster  smlAllErrs contains=smlBraceErr,smlBrackErr,smlParenErr,smlCommentErr,smlEndErr,smlThenErr
44
45syn cluster  smlAENoParen contains=smlBraceErr,smlBrackErr,smlCommentErr,smlEndErr,smlThenErr
46
47syn cluster  smlContained contains=smlTodo,smlPreDef,smlModParam,smlModParam1,smlPreMPRestr,smlMPRestr,smlMPRestr1,smlMPRestr2,smlMPRestr3,smlModRHS,smlFuncWith,smlFuncStruct,smlModTypeRestr,smlModTRWith,smlWith,smlWithRest,smlModType,smlFullMod
48
49
50" Enclosing delimiters
51syn region   smlEncl transparent matchgroup=smlKeyword start="(" matchgroup=smlKeyword end=")" contains=ALLBUT,@smlContained,smlParenErr
52syn region   smlEncl transparent matchgroup=smlKeyword start="{" matchgroup=smlKeyword end="}"  contains=ALLBUT,@smlContained,smlBraceErr
53syn region   smlEncl transparent matchgroup=smlKeyword start="\[" matchgroup=smlKeyword end="\]" contains=ALLBUT,@smlContained,smlBrackErr
54syn region   smlEncl transparent matchgroup=smlKeyword start="#\[" matchgroup=smlKeyword end="\]" contains=ALLBUT,@smlContained,smlBrackErr
55
56
57" Comments
58syn region   smlComment start="(\*" end="\*)" contains=smlComment,smlTodo,@Spell
59syn keyword  smlTodo contained TODO FIXME XXX
60
61
62" let
63syn region   smlEnd matchgroup=smlKeyword start="\<let\>" matchgroup=smlKeyword end="\<end\>" contains=ALLBUT,@smlContained,smlEndErr
64
65" local
66syn region   smlEnd matchgroup=smlKeyword start="\<local\>" matchgroup=smlKeyword end="\<end\>" contains=ALLBUT,@smlContained,smlEndErr
67
68" abstype
69syn region   smlNone matchgroup=smlKeyword start="\<abstype\>" matchgroup=smlKeyword end="\<end\>" contains=ALLBUT,@smlContained,smlEndErr
70
71" begin
72syn region   smlEnd matchgroup=smlKeyword start="\<begin\>" matchgroup=smlKeyword end="\<end\>" contains=ALLBUT,@smlContained,smlEndErr
73
74" if
75syn region   smlNone matchgroup=smlKeyword start="\<if\>" matchgroup=smlKeyword end="\<then\>" contains=ALLBUT,@smlContained,smlThenErr
76
77
78"" Modules
79
80" "struct"
81syn region   smlStruct matchgroup=smlModule start="\<struct\>" matchgroup=smlModule end="\<end\>" contains=ALLBUT,@smlContained,smlEndErr
82
83" "sig"
84syn region   smlSig matchgroup=smlModule start="\<sig\>" matchgroup=smlModule end="\<end\>" contains=ALLBUT,@smlContained,smlEndErr,smlModule
85syn region   smlModSpec matchgroup=smlKeyword start="\<structure\>" matchgroup=smlModule end="\<\u\(\w\|'\)*\>" contained contains=@smlAllErrs,smlComment skipwhite skipempty nextgroup=smlModTRWith,smlMPRestr
86
87" "open"
88syn region   smlNone matchgroup=smlKeyword start="\<open\>" matchgroup=smlModule end="\<\w\(\w\|'\)*\(\.\w\(\w\|'\)*\)*\>" contains=@smlAllErrs,smlComment
89
90" "structure" - somewhat complicated stuff ;-)
91syn region   smlModule matchgroup=smlKeyword start="\<\(structure\|functor\)\>" matchgroup=smlModule end="\<\u\(\w\|'\)*\>" contains=@smlAllErrs,smlComment skipwhite skipempty nextgroup=smlPreDef
92syn region   smlPreDef start="."me=e-1 matchgroup=smlKeyword end="\l\|="me=e-1 contained contains=@smlAllErrs,smlComment,smlModParam,smlModTypeRestr,smlModTRWith nextgroup=smlModPreRHS
93syn region   smlModParam start="([^*]" end=")" contained contains=@smlAENoParen,smlModParam1
94syn match    smlModParam1 "\<\u\(\w\|'\)*\>" contained skipwhite skipempty nextgroup=smlPreMPRestr
95
96syn region   smlPreMPRestr start="."me=e-1 end=")"me=e-1 contained contains=@smlAllErrs,smlComment,smlMPRestr,smlModTypeRestr
97
98syn region   smlMPRestr start=":" end="."me=e-1 contained contains=@smlComment skipwhite skipempty nextgroup=smlMPRestr1,smlMPRestr2,smlMPRestr3
99syn region   smlMPRestr1 matchgroup=smlModule start="\ssig\s\=" matchgroup=smlModule end="\<end\>" contained contains=ALLBUT,@smlContained,smlEndErr,smlModule
100syn region   smlMPRestr2 start="\sfunctor\(\s\|(\)\="me=e-1 matchgroup=smlKeyword end="->" contained contains=@smlAllErrs,smlComment,smlModParam skipwhite skipempty nextgroup=smlFuncWith
101syn match    smlMPRestr3 "\w\(\w\|'\)*\(\.\w\(\w\|'\)*\)*" contained
102syn match    smlModPreRHS "=" contained skipwhite skipempty nextgroup=smlModParam,smlFullMod
103syn region   smlModRHS start="." end=".\w\|([^*]"me=e-2 contained contains=smlComment skipwhite skipempty nextgroup=smlModParam,smlFullMod
104syn match    smlFullMod "\<\u\(\w\|'\)*\(\.\u\(\w\|'\)*\)*" contained skipwhite skipempty nextgroup=smlFuncWith
105
106syn region   smlFuncWith start="([^*]"me=e-1 end=")" contained contains=smlComment,smlWith,smlFuncStruct
107syn region   smlFuncStruct matchgroup=smlModule start="[^a-zA-Z]struct\>"hs=s+1 matchgroup=smlModule end="\<end\>" contains=ALLBUT,@smlContained,smlEndErr
108
109syn match    smlModTypeRestr "\<\w\(\w\|'\)*\(\.\w\(\w\|'\)*\)*\>" contained
110syn region   smlModTRWith start=":\s*("hs=s+1 end=")" contained contains=@smlAENoParen,smlWith
111syn match    smlWith "\<\(\u\(\w\|'\)*\.\)*\w\(\w\|'\)*\>" contained skipwhite skipempty nextgroup=smlWithRest
112syn region   smlWithRest start="[^)]" end=")"me=e-1 contained contains=ALLBUT,@smlContained
113
114" "signature"
115syn region   smlKeyword start="\<signature\>" matchgroup=smlModule end="\<\w\(\w\|'\)*\>" contains=smlComment skipwhite skipempty nextgroup=smlMTDef
116syn match    smlMTDef "=\s*\w\(\w\|'\)*\>"hs=s+1,me=s
117
118syn keyword  smlKeyword  and andalso case
119syn keyword  smlKeyword  datatype else eqtype
120syn keyword  smlKeyword  exception fn fun handle
121syn keyword  smlKeyword  in infix infixl infixr
122syn keyword  smlKeyword  match nonfix of orelse
123syn keyword  smlKeyword  raise handle type
124syn keyword  smlKeyword  val where while with withtype
125
126syn keyword  smlType     bool char exn int list option
127syn keyword  smlType     real string unit
128
129syn keyword  smlOperator div mod not or quot rem
130
131syn keyword  smlBoolean      true false
132syn match    smlConstructor  "(\s*)"
133syn match    smlConstructor  "\[\s*\]"
134syn match    smlConstructor  "#\[\s*\]"
135syn match    smlConstructor  "\u\(\w\|'\)*\>"
136
137" Module prefix
138syn match    smlModPath      "\u\(\w\|'\)*\."he=e-1
139
140syn match    smlCharacter    +#"\\""\|#"."\|#"\\\d\d\d"+
141syn match    smlCharErr      +#"\\\d\d"\|#"\\\d"+
142syn region   smlString       start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@Spell
143
144syn match    smlFunDef       "=>"
145syn match    smlRefAssign    ":="
146syn match    smlTopStop      ";;"
147syn match    smlOperator     "\^"
148syn match    smlOperator     "::"
149syn match    smlAnyVar       "\<_\>"
150syn match    smlKeyChar      "!"
151syn match    smlKeyChar      ";"
152syn match    smlKeyChar      "\*"
153syn match    smlKeyChar      "="
154
155syn match    smlNumber        "\<-\=\d\+\>"
156syn match    smlNumber        "\<-\=0[x|X]\x\+\>"
157syn match    smlReal          "\<-\=\d\+\.\d*\([eE][-+]\=\d\+\)\=[fl]\=\>"
158
159" Synchronization
160syn sync minlines=20
161syn sync maxlines=500
162
163syn sync match smlEndSync     grouphere  smlEnd     "\<begin\>"
164syn sync match smlEndSync     groupthere smlEnd     "\<end\>"
165syn sync match smlStructSync  grouphere  smlStruct  "\<struct\>"
166syn sync match smlStructSync  groupthere smlStruct  "\<end\>"
167syn sync match smlSigSync     grouphere  smlSig     "\<sig\>"
168syn sync match smlSigSync     groupthere smlSig     "\<end\>"
169
170" Define the default highlighting.
171" Only when an item doesn't have highlighting yet
172
173hi def link smlBraceErr     Error
174hi def link smlBrackErr     Error
175hi def link smlParenErr     Error
176
177hi def link smlCommentErr   Error
178
179hi def link smlEndErr       Error
180hi def link smlThenErr      Error
181
182hi def link smlCharErr      Error
183
184hi def link smlComment      Comment
185
186hi def link smlModPath      Include
187hi def link smlModule       Include
188hi def link smlModParam1    Include
189hi def link smlModType      Include
190hi def link smlMPRestr3     Include
191hi def link smlFullMod      Include
192hi def link smlModTypeRestr Include
193hi def link smlWith         Include
194hi def link smlMTDef        Include
195
196hi def link smlConstructor  Constant
197
198hi def link smlModPreRHS    Keyword
199hi def link smlMPRestr2     Keyword
200hi def link smlKeyword      Keyword
201hi def link smlFunDef       Keyword
202hi def link smlRefAssign    Keyword
203hi def link smlKeyChar      Keyword
204hi def link smlAnyVar       Keyword
205hi def link smlTopStop      Keyword
206hi def link smlOperator     Keyword
207
208hi def link smlBoolean      Boolean
209hi def link smlCharacter    Character
210hi def link smlNumber       Number
211hi def link smlReal         Float
212hi def link smlString       String
213hi def link smlType         Type
214hi def link smlTodo         Todo
215hi def link smlEncl         Keyword
216
217
218let b:current_syntax = "sml"
219
220" vim: ts=8
221