ThirdParty/Pygments/pygments/lexers/javascript.py

changeset 5713
6762afd9f963
parent 4697
c2e9bf425554
child 6651
e8f3b5568b21
equal deleted inserted replaced
5712:f0d08bdeacf4 5713:6762afd9f963
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-2015 by the Pygments team, see AUTHORS. 8 :copyright: Copyright 2006-2017 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
18 from pygments.util import get_bool_opt, iteritems 18 from pygments.util import get_bool_opt, iteritems
19 import pygments.unistring as uni 19 import pygments.unistring as uni
20 20
21 __all__ = ['JavascriptLexer', 'KalLexer', 'LiveScriptLexer', 'DartLexer', 21 __all__ = ['JavascriptLexer', 'KalLexer', 'LiveScriptLexer', 'DartLexer',
22 'TypeScriptLexer', 'LassoLexer', 'ObjectiveJLexer', 22 'TypeScriptLexer', 'LassoLexer', 'ObjectiveJLexer',
23 'CoffeeScriptLexer', 'MaskLexer', 'EarlGreyLexer'] 23 'CoffeeScriptLexer', 'MaskLexer', 'EarlGreyLexer', 'JuttleLexer']
24 24
25 JS_IDENT_START = ('(?:[$_' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl') + 25 JS_IDENT_START = ('(?:[$_' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl') +
26 ']|\\\\u[a-fA-F0-9]{4})') 26 ']|\\\\u[a-fA-F0-9]{4})')
27 JS_IDENT_PART = ('(?:[$' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl', 27 JS_IDENT_PART = ('(?:[$' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl',
28 'Mn', 'Mc', 'Nd', 'Pc') + 28 'Mn', 'Mc', 'Nd', 'Pc') +
51 (r'/\*.*?\*/', Comment.Multiline) 51 (r'/\*.*?\*/', Comment.Multiline)
52 ], 52 ],
53 'slashstartsregex': [ 53 'slashstartsregex': [
54 include('commentsandwhitespace'), 54 include('commentsandwhitespace'),
55 (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' 55 (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
56 r'([gim]+\b|\B)', String.Regex, '#pop'), 56 r'([gimuy]+\b|\B)', String.Regex, '#pop'),
57 (r'(?=/)', Text, ('#pop', 'badregex')), 57 (r'(?=/)', Text, ('#pop', 'badregex')),
58 default('#pop') 58 default('#pop')
59 ], 59 ],
60 'badregex': [ 60 'badregex': [
61 (r'\n', Text, '#pop') 61 (r'\n', Text, '#pop')
62 ], 62 ],
63 'root': [ 63 'root': [
64 (r'\A#! ?/.*?\n', Comment.Hashbang), # recognized by node.js 64 (r'\A#! ?/.*?\n', Comment.Hashbang), # recognized by node.js
65 (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), 65 (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'),
66 include('commentsandwhitespace'), 66 include('commentsandwhitespace'),
67 (r'(\.\d+|[0-9]+\.[0-9]*)([eE][-+]?[0-9]+)?', Number.Float),
68 (r'0[bB][01]+', Number.Bin),
69 (r'0[oO][0-7]+', Number.Oct),
70 (r'0[xX][0-9a-fA-F]+', Number.Hex),
71 (r'[0-9]+', Number.Integer),
72 (r'\.\.\.|=>', Punctuation),
67 (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|' 73 (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|'
68 r'(<<|>>>?|=>|==?|!=?|[-<>+*%&|^/])=?', Operator, 'slashstartsregex'), 74 r'(<<|>>>?|==?|!=?|[-<>+*%&|^/])=?', Operator, 'slashstartsregex'),
69 (r'\.\.\.', Punctuation),
70 (r'[{(\[;,]', Punctuation, 'slashstartsregex'), 75 (r'[{(\[;,]', Punctuation, 'slashstartsregex'),
71 (r'[})\].]', Punctuation), 76 (r'[})\].]', Punctuation),
72 (r'(for|in|while|do|break|return|continue|switch|case|default|if|else|' 77 (r'(for|in|while|do|break|return|continue|switch|case|default|if|else|'
73 r'throw|try|catch|finally|new|delete|typeof|instanceof|void|yield|' 78 r'throw|try|catch|finally|new|delete|typeof|instanceof|void|yield|'
74 r'this|of)\b', Keyword, 'slashstartsregex'), 79 r'this|of)\b', Keyword, 'slashstartsregex'),
82 r'Number|Object|Packages|RegExp|String|Promise|Proxy|sun|decodeURI|' 87 r'Number|Object|Packages|RegExp|String|Promise|Proxy|sun|decodeURI|'
83 r'decodeURIComponent|encodeURI|encodeURIComponent|' 88 r'decodeURIComponent|encodeURI|encodeURIComponent|'
84 r'Error|eval|isFinite|isNaN|isSafeInteger|parseFloat|parseInt|' 89 r'Error|eval|isFinite|isNaN|isSafeInteger|parseFloat|parseInt|'
85 r'document|this|window)\b', Name.Builtin), 90 r'document|this|window)\b', Name.Builtin),
86 (JS_IDENT, Name.Other), 91 (JS_IDENT, Name.Other),
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),
90 (r'0x[0-9a-fA-F]+', Number.Hex),
91 (r'[0-9]+', Number.Integer),
92 (r'"(\\\\|\\"|[^"])*"', String.Double), 92 (r'"(\\\\|\\"|[^"])*"', String.Double),
93 (r"'(\\\\|\\'|[^'])*'", String.Single), 93 (r"'(\\\\|\\'|[^'])*'", String.Single),
94 (r'`', String.Backtick, 'interp'), 94 (r'`', String.Backtick, 'interp'),
95 ], 95 ],
96 'interp': [ 96 'interp': [
97 (r'`', String.Backtick, '#pop'), 97 (r'`', String.Backtick, '#pop'),
98 (r'\\\\', String.Backtick), 98 (r'\\\\', String.Backtick),
99 (r'\\`', String.Backtick), 99 (r'\\`', String.Backtick),
100 (r'\${', String.Interpol, 'interp-inside'), 100 (r'\$\{', String.Interpol, 'interp-inside'),
101 (r'\$', String.Backtick), 101 (r'\$', String.Backtick),
102 (r'[^`\\$]+', String.Backtick), 102 (r'[^`\\$]+', String.Backtick),
103 ], 103 ],
104 'interp-inside': [ 104 'interp-inside': [
105 # TODO: should this include single-line comments and allow nesting strings? 105 # TODO: should this include single-line comments and allow nesting strings?
106 (r'}', String.Interpol, '#pop'), 106 (r'\}', String.Interpol, '#pop'),
107 include('root'), 107 include('root'),
108 ], 108 ],
109 # (\\\\|\\`|[^`])*`', String.Backtick), 109 # (\\\\|\\`|[^`])*`', String.Backtick),
110 } 110 }
111 111
364 (r'\b(class)\b(\s+)', 364 (r'\b(class)\b(\s+)',
365 bygroups(Keyword.Declaration, Text), 'class'), 365 bygroups(Keyword.Declaration, Text), 'class'),
366 (r'\b(assert|break|case|catch|continue|default|do|else|finally|for|' 366 (r'\b(assert|break|case|catch|continue|default|do|else|finally|for|'
367 r'if|in|is|new|return|super|switch|this|throw|try|while)\b', 367 r'if|in|is|new|return|super|switch|this|throw|try|while)\b',
368 Keyword), 368 Keyword),
369 (r'\b(abstract|const|extends|factory|final|get|implements|' 369 (r'\b(abstract|async|await|const|extends|factory|final|get|'
370 r'native|operator|set|static|typedef|var)\b', Keyword.Declaration), 370 r'implements|native|operator|set|static|sync|typedef|var|with|'
371 (r'\b(bool|double|Dynamic|int|num|Object|String|void)\b', Keyword.Type), 371 r'yield)\b', Keyword.Declaration),
372 (r'\b(bool|double|dynamic|int|num|Object|String|void)\b', Keyword.Type),
372 (r'\b(false|null|true)\b', Keyword.Constant), 373 (r'\b(false|null|true)\b', Keyword.Constant),
373 (r'[~!%^&*+=|?:<>/-]|as\b', Operator), 374 (r'[~!%^&*+=|?:<>/-]|as\b', Operator),
374 (r'[a-zA-Z_$]\w*:', Name.Label), 375 (r'[a-zA-Z_$]\w*:', Name.Label),
375 (r'[a-zA-Z_$]\w*', Name), 376 (r'[a-zA-Z_$]\w*', Name),
376 (r'[(){}\[\],.;]', Punctuation), 377 (r'[(){}\[\],.;]', Punctuation),
445 .. versionadded:: 1.6 446 .. versionadded:: 1.6
446 """ 447 """
447 448
448 name = 'TypeScript' 449 name = 'TypeScript'
449 aliases = ['ts', 'typescript'] 450 aliases = ['ts', 'typescript']
450 filenames = ['*.ts'] 451 filenames = ['*.ts', '*.tsx']
451 mimetypes = ['text/x-typescript'] 452 mimetypes = ['text/x-typescript']
452 453
453 flags = re.DOTALL | re.MULTILINE 454 flags = re.DOTALL | re.MULTILINE
454 455
455 tokens = { 456 tokens = {
509 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), 510 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
510 (r'0x[0-9a-fA-F]+', Number.Hex), 511 (r'0x[0-9a-fA-F]+', Number.Hex),
511 (r'[0-9]+', Number.Integer), 512 (r'[0-9]+', Number.Integer),
512 (r'"(\\\\|\\"|[^"])*"', String.Double), 513 (r'"(\\\\|\\"|[^"])*"', String.Double),
513 (r"'(\\\\|\\'|[^'])*'", String.Single), 514 (r"'(\\\\|\\'|[^'])*'", String.Single),
515 (r'`', String.Backtick, 'interp'),
514 # Match stuff like: Decorators 516 # Match stuff like: Decorators
515 (r'@\w+', Keyword.Declaration), 517 (r'@\w+', Keyword.Declaration),
516 ] 518 ],
519
520 # The 'interp*' rules match those in JavascriptLexer. Changes made
521 # there should be reflected here as well.
522 'interp': [
523 (r'`', String.Backtick, '#pop'),
524 (r'\\\\', String.Backtick),
525 (r'\\`', String.Backtick),
526 (r'\$\{', String.Interpol, 'interp-inside'),
527 (r'\$', String.Backtick),
528 (r'[^`\\$]+', String.Backtick),
529 ],
530 'interp-inside': [
531 # TODO: should this include single-line comments and allow nesting strings?
532 (r'\}', String.Interpol, '#pop'),
533 include('root'),
534 ],
517 } 535 }
536
537 def analyse_text(text):
538 if re.search('^(import.+(from\s+)?["\']|'
539 '(export\s*)?(interface|class|function)\s+)',
540 text, re.MULTILINE):
541 return 1.0
518 542
519 543
520 class LassoLexer(RegexLexer): 544 class LassoLexer(RegexLexer):
521 """ 545 """
522 For `Lasso <http://www.lassosoft.com/>`_ source code, covering both Lasso 9 546 For `Lasso <http://www.lassosoft.com/>`_ source code, covering both Lasso 9
543 flags = re.IGNORECASE | re.DOTALL | re.MULTILINE 567 flags = re.IGNORECASE | re.DOTALL | re.MULTILINE
544 568
545 tokens = { 569 tokens = {
546 'root': [ 570 'root': [
547 (r'^#![ \S]+lasso9\b', Comment.Preproc, 'lasso'), 571 (r'^#![ \S]+lasso9\b', Comment.Preproc, 'lasso'),
548 (r'\[no_square_brackets\]', Comment.Preproc, 'nosquarebrackets'), 572 (r'(?=\[|<)', Other, 'delimiters'),
549 (r'\[noprocess\]', Comment.Preproc, ('delimiters', 'noprocess')),
550 (r'\[', Comment.Preproc, ('delimiters', 'squarebrackets')),
551 (r'<\?(LassoScript|lasso|=)', Comment.Preproc,
552 ('delimiters', 'anglebrackets')),
553 (r'<(!--.*?-->)?', Other, 'delimiters'),
554 (r'\s+', Other), 573 (r'\s+', Other),
555 default(('delimiters', 'lassofile')), 574 default(('delimiters', 'lassofile')),
556 ], 575 ],
557 'delimiters': [ 576 'delimiters': [
558 (r'\[no_square_brackets\]', Comment.Preproc, 'nosquarebrackets'), 577 (r'\[no_square_brackets\]', Comment.Preproc, 'nosquarebrackets'),
559 (r'\[noprocess\]', Comment.Preproc, 'noprocess'), 578 (r'\[noprocess\]', Comment.Preproc, 'noprocess'),
560 (r'\[', Comment.Preproc, 'squarebrackets'), 579 (r'\[', Comment.Preproc, 'squarebrackets'),
561 (r'<\?(LassoScript|lasso|=)', Comment.Preproc, 'anglebrackets'), 580 (r'<\?(lasso(script)?|=)', Comment.Preproc, 'anglebrackets'),
562 (r'<(!--.*?-->)?', Other), 581 (r'<(!--.*?-->)?', Other),
563 (r'[^[<]+', Other), 582 (r'[^[<]+', Other),
564 ], 583 ],
565 'nosquarebrackets': [ 584 'nosquarebrackets': [
566 (r'\[noprocess\]', Comment.Preproc, 'noprocess'), 585 (r'\[noprocess\]', Comment.Preproc, 'noprocess'),
567 (r'\[', Other), 586 (r'\[', Other),
568 (r'<\?(LassoScript|lasso|=)', Comment.Preproc, 'anglebrackets'), 587 (r'<\?(lasso(script)?|=)', Comment.Preproc, 'anglebrackets'),
569 (r'<(!--.*?-->)?', Other), 588 (r'<(!--.*?-->)?', Other),
570 (r'[^[<]+', Other), 589 (r'[^[<]+', Other),
571 ], 590 ],
572 'noprocess': [ 591 'noprocess': [
573 (r'\[/noprocess\]', Comment.Preproc, '#pop'), 592 (r'\[/noprocess\]', Comment.Preproc, '#pop'),
605 (r'"', String.Double, 'doublestring'), 624 (r'"', String.Double, 'doublestring'),
606 (r'`[^`]*`', String.Backtick), 625 (r'`[^`]*`', String.Backtick),
607 626
608 # names 627 # names
609 (r'\$[a-z_][\w.]*', Name.Variable), 628 (r'\$[a-z_][\w.]*', Name.Variable),
610 (r'#([a-z_][\w.]*|\d+)', Name.Variable.Instance), 629 (r'#([a-z_][\w.]*|\d+\b)', Name.Variable.Instance),
611 (r"(\.\s*)('[a-z_][\w.]*')", 630 (r"(\.\s*)('[a-z_][\w.]*')",
612 bygroups(Name.Builtin.Pseudo, Name.Variable.Class)), 631 bygroups(Name.Builtin.Pseudo, Name.Variable.Class)),
613 (r"(self)(\s*->\s*)('[a-z_][\w.]*')", 632 (r"(self)(\s*->\s*)('[a-z_][\w.]*')",
614 bygroups(Name.Builtin.Pseudo, Operator, Name.Variable.Class)), 633 bygroups(Name.Builtin.Pseudo, Operator, Name.Variable.Class)),
615 (r'(\.\.?\s*)([a-z_][\w.]*(=(?!=))?)', 634 (r'(\.\.?\s*)([a-z_][\w.]*(=(?!=))?)',
656 (r'(/?)(Namespace_Using)\b', bygroups(Punctuation, Keyword.Namespace)), 675 (r'(/?)(Namespace_Using)\b', bygroups(Punctuation, Keyword.Namespace)),
657 (r'(/?)(Cache|Database_Names|Database_SchemaNames|' 676 (r'(/?)(Cache|Database_Names|Database_SchemaNames|'
658 r'Database_TableNames|Define_Tag|Define_Type|Email_Batch|' 677 r'Database_TableNames|Define_Tag|Define_Type|Email_Batch|'
659 r'Encode_Set|HTML_Comment|Handle|Handle_Error|Header|If|Inline|' 678 r'Encode_Set|HTML_Comment|Handle|Handle_Error|Header|If|Inline|'
660 r'Iterate|LJAX_Target|Link|Link_CurrentAction|Link_CurrentGroup|' 679 r'Iterate|LJAX_Target|Link|Link_CurrentAction|Link_CurrentGroup|'
661 r'Link_CurrentRecord|Link_Detail|Link_FirstGroup|' 680 r'Link_CurrentRecord|Link_Detail|Link_FirstGroup|Link_FirstRecord|'
662 r'Link_FirstRecord|Link_LastGroup|Link_LastRecord|Link_NextGroup|' 681 r'Link_LastGroup|Link_LastRecord|Link_NextGroup|Link_NextRecord|'
663 r'Link_NextRecord|Link_PrevGroup|Link_PrevRecord|Log|Loop|' 682 r'Link_PrevGroup|Link_PrevRecord|Log|Loop|Output_None|Portal|'
664 r'NoProcess|Output_None|Portal|Private|Protect|Records|Referer|' 683 r'Private|Protect|Records|Referer|Referrer|Repeating|ResultSet|'
665 r'Referrer|Repeating|ResultSet|Rows|Search_Args|Search_Arguments|' 684 r'Rows|Search_Args|Search_Arguments|Select|Sort_Args|'
666 r'Select|Sort_Args|Sort_Arguments|Thread_Atomic|Value_List|While|' 685 r'Sort_Arguments|Thread_Atomic|Value_List|While|Abort|Case|Else|'
667 r'Abort|Case|Else|If_Empty|If_False|If_Null|If_True|Loop_Abort|' 686 r'Fail_If|Fail_IfNot|Fail|If_Empty|If_False|If_Null|If_True|'
668 r'Loop_Continue|Loop_Count|Params|Params_Up|Return|Return_Value|' 687 r'Loop_Abort|Loop_Continue|Loop_Count|Params|Params_Up|Return|'
669 r'Run_Children|SOAP_DefineTag|SOAP_LastRequest|SOAP_LastResponse|' 688 r'Return_Value|Run_Children|SOAP_DefineTag|SOAP_LastRequest|'
670 r'Tag_Name|ascending|average|by|define|descending|do|equals|' 689 r'SOAP_LastResponse|Tag_Name|ascending|average|by|define|'
671 r'frozen|group|handle_failure|import|in|into|join|let|match|max|' 690 r'descending|do|equals|frozen|group|handle_failure|import|in|into|'
672 r'min|on|order|parent|protected|provide|public|require|returnhome|' 691 r'join|let|match|max|min|on|order|parent|protected|provide|public|'
673 r'skip|split_thread|sum|take|thread|to|trait|type|where|with|' 692 r'require|returnhome|skip|split_thread|sum|take|thread|to|trait|'
674 r'yield|yieldhome)\b', 693 r'type|where|with|yield|yieldhome)\b',
675 bygroups(Punctuation, Keyword)), 694 bygroups(Punctuation, Keyword)),
676 695
677 # other 696 # other
678 (r',', Punctuation, 'commamember'), 697 (r',', Punctuation, 'commamember'),
679 (r'(and|or|not)\b', Operator.Word), 698 (r'(and|or|not)\b', Operator.Word),
1014 name = 'CoffeeScript' 1033 name = 'CoffeeScript'
1015 aliases = ['coffee-script', 'coffeescript', 'coffee'] 1034 aliases = ['coffee-script', 'coffeescript', 'coffee']
1016 filenames = ['*.coffee'] 1035 filenames = ['*.coffee']
1017 mimetypes = ['text/coffeescript'] 1036 mimetypes = ['text/coffeescript']
1018 1037
1038
1039 _operator_re = (
1040 r'\+\+|~|&&|\band\b|\bor\b|\bis\b|\bisnt\b|\bnot\b|\?|:|'
1041 r'\|\||\\(?=\n)|'
1042 r'(<<|>>>?|==?(?!>)|!=?|=(?!>)|-(?!>)|[<>+*`%&\|\^/])=?')
1043
1019 flags = re.DOTALL 1044 flags = re.DOTALL
1020 tokens = { 1045 tokens = {
1021 'commentsandwhitespace': [ 1046 'commentsandwhitespace': [
1022 (r'\s+', Text), 1047 (r'\s+', Text),
1023 (r'###[^#].*?###', Comment.Multiline), 1048 (r'###[^#].*?###', Comment.Multiline),
1032 'slashstartsregex': [ 1057 'slashstartsregex': [
1033 include('commentsandwhitespace'), 1058 include('commentsandwhitespace'),
1034 (r'///', String.Regex, ('#pop', 'multilineregex')), 1059 (r'///', String.Regex, ('#pop', 'multilineregex')),
1035 (r'/(?! )(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' 1060 (r'/(?! )(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
1036 r'([gim]+\b|\B)', String.Regex, '#pop'), 1061 r'([gim]+\b|\B)', String.Regex, '#pop'),
1062 # This isn't really guarding against mishighlighting well-formed
1063 # code, just the ability to infinite-loop between root and
1064 # slashstartsregex.
1065 (r'/', Operator),
1037 default('#pop'), 1066 default('#pop'),
1038 ], 1067 ],
1039 'root': [ 1068 'root': [
1040 # this next expr leads to infinite loops root -> slashstartsregex
1041 # (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'),
1042 include('commentsandwhitespace'), 1069 include('commentsandwhitespace'),
1043 (r'\+\+|~|&&|\band\b|\bor\b|\bis\b|\bisnt\b|\bnot\b|\?|:|' 1070 (r'^(?=\s|/)', Text, 'slashstartsregex'),
1044 r'\|\||\\(?=\n)|' 1071 (_operator_re, Operator, 'slashstartsregex'),
1045 r'(<<|>>>?|==?(?!>)|!=?|=(?!>)|-(?!>)|[<>+*`%&|^/])=?', 1072 (r'(?:\([^()]*\))?\s*[=-]>', Name.Function, 'slashstartsregex'),
1046 Operator, 'slashstartsregex'),
1047 (r'(?:\([^()]*\))?\s*[=-]>', Name.Function),
1048 (r'[{(\[;,]', Punctuation, 'slashstartsregex'), 1073 (r'[{(\[;,]', Punctuation, 'slashstartsregex'),
1049 (r'[})\].]', Punctuation), 1074 (r'[})\].]', Punctuation),
1050 (r'(?<![.$])(for|own|in|of|while|until|' 1075 (r'(?<![.$])(for|own|in|of|while|until|'
1051 r'loop|break|return|continue|' 1076 r'loop|break|return|continue|'
1052 r'switch|when|then|if|unless|else|' 1077 r'switch|when|then|if|unless|else|'
1063 (r'[$a-zA-Z_][\w.:$]*\s*[:=]\s', Name.Variable, 1088 (r'[$a-zA-Z_][\w.:$]*\s*[:=]\s', Name.Variable,
1064 'slashstartsregex'), 1089 'slashstartsregex'),
1065 (r'@[$a-zA-Z_][\w.:$]*\s*[:=]\s', Name.Variable.Instance, 1090 (r'@[$a-zA-Z_][\w.:$]*\s*[:=]\s', Name.Variable.Instance,
1066 'slashstartsregex'), 1091 'slashstartsregex'),
1067 (r'@', Name.Other, 'slashstartsregex'), 1092 (r'@', Name.Other, 'slashstartsregex'),
1068 (r'@?[$a-zA-Z_][\w$]*', Name.Other, 'slashstartsregex'), 1093 (r'@?[$a-zA-Z_][\w$]*', Name.Other),
1069 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), 1094 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
1070 (r'0x[0-9a-fA-F]+', Number.Hex), 1095 (r'0x[0-9a-fA-F]+', Number.Hex),
1071 (r'[0-9]+', Number.Integer), 1096 (r'[0-9]+', Number.Integer),
1072 ('"""', String, 'tdqs'), 1097 ('"""', String, 'tdqs'),
1073 ("'''", String, 'tsqs'), 1098 ("'''", String, 'tsqs'),
1243 'root': [ 1268 'root': [
1244 (r'\n', Text), 1269 (r'\n', Text),
1245 include('control'), 1270 include('control'),
1246 (r'[^\S\n]+', Text), 1271 (r'[^\S\n]+', Text),
1247 (r';;.*\n', Comment), 1272 (r';;.*\n', Comment),
1248 (r'[\[\]\{\}\:\(\)\,\;]', Punctuation), 1273 (r'[\[\]{}:(),;]', Punctuation),
1249 (r'\\\n', Text), 1274 (r'\\\n', Text),
1250 (r'\\', Text), 1275 (r'\\', Text),
1251 include('errors'), 1276 include('errors'),
1252 (words(( 1277 (words((
1253 'with', 'where', 'when', 'and', 'not', 'or', 'in', 1278 'with', 'where', 'when', 'and', 'not', 'or', 'in',
1254 'as', 'of', 'is'), 1279 'as', 'of', 'is'),
1255 prefix=r'(?<=\s|\[)', suffix=r'(?![\w\$\-])'), 1280 prefix=r'(?<=\s|\[)', suffix=r'(?![\w$\-])'),
1256 Operator.Word), 1281 Operator.Word),
1257 (r'[\*@]?->', Name.Function), 1282 (r'[*@]?->', Name.Function),
1258 (r'[+\-*/~^<>%&|?!@#.]*=', Operator.Word), 1283 (r'[+\-*/~^<>%&|?!@#.]*=', Operator.Word),
1259 (r'\.{2,3}', Operator.Word), # Range Operator 1284 (r'\.{2,3}', Operator.Word), # Range Operator
1260 (r'([+*/~^<>&|?!]+)|([#\-](?=\s))|@@+(?=\s)|=+', Operator), 1285 (r'([+*/~^<>&|?!]+)|([#\-](?=\s))|@@+(?=\s)|=+', Operator),
1261 (r'(?<![\w\$\-])(var|let)(?:[^\w\$])', Keyword.Declaration), 1286 (r'(?<![\w$\-])(var|let)(?:[^\w$])', Keyword.Declaration),
1262 include('keywords'), 1287 include('keywords'),
1263 include('builtins'), 1288 include('builtins'),
1264 include('assignment'), 1289 include('assignment'),
1265 (r'''(?x) 1290 (r'''(?x)
1266 (?:()([a-zA-Z$_](?:[a-zA-Z$0-9_\-]*[a-zA-Z$0-9_])?)| 1291 (?:()([a-zA-Z$_](?:[\w$\-]*[\w$])?)|
1267 (?<=[\s\{\[\(])(\.)([a-zA-Z$_](?:[a-zA-Z$0-9_\-]*[a-zA-Z$0-9_])?)) 1292 (?<=[\s{\[(])(\.)([a-zA-Z$_](?:[\w$\-]*[\w$])?))
1268 (?=.*%)''', 1293 (?=.*%)''',
1269 bygroups(Punctuation, Name.Tag, Punctuation, Name.Class.Start), 'dbs'), 1294 bygroups(Punctuation, Name.Tag, Punctuation, Name.Class.Start), 'dbs'),
1270 (r'[rR]?`', String.Backtick, 'bt'), 1295 (r'[rR]?`', String.Backtick, 'bt'),
1271 (r'[rR]?```', String.Backtick, 'tbt'), 1296 (r'[rR]?```', String.Backtick, 'tbt'),
1272 (r'(?<=[\s\[\{\(,;])\.([a-zA-Z$_](?:[a-zA-Z$0-9_-]*[a-zA-Z$0-9_])?)' 1297 (r'(?<=[\s\[{(,;])\.([a-zA-Z$_](?:[\w$\-]*[\w$])?)'
1273 r'(?=[\s\]\}\),;])', String.Symbol), 1298 r'(?=[\s\]}),;])', String.Symbol),
1274 include('nested'), 1299 include('nested'),
1275 (r'(?:[rR]|[rR]\.[gmi]{1,3})?"', String, combined('stringescape', 'dqs')), 1300 (r'(?:[rR]|[rR]\.[gmi]{1,3})?"', String, combined('stringescape', 'dqs')),
1276 (r'(?:[rR]|[rR]\.[gmi]{1,3})?\'', String, combined('stringescape', 'sqs')), 1301 (r'(?:[rR]|[rR]\.[gmi]{1,3})?\'', String, combined('stringescape', 'sqs')),
1277 (r'"""', String, combined('stringescape', 'tdqs')), 1302 (r'"""', String, combined('stringescape', 'tdqs')),
1278 include('tuple'), 1303 include('tuple'),
1279 include('import_paths'), 1304 include('import_paths'),
1280 include('name'), 1305 include('name'),
1281 include('numbers'), 1306 include('numbers'),
1282 ], 1307 ],
1283 'dbs': [ 1308 'dbs': [
1284 (r'(\.)([a-zA-Z$_](?:[a-zA-Z$0-9_\-]*[a-zA-Z$0-9_])?)(?=[\[\.\s])', 1309 (r'(\.)([a-zA-Z$_](?:[\w$\-]*[\w$])?)(?=[.\[\s])',
1285 bygroups(Punctuation, Name.Class.DBS)), 1310 bygroups(Punctuation, Name.Class.DBS)),
1286 (r'(\[)([\^#][a-zA-Z$_](?:[a-zA-Z$0-9_\-]*[a-zA-Z$0-9_])?)(\])', 1311 (r'(\[)([\^#][a-zA-Z$_](?:[\w$\-]*[\w$])?)(\])',
1287 bygroups(Punctuation, Name.Entity.DBS, Punctuation)), 1312 bygroups(Punctuation, Name.Entity.DBS, Punctuation)),
1288 (r'\s+', Text), 1313 (r'\s+', Text),
1289 (r'%', Operator.DBS, '#pop'), 1314 (r'%', Operator.DBS, '#pop'),
1290 ], 1315 ],
1291 'import_paths': [ 1316 'import_paths': [
1292 (r'(?<=[\s:;,])(\.{1,3}(?:[\w\-]*/)*)(\w(?:[\w\-]*\w)*)(?=[\s;,])', 1317 (r'(?<=[\s:;,])(\.{1,3}(?:[\w\-]*/)*)(\w(?:[\w\-]*\w)*)(?=[\s;,])',
1293 bygroups(Text.Whitespace, Text)), 1318 bygroups(Text.Whitespace, Text)),
1294 ], 1319 ],
1295 'assignment': [ 1320 'assignment': [
1296 (r'(\.)?([a-zA-Z$_](?:[a-zA-Z$0-9_-]*[a-zA-Z$0-9_])?)' 1321 (r'(\.)?([a-zA-Z$_](?:[\w$\-]*[\w$])?)'
1297 r'(?=\s+[+\-*/~^<>%&|?!@#.]*\=\s)', 1322 r'(?=\s+[+\-*/~^<>%&|?!@#.]*\=\s)',
1298 bygroups(Punctuation, Name.Variable)) 1323 bygroups(Punctuation, Name.Variable))
1299 ], 1324 ],
1300 'errors': [ 1325 'errors': [
1301 (words(('Error', 'TypeError', 'ReferenceError'), 1326 (words(('Error', 'TypeError', 'ReferenceError'),
1302 prefix=r'(?<![\w\$\-\.])', suffix=r'(?![\w\$\-\.])'), 1327 prefix=r'(?<![\w\-$.])', suffix=r'(?![\w\-$.])'),
1303 Name.Exception), 1328 Name.Exception),
1304 (r'''(?x) 1329 (r'''(?x)
1305 (?<![\w\$]) 1330 (?<![\w$])
1306 E\.[\w\$](?:[\w\$\-]*[\w\$])? 1331 E\.[\w$](?:[\w$\-]*[\w$])?
1307 (?:\.[\w\$](?:[\w\$\-]*[\w\$])?)* 1332 (?:\.[\w$](?:[\w$\-]*[\w$])?)*
1308 (?=[\(\{\[\?\!\s])''', 1333 (?=[({\[?!\s])''',
1309 Name.Exception), 1334 Name.Exception),
1310 ], 1335 ],
1311 'control': [ 1336 'control': [
1312 (r'''(?x) 1337 (r'''(?x)
1313 ([a-zA-Z$_](?:[a-zA-Z$0-9_-]*[a-zA-Z$0-9_])?) 1338 ([a-zA-Z$_](?:[\w$-]*[\w$])?)
1314 (?!\n)\s+ 1339 (?!\n)\s+
1315 (?!and|as|each\*|each|in|is|mod|of|or|when|where|with) 1340 (?!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_])?)''', 1341 (?=(?:[+\-*/~^<>%&|?!@#.])?[a-zA-Z$_](?:[\w$-]*[\w$])?)''',
1317 Keyword.Control), 1342 Keyword.Control),
1318 (r'([a-zA-Z$_](?:[a-zA-Z$0-9_-]*[a-zA-Z$0-9_])?)(?!\n)\s+(?=[\'"\d\{\[\(])', 1343 (r'([a-zA-Z$_](?:[\w$-]*[\w$])?)(?!\n)\s+(?=[\'"\d{\[(])',
1319 Keyword.Control), 1344 Keyword.Control),
1320 (r'''(?x) 1345 (r'''(?x)
1321 (?: 1346 (?:
1322 (?<=[%=])| 1347 (?<=[%=])|
1323 (?<=[=\-]>)| 1348 (?<=[=\-]>)|
1324 (?<=with|each|with)| 1349 (?<=with|each|with)|
1325 (?<=each\*|where) 1350 (?<=each\*|where)
1326 )(\s+) 1351 )(\s+)
1327 ([a-zA-Z$_](?:[a-zA-Z$0-9_\-]*[a-zA-Z$0-9_])?)(:)''', 1352 ([a-zA-Z$_](?:[\w$-]*[\w$])?)(:)''',
1328 bygroups(Text, Keyword.Control, Punctuation)), 1353 bygroups(Text, Keyword.Control, Punctuation)),
1329 (r'''(?x) 1354 (r'''(?x)
1330 (?<![+\-*/~^<>%&|?!@#.])(\s+) 1355 (?<![+\-*/~^<>%&|?!@#.])(\s+)
1331 ([a-zA-Z$_](?:[a-zA-Z$0-9_-]*[a-zA-Z$0-9_])?)(:)''', 1356 ([a-zA-Z$_](?:[\w$-]*[\w$])?)(:)''',
1332 bygroups(Text, Keyword.Control, Punctuation)), 1357 bygroups(Text, Keyword.Control, Punctuation)),
1333 ], 1358 ],
1334 'nested': [ 1359 'nested': [
1335 (r'''(?x) 1360 (r'''(?x)
1336 (?<=[a-zA-Z$0-9_\]\}\)])(\.) 1361 (?<=[\w$\]})])(\.)
1337 ([a-zA-Z$_](?:[a-zA-Z$0-9_-]*[a-zA-Z$0-9_])?) 1362 ([a-zA-Z$_](?:[\w$-]*[\w$])?)
1338 (?=\s+with(?:\s|\n))''', 1363 (?=\s+with(?:\s|\n))''',
1339 bygroups(Punctuation, Name.Function)), 1364 bygroups(Punctuation, Name.Function)),
1340 (r'''(?x) 1365 (r'''(?x)
1341 (?<!\s)(\.) 1366 (?<!\s)(\.)
1342 ([a-zA-Z$_](?:[a-zA-Z$0-9_-]*[a-zA-Z$0-9_])?) 1367 ([a-zA-Z$_](?:[\w$-]*[\w$])?)
1343 (?=[\}\]\)\.,;:\s])''', 1368 (?=[}\]).,;:\s])''',
1344 bygroups(Punctuation, Name.Field)), 1369 bygroups(Punctuation, Name.Field)),
1345 (r'''(?x) 1370 (r'''(?x)
1346 (?<=[a-zA-Z$0-9_\]\}\)])(\.) 1371 (?<=[\w$\]})])(\.)
1347 ([a-zA-Z$_](?:[a-zA-Z$0-9_-]*[a-zA-Z$0-9_])?) 1372 ([a-zA-Z$_](?:[\w$-]*[\w$])?)
1348 (?=[\[\{\(:])''', 1373 (?=[\[{(:])''',
1349 bygroups(Punctuation, Name.Function)), 1374 bygroups(Punctuation, Name.Function)),
1350 ], 1375 ],
1351 'keywords': [ 1376 'keywords': [
1352 (words(( 1377 (words((
1353 'each', 'each*', 'mod', 'await', 'break', 'chain', 1378 'each', 'each*', 'mod', 'await', 'break', 'chain',
1354 'continue', 'elif', 'expr-value', 'if', 'match', 1379 'continue', 'elif', 'expr-value', 'if', 'match',
1355 'return', 'yield', 'pass', 'else', 'require', 'var', 1380 'return', 'yield', 'pass', 'else', 'require', 'var',
1356 'let', 'async', 'method', 'gen'), 1381 'let', 'async', 'method', 'gen'),
1357 prefix=r'(?<![\w\$\-\.])', suffix=r'(?![\w\$\-\.])'), 1382 prefix=r'(?<![\w\-$.])', suffix=r'(?![\w\-$.])'),
1358 Keyword.Pseudo), 1383 Keyword.Pseudo),
1359 (words(('this', 'self', '@'), 1384 (words(('this', 'self', '@'),
1360 prefix=r'(?<![\w\$\-\.])', suffix=r'(?![\w\$\-])'), 1385 prefix=r'(?<![\w\-$.])', suffix=r'(?![\w\-$])'),
1361 Keyword.Constant), 1386 Keyword.Constant),
1362 (words(( 1387 (words((
1363 'Function', 'Object', 'Array', 'String', 'Number', 1388 'Function', 'Object', 'Array', 'String', 'Number',
1364 'Boolean', 'ErrorFactory', 'ENode', 'Promise'), 1389 'Boolean', 'ErrorFactory', 'ENode', 'Promise'),
1365 prefix=r'(?<![\w\$\-\.])', suffix=r'(?![\w\$\-])'), 1390 prefix=r'(?<![\w\-$.])', suffix=r'(?![\w\-$])'),
1366 Keyword.Type), 1391 Keyword.Type),
1367 ], 1392 ],
1368 'builtins': [ 1393 'builtins': [
1369 (words(( 1394 (words((
1370 'send', 'object', 'keys', 'items', 'enumerate', 'zip', 1395 'send', 'object', 'keys', 'items', 'enumerate', 'zip',
1371 'product', 'neighbours', 'predicate', 'equal', 1396 'product', 'neighbours', 'predicate', 'equal',
1372 'nequal', 'contains', 'repr', 'clone', 'range', 1397 'nequal', 'contains', 'repr', 'clone', 'range',
1373 'getChecker', 'get-checker', 'getProperty', 'get-property', 1398 'getChecker', 'get-checker', 'getProperty', 'get-property',
1374 'getProjector', 'get-projector', 'consume', 'take', 1399 'getProjector', 'get-projector', 'consume', 'take',
1375 'promisify', 'spawn', 'constructor'), 1400 'promisify', 'spawn', 'constructor'),
1376 prefix=r'(?<![\w\-#\.])', suffix=r'(?![\w\-\.])'), 1401 prefix=r'(?<![\w\-#.])', suffix=r'(?![\w\-.])'),
1377 Name.Builtin), 1402 Name.Builtin),
1378 (words(( 1403 (words((
1379 'true', 'false', 'null', 'undefined'), 1404 'true', 'false', 'null', 'undefined'),
1380 prefix=r'(?<![\w\$\-\.])', suffix=r'(?![\w\$\-\.])'), 1405 prefix=r'(?<![\w\-$.])', suffix=r'(?![\w\-$.])'),
1381 Name.Constant), 1406 Name.Constant),
1382 ], 1407 ],
1383 'name': [ 1408 'name': [
1384 (r'@([a-zA-Z$_](?:[a-zA-Z$0-9_-]*[a-zA-Z$0-9_])?)', Name.Variable.Instance), 1409 (r'@([a-zA-Z$_](?:[\w$-]*[\w$])?)', Name.Variable.Instance),
1385 (r'([a-zA-Z$_](?:[a-zA-Z$0-9_-]*[a-zA-Z$0-9_])?)(\+\+|\-\-)?', 1410 (r'([a-zA-Z$_](?:[\w$-]*[\w$])?)(\+\+|\-\-)?',
1386 bygroups(Name.Symbol, Operator.Word)) 1411 bygroups(Name.Symbol, Operator.Word))
1387 ], 1412 ],
1388 'tuple': [ 1413 'tuple': [
1389 (r'#[a-zA-Z_][a-zA-Z_\-0-9]*(?=[\s\{\(,;\n])', Name.Namespace) 1414 (r'#[a-zA-Z_][\w\-]*(?=[\s{(,;])', Name.Namespace)
1390 ], 1415 ],
1391 'interpoling_string': [ 1416 'interpoling_string': [
1392 (r'\}', String.Interpol, '#pop'), 1417 (r'\}', String.Interpol, '#pop'),
1393 include('root') 1418 include('root')
1394 ], 1419 ],
1424 ], 1449 ],
1425 'tbt': [ 1450 'tbt': [
1426 (r'```', String.Backtick, '#pop'), 1451 (r'```', String.Backtick, '#pop'),
1427 (r'\n', String.Backtick), 1452 (r'\n', String.Backtick),
1428 (r'\^=?', String.Escape), 1453 (r'\^=?', String.Escape),
1429 (r'[^\`]+', String.Backtick), 1454 (r'[^`]+', String.Backtick),
1430 ], 1455 ],
1431 'numbers': [ 1456 'numbers': [
1432 (r'\d+\.(?!\.)\d*([eE][+-]?[0-9]+)?', Number.Float), 1457 (r'\d+\.(?!\.)\d*([eE][+-]?[0-9]+)?', Number.Float),
1433 (r'\d+[eE][+-]?[0-9]+', Number.Float), 1458 (r'\d+[eE][+-]?[0-9]+', Number.Float),
1434 (r'8r[0-7]+', Number.Oct), 1459 (r'8r[0-7]+', Number.Oct),
1435 (r'2r[01]+', Number.Bin), 1460 (r'2r[01]+', Number.Bin),
1436 (r'16r[a-fA-F0-9]+', Number.Hex), 1461 (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), 1462 (r'([3-79]|[12][0-9]|3[0-6])r[a-zA-Z\d]+(\.[a-zA-Z\d]+)?', Number.Radix),
1438 (r'\d+', Number.Integer) 1463 (r'\d+', Number.Integer)
1439 ], 1464 ],
1440 } 1465 }
1466
1467 class JuttleLexer(RegexLexer):
1468 """
1469 For `Juttle`_ source code.
1470
1471 .. _Juttle: https://github.com/juttle/juttle
1472
1473 """
1474
1475 name = 'Juttle'
1476 aliases = ['juttle', 'juttle']
1477 filenames = ['*.juttle']
1478 mimetypes = ['application/juttle', 'application/x-juttle',
1479 'text/x-juttle', 'text/juttle']
1480
1481 flags = re.DOTALL | re.UNICODE | re.MULTILINE
1482
1483 tokens = {
1484 'commentsandwhitespace': [
1485 (r'\s+', Text),
1486 (r'//.*?\n', Comment.Single),
1487 (r'/\*.*?\*/', Comment.Multiline)
1488 ],
1489 'slashstartsregex': [
1490 include('commentsandwhitespace'),
1491 (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
1492 r'([gim]+\b|\B)', String.Regex, '#pop'),
1493 (r'(?=/)', Text, ('#pop', 'badregex')),
1494 default('#pop')
1495 ],
1496 'badregex': [
1497 (r'\n', Text, '#pop')
1498 ],
1499 'root': [
1500 (r'^(?=\s|/)', Text, 'slashstartsregex'),
1501 include('commentsandwhitespace'),
1502 (r':\d{2}:\d{2}:\d{2}(\.\d*)?:', String.Moment),
1503 (r':(now|beginning|end|forever|yesterday|today|tomorrow|(\d+(\.\d*)?|\.\d+)(ms|[smhdwMy])?):', String.Moment),
1504 (r':\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d*)?)?(Z|[+-]\d{2}:\d{2}|[+-]\d{4})?:', String.Moment),
1505 (r':((\d+(\.\d*)?|\.\d+)[ ]+)?(millisecond|second|minute|hour|day|week|month|year)[s]?'
1506 r'(([ ]+and[ ]+(\d+[ ]+)?(millisecond|second|minute|hour|day|week|month|year)[s]?)'
1507 r'|[ ]+(ago|from[ ]+now))*:', String.Moment),
1508 (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|'
1509 r'(==?|!=?|[-<>+*%&|^/])=?', Operator, 'slashstartsregex'),
1510 (r'[{(\[;,]', Punctuation, 'slashstartsregex'),
1511 (r'[})\].]', Punctuation),
1512 (r'(import|return|continue|if|else)\b', Keyword, 'slashstartsregex'),
1513 (r'(var|const|function|reducer|sub|input)\b', Keyword.Declaration, 'slashstartsregex'),
1514 (r'(batch|emit|filter|head|join|keep|pace|pass|put|read|reduce|remove|'
1515 r'sequence|skip|sort|split|tail|unbatch|uniq|view|write)\b', Keyword.Reserved),
1516 (r'(true|false|null|Infinity)\b', Keyword.Constant),
1517 (r'(Array|Date|Juttle|Math|Number|Object|RegExp|String)\b', Name.Builtin),
1518 (JS_IDENT, Name.Other),
1519 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
1520 (r'[0-9]+', Number.Integer),
1521 (r'"(\\\\|\\"|[^"])*"', String.Double),
1522 (r"'(\\\\|\\'|[^'])*'", String.Single)
1523 ]
1524
1525 }

eric ide

mercurial