eric6/ThirdParty/Pygments/pygments/lexers/dsls.py

changeset 7547
21b0534faebc
parent 6942
2602857055c5
child 7701
25f42e208e08
equal deleted inserted replaced
7546:bf5f777260a6 7547:21b0534faebc
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-2017 by the Pygments team, see AUTHORS. 8 :copyright: Copyright 2006-2019 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 ExtendedRegexLexer, RegexLexer, bygroups, words, \ 14 from pygments.lexer import ExtendedRegexLexer, RegexLexer, bygroups, words, \
15 include, default, this, using, combined 15 include, default, this, using, combined
16 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ 16 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
17 Number, Punctuation, Literal, Whitespace 17 Number, Punctuation, Literal, Whitespace
18 18
19 __all__ = ['ProtoBufLexer', 'BroLexer', 'PuppetLexer', 'RslLexer', 19 __all__ = ['ProtoBufLexer', 'ZeekLexer', 'PuppetLexer', 'RslLexer',
20 'MscgenLexer', 'VGLLexer', 'AlloyLexer', 'PanLexer', 20 'MscgenLexer', 'VGLLexer', 'AlloyLexer', 'PanLexer',
21 'CrmshLexer', 'ThriftLexer', 'FlatlineLexer', 'SnowballLexer'] 21 'CrmshLexer', 'ThriftLexer', 'FlatlineLexer', 'SnowballLexer']
22 22
23 23
24 class ProtoBufLexer(RegexLexer): 24 class ProtoBufLexer(RegexLexer):
38 (r'[ \t]+', Text), 38 (r'[ \t]+', Text),
39 (r'[,;{}\[\]()<>]', Punctuation), 39 (r'[,;{}\[\]()<>]', Punctuation),
40 (r'/(\\\n)?/(\n|(.|\n)*?[^\\]\n)', Comment.Single), 40 (r'/(\\\n)?/(\n|(.|\n)*?[^\\]\n)', Comment.Single),
41 (r'/(\\\n)?\*(.|\n)*?\*(\\\n)?/', Comment.Multiline), 41 (r'/(\\\n)?\*(.|\n)*?\*(\\\n)?/', Comment.Multiline),
42 (words(( 42 (words((
43 'import', 'option', 'optional', 'required', 'repeated', 'default', 43 'import', 'option', 'optional', 'required', 'repeated',
44 'packed', 'ctype', 'extensions', 'to', 'max', 'rpc', 'returns', 44 'reserved', 'default', 'packed', 'ctype', 'extensions', 'to',
45 'oneof'), prefix=r'\b', suffix=r'\b'), 45 'max', 'rpc', 'returns', 'oneof'), prefix=r'\b', suffix=r'\b'),
46 Keyword), 46 Keyword),
47 (words(( 47 (words((
48 'int32', 'int64', 'uint32', 'uint64', 'sint32', 'sint64', 48 'int32', 'int64', 'uint32', 'uint64', 'sint32', 'sint64',
49 'fixed32', 'fixed64', 'sfixed32', 'sfixed64', 49 'fixed32', 'fixed64', 'sfixed32', 'sfixed64',
50 'float', 'double', 'bool', 'string', 'bytes'), suffix=r'\b'), 50 'float', 'double', 'bool', 'string', 'bytes'), suffix=r'\b'),
186 (r'[+-]?[0-9]+', Number.Integer), 186 (r'[+-]?[0-9]+', Number.Integer),
187 ], 187 ],
188 } 188 }
189 189
190 190
191 class BroLexer(RegexLexer): 191 class ZeekLexer(RegexLexer):
192 """ 192 """
193 For `Bro <http://bro-ids.org/>`_ scripts. 193 For `Zeek <https://www.zeek.org/>`_ scripts.
194 194
195 .. versionadded:: 1.5 195 .. versionadded:: 2.5
196 """ 196 """
197 name = 'Bro' 197 name = 'Zeek'
198 aliases = ['bro'] 198 aliases = ['zeek', 'bro']
199 filenames = ['*.bro'] 199 filenames = ['*.zeek', '*.bro']
200 200
201 _hex = r'[0-9a-fA-F_]' 201 _hex = r'[0-9a-fA-F]'
202 _float = r'((\d*\.?\d+)|(\d+\.?\d*))([eE][-+]?\d+)?' 202 _float = r'((\d*\.?\d+)|(\d+\.?\d*))([eE][-+]?\d+)?'
203 _h = r'[A-Za-z0-9][-A-Za-z0-9]*' 203 _h = r'[A-Za-z0-9][-A-Za-z0-9]*'
204 204
205 tokens = { 205 tokens = {
206 'root': [ 206 'root': [
207 # Whitespace 207 include('whitespace'),
208 (r'^@.*?\n', Comment.Preproc), 208 include('comments'),
209 (r'#.*?\n', Comment.Single), 209 include('directives'),
210 include('attributes'),
211 include('types'),
212 include('keywords'),
213 include('literals'),
214 include('operators'),
215 include('punctuation'),
216 (r'((?:[A-Za-z_]\w*)(?:::(?:[A-Za-z_]\w*))*)(?=\s*\()',
217 Name.Function),
218 include('identifiers'),
219 ],
220
221 'whitespace': [
210 (r'\n', Text), 222 (r'\n', Text),
211 (r'\s+', Text), 223 (r'\s+', Text),
212 (r'\\\n', Text), 224 (r'\\\n', Text),
213 # Keywords 225 ],
214 (r'(add|alarm|break|case|const|continue|delete|do|else|enum|event' 226
215 r'|export|for|function|if|global|hook|local|module|next' 227 'comments': [
216 r'|of|print|redef|return|schedule|switch|type|when|while)\b', Keyword), 228 (r'#.*$', Comment),
217 (r'(addr|any|bool|count|counter|double|file|int|interval|net' 229 ],
218 r'|pattern|port|record|set|string|subnet|table|time|timer' 230
219 r'|vector)\b', Keyword.Type), 231 'directives': [
232 (r'@(load-plugin|load-sigs|load|unload)\b.*$', Comment.Preproc),
233 (r'@(DEBUG|DIR|FILENAME|deprecated|if|ifdef|ifndef|else|endif)\b', Comment.Preproc),
234 (r'(@prefixes)\s*(\+?=).*$', Comment.Preproc),
235 ],
236
237 'attributes': [
238 (words(('redef', 'priority', 'log', 'optional', 'default', 'add_func',
239 'delete_func', 'expire_func', 'read_expire', 'write_expire',
240 'create_expire', 'synchronized', 'persistent', 'rotate_interval',
241 'rotate_size', 'encrypt', 'raw_output', 'mergeable', 'error_handler',
242 'type_column', 'deprecated'),
243 prefix=r'&', suffix=r'\b'),
244 Keyword.Pseudo),
245 ],
246
247 'types': [
248 (words(('any',
249 'enum', 'record', 'set', 'table', 'vector',
250 'function', 'hook', 'event',
251 'addr', 'bool', 'count', 'double', 'file', 'int', 'interval',
252 'pattern', 'port', 'string', 'subnet', 'time'),
253 suffix=r'\b'),
254 Keyword.Type),
255
256 (r'(opaque)(\s+)(of)(\s+)((?:[A-Za-z_]\w*)(?:::(?:[A-Za-z_]\w*))*)\b',
257 bygroups(Keyword.Type, Text, Operator.Word, Text, Keyword.Type)),
258
259 (r'(type)(\s+)((?:[A-Za-z_]\w*)(?:::(?:[A-Za-z_]\w*))*)(\s*)(:)(\s*)\b(record|enum)\b',
260 bygroups(Keyword, Text, Name.Class, Text, Operator, Text, Keyword.Type)),
261
262 (r'(type)(\s+)((?:[A-Za-z_]\w*)(?:::(?:[A-Za-z_]\w*))*)(\s*)(:)',
263 bygroups(Keyword, Text, Name, Text, Operator)),
264
265 (r'(redef)(\s+)(record|enum)(\s+)((?:[A-Za-z_]\w*)(?:::(?:[A-Za-z_]\w*))*)\b',
266 bygroups(Keyword, Text, Keyword.Type, Text, Name.Class)),
267 ],
268
269 'keywords': [
270 (words(('redef', 'export', 'if', 'else', 'for', 'while',
271 'return', 'break', 'next', 'continue', 'fallthrough',
272 'switch', 'default', 'case',
273 'add', 'delete',
274 'when', 'timeout', 'schedule'),
275 suffix=r'\b'),
276 Keyword),
277 (r'(print)\b', Keyword),
278 (r'(global|local|const|option)\b', Keyword.Declaration),
279 (r'(module)(\s+)(([A-Za-z_]\w*)(?:::([A-Za-z_]\w*))*)\b',
280 bygroups(Keyword.Namespace, Text, Name.Namespace)),
281 ],
282
283 'literals': [
284 (r'"', String, 'string'),
285
286 # Not the greatest match for patterns, but generally helps
287 # disambiguate between start of a pattern and just a division
288 # operator.
289 (r'/(?=.*/)', String.Regex, 'regex'),
290
220 (r'(T|F)\b', Keyword.Constant), 291 (r'(T|F)\b', Keyword.Constant),
221 (r'(&)((?:add|delete|expire)_func|attr|(?:create|read|write)_expire' 292
222 r'|default|disable_print_hook|raw_output|encrypt|group|log' 293 # Port
223 r'|mergeable|optional|persistent|priority|redef' 294 (r'\d{1,5}/(udp|tcp|icmp|unknown)\b', Number),
224 r'|rotate_(?:interval|size)|synchronized)\b', 295
225 bygroups(Punctuation, Keyword)), 296 # IPv4 Address
226 (r'\s+module\b', Keyword.Namespace), 297 (r'(\d{1,3}.){3}(\d{1,3})\b', Number),
227 # Addresses, ports and networks 298
228 (r'\d+/(tcp|udp|icmp|unknown)\b', Number), 299 # IPv6 Address
229 (r'(\d+\.){3}\d+', Number), 300 (r'\[([0-9a-fA-F]{0,4}:){2,7}([0-9a-fA-F]{0,4})?((\d{1,3}.){3}(\d{1,3}))?\]', Number),
230 (r'(' + _hex + r'){7}' + _hex, Number), 301
231 (r'0x' + _hex + r'(' + _hex + r'|:)*::(' + _hex + r'|:)*', Number), 302 # Numeric
232 (r'((\d+|:)(' + _hex + r'|:)*)?::(' + _hex + r'|:)*', Number), 303 (r'0[xX]' + _hex + r'+\b', Number.Hex),
233 (r'(\d+\.\d+\.|(\d+\.){2}\d+)', Number), 304 (_float + r'\s*(day|hr|min|sec|msec|usec)s?\b', Number.Float),
305 (_float + r'\b', Number.Float),
306 (r'(\d+)\b', Number.Integer),
307
234 # Hostnames 308 # Hostnames
235 (_h + r'(\.' + _h + r')+', String), 309 (_h + r'(\.' + _h + r')+', String),
236 # Numeric 310 ],
237 (_float + r'\s+(day|hr|min|sec|msec|usec)s?\b', Literal.Date), 311
238 (r'0[xX]' + _hex, Number.Hex), 312 'operators': [
239 (_float, Number.Float), 313 (r'[!%*/+<=>~|&^-]', Operator),
240 (r'\d+', Number.Integer),
241 (r'/', String.Regex, 'regex'),
242 (r'"', String, 'string'),
243 # Operators
244 (r'[!%*/+:<=>?~|-]', Operator),
245 (r'([-+=&|]{2}|[+=!><-]=)', Operator), 314 (r'([-+=&|]{2}|[+=!><-]=)', Operator),
246 (r'(in|match)\b', Operator.Word), 315 (r'(in|as|is|of)\b', Operator.Word),
247 (r'[{}()\[\]$.,;]', Punctuation), 316 (r'\??\$', Operator),
248 # Identfier 317 ],
249 (r'([_a-zA-Z]\w*)(::)', bygroups(Name, Name.Namespace)), 318
319 'punctuation': [
320 (r'[{}()\[\],;.]', Punctuation),
321 # The "ternary if", which uses '?' and ':', could instead be
322 # treated as an Operator, but colons are more frequently used to
323 # separate field/identifier names from their types, so the (often)
324 # less-prominent Punctuation is used even with '?' for consistency.
325 (r'[?:]', Punctuation),
326 ],
327
328 'identifiers': [
329 (r'([a-zA-Z_]\w*)(::)', bygroups(Name, Punctuation)),
250 (r'[a-zA-Z_]\w*', Name) 330 (r'[a-zA-Z_]\w*', Name)
251 ], 331 ],
332
252 'string': [ 333 'string': [
334 (r'\\.', String.Escape),
335 (r'%-?[0-9]*(\.[0-9]+)?[DTdxsefg]', String.Escape),
253 (r'"', String, '#pop'), 336 (r'"', String, '#pop'),
254 (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape), 337 (r'.', String),
255 (r'[^\\"\n]+', String), 338 ],
256 (r'\\\n', String), 339
257 (r'\\', String)
258 ],
259 'regex': [ 340 'regex': [
341 (r'\\.', String.Escape),
260 (r'/', String.Regex, '#pop'), 342 (r'/', String.Regex, '#pop'),
261 (r'\\[\\nt/]', String.Regex), # String.Escape is too intense here. 343 (r'.', String.Regex),
262 (r'[^\\/\n]+', String.Regex), 344 ],
263 (r'\\\n', String.Regex), 345 }
264 (r'\\', String.Regex) 346
265 ] 347
266 } 348 BroLexer = ZeekLexer
267 349
268 350
269 class PuppetLexer(RegexLexer): 351 class PuppetLexer(RegexLexer):
270 """ 352 """
271 For `Puppet <http://puppetlabs.com/>`__ configuration DSL. 353 For `Puppet <http://puppetlabs.com/>`__ configuration DSL.
556 } 638 }
557 639
558 640
559 class PanLexer(RegexLexer): 641 class PanLexer(RegexLexer):
560 """ 642 """
561 Lexer for `pan <http://github.com/quattor/pan/>`_ source files. 643 Lexer for `pan <https://github.com/quattor/pan/>`_ source files.
562 644
563 Based on tcsh lexer. 645 Based on tcsh lexer.
564 646
565 .. versionadded:: 2.0 647 .. versionadded:: 2.0
566 """ 648 """

eric ide

mercurial