ruby-changes:48550
From: nobu <ko1@a...>
Date: Mon, 6 Nov 2017 06:13:23 +0900 (JST)
Subject: [ruby-changes:48550] nobu:r60665 (trunk): lexer.rb: Ripper::Lexer::State
nobu 2017-11-06 06:13:18 +0900 (Mon, 06 Nov 2017) New Revision: 60665 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60665 Log: 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. Modified files: trunk/ext/ripper/lib/ripper/lexer.rb trunk/parse.y Index: parse.y =================================================================== --- parse.y (revision 60664) +++ parse.y (revision 60665) @@ -9865,7 +9865,7 @@ rb_parser_trace_lex_state(struct parser_ https://github.com/ruby/ruby/blob/trunk/parse.y#L9865 VALUE rb_parser_lex_state_name(enum lex_state_e state) { - return append_lex_state_name(state, rb_str_new(0, 0)); + return rb_fstring(append_lex_state_name(state, rb_str_new(0, 0))); } static void Index: ext/ripper/lib/ripper/lexer.rb =================================================================== --- ext/ripper/lib/ripper/lexer.rb (revision 60664) +++ ext/ripper/lib/ripper/lexer.rb (revision 60665) @@ -46,33 +46,19 @@ class Ripper https://github.com/ruby/ruby/blob/trunk/ext/ripper/lib/ripper/lexer.rb#L46 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 + 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 - def to_a - List[*values] + Elem = Struct.new(:pos, :event, :tok, :state) do + def initialize(pos, event, tok, state) + super(pos, event, tok, State.new(state)) end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/