From ae58e2ec6ce3c27e6cf39233cdba5966cd5f1af1 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Sat, 9 Jan 2010 11:51:32 -0500 Subject: [PATCH] adding body-less while expressions --- examples/poignant.coffee | 6 +++--- lib/coffee_script/grammar.y | 1 + lib/coffee_script/nodes.rb | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/poignant.coffee b/examples/poignant.coffee index 9714c980..9ed24328 100644 --- a/examples/poignant.coffee +++ b/examples/poignant.coffee @@ -14,9 +14,9 @@ # end LotteryTicket: { - get_picks: => this.picks - set_picks: nums => this.picks: nums - get_purchase: => this.purchase + get_picks: => this.picks + set_picks: nums => this.picks: nums + get_purchase: => this.purchase set_purchase: amount => this.purchase: amount } diff --git a/lib/coffee_script/grammar.y b/lib/coffee_script/grammar.y index ea3845ee..7c2ee5bb 100644 --- a/lib/coffee_script/grammar.y +++ b/lib/coffee_script/grammar.y @@ -340,6 +340,7 @@ rule # The while loop. (there is no do..while). While: WHILE Expression Block { result = WhileNode.new(val[1], val[2]) } + | WHILE Expression { result = WhileNode.new(val[1], nil) } ; # Array comprehensions, including guard and current index. diff --git a/lib/coffee_script/nodes.rb b/lib/coffee_script/nodes.rb index ce7275ca..1419ff2f 100644 --- a/lib/coffee_script/nodes.rb +++ b/lib/coffee_script/nodes.rb @@ -609,6 +609,7 @@ module CoffeeScript o[:top] = true cond = @condition.compile(o) post = returns ? "\n#{idt}return null;" : '' + return write("#{idt}while (#{cond});#{post}") if @body.nil? write("#{idt}while (#{cond}) {\n#{@body.compile(o)}\n#{idt}}#{post}") end end