parser and test tweaks for whitespace -- tests are coming along

This commit is contained in:
Jeremy Ashkenas 2009-12-30 17:58:27 -05:00
parent 62c51006a1
commit 9a7c075e06
4 changed files with 15 additions and 13 deletions

View File

@ -1,9 +1,9 @@
switch day
when "Tuesday" then eat_breakfast()
when "Wednesday" then go_to_the_park()
when "Saturday"
if day is bingo_day
go_to_bingo()
go_dancing()
when "Sunday" then go_to_church()
else go_to_work()
when "Tuesday" then eat_breakfast()
when "Wednesday" then go_to_the_park()
when "Saturday"
if day is bingo_day
go_to_bingo()
go_dancing()
when "Sunday" then go_to_church()
else go_to_work()

View File

@ -42,13 +42,13 @@ module CoffeeScript
BALANCED_PAIRS = [['(', ')'], ['[', ']'], ['{', '}'], [:INDENT, :OUTDENT]]
# Outdents that come before these tokens don't signify the end of the
# expression. TODO: Is this safe?
EXPRESSION_TAIL = [:CATCH, :WHEN, :ELSE, ')', ']', '}']
# expression.
EXPRESSION_TAIL = [:CATCH, :WHEN, :ELSE, :FINALLY, ')', ']', '}']
# Single-line flavors of block expressions that have unclosed endings.
# The grammar can't disambiguate them, so we insert the implicit indentation.
SINGLE_LINERS = [:ELSE, "=>", :TRY, :FINALLY, :THEN]
SINGLE_CLOSERS = ["\n", :CATCH, :FINALLY, :ELSE]
SINGLE_CLOSERS = ["\n", :CATCH, :FINALLY, :ELSE, :OUTDENT]
# The inverse mappings of token pairs we're trying to fix up.
INVERSES = {:INDENT => :OUTDENT, :OUTDENT => :INDENT, '(' => ')', ')' => '('}

View File

@ -8,6 +8,8 @@ func: =>
c: {
"text": b
other: null
something_else: x => x + 5
}
c: 'error' unless 42 > 41

View File

@ -78,9 +78,9 @@ class ParserTest < Test::Unit::TestCase
end
def test_no_wrapping_parens_around_statements
@par.parse("try thing() catch error fail()").compile
@par.parse("try thing() catch error then fail()").compile
assert_raises(SyntaxError) do
@par.parse("(try thing() catch error fail())").compile
@par.parse("(try thing() catch error then fail())").compile
end
end