summaryrefslogtreecommitdiffstats
path: root/Parser/pegen.c
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-05-22 22:23:26 (GMT)
committerGitHub <noreply@github.com>2021-05-22 22:23:26 (GMT)
commit1fb6b9e91d8685f7eca0fc33402589c65723bd94 (patch)
treec5900d8a81b1614306fb3e407fbf0026dc15d1f1 /Parser/pegen.c
parent413df57968e4d612f87722bb8454a66357f84839 (diff)
downloadcpython-1fb6b9e91d8685f7eca0fc33402589c65723bd94.zip
cpython-1fb6b9e91d8685f7eca0fc33402589c65723bd94.tar.gz
cpython-1fb6b9e91d8685f7eca0fc33402589c65723bd94.tar.bz2
bpo-44201: Avoid side effects of "invalid_*" rules in the REPL (GH-26298) (GH-26313)
When the parser does a second pass to check for errors, these rules can have some small side-effects as they may advance the parser more than the point reached in the first pass. This can cause the tokenizer to ask for extra tokens in interactive mode causing the tokenizer to show the prompt instead of failing instantly. To avoid this, add a new mode to the tokenizer that is activated in the second pass and deactivates asking for new tokens when the interactive line is finished. As the parsing should have reached the last line in the first pass, the second pass should not need to ask for more tokens. (cherry picked from commit bd7476dae337e905e7b1bbf33ddb96cc270fdc84) Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Diffstat (limited to 'Parser/pegen.c')
-rw-r--r--Parser/pegen.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/Parser/pegen.c b/Parser/pegen.c
index 3c25e4d..548a647 100644
--- a/Parser/pegen.c
+++ b/Parser/pegen.c
@@ -1234,6 +1234,9 @@ reset_parser_state(Parser *p)
}
p->mark = 0;
p->call_invalid_rules = 1;
+ // Don't try to get extra tokens in interactive mode when trying to
+ // raise specialized errors in the second pass.
+ p->tok->interactive_underflow = IUNDERFLOW_STOP;
}
static int