mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
little more progress on whitespace
This commit is contained in:
parent
5bed5646be
commit
556f8cb68a
4 changed files with 24 additions and 17 deletions
|
@ -39,7 +39,7 @@
|
|||
<key>comment</key>
|
||||
<string>match stuff like: funcName: => … </string>
|
||||
<key>match</key>
|
||||
<string>([a-zA-Z_?.$]*)\s*(=|:)\s*([\w,\s]*?)\s*(=>)</string>
|
||||
<string>([a-zA-Z0-9_?.$]*)\s*(=|:)\s*([\w,\s]*?)\s*(=>)</string>
|
||||
<key>name</key>
|
||||
<string>meta.function.coffee</string>
|
||||
</dict>
|
||||
|
@ -60,7 +60,7 @@
|
|||
<key>comment</key>
|
||||
<string>match stuff like: a => … </string>
|
||||
<key>match</key>
|
||||
<string>([a-zA-Z_?., $]*)\s*(=>)</string>
|
||||
<string>([a-zA-Z0-9_?., $]*)\s*(=>)</string>
|
||||
<key>name</key>
|
||||
<string>meta.inline.function.coffee</string>
|
||||
</dict>
|
||||
|
|
|
@ -33,7 +33,7 @@ prechigh
|
|||
right THROW FOR IN WHILE NEW SUPER
|
||||
left UNLESS IF ELSE EXTENDS
|
||||
left ASSIGN '||=' '&&='
|
||||
right RETURN
|
||||
right RETURN INDENT
|
||||
left OUTDENT
|
||||
preclow
|
||||
|
||||
|
@ -88,8 +88,8 @@ rule
|
|||
;
|
||||
|
||||
Block:
|
||||
Expression { result = Expressions.new(val) }
|
||||
| INDENT Expressions Outdent { result = val[1] }
|
||||
# Expression { result = Expressions.new(val) }
|
||||
INDENT Expressions Outdent { result = val[1] }
|
||||
;
|
||||
|
||||
Outdent:
|
||||
|
|
|
@ -131,17 +131,16 @@ module CoffeeScript
|
|||
size = indent.size
|
||||
return literal_token if size == @indent
|
||||
if size > @indent
|
||||
tag = :INDENT
|
||||
token(:INDENT, size - @indent)
|
||||
@indent = size
|
||||
@indents << @indent
|
||||
else
|
||||
tag = :OUTDENT
|
||||
token(:OUTDENT, @indent - size)
|
||||
@indents.pop while @indents.last && ((@indents.last || 0) > size)
|
||||
@indent = @indents.last || 0
|
||||
end
|
||||
@line += 1
|
||||
@i += (size + 1)
|
||||
token(tag, size)
|
||||
end
|
||||
|
||||
# Matches and consumes non-meaningful whitespace.
|
||||
|
@ -150,18 +149,20 @@ module CoffeeScript
|
|||
@i += whitespace.length
|
||||
end
|
||||
|
||||
# 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.
|
||||
# Multiple newlines get merged together.
|
||||
# Use a trailing \ to escape newlines.
|
||||
def literal_token
|
||||
value = @chunk[NEWLINE, 1]
|
||||
if value
|
||||
@line += value.length
|
||||
def newline_token(newlines)
|
||||
return false unless newlines = @chunk[NEWLINE, 1]
|
||||
@line += newlines.length
|
||||
token("\n", "\n") unless ["\n", "\\"].include?(last_value)
|
||||
@tokens.pop if last_value == "\\"
|
||||
return @i += value.length
|
||||
@i += newlines.length
|
||||
end
|
||||
|
||||
# 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.
|
||||
def literal_token
|
||||
value = @chunk[OPERATOR, 1]
|
||||
tag_parameters if value && value.match(CODE)
|
||||
value ||= @chunk[0,1]
|
||||
|
|
6
test/fixtures/generation/whitespace.coffee
vendored
Normal file
6
test/fixtures/generation/whitespace.coffee
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
# test
|
||||
f1: x =>
|
||||
x * x
|
||||
f2: y =>
|
||||
y * x
|
||||
|
Loading…
Reference in a new issue