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

changeset 7547
21b0534faebc
parent 6942
2602857055c5
child 7701
25f42e208e08
--- a/eric6/ThirdParty/Pygments/pygments/lexers/javascript.py	Tue Apr 21 19:44:19 2020 +0200
+++ b/eric6/ThirdParty/Pygments/pygments/lexers/javascript.py	Tue Apr 21 19:47:10 2020 +0200
@@ -5,7 +5,7 @@
 
     Lexers for JavaScript and related languages.
 
-    :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS.
+    :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS.
     :license: BSD, see LICENSE for details.
 """
 
@@ -15,7 +15,7 @@
     this, words, combined
 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
     Number, Punctuation, Other
-from pygments.util import get_bool_opt, iteritems
+from pygments.util import get_bool_opt
 import pygments.unistring as uni
 
 __all__ = ['JavascriptLexer', 'KalLexer', 'LiveScriptLexer', 'DartLexer',
@@ -37,7 +37,7 @@
 
     name = 'JavaScript'
     aliases = ['js', 'javascript']
-    filenames = ['*.js', '*.jsm']
+    filenames = ['*.js', '*.jsm', '*.mjs']
     mimetypes = ['application/javascript', 'application/x-javascript',
                  'text/x-javascript', 'text/javascript']
 
@@ -259,11 +259,11 @@
             (r'//', String.Regex, ('#pop', 'multilineregex')),
             (r'/(?! )(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
              r'([gim]+\b|\B)', String.Regex, '#pop'),
+            (r'/', Operator, '#pop'),
             default('#pop'),
         ],
         'root': [
-            # this next expr leads to infinite loops root -> slashstartsregex
-            # (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'),
+            (r'^(?=\s|/)', Text, 'slashstartsregex'),
             include('commentsandwhitespace'),
             (r'(?:\([^()]+\))?[ ]*[~-]{1,2}>|'
              r'(?:\(?[^()\n]+\)?)?[ ]*<[~-]{1,2}', Name.Function),
@@ -372,6 +372,7 @@
             (r'\b(bool|double|dynamic|int|num|Object|String|void)\b', Keyword.Type),
             (r'\b(false|null|true)\b', Keyword.Constant),
             (r'[~!%^&*+=|?:<>/-]|as\b', Operator),
+            (r'@[a-zA-Z_$]\w*', Name.Decorator),
             (r'[a-zA-Z_$]\w*:', Name.Label),
             (r'[a-zA-Z_$]\w*', Name),
             (r'[(){}\[\],.;]', Punctuation),
@@ -453,6 +454,10 @@
 
     flags = re.DOTALL | re.MULTILINE
 
+    # Higher priority than the TypoScriptLexer, as TypeScript is far more
+    # common these days
+    priority = 0.5
+
     tokens = {
         'commentsandwhitespace': [
             (r'\s+', Text),
@@ -478,7 +483,7 @@
             (r'[{(\[;,]', Punctuation, 'slashstartsregex'),
             (r'[})\].]', Punctuation),
             (r'(for|in|while|do|break|return|continue|switch|case|default|if|else|'
-             r'throw|try|catch|finally|new|delete|typeof|instanceof|void|'
+             r'throw|try|catch|finally|new|delete|typeof|instanceof|void|of|'
              r'this)\b', Keyword, 'slashstartsregex'),
             (r'(var|let|with|function)\b', Keyword.Declaration, 'slashstartsregex'),
             (r'(abstract|boolean|byte|char|class|const|debugger|double|enum|export|'
@@ -534,12 +539,6 @@
         ],
     }
 
-    def analyse_text(text):
-        if re.search(r'^(import.+(from\s+)?["\']|'
-                     r'(export\s*)?(interface|class|function)\s+)',
-                     text, re.MULTILINE):
-            return 1.0
-
 
 class LassoLexer(RegexLexer):
     """
@@ -768,9 +767,9 @@
         self._members = set()
         if self.builtinshighlighting:
             from pygments.lexers._lasso_builtins import BUILTINS, MEMBERS
-            for key, value in iteritems(BUILTINS):
+            for key, value in BUILTINS.items():
                 self._builtins.update(value)
-            for key, value in iteritems(MEMBERS):
+            for key, value in MEMBERS.items():
                 self._members.update(value)
         RegexLexer.__init__(self, **options)
 
@@ -1035,7 +1034,6 @@
     filenames = ['*.coffee']
     mimetypes = ['text/coffeescript']
 
-
     _operator_re = (
         r'\+\+|~|&&|\band\b|\bor\b|\bis\b|\bisnt\b|\bnot\b|\?|:|'
         r'\|\||\\(?=\n)|'
@@ -1062,7 +1060,7 @@
             # This isn't really guarding against mishighlighting well-formed
             # code, just the ability to infinite-loop between root and
             # slashstartsregex.
-            (r'/', Operator),
+            (r'/', Operator, '#pop'),
             default('#pop'),
         ],
         'root': [
@@ -1137,7 +1135,7 @@
 
 class MaskLexer(RegexLexer):
     """
-    For `Mask <http://github.com/atmajs/MaskJS>`__ markup.
+    For `Mask <https://github.com/atmajs/MaskJS>`__ markup.
 
     .. versionadded:: 2.0
     """
@@ -1459,17 +1457,20 @@
             (r'8r[0-7]+', Number.Oct),
             (r'2r[01]+', Number.Bin),
             (r'16r[a-fA-F0-9]+', Number.Hex),
-            (r'([3-79]|[12][0-9]|3[0-6])r[a-zA-Z\d]+(\.[a-zA-Z\d]+)?', Number.Radix),
+            (r'([3-79]|[12][0-9]|3[0-6])r[a-zA-Z\d]+(\.[a-zA-Z\d]+)?',
+             Number.Radix),
             (r'\d+', Number.Integer)
         ],
     }
 
+
 class JuttleLexer(RegexLexer):
     """
     For `Juttle`_ source code.
 
     .. _Juttle: https://github.com/juttle/juttle
 
+    .. versionadded:: 2.2
     """
 
     name = 'Juttle'
@@ -1504,19 +1505,24 @@
              r'(\d+(\.\d*)?|\.\d+)(ms|[smhdwMy])?):', String.Moment),
             (r':\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d*)?)?'
              r'(Z|[+-]\d{2}:\d{2}|[+-]\d{4})?:', String.Moment),
-            (r':((\d+(\.\d*)?|\.\d+)[ ]+)?(millisecond|second|minute|hour|day|week|month|year)[s]?'
-             r'(([ ]+and[ ]+(\d+[ ]+)?(millisecond|second|minute|hour|day|week|month|year)[s]?)'
+            (r':((\d+(\.\d*)?|\.\d+)[ ]+)?(millisecond|second|minute|hour|'
+             r'day|week|month|year)[s]?'
+             r'(([ ]+and[ ]+(\d+[ ]+)?(millisecond|second|minute|hour|'
+             r'day|week|month|year)[s]?)'
              r'|[ ]+(ago|from[ ]+now))*:', String.Moment),
             (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|'
              r'(==?|!=?|[-<>+*%&|^/])=?', Operator, 'slashstartsregex'),
             (r'[{(\[;,]', Punctuation, 'slashstartsregex'),
             (r'[})\].]', Punctuation),
             (r'(import|return|continue|if|else)\b', Keyword, 'slashstartsregex'),
-            (r'(var|const|function|reducer|sub|input)\b', Keyword.Declaration, 'slashstartsregex'),
+            (r'(var|const|function|reducer|sub|input)\b', Keyword.Declaration,
+             'slashstartsregex'),
             (r'(batch|emit|filter|head|join|keep|pace|pass|put|read|reduce|remove|'
-             r'sequence|skip|sort|split|tail|unbatch|uniq|view|write)\b', Keyword.Reserved),
+             r'sequence|skip|sort|split|tail|unbatch|uniq|view|write)\b',
+             Keyword.Reserved),
             (r'(true|false|null|Infinity)\b', Keyword.Constant),
-            (r'(Array|Date|Juttle|Math|Number|Object|RegExp|String)\b', Name.Builtin),
+            (r'(Array|Date|Juttle|Math|Number|Object|RegExp|String)\b',
+             Name.Builtin),
             (JS_IDENT, Name.Other),
             (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
             (r'[0-9]+', Number.Integer),

eric ide

mercurial