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