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: 2021 Oct 04 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 finish 13endif 14 15" Disable spell checking of syntax. 16syn spell notoplevel 17 18" 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 57syn region smlComment start="(\*" end="\*)" contains=smlComment,smlTodo,@Spell 58syn 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" 87syn region smlNone matchgroup=smlKeyword start="\<open\>" matchgroup=smlModule end="\<\w\(\w\|'\)*\(\.\w\(\w\|'\)*\)*\>" contains=@smlAllErrs,smlComment 88 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 139syn match smlCharacter +#"\\""\|#"."\|#"\\\d\d\d"+ 140syn match smlCharErr +#"\\\d\d"\|#"\\\d"+ 141syn region smlString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@Spell 142 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 154syn match smlNumber "\<-\=\d\+\>" 155syn match smlNumber "\<-\=0[x|X]\x\+\>" 156syn match smlReal "\<-\=\d\+\.\d*\([eE][-+]\=\d\+\)\=[fl]\=\>" 157 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. 170" Only when an item doesn't have highlighting yet 171 172hi def link smlBraceErr Error 173hi def link smlBrackErr Error 174hi def link smlParenErr Error 175 176hi def link smlCommentErr Error 177 178hi def link smlEndErr Error 179hi def link smlThenErr Error 180 181hi def link smlCharErr Error 182 183hi def link smlComment Comment 184 185hi 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 191hi def link smlModTypeRestr Include 192hi def link smlWith Include 193hi def link smlMTDef Include 194 195hi def link smlConstructor Constant 196 197hi 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 206 207hi 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 215 216 217let b:current_syntax = "sml" 218 219" vim: ts=8 220