diff --git a/lib/coffee_script/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage b/lib/coffee_script/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage index 927e017d..990a2368 100644 --- a/lib/coffee_script/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage +++ b/lib/coffee_script/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage @@ -234,7 +234,7 @@ match - \b(debugger)\b + \b(debugger|\\)\b name keyword.other.coffee diff --git a/lib/coffee_script/lexer.rb b/lib/coffee_script/lexer.rb index fcf21618..ed959f84 100644 --- a/lib/coffee_script/lexer.rb +++ b/lib/coffee_script/lexer.rb @@ -130,11 +130,13 @@ module CoffeeScript # We treat all other single characters as a token. Eg.: ( ) , . ! # Multi-character operators are also literal tokens, so that Racc can assign # the proper order of operations. Multiple newlines get merged together. + # Use a trailing \ to escape newlines. def literal_token value = @chunk[NEWLINE, 1] if value @line += value.length - token("\n", "\n") unless last_value == "\n" + token("\n", "\n") unless ["\n", "\\"].include?(last_value) + @tokens.pop if last_value == "\\" return @i += value.length end value = @chunk[OPERATOR, 1] diff --git a/test/fixtures/execution/test_newline_escaping.coffee b/test/fixtures/execution/test_newline_escaping.coffee new file mode 100644 index 00000000..2f52e932 --- /dev/null +++ b/test/fixtures/execution/test_newline_escaping.coffee @@ -0,0 +1,6 @@ +six: \ + 1 + \ + 2 + \ + 3 + +print(six is 6) \ No newline at end of file diff --git a/test/unit/test_lexer.rb b/test/unit/test_lexer.rb index 5f8d52d2..0d2ec1b5 100644 --- a/test/unit/test_lexer.rb +++ b/test/unit/test_lexer.rb @@ -38,8 +38,14 @@ class LexerTest < Test::Unit::TestCase def test_lexing_comment code = "a: 1\n # comment\n # on two lines\nb: 2" assert @lex.tokenize(code) == [[:IDENTIFIER, "a"], [:ASSIGN, ":"], [:NUMBER, "1"], - ["\n", "\n"], [:COMMENT, [" comment", " on two lines"]], ["\n", "\n"], - [:IDENTIFIER, "b"], [:ASSIGN, ":"], [:NUMBER, "2"]] + ["\n", "\n"], [:COMMENT, [" comment", " on two lines"]], ["\n", "\n"], + [:IDENTIFIER, "b"], [:ASSIGN, ":"], [:NUMBER, "2"]] + end + + def test_lexing_newline_escaper + code = "two: 1 + \\\n\n 1" + assert @lex.tokenize(code) == [[:IDENTIFIER, "two"], [:ASSIGN, ":"], + [:NUMBER, "1"], ["+", "+"], [:NUMBER, "1"]] end def test_lexing