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