Skip to content

Commit 8855028

Browse files
committed
bpo-40334: Avoid collisions between parser variables and grammar variables
1 parent 2c3d508 commit 8855028

File tree

5 files changed

+5758
-5716
lines changed

5 files changed

+5758
-5716
lines changed

Lib/test/test_peg_generator/test_pegen.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,33 @@ def test_missing_start(self) -> None:
540540
with self.assertRaises(GrammarError):
541541
parser_class = make_parser(grammar)
542542

543+
def test_invalid_rule_name(self) -> None:
544+
grammar = """
545+
start: a b
546+
_a: 'a'
547+
b: 'b'
548+
"""
549+
with self.assertRaises(GrammarError):
550+
parser_class = make_parser(grammar)
551+
552+
def test_invalid_variable_name(self) -> None:
553+
grammar = """
554+
start: a b
555+
a: _x='a'
556+
b: 'b'
557+
"""
558+
with self.assertRaises(GrammarError):
559+
parser_class = make_parser(grammar)
560+
561+
def test_invalid_variable_name_in_temporal_rule(self) -> None:
562+
grammar = """
563+
start: a b
564+
a: (_x='a' | 'b') | 'c'
565+
b: 'b'
566+
"""
567+
with self.assertRaises(GrammarError):
568+
parser_class = make_parser(grammar)
569+
543570

544571
class TestGrammarVisitor:
545572
class Visitor(GrammarVisitor):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy