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