New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch parse errors in C #3248

Closed
dabroz opened this Issue Nov 14, 2016 · 0 comments

Comments

Projects
None yet
1 participant
@dabroz
Contributor

dabroz commented Nov 14, 2016

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?

dabroz added a commit to dabroz/mruby that referenced this issue Dec 7, 2016

dabroz added a commit to dabroz/mruby that referenced this issue Dec 7, 2016

@matz matz closed this in #3331 Dec 8, 2016

matz added a commit that referenced this issue Dec 8, 2016

Merge pull request #3331 from dabroz/feature-load-exec
Promote load_exec to mruby API as mrb_load_exec (fixes #3248)

matz added a commit that referenced this issue Jun 28, 2017

Revert "Make `mrb_load_exec` a static function."
This reverts commit 7944d9a.
Because it voids #3248 and #3331. But we should add better way
to check whether compile errors occur without duplicated callings.

matz added a commit that referenced this issue Jun 28, 2017

Provide better way to check compile errors.
Now you can just call `mrb_load_*` functions then check
`context->parser_nerr > 0` if the return value is `undef`,
instead of calling `mrb_parse_*` functions independently.
ref #3248 #3331
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment