summaryrefslogtreecommitdiffstatshomepage
path: root/unix-cpy
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-01-15 21:23:31 +0000
committerDamien George <damien.p.george@gmail.com>2014-01-15 21:23:31 +0000
commit9528cd66d7c94d7376884a53c2080b29e9bc3a0a (patch)
tree7c3ad5d4af03b7760f7c3be4ae1a1e9555113324 /unix-cpy
parent24224d7c72e1d6572ef0d24f08eb882dcac8dc50 (diff)
downloadmicropython-9528cd66d7c94d7376884a53c2080b29e9bc3a0a.tar.gz
micropython-9528cd66d7c94d7376884a53c2080b29e9bc3a0a.zip
Convert parse errors to exceptions.
Parser no longer prints an error, but instead returns an exception ID and message.
Diffstat (limited to 'unix-cpy')
-rw-r--r--unix-cpy/main.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/unix-cpy/main.c b/unix-cpy/main.c
index ea85e32757..7d56ceaf34 100644
--- a/unix-cpy/main.c
+++ b/unix-cpy/main.c
@@ -27,16 +27,29 @@ void do_file(const char *file) {
mp_lexer_free(lex);
} else {
- // compile
+ // parse
+ 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);
+
+ if (pn == MP_PARSE_NODE_NULL) {
+ // parse error
+ mp_lexer_show_error_pythonic_prefix(lex);
+ printf("%s: %s\n", qstr_str(parse_exc_id), parse_exc_msg);
+ mp_lexer_free(lex);
+ return;
+ }
- mp_parse_node_t pn = mp_parse(lex, MP_PARSE_FILE_INPUT);
mp_lexer_free(lex);
if (pn != MP_PARSE_NODE_NULL) {
//printf("----------------\n");
//parse_node_show(pn, 0);
//printf("----------------\n");
+
+ // compile
mp_obj_t module_fun = mp_compile(pn, false);
+
//printf("----------------\n");
if (module_fun == mp_const_none) {