summaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2021-09-14 16:36:39 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-09-14 18:51:38 +0900
commitfa05697e4832fbd67a4f91b9bb362471902faab3 (patch)
tree2986a820e14ad1a661eea5ec7ce124b02f62eff3 /parse.y
parent6031f4268b56d9db807fc05a06ba7c4fcb5c5bf8 (diff)
Use `%printer` directive for Bison 3.8
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4836
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y74
1 files changed, 29 insertions, 45 deletions
diff --git a/parse.y b/parse.y
index 88ae901e6d..6184112d54 100644
--- a/parse.y
+++ b/parse.y
@@ -88,7 +88,6 @@ struct lex_context {
#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,\
@@ -653,7 +652,6 @@ RUBY_SYMBOL_EXPORT_END
static void error_duplicate_pattern_variable(struct parser_params *p, ID id, const YYLTYPE *loc);
static void error_duplicate_pattern_key(struct parser_params *p, ID id, const YYLTYPE *loc);
-static void parser_token_value_print(struct parser_params *p, enum yytokentype type, const YYSTYPE *valp);
#ifndef RIPPER
static ID formal_argument(struct parser_params*, ID);
#else
@@ -1083,6 +1081,35 @@ static int looking_at_eol_p(struct parser_params *p);
%expect 0
%define api.pure
%define parse.error verbose
+%printer {
+#ifndef RIPPER
+ rb_parser_printf(p, "%"PRIsVALUE, rb_id2str($$));
+#else
+ rb_parser_printf(p, "%"PRIsVALUE, RNODE($$)->nd_rval);
+#endif
+} tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tCVAR tLABEL tOP_ASGN
+%printer {
+#ifndef RIPPER
+ rb_parser_printf(p, "%+"PRIsVALUE, $$->nd_lit);
+#else
+ rb_parser_printf(p, "%+"PRIsVALUE, get_value($$));
+#endif
+} tINTEGER tFLOAT tRATIONAL tIMAGINARY tSTRING_CONTENT tCHAR
+%printer {
+#ifndef RIPPER
+ rb_parser_printf(p, "$%ld", $$->nd_nth);
+#else
+ rb_parser_printf(p, "%"PRIsVALUE, $$);
+#endif
+} tNTH_REF
+%printer {
+#ifndef RIPPER
+ rb_parser_printf(p, "$%c", (int)$$->nd_nth);
+#else
+ rb_parser_printf(p, "%"PRIsVALUE, $$);
+#endif
+} tBACK_REF
+
%lex-param {struct parser_params *p}
%parse-param {struct parser_params *p}
%initial-action
@@ -10779,49 +10806,6 @@ rb_parser_set_location(struct parser_params *p, YYLTYPE *yylloc)
}
#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->node->nd_rval;
-#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 = get_value(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", (int)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)
{