1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Added #inspect and #pretty_inspect to Ripper::Lexer::Elem

This commit is contained in:
Nobuyoshi Nakada 2019-05-27 11:57:48 +09:00
parent 43730256e8
commit af17e111b3
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60

View file

@ -49,7 +49,8 @@ class Ripper
State = Struct.new(:to_int, :to_s) do
alias to_i to_int
def initialize(i) super(i, Ripper.lex_state_name(i)).freeze end
def inspect; "#<#{self.class}: #{self}>" end
# def inspect; "#<#{self.class}: #{self}>" end
alias inspect to_s
def pretty_print(q) q.text(to_s) end
def ==(i) super or to_int == i end
def &(i) self.class.new(to_int & i) end
@ -63,6 +64,20 @@ class Ripper
def initialize(pos, event, tok, state)
super(pos, event, tok, State.new(state))
end
def inspect
"#<#{self.class}: #{event}@#{pos[0]}:#{pos[0]}:#{state}: #{tok.inspect}>"
end
def pretty_print(q)
q.group(2, "#<#{self.class}:", ">") {
q.breakable
q.text("#{event}@#{pos[0]}:#{pos[0]}")
q.breakable
q.text("token: ")
tok.pretty_print(q)
}
end
end
def tokenize