summaryrefslogtreecommitdiff
path: root/pygments/lexers/javascript.py
diff options
context:
space:
mode:
authorTim Hatch <tim@timhatch.com>2016-05-31 23:52:12 -0700
committerTim Hatch <tim@timhatch.com>2016-05-31 23:52:12 -0700
commit096e15f76cc4cd796b097f73727799801293005b (patch)
tree617977f98af9473063317dc9371ddff03869ef97 /pygments/lexers/javascript.py
parent85ad3e52807b9e3e1b5daf870c7b189f592d35d7 (diff)
downloadpygments-git-096e15f76cc4cd796b097f73727799801293005b.tar.gz
Rework CoffeeScript use of slashstartsregex.
Fixes #991
Diffstat (limited to 'pygments/lexers/javascript.py')
-rw-r--r--pygments/lexers/javascript.py22
1 files changed, 14 insertions, 8 deletions
diff --git a/pygments/lexers/javascript.py b/pygments/lexers/javascript.py
index d8ce87d4..a23ba184 100644
--- a/pygments/lexers/javascript.py
+++ b/pygments/lexers/javascript.py
@@ -1016,6 +1016,12 @@ class CoffeeScriptLexer(RegexLexer):
filenames = ['*.coffee']
mimetypes = ['text/coffeescript']
+
+ _operator_re = (
+ r'\+\+|~|&&|\band\b|\bor\b|\bis\b|\bisnt\b|\bnot\b|\?|:|'
+ r'\|\||\\(?=\n)|'
+ r'(<<|>>>?|==?(?!>)|!=?|=(?!>)|-(?!>)|[<>+*`%&\|\^/])=?')
+
flags = re.DOTALL
tokens = {
'commentsandwhitespace': [
@@ -1034,17 +1040,17 @@ class CoffeeScriptLexer(RegexLexer):
(r'///', String.Regex, ('#pop', 'multilineregex')),
(r'/(?! )(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
r'([gim]+\b|\B)', String.Regex, '#pop'),
+ # This isn't really guarding against mishighlighting well-formed
+ # code, just the ability to infinite-loop between root and
+ # slashstartsregex.
+ (r'/', Operator),
default('#pop'),
],
'root': [
- # this next expr leads to infinite loops root -> slashstartsregex
- # (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'),
include('commentsandwhitespace'),
- (r'\+\+|~|&&|\band\b|\bor\b|\bis\b|\bisnt\b|\bnot\b|\?|:|'
- r'\|\||\\(?=\n)|'
- r'(<<|>>>?|==?(?!>)|!=?|=(?!>)|-(?!>)|[<>+*`%&|^/])=?',
- Operator, 'slashstartsregex'),
- (r'(?:\([^()]*\))?\s*[=-]>', Name.Function),
+ (r'^(?=\s|/)', Text, 'slashstartsregex'),
+ (_operator_re, Operator, 'slashstartsregex'),
+ (r'(?:\([^()]*\))?\s*[=-]>', Name.Function, 'slashstartsregex'),
(r'[{(\[;,]', Punctuation, 'slashstartsregex'),
(r'[})\].]', Punctuation),
(r'(?<![.$])(for|own|in|of|while|until|'
@@ -1065,7 +1071,7 @@ class CoffeeScriptLexer(RegexLexer):
(r'@[$a-zA-Z_][\w.:$]*\s*[:=]\s', Name.Variable.Instance,
'slashstartsregex'),
(r'@', Name.Other, 'slashstartsregex'),
- (r'@?[$a-zA-Z_][\w$]*', Name.Other, 'slashstartsregex'),
+ (r'@?[$a-zA-Z_][\w$]*', Name.Other),
(r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
(r'0x[0-9a-fA-F]+', Number.Hex),
(r'[0-9]+', Number.Integer),