ThirdParty/Pygments/pygments/lexers/javascript.py

changeset 4697
c2e9bf425554
parent 4172
4f20dba37ab6
child 5713
6762afd9f963
equal deleted inserted replaced
4696:bf4d19a7cade 4697:c2e9bf425554
3 pygments.lexers.javascript 3 pygments.lexers.javascript
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~ 4 ~~~~~~~~~~~~~~~~~~~~~~~~~~
5 5
6 Lexers for JavaScript and related languages. 6 Lexers for JavaScript and related 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, include, bygroups, default, using, this 14 from pygments.lexer import RegexLexer, include, bygroups, default, using, \
15 this, words, 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, Other 17 Number, Punctuation, Other
17 from pygments.util import get_bool_opt, iteritems 18 from pygments.util import get_bool_opt, iteritems
18 import pygments.unistring as uni 19 import pygments.unistring as uni
19 20
20 __all__ = ['JavascriptLexer', 'KalLexer', 'LiveScriptLexer', 'DartLexer', 21 __all__ = ['JavascriptLexer', 'KalLexer', 'LiveScriptLexer', 'DartLexer',
21 'TypeScriptLexer', 'LassoLexer', 'ObjectiveJLexer', 22 'TypeScriptLexer', 'LassoLexer', 'ObjectiveJLexer',
22 'CoffeeScriptLexer', 'MaskLexer'] 23 'CoffeeScriptLexer', 'MaskLexer', 'EarlGreyLexer']
23 24
24 JS_IDENT_START = ('(?:[$_' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl') + 25 JS_IDENT_START = ('(?:[$_' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl') +
25 ']|\\\\u[a-fA-F0-9]{4})') 26 ']|\\\\u[a-fA-F0-9]{4})')
26 JS_IDENT_PART = ('(?:[$' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl', 27 JS_IDENT_PART = ('(?:[$' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl',
27 'Mn', 'Mc', 'Nd', 'Pc') + 28 'Mn', 'Mc', 'Nd', 'Pc') +
34 For JavaScript source code. 35 For JavaScript source code.
35 """ 36 """
36 37
37 name = 'JavaScript' 38 name = 'JavaScript'
38 aliases = ['js', 'javascript'] 39 aliases = ['js', 'javascript']
39 filenames = ['*.js', ] 40 filenames = ['*.js', '*.jsm']
40 mimetypes = ['application/javascript', 'application/x-javascript', 41 mimetypes = ['application/javascript', 'application/x-javascript',
41 'text/x-javascript', 'text/javascript', ] 42 'text/x-javascript', 'text/javascript']
42 43
43 flags = re.DOTALL | re.UNICODE | re.MULTILINE 44 flags = re.DOTALL | re.UNICODE | re.MULTILINE
44 45
45 tokens = { 46 tokens = {
46 'commentsandwhitespace': [ 47 'commentsandwhitespace': [
58 ], 59 ],
59 'badregex': [ 60 'badregex': [
60 (r'\n', Text, '#pop') 61 (r'\n', Text, '#pop')
61 ], 62 ],
62 'root': [ 63 'root': [
63 (r'\A#! ?/.*?\n', Comment), # shebang lines are recognized by node.js 64 (r'\A#! ?/.*?\n', Comment.Hashbang), # recognized by node.js
64 (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), 65 (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'),
65 include('commentsandwhitespace'), 66 include('commentsandwhitespace'),
66 (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|' 67 (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|'
67 r'(<<|>>>?|==?|!=?|[-<>+*%&|^/])=?', Operator, 'slashstartsregex'), 68 r'(<<|>>>?|=>|==?|!=?|[-<>+*%&|^/])=?', Operator, 'slashstartsregex'),
69 (r'\.\.\.', Punctuation),
68 (r'[{(\[;,]', Punctuation, 'slashstartsregex'), 70 (r'[{(\[;,]', Punctuation, 'slashstartsregex'),
69 (r'[})\].]', Punctuation), 71 (r'[})\].]', Punctuation),
70 (r'(for|in|while|do|break|return|continue|switch|case|default|if|else|' 72 (r'(for|in|while|do|break|return|continue|switch|case|default|if|else|'
71 r'throw|try|catch|finally|new|delete|typeof|instanceof|void|yield|' 73 r'throw|try|catch|finally|new|delete|typeof|instanceof|void|yield|'
72 r'this)\b', Keyword, 'slashstartsregex'), 74 r'this|of)\b', Keyword, 'slashstartsregex'),
73 (r'(var|let|with|function)\b', Keyword.Declaration, 'slashstartsregex'), 75 (r'(var|let|with|function)\b', Keyword.Declaration, 'slashstartsregex'),
74 (r'(abstract|boolean|byte|char|class|const|debugger|double|enum|export|' 76 (r'(abstract|boolean|byte|char|class|const|debugger|double|enum|export|'
75 r'extends|final|float|goto|implements|import|int|interface|long|native|' 77 r'extends|final|float|goto|implements|import|int|interface|long|native|'
76 r'package|private|protected|public|short|static|super|synchronized|throws|' 78 r'package|private|protected|public|short|static|super|synchronized|throws|'
77 r'transient|volatile)\b', Keyword.Reserved), 79 r'transient|volatile)\b', Keyword.Reserved),
78 (r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant), 80 (r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant),
79 (r'(Array|Boolean|Date|Error|Function|Math|netscape|' 81 (r'(Array|Boolean|Date|Error|Function|Math|netscape|'
80 r'Number|Object|Packages|RegExp|String|sun|decodeURI|' 82 r'Number|Object|Packages|RegExp|String|Promise|Proxy|sun|decodeURI|'
81 r'decodeURIComponent|encodeURI|encodeURIComponent|' 83 r'decodeURIComponent|encodeURI|encodeURIComponent|'
82 r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|' 84 r'Error|eval|isFinite|isNaN|isSafeInteger|parseFloat|parseInt|'
83 r'window)\b', Name.Builtin), 85 r'document|this|window)\b', Name.Builtin),
84 (JS_IDENT, Name.Other), 86 (JS_IDENT, Name.Other),
85 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), 87 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
88 (r'0b[01]+', Number.Bin),
89 (r'0o[0-7]+', Number.Oct),
86 (r'0x[0-9a-fA-F]+', Number.Hex), 90 (r'0x[0-9a-fA-F]+', Number.Hex),
87 (r'[0-9]+', Number.Integer), 91 (r'[0-9]+', Number.Integer),
88 (r'"(\\\\|\\"|[^"])*"', String.Double), 92 (r'"(\\\\|\\"|[^"])*"', String.Double),
89 (r"'(\\\\|\\'|[^'])*'", String.Single), 93 (r"'(\\\\|\\'|[^'])*'", String.Single),
90 ] 94 (r'`', String.Backtick, 'interp'),
95 ],
96 'interp': [
97 (r'`', String.Backtick, '#pop'),
98 (r'\\\\', String.Backtick),
99 (r'\\`', String.Backtick),
100 (r'\${', String.Interpol, 'interp-inside'),
101 (r'\$', String.Backtick),
102 (r'[^`\\$]+', String.Backtick),
103 ],
104 'interp-inside': [
105 # TODO: should this include single-line comments and allow nesting strings?
106 (r'}', String.Interpol, '#pop'),
107 include('root'),
108 ],
109 # (\\\\|\\`|[^`])*`', String.Backtick),
91 } 110 }
92 111
93 112
94 class KalLexer(RegexLexer): 113 class KalLexer(RegexLexer):
95 """ 114 """
159 r'NaN|Infinity|undefined)\b', 178 r'NaN|Infinity|undefined)\b',
160 Keyword.Constant), 179 Keyword.Constant),
161 (r'(Array|Boolean|Date|Error|Function|Math|netscape|' 180 (r'(Array|Boolean|Date|Error|Function|Math|netscape|'
162 r'Number|Object|Packages|RegExp|String|sun|decodeURI|' 181 r'Number|Object|Packages|RegExp|String|sun|decodeURI|'
163 r'decodeURIComponent|encodeURI|encodeURIComponent|' 182 r'decodeURIComponent|encodeURI|encodeURIComponent|'
164 r'eval|isFinite|isNaN|parseFloat|parseInt|document|window|' 183 r'eval|isFinite|isNaN|isSafeInteger|parseFloat|parseInt|document|'
184 r'window|'
165 r'print)\b', 185 r'print)\b',
166 Name.Builtin), 186 Name.Builtin),
167 (r'[$a-zA-Z_][\w.$]*\s*(:|[+\-*/]?\=)?\b', Name.Variable), 187 (r'[$a-zA-Z_][\w.$]*\s*(:|[+\-*/]?\=)?\b', Name.Variable),
168 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), 188 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
169 (r'0x[0-9a-fA-F]+', Number.Hex), 189 (r'0x[0-9a-fA-F]+', Number.Hex),
424 444
425 .. versionadded:: 1.6 445 .. versionadded:: 1.6
426 """ 446 """
427 447
428 name = 'TypeScript' 448 name = 'TypeScript'
429 aliases = ['ts'] 449 aliases = ['ts', 'typescript']
430 filenames = ['*.ts'] 450 filenames = ['*.ts']
431 mimetypes = ['text/x-typescript'] 451 mimetypes = ['text/x-typescript']
432 452
433 flags = re.DOTALL | re.MULTILINE 453 flags = re.DOTALL | re.MULTILINE
434 454
489 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), 509 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
490 (r'0x[0-9a-fA-F]+', Number.Hex), 510 (r'0x[0-9a-fA-F]+', Number.Hex),
491 (r'[0-9]+', Number.Integer), 511 (r'[0-9]+', Number.Integer),
492 (r'"(\\\\|\\"|[^"])*"', String.Double), 512 (r'"(\\\\|\\"|[^"])*"', String.Double),
493 (r"'(\\\\|\\'|[^'])*'", String.Single), 513 (r"'(\\\\|\\'|[^'])*'", String.Single),
514 # Match stuff like: Decorators
515 (r'@\w+', Keyword.Declaration),
494 ] 516 ]
495 } 517 }
496 518
497 519
498 class LassoLexer(RegexLexer): 520 class LassoLexer(RegexLexer):
520 mimetypes = ['text/x-lasso'] 542 mimetypes = ['text/x-lasso']
521 flags = re.IGNORECASE | re.DOTALL | re.MULTILINE 543 flags = re.IGNORECASE | re.DOTALL | re.MULTILINE
522 544
523 tokens = { 545 tokens = {
524 'root': [ 546 'root': [
525 (r'^#!.+lasso9\b', Comment.Preproc, 'lasso'), 547 (r'^#![ \S]+lasso9\b', Comment.Preproc, 'lasso'),
526 (r'\[no_square_brackets\]', Comment.Preproc, 'nosquarebrackets'), 548 (r'\[no_square_brackets\]', Comment.Preproc, 'nosquarebrackets'),
527 (r'\[noprocess\]', Comment.Preproc, ('delimiters', 'noprocess')), 549 (r'\[noprocess\]', Comment.Preproc, ('delimiters', 'noprocess')),
528 (r'\[', Comment.Preproc, ('delimiters', 'squarebrackets')), 550 (r'\[', Comment.Preproc, ('delimiters', 'squarebrackets')),
529 (r'<\?(LassoScript|lasso|=)', Comment.Preproc, 551 (r'<\?(LassoScript|lasso|=)', Comment.Preproc,
530 ('delimiters', 'anglebrackets')), 552 ('delimiters', 'anglebrackets')),
539 (r'<\?(LassoScript|lasso|=)', Comment.Preproc, 'anglebrackets'), 561 (r'<\?(LassoScript|lasso|=)', Comment.Preproc, 'anglebrackets'),
540 (r'<(!--.*?-->)?', Other), 562 (r'<(!--.*?-->)?', Other),
541 (r'[^[<]+', Other), 563 (r'[^[<]+', Other),
542 ], 564 ],
543 'nosquarebrackets': [ 565 'nosquarebrackets': [
566 (r'\[noprocess\]', Comment.Preproc, 'noprocess'),
567 (r'\[', Other),
544 (r'<\?(LassoScript|lasso|=)', Comment.Preproc, 'anglebrackets'), 568 (r'<\?(LassoScript|lasso|=)', Comment.Preproc, 'anglebrackets'),
545 (r'<', Other), 569 (r'<(!--.*?-->)?', Other),
546 (r'[^<]+', Other), 570 (r'[^[<]+', Other),
547 ], 571 ],
548 'noprocess': [ 572 'noprocess': [
549 (r'\[/noprocess\]', Comment.Preproc, '#pop'), 573 (r'\[/noprocess\]', Comment.Preproc, '#pop'),
550 (r'\[', Other), 574 (r'\[', Other),
551 (r'[^[]', Other), 575 (r'[^[]', Other),
574 598
575 # literals 599 # literals
576 (r'\d*\.\d+(e[+-]?\d+)?', Number.Float), 600 (r'\d*\.\d+(e[+-]?\d+)?', Number.Float),
577 (r'0x[\da-f]+', Number.Hex), 601 (r'0x[\da-f]+', Number.Hex),
578 (r'\d+', Number.Integer), 602 (r'\d+', Number.Integer),
579 (r'([+-]?)(infinity|NaN)\b', bygroups(Operator, Number)), 603 (r'(infinity|NaN)\b', Number),
580 (r"'", String.Single, 'singlestring'), 604 (r"'", String.Single, 'singlestring'),
581 (r'"', String.Double, 'doublestring'), 605 (r'"', String.Double, 'doublestring'),
582 (r'`[^`]*`', String.Backtick), 606 (r'`[^`]*`', String.Backtick),
583 607
584 # names 608 # names
585 (r'\$[a-z_][\w.]*', Name.Variable), 609 (r'\$[a-z_][\w.]*', Name.Variable),
586 (r'#([a-z_][\w.]*|\d+)', Name.Variable.Instance), 610 (r'#([a-z_][\w.]*|\d+)', Name.Variable.Instance),
587 (r"(\.)('[a-z_][\w.]*')", 611 (r"(\.\s*)('[a-z_][\w.]*')",
588 bygroups(Name.Builtin.Pseudo, Name.Variable.Class)), 612 bygroups(Name.Builtin.Pseudo, Name.Variable.Class)),
589 (r"(self)(\s*->\s*)('[a-z_][\w.]*')", 613 (r"(self)(\s*->\s*)('[a-z_][\w.]*')",
590 bygroups(Name.Builtin.Pseudo, Operator, Name.Variable.Class)), 614 bygroups(Name.Builtin.Pseudo, Operator, Name.Variable.Class)),
591 (r'(\.\.?)([a-z_][\w.]*(=(?!=))?)', 615 (r'(\.\.?\s*)([a-z_][\w.]*(=(?!=))?)',
592 bygroups(Name.Builtin.Pseudo, Name.Other.Member)), 616 bygroups(Name.Builtin.Pseudo, Name.Other.Member)),
593 (r'(->\\?\s*|&\s*)([a-z_][\w.]*(=(?!=))?)', 617 (r'(->\\?\s*|&\s*)([a-z_][\w.]*(=(?!=))?)',
594 bygroups(Operator, Name.Other.Member)), 618 bygroups(Operator, Name.Other.Member)),
595 (r'(self|inherited)\b', Name.Builtin.Pseudo), 619 (r'(?<!->)(self|inherited|currentcapture|givenblock)\b',
596 (r'-[a-z_][\w.]*', Name.Attribute), 620 Name.Builtin.Pseudo),
621 (r'-(?!infinity)[a-z_][\w.]*', Name.Attribute),
597 (r'::\s*[a-z_][\w.]*', Name.Label), 622 (r'::\s*[a-z_][\w.]*', Name.Label),
598 (r'(error_(code|msg)_\w+|Error_AddError|Error_ColumnRestriction|' 623 (r'(error_(code|msg)_\w+|Error_AddError|Error_ColumnRestriction|'
599 r'Error_DatabaseConnectionUnavailable|Error_DatabaseTimeout|' 624 r'Error_DatabaseConnectionUnavailable|Error_DatabaseTimeout|'
600 r'Error_DeleteError|Error_FieldRestriction|Error_FileNotFound|' 625 r'Error_DeleteError|Error_FieldRestriction|Error_FileNotFound|'
601 r'Error_InvalidDatabase|Error_InvalidPassword|' 626 r'Error_InvalidDatabase|Error_InvalidPassword|'
621 646
622 # keywords 647 # keywords
623 (r'(true|false|none|minimal|full|all|void)\b', Keyword.Constant), 648 (r'(true|false|none|minimal|full|all|void)\b', Keyword.Constant),
624 (r'(local|var|variable|global|data(?=\s))\b', Keyword.Declaration), 649 (r'(local|var|variable|global|data(?=\s))\b', Keyword.Declaration),
625 (r'(array|date|decimal|duration|integer|map|pair|string|tag|xml|' 650 (r'(array|date|decimal|duration|integer|map|pair|string|tag|xml|'
626 r'null|bytes|list|queue|set|stack|staticarray|tie)\b', Keyword.Type), 651 r'null|boolean|bytes|keyword|list|locale|queue|set|stack|'
652 r'staticarray)\b', Keyword.Type),
627 (r'([a-z_][\w.]*)(\s+)(in)\b', bygroups(Name, Text, Keyword)), 653 (r'([a-z_][\w.]*)(\s+)(in)\b', bygroups(Name, Text, Keyword)),
628 (r'(let|into)(\s+)([a-z_][\w.]*)', bygroups(Keyword, Text, Name)), 654 (r'(let|into)(\s+)([a-z_][\w.]*)', bygroups(Keyword, Text, Name)),
629 (r'require\b', Keyword, 'requiresection'), 655 (r'require\b', Keyword, 'requiresection'),
630 (r'(/?)(Namespace_Using)\b', bygroups(Punctuation, Keyword.Namespace)), 656 (r'(/?)(Namespace_Using)\b', bygroups(Punctuation, Keyword.Namespace)),
631 (r'(/?)(Cache|Database_Names|Database_SchemaNames|' 657 (r'(/?)(Cache|Database_Names|Database_SchemaNames|'
670 (r'[^"\\]+', String.Double), 696 (r'[^"\\]+', String.Double),
671 include('escape'), 697 include('escape'),
672 (r'\\', String.Double), 698 (r'\\', String.Double),
673 ], 699 ],
674 'escape': [ 700 'escape': [
675 (r'\\(U[\da-f]{8}|u[\da-f]{4}|x[\da-f]{1,2}|[0-7]{1,3}|:[^:]+:|' 701 (r'\\(U[\da-f]{8}|u[\da-f]{4}|x[\da-f]{1,2}|[0-7]{1,3}|:[^:\n\r]+:|'
676 r'[abefnrtv?"\'\\]|$)', String.Escape), 702 r'[abefnrtv?"\'\\]|$)', String.Escape),
677 ], 703 ],
678 'signature': [ 704 'signature': [
679 (r'=>', Operator, '#pop'), 705 (r'=>', Operator, '#pop'),
680 (r'\)', Punctuation, '#pop'), 706 (r'\)', Punctuation, '#pop'),
1195 'string-double-pop2': [ 1221 'string-double-pop2': [
1196 (r'"', String.Single, '#pop:2'), 1222 (r'"', String.Single, '#pop:2'),
1197 include('string-base') 1223 include('string-base')
1198 ], 1224 ],
1199 } 1225 }
1226
1227
1228 class EarlGreyLexer(RegexLexer):
1229 """
1230 For `Earl-Grey`_ source code.
1231
1232 .. _Earl-Grey: https://breuleux.github.io/earl-grey/
1233
1234 .. versionadded: 2.1
1235 """
1236
1237 name = 'Earl Grey'
1238 aliases = ['earl-grey', 'earlgrey', 'eg']
1239 filenames = ['*.eg']
1240 mimetypes = ['text/x-earl-grey']
1241
1242 tokens = {
1243 'root': [
1244 (r'\n', Text),
1245 include('control'),
1246 (r'[^\S\n]+', Text),
1247 (r';;.*\n', Comment),
1248 (r'[\[\]\{\}\:\(\)\,\;]', Punctuation),
1249 (r'\\\n', Text),
1250 (r'\\', Text),
1251 include('errors'),
1252 (words((
1253 'with', 'where', 'when', 'and', 'not', 'or', 'in',
1254 'as', 'of', 'is'),
1255 prefix=r'(?<=\s|\[)', suffix=r'(?![\w\$\-])'),
1256 Operator.Word),
1257 (r'[\*@]?->', Name.Function),
1258 (r'[+\-*/~^<>%&|?!@#.]*=', Operator.Word),
1259 (r'\.{2,3}', Operator.Word), # Range Operator
1260 (r'([+*/~^<>&|?!]+)|([#\-](?=\s))|@@+(?=\s)|=+', Operator),
1261 (r'(?<![\w\$\-])(var|let)(?:[^\w\$])', Keyword.Declaration),
1262 include('keywords'),
1263 include('builtins'),
1264 include('assignment'),
1265 (r'''(?x)
1266 (?:()([a-zA-Z$_](?:[a-zA-Z$0-9_\-]*[a-zA-Z$0-9_])?)|
1267 (?<=[\s\{\[\(])(\.)([a-zA-Z$_](?:[a-zA-Z$0-9_\-]*[a-zA-Z$0-9_])?))
1268 (?=.*%)''',
1269 bygroups(Punctuation, Name.Tag, Punctuation, Name.Class.Start), 'dbs'),
1270 (r'[rR]?`', String.Backtick, 'bt'),
1271 (r'[rR]?```', String.Backtick, 'tbt'),
1272 (r'(?<=[\s\[\{\(,;])\.([a-zA-Z$_](?:[a-zA-Z$0-9_-]*[a-zA-Z$0-9_])?)'
1273 r'(?=[\s\]\}\),;])', String.Symbol),
1274 include('nested'),
1275 (r'(?:[rR]|[rR]\.[gmi]{1,3})?"', String, combined('stringescape', 'dqs')),
1276 (r'(?:[rR]|[rR]\.[gmi]{1,3})?\'', String, combined('stringescape', 'sqs')),
1277 (r'"""', String, combined('stringescape', 'tdqs')),
1278 include('tuple'),
1279 include('import_paths'),
1280 include('name'),
1281 include('numbers'),
1282 ],
1283 'dbs': [
1284 (r'(\.)([a-zA-Z$_](?:[a-zA-Z$0-9_\-]*[a-zA-Z$0-9_])?)(?=[\[\.\s])',
1285 bygroups(Punctuation, Name.Class.DBS)),
1286 (r'(\[)([\^#][a-zA-Z$_](?:[a-zA-Z$0-9_\-]*[a-zA-Z$0-9_])?)(\])',
1287 bygroups(Punctuation, Name.Entity.DBS, Punctuation)),
1288 (r'\s+', Text),
1289 (r'%', Operator.DBS, '#pop'),
1290 ],
1291 'import_paths': [
1292 (r'(?<=[\s:;,])(\.{1,3}(?:[\w\-]*/)*)(\w(?:[\w\-]*\w)*)(?=[\s;,])',
1293 bygroups(Text.Whitespace, Text)),
1294 ],
1295 'assignment': [
1296 (r'(\.)?([a-zA-Z$_](?:[a-zA-Z$0-9_-]*[a-zA-Z$0-9_])?)'
1297 r'(?=\s+[+\-*/~^<>%&|?!@#.]*\=\s)',
1298 bygroups(Punctuation, Name.Variable))
1299 ],
1300 'errors': [
1301 (words(('Error', 'TypeError', 'ReferenceError'),
1302 prefix=r'(?<![\w\$\-\.])', suffix=r'(?![\w\$\-\.])'),
1303 Name.Exception),
1304 (r'''(?x)
1305 (?<![\w\$])
1306 E\.[\w\$](?:[\w\$\-]*[\w\$])?
1307 (?:\.[\w\$](?:[\w\$\-]*[\w\$])?)*
1308 (?=[\(\{\[\?\!\s])''',
1309 Name.Exception),
1310 ],
1311 'control': [
1312 (r'''(?x)
1313 ([a-zA-Z$_](?:[a-zA-Z$0-9_-]*[a-zA-Z$0-9_])?)
1314 (?!\n)\s+
1315 (?!and|as|each\*|each|in|is|mod|of|or|when|where|with)
1316 (?=(?:[+\-*/~^<>%&|?!@#.])?[a-zA-Z$_](?:[a-zA-Z$0-9_-]*[a-zA-Z$0-9_])?)''',
1317 Keyword.Control),
1318 (r'([a-zA-Z$_](?:[a-zA-Z$0-9_-]*[a-zA-Z$0-9_])?)(?!\n)\s+(?=[\'"\d\{\[\(])',
1319 Keyword.Control),
1320 (r'''(?x)
1321 (?:
1322 (?<=[%=])|
1323 (?<=[=\-]>)|
1324 (?<=with|each|with)|
1325 (?<=each\*|where)
1326 )(\s+)
1327 ([a-zA-Z$_](?:[a-zA-Z$0-9_\-]*[a-zA-Z$0-9_])?)(:)''',
1328 bygroups(Text, Keyword.Control, Punctuation)),
1329 (r'''(?x)
1330 (?<![+\-*/~^<>%&|?!@#.])(\s+)
1331 ([a-zA-Z$_](?:[a-zA-Z$0-9_-]*[a-zA-Z$0-9_])?)(:)''',
1332 bygroups(Text, Keyword.Control, Punctuation)),
1333 ],
1334 'nested': [
1335 (r'''(?x)
1336 (?<=[a-zA-Z$0-9_\]\}\)])(\.)
1337 ([a-zA-Z$_](?:[a-zA-Z$0-9_-]*[a-zA-Z$0-9_])?)
1338 (?=\s+with(?:\s|\n))''',
1339 bygroups(Punctuation, Name.Function)),
1340 (r'''(?x)
1341 (?<!\s)(\.)
1342 ([a-zA-Z$_](?:[a-zA-Z$0-9_-]*[a-zA-Z$0-9_])?)
1343 (?=[\}\]\)\.,;:\s])''',
1344 bygroups(Punctuation, Name.Field)),
1345 (r'''(?x)
1346 (?<=[a-zA-Z$0-9_\]\}\)])(\.)
1347 ([a-zA-Z$_](?:[a-zA-Z$0-9_-]*[a-zA-Z$0-9_])?)
1348 (?=[\[\{\(:])''',
1349 bygroups(Punctuation, Name.Function)),
1350 ],
1351 'keywords': [
1352 (words((
1353 'each', 'each*', 'mod', 'await', 'break', 'chain',
1354 'continue', 'elif', 'expr-value', 'if', 'match',
1355 'return', 'yield', 'pass', 'else', 'require', 'var',
1356 'let', 'async', 'method', 'gen'),
1357 prefix=r'(?<![\w\$\-\.])', suffix=r'(?![\w\$\-\.])'),
1358 Keyword.Pseudo),
1359 (words(('this', 'self', '@'),
1360 prefix=r'(?<![\w\$\-\.])', suffix=r'(?![\w\$\-])'),
1361 Keyword.Constant),
1362 (words((
1363 'Function', 'Object', 'Array', 'String', 'Number',
1364 'Boolean', 'ErrorFactory', 'ENode', 'Promise'),
1365 prefix=r'(?<![\w\$\-\.])', suffix=r'(?![\w\$\-])'),
1366 Keyword.Type),
1367 ],
1368 'builtins': [
1369 (words((
1370 'send', 'object', 'keys', 'items', 'enumerate', 'zip',
1371 'product', 'neighbours', 'predicate', 'equal',
1372 'nequal', 'contains', 'repr', 'clone', 'range',
1373 'getChecker', 'get-checker', 'getProperty', 'get-property',
1374 'getProjector', 'get-projector', 'consume', 'take',
1375 'promisify', 'spawn', 'constructor'),
1376 prefix=r'(?<![\w\-#\.])', suffix=r'(?![\w\-\.])'),
1377 Name.Builtin),
1378 (words((
1379 'true', 'false', 'null', 'undefined'),
1380 prefix=r'(?<![\w\$\-\.])', suffix=r'(?![\w\$\-\.])'),
1381 Name.Constant),
1382 ],
1383 'name': [
1384 (r'@([a-zA-Z$_](?:[a-zA-Z$0-9_-]*[a-zA-Z$0-9_])?)', Name.Variable.Instance),
1385 (r'([a-zA-Z$_](?:[a-zA-Z$0-9_-]*[a-zA-Z$0-9_])?)(\+\+|\-\-)?',
1386 bygroups(Name.Symbol, Operator.Word))
1387 ],
1388 'tuple': [
1389 (r'#[a-zA-Z_][a-zA-Z_\-0-9]*(?=[\s\{\(,;\n])', Name.Namespace)
1390 ],
1391 'interpoling_string': [
1392 (r'\}', String.Interpol, '#pop'),
1393 include('root')
1394 ],
1395 'stringescape': [
1396 (r'\\([\\abfnrtv"\']|\n|N\{.*?\}|u[a-fA-F0-9]{4}|'
1397 r'U[a-fA-F0-9]{8}|x[a-fA-F0-9]{2}|[0-7]{1,3})', String.Escape)
1398 ],
1399 'strings': [
1400 (r'[^\\\'"]', String),
1401 (r'[\'"\\]', String),
1402 (r'\n', String) # All strings are multiline in EG
1403 ],
1404 'dqs': [
1405 (r'"', String, '#pop'),
1406 (r'\\\\|\\"|\\\n', String.Escape),
1407 include('strings')
1408 ],
1409 'sqs': [
1410 (r"'", String, '#pop'),
1411 (r"\\\\|\\'|\\\n", String.Escape),
1412 (r'\{', String.Interpol, 'interpoling_string'),
1413 include('strings')
1414 ],
1415 'tdqs': [
1416 (r'"""', String, '#pop'),
1417 include('strings'),
1418 ],
1419 'bt': [
1420 (r'`', String.Backtick, '#pop'),
1421 (r'(?<!`)\n', String.Backtick),
1422 (r'\^=?', String.Escape),
1423 (r'.+', String.Backtick),
1424 ],
1425 'tbt': [
1426 (r'```', String.Backtick, '#pop'),
1427 (r'\n', String.Backtick),
1428 (r'\^=?', String.Escape),
1429 (r'[^\`]+', String.Backtick),
1430 ],
1431 'numbers': [
1432 (r'\d+\.(?!\.)\d*([eE][+-]?[0-9]+)?', Number.Float),
1433 (r'\d+[eE][+-]?[0-9]+', Number.Float),
1434 (r'8r[0-7]+', Number.Oct),
1435 (r'2r[01]+', Number.Bin),
1436 (r'16r[a-fA-F0-9]+', Number.Hex),
1437 (r'([3-79]|[1-2][0-9]|3[0-6])r[a-zA-Z\d]+(\.[a-zA-Z\d]+)?', Number.Radix),
1438 (r'\d+', Number.Integer)
1439 ],
1440 }

eric ide

mercurial