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