From 033751317263ea980f4ccea165263305fb649cd9 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Fri, 25 Dec 2009 13:40:57 -0800 Subject: [PATCH] ForBody is really the ForSource --- lib/coffee_script/grammar.y | 6 ++++-- lib/coffee_script/parser.rb | 42 ++++++++++++++++++------------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/lib/coffee_script/grammar.y b/lib/coffee_script/grammar.y index 5dd42d3b..99034a2a 100644 --- a/lib/coffee_script/grammar.y +++ b/lib/coffee_script/grammar.y @@ -318,15 +318,17 @@ rule # Array comprehensions, including guard and current index. For: Expression FOR - ForVariables ForBody { result = ForNode.new(val[0], val[3][0], val[2][0], val[3][1], val[2][1]) } + ForVariables ForSource { result = ForNode.new(val[0], val[3][0], val[2][0], val[3][1], val[2][1]) } ; + # An array comprehension has variables for the current element and index. ForVariables: IDENTIFIER { result = val } | IDENTIFIER "," IDENTIFIER { result = [val[0], val[2]] } ; - ForBody: + # The source of the array comprehension can optionally be filtered. + ForSource: IN PureExpression "." { result = [val[1]] } | IN PureExpression IF Expression "." { result = [val[1], val[3]] } diff --git a/lib/coffee_script/parser.rb b/lib/coffee_script/parser.rb index 46d7bb78..9b8d608d 100644 --- a/lib/coffee_script/parser.rb +++ b/lib/coffee_script/parser.rb @@ -10,7 +10,7 @@ module CoffeeScript class Parser < Racc::Parser -module_eval(<<'...end grammar.y/module_eval...', 'grammar.y', 395) +module_eval(<<'...end grammar.y/module_eval...', 'grammar.y', 397) # Lex and parse a CoffeeScript. def parse(code) # Uncomment the following line to enable grammar debugging, in combination @@ -1164,7 +1164,7 @@ Racc_token_to_s_table = [ "ArgList", "Catch", "ForVariables", - "ForBody", + "ForSource", "Whens", "When", "ElsIf", @@ -1983,133 +1983,133 @@ module_eval(<<'.,.,', 'grammar.y', 320) end .,., -module_eval(<<'.,.,', 'grammar.y', 324) +module_eval(<<'.,.,', 'grammar.y', 325) def _reduce_131(val, _values, result) result = val result end .,., -module_eval(<<'.,.,', 'grammar.y', 325) +module_eval(<<'.,.,', 'grammar.y', 326) def _reduce_132(val, _values, result) result = [val[0], val[2]] result end .,., -module_eval(<<'.,.,', 'grammar.y', 329) +module_eval(<<'.,.,', 'grammar.y', 331) def _reduce_133(val, _values, result) result = [val[1]] result end .,., -module_eval(<<'.,.,', 'grammar.y', 331) +module_eval(<<'.,.,', 'grammar.y', 333) def _reduce_134(val, _values, result) result = [val[1], val[3]] result end .,., -module_eval(<<'.,.,', 'grammar.y', 337) +module_eval(<<'.,.,', 'grammar.y', 339) def _reduce_135(val, _values, result) result = val[3].rewrite_condition(val[1]) result end .,., -module_eval(<<'.,.,', 'grammar.y', 339) +module_eval(<<'.,.,', 'grammar.y', 341) def _reduce_136(val, _values, result) result = val[3].rewrite_condition(val[1]).add_else(val[5]) result end .,., -module_eval(<<'.,.,', 'grammar.y', 344) +module_eval(<<'.,.,', 'grammar.y', 346) def _reduce_137(val, _values, result) result = val[0] result end .,., -module_eval(<<'.,.,', 'grammar.y', 345) +module_eval(<<'.,.,', 'grammar.y', 347) def _reduce_138(val, _values, result) result = val[0] << val[1] result end .,., -module_eval(<<'.,.,', 'grammar.y', 350) +module_eval(<<'.,.,', 'grammar.y', 352) def _reduce_139(val, _values, result) result = IfNode.new(val[1], val[3]) result end .,., -module_eval(<<'.,.,', 'grammar.y', 359) +module_eval(<<'.,.,', 'grammar.y', 361) def _reduce_140(val, _values, result) result = IfNode.new(val[2], val[4]) result end .,., -module_eval(<<'.,.,', 'grammar.y', 364) +module_eval(<<'.,.,', 'grammar.y', 366) def _reduce_141(val, _values, result) result = val[0] result end .,., -module_eval(<<'.,.,', 'grammar.y', 365) +module_eval(<<'.,.,', 'grammar.y', 367) def _reduce_142(val, _values, result) result = val[0].add_else(val[1]) result end .,., -module_eval(<<'.,.,', 'grammar.y', 370) +module_eval(<<'.,.,', 'grammar.y', 372) def _reduce_143(val, _values, result) result = nil result end .,., -module_eval(<<'.,.,', 'grammar.y', 371) +module_eval(<<'.,.,', 'grammar.y', 373) def _reduce_144(val, _values, result) result = val[1] result end .,., -module_eval(<<'.,.,', 'grammar.y', 376) +module_eval(<<'.,.,', 'grammar.y', 378) def _reduce_145(val, _values, result) result = val[0] result end .,., -module_eval(<<'.,.,', 'grammar.y', 377) +module_eval(<<'.,.,', 'grammar.y', 379) def _reduce_146(val, _values, result) result = val[0].add_else(val[1]) result end .,., -module_eval(<<'.,.,', 'grammar.y', 383) +module_eval(<<'.,.,', 'grammar.y', 385) def _reduce_147(val, _values, result) result = IfNode.new(val[1], val[3], val[4]) result end .,., -module_eval(<<'.,.,', 'grammar.y', 384) +module_eval(<<'.,.,', 'grammar.y', 386) def _reduce_148(val, _values, result) result = IfNode.new(val[2], Expressions.new([val[0]]), nil, {:statement => true}) result end .,., -module_eval(<<'.,.,', 'grammar.y', 385) +module_eval(<<'.,.,', 'grammar.y', 387) def _reduce_149(val, _values, result) result = IfNode.new(val[2], Expressions.new([val[0]]), nil, {:statement => true, :invert => true}) result