@@ -145,6 +145,35 @@ def run_test(self, grammar_source, test_source):
145145 TEST_TEMPLATE .format (extension_path = self .tmp_path , test_source = test_source ),
146146 )
147147
148+ def test_prefix_reuses_position (self ) -> None :
149+ grammar_source = """
150+ start:
151+ | prefix ':' NAME NEWLINE? ENDMARKER
152+ | prefix ':' NUMBER NEWLINE? ENDMARKER
153+ | prefix '=' NUMBER NEWLINE? ENDMARKER
154+ prefix (memo): NAME NAME
155+ """
156+ self .run_test (grammar_source , """
157+ self.check_input_strings_for_grammar(
158+ valid_cases=['one two : name', 'one two : 3', 'one two = 3'],
159+ invalid_cases=['one = 3', 'one two = name', 'one two :'],
160+ )
161+ """ )
162+
163+ def test_prefix_respects_cut (self ) -> None :
164+ grammar_source = """
165+ start:
166+ | prefix ':' ~ NAME NEWLINE? ENDMARKER
167+ | prefix ':' NUMBER NEWLINE? ENDMARKER
168+ prefix (memo): NAME NAME
169+ """
170+ self .run_test (grammar_source , """
171+ self.check_input_strings_for_grammar(
172+ valid_cases=['one two : name'],
173+ invalid_cases=['one two : 3'],
174+ )
175+ """ )
176+
148177 def test_c_parser (self ) -> None :
149178 grammar_source = """
150179 start[mod_ty]: a[asdl_stmt_seq*]=stmt* $ { _PyAST_Module(a, NULL, p->arena) }
0 commit comments