Skip to content

Catch parse errors in C #3248

@dabroz

Description

@dabroz

When reloading Ruby scripts, currently I need to parse them twice to be able to catch parse errors:

mrbc_context* context = mrbc_context_new(mrb);
mrbc_filename(mrb, context, path);
parser_state* parser = mrb_parse_nstring(mrb, data, length, context);
int num_errors = parser->nerr;
mrb_parser_free(parser);
if (num_errors > 0)
{ ... }
mrb_load_nstring_cxt(mrb, data, length, context);

all because mrb_load_nstring_cxt is defined as

MRB_API mrb_value
mrb_load_nstring_cxt(mrb_state *mrb, const char *s, int len, mrbc_context *c)
{
  return load_exec(mrb, mrb_parse_nstring(mrb, s, len, c), c);
}

and load_exec in not in the mruby API.

Is there a different way to do it without parsing the file twice, or could we promote load_exec to API?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions