mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-124889: Remove redundant artificial rules in PEG parser (#124893)
Cache in C PEG-generator reworked: we save artificial rules in cache by Node string representation as a key instead of Node object itself. As a result total count of artificial rules in parsers.c is lowered from 283 to 170. More natural number ordering is used for the names of artificial rules. Auxiliary method CCallMakerVisitor._generate_artificial_rule_call is added. Its purpose is abstracting work with artificial rules cache. Explicit using of "is_repeat1" kwarg is added to visit_Repeat0 and visit_Repeat1 methods. Its slightly improve code readabitily.
This commit is contained in:
parent
e6dd71da3a
commit
1f9025a4e7
3 changed files with 4635 additions and 11473 deletions
|
@ -184,8 +184,6 @@ class ParserGenerator:
|
|||
return name
|
||||
|
||||
def artificial_rule_from_gather(self, node: Gather) -> str:
|
||||
self.counter += 1
|
||||
name = f"_gather_{self.counter}"
|
||||
self.counter += 1
|
||||
extra_function_name = f"_loop0_{self.counter}"
|
||||
extra_function_alt = Alt(
|
||||
|
@ -197,6 +195,8 @@ class ParserGenerator:
|
|||
None,
|
||||
Rhs([extra_function_alt]),
|
||||
)
|
||||
self.counter += 1
|
||||
name = f"_gather_{self.counter}"
|
||||
alt = Alt(
|
||||
[NamedItem("elem", node.node), NamedItem("seq", NameLeaf(extra_function_name))],
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue