mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
parser and test tweaks for whitespace -- tests are coming along
This commit is contained in:
parent
62c51006a1
commit
9a7c075e06
4 changed files with 15 additions and 13 deletions
|
@ -1,9 +1,9 @@
|
||||||
switch day
|
switch day
|
||||||
when "Tuesday" then eat_breakfast()
|
when "Tuesday" then eat_breakfast()
|
||||||
when "Wednesday" then go_to_the_park()
|
when "Wednesday" then go_to_the_park()
|
||||||
when "Saturday"
|
when "Saturday"
|
||||||
if day is bingo_day
|
if day is bingo_day
|
||||||
go_to_bingo()
|
go_to_bingo()
|
||||||
go_dancing()
|
go_dancing()
|
||||||
when "Sunday" then go_to_church()
|
when "Sunday" then go_to_church()
|
||||||
else go_to_work()
|
else go_to_work()
|
|
@ -42,13 +42,13 @@ module CoffeeScript
|
||||||
BALANCED_PAIRS = [['(', ')'], ['[', ']'], ['{', '}'], [:INDENT, :OUTDENT]]
|
BALANCED_PAIRS = [['(', ')'], ['[', ']'], ['{', '}'], [:INDENT, :OUTDENT]]
|
||||||
|
|
||||||
# Outdents that come before these tokens don't signify the end of the
|
# Outdents that come before these tokens don't signify the end of the
|
||||||
# expression. TODO: Is this safe?
|
# expression.
|
||||||
EXPRESSION_TAIL = [:CATCH, :WHEN, :ELSE, ')', ']', '}']
|
EXPRESSION_TAIL = [:CATCH, :WHEN, :ELSE, :FINALLY, ')', ']', '}']
|
||||||
|
|
||||||
# Single-line flavors of block expressions that have unclosed endings.
|
# Single-line flavors of block expressions that have unclosed endings.
|
||||||
# The grammar can't disambiguate them, so we insert the implicit indentation.
|
# The grammar can't disambiguate them, so we insert the implicit indentation.
|
||||||
SINGLE_LINERS = [:ELSE, "=>", :TRY, :FINALLY, :THEN]
|
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.
|
# The inverse mappings of token pairs we're trying to fix up.
|
||||||
INVERSES = {:INDENT => :OUTDENT, :OUTDENT => :INDENT, '(' => ')', ')' => '('}
|
INVERSES = {:INDENT => :OUTDENT, :OUTDENT => :INDENT, '(' => ')', ')' => '('}
|
||||||
|
|
|
@ -8,6 +8,8 @@ func: =>
|
||||||
|
|
||||||
c: {
|
c: {
|
||||||
"text": b
|
"text": b
|
||||||
|
other: null
|
||||||
|
something_else: x => x + 5
|
||||||
}
|
}
|
||||||
|
|
||||||
c: 'error' unless 42 > 41
|
c: 'error' unless 42 > 41
|
||||||
|
|
|
@ -78,9 +78,9 @@ class ParserTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_no_wrapping_parens_around_statements
|
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
|
assert_raises(SyntaxError) do
|
||||||
@par.parse("(try thing() catch error fail())").compile
|
@par.parse("(try thing() catch error then fail())").compile
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue