py: Protect mp_parse and mp_compile with nlr push/pop block.

To enable parsing constants more efficiently, mp_parse should be allowed
to raise an exception, and mp_compile can already raise a MemoryError.
So these functions need to be protected by an nlr push/pop block.

This patch adds that feature in all places.  This allows to simplify how
mp_parse and mp_compile are called: they now raise an exception if they
have an error and so explicit checking is not needed anymore.
This commit is contained in:
Damien George
2015-02-07 18:33:58 +00:00
parent e1e359ff59
commit 0bfc7638ba
17 changed files with 97 additions and 365 deletions

View File

@@ -90,14 +90,8 @@ typedef enum {
MP_PARSE_EVAL_INPUT,
} mp_parse_input_kind_t;
typedef enum {
MP_PARSE_ERROR_MEMORY,
MP_PARSE_ERROR_UNEXPECTED_INDENT,
MP_PARSE_ERROR_UNMATCHED_UNINDENT,
MP_PARSE_ERROR_INVALID_SYNTAX,
} mp_parse_error_kind_t;
// returns MP_PARSE_NODE_NULL on error, and then parse_error_kind_out is valid
mp_parse_node_t mp_parse(struct _mp_lexer_t *lex, mp_parse_input_kind_t input_kind, mp_parse_error_kind_t *parse_error_kind_out);
// the parser will raise an exception if an error occurred
// the parser will free the lexer before it returns
mp_parse_node_t mp_parse(struct _mp_lexer_t *lex, mp_parse_input_kind_t input_kind);
#endif // __MICROPY_INCLUDED_PY_PARSE_H__