mirror of
https://github.com/micropython/micropython.git
synced 2026-01-05 03:30:14 +01:00
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:
12
py/parse.h
12
py/parse.h
@@ -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__
|
||||
|
||||
Reference in New Issue
Block a user