diff options
-rw-r--r-- | pygments/lexers/web.py | 54 | ||||
-rw-r--r-- | tests/examplefiles/example.hx | 45 |
2 files changed, 85 insertions, 14 deletions
diff --git a/pygments/lexers/web.py b/pygments/lexers/web.py index 65d07a1c..f7f2b7ef 100644 --- a/pygments/lexers/web.py +++ b/pygments/lexers/web.py @@ -1297,6 +1297,19 @@ class HaxeLexer(ExtendedRegexLexer): (r'\(', Comment.Preproc, ('#pop', 'preproc-parenthesis')), (ident, Comment.Preproc, '#pop'), + + # Float + (r'\.[0-9]+', Number.Float), + (r'[0-9]+[eE][\+\-]?[0-9]+', Number.Float), + (r'[0-9]+\.[0-9]*[eE][\+\-]?[0-9]+', Number.Float), + (r'[0-9]+\.[0-9]+', Number.Float), + (r'[0-9]+\.(?!' + ident + '|\.\.)', Number.Float), + + # Int + (r'0x[0-9a-fA-F]+', Number.Hex), + (r'[0-9]+', Number.Integer), + + # String (r"'", String.Single, ('#pop', 'string-single')), (r'"', String.Double, ('#pop', 'string-double')), ], @@ -1321,6 +1334,19 @@ class HaxeLexer(ExtendedRegexLexer): ('#pop', 'preproc-expr-chain', 'preproc-parenthesis')), (ident, Comment.Preproc, ('#pop', 'preproc-expr-chain')), + + # Float + (r'\.[0-9]+', Number.Float, ('#pop', 'preproc-expr-chain')), + (r'[0-9]+[eE][\+\-]?[0-9]+', Number.Float, ('#pop', 'preproc-expr-chain')), + (r'[0-9]+\.[0-9]*[eE][\+\-]?[0-9]+', Number.Float, ('#pop', 'preproc-expr-chain')), + (r'[0-9]+\.[0-9]+', Number.Float, ('#pop', 'preproc-expr-chain')), + (r'[0-9]+\.(?!' + ident + '|\.\.)', Number.Float, ('#pop', 'preproc-expr-chain')), + + # Int + (r'0x[0-9a-fA-F]+', Number.Hex, ('#pop', 'preproc-expr-chain')), + (r'[0-9]+', Number.Integer, ('#pop', 'preproc-expr-chain')), + + # String (r"'", String.Single, ('#pop', 'preproc-expr-chain', 'string-single')), (r'"', String.Double, @@ -1454,7 +1480,7 @@ class HaxeLexer(ExtendedRegexLexer): 'class-member': [ include('spaces'), (r'(var)\b', Keyword.Declaration, - ('#pop', 'optional-semicolon', 'prop')), + ('#pop', 'optional-semicolon', 'var')), (r'(function)\b', Keyword.Declaration, ('#pop', 'optional-semicolon', 'class-method')), ], @@ -1463,7 +1489,7 @@ class HaxeLexer(ExtendedRegexLexer): 'function-local': [ include('spaces'), (r'(' + ident_no_keyword + ')?', Name.Function, - ('#pop', 'expr', 'flag', 'function-param', + ('#pop', 'optional-expr', 'flag', 'function-param', 'parenthesis-open', 'type-param-constraint')), ], @@ -1495,13 +1521,6 @@ class HaxeLexer(ExtendedRegexLexer): (r',', Punctuation, ('#pop', 'function-param')), ], - # class property - # eg. var prop(default, null):String; - 'prop': [ - include('spaces'), - (ident_no_keyword, Name, ('#pop', 'assign', 'flag', 'prop-get-set')), - ], - 'prop-get-set': [ include('spaces'), (r'\(', Punctuation, ('#pop', 'parenthesis-close', @@ -1528,7 +1547,8 @@ class HaxeLexer(ExtendedRegexLexer): 'meta-ident', 'meta-colon')), (r'(?:\+\+|\-\-|~(?!/)|!|\-)', Operator), (r'\(', Punctuation, ('#pop', 'expr-chain', 'parenthesis')), - (r'(?:inline)\b', Keyword.Declaration), + (r'(?:static|public|private|override|dynamic|inline)\b', + Keyword.Declaration), (r'(?:function)\b', Keyword.Declaration, ('#pop', 'expr-chain', 'function-local')), (r'\{', Punctuation, ('#pop', 'expr-chain', 'bracket')), @@ -1587,7 +1607,15 @@ class HaxeLexer(ExtendedRegexLexer): # macro reification 'macro': [ include('spaces'), + include('meta'), (r':', Punctuation, ('#pop', 'type')), + + (r'(?:extern|private)\b', Keyword.Declaration), + (r'(?:abstract)\b', Keyword.Declaration, 'abstract'), + (r'(?:class|interface)\b', Keyword.Declaration, 'class'), + (r'(?:enum)\b', Keyword.Declaration, 'enum'), + (r'(?:typedef)\b', Keyword.Declaration, 'typedef'), + (r'', Text, ('#pop', 'expr')), ], @@ -1740,7 +1768,7 @@ class HaxeLexer(ExtendedRegexLexer): 'dollar': [ include('spaces'), - (r'\{', Keyword, ('#pop', 'bracket-close', 'expr')), + (r'\{', Punctuation, ('#pop', 'expr-chain', 'bracket-close', 'expr')), (r'', Text, ('#pop', 'expr-chain')), ], @@ -1868,7 +1896,7 @@ class HaxeLexer(ExtendedRegexLexer): # a parenthesis expr that contain exactly one expr 'parenthesis': [ include('spaces'), - (r'', Text, ('#pop', 'parenthesis-close', 'expr')), + (r'', Text, ('#pop', 'parenthesis-close', 'flag', 'expr')), ], 'parenthesis-open': [ @@ -1883,7 +1911,7 @@ class HaxeLexer(ExtendedRegexLexer): 'var': [ include('spaces'), - (ident_no_keyword, Text, ('#pop', 'var-sep', 'assign', 'flag')), + (ident_no_keyword, Text, ('#pop', 'var-sep', 'assign', 'flag', 'prop-get-set')), ], # optional more var decl. diff --git a/tests/examplefiles/example.hx b/tests/examplefiles/example.hx index fd93bb49..76749c0a 100644 --- a/tests/examplefiles/example.hx +++ b/tests/examplefiles/example.hx @@ -139,4 +139,47 @@ typedef Pt2 = { y:Float, ?z:Float, //optional z add : Point -> Void, -}
\ No newline at end of file +} + + +//top-level class members +public function test(); +private var attr(get, set) = 1; + + +//pre-proc number +public static inline function indexOf<T>(arr:Array<T>, v:T) : Int +{ + #if (haxe_ver >= 3.1) + return arr.indexOf(v); + #else + #if (flash || js) + return untyped arr.indexOf(v); + #else + return std.Lambda.indexOf(arr, v); + #end + #end +} + +//macro reification +var e = macro var $myVar = 0; +var e = macro ${v}.toLowerCase(); +var e = macro o.$myField; +var e = macro { $myField : 0 }; +var e = macro $i{varName}++; +var e = macro $v{myStr}; +var args = [macro "sub", macro 3]; +var e = macro "Hello".toLowerCase($a{args}); +(macro $i{tmp}.addAtom($v{name}, $atom)).finalize(op.pos); + +var c = macro class MyClass { + public function new() { } + public function $funcName() { + trace($v{funcName} + " was called"); + } +} + +var c = macro interface IClass {} + +//ECheckType +var f = (123:Float);
\ No newline at end of file |