ruby-changes:68267
From: Nobuyoshi <ko1@a...>
Date: Tue, 5 Oct 2021 17:10:45 +0900 (JST)
Subject: [ruby-changes:68267] a15996c752 (master): Split parser_yyerror0 from parser_yyerror
https://git.ruby-lang.org/ruby.git/commit/?id=a15996c752 From a15996c752cccbdcad2065b9b0a22271c3bbbb99 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Tue, 5 Oct 2021 16:59:35 +0900 Subject: Split parser_yyerror0 from parser_yyerror The former uses the current location, while the latter takes a non-null location. --- parse.y | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/parse.y b/parse.y index 1f000a13de..3ae456ca4c 100644 --- a/parse.y +++ b/parse.y @@ -398,8 +398,11 @@ pop_pktbl(struct parser_params *p, st_table *tbl) https://github.com/ruby/ruby/blob/trunk/parse.y#L398 p->pktbl = tbl; } +RBIMPL_ATTR_NONNULL((1, 2, 3)) static int parser_yyerror(struct parser_params*, const YYLTYPE *yylloc, const char*); -#define yyerror0(msg) parser_yyerror(p, NULL, (msg)) +RBIMPL_ATTR_NONNULL((1, 2)) +static int parser_yyerror0(struct parser_params*, const char*); +#define yyerror0(msg) parser_yyerror0(p, (msg)) #define yyerror1(loc, msg) parser_yyerror(p, (loc), (msg)) #define yyerror(yylloc, p, msg) parser_yyerror(p, yylloc, msg) #define token_flush(ptr) ((ptr)->lex.ptok = (ptr)->lex.pcur) @@ -5989,6 +5992,7 @@ parser_show_error_line(struct parser_params *p, const YYLTYPE *yylloc) https://github.com/ruby/ruby/blob/trunk/parse.y#L5992 static int parser_yyerror(struct parser_params *p, const YYLTYPE *yylloc, const char *msg) { +#if 0 YYLTYPE current; if (!yylloc) { @@ -5998,11 +6002,19 @@ parser_yyerror(struct parser_params *p, const YYLTYPE *yylloc, const char *msg) https://github.com/ruby/ruby/blob/trunk/parse.y#L6002 p->ruby_sourceline != yylloc->end_pos.lineno)) { yylloc = 0; } +#endif compile_error(p, "%s", msg); parser_show_error_line(p, yylloc); return 0; } +static int +parser_yyerror0(struct parser_params *p, const char *msg) +{ + YYLTYPE current; + return parser_yyerror(p, RUBY_SET_YYLLOC(current), msg); +} + static void ruby_show_error_line(VALUE errbuf, const YYLTYPE *yylloc, int lineno, VALUE str) { @@ -6112,16 +6124,14 @@ static int https://github.com/ruby/ruby/blob/trunk/parse.y#L6124 parser_yyerror(struct parser_params *p, const YYLTYPE *yylloc, const char *msg) { const char *pcur = 0, *ptok = 0; - if (yylloc && - p->ruby_sourceline == yylloc->beg_pos.lineno && + if (p->ruby_sourceline == yylloc->beg_pos.lineno && p->ruby_sourceline == yylloc->end_pos.lineno) { pcur = p->lex.pcur; ptok = p->lex.ptok; p->lex.ptok = p->lex.pbeg + yylloc->beg_pos.column; p->lex.pcur = p->lex.pbeg + yylloc->end_pos.column; } - dispatch1(parse_error, STR_NEW2(msg)); - ripper_error(p); + parser_yyerror0(p, msg); if (pcur) { p->lex.ptok = ptok; p->lex.pcur = pcur; @@ -6129,6 +6139,14 @@ parser_yyerror(struct parser_params *p, const YYLTYPE *yylloc, const char *msg) https://github.com/ruby/ruby/blob/trunk/parse.y#L6139 return 0; } +static int +parser_yyerror0(struct parser_params *p, const char *msg) +{ + dispatch1(parse_error, STR_NEW2(msg)); + ripper_error(p); + return 0; +} + static inline void parser_show_error_line(struct parser_params *p, const YYLTYPE *yylloc) { @@ -7505,7 +7523,7 @@ heredoc_identifier(struct parser_params *p) https://github.com/ruby/ruby/blob/trunk/parse.y#L7523 len = 0; while ((c = nextc(p)) != term) { if (c == -1 || c == '\r' || c == '\n') { - yyerror(NULL, p, "unterminated here document identifier"); + yyerror0("unterminated here document identifier"); return -1; } } @@ -7531,7 +7549,7 @@ heredoc_identifier(struct parser_params *p) https://github.com/ruby/ruby/blob/trunk/parse.y#L7549 len = p->lex.pcur - (p->lex.pbeg + offset) - quote; if ((unsigned long)len >= HERETERM_LENGTH_MAX) - yyerror(NULL, p, "too long here document identifier"); + yyerror0("too long here document identifier"); dispatch_scan_event(p, tHEREDOC_BEG); lex_goto_eol(p); @@ -10754,7 +10772,7 @@ rb_parser_fatal(struct parser_params *p, const char *fmt, ...) https://github.com/ruby/ruby/blob/trunk/parse.y#L10772 va_start(ap, fmt); rb_str_vcatf(mesg, fmt, ap); va_end(ap); - parser_yyerror(p, NULL, RSTRING_PTR(mesg)); + yyerror0(RSTRING_PTR(mesg)); RB_GC_GUARD(mesg); mesg = rb_str_new(0, 0); -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/