we-like-parsers / pegen

PEG parser generator for Python
https://we-like-parsers.github.io/pegen/
MIT License
155 stars 33 forks source link

Consistent keyword ordering #40

Closed edemaine closed 3 years ago

edemaine commented 3 years ago

Every time I run pegen on the same grammar, I (often) get a different order for KEYWORDS and SOFT_KEYWORDS. This is annoying for version control, when parse.py is committed to a repo.

I imagine the cause is that the keywords are stored in a set which has nondeterministic order, and sorted will make this behavior deterministic. Specifically, tuple(...) should be replaced with tuple(sorted(...)) in these lines:

https://github.com/we-like-parsers/pegen/blob/31f489a16ba961be2b7142789f54e4a02561acbc/src/pegen/python_generator.py#L240-L241

Is it appropriate to make PR here, or would it be better against cpython?

MatthieuDartiailh commented 3 years ago

I believe such a PR would be welcome. This repo focuses on the pure python parser generation while the cpython repo focuses more on the generation of the C parser. So there is some non ideal duplication but for your case a PR against this repo is the most appropriate I would say.