whitequark / parser

A Ruby parser.
Other
1.59k stars 199 forks source link

Incompatibility in syntax error when blank heredoc delimiters #996

Open koic opened 9 months ago

koic commented 9 months ago

There is an incompatibility in syntax error between Parser gem and Ruby:

$ cat example.rb
<<~''

Expected

<<~'' has been a syntax error since at least Ruby 2.0:

$ ruby -v example.rb
ruby 2.0.0p648 (2015-12-16 revision 53162) [x86_64-darwin13.0.2]
example.rb:1: syntax error, unexpected <<
<<~''
  ^

The same goes for Ruby 3.3:

$ ruby -v example.rb
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin22]
example.rb:1: warning: possibly useless use of a literal in void context
example.rb: --> /tmp/h.rb
could not find a terminator for the heredoc
> 1  <<~''

Actual

Although the Parser gem is able to parse it, this is likely an unexpected behavior:

$ ruby-parse --33 example.rb
(dstr)

The same goes for <<'' and <<-''.