mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
adding proper auto-newline escaping
This commit is contained in:
@@ -403,9 +403,9 @@ _.isEqual: a, b =>
|
||||
return true if _.isNaN(a) and _.isNaN(b)
|
||||
# Compare regular expressions.
|
||||
if _.isRegExp(a) and _.isRegExp(b)
|
||||
return a.source is b.source and \
|
||||
a.global is b.global and \
|
||||
a.ignoreCase is b.ignoreCase and \
|
||||
return a.source is b.source and
|
||||
a.global is b.global and
|
||||
a.ignoreCase is b.ignoreCase and
|
||||
a.multiline is b.multiline
|
||||
# If a is not an object by this point, we can't handle it.
|
||||
return false if atype isnt 'object'
|
||||
|
||||
@@ -34,6 +34,7 @@ module CoffeeScript
|
||||
JS_CLEANER = /(\A`|`\Z)/
|
||||
MULTILINER = /\n/
|
||||
COMMENT_CLEANER = /(^\s*#|\n\s*$)/
|
||||
NO_NEWLINE = /\A([+\*&|\/\-%=<>:!.\\][<>=&|]*|and|or|is|isnt|not|delete|typeof|instanceof)\Z/
|
||||
|
||||
# Assignment tokens.
|
||||
ASSIGN = [':', '=']
|
||||
@@ -157,10 +158,7 @@ module CoffeeScript
|
||||
return false unless indent = @chunk[MULTI_DENT, 1]
|
||||
@line += indent.scan(MULTILINER).size
|
||||
@i += indent.size
|
||||
if last_value == "\\"
|
||||
@tokens.pop
|
||||
return true
|
||||
end
|
||||
return suppress_newlines(indent) if last_value.to_s.match(NO_NEWLINE) && last_value != "=>"
|
||||
size = indent.scan(LAST_DENT).last.last.length
|
||||
return newline_token(indent) if size == @indent
|
||||
if size > @indent
|
||||
@@ -193,6 +191,12 @@ module CoffeeScript
|
||||
token("\n", "\n") unless last_value == "\n"
|
||||
true
|
||||
end
|
||||
|
||||
# Tokens to explicitly escape newlines are removed once their job is done.
|
||||
def suppress_newlines(newlines)
|
||||
@tokens.pop if last_value == "\\"
|
||||
true
|
||||
end
|
||||
|
||||
# We treat all other single characters as a token. Eg.: ( ) , . !
|
||||
# Multi-character operators are also literal tokens, so that Racc can assign
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
six: \
|
||||
1 + \
|
||||
2 + \
|
||||
3
|
||||
six:
|
||||
1 +
|
||||
2 +
|
||||
3
|
||||
|
||||
print(six is 6)
|
||||
Reference in New Issue
Block a user