ruby-changes:49879
From: nobu <ko1@a...>
Date: Sun, 21 Jan 2018 16:44:28 +0900 (JST)
Subject: [ruby-changes:49879] nobu:r61997 (trunk): parse.y: parser_token_value_print for yydebug
nobu 2018-01-21 16:44:23 +0900 (Sun, 21 Jan 2018) New Revision: 61997 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61997 Log: parse.y: parser_token_value_print for yydebug Modified files: trunk/parse.y Index: parse.y =================================================================== --- parse.y (revision 61996) +++ parse.y (revision 61997) @@ -46,6 +46,7 @@ https://github.com/ruby/ruby/blob/trunk/parse.y#L46 #define YYCALLOC(nelem, size) rb_parser_calloc(p, (nelem), (size)) #define YYFREE(ptr) rb_parser_free(p, (ptr)) #define YYFPRINTF rb_parser_printf +#define YYPRINT(out, tok, val) parser_token_value_print(p, (tok), &(val)) #define YY_LOCATION_PRINT(File, loc) \ rb_parser_printf(p, "%d.%d-%d.%d", \ (loc).beg_pos.lineno, (loc).beg_pos.column,\ @@ -500,6 +501,7 @@ void rb_parser_set_location_of_none(stru https://github.com/ruby/ruby/blob/trunk/parse.y#L501 void rb_parser_set_location(struct parser_params *p, YYLTYPE *yylloc); RUBY_SYMBOL_EXPORT_END +static void parser_token_value_print(struct parser_params *p, enum yytokentype type, const YYSTYPE *valp); static ID formal_argument(struct parser_params*, ID); static ID shadowing_lvar(struct parser_params*,ID); static void new_bv(struct parser_params*,ID); @@ -8946,6 +8948,49 @@ rb_parser_set_location(struct parser_par https://github.com/ruby/ruby/blob/trunk/parse.y#L8948 } #endif /* !RIPPER */ +static void +parser_token_value_print(struct parser_params *p, enum yytokentype type, const YYSTYPE *valp) +{ + VALUE v; + + switch (type) { + case tIDENTIFIER: case tFID: case tGVAR: case tIVAR: + case tCONSTANT: case tCVAR: case tLABEL: case tOP_ASGN: +#ifndef RIPPER + v = rb_id2str(valp->id); +#else + v = valp->val; +#endif + rb_parser_printf(p, "%"PRIsVALUE, v); + break; + case tINTEGER: case tFLOAT: case tRATIONAL: case tIMAGINARY: + case tSTRING_CONTENT: case tCHAR: +#ifndef RIPPER + v = valp->node->nd_lit; +#else + v = valp->val; +#endif + rb_parser_printf(p, "%+"PRIsVALUE, v); + break; + case tNTH_REF: +#ifndef RIPPER + rb_parser_printf(p, "$%ld", valp->node->nd_nth); +#else + rb_parser_printf(p, "%"PRIsVALUE, valp->val); +#endif + break; + case tBACK_REF: +#ifndef RIPPER + rb_parser_printf(p, "$%c", valp->node->nd_nth); +#else + rb_parser_printf(p, "%"PRIsVALUE, valp->val); +#endif + break; + default: + break; + } +} + static int assignable0(struct parser_params *p, ID id, const char **err) { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/