diff --git a/lib/coffee_script/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage b/lib/coffee_script/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage index 990a2368..df92adbf 100644 --- a/lib/coffee_script/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage +++ b/lib/coffee_script/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage @@ -39,7 +39,7 @@ comment match stuff like: funcName: => … match - ([a-zA-Z_?.$]*)\s*(=|:)\s*([\w,\s]*?)\s*(=>) + ([a-zA-Z0-9_?.$]*)\s*(=|:)\s*([\w,\s]*?)\s*(=>) name meta.function.coffee @@ -60,7 +60,7 @@ comment match stuff like: a => … match - ([a-zA-Z_?., $]*)\s*(=>) + ([a-zA-Z0-9_?., $]*)\s*(=>) name meta.inline.function.coffee diff --git a/lib/coffee_script/grammar.y b/lib/coffee_script/grammar.y index 6fd9df12..b8089cdb 100644 --- a/lib/coffee_script/grammar.y +++ b/lib/coffee_script/grammar.y @@ -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: diff --git a/lib/coffee_script/lexer.rb b/lib/coffee_script/lexer.rb index b0fb531d..abd45592 100644 --- a/lib/coffee_script/lexer.rb +++ b/lib/coffee_script/lexer.rb @@ -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 + # Multiple newlines get merged together. + # Use a trailing \ to escape newlines. + 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 == "\\" + @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. Multiple newlines get merged together. - # Use a trailing \ to escape newlines. + # the proper order of operations. def literal_token - value = @chunk[NEWLINE, 1] - if value - @line += value.length - token("\n", "\n") unless ["\n", "\\"].include?(last_value) - @tokens.pop if last_value == "\\" - return @i += value.length - end value = @chunk[OPERATOR, 1] tag_parameters if value && value.match(CODE) value ||= @chunk[0,1] diff --git a/test/fixtures/generation/whitespace.coffee b/test/fixtures/generation/whitespace.coffee new file mode 100644 index 00000000..7a5bfaf7 --- /dev/null +++ b/test/fixtures/generation/whitespace.coffee @@ -0,0 +1,6 @@ +# test +f1: x => + x * x + f2: y => + y * x +