summaryrefslogtreecommitdiffstats
path: root/Parser/pegen.h
diff options
context:
space:
mode:
authorLysandros Nikolaou <lisandrosnik@gmail.com>2020-06-18 23:10:43 (GMT)
committerGitHub <noreply@github.com>2020-06-18 23:10:43 (GMT)
commit01ece63d42b830df106948db0aefa6c1ba24416a (patch)
tree0bb2f932d4604c12507dd79b12b06d4dafc46e8b /Parser/pegen.h
parentd906f0ec1a5f4ec29a4de74240acf43139886514 (diff)
downloadcpython-01ece63d42b830df106948db0aefa6c1ba24416a.zip
cpython-01ece63d42b830df106948db0aefa6c1ba24416a.tar.gz
cpython-01ece63d42b830df106948db0aefa6c1ba24416a.tar.bz2
bpo-40334: Produce better error messages on invalid targets (GH-20106)
The following error messages get produced: - `cannot delete ...` for invalid `del` targets - `... is an illegal 'for' target` for invalid targets in for statements - `... is an illegal 'with' target` for invalid targets in with statements Additionally, a few `cut`s were added in various places before the invocation of the `invalid_*` rule, in order to speed things up. Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Diffstat (limited to 'Parser/pegen.h')
-rw-r--r--Parser/pegen.h12
1 files changed, 11 insertions, 1 deletions
diff --git a/Parser/pegen.h b/Parser/pegen.h
index c4ff8c9..4316807 100644
--- a/Parser/pegen.h
+++ b/Parser/pegen.h
@@ -263,11 +263,21 @@ int _PyPegen_check_barry_as_flufl(Parser *);
mod_ty _PyPegen_make_module(Parser *, asdl_seq *);
// Error reporting helpers
-expr_ty _PyPegen_get_invalid_target(expr_ty e);
+typedef enum {
+ STAR_TARGETS,
+ DEL_TARGETS,
+ FOR_TARGETS
+} TARGETS_TYPE;
+expr_ty _PyPegen_get_invalid_target(expr_ty e, TARGETS_TYPE targets_type);
+#define GET_INVALID_TARGET(e) (expr_ty)CHECK(_PyPegen_get_invalid_target(e, STAR_TARGETS))
+#define GET_INVALID_DEL_TARGET(e) (expr_ty)CHECK_NULL_ALLOWED(_PyPegen_get_invalid_target(e, DEL_TARGETS))
+#define GET_INVALID_FOR_TARGET(e) (expr_ty)CHECK_NULL_ALLOWED(_PyPegen_get_invalid_target(e, FOR_TARGETS))
+
void *_PyPegen_arguments_parsing_error(Parser *, expr_ty);
void *_PyPegen_nonparen_genexp_in_call(Parser *p, expr_ty args);
+// Generated function in parse.c - function definition in python.gram
void *_PyPegen_parse(Parser *);
#endif