diff options
author | Damien <damien.p.george@gmail.com> | 2013-10-09 15:09:52 +0100 |
---|---|---|
committer | Damien <damien.p.george@gmail.com> | 2013-10-09 15:09:52 +0100 |
commit | 91d387de7df9e19bb5b00e6ad4c94790eb3422e3 (patch) | |
tree | 1af3603b73c8ab1b2dd917f1654548fc0f1aaafb /py/parse.c | |
parent | ff8ed77cc12f707b6b0eb78ccc02bafb20bdf248 (diff) | |
download | micropython-91d387de7df9e19bb5b00e6ad4c94790eb3422e3.tar.gz micropython-91d387de7df9e19bb5b00e6ad4c94790eb3422e3.zip |
Improve indent/dedent error checking and reporting.
Diffstat (limited to 'py/parse.c')
-rw-r--r-- | py/parse.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/py/parse.c b/py/parse.c index 5eb4b27dbf..124d00ffeb 100644 --- a/py/parse.c +++ b/py/parse.c @@ -545,10 +545,12 @@ py_parse_node_t py_parse(py_lexer_t *lex, int wanted_rule) { assert(0); } } + + // check we are at the end of the token stream if (!py_lexer_is_kind(lex, PY_TOKEN_END)) { - py_lexer_show_error(lex, "unexpected token at end:"); - py_token_show(py_lexer_cur(lex)); + goto syntax_error; } + //printf("--------------\n"); //result_stack_show(parser); assert(parser->result_stack_top == 1); @@ -557,10 +559,16 @@ py_parse_node_t py_parse(py_lexer_t *lex, int wanted_rule) { return parser->result_stack[0]; syntax_error: - py_lexer_show_error(lex, "syntax error:"); + if (py_lexer_is_kind(lex, PY_TOKEN_INDENT)) { + py_lexer_show_error_pythonic(lex, "IndentationError: unexpected indent"); + } else if (py_lexer_is_kind(lex, PY_TOKEN_DEDENT_MISMATCH)) { + py_lexer_show_error_pythonic(lex, "IndentationError: unindent does not match any outer indentation level"); + } else { + py_lexer_show_error_pythonic(lex, "syntax error:"); #ifdef USE_RULE_NAME - py_lexer_show_error(lex, rule->rule_name); + py_lexer_show_error(lex, rule->rule_name); #endif - py_token_show(py_lexer_cur(lex)); + py_token_show(py_lexer_cur(lex)); + } return PY_PARSE_NODE_NULL; } |