diff options
author | Damien George <damien.p.george@gmail.com> | 2014-02-15 16:10:44 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-02-15 16:10:44 +0000 |
commit | c5966128c7c8a768f6726f299d85d5daef6bed48 (patch) | |
tree | fea6913ae43d722078a837d8c7fd9a1e459f3891 /py/parse.c | |
parent | a71c83a1d1aeca1d81d7c673929f8e836dec131e (diff) |
Implement proper exception type hierarchy.
Each built-in exception is now a type, with base type BaseException.
C exceptions are created by passing a pointer to the exception type to
make an instance of. When raising an exception from the VM, an
instance is created automatically if an exception type is raised (as
opposed to an exception instance).
Exception matching (RT_BINARY_OP_EXCEPTION_MATCH) is now proper.
Handling of parse error changed to match new exceptions.
mp_const_type renamed to mp_type_type for consistency.
Diffstat (limited to 'py/parse.c')
-rw-r--r-- | py/parse.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/py/parse.c b/py/parse.c index d2e892b39..bbab19d35 100644 --- a/py/parse.c +++ b/py/parse.c @@ -302,7 +302,7 @@ STATIC void push_result_rule(parser_t *parser, int src_line, const rule_t *rule, push_result_node(parser, (mp_parse_node_t)pn); } -mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind, qstr *exc_id_out, const char **exc_msg_out) { +mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind, mp_parse_error_kind_t *parse_error_kind_out) { // allocate memory for the parser and its stacks @@ -634,19 +634,18 @@ finished: syntax_error: if (mp_lexer_is_kind(lex, MP_TOKEN_INDENT)) { - *exc_id_out = MP_QSTR_IndentationError; - *exc_msg_out = "unexpected indent"; + *parse_error_kind_out = MP_PARSE_ERROR_UNEXPECTED_INDENT; } else if (mp_lexer_is_kind(lex, MP_TOKEN_DEDENT_MISMATCH)) { - *exc_id_out = MP_QSTR_IndentationError; - *exc_msg_out = "unindent does not match any outer indentation level"; + *parse_error_kind_out = MP_PARSE_ERROR_UNMATCHED_UNINDENT; } else { - *exc_id_out = MP_QSTR_SyntaxError; - *exc_msg_out = "invalid syntax"; + *parse_error_kind_out = MP_PARSE_ERROR_INVALID_SYNTAX; #ifdef USE_RULE_NAME // debugging: print the rule name that failed and the token - mp_lexer_show_error_pythonic(lex, rule->rule_name); + printf("rule: %s\n", rule->rule_name); +#if MICROPY_DEBUG_PRINTERS mp_token_show(mp_lexer_cur(lex)); #endif +#endif } result = MP_PARSE_NODE_NULL; goto finished; |