diff options
author | Damien George <damien.p.george@gmail.com> | 2014-01-15 21:23:31 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-01-15 21:23:31 +0000 |
commit | 9528cd66d7c94d7376884a53c2080b29e9bc3a0a (patch) | |
tree | 7c3ad5d4af03b7760f7c3be4ae1a1e9555113324 /py/builtinimport.c | |
parent | 24224d7c72e1d6572ef0d24f08eb882dcac8dc50 (diff) |
Convert parse errors to exceptions.
Parser no longer prints an error, but instead returns an exception ID
and message.
Diffstat (limited to 'py/builtinimport.c')
-rw-r--r-- | py/builtinimport.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/py/builtinimport.c b/py/builtinimport.c index 33576e3f0..2eca36fbc 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -48,16 +48,19 @@ mp_obj_t mp_builtin___import__(int n_args, mp_obj_t *args) { rt_globals_set(mp_obj_module_get_globals(module_obj)); // parse the imported script - mp_parse_node_t pn = mp_parse(lex, MP_PARSE_FILE_INPUT); + qstr parse_exc_id; + const char *parse_exc_msg; + mp_parse_node_t pn = mp_parse(lex, MP_PARSE_FILE_INPUT, &parse_exc_id, &parse_exc_msg); mp_lexer_free(lex); if (pn == MP_PARSE_NODE_NULL) { - // TODO handle parse error correctly + // parse error; clean up and raise exception rt_locals_set(old_locals); rt_globals_set(old_globals); - return mp_const_none; + nlr_jump(mp_obj_new_exception_msg(parse_exc_id, parse_exc_msg)); } + // compile the imported script mp_obj_t module_fun = mp_compile(pn, false); if (module_fun == mp_const_none) { |