summaryrefslogtreecommitdiff
path: root/ext/ripper
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-18 00:08:19 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-18 00:08:19 (GMT)
commitd1e63172c6ecf2606ff9a947d917117eb6923436 (patch)
treee1789775c8eb2c828ba119c5cfc510a7f58f82d3 /ext/ripper
parent5166f948792af7335e1c2576ac506e3cc73104f2 (diff)
parse.y: ripper_lex_state_name
* parse.y (ripper_lex_state_name): represent lex_state as OR-ed form. * ext/ripper/lib/ripper/lexer.rb (Ripper::Lexer::Elem#to_a): lex_state for inspection. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59949 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/ripper')
-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 4e82a12..c682c18 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)