diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2023-09-22 18:03:23 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-22 18:03:23 (GMT) |
commit | b28ffaa193efc66f46ab90d383279174a11a11d7 (patch) | |
tree | acea940a825714a0c55c4669d31e23fa08ed8bf0 /Tools | |
parent | 7c553991724d8d537f8444db73f016008753d77a (diff) | |
download | cpython-b28ffaa193efc66f46ab90d383279174a11a11d7.zip cpython-b28ffaa193efc66f46ab90d383279174a11a11d7.tar.gz cpython-b28ffaa193efc66f46ab90d383279174a11a11d7.tar.bz2 |
gh-109596: Ensure repeated rules in the grammar are not allowed and fix incorrect soft keywords (#109606)
Diffstat (limited to 'Tools')
-rw-r--r-- | Tools/peg_generator/pegen/grammar.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Tools/peg_generator/pegen/grammar.py b/Tools/peg_generator/pegen/grammar.py index 065894e..1ee9d10 100644 --- a/Tools/peg_generator/pegen/grammar.py +++ b/Tools/peg_generator/pegen/grammar.py @@ -35,7 +35,13 @@ class GrammarVisitor: class Grammar: def __init__(self, rules: Iterable[Rule], metas: Iterable[Tuple[str, Optional[str]]]): - self.rules = {rule.name: rule for rule in rules} + # Check if there are repeated rules in "rules" + all_rules = {} + for rule in rules: + if rule.name in all_rules: + raise GrammarError(f"Repeated rule {rule.name!r}") + all_rules[rule.name] = rule + self.rules = all_rules self.metas = dict(metas) def __str__(self) -> str: |