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
This commit is contained in:
nobu 2017-11-05 21:13:18 +00:00
Родитель ca551eed45
Коммит 3280f54168
2 изменённых файлов: 13 добавлений и 27 удалений

Просмотреть файл

@ -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
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 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]
Elem = Struct.new(:pos, :event, :tok, :state) do
def initialize(pos, event, tok, state)
super(pos, event, tok, State.new(state))
end
end

Просмотреть файл

@ -9865,7 +9865,7 @@ rb_parser_trace_lex_state(struct parser_params *parser, enum lex_state_e from,
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