summaryrefslogtreecommitdiffstats
path: root/Tools/peg_generator/pegen
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2020-04-27 17:02:07 (GMT)
committerGitHub <noreply@github.com>2020-04-27 17:02:07 (GMT)
commit2b74c835a7280840a853e3a9aaeb83758b13a458 (patch)
treea8f64047d5872571e12d6c256bbc54a9551f8bb6 /Tools/peg_generator/pegen
parent9adccc1384568f4d46e37f698cb3e3a4f6ca0252 (diff)
downloadcpython-2b74c835a7280840a853e3a9aaeb83758b13a458.zip
cpython-2b74c835a7280840a853e3a9aaeb83758b13a458.tar.gz
cpython-2b74c835a7280840a853e3a9aaeb83758b13a458.tar.bz2
bpo-40334: Support CO_FUTURE_BARRY_AS_BDFL in the new parser (GH-19721)
This commit also allows to pass flags to the new parser in all interfaces and fixes a bug in the parser generator that was causing to inline rules with actions, making them disappear.
Diffstat (limited to 'Tools/peg_generator/pegen')
-rw-r--r--Tools/peg_generator/pegen/c_generator.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/Tools/peg_generator/pegen/c_generator.py b/Tools/peg_generator/pegen/c_generator.py
index 5b9d804..6c4b8f1 100644
--- a/Tools/peg_generator/pegen/c_generator.py
+++ b/Tools/peg_generator/pegen/c_generator.py
@@ -73,9 +73,17 @@ class CCallMakerVisitor(GrammarVisitor):
return "literal", f"_PyPegen_expect_token(p, {type})"
def visit_Rhs(self, node: Rhs) -> Tuple[Optional[str], str]:
+ def can_we_inline(node):
+ if len(node.alts) != 1 or len(node.alts[0].items) != 1:
+ return False
+ # If the alternative has an action we cannot inline
+ if getattr(node.alts[0], "action", None) is not None:
+ return False
+ return True
+
if node in self.cache:
return self.cache[node]
- if len(node.alts) == 1 and len(node.alts[0].items) == 1:
+ if can_we_inline(node):
self.cache[node] = self.visit(node.alts[0].items[0])
else:
name = self.gen.name_node(node)