diff options
author | Guido van Rossum <guido@python.org> | 2019-01-31 11:40:27 (GMT) |
---|---|---|
committer | Ćukasz Langa <lukasz@langa.pl> | 2019-01-31 11:40:27 (GMT) |
commit | dcfcd146f8e6fc5c2fc16a4c192a0c5f5ca8c53c (patch) | |
tree | 07829c4f286194d0e3d08151a26ef1f3494a849b /Parser/parser.c | |
parent | d97daebfa69b4df95231bcae4123eacad6a48d14 (diff) | |
download | cpython-dcfcd146f8e6fc5c2fc16a4c192a0c5f5ca8c53c.zip cpython-dcfcd146f8e6fc5c2fc16a4c192a0c5f5ca8c53c.tar.gz cpython-dcfcd146f8e6fc5c2fc16a4c192a0c5f5ca8c53c.tar.bz2 |
bpo-35766: Merge typed_ast back into CPython (GH-11645)
Diffstat (limited to 'Parser/parser.c')
-rw-r--r-- | Parser/parser.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/Parser/parser.c b/Parser/parser.c index a9916d3..fa4a8f0 100644 --- a/Parser/parser.c +++ b/Parser/parser.c @@ -12,6 +12,7 @@ #include "node.h" #include "parser.h" #include "errcode.h" +#include "graminit.h" #ifdef Py_DEBUG @@ -260,7 +261,15 @@ PyParser_AddToken(parser_state *ps, int type, char *str, /* Push non-terminal */ int nt = (x >> 8) + NT_OFFSET; int arrow = x & ((1<<7)-1); - dfa *d1 = PyGrammar_FindDFA( + dfa *d1; + if (nt == func_body_suite && !(ps->p_flags & PyCF_TYPE_COMMENTS)) { + /* When parsing type comments is not requested, + we can provide better errors about bad indentation + by using 'suite' for the body of a funcdef */ + D(printf(" [switch func_body_suite to suite]")); + nt = suite; + } + d1 = PyGrammar_FindDFA( ps->p_grammar, nt); if ((err = push(&ps->p_stack, nt, d1, arrow, lineno, col_offset, @@ -268,7 +277,7 @@ PyParser_AddToken(parser_state *ps, int type, char *str, D(printf(" MemError: push\n")); return err; } - D(printf(" Push ...\n")); + D(printf(" Push '%s'\n", d1->d_name)); continue; } |