Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
yui-knk committed Apr 24, 2024
1 parent 481d70e commit d66a573
Showing 1 changed file with 24 additions and 54 deletions.
78 changes: 24 additions & 54 deletions parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -1822,6 +1822,7 @@ extern const ID id_warn, id_warning, id_gets, id_assoc;
# define WARNING_CALL rb_funcall
# endif
# define compile_error ripper_compile_error
# define compile_error_with_loc(p, loc, ...) ((void)loc, ripper_compile_error(p, __VA_ARGS__))
#else
# define WARN_S_L(s,l) s
# define WARN_S(s) s
Expand All @@ -1837,6 +1838,7 @@ extern const ID id_warn, id_warning, id_gets, id_assoc;
# define WARNING_CALL rb_compile_warning
PRINTF_ARGS(static void parser_compile_error(struct parser_params*, const rb_code_location_t *loc, const char *fmt, ...), 3, 4);
# define compile_error(p, ...) parser_compile_error(p, NULL, __VA_ARGS__)
# define compile_error_with_loc parser_compile_error
#endif

struct RNode_EXITS {
Expand Down Expand Up @@ -7441,23 +7443,6 @@ parser_precise_mbclen(struct parser_params *p, const char *ptr)
}

#ifndef RIPPER
static inline void
parser_show_error_line(struct parser_params *p, const YYLTYPE *yylloc)
{
rb_parser_string_t *str;
int lineno = p->ruby_sourceline;
if (!yylloc) {
return;
}
else if (yylloc->beg_pos.lineno == lineno) {
str = p->lex.lastline;
}
else {
return;
}
ruby_show_error_line(p, p->error_buffer, Qnil, yylloc, lineno, str);
}

static int
parser_yyerror(struct parser_params *p, const rb_code_location_t *yylloc, const char *msg)
{
Expand All @@ -7472,8 +7457,7 @@ parser_yyerror(struct parser_params *p, const rb_code_location_t *yylloc, const
yylloc = 0;
}
#endif
parser_compile_error(p, yylloc, "%s", msg);
parser_show_error_line(p, yylloc);
compile_error_with_loc(p, yylloc, "%s", msg);
return 0;
}

Expand Down Expand Up @@ -7614,11 +7598,6 @@ parser_yyerror0(struct parser_params *p, const char *msg)
ripper_error(p);
return 0;
}

static inline void
parser_show_error_line(struct parser_params *p, const YYLTYPE *yylloc)
{
}
#endif /* !RIPPER */

static int
Expand Down Expand Up @@ -8216,8 +8195,7 @@ tokadd_codepoint(struct parser_params *p, rb_encoding **encp,
rb_encoding *utf8 = rb_utf8_encoding();
if (*encp && utf8 != *encp) {
YYLTYPE loc = RUBY_INIT_YYLLOC();
compile_error(p, "UTF-8 mixed within %s source", rb_enc_name(*encp));
parser_show_error_line(p, &loc);
compile_error_with_loc(p, &loc, "UTF-8 mixed within %s source", rb_enc_name(*encp));
return wide;
}
*encp = utf8;
Expand Down Expand Up @@ -8602,9 +8580,8 @@ regx_options(struct parser_params *p)
if (toklen(p)) {
YYLTYPE loc = RUBY_INIT_YYLLOC();
tokfix(p);
compile_error(p, "unknown regexp option%s - %*s",
toklen(p) > 1 ? "s" : "", toklen(p), tok(p));
parser_show_error_line(p, &loc);
compile_error_with_loc(p, &loc, "unknown regexp option%s - %*s",
toklen(p) > 1 ? "s" : "", toklen(p), tok(p));
}
return options | RE_OPTION_ENCODING(kcode);
}
Expand Down Expand Up @@ -8664,8 +8641,7 @@ parser_mixed_error(struct parser_params *p, rb_encoding *enc1, rb_encoding *enc2
{
YYLTYPE loc = RUBY_INIT_YYLLOC();
const char *n1 = rb_enc_name(enc1), *n2 = rb_enc_name(enc2);
compile_error(p, "%s mixed within %s source", n1, n2);
parser_show_error_line(p, &loc);
compile_error_with_loc(p, &loc, "%s mixed within %s source", n1, n2);
}

static void
Expand Down Expand Up @@ -10290,8 +10266,7 @@ parse_numeric(struct parser_params *p, int c)
trailing_uc:
literal_flush(p, p->lex.pcur - 1);
YYLTYPE loc = RUBY_INIT_YYLLOC();
compile_error(p, "trailing '%c' in number", nondigit);
parser_show_error_line(p, &loc);
compile_error_with_loc(p, &loc, "trailing '%c' in number", nondigit);
}
tokfix(p);
if (is_float) {
Expand Down Expand Up @@ -10616,11 +10591,11 @@ parse_gvar(struct parser_params *p, const enum lex_state_e last_state)
if (!parser_is_identchar(p)) {
YYLTYPE loc = RUBY_INIT_YYLLOC();
if (c == -1 || ISSPACE(c)) {
parser_compile_error(p, &loc, "'$' without identifiers is not allowed as a global variable name");
compile_error_with_loc(p, &loc, "'$' without identifiers is not allowed as a global variable name");
}
else {
pushback(p, c);
parser_compile_error(p, &loc, "'$%c' is not allowed as a global variable name", c);
compile_error_with_loc(p, &loc, "'$%c' is not allowed as a global variable name", c);
}
set_yylval_noname();
return tGVAR;
Expand Down Expand Up @@ -10685,12 +10660,11 @@ parse_atmark(struct parser_params *p, const enum lex_state_e last_state)
pushback(p, c);
RUBY_SET_YYLLOC(loc);
if (result == tIVAR) {
compile_error(p, "'@' without identifiers is not allowed as an instance variable name");
compile_error_with_loc(p, &loc, "'@' without identifiers is not allowed as an instance variable name");
}
else {
compile_error(p, "'@@' without identifiers is not allowed as a class variable name");
compile_error_with_loc(p, &loc, "'@@' without identifiers is not allowed as a class variable name");
}
parser_show_error_line(p, &loc);
set_yylval_noname();
SET_LEX_STATE(EXPR_END);
return result;
Expand All @@ -10699,12 +10673,11 @@ parse_atmark(struct parser_params *p, const enum lex_state_e last_state)
pushback(p, c);
RUBY_SET_YYLLOC(loc);
if (result == tIVAR) {
compile_error(p, "'@%c' is not allowed as an instance variable name", c);
compile_error_with_loc(p, &loc, "'@%c' is not allowed as an instance variable name", c);
}
else {
compile_error(p, "'@@%c' is not allowed as a class variable name", c);
compile_error_with_loc(p, &loc, "'@@%c' is not allowed as a class variable name", c);
}
parser_show_error_line(p, &loc);
set_yylval_noname();
SET_LEX_STATE(EXPR_END);
return result;
Expand Down Expand Up @@ -13203,11 +13176,10 @@ numparam_nested_p(struct parser_params *p)
NODE *inner = local->numparam.inner;
if (outer || inner) {
NODE *used = outer ? outer : inner;
compile_error(p, "numbered parameter is already used in\n"
"%s:%d: %s block here",
p->ruby_sourcefile, nd_line(used),
outer ? "outer" : "inner");
parser_show_error_line(p, &used->nd_loc);
compile_error_with_loc(p, &used->nd_loc, "numbered parameter is already used in\n"
"%s:%d: %s block here",
p->ruby_sourcefile, nd_line(used),
outer ? "outer" : "inner");
return 1;
}
return 0;
Expand All @@ -13218,10 +13190,9 @@ numparam_used_p(struct parser_params *p)
{
NODE *numparam = p->lvtbl->numparam.current;
if (numparam) {
compile_error(p, "numbered parameter is already used in\n"
"%s:%d: current block here",
p->ruby_sourcefile, nd_line(numparam));
parser_show_error_line(p, &numparam->nd_loc);
compile_error_with_loc(p, &numparam->nd_loc, "numbered parameter is already used in\n"
"%s:%d: current block here",
p->ruby_sourcefile, nd_line(numparam));
return 1;
}
return 0;
Expand All @@ -13232,10 +13203,9 @@ it_used_p(struct parser_params *p)
{
NODE *it = p->lvtbl->it;
if (it) {
compile_error(p, "'it' is already used in\n"
"%s:%d: current block here",
p->ruby_sourcefile, nd_line(it));
parser_show_error_line(p, &it->nd_loc);
compile_error_with_loc(p, &it->nd_loc, "'it' is already used in\n"
"%s:%d: current block here",
p->ruby_sourcefile, nd_line(it));
return 1;
}
return 0;
Expand Down

0 comments on commit d66a573

Please sign in to comment.