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:
parent
43730256e8
commit
af17e111b3
1 changed files with 16 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue