@@ -90,7 +90,7 @@ def run_test(self, grammar_source, test_source):
90
90
91
91
def test_c_parser (self ) -> None :
92
92
grammar_source = """
93
- start[mod_ty]: a=stmt* $ { Module(a, NULL, p->arena) }
93
+ start[mod_ty]: a[asdl_stmt_seq*] =stmt* $ { Module(a, NULL, p->arena) }
94
94
stmt[stmt_ty]: a=expr_stmt { a }
95
95
expr_stmt[stmt_ty]: a=expression NEWLINE { _Py_Expr(a, EXTRA) }
96
96
expression[expr_ty]: ( l=expression '+' r=term { _Py_BinOp(l, Add, r, EXTRA) }
@@ -232,7 +232,7 @@ def test_nasty_mutually_left_recursive(self) -> None:
232
232
def test_return_stmt_noexpr_action (self ) -> None :
233
233
grammar_source = """
234
234
start[mod_ty]: a=[statements] ENDMARKER { Module(a, NULL, p->arena) }
235
- statements[asdl_seq *]: a=statement+ { a }
235
+ statements[asdl_stmt_seq *]: a[asdl_stmt_seq*] =statement+ { a }
236
236
statement[stmt_ty]: simple_stmt
237
237
simple_stmt[stmt_ty]: small_stmt
238
238
small_stmt[stmt_ty]: return_stmt
@@ -246,7 +246,7 @@ def test_return_stmt_noexpr_action(self) -> None:
246
246
247
247
def test_gather_action_ast (self ) -> None :
248
248
grammar_source = """
249
- start[mod_ty]: a=';'.pass_stmt+ NEWLINE ENDMARKER { Module(a, NULL, p->arena) }
249
+ start[mod_ty]: a[asdl_stmt_seq*] =';'.pass_stmt+ NEWLINE ENDMARKER { Module(a, NULL, p->arena) }
250
250
pass_stmt[stmt_ty]: a='pass' { _Py_Pass(EXTRA)}
251
251
"""
252
252
test_source = """
@@ -258,7 +258,7 @@ def test_gather_action_ast(self) -> None:
258
258
def test_pass_stmt_action (self ) -> None :
259
259
grammar_source = """
260
260
start[mod_ty]: a=[statements] ENDMARKER { Module(a, NULL, p->arena) }
261
- statements[asdl_seq *]: a=statement+ { a }
261
+ statements[asdl_stmt_seq *]: a[asdl_stmt_seq*] =statement+ { a }
262
262
statement[stmt_ty]: simple_stmt
263
263
simple_stmt[stmt_ty]: small_stmt
264
264
small_stmt[stmt_ty]: pass_stmt
@@ -273,10 +273,11 @@ def test_pass_stmt_action(self) -> None:
273
273
def test_if_stmt_action (self ) -> None :
274
274
grammar_source = """
275
275
start[mod_ty]: a=[statements] ENDMARKER { Module(a, NULL, p->arena) }
276
- statements[asdl_seq *]: a=statement+ { _PyPegen_seq_flatten(p, a) }
277
- statement[asdl_seq *]: a=compound_stmt { _PyPegen_singleton_seq(p, a) } | simple_stmt
276
+ statements[asdl_stmt_seq *]: a=statement+ { (asdl_stmt_seq*) _PyPegen_seq_flatten(p, a) }
277
+ statement[asdl_stmt_seq *]: a=compound_stmt { (asdl_stmt_seq*) _PyPegen_singleton_seq(p, a) } | simple_stmt
278
278
279
- simple_stmt[asdl_seq*]: a=small_stmt b=further_small_stmt* [';'] NEWLINE { _PyPegen_seq_insert_in_front(p, a, b) }
279
+ simple_stmt[asdl_stmt_seq*]: a=small_stmt b=further_small_stmt* [';'] NEWLINE {
280
+ (asdl_stmt_seq*)_PyPegen_seq_insert_in_front(p, a, b) }
280
281
further_small_stmt[stmt_ty]: ';' a=small_stmt { a }
281
282
282
283
block: simple_stmt | NEWLINE INDENT a=statements DEDENT { a }
@@ -299,14 +300,14 @@ def test_if_stmt_action(self) -> None:
299
300
300
301
def test_same_name_different_types (self ) -> None :
301
302
grammar_source = """
302
- start[mod_ty]: a=import_from+ NEWLINE ENDMARKER { Module(a, NULL, p->arena)}
303
+ start[mod_ty]: a[asdl_stmt_seq*] =import_from+ NEWLINE ENDMARKER { Module(a, NULL, p->arena)}
303
304
import_from[stmt_ty]: ( a='from' !'import' c=simple_name 'import' d=import_as_names_from {
304
305
_Py_ImportFrom(c->v.Name.id, d, 0, EXTRA) }
305
306
| a='from' '.' 'import' c=import_as_names_from {
306
307
_Py_ImportFrom(NULL, c, 1, EXTRA) }
307
308
)
308
309
simple_name[expr_ty]: NAME
309
- import_as_names_from[asdl_seq *]: a=','.import_as_name_from+ { a }
310
+ import_as_names_from[asdl_alias_seq *]: a[asdl_alias_seq*] =','.import_as_name_from+ { a }
310
311
import_as_name_from[alias_ty]: a=NAME 'as' b=NAME { _Py_alias(((expr_ty) a)->v.Name.id, ((expr_ty) b)->v.Name.id, p->arena) }
311
312
"""
312
313
test_source = """
@@ -320,12 +321,12 @@ def test_same_name_different_types(self) -> None:
320
321
def test_with_stmt_with_paren (self ) -> None :
321
322
grammar_source = """
322
323
start[mod_ty]: a=[statements] ENDMARKER { Module(a, NULL, p->arena) }
323
- statements[asdl_seq *]: a=statement+ { _PyPegen_seq_flatten(p, a) }
324
- statement[asdl_seq *]: a=compound_stmt { _PyPegen_singleton_seq(p, a) }
324
+ statements[asdl_stmt_seq *]: a=statement+ { (asdl_stmt_seq*) _PyPegen_seq_flatten(p, a) }
325
+ statement[asdl_stmt_seq *]: a=compound_stmt { (asdl_stmt_seq*) _PyPegen_singleton_seq(p, a) }
325
326
compound_stmt[stmt_ty]: with_stmt
326
327
with_stmt[stmt_ty]: (
327
- a='with' '(' b=','.with_item+ ')' ':' c=block {
328
- _Py_With(b, _PyPegen_singleton_seq(p, c), NULL, EXTRA) }
328
+ a='with' '(' b[asdl_withitem_seq*] =','.with_item+ ')' ':' c=block {
329
+ _Py_With(b, (asdl_stmt_seq*) _PyPegen_singleton_seq(p, c), NULL, EXTRA) }
329
330
)
330
331
with_item[withitem_ty]: (
331
332
e=NAME o=['as' t=NAME { t }] { _Py_withitem(e, _PyPegen_set_expr_context(p, o, Store), p->arena) }
@@ -346,12 +347,12 @@ def test_with_stmt_with_paren(self) -> None:
346
347
def test_ternary_operator (self ) -> None :
347
348
grammar_source = """
348
349
start[mod_ty]: a=expr ENDMARKER { Module(a, NULL, p->arena) }
349
- expr[asdl_seq *]: a=listcomp NEWLINE { _PyPegen_singleton_seq(p, _Py_Expr(a, EXTRA)) }
350
+ expr[asdl_stmt_seq *]: a=listcomp NEWLINE { (asdl_stmt_seq*) _PyPegen_singleton_seq(p, _Py_Expr(a, EXTRA)) }
350
351
listcomp[expr_ty]: (
351
352
a='[' b=NAME c=for_if_clauses d=']' { _Py_ListComp(b, c, EXTRA) }
352
353
)
353
- for_if_clauses[asdl_seq *]: (
354
- a=(y=[ASYNC] 'for' a=NAME 'in' b=NAME c=('if' z=NAME { z })*
354
+ for_if_clauses[asdl_comprehension_seq *]: (
355
+ a[asdl_comprehension_seq*] =(y=[ASYNC] 'for' a=NAME 'in' b=NAME c[asdl_expr_seq*] =('if' z=NAME { z })*
355
356
{ _Py_comprehension(_Py_Name(((expr_ty) a)->v.Name.id, Store, EXTRA), b, c, (y == NULL) ? 0 : 1, p->arena) })+ { a }
356
357
)
357
358
"""
0 commit comments