From af17e111b3f7cb3c5ad7dc194399b44d0e5004d0 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Mon, 27 May 2019 11:57:48 +0900 Subject: Added #inspect and #pretty_inspect to Ripper::Lexer::Elem --- ext/ripper/lib/ripper/lexer.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'ext') diff --git a/ext/ripper/lib/ripper/lexer.rb b/ext/ripper/lib/ripper/lexer.rb index 95e1ebcdfe..3301a6078c 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 -- cgit v1.2.1