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

bpo-40334: Avoid collisions between parser variables and grammar variables #19987

Merged
merged 2 commits into from May 10, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions Lib/test/test_peg_generator/test_pegen.py
Expand Up @@ -540,6 +540,33 @@ def test_missing_start(self) -> None:
with self.assertRaises(GrammarError):
parser_class = make_parser(grammar)

def test_invalid_rule_name(self) -> None:
grammar = """
start: a b
_a: 'a'
b: 'b'
"""
with self.assertRaises(GrammarError):
pablogsal marked this conversation as resolved.
Show resolved Hide resolved
parser_class = make_parser(grammar)

def test_invalid_variable_name(self) -> None:
grammar = """
start: a b
a: _x='a'
b: 'b'
"""
with self.assertRaises(GrammarError):
parser_class = make_parser(grammar)

def test_invalid_variable_name_in_temporal_rule(self) -> None:
grammar = """
start: a b
a: (_x='a' | 'b') | 'c'
b: 'b'
"""
with self.assertRaises(GrammarError):
parser_class = make_parser(grammar)


class TestGrammarVisitor:
class Visitor(GrammarVisitor):
Expand Down