Incompatibility in syntax error when blank heredoc delimiters

Open
#996 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
ruby
Domain
compilers

Research direction

Start by reproducing the examples in example.rb and compare Ruby 3.3's syntax error with ruby-parse --33 example.rb. Check the parser's handling of <<~'', <<'', and <<-''; done means these blank heredoc delimiters are rejected consistently with Ruby.

Written by the indexing model from the issue text.

Description

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 <<-''.

Dominant language
Yacc
Stars
1.6k
Forks
205
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from whitequark/parser

All issues in whitequark/parser

Similar issues

More Compilers issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.