]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
A better hack for IndentationError
authorGuido van Rossum <guido@python.org>
Wed, 23 Jan 2019 19:58:41 +0000 (11:58 -0800)
committerGuido van Rossum <guido@python.org>
Wed, 23 Jan 2019 19:58:41 +0000 (11:58 -0800)
This is fragile -- it just substitutes 'suite' when 'func_body_suite'
is found but type comments are off.

Parser/parser.c
Parser/parsetok.c

index a9916d392aabb28fa4ce0401e8d87aefc75fce5b..b082afca27b6240e22666e970162dbc1f741df10 100644 (file)
@@ -12,6 +12,7 @@
 #include "node.h"
 #include "parser.h"
 #include "errcode.h"
+#include "graminit.h"
 
 
 #ifdef Py_DEBUG
@@ -260,7 +261,12 @@ 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)) {
+                        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 +274,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;
                 }
 
index c543353ecd5caa1ac8ec00240ea8a6d20529a65a..6fcf91570176fb25cb561f789a8826d286882a7b 100644 (file)
@@ -245,6 +245,8 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret,
 #ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD
     if (*flags & PyPARSE_BARRY_AS_BDFL)
         ps->p_flags |= CO_FUTURE_BARRY_AS_BDFL;
+    if (*flags & PyPARSE_TYPE_COMMENTS)
+        ps->p_flags |= PyCF_TYPE_COMMENTS;
 #endif
 
     for (;;) {