ruby-changes:47831
From: nobu <ko1@a...>
Date: Mon, 18 Sep 2017 09:08:31 +0900 (JST)
Subject: [ruby-changes:47831] nobu:r59949 (trunk): parse.y: ripper_lex_state_name
nobu 2017-09-18 09:08:19 +0900 (Mon, 18 Sep 2017) New Revision: 59949 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59949 Log: 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. Modified files: trunk/ext/ripper/lib/ripper/lexer.rb trunk/parse.y Index: ext/ripper/lib/ripper/lexer.rb =================================================================== --- ext/ripper/lib/ripper/lexer.rb (revision 59948) +++ ext/ripper/lib/ripper/lexer.rb (revision 59949) @@ -47,6 +47,33 @@ class Ripper https://github.com/ruby/ruby/blob/trunk/ext/ripper/lib/ripper/lexer.rb#L47 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) Index: parse.y =================================================================== --- parse.y (revision 59948) +++ parse.y (revision 59949) @@ -568,6 +568,7 @@ RUBY_SYMBOL_EXPORT_BEGIN https://github.com/ruby/ruby/blob/trunk/parse.y#L568 VALUE rb_parser_reg_compile(struct parser_params* parser, VALUE str, int options); int rb_reg_fragment_setenc(struct parser_params*, VALUE, int); enum lex_state_e rb_parser_trace_lex_state(struct parser_params *, enum lex_state_e, enum lex_state_e, int); +VALUE rb_parser_lex_state_name(enum lex_state_e state); void rb_parser_show_bitstack(struct parser_params *, stack_type, const char *, int); PRINTF_ARGS(void rb_parser_fatal(struct parser_params *parser, const char *fmt, ...), 2, 3); RUBY_SYMBOL_EXPORT_END @@ -9191,6 +9192,12 @@ rb_parser_trace_lex_state(struct parser_ https://github.com/ruby/ruby/blob/trunk/parse.y#L9192 return to; } +VALUE +rb_parser_lex_state_name(enum lex_state_e state) +{ + return append_lex_state_name(state, rb_str_new(0, 0)); +} + static void append_bitstack_value(stack_type stack, VALUE mesg) { @@ -11484,6 +11491,11 @@ ripper_value(VALUE self, VALUE obj) https://github.com/ruby/ruby/blob/trunk/parse.y#L11491 } #endif +static VALUE +ripper_lex_state_name(VALUE self, VALUE state) +{ + return rb_parser_lex_state_name(NUM2INT(state)); +} void Init_ripper(void) @@ -11526,6 +11538,8 @@ InitVM_ripper(void) https://github.com/ruby/ruby/blob/trunk/parse.y#L11538 rb_define_singleton_method(Ripper, "dedent_string", parser_dedent_string, 2); rb_define_private_method(Ripper, "dedent_string", parser_dedent_string, 2); + rb_define_singleton_method(Ripper, "lex_state_name", ripper_lex_state_name, 1); + <% @exprs.each do |expr, desc| -%> /* <%=desc%> */ rb_define_const(Ripper, "<%=expr%>", INT2NUM(<%=expr%>)); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/