summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorPablo Galindo Salgado <Pablogsal@gmail.com>2021-09-05 13:58:52 (GMT)
committerGitHub <noreply@github.com>2021-09-05 13:58:52 (GMT)
commitb01fd533fef78b088674bad73267b89bea98e904 (patch)
treede68ee97cc624f412d3e357db0d45eb98227207d /Lib
parent28264269de9ff88d9ee7110fc56ac2d2db275bec (diff)
downloadcpython-b01fd533fef78b088674bad73267b89bea98e904.zip
cpython-b01fd533fef78b088674bad73267b89bea98e904.tar.gz
cpython-b01fd533fef78b088674bad73267b89bea98e904.tar.bz2
Extract visitors from the grammar nodes and call makers in the peg generator (GH-28172)
Simplify the peg generator logic by extracting as much visitors as possible to disentangle the flow and separate concerns.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_peg_generator/test_pegen.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/Lib/test/test_peg_generator/test_pegen.py b/Lib/test/test_peg_generator/test_pegen.py
index 71b0fdc..99c75f0 100644
--- a/Lib/test/test_peg_generator/test_pegen.py
+++ b/Lib/test/test_peg_generator/test_pegen.py
@@ -15,6 +15,7 @@ with test_tools.imports_under_tool("peg_generator"):
from pegen.grammar import GrammarVisitor, GrammarError, Grammar
from pegen.grammar_visualizer import ASTGrammarPrinter
from pegen.parser import Parser
+ from pegen.parser_generator import compute_nullables, compute_left_recursives
from pegen.python_generator import PythonParserGenerator
@@ -502,11 +503,10 @@ class TestPegen(unittest.TestCase):
sign: ['-' | '+']
"""
grammar: Grammar = parse_string(grammar_source, GrammarParser)
- out = io.StringIO()
- genr = PythonParserGenerator(grammar, out)
rules = grammar.rules
- self.assertFalse(rules["start"].nullable) # Not None!
- self.assertTrue(rules["sign"].nullable)
+ nullables = compute_nullables(rules)
+ self.assertNotIn(rules["start"], nullables) # Not None!
+ self.assertIn(rules["sign"], nullables)
def test_advanced_left_recursive(self) -> None:
grammar_source = """
@@ -514,11 +514,11 @@ class TestPegen(unittest.TestCase):
sign: ['-']
"""
grammar: Grammar = parse_string(grammar_source, GrammarParser)
- out = io.StringIO()
- genr = PythonParserGenerator(grammar, out)
rules = grammar.rules
- self.assertFalse(rules["start"].nullable) # Not None!
- self.assertTrue(rules["sign"].nullable)
+ nullables = compute_nullables(rules)
+ compute_left_recursives(rules)
+ self.assertNotIn(rules["start"], nullables) # Not None!
+ self.assertIn(rules["sign"], nullables)
self.assertTrue(rules["start"].left_recursive)
self.assertFalse(rules["sign"].left_recursive)