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:
efimov-mikhail 2024-10-03 15:58:56 +03:00 committed by GitHub
parent e6dd71da3a
commit 1f9025a4e7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 4635 additions and 11473 deletions

View file

@ -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))],
)