summaryrefslogtreecommitdiff
path: root/ext/ripper/lib/ripper/lexer.rb
diff options
context:
space:
mode:
Diffstat (limited to 'ext/ripper/lib/ripper/lexer.rb')
-rw-r--r--ext/ripper/lib/ripper/lexer.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/ext/ripper/lib/ripper/lexer.rb b/ext/ripper/lib/ripper/lexer.rb
index 4e82a1275c2..c682c1836f9 100644
--- a/ext/ripper/lib/ripper/lexer.rb
+++ b/ext/ripper/lib/ripper/lexer.rb
@@ -47,6 +47,33 @@ class Ripper
class Lexer < ::Ripper #:nodoc: internal use only
Elem = Struct.new(:pos, :event, :tok, :state)
+ class Elem
+ class List < ::Array
+ def inspect
+ [pos, event, tok, Ripper.lex_state_name(state)].inspect
+ end
+
+ def pretty_print(q) # :nodoc:
+ q.group(1, '[', ']') {
+ q.pp pos
+ q.comma_breakable
+ q.pp event
+ q.comma_breakable
+ q.pp tok
+ q.comma_breakable
+ q.text(Ripper.lex_state_name(state))
+ }
+ end
+
+ def pretty_print_cycle(q) # :nodoc:
+ q.text('[...]')
+ end
+ end
+
+ def to_a
+ List[*values]
+ end
+ end
def tokenize
parse().sort_by(&:pos).map(&:tok)