From 9528cd66d7c94d7376884a53c2080b29e9bc3a0a Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 15 Jan 2014 21:23:31 +0000 Subject: Convert parse errors to exceptions. Parser no longer prints an error, but instead returns an exception ID and message. --- unix-cpy/main.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'unix-cpy/main.c') diff --git a/unix-cpy/main.c b/unix-cpy/main.c index ea85e3275..7d56ceaf3 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) { -- cgit v1.2.3