ThirdParty/Pygments/pygments/lexers/dsls.py

changeset 4697
c2e9bf425554
parent 4172
4f20dba37ab6
child 5713
6762afd9f963
equal deleted inserted replaced
4696:bf4d19a7cade 4697:c2e9bf425554
3 pygments.lexers.dsls 3 pygments.lexers.dsls
4 ~~~~~~~~~~~~~~~~~~~~ 4 ~~~~~~~~~~~~~~~~~~~~
5 5
6 Lexers for various domain-specific languages. 6 Lexers for various domain-specific languages.
7 7
8 :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS. 8 :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
9 :license: BSD, see LICENSE for details. 9 :license: BSD, see LICENSE for details.
10 """ 10 """
11 11
12 import re 12 import re
13 13
14 from pygments.lexer import RegexLexer, bygroups, words, include, default 14 from pygments.lexer import RegexLexer, bygroups, words, include, default, \
15 this, using, combined
15 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ 16 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
16 Number, Punctuation, Literal 17 Number, Punctuation, Literal, Whitespace
17 18
18 __all__ = ['ProtoBufLexer', 'BroLexer', 'PuppetLexer', 'RslLexer', 19 __all__ = ['ProtoBufLexer', 'BroLexer', 'PuppetLexer', 'RslLexer',
19 'MscgenLexer', 'VGLLexer', 'AlloyLexer', 'PanLexer'] 20 'MscgenLexer', 'VGLLexer', 'AlloyLexer', 'PanLexer',
21 'CrmshLexer', 'ThriftLexer']
20 22
21 23
22 class ProtoBufLexer(RegexLexer): 24 class ProtoBufLexer(RegexLexer):
23 """ 25 """
24 Lexer for `Protocol Buffer <http://code.google.com/p/protobuf/>`_ 26 Lexer for `Protocol Buffer <http://code.google.com/p/protobuf/>`_
75 default('#pop'), 77 default('#pop'),
76 ], 78 ],
77 'type': [ 79 'type': [
78 (r'[a-zA-Z_]\w*', Name, '#pop'), 80 (r'[a-zA-Z_]\w*', Name, '#pop'),
79 default('#pop'), 81 default('#pop'),
82 ],
83 }
84
85
86 class ThriftLexer(RegexLexer):
87 """
88 For `Thrift <https://thrift.apache.org/>`__ interface definitions.
89
90 .. versionadded:: 2.1
91 """
92 name = 'Thrift'
93 aliases = ['thrift']
94 filenames = ['*.thrift']
95 mimetypes = ['application/x-thrift']
96
97 tokens = {
98 'root': [
99 include('whitespace'),
100 include('comments'),
101 (r'"', String.Double, combined('stringescape', 'dqs')),
102 (r'\'', String.Single, combined('stringescape', 'sqs')),
103 (r'(namespace)(\s+)',
104 bygroups(Keyword.Namespace, Text.Whitespace), 'namespace'),
105 (r'(enum|union|struct|service|exception)(\s+)',
106 bygroups(Keyword.Declaration, Text.Whitespace), 'class'),
107 (r'((?:(?:[^\W\d]|\$)[\w.\[\]$<>]*\s+)+?)' # return arguments
108 r'((?:[^\W\d]|\$)[\w$]*)' # method name
109 r'(\s*)(\()', # signature start
110 bygroups(using(this), Name.Function, Text, Operator)),
111 include('keywords'),
112 include('numbers'),
113 (r'[&=]', Operator),
114 (r'[:;\,\{\}\(\)\<>\[\]]', Punctuation),
115 (r'[a-zA-Z_](\.[a-zA-Z_0-9]|[a-zA-Z_0-9])*', Name),
116 ],
117 'whitespace': [
118 (r'\n', Text.Whitespace),
119 (r'\s+', Text.Whitespace),
120 ],
121 'comments': [
122 (r'#.*$', Comment),
123 (r'//.*?\n', Comment),
124 (r'/\*[\w\W]*?\*/', Comment.Multiline),
125 ],
126 'stringescape': [
127 (r'\\([\\nrt"\'])', String.Escape),
128 ],
129 'dqs': [
130 (r'"', String.Double, '#pop'),
131 (r'[^\\"\n]+', String.Double),
132 ],
133 'sqs': [
134 (r"'", String.Single, '#pop'),
135 (r'[^\\\'\n]+', String.Single),
136 ],
137 'namespace': [
138 (r'[a-z\*](\.[a-zA-Z_0-9]|[a-zA-Z_0-9])*', Name.Namespace, '#pop'),
139 default('#pop'),
140 ],
141 'class': [
142 (r'[a-zA-Z_]\w*', Name.Class, '#pop'),
143 default('#pop'),
144 ],
145 'keywords': [
146 (r'(async|oneway|extends|throws|required|optional)\b', Keyword),
147 (r'(true|false)\b', Keyword.Constant),
148 (r'(const|typedef)\b', Keyword.Declaration),
149 (words((
150 'cpp_namespace', 'cpp_include', 'cpp_type', 'java_package',
151 'cocoa_prefix', 'csharp_namespace', 'delphi_namespace',
152 'php_namespace', 'py_module', 'perl_package',
153 'ruby_namespace', 'smalltalk_category', 'smalltalk_prefix',
154 'xsd_all', 'xsd_optional', 'xsd_nillable', 'xsd_namespace',
155 'xsd_attrs', 'include'), suffix=r'\b'),
156 Keyword.Namespace),
157 (words((
158 'void', 'bool', 'byte', 'i16', 'i32', 'i64', 'double',
159 'string', 'binary', 'void', 'map', 'list', 'set', 'slist',
160 'senum'), suffix=r'\b'),
161 Keyword.Type),
162 (words((
163 'BEGIN', 'END', '__CLASS__', '__DIR__', '__FILE__',
164 '__FUNCTION__', '__LINE__', '__METHOD__', '__NAMESPACE__',
165 'abstract', 'alias', 'and', 'args', 'as', 'assert', 'begin',
166 'break', 'case', 'catch', 'class', 'clone', 'continue',
167 'declare', 'def', 'default', 'del', 'delete', 'do', 'dynamic',
168 'elif', 'else', 'elseif', 'elsif', 'end', 'enddeclare',
169 'endfor', 'endforeach', 'endif', 'endswitch', 'endwhile',
170 'ensure', 'except', 'exec', 'finally', 'float', 'for',
171 'foreach', 'function', 'global', 'goto', 'if', 'implements',
172 'import', 'in', 'inline', 'instanceof', 'interface', 'is',
173 'lambda', 'module', 'native', 'new', 'next', 'nil', 'not',
174 'or', 'pass', 'public', 'print', 'private', 'protected',
175 'raise', 'redo', 'rescue', 'retry', 'register', 'return',
176 'self', 'sizeof', 'static', 'super', 'switch', 'synchronized',
177 'then', 'this', 'throw', 'transient', 'try', 'undef',
178 'unless', 'unsigned', 'until', 'use', 'var', 'virtual',
179 'volatile', 'when', 'while', 'with', 'xor', 'yield'),
180 prefix=r'\b', suffix=r'\b'),
181 Keyword.Reserved),
182 ],
183 'numbers': [
184 (r'[+-]?(\d+\.\d+([eE][+-]?\d+)?|\.?\d+[eE][+-]?\d+)', Number.Float),
185 (r'[+-]?0x[0-9A-Fa-f]+', Number.Hex),
186 (r'[+-]?[0-9]+', Number.Integer),
80 ], 187 ],
81 } 188 }
82 189
83 190
84 class BroLexer(RegexLexer): 191 class BroLexer(RegexLexer):
469 (r'\{', Keyword, 'curly'), 576 (r'\{', Keyword, 'curly'),
470 include('data'), 577 include('data'),
471 ], 578 ],
472 'basic': [ 579 'basic': [
473 (words(( 580 (words((
474 'if', 'for', 'with', 'else', 'type', 'bind', 'while', 'valid', 'final', 'prefix', 581 'if', 'for', 'with', 'else', 'type', 'bind', 'while', 'valid', 'final',
475 'unique', 'object', 'foreach', 'include', 'template', 'function', 'variable', 582 'prefix', 'unique', 'object', 'foreach', 'include', 'template',
476 'structure', 'extensible', 'declaration'), prefix=r'\b', suffix=r'\s*\b'), 583 'function', 'variable', 'structure', 'extensible', 'declaration'),
584 prefix=r'\b', suffix=r'\s*\b'),
477 Keyword), 585 Keyword),
478 (words(( 586 (words((
479 'file_contents', 'format', 'index', 'length', 'match', 'matches', 'replace', 587 'file_contents', 'format', 'index', 'length', 'match', 'matches',
480 'splice', 'split', 'substr', 'to_lowercase', 'to_uppercase', 'debug', 'error', 588 'replace', 'splice', 'split', 'substr', 'to_lowercase', 'to_uppercase',
481 'traceback', 'deprecated', 'base64_decode', 'base64_encode', 'digest', 'escape', 589 'debug', 'error', 'traceback', 'deprecated', 'base64_decode',
482 'unescape', 'append', 'create', 'first', 'nlist', 'key', 'list', 'merge', 'next', 590 'base64_encode', 'digest', 'escape', 'unescape', 'append', 'create',
483 'prepend', 'is_boolean', 'is_defined', 'is_double', 'is_list', 'is_long', 591 'first', 'nlist', 'key', 'list', 'merge', 'next', 'prepend', 'is_boolean',
484 'is_nlist', 'is_null', 'is_number', 'is_property', 'is_resource', 'is_string', 592 'is_defined', 'is_double', 'is_list', 'is_long', 'is_nlist', 'is_null',
485 'to_boolean', 'to_double', 'to_long', 'to_string', 'clone', 'delete', 'exists', 593 'is_number', 'is_property', 'is_resource', 'is_string', 'to_boolean',
486 'path_exists', 'if_exists', 'return', 'value'), prefix=r'\b', suffix=r'\s*\b'), 594 'to_double', 'to_long', 'to_string', 'clone', 'delete', 'exists',
595 'path_exists', 'if_exists', 'return', 'value'),
596 prefix=r'\b', suffix=r'\s*\b'),
487 Name.Builtin), 597 Name.Builtin),
488 (r'#.*', Comment), 598 (r'#.*', Comment),
489 (r'\\[\w\W]', String.Escape), 599 (r'\\[\w\W]', String.Escape),
490 (r'(\b\w+)(\s*)(=)', bygroups(Name.Variable, Text, Operator)), 600 (r'(\b\w+)(\s*)(=)', bygroups(Name.Variable, Text, Operator)),
491 (r'[\[\]{}()=]+', Operator), 601 (r'[\[\]{}()=]+', Operator),
510 'paren': [ 620 'paren': [
511 (r'\)', Keyword, '#pop'), 621 (r'\)', Keyword, '#pop'),
512 include('root'), 622 include('root'),
513 ], 623 ],
514 } 624 }
625
626
627 class CrmshLexer(RegexLexer):
628 """
629 Lexer for `crmsh <http://crmsh.github.io/>`_ configuration files
630 for Pacemaker clusters.
631
632 .. versionadded:: 2.1
633 """
634 name = 'Crmsh'
635 aliases = ['crmsh', 'pcmk']
636 filenames = ['*.crmsh', '*.pcmk']
637 mimetypes = []
638
639 elem = words((
640 'node', 'primitive', 'group', 'clone', 'ms', 'location',
641 'colocation', 'order', 'fencing_topology', 'rsc_ticket',
642 'rsc_template', 'property', 'rsc_defaults',
643 'op_defaults', 'acl_target', 'acl_group', 'user', 'role',
644 'tag'), suffix=r'(?![\w#$-])')
645 sub = words((
646 'params', 'meta', 'operations', 'op', 'rule',
647 'attributes', 'utilization'), suffix=r'(?![\w#$-])')
648 acl = words(('read', 'write', 'deny'), suffix=r'(?![\w#$-])')
649 bin_rel = words(('and', 'or'), suffix=r'(?![\w#$-])')
650 un_ops = words(('defined', 'not_defined'), suffix=r'(?![\w#$-])')
651 date_exp = words(('in_range', 'date', 'spec', 'in'), suffix=r'(?![\w#$-])')
652 acl_mod = (r'(?:tag|ref|reference|attribute|type|xpath)')
653 bin_ops = (r'(?:lt|gt|lte|gte|eq|ne)')
654 val_qual = (r'(?:string|version|number)')
655 rsc_role_action = (r'(?:Master|Started|Slave|Stopped|'
656 r'start|promote|demote|stop)')
657
658 tokens = {
659 'root': [
660 (r'^#.*\n?', Comment),
661 # attr=value (nvpair)
662 (r'([\w#$-]+)(=)("(?:""|[^"])*"|\S+)',
663 bygroups(Name.Attribute, Punctuation, String)),
664 # need this construct, otherwise numeric node ids
665 # are matched as scores
666 # elem id:
667 (r'(node)(\s+)([\w#$-]+)(:)',
668 bygroups(Keyword, Whitespace, Name, Punctuation)),
669 # scores
670 (r'([+-]?([0-9]+|inf)):', Number),
671 # keywords (elements and other)
672 (elem, Keyword),
673 (sub, Keyword),
674 (acl, Keyword),
675 # binary operators
676 (r'(?:%s:)?(%s)(?![\w#$-])' % (val_qual, bin_ops), Operator.Word),
677 # other operators
678 (bin_rel, Operator.Word),
679 (un_ops, Operator.Word),
680 (date_exp, Operator.Word),
681 # builtin attributes (e.g. #uname)
682 (r'#[a-z]+(?![\w#$-])', Name.Builtin),
683 # acl_mod:blah
684 (r'(%s)(:)("(?:""|[^"])*"|\S+)' % acl_mod,
685 bygroups(Keyword, Punctuation, Name)),
686 # rsc_id[:(role|action)]
687 # NB: this matches all other identifiers
688 (r'([\w#$-]+)(?:(:)(%s))?(?![\w#$-])' % rsc_role_action,
689 bygroups(Name, Punctuation, Operator.Word)),
690 # punctuation
691 (r'(\\(?=\n)|[[\](){}/:@])', Punctuation),
692 (r'\s+|\n', Whitespace),
693 ],
694 }

eric ide

mercurial