diff --git a/lib/coffee_script/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage b/lib/coffee_script/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage index e2922226..23858937 100644 --- a/lib/coffee_script/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage +++ b/lib/coffee_script/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage @@ -240,7 +240,7 @@ match - !|\$|%|&|\*|\-\-|\-|\+\+|\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\?|\|\||\:|\*=|(?<!\()/=|%=|\+=|\-=|&=|\^=|\b(in|instanceof|new|delete|typeof|and|or|is|isnt|not)\b + !|\$|%|&|\*|\/|\-\-|\-|\+\+|\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\?|\|\||\:|\*=|(?<!\()/=|%=|\+=|\-=|&=|\^=|\b(in|instanceof|new|delete|typeof|and|or|is|isnt|not)\b name keyword.operator.coffee diff --git a/lib/coffee_script/lexer.rb b/lib/coffee_script/lexer.rb index 58789815..70c60558 100644 --- a/lib/coffee_script/lexer.rb +++ b/lib/coffee_script/lexer.rb @@ -37,6 +37,10 @@ module CoffeeScript COMMENT_CLEANER = /(^\s*#|\n\s*$)/ NO_NEWLINE = /\A([+\*&|\/\-%=<>:!.\\][<>=&|]*|and|or|is|isnt|not|delete|typeof|instanceof)\Z/ + # Tokens which a regular expression will never immediately follow. + # See: http://www.mozilla.org/js/language/js20-2002-04/rationale/syntax.html#regular-expressions + NOT_REGEX = [:IDENTIFIER, :NUMBER, :STRING] + # Scan by attempting to match tokens one character at a time. Slow and steady. def tokenize(code) @code = code.chomp # Cleanup code by remove extra line breaks @@ -107,6 +111,7 @@ module CoffeeScript # Matches regular expression literals. def regex_token return false unless regex = @chunk[REGEX, 1] + return false if NOT_REGEX.include?(last_tag) token(:REGEX, regex) @i += regex.length end @@ -183,11 +188,16 @@ module CoffeeScript @tokens << [tag, Value.new(value, @line)] end - # Peek at the previous token. + # Peek at the previous token's value. def last_value @tokens.last && @tokens.last[1] end + # Peek at the previous token's tag. + def last_tag + @tokens.last && @tokens.last[0] + end + # A source of ambiguity in our grammar was parameter lists in function # definitions (as opposed to argument lists in function calls). Tag # parameter identifiers in order to avoid this. Also, parameter lists can diff --git a/test/fixtures/execution/test_literals.coffee b/test/fixtures/execution/test_literals.coffee index 73a5b4d2..24f54e65 100644 --- a/test/fixtures/execution/test_literals.coffee +++ b/test/fixtures/execution/test_literals.coffee @@ -1,3 +1,9 @@ a: [(x => x), (x => x * x)] -print(a.length is 2) \ No newline at end of file +print(a.length is 2) + + +regex: /match/i +words: "I think there is a match in here." + +print(!!words.match(regex)) \ No newline at end of file