summaryrefslogtreecommitdiffstats
path: root/Parser/tokenizer.c
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2015-05-18 16:50:52 (GMT)
committerYury Selivanov <yselivanov@sprymix.com>2015-05-18 16:50:52 (GMT)
commit8085b80c187865e6feab652465d0f6742b9083a1 (patch)
tree08000252dd137273867ac5e61710fa8c64fdc159 /Parser/tokenizer.c
parenta2c145c2f3def66a39295422a3d99b0b357978d5 (diff)
downloadcpython-8085b80c187865e6feab652465d0f6742b9083a1.zip
cpython-8085b80c187865e6feab652465d0f6742b9083a1.tar.gz
cpython-8085b80c187865e6feab652465d0f6742b9083a1.tar.bz2
Issue 24226: Fix parsing of many sequential one-line 'def' statements.
Diffstat (limited to 'Parser/tokenizer.c')
-rw-r--r--Parser/tokenizer.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c
index 798758d..d4476ae 100644
--- a/Parser/tokenizer.c
+++ b/Parser/tokenizer.c
@@ -1501,17 +1501,20 @@ tok_get(struct tok_state *tok, char **p_start, char **p_end)
tok_len = tok->cur - tok->start;
if (tok_len == 3 && memcmp(tok->start, "def", 3) == 0) {
-
- if (tok->def + 1 >= MAXINDENT) {
- tok->done = E_TOODEEP;
- tok->cur = tok->inp;
- return ERRORTOKEN;
- }
-
if (tok->def && tok->deftypestack[tok->def] == 3) {
tok->deftypestack[tok->def] = 2;
}
- else {
+ else if (tok->defstack[tok->def] < tok->indent) {
+ /* We advance defs stack only when we see "def" *and*
+ the indentation level was increased relative to the
+ previous "def". */
+
+ if (tok->def + 1 >= MAXINDENT) {
+ tok->done = E_TOODEEP;
+ tok->cur = tok->inp;
+ return ERRORTOKEN;
+ }
+
tok->def++;
tok->defstack[tok->def] = tok->indent;
tok->deftypestack[tok->def] = 1;
@@ -1528,6 +1531,12 @@ tok_get(struct tok_state *tok, char **p_start, char **p_end)
ahead_tok.cur - ahead_tok.start == 3 &&
memcmp(ahead_tok.start, "def", 3) == 0) {
+ if (tok->def + 1 >= MAXINDENT) {
+ tok->done = E_TOODEEP;
+ tok->cur = tok->inp;
+ return ERRORTOKEN;
+ }
+
tok->def++;
tok->defstack[tok->def] = tok->indent;
tok->deftypestack[tok->def] = 3;