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

changeset 7547
21b0534faebc
parent 6942
2602857055c5
child 7701
25f42e208e08
equal deleted inserted replaced
7546:bf5f777260a6 7547:21b0534faebc
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-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 RegexLexer, include, bygroups, default, using, \ 14 from pygments.lexer import RegexLexer, include, bygroups, default, using, \
15 this, words, combined 15 this, words, 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, Other 17 Number, Punctuation, Other
18 from pygments.util import get_bool_opt, iteritems 18 from pygments.util import get_bool_opt
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', 'JuttleLexer'] 23 'CoffeeScriptLexer', 'MaskLexer', 'EarlGreyLexer', 'JuttleLexer']
35 For JavaScript source code. 35 For JavaScript source code.
36 """ 36 """
37 37
38 name = 'JavaScript' 38 name = 'JavaScript'
39 aliases = ['js', 'javascript'] 39 aliases = ['js', 'javascript']
40 filenames = ['*.js', '*.jsm'] 40 filenames = ['*.js', '*.jsm', '*.mjs']
41 mimetypes = ['application/javascript', 'application/x-javascript', 41 mimetypes = ['application/javascript', 'application/x-javascript',
42 'text/x-javascript', 'text/javascript'] 42 'text/x-javascript', 'text/javascript']
43 43
44 flags = re.DOTALL | re.UNICODE | re.MULTILINE 44 flags = re.DOTALL | re.UNICODE | re.MULTILINE
45 45
257 'slashstartsregex': [ 257 'slashstartsregex': [
258 include('commentsandwhitespace'), 258 include('commentsandwhitespace'),
259 (r'//', String.Regex, ('#pop', 'multilineregex')), 259 (r'//', String.Regex, ('#pop', 'multilineregex')),
260 (r'/(?! )(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' 260 (r'/(?! )(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
261 r'([gim]+\b|\B)', String.Regex, '#pop'), 261 r'([gim]+\b|\B)', String.Regex, '#pop'),
262 (r'/', Operator, '#pop'),
262 default('#pop'), 263 default('#pop'),
263 ], 264 ],
264 'root': [ 265 'root': [
265 # this next expr leads to infinite loops root -> slashstartsregex 266 (r'^(?=\s|/)', Text, 'slashstartsregex'),
266 # (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'),
267 include('commentsandwhitespace'), 267 include('commentsandwhitespace'),
268 (r'(?:\([^()]+\))?[ ]*[~-]{1,2}>|' 268 (r'(?:\([^()]+\))?[ ]*[~-]{1,2}>|'
269 r'(?:\(?[^()\n]+\)?)?[ ]*<[~-]{1,2}', Name.Function), 269 r'(?:\(?[^()\n]+\)?)?[ ]*<[~-]{1,2}', Name.Function),
270 (r'\+\+|&&|(?<![.$])\b(?:and|x?or|is|isnt|not)\b|\?|:|=|' 270 (r'\+\+|&&|(?<![.$])\b(?:and|x?or|is|isnt|not)\b|\?|:|=|'
271 r'\|\||\\(?=\n)|(<<|>>>?|==?|!=?|' 271 r'\|\||\\(?=\n)|(<<|>>>?|==?|!=?|'
370 r'implements|native|operator|set|static|sync|typedef|var|with|' 370 r'implements|native|operator|set|static|sync|typedef|var|with|'
371 r'yield)\b', Keyword.Declaration), 371 r'yield)\b', Keyword.Declaration),
372 (r'\b(bool|double|dynamic|int|num|Object|String|void)\b', Keyword.Type), 372 (r'\b(bool|double|dynamic|int|num|Object|String|void)\b', Keyword.Type),
373 (r'\b(false|null|true)\b', Keyword.Constant), 373 (r'\b(false|null|true)\b', Keyword.Constant),
374 (r'[~!%^&*+=|?:<>/-]|as\b', Operator), 374 (r'[~!%^&*+=|?:<>/-]|as\b', Operator),
375 (r'@[a-zA-Z_$]\w*', Name.Decorator),
375 (r'[a-zA-Z_$]\w*:', Name.Label), 376 (r'[a-zA-Z_$]\w*:', Name.Label),
376 (r'[a-zA-Z_$]\w*', Name), 377 (r'[a-zA-Z_$]\w*', Name),
377 (r'[(){}\[\],.;]', Punctuation), 378 (r'[(){}\[\],.;]', Punctuation),
378 (r'0[xX][0-9a-fA-F]+', Number.Hex), 379 (r'0[xX][0-9a-fA-F]+', Number.Hex),
379 # DIGIT+ (‘.’ DIGIT*)? EXPONENT? 380 # DIGIT+ (‘.’ DIGIT*)? EXPONENT?
451 filenames = ['*.ts', '*.tsx'] 452 filenames = ['*.ts', '*.tsx']
452 mimetypes = ['text/x-typescript'] 453 mimetypes = ['text/x-typescript']
453 454
454 flags = re.DOTALL | re.MULTILINE 455 flags = re.DOTALL | re.MULTILINE
455 456
457 # Higher priority than the TypoScriptLexer, as TypeScript is far more
458 # common these days
459 priority = 0.5
460
456 tokens = { 461 tokens = {
457 'commentsandwhitespace': [ 462 'commentsandwhitespace': [
458 (r'\s+', Text), 463 (r'\s+', Text),
459 (r'<!--', Comment), 464 (r'<!--', Comment),
460 (r'//.*?\n', Comment.Single), 465 (r'//.*?\n', Comment.Single),
476 (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|' 481 (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|'
477 r'(<<|>>>?|==?|!=?|[-<>+*%&|^/])=?', Operator, 'slashstartsregex'), 482 r'(<<|>>>?|==?|!=?|[-<>+*%&|^/])=?', Operator, 'slashstartsregex'),
478 (r'[{(\[;,]', Punctuation, 'slashstartsregex'), 483 (r'[{(\[;,]', Punctuation, 'slashstartsregex'),
479 (r'[})\].]', Punctuation), 484 (r'[})\].]', Punctuation),
480 (r'(for|in|while|do|break|return|continue|switch|case|default|if|else|' 485 (r'(for|in|while|do|break|return|continue|switch|case|default|if|else|'
481 r'throw|try|catch|finally|new|delete|typeof|instanceof|void|' 486 r'throw|try|catch|finally|new|delete|typeof|instanceof|void|of|'
482 r'this)\b', Keyword, 'slashstartsregex'), 487 r'this)\b', Keyword, 'slashstartsregex'),
483 (r'(var|let|with|function)\b', Keyword.Declaration, 'slashstartsregex'), 488 (r'(var|let|with|function)\b', Keyword.Declaration, 'slashstartsregex'),
484 (r'(abstract|boolean|byte|char|class|const|debugger|double|enum|export|' 489 (r'(abstract|boolean|byte|char|class|const|debugger|double|enum|export|'
485 r'extends|final|float|goto|implements|import|int|interface|long|native|' 490 r'extends|final|float|goto|implements|import|int|interface|long|native|'
486 r'package|private|protected|public|short|static|super|synchronized|throws|' 491 r'package|private|protected|public|short|static|super|synchronized|throws|'
532 (r'\}', String.Interpol, '#pop'), 537 (r'\}', String.Interpol, '#pop'),
533 include('root'), 538 include('root'),
534 ], 539 ],
535 } 540 }
536 541
537 def analyse_text(text):
538 if re.search(r'^(import.+(from\s+)?["\']|'
539 r'(export\s*)?(interface|class|function)\s+)',
540 text, re.MULTILINE):
541 return 1.0
542
543 542
544 class LassoLexer(RegexLexer): 543 class LassoLexer(RegexLexer):
545 """ 544 """
546 For `Lasso <http://www.lassosoft.com/>`_ source code, covering both Lasso 9 545 For `Lasso <http://www.lassosoft.com/>`_ source code, covering both Lasso 9
547 syntax and LassoScript for Lasso 8.6 and earlier. For Lasso embedded in 546 syntax and LassoScript for Lasso 8.6 and earlier. For Lasso embedded in
766 765
767 self._builtins = set() 766 self._builtins = set()
768 self._members = set() 767 self._members = set()
769 if self.builtinshighlighting: 768 if self.builtinshighlighting:
770 from pygments.lexers._lasso_builtins import BUILTINS, MEMBERS 769 from pygments.lexers._lasso_builtins import BUILTINS, MEMBERS
771 for key, value in iteritems(BUILTINS): 770 for key, value in BUILTINS.items():
772 self._builtins.update(value) 771 self._builtins.update(value)
773 for key, value in iteritems(MEMBERS): 772 for key, value in MEMBERS.items():
774 self._members.update(value) 773 self._members.update(value)
775 RegexLexer.__init__(self, **options) 774 RegexLexer.__init__(self, **options)
776 775
777 def get_tokens_unprocessed(self, text): 776 def get_tokens_unprocessed(self, text):
778 stack = ['root'] 777 stack = ['root']
1033 name = 'CoffeeScript' 1032 name = 'CoffeeScript'
1034 aliases = ['coffee-script', 'coffeescript', 'coffee'] 1033 aliases = ['coffee-script', 'coffeescript', 'coffee']
1035 filenames = ['*.coffee'] 1034 filenames = ['*.coffee']
1036 mimetypes = ['text/coffeescript'] 1035 mimetypes = ['text/coffeescript']
1037 1036
1038
1039 _operator_re = ( 1037 _operator_re = (
1040 r'\+\+|~|&&|\band\b|\bor\b|\bis\b|\bisnt\b|\bnot\b|\?|:|' 1038 r'\+\+|~|&&|\band\b|\bor\b|\bis\b|\bisnt\b|\bnot\b|\?|:|'
1041 r'\|\||\\(?=\n)|' 1039 r'\|\||\\(?=\n)|'
1042 r'(<<|>>>?|==?(?!>)|!=?|=(?!>)|-(?!>)|[<>+*`%&\|\^/])=?') 1040 r'(<<|>>>?|==?(?!>)|!=?|=(?!>)|-(?!>)|[<>+*`%&\|\^/])=?')
1043 1041
1060 (r'/(?! )(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' 1058 (r'/(?! )(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
1061 r'([gim]+\b|\B)', String.Regex, '#pop'), 1059 r'([gim]+\b|\B)', String.Regex, '#pop'),
1062 # This isn't really guarding against mishighlighting well-formed 1060 # This isn't really guarding against mishighlighting well-formed
1063 # code, just the ability to infinite-loop between root and 1061 # code, just the ability to infinite-loop between root and
1064 # slashstartsregex. 1062 # slashstartsregex.
1065 (r'/', Operator), 1063 (r'/', Operator, '#pop'),
1066 default('#pop'), 1064 default('#pop'),
1067 ], 1065 ],
1068 'root': [ 1066 'root': [
1069 include('commentsandwhitespace'), 1067 include('commentsandwhitespace'),
1070 (r'^(?=\s|/)', Text, 'slashstartsregex'), 1068 (r'^(?=\s|/)', Text, 'slashstartsregex'),
1135 } 1133 }
1136 1134
1137 1135
1138 class MaskLexer(RegexLexer): 1136 class MaskLexer(RegexLexer):
1139 """ 1137 """
1140 For `Mask <http://github.com/atmajs/MaskJS>`__ markup. 1138 For `Mask <https://github.com/atmajs/MaskJS>`__ markup.
1141 1139
1142 .. versionadded:: 2.0 1140 .. versionadded:: 2.0
1143 """ 1141 """
1144 name = 'Mask' 1142 name = 'Mask'
1145 aliases = ['mask'] 1143 aliases = ['mask']
1457 (r'\d+\.(?!\.)\d*([eE][+-]?[0-9]+)?', Number.Float), 1455 (r'\d+\.(?!\.)\d*([eE][+-]?[0-9]+)?', Number.Float),
1458 (r'\d+[eE][+-]?[0-9]+', Number.Float), 1456 (r'\d+[eE][+-]?[0-9]+', Number.Float),
1459 (r'8r[0-7]+', Number.Oct), 1457 (r'8r[0-7]+', Number.Oct),
1460 (r'2r[01]+', Number.Bin), 1458 (r'2r[01]+', Number.Bin),
1461 (r'16r[a-fA-F0-9]+', Number.Hex), 1459 (r'16r[a-fA-F0-9]+', Number.Hex),
1462 (r'([3-79]|[12][0-9]|3[0-6])r[a-zA-Z\d]+(\.[a-zA-Z\d]+)?', Number.Radix), 1460 (r'([3-79]|[12][0-9]|3[0-6])r[a-zA-Z\d]+(\.[a-zA-Z\d]+)?',
1461 Number.Radix),
1463 (r'\d+', Number.Integer) 1462 (r'\d+', Number.Integer)
1464 ], 1463 ],
1465 } 1464 }
1466 1465
1466
1467 class JuttleLexer(RegexLexer): 1467 class JuttleLexer(RegexLexer):
1468 """ 1468 """
1469 For `Juttle`_ source code. 1469 For `Juttle`_ source code.
1470 1470
1471 .. _Juttle: https://github.com/juttle/juttle 1471 .. _Juttle: https://github.com/juttle/juttle
1472 1472
1473 .. versionadded:: 2.2
1473 """ 1474 """
1474 1475
1475 name = 'Juttle' 1476 name = 'Juttle'
1476 aliases = ['juttle', 'juttle'] 1477 aliases = ['juttle', 'juttle']
1477 filenames = ['*.juttle'] 1478 filenames = ['*.juttle']
1502 (r':\d{2}:\d{2}:\d{2}(\.\d*)?:', String.Moment), 1503 (r':\d{2}:\d{2}:\d{2}(\.\d*)?:', String.Moment),
1503 (r':(now|beginning|end|forever|yesterday|today|tomorrow|' 1504 (r':(now|beginning|end|forever|yesterday|today|tomorrow|'
1504 r'(\d+(\.\d*)?|\.\d+)(ms|[smhdwMy])?):', String.Moment), 1505 r'(\d+(\.\d*)?|\.\d+)(ms|[smhdwMy])?):', String.Moment),
1505 (r':\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d*)?)?' 1506 (r':\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d*)?)?'
1506 r'(Z|[+-]\d{2}:\d{2}|[+-]\d{4})?:', String.Moment), 1507 r'(Z|[+-]\d{2}:\d{2}|[+-]\d{4})?:', String.Moment),
1507 (r':((\d+(\.\d*)?|\.\d+)[ ]+)?(millisecond|second|minute|hour|day|week|month|year)[s]?' 1508 (r':((\d+(\.\d*)?|\.\d+)[ ]+)?(millisecond|second|minute|hour|'
1508 r'(([ ]+and[ ]+(\d+[ ]+)?(millisecond|second|minute|hour|day|week|month|year)[s]?)' 1509 r'day|week|month|year)[s]?'
1510 r'(([ ]+and[ ]+(\d+[ ]+)?(millisecond|second|minute|hour|'
1511 r'day|week|month|year)[s]?)'
1509 r'|[ ]+(ago|from[ ]+now))*:', String.Moment), 1512 r'|[ ]+(ago|from[ ]+now))*:', String.Moment),
1510 (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|' 1513 (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|'
1511 r'(==?|!=?|[-<>+*%&|^/])=?', Operator, 'slashstartsregex'), 1514 r'(==?|!=?|[-<>+*%&|^/])=?', Operator, 'slashstartsregex'),
1512 (r'[{(\[;,]', Punctuation, 'slashstartsregex'), 1515 (r'[{(\[;,]', Punctuation, 'slashstartsregex'),
1513 (r'[})\].]', Punctuation), 1516 (r'[})\].]', Punctuation),
1514 (r'(import|return|continue|if|else)\b', Keyword, 'slashstartsregex'), 1517 (r'(import|return|continue|if|else)\b', Keyword, 'slashstartsregex'),
1515 (r'(var|const|function|reducer|sub|input)\b', Keyword.Declaration, 'slashstartsregex'), 1518 (r'(var|const|function|reducer|sub|input)\b', Keyword.Declaration,
1519 'slashstartsregex'),
1516 (r'(batch|emit|filter|head|join|keep|pace|pass|put|read|reduce|remove|' 1520 (r'(batch|emit|filter|head|join|keep|pace|pass|put|read|reduce|remove|'
1517 r'sequence|skip|sort|split|tail|unbatch|uniq|view|write)\b', Keyword.Reserved), 1521 r'sequence|skip|sort|split|tail|unbatch|uniq|view|write)\b',
1522 Keyword.Reserved),
1518 (r'(true|false|null|Infinity)\b', Keyword.Constant), 1523 (r'(true|false|null|Infinity)\b', Keyword.Constant),
1519 (r'(Array|Date|Juttle|Math|Number|Object|RegExp|String)\b', Name.Builtin), 1524 (r'(Array|Date|Juttle|Math|Number|Object|RegExp|String)\b',
1525 Name.Builtin),
1520 (JS_IDENT, Name.Other), 1526 (JS_IDENT, Name.Other),
1521 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), 1527 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
1522 (r'[0-9]+', Number.Integer), 1528 (r'[0-9]+', Number.Integer),
1523 (r'"(\\\\|\\"|[^"])*"', String.Double), 1529 (r'"(\\\\|\\"|[^"])*"', String.Double),
1524 (r"'(\\\\|\\'|[^'])*'", String.Single) 1530 (r"'(\\\\|\\'|[^'])*'", String.Single)

eric ide

mercurial