robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

zeertzjqMerge pull request #36826 from zeertzjq/vim-ffc7f8c6383123326

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