diff options
author | Tim Hatch <tim@timhatch.com> | 2015-10-13 13:52:55 -0700 |
---|---|---|
committer | Tim Hatch <tim@timhatch.com> | 2015-10-13 13:52:55 -0700 |
commit | b95523e4d56ee3d409e31f377a9d4ff9f85149bd (patch) | |
tree | d83f104b2dbd31c82fe5087cb53a275671c26924 /pygments/lexers/javascript.py | |
parent | f25271b0df511d4f0cb09fbe69f066897c79a201 (diff) | |
download | pygments-b95523e4d56ee3d409e31f377a9d4ff9f85149bd.tar.gz |
Fixes #1100. Add support for ECMAScript6 syntax, with example file.
Diffstat (limited to 'pygments/lexers/javascript.py')
-rw-r--r-- | pygments/lexers/javascript.py | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/pygments/lexers/javascript.py b/pygments/lexers/javascript.py index 3992d072..d13fcbca 100644 --- a/pygments/lexers/javascript.py +++ b/pygments/lexers/javascript.py @@ -64,12 +64,13 @@ class JavascriptLexer(RegexLexer): (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), include('commentsandwhitespace'), (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|' - r'(<<|>>>?|==?|!=?|[-<>+*%&|^/])=?', Operator, 'slashstartsregex'), + r'(<<|>>>?|=>|==?|!=?|[-<>+*%&|^/])=?', Operator, 'slashstartsregex'), + (r'\.\.\.', Punctuation), (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|yield|' - r'this)\b', Keyword, 'slashstartsregex'), + r'this|of)\b', Keyword, 'slashstartsregex'), (r'(var|let|with|function)\b', Keyword.Declaration, 'slashstartsregex'), (r'(abstract|boolean|byte|char|class|const|debugger|double|enum|export|' r'extends|final|float|goto|implements|import|int|interface|long|native|' @@ -77,18 +78,34 @@ class JavascriptLexer(RegexLexer): r'transient|volatile)\b', Keyword.Reserved), (r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant), (r'(Array|Boolean|Date|Error|Function|Math|netscape|' - r'Number|Object|Packages|RegExp|String|sun|decodeURI|' + r'Number|Object|Packages|RegExp|String|Promise|Proxy|sun|decodeURI|' r'decodeURIComponent|encodeURI|encodeURIComponent|' - r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|' - r'window)\b', Name.Builtin), + r'Error|eval|isFinite|isNaN|isSafeInteger|parseFloat|parseInt|' + r'document|this|window)\b', Name.Builtin), (JS_IDENT, Name.Other), (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), + (r'0b[01]+', Number.Bin), + (r'0o[0-7]+', Number.Oct), (r'0x[0-9a-fA-F]+', Number.Hex), (r'[0-9]+', Number.Integer), (r'"(\\\\|\\"|[^"])*"', String.Double), (r"'(\\\\|\\'|[^'])*'", String.Single), - (r'`(\\\\|\\`|[^`])*`', String.Backtick), - ] + (r'`', String.Backtick, 'interp'), + ], + 'interp': [ + (r'`', String.Backtick, '#pop'), + (r'\\\\', String.Backtick), + (r'\\`', String.Backtick), + (r'\${', String.Interpol, 'interp-inside'), + (r'\$', String.Backtick), + (r'[^`\\$]+', String.Backtick), + ], + 'interp-inside': [ + # TODO: should this include single-line comments and allow nesting strings? + (r'}', String.Interpol, '#pop'), + include('root'), + ], + #(\\\\|\\`|[^`])*`', String.Backtick), } @@ -162,7 +179,8 @@ class KalLexer(RegexLexer): (r'(Array|Boolean|Date|Error|Function|Math|netscape|' r'Number|Object|Packages|RegExp|String|sun|decodeURI|' r'decodeURIComponent|encodeURI|encodeURIComponent|' - r'eval|isFinite|isNaN|parseFloat|parseInt|document|window|' + r'eval|isFinite|isNaN|isSafeInteger|parseFloat|parseInt|document|' + r'window|' r'print)\b', Name.Builtin), (r'[$a-zA-Z_][\w.$]*\s*(:|[+\-*/]?\=)?\b', Name.Variable), |