Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort KEYWORDS for consistent output ordering #44

Merged
merged 3 commits into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/pegen/python_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ def generate(self, filename: str) -> None:

self.print()
with self.indent():
self.print(f"KEYWORDS = {tuple(self.callmakervisitor.keywords)}")
self.print(f"SOFT_KEYWORDS = {tuple(self.callmakervisitor.soft_keywords)}")
self.print(f"KEYWORDS = {tuple(sorted(self.callmakervisitor.keywords))}")
self.print(f"SOFT_KEYWORDS = {tuple(sorted(self.callmakervisitor.soft_keywords))}")

trailer = self.grammar.metas.get("trailer", MODULE_SUFFIX.format(class_name=cls_name))
if trailer is not None:
Expand Down
9 changes: 9 additions & 0 deletions tests/test_pegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,3 +682,12 @@ def test_locations_in_alt_action_and_group() -> None:
if diff:
print(diff)
assert not diff


def test_keywords() -> None:
grammar = """
start: 'one' 'two' 'three' 'four' 'five' "six" "seven" "eight" "nine" "ten"
"""
parser_class = make_parser(grammar)
assert parser_class.KEYWORDS == ("five", "four", "one", "three", "two")
assert parser_class.SOFT_KEYWORDS == ("eight", "nine", "seven", "six", "ten")