ruby-changes:48006
From: nobu <ko1@a...>
Date: Thu, 5 Oct 2017 10:53:27 +0900 (JST)
Subject: [ruby-changes:48006] nobu:r60120 (trunk): parse.y: fix KWD2EID
nobu 2017-10-05 10:53:22 +0900 (Thu, 05 Oct 2017) New Revision: 60120 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60120 Log: parse.y: fix KWD2EID * parse.y (KWD2EID): should respect the previous callback result for keywords. [ruby-core:83106] [Bug #13971] Modified files: trunk/parse.y trunk/test/ripper/test_sexp.rb Index: test/ripper/test_sexp.rb =================================================================== --- test/ripper/test_sexp.rb (revision 60119) +++ test/ripper/test_sexp.rb (revision 60120) @@ -87,6 +87,15 @@ eot https://github.com/ruby/ruby/blob/trunk/test/ripper/test_sexp.rb#L87 assert_equal("<<", fname) end + def test_defs_fname + sexp = Ripper.sexp("def self.t; end") + _, recv, _, (type, fname) = search_sexp(:defs, sexp) + assert_equal(:var_ref, recv[0], recv) + assert_equal([:@kw, "self", [1, 4]], recv[1], recv) + assert_equal(:@ident, type) + assert_equal("t", fname) + end + def search_sexp(sym, sexp) return sexp if !sexp or sexp[0] == sym sexp.find do |e| Index: parse.y =================================================================== --- parse.y (revision 60119) +++ parse.y (revision 60120) @@ -678,10 +678,7 @@ static void ripper_error_gen(struct pars https://github.com/ruby/ruby/blob/trunk/parse.y#L678 #define ID2VAL(id) STATIC_ID2SYM(id) #define TOKEN2VAL(t) ID2VAL(TOKEN2ID(t)) -#define KWD2EID(t) \ - ripper_new_yylval(keyword_##t, \ - ID2SYM(#t[0]=='_' ? rb_intern("_"#t) : rb_intern(#t)), \ - 0) +#define KWD2EID(t, v) ripper_new_yylval(keyword_##t, get_value(v), 0) #define arg_new() dispatch0(args_new) #define arg_add(l,a) dispatch2(args_add, (l), (a)) @@ -738,7 +735,7 @@ static VALUE parser_heredoc_dedent(struc https://github.com/ruby/ruby/blob/trunk/parse.y#L735 #else #define ID2VAL(id) ((VALUE)(id)) #define TOKEN2VAL(t) ID2VAL(t) -#define KWD2EID(t) keyword_##t +#define KWD2EID(t, v) keyword_##t #endif /* RIPPER */ #ifndef RIPPER @@ -4107,13 +4104,13 @@ user_variable : tIDENTIFIER https://github.com/ruby/ruby/blob/trunk/parse.y#L4104 | tCVAR ; -keyword_variable: keyword_nil {$$ = KWD2EID(nil);} - | keyword_self {$$ = KWD2EID(self);} - | keyword_true {$$ = KWD2EID(true);} - | keyword_false {$$ = KWD2EID(false);} - | keyword__FILE__ {$$ = KWD2EID(_FILE__);} - | keyword__LINE__ {$$ = KWD2EID(_LINE__);} - | keyword__ENCODING__ {$$ = KWD2EID(_ENCODING__);} +keyword_variable: keyword_nil {$$ = KWD2EID(nil, $1);} + | keyword_self {$$ = KWD2EID(self, $1);} + | keyword_true {$$ = KWD2EID(true, $1);} + | keyword_false {$$ = KWD2EID(false, $1);} + | keyword__FILE__ {$$ = KWD2EID(_FILE__, $1);} + | keyword__LINE__ {$$ = KWD2EID(_LINE__, $1);} + | keyword__ENCODING__ {$$ = KWD2EID(_ENCODING__, $1);} ; var_ref : user_variable -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/