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 cb19709 commit 2e40252
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -7729,6 +7729,32 @@ e_option_supplied(struct parser_params *p)
#ifndef RIPPER
static NODE *parser_append_options(struct parser_params *p, NODE *node);

static void
append_error_message_to_str(struct parser_params *p, VALUE str, const char *file, rb_parser_error_t *error)
{
/* Ref: err_vcatf */
rb_parser_string_t *msg = error->message;

if (file) {
int line = error->lineno;

rb_str_cat2(str, file);
if (line) rb_str_catf(str, ":%d", line);
rb_str_cat2(str, ": ");
}
rb_str_cat(str, PARSER_STRING_PTR(msg), PARSER_STRING_LEN(msg));
}

static void
append_error_message(struct parser_params *p, rb_parser_errors_t *errors, VALUE str)
{
const char *fn = NIL_P(p->ruby_sourcefile_string) ? NULL : RSTRING_PTR(p->ruby_sourcefile_string);

for (long i = 0; i < errors->errors->len; i++) {
append_error_message_to_str(p, str, fn, errors->errors->data[i]);
}
}

static VALUE
yycompile0(VALUE arg)
{
Expand Down Expand Up @@ -7763,13 +7789,12 @@ yycompile0(VALUE arg)
if (n || p->error_p) {
VALUE exc = p->error_buffer;
if (!exc) {
if (p->errors.errors->len) {
VALUE mesg;
exc = rb_syntax_error_with_path(0, p->ruby_sourcefile_string, &mesg, p->enc);
}
else {
exc = syntax_error_new();
}
exc = syntax_error_new();
}
else {
VALUE mesg;
exc = rb_syntax_error_with_path(Qnil, p->ruby_sourcefile_string, &mesg, p->enc);
append_error_message(p, &p->errors, mesg);
}
if (!p->error_tolerant) {
rb_set_errinfo(exc);
Expand Down

0 comments on commit 2e40252

Please sign in to comment.