whitequark / parser

A Ruby parser.
Other
1.58k stars 198 forks source link

EOF characters should be allowed as heredoc delimiter #809

Open pocke opened 3 years ago

pocke commented 3 years ago

Problem

^D, ^Z, and \0 should be allowed as heredoc delimiter if it is surrounded with quotes, but isn't.

For example:

# test.rb
puts <<~RUBY
  <<~'\0'
  \0
RUBY
$ ruby test.rb | ruby -c
Syntax OK
$ ruby test.rb | ruby-parse /dev/stdin 
/dev/stdin:1:1: fatal: unterminated string meets end of file
/dev/stdin:1: <<~'
pocke commented 3 years ago

By the way, I found other bugs during grep c_any in lexer.rl. Both of the following are accepted by CRuby, but ruby-parse raises an error unexpectedly.

Note that ^D means 0x04.

Maybe there are other bugs related to c_any char class in lexer.rl but didn't investigate it deeply.

ref: #808