Actions
Bug #8628
closedParse error with method argument that is a Hash with a specific pattern
Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 2.0.0p195 (2013-05-14) [i386-mingw32]
Backport:
Description
The next two lines cause a parse error¶
p /=/ => 'works'
/in comment/ => 'fails'¶
The reported error is:¶
syntax error, unexpected ',', expecting $end¶
/in comment/ => 'fails'¶
^¶
The issue is caused by the /=/ regexp in the method p call.¶
Notice that no parse error occurs when the Hash argument is put between parentheses¶
p(/=/ => 'works').
Files
Updated by dimitri-lo2u (Dimitri Geshef) over 11 years ago
First detected in ruby 1.9.3p374 (2013-01-15) [i386-mingw32]
Updated by dimitri-lo2u (Dimitri Geshef) over 11 years ago
The error message when you run the snippet in attachment is:
snippet.rb:9: syntax error, unexpected tIDENTIFIER, expecting $end
/in comment/ => 'fails'¶
^
Updated by dimitri-lo2u (Dimitri Geshef) over 11 years ago
Updated by nobu (Nobuyoshi Nakada) over 11 years ago
- Status changed from Open to Rejected
p /=/' is interpreted as
p /= /.../', an assignment to a variable `p'.
Updated by dimitri-lo2u (Dimitri Geshef) over 11 years ago
@nobu (Nobuyoshi Nakada).
My apologies for this false alarm.
Thank you for pointing the grammatical ambiguity:
/=/ can be parsed as the /= operator followed by a regexp literal or the regexp literal /=/ itself.
Didn't realize this.
Actions
Like0
Like0Like0Like0Like0Like0