diff options
author | Andy Li <andy@onthewings.net> | 2013-02-22 04:05:44 +0800 |
---|---|---|
committer | Andy Li <andy@onthewings.net> | 2013-02-22 04:05:44 +0800 |
commit | 5c449dd859b694ee5a8ea14140a7be03f5316388 (patch) | |
tree | 3725a7f41aebe6c5cba5207928fd454ff04f7271 | |
parent | 9f55ab87e7f817e902c18ef08d06744f3ff59482 (diff) | |
download | pygments-5c449dd859b694ee5a8ea14140a7be03f5316388.tar.gz |
Improved preproc to actually allow binops inside parenthesis. Fixed meta with no expr.
-rw-r--r-- | pygments/lexers/web.py | 48 |
1 files changed, 38 insertions, 10 deletions
diff --git a/pygments/lexers/web.py b/pygments/lexers/web.py index 88f15af7..e14f7217 100644 --- a/pygments/lexers/web.py +++ b/pygments/lexers/web.py @@ -1151,6 +1151,8 @@ class HaxeLexer(ExtendedRegexLexer): # combined ident and dollar and idtype ident = r'(?:_*[a-z][_a-zA-Z0-9]*|_+[0-9][_a-zA-Z0-9]*|' + typeid + '|_+|\$[_a-zA-Z0-9]+)' + binop = r'(?:%=|&=|\|=|\^=|\+=|\-=|\*=|/=|<<=|>\s*>\s*=|>\s*>\s*>\s*=|==|!=|<=|>\s*=|&&|\|\||<<|>>>|>\s*>|\.\.\.|<|>|%|&|\||\^|\+|\*|/|\-|=>|=)' + # ident except keywords ident_no_keyword = r'(?!' + keyword + ')' + ident @@ -1273,22 +1275,36 @@ class HaxeLexer(ExtendedRegexLexer): 'preproc-expr': [ (r'\s+', Comment.Preproc), (r'\!', Comment.Preproc), - (r'\(', Comment.Preproc, ('#pop', 'preproc-expr-chain', 'preproc-parenthesis')), + (r'\(', Comment.Preproc, ('#pop', 'preproc-parenthesis')), # Haxe preproc name can contains '-' - (ident + r'(?:-' + ident + ')*', Comment.Preproc, ('#pop', 'preproc-expr-chain')), + (ident + r'(?:-' + ident + ')*', Comment.Preproc, '#pop'), + (r"'", String.Single, ('#pop', 'string-single')), + (r'"', String.Double, ('#pop', 'string-double')), + ], + + 'preproc-parenthesis': [ + (r'\s+', Comment.Preproc), + (r'\)', Comment.Preproc, '#pop'), + ('', Text, 'preproc-expr-in-parenthesis'), ], 'preproc-expr-chain': [ (r'\s+', Comment.Preproc), - (r'(?:&&|\|\|)', Comment.Preproc, ('#pop', 'preproc-expr')), + (binop, Comment.Preproc, ('#pop', 'preproc-expr-in-parenthesis')), (r'', Text, '#pop'), ], - - 'preproc-parenthesis': [ + + # same as 'preproc-expr' but able to chain 'preproc-expr-chain' + 'preproc-expr-in-parenthesis': [ (r'\s+', Comment.Preproc), - (r'\)', Comment.Preproc, '#pop'), - ('', Text, 'preproc-expr'), + (r'\!', Comment.Preproc), + (r'\(', Comment.Preproc, ('#pop', 'preproc-expr-chain', 'preproc-parenthesis')), + + # Haxe preproc name can contains '-' + (ident + r'(?:-' + ident + ')*', Comment.Preproc, ('#pop', 'preproc-expr-chain')), + (r"'", String.Single, ('#pop', 'preproc-expr-chain', 'string-single')), + (r'"', String.Double, ('#pop', 'preproc-expr-chain', 'string-double')), ], 'abstract' : [ @@ -1334,10 +1350,22 @@ class HaxeLexer(ExtendedRegexLexer): 'meta-body': [ include('spaces'), - (r'\(', Punctuation, ('#pop', 'call')), + (r'\(', Name.Decorator, ('#pop', 'meta-call')), (r'', Text, '#pop'), ], + 'meta-call': [ + include('spaces'), + (r'\)', Name.Decorator, '#pop'), + (r'', Text, ('#pop', 'meta-call-sep', 'expr')), + ], + + 'meta-call-sep': [ + include('spaces'), + (r'\)', Name.Decorator, '#pop'), + (r',', Punctuation, ('#pop', 'meta-call')), + ], + 'typedef': [ include('spaces'), (r'', Text, ('#pop', 'typedef-body', 'type-param-constraint', 'type-name')), @@ -1460,7 +1488,7 @@ class HaxeLexer(ExtendedRegexLexer): 'expr': [ include('spaces'), - include('meta'), + (r'@', Name.Decorator, ('#pop', 'optional-expr', 'meta-body', 'meta-ident', 'meta-colon')), (r'(?:\+\+|\-\-|~(?!/)|!|\-)', Operator), (r'\(', Punctuation, ('#pop', 'expr-chain', 'parenthesis')), (r'(?:inline)\b', Keyword.Declaration), @@ -1509,7 +1537,7 @@ class HaxeLexer(ExtendedRegexLexer): 'expr-chain': [ include('spaces'), (r'(?:\+\+|\-\-)', Operator), - (r'(?:%=|&=|\|=|\^=|\+=|\-=|\*=|/=|<<=|>\s*>\s*=|>\s*>\s*>\s*=|==|!=|<=|>\s*=|&&|\|\||<<|>>>|>\s*>|\.\.\.|<|>|%|&|\||\^|\+|\*|/|\-|=>|=)', Operator, ('#pop', 'expr')), + (binop, Operator, ('#pop', 'expr')), (r'(?:in)\b', Keyword, ('#pop', 'expr')), (r'\?', Operator, ('#pop', 'expr', 'ternary', 'expr')), (r'(\.)(' + ident_no_keyword + ')', bygroups(Punctuation, Name)), |