Bug #6115
closedA block after the do-block without parenthesis
Description
=begin
= ((<pull request 102 by pasberth: A block after the do-block without parenthesis|URL:https://github.com/ruby/ruby/pull/102>))
((<patch|URL:https://github.com/pasberth/ruby/commit/2d6624238aae89110141a8e223f244bf92eb27a9>))
I think seemingly this source code is no problem:
$ cat unexpected.rb
langs = ["Ruby"]
langs.each_with_object [] do |lang, the_langs|
the_langs << "The #{lang}"
end.each do |the_lang|
puts the_lang
end
But syntax error:
$ ruby unexpected.rb
unexpected.rb:4: syntax error, unexpected keyword_do
end.each do |the_lang|
^
unexpected.rb:5: syntax error, unexpected tIDENTIFIER, expecting keyword_do or '{' or '('
I want to this code behaves like:
$ cat expected.rb
langs = ["Ruby"]
(langs.each_with_object [] do |lang, the_langs|
the_langs << "The #{lang}"
end).each do |the_lang|
puts the_lang
end
$ ruby expected.rb
The Ruby
I changed the block_call in the parse.y to a primary-expression.
$ ./ruby -I./lib -I. unexpected.rb
The Ruby
英語に自信がないので日本語でも失礼します。
上の unexpected.rb はぼくには一見なんの問題もなさそうなコードに見えます。
しかしそれは構文エラーです。
ぼくはこのブロックを一次式として扱うべきだと思いました。
=end
Updated by nobu (Nobuyoshi Nakada) almost 13 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
This issue was solved with changeset r34913.
Nobuyoshi, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
- parse.y (block_call): rules for block_call after block_call.
based on a patch by pasberth https://github.com/ruby/ruby/pull/102
[ruby-dev:45308][Bug #6115]