Author pablogsal
Recipients gvanrossum, lys.nikolaou, pablogsal
Date 2020-05-17.16:04:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1589731489.25.0.151931382723.issue40661@roundup.psfhosted.org>
In-reply-to
Content
I think we may need to test for the error indicator (and maybe PyErr_Ocurred for safety) before every alternative. Something like:

diff --git a/Tools/peg_generator/pegen/c_generator.py b/Tools/peg_generator/pegen/c_generator.py
index 8f9972bb41..61cb694628 100644
--- a/Tools/peg_generator/pegen/c_generator.py
+++ b/Tools/peg_generator/pegen/c_generator.py
@@ -468,10 +468,6 @@ class CParserGenerator(ParserGenerator, GrammarVisitor):
         memoize = self._should_memoize(node)

         with self.indent():
-            self.print("if (p->error_indicator) {")
-            with self.indent():
-                self.print("return NULL;")
-            self.print("}")
             self.print(f"{result_type} _res = NULL;")
             if memoize:
                 self.print(f"if (_PyPegen_is_memoized(p, {node.name}_type, &_res))")
@@ -685,6 +681,12 @@ class CParserGenerator(ParserGenerator, GrammarVisitor):
     def visit_Alt(
         self, node: Alt, is_loop: bool, is_gather: bool, rulename: Optional[str]
     ) -> None:
+        self.print("if (p->error_indicator == 1 || PyErr_Occurred()) {")
+        with self.indent():
+            self.print("p->error_indicator = 1;")
+            self.print("return NULL;")
+        self.print("}")
+
         self.print(f"{{ // {node}")
         with self.indent():
             # Prepare variable declarations for the alternative
History
Date User Action Args
2020-05-17 16:04:49pablogsalsetrecipients: + pablogsal, gvanrossum, lys.nikolaou
2020-05-17 16:04:49pablogsalsetmessageid: <1589731489.25.0.151931382723.issue40661@roundup.psfhosted.org>
2020-05-17 16:04:49pablogsallinkissue40661 messages
2020-05-17 16:04:49pablogsalcreate