From: Ryan Davis Date: 2011-08-22T08:44:54+09:00 Subject: Re: Possble bug in Ruby parser (Fixnum#times within "case" statement) On Aug 21, 2011, at 16:12 , Iņaki Baz Castillo wrote: > Hi, I cannot find an explanation for the following issue so I think it's a bug: > reformatted to be idiomatic and therefore readable: > def kk > while case @state > when :init > 10.times do |index| > puts "index = #{index}" > end > @state = :end > true > when :end > puts "END" > end > # zenspider: do nothing??? > end > end > > @state = :init > kk > > Running the above code gives an error: > > ~# ruby1.9.3 kk.rb > > kk.rb:6: syntax error, unexpected keyword_do_cond, expecting keyword_end > 10.times do |index| > ^ > Why???? Because it is nonsensical and confuses the parser. I'm not really sure WHY you have a while in there at all but I can describe the components involved: while expr [do] body end That 'do' is important here... You've started a while loop, started the condition expression, left it hanging, and then hit the do in a place that doesn't make any sense to the condition expression... You have an unterminated case/when. You can see this in all of its grubby detail by running 'ruby -ycw kk.rb' Since I can't make any sense of your code, I can only guess as to your intent and offer suggestions: loop do # ... case, et al end or def kk while (case @state when :init then 10.times do |index| puts "index = #{index}" end @state = :end true when :end then puts "END" end) do # do nothing? end end or just get rid of your loop as it contributes nothing.