mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
adding newline escaping, with tests
This commit is contained in:
@@ -234,7 +234,7 @@
|
|||||||
</dict>
|
</dict>
|
||||||
<dict>
|
<dict>
|
||||||
<key>match</key>
|
<key>match</key>
|
||||||
<string>\b(debugger)\b</string>
|
<string>\b(debugger|\\)\b</string>
|
||||||
<key>name</key>
|
<key>name</key>
|
||||||
<string>keyword.other.coffee</string>
|
<string>keyword.other.coffee</string>
|
||||||
</dict>
|
</dict>
|
||||||
|
|||||||
@@ -130,11 +130,13 @@ module CoffeeScript
|
|||||||
# We treat all other single characters as a token. Eg.: ( ) , . !
|
# We treat all other single characters as a token. Eg.: ( ) , . !
|
||||||
# Multi-character operators are also literal tokens, so that Racc can assign
|
# Multi-character operators are also literal tokens, so that Racc can assign
|
||||||
# the proper order of operations. Multiple newlines get merged together.
|
# the proper order of operations. Multiple newlines get merged together.
|
||||||
|
# Use a trailing \ to escape newlines.
|
||||||
def literal_token
|
def literal_token
|
||||||
value = @chunk[NEWLINE, 1]
|
value = @chunk[NEWLINE, 1]
|
||||||
if value
|
if value
|
||||||
@line += value.length
|
@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
|
return @i += value.length
|
||||||
end
|
end
|
||||||
value = @chunk[OPERATOR, 1]
|
value = @chunk[OPERATOR, 1]
|
||||||
|
|||||||
6
test/fixtures/execution/test_newline_escaping.coffee
vendored
Normal file
6
test/fixtures/execution/test_newline_escaping.coffee
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
six: \
|
||||||
|
1 + \
|
||||||
|
2 + \
|
||||||
|
3
|
||||||
|
|
||||||
|
print(six is 6)
|
||||||
@@ -38,8 +38,14 @@ class LexerTest < Test::Unit::TestCase
|
|||||||
def test_lexing_comment
|
def test_lexing_comment
|
||||||
code = "a: 1\n # comment\n # on two lines\nb: 2"
|
code = "a: 1\n # comment\n # on two lines\nb: 2"
|
||||||
assert @lex.tokenize(code) == [[:IDENTIFIER, "a"], [:ASSIGN, ":"], [:NUMBER, "1"],
|
assert @lex.tokenize(code) == [[:IDENTIFIER, "a"], [:ASSIGN, ":"], [:NUMBER, "1"],
|
||||||
["\n", "\n"], [:COMMENT, [" comment", " on two lines"]], ["\n", "\n"],
|
["\n", "\n"], [:COMMENT, [" comment", " on two lines"]], ["\n", "\n"],
|
||||||
[:IDENTIFIER, "b"], [:ASSIGN, ":"], [:NUMBER, "2"]]
|
[: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
|
end
|
||||||
|
|
||||||
def test_lexing
|
def test_lexing
|
||||||
|
|||||||
Reference in New Issue
Block a user