Skip to content

Remove redundant artificial rules and functions for them in parser.c file #124889

@efimov-mikhail

Description

@efimov-mikhail

Feature or enhancement

Proposal:

It seems like PEG parser produces more than one artificial rule for the same grammar rule.
For example, on each gather rule (','.NAME+) in Grammar/python.gram a function '_gather_N_rule' will be generated.
But only one implementation of such function makes sense, others are just redundant.

Some simple changes in Tools/peg_generator/pegen/c_generator.py file should be made.
We can save artificial rules in cache by Node string representation as a key instead of Node object itself.
Total count of artificial rules can be lowered from 283 to 170 with this change, size of parser.c file can be lowered from 1.5 megabytes to 1.3 megabytes without any cost.

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions