capnproto

FORK: Cap'n Proto serialization/RPC system - core tools and C++ library
git clone https://git.neptards.moe/neptards/capnproto.git
Log | Files | Refs | README | LICENSE

capnp_lexer.py (2117B)


      1 #! /usr/bin/env python
      2 
      3 from pygments.lexer import RegexLexer
      4 from pygments.token import *
      5 
      6 class CapnpLexer(RegexLexer):
      7     name = "Cap'n Proto lexer"
      8     aliases = ['capnp']
      9     filenames = ['*.capnp']
     10 
     11     tokens = {
     12         'root': [
     13             (r'#.*?$', Comment.Single),
     14             (r'@[0-9a-zA-Z]*', Name.Decorator),
     15             (r'=', Literal, 'expression'),
     16             (r':', Name.Class, 'type'),
     17             (r'\$', Name.Attribute, 'annotation'),
     18             (r'(struct|enum|interface|union|import|using|const|annotation|extends|in|of|on|as|with|from|fixed|bulk|realtime)\b',
     19                 Token.Keyword),
     20             (r'[a-zA-Z0-9_.]+', Token.Name),
     21             (r'[^#@=:$a-zA-Z0-9_]+', Text),
     22         ],
     23         'type': [
     24             (r'[^][=;,(){}$]+', Name.Class),
     25             (r'[[(]', Name.Class, 'parentype'),
     26             (r'', Name.Class, '#pop')
     27         ],
     28         'parentype': [
     29             (r'[^][;()]+', Name.Class),
     30             (r'[[(]', Name.Class, '#push'),
     31             (r'[])]', Name.Class, '#pop'),
     32             (r'', Name.Class, '#pop')
     33         ],
     34         'expression': [
     35             (r'[^][;,(){}$]+', Literal),
     36             (r'[[(]', Literal, 'parenexp'),
     37             (r'', Literal, '#pop')
     38         ],
     39         'parenexp': [
     40             (r'[^][;()]+', Literal),
     41             (r'[[(]', Literal, '#push'),
     42             (r'[])]', Literal, '#pop'),
     43             (r'', Literal, '#pop')
     44         ],
     45         'annotation': [
     46             (r'[^][;,(){}=:]+', Name.Attribute),
     47             (r'[[(]', Name.Attribute, 'annexp'),
     48             (r'', Name.Attribute, '#pop')
     49         ],
     50         'annexp': [
     51             (r'[^][;()]+', Name.Attribute),
     52             (r'[[(]', Name.Attribute, '#push'),
     53             (r'[])]', Name.Attribute, '#pop'),
     54             (r'', Name.Attribute, '#pop')
     55         ],
     56     }
     57 
     58 if __name__ == "__main__":
     59     from setuptools import setup, find_packages
     60     setup(name = "CapnpPygmentsLexer",
     61           version = "0.1",
     62           packages = find_packages(),
     63           py_modules = [ 'capnp_lexer' ],
     64           entry_points = {'pygments.lexers': 'capnp = capnp_lexer:CapnpLexer'})