summaryrefslogtreecommitdiff
path: root/ext/ripper/lib
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2019-05-27 11:57:48 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-05-27 13:58:40 +0900
commitaf17e111b3f7cb3c5ad7dc194399b44d0e5004d0 (patch)
tree1d0e6aa9eb4d1b4b31bc0483ef70bb3203e6beb7 /ext/ripper/lib
parent43730256e800dd8e0c5cc482e9861868590ae037 (diff)
Added #inspect and #pretty_inspect to Ripper::Lexer::Elem
Diffstat (limited to 'ext/ripper/lib')
-rw-r--r--ext/ripper/lib/ripper/lexer.rb17
1 files changed, 16 insertions, 1 deletions
diff --git a/ext/ripper/lib/ripper/lexer.rb b/ext/ripper/lib/ripper/lexer.rb
index 95e1ebcdfe3..3301a6078c6 100644
--- a/ext/ripper/lib/ripper/lexer.rb
+++ b/ext/ripper/lib/ripper/lexer.rb
@@ -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