Project

General

Profile

Actions

Bug #19788

closed

Ripper returns a symbol instead of a token as operator for "::"

Added by thyresias (Thierry Lambert) over 1 year ago. Updated over 1 year ago.

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

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

require 'pp'

BasicParser.new('a&.b').parse
# in stdout:
# ident(["a"])
# op(["&."])
# vcall([[:ident, "a"]])
# ident(["b"])
# call([[:vcall, [:ident, "a"]], [:op, "&."], [:ident, "b"]])

BasicParser.new('a::b').parse
# in stdout:
# ident(["a"])
# op(["::"])
# vcall([[:ident, "a"]])
# ident(["b"])
# call([[:vcall, [:ident, "a"]], :"::", [:ident, "b"]])

On the last line, consistent with &., I would have expected:

# call([[:vcall, [:ident, "a"]], [:op, "::"], [:ident, "b"]])

This is true for the "operator" argument of call, command_call and field.
Is it intended?

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0