Project

General

Profile

Actions

Bug #19861

closed

Ripper does not fire any error event on unfinished heredoc

Added by thyresias (Thierry Lambert) 8 months ago. Updated 8 months ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x64-mingw-ucrt]
[ruby-core:114625]

Description

require 'ripper'

class BasicParser < Ripper
  EVENTS.each do |event|
    module_eval(<<~RUBY, __FILE__, __LINE__ + 1)
      def on_#{event}(*args)
        puts "#{event}(\#{args.inspect})"
        args.unshift :#{event}
        args
      end
    RUBY
  end
end

p = BasicParser.new(<<~RUBY)
  <<~EOT
    foo
RUBY
p.parse
p error: p.error?
# in stdout:
# heredoc_beg(["<<~EOT"])
# string_content([])
# tstring_content(["  foo\n"])
# string_add([[:string_content], [:tstring_content, "  foo\n"]])
# heredoc_dedent([[:string_add, [:string_content], [:tstring_content, "  foo\n"]], 2])
# string_literal([[:string_add, [:string_content], [:tstring_content, "  foo\n"]]])
# nl(["\n"])
# stmts_new([])
# stmts_add([[:stmts_new], [:string_literal, [:string_add, [:string_content], [:tstring_content, "  foo\n"]]]])
# program([[:stmts_add, [:stmts_new], [:string_literal, [:string_add, [:string_content], [:tstring_content, "  foo\n"]]]]])
# {:error=>true}

I would have expected one of the _error events to fire, since p.error? returns true.

Actions #1

Updated by thyresias (Thierry Lambert) 8 months ago

  • Description updated (diff)

Updated by nobu (Nobuyoshi Nakada) 8 months ago

  • Status changed from Open to Feedback

compile_error will be called at that time.

Updated by thyresias (Thierry Lambert) 8 months ago

I had missed this one.
Thanks, nobu.

Actions #4

Updated by nobu (Nobuyoshi Nakada) 8 months ago

  • Status changed from Feedback to Closed
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0