summaryrefslogtreecommitdiff
path: root/ext/ripper
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-11-05 21:13:18 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-11-05 21:13:18 (GMT)
commit3280f54168069d207834d9d15b0fb2ffa17168ce (patch)
treefdfa49d2e355dc6f96599a2dc83c40fd431bad1d /ext/ripper
parentca551eed45fe416292ae08ed018c772cb430d5cb (diff)
lexer.rb: Ripper::Lexer::State
* ext/ripper/lib/ripper/lexer.rb (Ripper::Lexer::State): wrapper of lex_state values. * parse.y (rb_parser_lex_state_name): return shared strings. lex state combinations are very restricted. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60665 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/ripper')
-rw-r--r--ext/ripper/lib/ripper/lexer.rb40
1 files changed, 13 insertions, 27 deletions
diff --git a/ext/ripper/lib/ripper/lexer.rb b/ext/ripper/lib/ripper/lexer.rb
index 22f18ff..22e01b3 100644
--- a/ext/ripper/lib/ripper/lexer.rb
+++ b/ext/ripper/lib/ripper/lexer.rb
@@ -46,33 +46,19 @@ class Ripper
end
class Lexer < ::Ripper #:nodoc: internal use only
- Elem = Struct.new(:pos, :event, :tok, :state)
- class Elem
- class List < ::Array
- def inspect
- super.sub!(/\d+(?=\]\z)/, Ripper.lex_state_name(self[3]))
- end
-
- def pretty_print(q) # :nodoc:
- pos, event, tok, state = self
- 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]
+ 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 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
+ def |(i) self.class.new(to_int & i) end
+ end
+
+ Elem = Struct.new(:pos, :event, :tok, :state) do
+ def initialize(pos, event, tok, state)
+ super(pos, event, tok, State.new(state))
end
end