Skip to content

gh-153195: Allow splitting the PEG grammar into several files - #159917

Merged
lysnikolaou merged 3 commits into
python:mainfrom
lysnikolaou:pegen-include-grammar
Oct 23, 2026
Merged

lysnikolaou merged 3 commits into
python:mainfrom
lysnikolaou:pegen-include-grammar

Conversation

@lysnikolaou

@lysnikolaou lysnikolaou commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Add an @include meta to pegen: the rules of an included grammar file are appended to the including file's rules. The C generator emits the rules of each included file into a separate C file next to the main output.

Use it to move the invalid_* rules from Grammar/python.gram into Grammar/invalid.gram, which generates Parser/parser_invalid.c.

Add an @include meta to pegen: the rules of an included grammar file are
appended to the including file's rules. The C generator emits the rules
of each included file into a separate C file next to the main output.

Use it to move the invalid_* rules from Grammar/python.gram into
Grammar/invalid.gram, which generates Parser/parser_invalid.c.
Comment thread Tools/peg_generator/pegen/c_generator.py
Comment thread Tools/peg_generator/pegen/c_generator_file.py Outdated
@hugovk
hugovk removed their request for review October 20, 2026 21:14

@pablogsal pablogsal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I am going to benchmark to check if there is any speed regressions

@lysnikolaou
lysnikolaou merged commit e548b47 into python:main Oct 23, 2026
114 of 117 checks passed
@lysnikolaou
lysnikolaou deleted the pegen-include-grammar branch October 23, 2026 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants