summaryrefslogtreecommitdiffstats
path: root/Parser/pegen.c
diff options
context:
space:
mode:
authorPablo Galindo Salgado <Pablogsal@gmail.com>2022-02-08 11:54:37 (GMT)
committerGitHub <noreply@github.com>2022-02-08 11:54:37 (GMT)
commit69e10976b2e7682c6d57f4272932ebc19f8e8859 (patch)
tree58a1716aab40f00e50fcd6e8abea7ae294e960c0 /Parser/pegen.c
parent25db2b361beb865192a3424830ddcb0ae4b17318 (diff)
downloadcpython-69e10976b2e7682c6d57f4272932ebc19f8e8859.zip
cpython-69e10976b2e7682c6d57f4272932ebc19f8e8859.tar.gz
cpython-69e10976b2e7682c6d57f4272932ebc19f8e8859.tar.bz2
bpo-46521: Fix codeop to use a new partial-input mode of the parser (GH-31010)
Diffstat (limited to 'Parser/pegen.c')
-rw-r--r--Parser/pegen.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/Parser/pegen.c b/Parser/pegen.c
index 470c2cb..6adde84 100644
--- a/Parser/pegen.c
+++ b/Parser/pegen.c
@@ -726,6 +726,9 @@ compute_parser_flags(PyCompilerFlags *flags)
if ((flags->cf_flags & PyCF_ONLY_AST) && flags->cf_feature_version < 7) {
parser_flags |= PyPARSE_ASYNC_HACKS;
}
+ if (flags->cf_flags & PyCF_ALLOW_INCOMPLETE_INPUT) {
+ parser_flags |= PyPARSE_ALLOW_INCOMPLETE_INPUT;
+ }
return parser_flags;
}
@@ -811,16 +814,26 @@ reset_parser_state_for_error_pass(Parser *p)
p->tok->interactive_underflow = IUNDERFLOW_STOP;
}
+static inline int
+_is_end_of_source(Parser *p) {
+ int err = p->tok->done;
+ return err == E_EOF || err == E_EOFS || err == E_EOLS;
+}
+
void *
_PyPegen_run_parser(Parser *p)
{
void *res = _PyPegen_parse(p);
assert(p->level == 0);
if (res == NULL) {
+ if ((p->flags & PyPARSE_ALLOW_INCOMPLETE_INPUT) && _is_end_of_source(p)) {
+ PyErr_Clear();
+ return RAISE_SYNTAX_ERROR("incomplete input");
+ }
if (PyErr_Occurred() && !PyErr_ExceptionMatches(PyExc_SyntaxError)) {
return NULL;
}
- // Make a second parser pass. In this pass we activate heavier and slower checks
+ // Make a second parser pass. In this pass we activate heavier and slower checks
// to produce better error messages and more complete diagnostics. Extra "invalid_*"
// rules will be active during parsing.
Token *last_token = p->tokens[p->fill - 1];