diff options
author | Corey Richardson <corey@octayn.net> | 2016-05-19 06:45:10 +1000 |
---|---|---|
committer | Corey Richardson <corey@octayn.net> | 2016-05-19 06:45:10 +1000 |
commit | 2030bc55da7b11c58cd6f25d113f85da8bbff28c (patch) | |
tree | fe97700316114869ba4b3d2dbde60e65c536a54c /pygments/lexers/capnproto.py | |
parent | 83170e453264e080993aaf9bfdff5be8b989d119 (diff) | |
download | pygments-2030bc55da7b11c58cd6f25d113f85da8bbff28c.tar.gz |
Cap'n Proto: use the upstream lexer
Diffstat (limited to 'pygments/lexers/capnproto.py')
-rw-r--r-- | pygments/lexers/capnproto.py | 72 |
1 files changed, 43 insertions, 29 deletions
diff --git a/pygments/lexers/capnproto.py b/pygments/lexers/capnproto.py index 585f3b4b..f9c11330 100644 --- a/pygments/lexers/capnproto.py +++ b/pygments/lexers/capnproto.py @@ -13,7 +13,7 @@ import re from pygments.lexer import RegexLexer, bygroups, words from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ - Number, Punctuation + Number, Punctuation, Literal __all__ = ['CapnProtoLexer'] @@ -30,36 +30,50 @@ class CapnProtoLexer(RegexLexer): flags = re.MULTILINE | re.UNICODE + tokens = { 'root': [ - (r'(\s|\ufeff)+', Text), - (r'(struct|union|enum|const|interface|annotation)(\s+)([A-Z]\w*)', - bygroups(Keyword.Declaration, Text, Name.Class)), - (r'(using|import)\b', Keyword.Namespace), - (r':(Void|Bool|U?Int(8|16|32|64)|Float(32|64)|Text|Data|' - r'List|AnyPointer|Capability|' - r'union|group)', Keyword.Type), - (r':[.a-zA-Z0-9]+', Name), - (r'\b(true|false|void)\b', Keyword.Constant), - (r'@(0x[a-fA-F0-9]+|\d+)', Keyword.Constant), - (r'0x"[^"]+"', String), - (r'0x[a-fA-F0-9]+', Number.Hex), - (r'\d+\.\d*([eE][+-]?\d+)?', Number.Float), - (r'\d+([eE][+-]?\d+)?', Number.Float), - (r'\d+', Number.Integer), - (r'"', String, 'string'), - (r'#.*$', Comment), - (r'\w+', Name), - (r'[!$%&*+-./<=>?@^|~]+', Operator), - (r'[{}()\[\],;]', Punctuation), + (r'#.*?$', Comment.Single), + (r'@[0-9a-zA-Z]*', Name.Decorator), + (r'=', Literal, 'expression'), + (r':', Name.Class, 'type'), + (r'\$', Name.Attribute, 'annotation'), + (r'(struct|enum|interface|union|import|using|const|annotation|extends|in|of|on|as|with|from|fixed)\b', + Keyword), + (r'[a-zA-Z0-9_.]+', Name), + (r'[^#@=:$a-zA-Z0-9_]+', Text), + ], + 'type': [ + (r'[^][=;,(){}$]+', Name.Class), + (r'[[(]', Name.Class, 'parentype'), + (r'', Name.Class, '#pop') + ], + 'parentype': [ + (r'[^][;()]+', Name.Class), + (r'[[(]', Name.Class, '#push'), + (r'[])]', Name.Class, '#pop'), + (r'', Name.Class, '#pop') + ], + 'expression': [ + (r'[^][;,(){}$]+', Literal), + (r'[[(]', Literal, 'parenexp'), + (r'', Literal, '#pop') + ], + 'parenexp': [ + (r'[^][;()]+', Literal), + (r'[[(]', Literal, '#push'), + (r'[])]', Literal, '#pop'), + (r'', Literal, '#pop') + ], + 'annotation': [ + (r'[^][;,(){}=:]+', Name.Attribute), + (r'[[(]', Name.Attribute, 'annexp'), + (r'', Name.Attribute, '#pop') ], - 'string': [ - (r'"', String, '#pop'), - (r'[^\\"]+', String), - (r'\\[abfnrtv\'"\\]', String.Escape), - # hex - (r'\\x[a-fA-F0-9]{2}', String.Escape), - # octal - (r'\\[0-7]{3}', String.Escape), + 'annexp': [ + (r'[^][;()]+', Name.Attribute), + (r'[[(]', Name.Attribute, '#push'), + (r'[])]', Name.Attribute, '#pop'), + (r'', Name.Attribute, '#pop') ], } |