The tl;dr is that actions specified in the grammar are specific to the target language. So if you want to use the pegen tool to generate both Python and C code for the same grammar, you would need two grammar files with the same grammar but different actions. Since our goal here is just to generate a parser for use in CPython that's not a problem. Other PEG parser generators make different choices, e.g. TatSu puts semantics actions in a separate file (
https://tatsu.readthedocs.io/en/stable/semantics.html).