1 package s
2
3 import (
4 . "github.com/alecthomas/chroma"
5 "github.com/alecthomas/chroma/lexers/internal"
6 )
7
8
9 var StandardML = internal.Register(MustNewLazyLexer(
10 &Config{
11 Name: "Standard ML",
12 Aliases: []string{"sml"},
13 Filenames: []string{"*.sml", "*.sig", "*.fun"},
14 MimeTypes: []string{"text/x-standardml", "application/x-standardml"},
15 },
16 standardMLRules,
17 ))
18
19 func standardMLRules() Rules {
20 return Rules{
21 "whitespace": {
22 {`\s+`, Text, nil},
23 {`\(\*`, CommentMultiline, Push("comment")},
24 },
25 "delimiters": {
26 {`\(|\[|\{`, Punctuation, Push("main")},
27 {`\)|\]|\}`, Punctuation, Pop(1)},
28 {`\b(let|if|local)\b(?!\')`, KeywordReserved, Push("main", "main")},
29 {`\b(struct|sig|while)\b(?!\')`, KeywordReserved, Push("main")},
30 {`\b(do|else|end|in|then)\b(?!\')`, KeywordReserved, Pop(1)},
31 },
32 "core": {
33 {`(_|\}|\{|\)|;|,|\[|\(|\]|\.\.\.)`, Punctuation, nil},
34 {`#"`, LiteralStringChar, Push("char")},
35 {`"`, LiteralStringDouble, Push("string")},
36 {`~?0x[0-9a-fA-F]+`, LiteralNumberHex, nil},
37 {`0wx[0-9a-fA-F]+`, LiteralNumberHex, nil},
38 {`0w\d+`, LiteralNumberInteger, nil},
39 {`~?\d+\.\d+[eE]~?\d+`, LiteralNumberFloat, nil},
40 {`~?\d+\.\d+`, LiteralNumberFloat, nil},
41 {`~?\d+[eE]~?\d+`, LiteralNumberFloat, nil},
42 {`~?\d+`, LiteralNumberInteger, nil},
43 {`#\s*[1-9][0-9]*`, NameLabel, nil},
44 {`#\s*([a-zA-Z][\w']*)`, NameLabel, nil},
45 {"#\\s+([!%&$#+\\-/:<=>?@\\\\~`^|*]+)", NameLabel, nil},
46 {`\b(datatype|abstype)\b(?!\')`, KeywordReserved, Push("dname")},
47 {`(?=\b(exception)\b(?!\'))`, Text, Push("ename")},
48 {`\b(functor|include|open|signature|structure)\b(?!\')`, KeywordReserved, Push("sname")},
49 {`\b(type|eqtype)\b(?!\')`, KeywordReserved, Push("tname")},
50 {`\'[\w\']*`, NameDecorator, nil},
51 {`([a-zA-Z][\w']*)(\.)`, NameNamespace, Push("dotted")},
52 {`\b(abstype|and|andalso|as|case|datatype|do|else|end|exception|fn|fun|handle|if|in|infix|infixr|let|local|nonfix|of|op|open|orelse|raise|rec|then|type|val|with|withtype|while|eqtype|functor|include|sharing|sig|signature|struct|structure|where)\b`, KeywordReserved, nil},
53 {`([a-zA-Z][\w']*)`, Name, nil},
54 {`\b(:|\|,=|=>|->|#|:>)\b`, KeywordReserved, nil},
55 {"([!%&$#+\\-/:<=>?@\\\\~`^|*]+)", Name, nil},
56 },
57 "dotted": {
58 {`([a-zA-Z][\w']*)(\.)`, NameNamespace, nil},
59
60 {`([a-zA-Z][\w']*)`, Name, Pop(1)},
61
62 {"([!%&$#+\\-/:<=>?@\\\\~`^|*]+)", Name, Pop(1)},
63 {`\s+`, Error, nil},
64 {`\S+`, Error, nil},
65 },
66 "root": {
67 Default(Push("main")),
68 },
69 "main": {
70 Include("whitespace"),
71 {`\b(val|and)\b(?!\')`, KeywordReserved, Push("vname")},
72 {`\b(fun)\b(?!\')`, KeywordReserved, Push("#pop", "main-fun", "fname")},
73 Include("delimiters"),
74 Include("core"),
75 {`\S+`, Error, nil},
76 },
77 "main-fun": {
78 Include("whitespace"),
79 {`\s`, Text, nil},
80 {`\(\*`, CommentMultiline, Push("comment")},
81 {`\b(fun|and)\b(?!\')`, KeywordReserved, Push("fname")},
82 {`\b(val)\b(?!\')`, KeywordReserved, Push("#pop", "main", "vname")},
83 {`\|`, Punctuation, Push("fname")},
84 {`\b(case|handle)\b(?!\')`, KeywordReserved, Push("#pop", "main")},
85 Include("delimiters"),
86 Include("core"),
87 {`\S+`, Error, nil},
88 },
89 "char": {
90 {`[^"\\]`, LiteralStringChar, nil},
91 {`\\[\\"abtnvfr]`, LiteralStringEscape, nil},
92 {`\\\^[\x40-\x5e]`, LiteralStringEscape, nil},
93 {`\\[0-9]{3}`, LiteralStringEscape, nil},
94 {`\\u[0-9a-fA-F]{4}`, LiteralStringEscape, nil},
95 {`\\\s+\\`, LiteralStringInterpol, nil},
96 {`"`, LiteralStringChar, Pop(1)},
97 },
98 "string": {
99 {`[^"\\]`, LiteralStringDouble, nil},
100 {`\\[\\"abtnvfr]`, LiteralStringEscape, nil},
101 {`\\\^[\x40-\x5e]`, LiteralStringEscape, nil},
102 {`\\[0-9]{3}`, LiteralStringEscape, nil},
103 {`\\u[0-9a-fA-F]{4}`, LiteralStringEscape, nil},
104 {`\\\s+\\`, LiteralStringInterpol, nil},
105 {`"`, LiteralStringDouble, Pop(1)},
106 },
107 "breakout": {
108 {`(?=\b(where|do|handle|if|sig|op|while|case|as|else|signature|andalso|struct|infixr|functor|in|structure|then|local|rec|end|fun|of|orelse|val|include|fn|with|exception|let|and|infix|sharing|datatype|type|abstype|withtype|eqtype|nonfix|raise|open)\b(?!\'))`, Text, Pop(1)},
109 },
110 "sname": {
111 Include("whitespace"),
112 Include("breakout"),
113 {`([a-zA-Z][\w']*)`, NameNamespace, nil},
114 Default(Pop(1)),
115 },
116 "fname": {
117 Include("whitespace"),
118 {`\'[\w\']*`, NameDecorator, nil},
119 {`\(`, Punctuation, Push("tyvarseq")},
120 {`([a-zA-Z][\w']*)`, NameFunction, Pop(1)},
121 {"([!%&$#+\\-/:<=>?@\\\\~`^|*]+)", NameFunction, Pop(1)},
122 Default(Pop(1)),
123 },
124 "vname": {
125 Include("whitespace"),
126 {`\'[\w\']*`, NameDecorator, nil},
127 {`\(`, Punctuation, Push("tyvarseq")},
128 {"([a-zA-Z][\\w']*)(\\s*)(=(?![!%&$#+\\-/:<=>?@\\\\~`^|*]+))", ByGroups(NameVariable, Text, Punctuation), Pop(1)},
129 {"([!%&$#+\\-/:<=>?@\\\\~`^|*]+)(\\s*)(=(?![!%&$#+\\-/:<=>?@\\\\~`^|*]+))", ByGroups(NameVariable, Text, Punctuation), Pop(1)},
130 {`([a-zA-Z][\w']*)`, NameVariable, Pop(1)},
131 {"([!%&$#+\\-/:<=>?@\\\\~`^|*]+)", NameVariable, Pop(1)},
132 Default(Pop(1)),
133 },
134 "tname": {
135 Include("whitespace"),
136 Include("breakout"),
137 {`\'[\w\']*`, NameDecorator, nil},
138 {`\(`, Punctuation, Push("tyvarseq")},
139 {"=(?![!%&$#+\\-/:<=>?@\\\\~`^|*]+)", Punctuation, Push("#pop", "typbind")},
140 {`([a-zA-Z][\w']*)`, KeywordType, nil},
141 {"([!%&$#+\\-/:<=>?@\\\\~`^|*]+)", KeywordType, nil},
142 {`\S+`, Error, Pop(1)},
143 },
144 "typbind": {
145 Include("whitespace"),
146 {`\b(and)\b(?!\')`, KeywordReserved, Push("#pop", "tname")},
147 Include("breakout"),
148 Include("core"),
149 {`\S+`, Error, Pop(1)},
150 },
151 "dname": {
152 Include("whitespace"),
153 Include("breakout"),
154 {`\'[\w\']*`, NameDecorator, nil},
155 {`\(`, Punctuation, Push("tyvarseq")},
156 {`(=)(\s*)(datatype)`, ByGroups(Punctuation, Text, KeywordReserved), Pop(1)},
157 {"=(?![!%&$#+\\-/:<=>?@\\\\~`^|*]+)", Punctuation, Push("#pop", "datbind", "datcon")},
158 {`([a-zA-Z][\w']*)`, KeywordType, nil},
159 {"([!%&$#+\\-/:<=>?@\\\\~`^|*]+)", KeywordType, nil},
160 {`\S+`, Error, Pop(1)},
161 },
162 "datbind": {
163 Include("whitespace"),
164 {`\b(and)\b(?!\')`, KeywordReserved, Push("#pop", "dname")},
165 {`\b(withtype)\b(?!\')`, KeywordReserved, Push("#pop", "tname")},
166 {`\b(of)\b(?!\')`, KeywordReserved, nil},
167 {`(\|)(\s*)([a-zA-Z][\w']*)`, ByGroups(Punctuation, Text, NameClass), nil},
168 {"(\\|)(\\s+)([!%&$#+\\-/:<=>?@\\\\~`^|*]+)", ByGroups(Punctuation, Text, NameClass), nil},
169 Include("breakout"),
170 Include("core"),
171 {`\S+`, Error, nil},
172 },
173 "ename": {
174 Include("whitespace"),
175 {`(exception|and)\b(\s+)([a-zA-Z][\w']*)`, ByGroups(KeywordReserved, Text, NameClass), nil},
176 {"(exception|and)\\b(\\s*)([!%&$#+\\-/:<=>?@\\\\~`^|*]+)", ByGroups(KeywordReserved, Text, NameClass), nil},
177 {`\b(of)\b(?!\')`, KeywordReserved, nil},
178 Include("breakout"),
179 Include("core"),
180 {`\S+`, Error, nil},
181 },
182 "datcon": {
183 Include("whitespace"),
184 {`([a-zA-Z][\w']*)`, NameClass, Pop(1)},
185 {"([!%&$#+\\-/:<=>?@\\\\~`^|*]+)", NameClass, Pop(1)},
186 {`\S+`, Error, Pop(1)},
187 },
188 "tyvarseq": {
189 {`\s`, Text, nil},
190 {`\(\*`, CommentMultiline, Push("comment")},
191 {`\'[\w\']*`, NameDecorator, nil},
192 {`[a-zA-Z][\w']*`, Name, nil},
193 {`,`, Punctuation, nil},
194 {`\)`, Punctuation, Pop(1)},
195 {"[!%&$#+\\-/:<=>?@\\\\~`^|*]+", Name, nil},
196 },
197 "comment": {
198 {`[^(*)]`, CommentMultiline, nil},
199 {`\(\*`, CommentMultiline, Push()},
200 {`\*\)`, CommentMultiline, Pop(1)},
201 {`[(*)]`, CommentMultiline, nil},
202 },
203 }
204 }
205
View as plain text