Mercurial > yakumo_izuru > aya
comparison vendor/github.com/alecthomas/chroma/v2/lexers/haxe.go @ 66:787b5ee0289d draft
Use vendored modules
Signed-off-by: Izuru Yakumo <yakumo.izuru@chaotic.ninja>
author | yakumo.izuru |
---|---|
date | Sun, 23 Jul 2023 13:18:53 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
65:6d985efa0f7a | 66:787b5ee0289d |
---|---|
1 package lexers | |
2 | |
3 import ( | |
4 . "github.com/alecthomas/chroma/v2" // nolint | |
5 ) | |
6 | |
7 // Haxe lexer. | |
8 var Haxe = Register(MustNewLexer( | |
9 &Config{ | |
10 Name: "Haxe", | |
11 Aliases: []string{"hx", "haxe", "hxsl"}, | |
12 Filenames: []string{"*.hx", "*.hxsl"}, | |
13 MimeTypes: []string{"text/haxe", "text/x-haxe", "text/x-hx"}, | |
14 DotAll: true, | |
15 }, | |
16 haxeRules, | |
17 )) | |
18 | |
19 func haxeRules() Rules { | |
20 return Rules{ | |
21 "root": { | |
22 Include("spaces"), | |
23 Include("meta"), | |
24 {`(?:package)\b`, KeywordNamespace, Push("semicolon", "package")}, | |
25 {`(?:import)\b`, KeywordNamespace, Push("semicolon", "import")}, | |
26 {`(?:using)\b`, KeywordNamespace, Push("semicolon", "using")}, | |
27 {`(?:extern|private)\b`, KeywordDeclaration, nil}, | |
28 {`(?:abstract)\b`, KeywordDeclaration, Push("abstract")}, | |
29 {`(?:class|interface)\b`, KeywordDeclaration, Push("class")}, | |
30 {`(?:enum)\b`, KeywordDeclaration, Push("enum")}, | |
31 {`(?:typedef)\b`, KeywordDeclaration, Push("typedef")}, | |
32 {`(?=.)`, Text, Push("expr-statement")}, | |
33 }, | |
34 "spaces": { | |
35 {`\s+`, Text, nil}, | |
36 {`//[^\n\r]*`, CommentSingle, nil}, | |
37 {`/\*.*?\*/`, CommentMultiline, nil}, | |
38 {`(#)(if|elseif|else|end|error)\b`, CommentPreproc, MutatorFunc(haxePreProcMutator)}, | |
39 }, | |
40 "string-single-interpol": { | |
41 {`\$\{`, LiteralStringInterpol, Push("string-interpol-close", "expr")}, | |
42 {`\$\$`, LiteralStringEscape, nil}, | |
43 {`\$(?=(?:_*[a-z]\w*|_+[0-9]\w*|_*[A-Z]\w*|_+|\$\w+))`, LiteralStringInterpol, Push("ident")}, | |
44 Include("string-single"), | |
45 }, | |
46 "string-single": { | |
47 {`'`, LiteralStringSingle, Pop(1)}, | |
48 {`\\.`, LiteralStringEscape, nil}, | |
49 {`.`, LiteralStringSingle, nil}, | |
50 }, | |
51 "string-double": { | |
52 {`"`, LiteralStringDouble, Pop(1)}, | |
53 {`\\.`, LiteralStringEscape, nil}, | |
54 {`.`, LiteralStringDouble, nil}, | |
55 }, | |
56 "string-interpol-close": { | |
57 {`\$(?:_*[a-z]\w*|_+[0-9]\w*|_*[A-Z]\w*|_+|\$\w+)`, LiteralStringInterpol, nil}, | |
58 {`\}`, LiteralStringInterpol, Pop(1)}, | |
59 }, | |
60 "package": { | |
61 Include("spaces"), | |
62 {`(?:_*[a-z]\w*|_+[0-9]\w*|_*[A-Z]\w*|_+|\$\w+)`, NameNamespace, nil}, | |
63 {`\.`, Punctuation, Push("import-ident")}, | |
64 Default(Pop(1)), | |
65 }, | |
66 "import": { | |
67 Include("spaces"), | |
68 {`(?:_*[a-z]\w*|_+[0-9]\w*|_*[A-Z]\w*|_+|\$\w+)`, NameNamespace, nil}, | |
69 {`\*`, Keyword, nil}, | |
70 {`\.`, Punctuation, Push("import-ident")}, | |
71 {`in`, KeywordNamespace, Push("ident")}, | |
72 Default(Pop(1)), | |
73 }, | |
74 "import-ident": { | |
75 Include("spaces"), | |
76 {`\*`, Keyword, Pop(1)}, | |
77 {`(?:_*[a-z]\w*|_+[0-9]\w*|_*[A-Z]\w*|_+|\$\w+)`, NameNamespace, Pop(1)}, | |
78 }, | |
79 "using": { | |
80 Include("spaces"), | |
81 {`(?:_*[a-z]\w*|_+[0-9]\w*|_*[A-Z]\w*|_+|\$\w+)`, NameNamespace, nil}, | |
82 {`\.`, Punctuation, Push("import-ident")}, | |
83 Default(Pop(1)), | |
84 }, | |
85 "preproc-error": { | |
86 {`\s+`, CommentPreproc, nil}, | |
87 {`'`, LiteralStringSingle, Push("#pop", "string-single")}, | |
88 {`"`, LiteralStringDouble, Push("#pop", "string-double")}, | |
89 Default(Pop(1)), | |
90 }, | |
91 "preproc-expr": { | |
92 {`\s+`, CommentPreproc, nil}, | |
93 {`\!`, CommentPreproc, nil}, | |
94 {`\(`, CommentPreproc, Push("#pop", "preproc-parenthesis")}, | |
95 {`(?:_*[a-z]\w*|_+[0-9]\w*|_*[A-Z]\w*|_+|\$\w+)`, CommentPreproc, Pop(1)}, | |
96 {`\.[0-9]+`, LiteralNumberFloat, nil}, | |
97 {`[0-9]+[eE][+\-]?[0-9]+`, LiteralNumberFloat, nil}, | |
98 {`[0-9]+\.[0-9]*[eE][+\-]?[0-9]+`, LiteralNumberFloat, nil}, | |
99 {`[0-9]+\.[0-9]+`, LiteralNumberFloat, nil}, | |
100 {`[0-9]+\.(?!(?:_*[a-z]\w*|_+[0-9]\w*|_*[A-Z]\w*|_+|\$\w+)|\.\.)`, LiteralNumberFloat, nil}, | |
101 {`0x[0-9a-fA-F]+`, LiteralNumberHex, nil}, | |
102 {`[0-9]+`, LiteralNumberInteger, nil}, | |
103 {`'`, LiteralStringSingle, Push("#pop", "string-single")}, | |
104 {`"`, LiteralStringDouble, Push("#pop", "string-double")}, | |
105 }, | |
106 "preproc-parenthesis": { | |
107 {`\s+`, CommentPreproc, nil}, | |
108 {`\)`, CommentPreproc, Pop(1)}, | |
109 Default(Push("preproc-expr-in-parenthesis")), | |
110 }, | |
111 "preproc-expr-chain": { | |
112 {`\s+`, CommentPreproc, nil}, | |
113 {`(?:%=|&=|\|=|\^=|\+=|\-=|\*=|/=|<<=|>\s*>\s*=|>\s*>\s*>\s*=|==|!=|<=|>\s*=|&&|\|\||<<|>>>|>\s*>|\.\.\.|<|>|%|&|\||\^|\+|\*|/|\-|=>|=)`, CommentPreproc, Push("#pop", "preproc-expr-in-parenthesis")}, | |
114 Default(Pop(1)), | |
115 }, | |
116 "preproc-expr-in-parenthesis": { | |
117 {`\s+`, CommentPreproc, nil}, | |
118 {`\!`, CommentPreproc, nil}, | |
119 {`\(`, CommentPreproc, Push("#pop", "preproc-expr-chain", "preproc-parenthesis")}, | |
120 {`(?:_*[a-z]\w*|_+[0-9]\w*|_*[A-Z]\w*|_+|\$\w+)`, CommentPreproc, Push("#pop", "preproc-expr-chain")}, | |
121 {`\.[0-9]+`, LiteralNumberFloat, Push("#pop", "preproc-expr-chain")}, | |
122 {`[0-9]+[eE][+\-]?[0-9]+`, LiteralNumberFloat, Push("#pop", "preproc-expr-chain")}, | |
123 {`[0-9]+\.[0-9]*[eE][+\-]?[0-9]+`, LiteralNumberFloat, Push("#pop", "preproc-expr-chain")}, | |
124 {`[0-9]+\.[0-9]+`, LiteralNumberFloat, Push("#pop", "preproc-expr-chain")}, | |
125 {`[0-9]+\.(?!(?:_*[a-z]\w*|_+[0-9]\w*|_*[A-Z]\w*|_+|\$\w+)|\.\.)`, LiteralNumberFloat, Push("#pop", "preproc-expr-chain")}, | |
126 {`0x[0-9a-fA-F]+`, LiteralNumberHex, Push("#pop", "preproc-expr-chain")}, | |
127 {`[0-9]+`, LiteralNumberInteger, Push("#pop", "preproc-expr-chain")}, | |
128 {`'`, LiteralStringSingle, Push("#pop", "preproc-expr-chain", "string-single")}, | |
129 {`"`, LiteralStringDouble, Push("#pop", "preproc-expr-chain", "string-double")}, | |
130 }, | |
131 "abstract": { | |
132 Include("spaces"), | |
133 Default(Pop(1), Push("abstract-body"), Push("abstract-relation"), Push("abstract-opaque"), Push("type-param-constraint"), Push("type-name")), | |
134 }, | |
135 "abstract-body": { | |
136 Include("spaces"), | |
137 {`\{`, Punctuation, Push("#pop", "class-body")}, | |
138 }, | |
139 "abstract-opaque": { | |
140 Include("spaces"), | |
141 {`\(`, Punctuation, Push("#pop", "parenthesis-close", "type")}, | |
142 Default(Pop(1)), | |
143 }, | |
144 "abstract-relation": { | |
145 Include("spaces"), | |
146 {`(?:to|from)`, KeywordDeclaration, Push("type")}, | |
147 {`,`, Punctuation, nil}, | |
148 Default(Pop(1)), | |
149 }, | |
150 "meta": { | |
151 Include("spaces"), | |
152 {`@`, NameDecorator, Push("meta-body", "meta-ident", "meta-colon")}, | |
153 }, | |
154 "meta-colon": { | |
155 Include("spaces"), | |
156 {`:`, NameDecorator, Pop(1)}, | |
157 Default(Pop(1)), | |
158 }, | |
159 "meta-ident": { | |
160 Include("spaces"), | |
161 {`(?:_*[a-z]\w*|_+[0-9]\w*|_*[A-Z]\w*|_+|\$\w+)`, NameDecorator, Pop(1)}, | |
162 }, | |
163 "meta-body": { | |
164 Include("spaces"), | |
165 {`\(`, NameDecorator, Push("#pop", "meta-call")}, | |
166 Default(Pop(1)), | |
167 }, | |
168 "meta-call": { | |
169 Include("spaces"), | |
170 {`\)`, NameDecorator, Pop(1)}, | |
171 Default(Pop(1), Push("meta-call-sep"), Push("expr")), | |
172 }, | |
173 "meta-call-sep": { | |
174 Include("spaces"), | |
175 {`\)`, NameDecorator, Pop(1)}, | |
176 {`,`, Punctuation, Push("#pop", "meta-call")}, | |
177 }, | |
178 "typedef": { | |
179 Include("spaces"), | |
180 Default(Pop(1), Push("typedef-body"), Push("type-param-constraint"), Push("type-name")), | |
181 }, | |
182 "typedef-body": { | |
183 Include("spaces"), | |
184 {`=`, Operator, Push("#pop", "optional-semicolon", "type")}, | |
185 }, | |
186 "enum": { | |
187 Include("spaces"), | |
188 Default(Pop(1), Push("enum-body"), Push("bracket-open"), Push("type-param-constraint"), Push("type-name")), | |
189 }, | |
190 "enum-body": { | |
191 Include("spaces"), | |
192 Include("meta"), | |
193 {`\}`, Punctuation, Pop(1)}, | |
194 {`(?!(?:function|class|static|var|if|else|while|do|for|break|return|continue|extends|implements|import|switch|case|default|public|private|try|untyped|catch|new|this|throw|extern|enum|in|interface|cast|override|dynamic|typedef|package|inline|using|null|true|false|abstract)\b)(?:_*[a-z]\w*|_+[0-9]\w*|_*[A-Z]\w*|_+|\$\w+)`, Name, Push("enum-member", "type-param-constraint")}, | |
195 }, | |
196 "enum-member": { | |
197 Include("spaces"), | |
198 {`\(`, Punctuation, Push("#pop", "semicolon", "flag", "function-param")}, | |
199 Default(Pop(1), Push("semicolon"), Push("flag")), | |
200 }, | |
201 "class": { | |
202 Include("spaces"), | |
203 Default(Pop(1), Push("class-body"), Push("bracket-open"), Push("extends"), Push("type-param-constraint"), Push("type-name")), | |
204 }, | |
205 "extends": { | |
206 Include("spaces"), | |
207 {`(?:extends|implements)\b`, KeywordDeclaration, Push("type")}, | |
208 {`,`, Punctuation, nil}, | |
209 Default(Pop(1)), | |
210 }, | |
211 "bracket-open": { | |
212 Include("spaces"), | |
213 {`\{`, Punctuation, Pop(1)}, | |
214 }, | |
215 "bracket-close": { | |
216 Include("spaces"), | |
217 {`\}`, Punctuation, Pop(1)}, | |
218 }, | |
219 "class-body": { | |
220 Include("spaces"), | |
221 Include("meta"), | |
222 {`\}`, Punctuation, Pop(1)}, | |
223 {`(?:static|public|private|override|dynamic|inline|macro)\b`, KeywordDeclaration, nil}, | |
224 Default(Push("class-member")), | |
225 }, | |
226 "class-member": { | |
227 Include("spaces"), | |
228 {`(var)\b`, KeywordDeclaration, Push("#pop", "optional-semicolon", "var")}, | |
229 {`(function)\b`, KeywordDeclaration, Push("#pop", "optional-semicolon", "class-method")}, | |
230 }, | |
231 "function-local": { | |
232 Include("spaces"), | |
233 {`(?!(?:function|class|static|var|if|else|while|do|for|break|return|continue|extends|implements|import|switch|case|default|public|private|try|untyped|catch|new|this|throw|extern|enum|in|interface|cast|override|dynamic|typedef|package|inline|using|null|true|false|abstract)\b)(?:_*[a-z]\w*|_+[0-9]\w*|_*[A-Z]\w*|_+|\$\w+)`, NameFunction, Push("#pop", "optional-expr", "flag", "function-param", "parenthesis-open", "type-param-constraint")}, | |
234 Default(Pop(1), Push("optional-expr"), Push("flag"), Push("function-param"), Push("parenthesis-open"), Push("type-param-constraint")), | |
235 }, | |
236 "optional-expr": { | |
237 Include("spaces"), | |
238 Include("expr"), | |
239 Default(Pop(1)), | |
240 }, | |
241 "class-method": { | |
242 Include("spaces"), | |
243 {`(?:_*[a-z]\w*|_+[0-9]\w*|_*[A-Z]\w*|_+|\$\w+)`, NameFunction, Push("#pop", "optional-expr", "flag", "function-param", "parenthesis-open", "type-param-constraint")}, | |
244 }, | |
245 "function-param": { | |
246 Include("spaces"), | |
247 {`\)`, Punctuation, Pop(1)}, | |
248 {`\?`, Punctuation, nil}, | |
249 {`(?!(?:function|class|static|var|if|else|while|do|for|break|return|continue|extends|implements|import|switch|case|default|public|private|try|untyped|catch|new|this|throw|extern|enum|in|interface|cast|override|dynamic|typedef|package|inline|using|null|true|false|abstract)\b)(?:_*[a-z]\w*|_+[0-9]\w*|_*[A-Z]\w*|_+|\$\w+)`, Name, Push("#pop", "function-param-sep", "assign", "flag")}, | |
250 }, | |
251 "function-param-sep": { | |
252 Include("spaces"), | |
253 {`\)`, Punctuation, Pop(1)}, | |
254 {`,`, Punctuation, Push("#pop", "function-param")}, | |
255 }, | |
256 "prop-get-set": { | |
257 Include("spaces"), | |
258 {`\(`, Punctuation, Push("#pop", "parenthesis-close", "prop-get-set-opt", "comma", "prop-get-set-opt")}, | |
259 Default(Pop(1)), | |
260 }, | |
261 "prop-get-set-opt": { | |
262 Include("spaces"), | |
263 {`(?:default|null|never|dynamic|get|set)\b`, Keyword, Pop(1)}, | |
264 {`(?!(?:function|class|static|var|if|else|while|do|for|break|return|continue|extends|implements|import|switch|case|default|public|private|try|untyped|catch|new|this|throw|extern|enum|in|interface|cast|override|dynamic|typedef|package|inline|using|null|true|false|abstract)\b)(?:_*[a-z]\w*|_+[0-9]\w*|_*[A-Z]\w*|_+|\$\w+)`, Text, Pop(1)}, | |
265 }, | |
266 "expr-statement": { | |
267 Include("spaces"), | |
268 Default(Pop(1), Push("optional-semicolon"), Push("expr")), | |
269 }, | |
270 "expr": { | |
271 Include("spaces"), | |
272 {`@`, NameDecorator, Push("#pop", "optional-expr", "meta-body", "meta-ident", "meta-colon")}, | |
273 {`(?:\+\+|\-\-|~(?!/)|!|\-)`, Operator, nil}, | |
274 {`\(`, Punctuation, Push("#pop", "expr-chain", "parenthesis")}, | |
275 {`(?:static|public|private|override|dynamic|inline)\b`, KeywordDeclaration, nil}, | |
276 {`(?:function)\b`, KeywordDeclaration, Push("#pop", "expr-chain", "function-local")}, | |
277 {`\{`, Punctuation, Push("#pop", "expr-chain", "bracket")}, | |
278 {`(?:true|false|null)\b`, KeywordConstant, Push("#pop", "expr-chain")}, | |
279 {`(?:this)\b`, Keyword, Push("#pop", "expr-chain")}, | |
280 {`(?:cast)\b`, Keyword, Push("#pop", "expr-chain", "cast")}, | |
281 {`(?:try)\b`, Keyword, Push("#pop", "catch", "expr")}, | |
282 {`(?:var)\b`, KeywordDeclaration, Push("#pop", "var")}, | |
283 {`(?:new)\b`, Keyword, Push("#pop", "expr-chain", "new")}, | |
284 {`(?:switch)\b`, Keyword, Push("#pop", "switch")}, | |
285 {`(?:if)\b`, Keyword, Push("#pop", "if")}, | |
286 {`(?:do)\b`, Keyword, Push("#pop", "do")}, | |
287 {`(?:while)\b`, Keyword, Push("#pop", "while")}, | |
288 {`(?:for)\b`, Keyword, Push("#pop", "for")}, | |
289 {`(?:untyped|throw)\b`, Keyword, nil}, | |
290 {`(?:return)\b`, Keyword, Push("#pop", "optional-expr")}, | |
291 {`(?:macro)\b`, Keyword, Push("#pop", "macro")}, | |
292 {`(?:continue|break)\b`, Keyword, Pop(1)}, | |
293 {`(?:\$\s*[a-z]\b|\$(?!(?:_*[a-z]\w*|_+[0-9]\w*|_*[A-Z]\w*|_+|\$\w+)))`, Name, Push("#pop", "dollar")}, | |
294 {`(?!(?:function|class|static|var|if|else|while|do|for|break|return|continue|extends|implements|import|switch|case|default|public|private|try|untyped|catch|new|this|throw|extern|enum|in|interface|cast|override|dynamic|typedef|package|inline|using|null|true|false|abstract)\b)(?:_*[a-z]\w*|_+[0-9]\w*|_*[A-Z]\w*|_+|\$\w+)`, Name, Push("#pop", "expr-chain")}, | |
295 {`\.[0-9]+`, LiteralNumberFloat, Push("#pop", "expr-chain")}, | |
296 {`[0-9]+[eE][+\-]?[0-9]+`, LiteralNumberFloat, Push("#pop", "expr-chain")}, | |
297 {`[0-9]+\.[0-9]*[eE][+\-]?[0-9]+`, LiteralNumberFloat, Push("#pop", "expr-chain")}, | |
298 {`[0-9]+\.[0-9]+`, LiteralNumberFloat, Push("#pop", "expr-chain")}, | |
299 {`[0-9]+\.(?!(?:_*[a-z]\w*|_+[0-9]\w*|_*[A-Z]\w*|_+|\$\w+)|\.\.)`, LiteralNumberFloat, Push("#pop", "expr-chain")}, | |
300 {`0x[0-9a-fA-F]+`, LiteralNumberHex, Push("#pop", "expr-chain")}, | |
301 {`[0-9]+`, LiteralNumberInteger, Push("#pop", "expr-chain")}, | |
302 {`'`, LiteralStringSingle, Push("#pop", "expr-chain", "string-single-interpol")}, | |
303 {`"`, LiteralStringDouble, Push("#pop", "expr-chain", "string-double")}, | |
304 {`~/(\\\\|\\/|[^/\n])*/[gimsu]*`, LiteralStringRegex, Push("#pop", "expr-chain")}, | |
305 {`\[`, Punctuation, Push("#pop", "expr-chain", "array-decl")}, | |
306 }, | |
307 "expr-chain": { | |
308 Include("spaces"), | |
309 {`(?:\+\+|\-\-)`, Operator, nil}, | |
310 {`(?:%=|&=|\|=|\^=|\+=|\-=|\*=|/=|<<=|>\s*>\s*=|>\s*>\s*>\s*=|==|!=|<=|>\s*=|&&|\|\||<<|>>>|>\s*>|\.\.\.|<|>|%|&|\||\^|\+|\*|/|\-|=>|=)`, Operator, Push("#pop", "expr")}, | |
311 {`(?:in)\b`, Keyword, Push("#pop", "expr")}, | |
312 {`\?`, Operator, Push("#pop", "expr", "ternary", "expr")}, | |
313 {`(\.)((?!(?:function|class|static|var|if|else|while|do|for|break|return|continue|extends|implements|import|switch|case|default|public|private|try|untyped|catch|new|this|throw|extern|enum|in|interface|cast|override|dynamic|typedef|package|inline|using|null|true|false|abstract)\b)(?:_*[a-z]\w*|_+[0-9]\w*|_*[A-Z]\w*|_+|\$\w+))`, ByGroups(Punctuation, Name), nil}, | |
314 {`\[`, Punctuation, Push("array-access")}, | |
315 {`\(`, Punctuation, Push("call")}, | |
316 Default(Pop(1)), | |
317 }, | |
318 "macro": { | |
319 Include("spaces"), | |
320 Include("meta"), | |
321 {`:`, Punctuation, Push("#pop", "type")}, | |
322 {`(?:extern|private)\b`, KeywordDeclaration, nil}, | |
323 {`(?:abstract)\b`, KeywordDeclaration, Push("#pop", "optional-semicolon", "abstract")}, | |
324 {`(?:class|interface)\b`, KeywordDeclaration, Push("#pop", "optional-semicolon", "macro-class")}, | |
325 {`(?:enum)\b`, KeywordDeclaration, Push("#pop", "optional-semicolon", "enum")}, | |
326 {`(?:typedef)\b`, KeywordDeclaration, Push("#pop", "optional-semicolon", "typedef")}, | |
327 Default(Pop(1), Push("expr")), | |
328 }, | |
329 "macro-class": { | |
330 {`\{`, Punctuation, Push("#pop", "class-body")}, | |
331 Include("class"), | |
332 }, | |
333 "cast": { | |
334 Include("spaces"), | |
335 {`\(`, Punctuation, Push("#pop", "parenthesis-close", "cast-type", "expr")}, | |
336 Default(Pop(1), Push("expr")), | |
337 }, | |
338 "cast-type": { | |
339 Include("spaces"), | |
340 {`,`, Punctuation, Push("#pop", "type")}, | |
341 Default(Pop(1)), | |
342 }, | |
343 "catch": { | |
344 Include("spaces"), | |
345 {`(?:catch)\b`, Keyword, Push("expr", "function-param", "parenthesis-open")}, | |
346 Default(Pop(1)), | |
347 }, | |
348 "do": { | |
349 Include("spaces"), | |
350 Default(Pop(1), Push("do-while"), Push("expr")), | |
351 }, | |
352 "do-while": { | |
353 Include("spaces"), | |
354 {`(?:while)\b`, Keyword, Push("#pop", "parenthesis", "parenthesis-open")}, | |
355 }, | |
356 "while": { | |
357 Include("spaces"), | |
358 {`\(`, Punctuation, Push("#pop", "expr", "parenthesis")}, | |
359 }, | |
360 "for": { | |
361 Include("spaces"), | |
362 {`\(`, Punctuation, Push("#pop", "expr", "parenthesis")}, | |
363 }, | |
364 "if": { | |
365 Include("spaces"), | |
366 {`\(`, Punctuation, Push("#pop", "else", "optional-semicolon", "expr", "parenthesis")}, | |
367 }, | |
368 "else": { | |
369 Include("spaces"), | |
370 {`(?:else)\b`, Keyword, Push("#pop", "expr")}, | |
371 Default(Pop(1)), | |
372 }, | |
373 "switch": { | |
374 Include("spaces"), | |
375 Default(Pop(1), Push("switch-body"), Push("bracket-open"), Push("expr")), | |
376 }, | |
377 "switch-body": { | |
378 Include("spaces"), | |
379 {`(?:case|default)\b`, Keyword, Push("case-block", "case")}, | |
380 {`\}`, Punctuation, Pop(1)}, | |
381 }, | |
382 "case": { | |
383 Include("spaces"), | |
384 {`:`, Punctuation, Pop(1)}, | |
385 Default(Pop(1), Push("case-sep"), Push("case-guard"), Push("expr")), | |
386 }, | |
387 "case-sep": { | |
388 Include("spaces"), | |
389 {`:`, Punctuation, Pop(1)}, | |
390 {`,`, Punctuation, Push("#pop", "case")}, | |
391 }, | |
392 "case-guard": { | |
393 Include("spaces"), | |
394 {`(?:if)\b`, Keyword, Push("#pop", "parenthesis", "parenthesis-open")}, | |
395 Default(Pop(1)), | |
396 }, | |
397 "case-block": { | |
398 Include("spaces"), | |
399 {`(?!(?:case|default)\b|\})`, Keyword, Push("expr-statement")}, | |
400 Default(Pop(1)), | |
401 }, | |
402 "new": { | |
403 Include("spaces"), | |
404 Default(Pop(1), Push("call"), Push("parenthesis-open"), Push("type")), | |
405 }, | |
406 "array-decl": { | |
407 Include("spaces"), | |
408 {`\]`, Punctuation, Pop(1)}, | |
409 Default(Pop(1), Push("array-decl-sep"), Push("expr")), | |
410 }, | |
411 "array-decl-sep": { | |
412 Include("spaces"), | |
413 {`\]`, Punctuation, Pop(1)}, | |
414 {`,`, Punctuation, Push("#pop", "array-decl")}, | |
415 }, | |
416 "array-access": { | |
417 Include("spaces"), | |
418 Default(Pop(1), Push("array-access-close"), Push("expr")), | |
419 }, | |
420 "array-access-close": { | |
421 Include("spaces"), | |
422 {`\]`, Punctuation, Pop(1)}, | |
423 }, | |
424 "comma": { | |
425 Include("spaces"), | |
426 {`,`, Punctuation, Pop(1)}, | |
427 }, | |
428 "colon": { | |
429 Include("spaces"), | |
430 {`:`, Punctuation, Pop(1)}, | |
431 }, | |
432 "semicolon": { | |
433 Include("spaces"), | |
434 {`;`, Punctuation, Pop(1)}, | |
435 }, | |
436 "optional-semicolon": { | |
437 Include("spaces"), | |
438 {`;`, Punctuation, Pop(1)}, | |
439 Default(Pop(1)), | |
440 }, | |
441 "ident": { | |
442 Include("spaces"), | |
443 {`(?:_*[a-z]\w*|_+[0-9]\w*|_*[A-Z]\w*|_+|\$\w+)`, Name, Pop(1)}, | |
444 }, | |
445 "dollar": { | |
446 Include("spaces"), | |
447 {`\{`, Punctuation, Push("#pop", "expr-chain", "bracket-close", "expr")}, | |
448 Default(Pop(1), Push("expr-chain")), | |
449 }, | |
450 "type-name": { | |
451 Include("spaces"), | |
452 {`_*[A-Z]\w*`, Name, Pop(1)}, | |
453 }, | |
454 "type-full-name": { | |
455 Include("spaces"), | |
456 {`\.`, Punctuation, Push("ident")}, | |
457 Default(Pop(1)), | |
458 }, | |
459 "type": { | |
460 Include("spaces"), | |
461 {`\?`, Punctuation, nil}, | |
462 {`(?:_*[a-z]\w*|_+[0-9]\w*|_*[A-Z]\w*|_+|\$\w+)`, Name, Push("#pop", "type-check", "type-full-name")}, | |
463 {`\{`, Punctuation, Push("#pop", "type-check", "type-struct")}, | |
464 {`\(`, Punctuation, Push("#pop", "type-check", "type-parenthesis")}, | |
465 }, | |
466 "type-parenthesis": { | |
467 Include("spaces"), | |
468 Default(Pop(1), Push("parenthesis-close"), Push("type")), | |
469 }, | |
470 "type-check": { | |
471 Include("spaces"), | |
472 {`->`, Punctuation, Push("#pop", "type")}, | |
473 {`<(?!=)`, Punctuation, Push("type-param")}, | |
474 Default(Pop(1)), | |
475 }, | |
476 "type-struct": { | |
477 Include("spaces"), | |
478 {`\}`, Punctuation, Pop(1)}, | |
479 {`\?`, Punctuation, nil}, | |
480 {`>`, Punctuation, Push("comma", "type")}, | |
481 {`(?!(?:function|class|static|var|if|else|while|do|for|break|return|continue|extends|implements|import|switch|case|default|public|private|try|untyped|catch|new|this|throw|extern|enum|in|interface|cast|override|dynamic|typedef|package|inline|using|null|true|false|abstract)\b)(?:_*[a-z]\w*|_+[0-9]\w*|_*[A-Z]\w*|_+|\$\w+)`, Name, Push("#pop", "type-struct-sep", "type", "colon")}, | |
482 Include("class-body"), | |
483 }, | |
484 "type-struct-sep": { | |
485 Include("spaces"), | |
486 {`\}`, Punctuation, Pop(1)}, | |
487 {`,`, Punctuation, Push("#pop", "type-struct")}, | |
488 }, | |
489 "type-param-type": { | |
490 {`\.[0-9]+`, LiteralNumberFloat, Pop(1)}, | |
491 {`[0-9]+[eE][+\-]?[0-9]+`, LiteralNumberFloat, Pop(1)}, | |
492 {`[0-9]+\.[0-9]*[eE][+\-]?[0-9]+`, LiteralNumberFloat, Pop(1)}, | |
493 {`[0-9]+\.[0-9]+`, LiteralNumberFloat, Pop(1)}, | |
494 {`[0-9]+\.(?!(?:_*[a-z]\w*|_+[0-9]\w*|_*[A-Z]\w*|_+|\$\w+)|\.\.)`, LiteralNumberFloat, Pop(1)}, | |
495 {`0x[0-9a-fA-F]+`, LiteralNumberHex, Pop(1)}, | |
496 {`[0-9]+`, LiteralNumberInteger, Pop(1)}, | |
497 {`'`, LiteralStringSingle, Push("#pop", "string-single")}, | |
498 {`"`, LiteralStringDouble, Push("#pop", "string-double")}, | |
499 {`~/(\\\\|\\/|[^/\n])*/[gim]*`, LiteralStringRegex, Pop(1)}, | |
500 {`\[`, Operator, Push("#pop", "array-decl")}, | |
501 Include("type"), | |
502 }, | |
503 "type-param": { | |
504 Include("spaces"), | |
505 Default(Pop(1), Push("type-param-sep"), Push("type-param-type")), | |
506 }, | |
507 "type-param-sep": { | |
508 Include("spaces"), | |
509 {`>`, Punctuation, Pop(1)}, | |
510 {`,`, Punctuation, Push("#pop", "type-param")}, | |
511 }, | |
512 "type-param-constraint": { | |
513 Include("spaces"), | |
514 {`<(?!=)`, Punctuation, Push("#pop", "type-param-constraint-sep", "type-param-constraint-flag", "type-name")}, | |
515 Default(Pop(1)), | |
516 }, | |
517 "type-param-constraint-sep": { | |
518 Include("spaces"), | |
519 {`>`, Punctuation, Pop(1)}, | |
520 {`,`, Punctuation, Push("#pop", "type-param-constraint-sep", "type-param-constraint-flag", "type-name")}, | |
521 }, | |
522 "type-param-constraint-flag": { | |
523 Include("spaces"), | |
524 {`:`, Punctuation, Push("#pop", "type-param-constraint-flag-type")}, | |
525 Default(Pop(1)), | |
526 }, | |
527 "type-param-constraint-flag-type": { | |
528 Include("spaces"), | |
529 {`\(`, Punctuation, Push("#pop", "type-param-constraint-flag-type-sep", "type")}, | |
530 Default(Pop(1), Push("type")), | |
531 }, | |
532 "type-param-constraint-flag-type-sep": { | |
533 Include("spaces"), | |
534 {`\)`, Punctuation, Pop(1)}, | |
535 {`,`, Punctuation, Push("type")}, | |
536 }, | |
537 "parenthesis": { | |
538 Include("spaces"), | |
539 Default(Pop(1), Push("parenthesis-close"), Push("flag"), Push("expr")), | |
540 }, | |
541 "parenthesis-open": { | |
542 Include("spaces"), | |
543 {`\(`, Punctuation, Pop(1)}, | |
544 }, | |
545 "parenthesis-close": { | |
546 Include("spaces"), | |
547 {`\)`, Punctuation, Pop(1)}, | |
548 }, | |
549 "var": { | |
550 Include("spaces"), | |
551 {`(?!(?:function|class|static|var|if|else|while|do|for|break|return|continue|extends|implements|import|switch|case|default|public|private|try|untyped|catch|new|this|throw|extern|enum|in|interface|cast|override|dynamic|typedef|package|inline|using|null|true|false|abstract)\b)(?:_*[a-z]\w*|_+[0-9]\w*|_*[A-Z]\w*|_+|\$\w+)`, Text, Push("#pop", "var-sep", "assign", "flag", "prop-get-set")}, | |
552 }, | |
553 "var-sep": { | |
554 Include("spaces"), | |
555 {`,`, Punctuation, Push("#pop", "var")}, | |
556 Default(Pop(1)), | |
557 }, | |
558 "assign": { | |
559 Include("spaces"), | |
560 {`=`, Operator, Push("#pop", "expr")}, | |
561 Default(Pop(1)), | |
562 }, | |
563 "flag": { | |
564 Include("spaces"), | |
565 {`:`, Punctuation, Push("#pop", "type")}, | |
566 Default(Pop(1)), | |
567 }, | |
568 "ternary": { | |
569 Include("spaces"), | |
570 {`:`, Operator, Pop(1)}, | |
571 }, | |
572 "call": { | |
573 Include("spaces"), | |
574 {`\)`, Punctuation, Pop(1)}, | |
575 Default(Pop(1), Push("call-sep"), Push("expr")), | |
576 }, | |
577 "call-sep": { | |
578 Include("spaces"), | |
579 {`\)`, Punctuation, Pop(1)}, | |
580 {`,`, Punctuation, Push("#pop", "call")}, | |
581 }, | |
582 "bracket": { | |
583 Include("spaces"), | |
584 {`(?!(?:\$\s*[a-z]\b|\$(?!(?:_*[a-z]\w*|_+[0-9]\w*|_*[A-Z]\w*|_+|\$\w+))))(?!(?:function|class|static|var|if|else|while|do|for|break|return|continue|extends|implements|import|switch|case|default|public|private|try|untyped|catch|new|this|throw|extern|enum|in|interface|cast|override|dynamic|typedef|package|inline|using|null|true|false|abstract)\b)(?:_*[a-z]\w*|_+[0-9]\w*|_*[A-Z]\w*|_+|\$\w+)`, Name, Push("#pop", "bracket-check")}, | |
585 {`'`, LiteralStringSingle, Push("#pop", "bracket-check", "string-single")}, | |
586 {`"`, LiteralStringDouble, Push("#pop", "bracket-check", "string-double")}, | |
587 Default(Pop(1), Push("block")), | |
588 }, | |
589 "bracket-check": { | |
590 Include("spaces"), | |
591 {`:`, Punctuation, Push("#pop", "object-sep", "expr")}, | |
592 Default(Pop(1), Push("block"), Push("optional-semicolon"), Push("expr-chain")), | |
593 }, | |
594 "block": { | |
595 Include("spaces"), | |
596 {`\}`, Punctuation, Pop(1)}, | |
597 Default(Push("expr-statement")), | |
598 }, | |
599 "object": { | |
600 Include("spaces"), | |
601 {`\}`, Punctuation, Pop(1)}, | |
602 Default(Pop(1), Push("object-sep"), Push("expr"), Push("colon"), Push("ident-or-string")), | |
603 }, | |
604 "ident-or-string": { | |
605 Include("spaces"), | |
606 {`(?!(?:function|class|static|var|if|else|while|do|for|break|return|continue|extends|implements|import|switch|case|default|public|private|try|untyped|catch|new|this|throw|extern|enum|in|interface|cast|override|dynamic|typedef|package|inline|using|null|true|false|abstract)\b)(?:_*[a-z]\w*|_+[0-9]\w*|_*[A-Z]\w*|_+|\$\w+)`, Name, Pop(1)}, | |
607 {`'`, LiteralStringSingle, Push("#pop", "string-single")}, | |
608 {`"`, LiteralStringDouble, Push("#pop", "string-double")}, | |
609 }, | |
610 "object-sep": { | |
611 Include("spaces"), | |
612 {`\}`, Punctuation, Pop(1)}, | |
613 {`,`, Punctuation, Push("#pop", "object")}, | |
614 }, | |
615 } | |
616 } | |
617 | |
618 func haxePreProcMutator(state *LexerState) error { | |
619 stack, ok := state.Get("haxe-pre-proc").([][]string) | |
620 if !ok { | |
621 stack = [][]string{} | |
622 } | |
623 | |
624 proc := state.Groups[2] | |
625 switch proc { | |
626 case "if": | |
627 stack = append(stack, state.Stack) | |
628 case "else", "elseif": | |
629 if len(stack) > 0 { | |
630 state.Stack = stack[len(stack)-1] | |
631 } | |
632 case "end": | |
633 stack = stack[:len(stack)-1] | |
634 } | |
635 | |
636 if proc == "if" || proc == "elseif" { | |
637 state.Stack = append(state.Stack, "preproc-expr") | |
638 } | |
639 | |
640 if proc == "error" { | |
641 state.Stack = append(state.Stack, "preproc-error") | |
642 } | |
643 state.Set("haxe-pre-proc", stack) | |
644 return nil | |
645 } |