whitequark / parser

A Ruby parser.
Other
1.57k stars 197 forks source link

Syntax error on heredoc inside block indented with tabs #989

Closed bquorning closed 6 months ago

bquorning commented 6 months ago

An error report in rubocop-rspec led me all the way via rubocop-ast into this gem. I wrote the following test case for test/test_parser.rb, and it fails (seemingly in all ruby versions and not just 3.3.0 as in the linked issue) with Parser::SyntaxError: (2.3) unterminated string meets end of file

  def test_parser_of_heredoc_inside_block_with_tab_indentation
    assert_parses(
      s(:block,
        s(:send, nil, :foo),
        s(:args),
        s(:str, "bar\n")),
      %Q{foo do!\t<<~DESC!\t\tbar!\tDESC!end}.gsub('!', "\n"),
      %q{},
      SINCE_2_3)
  end
AlexWayfer commented 6 months ago

With Ruby 3.2 RuboCop gives such output (not breaking itself at least):

> bundle exec rubocop
Inspecting 8 files
...F...F

Offenses:

lib/static_files_toys/template.rb:10:18: F: Lint/Syntax: unterminated string meets end of file
(Using Ruby 3.0 parser; configure using TargetRubyVersion parameter, under AllCops)
        GREP_OPTIONS = <<~STR.chomp
                 ^
static_files_toys.gemspec:12:23: F: Lint/Syntax: unterminated string meets end of file
(Using Ruby 3.0 parser; configure using TargetRubyVersion parameter, under AllCops)
    spec.description   = <<~DESC
                      ^

8 files inspected, 2 offenses detected
iliabylich commented 6 months ago

Thanks for reporting, that's definitely a regression introduced in 3.3.0.0, I'll make a fix soon.

AlexWayfer commented 6 months ago

I can confirm that version 3.3.0.3 fixes the problem. Great thank you.

iliabylich commented 6 months ago

parser 3.3.0.3 has been released (and it seems to fix the issue, thanks @AlexWayfer )

bquorning commented 6 months ago

Thank you for the quick fix ❤️