diff --git a/documentation/coffee/aliases.coffee b/documentation/coffee/aliases.coffee index f1a29e0f..720c2081 100644 --- a/documentation/coffee/aliases.coffee +++ b/documentation/coffee/aliases.coffee @@ -4,4 +4,4 @@ volume: 10 if band isnt spinal_tap let_the_wild_rumpus_begin() unless answer is no -if car.speed < speed_limit then accelerate(). +if car.speed < speed_limit then accelerate() diff --git a/documentation/coffee/array_comprehensions.coffee b/documentation/coffee/array_comprehensions.coffee index ddda9319..a04ab395 100644 --- a/documentation/coffee/array_comprehensions.coffee +++ b/documentation/coffee/array_comprehensions.coffee @@ -1,5 +1,5 @@ # Eat lunch. -lunch: food.eat() for food in ['toast', 'cheese', 'wine']. +lunch: food.eat() for food in ['toast', 'cheese', 'wine'] # Zebra-stripe a table. -highlight(row) for row, i in table if i % 2 is 0. \ No newline at end of file +highlight(row) for row, i in table when i % 2 is 0 \ No newline at end of file diff --git a/documentation/coffee/conditionals.coffee b/documentation/coffee/conditionals.coffee index 253d912c..50c18c43 100644 --- a/documentation/coffee/conditionals.coffee +++ b/documentation/coffee/conditionals.coffee @@ -2,8 +2,8 @@ mood: greatly_improved if singing if happy and knows_it claps_hands() - cha_cha_cha(). + cha_cha_cha() -date: if friday then sue else jill. +date: if friday then sue else jill expensive ||= do_the_math() \ No newline at end of file diff --git a/documentation/coffee/expressions.coffee b/documentation/coffee/expressions.coffee index 0e8da6d5..fa0c1e3a 100644 --- a/documentation/coffee/expressions.coffee +++ b/documentation/coffee/expressions.coffee @@ -2,8 +2,8 @@ grade: student => if student.excellent_work "A+" else if student.okay_stuff - if student.tried_hard then "B" else "B-". + if student.tried_hard then "B" else "B-" else - "C".. + "C" -eldest: if 24 > 21 then "Liz" else "Ike". \ No newline at end of file +eldest: if 24 > 21 then "Liz" else "Ike" \ No newline at end of file diff --git a/documentation/coffee/functions.coffee b/documentation/coffee/functions.coffee index 35f4415a..eb2b9b9b 100644 --- a/documentation/coffee/functions.coffee +++ b/documentation/coffee/functions.coffee @@ -1,2 +1,2 @@ -square: x => x * x. -cube: x => square(x) * x. \ No newline at end of file +square: x => x * x +cube: x => square(x) * x \ No newline at end of file diff --git a/documentation/coffee/overview.coffee b/documentation/coffee/overview.coffee index 8e44f8aa..44e4ec95 100644 --- a/documentation/coffee/overview.coffee +++ b/documentation/coffee/overview.coffee @@ -6,7 +6,7 @@ opposite_day: true number: -42 if opposite_day # Functions: -square: x => x * x. +square: x => x * x # Arrays: list: [1, 2, 3, 4, 5] @@ -15,8 +15,8 @@ list: [1, 2, 3, 4, 5] math: { root: Math.sqrt square: square - cube: x => x * square(x). + cube: x => x * square(x) } # Array comprehensions: -cubed_list: math.cube(num) for num in list. +cubed_list: math.cube(num) for num in list diff --git a/documentation/coffee/scope.coffee b/documentation/coffee/scope.coffee index f15b3eff..691072ab 100644 --- a/documentation/coffee/scope.coffee +++ b/documentation/coffee/scope.coffee @@ -1,5 +1,5 @@ num: 1 change_numbers: => num: 2 - new_num: 3. + new_num: 3 new_num: change_numbers() \ No newline at end of file diff --git a/documentation/coffee/super.coffee b/documentation/coffee/super.coffee index 3e80e804..cc28c84d 100644 --- a/documentation/coffee/super.coffee +++ b/documentation/coffee/super.coffee @@ -1,18 +1,18 @@ -Animal: => . +Animal: => Animal.prototype.move: meters => - alert(this.name + " moved " + meters + "m."). + alert(this.name + " moved " + meters + "m.") -Snake: name => this.name: name. +Snake: name => this.name: name Snake extends Animal Snake.prototype.move: => alert("Slithering...") - super(5). + super(5) -Horse: name => this.name: name. +Horse: name => this.name: name Horse extends Animal Horse.prototype.move: => alert("Galloping...") - super(45). + super(45) sam: new Snake("Sammy the Python") tom: new Horse("Tommy the Palomino") diff --git a/documentation/coffee/switch.coffee b/documentation/coffee/switch.coffee index 955adef6..ee6963a3 100644 --- a/documentation/coffee/switch.coffee +++ b/documentation/coffee/switch.coffee @@ -4,6 +4,6 @@ when "Wednesday" then go_to_the_park() when "Saturday" if day is bingo_day go_to_bingo() - go_dancing(). + go_dancing() when "Sunday" then go_to_church() -else go_to_work(). \ No newline at end of file +else go_to_work() \ No newline at end of file diff --git a/documentation/coffee/try.coffee b/documentation/coffee/try.coffee index 8a2c6275..169df020 100644 --- a/documentation/coffee/try.coffee +++ b/documentation/coffee/try.coffee @@ -4,4 +4,4 @@ try catch error print(error) finally - clean_up(). \ No newline at end of file + clean_up() \ No newline at end of file diff --git a/documentation/coffee/while.coffee b/documentation/coffee/while.coffee index ab0a850a..3ca4a984 100644 --- a/documentation/coffee/while.coffee +++ b/documentation/coffee/while.coffee @@ -1,5 +1,5 @@ while demand > supply sell() - restock(). + restock() -while supply > demand then buy(). \ No newline at end of file +while supply > demand then buy() \ No newline at end of file diff --git a/lib/coffee_script/grammar.y b/lib/coffee_script/grammar.y index 552331cd..1bbdde76 100644 --- a/lib/coffee_script/grammar.y +++ b/lib/coffee_script/grammar.y @@ -32,8 +32,8 @@ prechigh left '.' right INDENT left OUTDENT - right THROW FOR IN WHILE WHEN NEW SUPER IF THEN ELSE - left UNLESS EXTENDS + right THROW FOR IN WHILE WHEN NEW SUPER THEN ELSE + left UNLESS EXTENDS IF left ASSIGN '||=' '&&=' right RETURN '=>' preclow @@ -284,14 +284,14 @@ rule # Try/catch/finally exception handling blocks. Try: TRY Block Catch { result = TryNode.new(val[1], val[2][0], val[2][1]) } + | TRY Block FINALLY Block { result = TryNode.new(val[1], nil, nil, val[3]) } | TRY Block Catch FINALLY Block { result = TryNode.new(val[1], val[2][0], val[2][1], val[4]) } ; # A catch clause. Catch: - /* nothing */ { result = [nil, nil] } - | CATCH IDENTIFIER Block { result = [val[1], val[2]] } + CATCH IDENTIFIER Block { result = [val[1], val[2]] } ; # Throw an exception. diff --git a/test/unit/test_parser.rb b/test/unit/test_parser.rb index e8318501..88305e73 100644 --- a/test/unit/test_parser.rb +++ b/test/unit/test_parser.rb @@ -45,7 +45,7 @@ class ParserTest < Test::Unit::TestCase end def test_parsing_array_comprehension - nodes = @par.parse("i for x, i in [10, 9, 8, 7, 6, 5] if i % 2 is 0").expressions + nodes = @par.parse("i for x, i in [10, 9, 8, 7, 6, 5] when i % 2 is 0").expressions assert nodes.first.is_a? ForNode assert nodes.first.body.literal == 'i' assert nodes.first.filter.operator == '===' @@ -78,6 +78,7 @@ class ParserTest < Test::Unit::TestCase end def test_no_wrapping_parens_around_statements + @par.parse("try thing() catch error fail()").compile assert_raises(SyntaxError) do @par.parse("(try thing() catch error fail())").compile end