mirror of https://github.com/python/cpython
bpo-43244: Rename pycore_ast.h functions to _PyAST_xxx() (GH-25252)
Rename AST functions of pycore_ast.h to use the "_PyAST_" prefix. Remove macros creating aliases without prefix. For example, Module() becomes _PyAST_Module(). Update Grammar/python.gram to use _PyAST_xxx() functions.
This commit is contained in:
parent
58d72cab89
commit
d27f8d2e07
|
@ -28,9 +28,9 @@ _PyPegen_parse(Parser *p)
|
||||||
// The end
|
// The end
|
||||||
'''
|
'''
|
||||||
file[mod_ty]: a=[statements] ENDMARKER { _PyPegen_make_module(p, a) }
|
file[mod_ty]: a=[statements] ENDMARKER { _PyPegen_make_module(p, a) }
|
||||||
interactive[mod_ty]: a=statement_newline { Interactive(a, p->arena) }
|
interactive[mod_ty]: a=statement_newline { _PyAST_Interactive(a, p->arena) }
|
||||||
eval[mod_ty]: a=expressions NEWLINE* ENDMARKER { Expression(a, p->arena) }
|
eval[mod_ty]: a=expressions NEWLINE* ENDMARKER { _PyAST_Expression(a, p->arena) }
|
||||||
func_type[mod_ty]: '(' a=[type_expressions] ')' '->' b=expression NEWLINE* ENDMARKER { FunctionType(a, b, p->arena) }
|
func_type[mod_ty]: '(' a=[type_expressions] ')' '->' b=expression NEWLINE* ENDMARKER { _PyAST_FunctionType(a, b, p->arena) }
|
||||||
fstring[expr_ty]: star_expressions
|
fstring[expr_ty]: star_expressions
|
||||||
|
|
||||||
# type_expressions allow */** but ignore them
|
# type_expressions allow */** but ignore them
|
||||||
|
@ -56,7 +56,7 @@ statement[asdl_stmt_seq*]: a=compound_stmt { (asdl_stmt_seq*)_PyPegen_singleton_
|
||||||
statement_newline[asdl_stmt_seq*]:
|
statement_newline[asdl_stmt_seq*]:
|
||||||
| a=compound_stmt NEWLINE { (asdl_stmt_seq*)_PyPegen_singleton_seq(p, a) }
|
| a=compound_stmt NEWLINE { (asdl_stmt_seq*)_PyPegen_singleton_seq(p, a) }
|
||||||
| simple_stmts
|
| simple_stmts
|
||||||
| NEWLINE { (asdl_stmt_seq*)_PyPegen_singleton_seq(p, CHECK(stmt_ty, _Py_Pass(EXTRA))) }
|
| NEWLINE { (asdl_stmt_seq*)_PyPegen_singleton_seq(p, CHECK(stmt_ty, _PyAST_Pass(EXTRA))) }
|
||||||
| ENDMARKER { _PyPegen_interactive_exit(p) }
|
| ENDMARKER { _PyPegen_interactive_exit(p) }
|
||||||
simple_stmts[asdl_stmt_seq*]:
|
simple_stmts[asdl_stmt_seq*]:
|
||||||
| a=simple_stmt !';' NEWLINE { (asdl_stmt_seq*)_PyPegen_singleton_seq(p, a) } # Not needed, there for speedup
|
| a=simple_stmt !';' NEWLINE { (asdl_stmt_seq*)_PyPegen_singleton_seq(p, a) } # Not needed, there for speedup
|
||||||
|
@ -65,16 +65,16 @@ simple_stmts[asdl_stmt_seq*]:
|
||||||
# will throw a SyntaxError.
|
# will throw a SyntaxError.
|
||||||
simple_stmt[stmt_ty] (memo):
|
simple_stmt[stmt_ty] (memo):
|
||||||
| assignment
|
| assignment
|
||||||
| e=star_expressions { _Py_Expr(e, EXTRA) }
|
| e=star_expressions { _PyAST_Expr(e, EXTRA) }
|
||||||
| &'return' return_stmt
|
| &'return' return_stmt
|
||||||
| &('import' | 'from') import_stmt
|
| &('import' | 'from') import_stmt
|
||||||
| &'raise' raise_stmt
|
| &'raise' raise_stmt
|
||||||
| 'pass' { _Py_Pass(EXTRA) }
|
| 'pass' { _PyAST_Pass(EXTRA) }
|
||||||
| &'del' del_stmt
|
| &'del' del_stmt
|
||||||
| &'yield' yield_stmt
|
| &'yield' yield_stmt
|
||||||
| &'assert' assert_stmt
|
| &'assert' assert_stmt
|
||||||
| 'break' { _Py_Break(EXTRA) }
|
| 'break' { _PyAST_Break(EXTRA) }
|
||||||
| 'continue' { _Py_Continue(EXTRA) }
|
| 'continue' { _PyAST_Continue(EXTRA) }
|
||||||
| &'global' global_stmt
|
| &'global' global_stmt
|
||||||
| &'nonlocal' nonlocal_stmt
|
| &'nonlocal' nonlocal_stmt
|
||||||
compound_stmt[stmt_ty]:
|
compound_stmt[stmt_ty]:
|
||||||
|
@ -94,15 +94,15 @@ assignment[stmt_ty]:
|
||||||
stmt_ty,
|
stmt_ty,
|
||||||
6,
|
6,
|
||||||
"Variable annotation syntax is",
|
"Variable annotation syntax is",
|
||||||
_Py_AnnAssign(CHECK(expr_ty, _PyPegen_set_expr_context(p, a, Store)), b, c, 1, EXTRA)
|
_PyAST_AnnAssign(CHECK(expr_ty, _PyPegen_set_expr_context(p, a, Store)), b, c, 1, EXTRA)
|
||||||
) }
|
) }
|
||||||
| a=('(' b=single_target ')' { b }
|
| a=('(' b=single_target ')' { b }
|
||||||
| single_subscript_attribute_target) ':' b=expression c=['=' d=annotated_rhs { d }] {
|
| single_subscript_attribute_target) ':' b=expression c=['=' d=annotated_rhs { d }] {
|
||||||
CHECK_VERSION(stmt_ty, 6, "Variable annotations syntax is", _Py_AnnAssign(a, b, c, 0, EXTRA)) }
|
CHECK_VERSION(stmt_ty, 6, "Variable annotations syntax is", _PyAST_AnnAssign(a, b, c, 0, EXTRA)) }
|
||||||
| a[asdl_expr_seq*]=(z=star_targets '=' { z })+ b=(yield_expr | star_expressions) !'=' tc=[TYPE_COMMENT] {
|
| a[asdl_expr_seq*]=(z=star_targets '=' { z })+ b=(yield_expr | star_expressions) !'=' tc=[TYPE_COMMENT] {
|
||||||
_Py_Assign(a, b, NEW_TYPE_COMMENT(p, tc), EXTRA) }
|
_PyAST_Assign(a, b, NEW_TYPE_COMMENT(p, tc), EXTRA) }
|
||||||
| a=single_target b=augassign ~ c=(yield_expr | star_expressions) {
|
| a=single_target b=augassign ~ c=(yield_expr | star_expressions) {
|
||||||
_Py_AugAssign(a, b->kind, c, EXTRA) }
|
_PyAST_AugAssign(a, b->kind, c, EXTRA) }
|
||||||
| invalid_assignment
|
| invalid_assignment
|
||||||
|
|
||||||
augassign[AugOperator*]:
|
augassign[AugOperator*]:
|
||||||
|
@ -121,26 +121,26 @@ augassign[AugOperator*]:
|
||||||
| '//=' { _PyPegen_augoperator(p, FloorDiv) }
|
| '//=' { _PyPegen_augoperator(p, FloorDiv) }
|
||||||
|
|
||||||
global_stmt[stmt_ty]: 'global' a[asdl_expr_seq*]=','.NAME+ {
|
global_stmt[stmt_ty]: 'global' a[asdl_expr_seq*]=','.NAME+ {
|
||||||
_Py_Global(CHECK(asdl_identifier_seq*, _PyPegen_map_names_to_ids(p, a)), EXTRA) }
|
_PyAST_Global(CHECK(asdl_identifier_seq*, _PyPegen_map_names_to_ids(p, a)), EXTRA) }
|
||||||
nonlocal_stmt[stmt_ty]: 'nonlocal' a[asdl_expr_seq*]=','.NAME+ {
|
nonlocal_stmt[stmt_ty]: 'nonlocal' a[asdl_expr_seq*]=','.NAME+ {
|
||||||
_Py_Nonlocal(CHECK(asdl_identifier_seq*, _PyPegen_map_names_to_ids(p, a)), EXTRA) }
|
_PyAST_Nonlocal(CHECK(asdl_identifier_seq*, _PyPegen_map_names_to_ids(p, a)), EXTRA) }
|
||||||
|
|
||||||
yield_stmt[stmt_ty]: y=yield_expr { _Py_Expr(y, EXTRA) }
|
yield_stmt[stmt_ty]: y=yield_expr { _PyAST_Expr(y, EXTRA) }
|
||||||
|
|
||||||
assert_stmt[stmt_ty]: 'assert' a=expression b=[',' z=expression { z }] { _Py_Assert(a, b, EXTRA) }
|
assert_stmt[stmt_ty]: 'assert' a=expression b=[',' z=expression { z }] { _PyAST_Assert(a, b, EXTRA) }
|
||||||
|
|
||||||
del_stmt[stmt_ty]:
|
del_stmt[stmt_ty]:
|
||||||
| 'del' a=del_targets &(';' | NEWLINE) { _Py_Delete(a, EXTRA) }
|
| 'del' a=del_targets &(';' | NEWLINE) { _PyAST_Delete(a, EXTRA) }
|
||||||
| invalid_del_stmt
|
| invalid_del_stmt
|
||||||
|
|
||||||
import_stmt[stmt_ty]: import_name | import_from
|
import_stmt[stmt_ty]: import_name | import_from
|
||||||
import_name[stmt_ty]: 'import' a=dotted_as_names { _Py_Import(a, EXTRA) }
|
import_name[stmt_ty]: 'import' a=dotted_as_names { _PyAST_Import(a, EXTRA) }
|
||||||
# note below: the ('.' | '...') is necessary because '...' is tokenized as ELLIPSIS
|
# note below: the ('.' | '...') is necessary because '...' is tokenized as ELLIPSIS
|
||||||
import_from[stmt_ty]:
|
import_from[stmt_ty]:
|
||||||
| 'from' a=('.' | '...')* b=dotted_name 'import' c=import_from_targets {
|
| 'from' a=('.' | '...')* b=dotted_name 'import' c=import_from_targets {
|
||||||
_Py_ImportFrom(b->v.Name.id, c, _PyPegen_seq_count_dots(a), EXTRA) }
|
_PyAST_ImportFrom(b->v.Name.id, c, _PyPegen_seq_count_dots(a), EXTRA) }
|
||||||
| 'from' a=('.' | '...')+ 'import' b=import_from_targets {
|
| 'from' a=('.' | '...')+ 'import' b=import_from_targets {
|
||||||
_Py_ImportFrom(NULL, b, _PyPegen_seq_count_dots(a), EXTRA) }
|
_PyAST_ImportFrom(NULL, b, _PyPegen_seq_count_dots(a), EXTRA) }
|
||||||
import_from_targets[asdl_alias_seq*]:
|
import_from_targets[asdl_alias_seq*]:
|
||||||
| '(' a=import_from_as_names [','] ')' { a }
|
| '(' a=import_from_as_names [','] ')' { a }
|
||||||
| import_from_as_names !','
|
| import_from_as_names !','
|
||||||
|
@ -149,13 +149,13 @@ import_from_targets[asdl_alias_seq*]:
|
||||||
import_from_as_names[asdl_alias_seq*]:
|
import_from_as_names[asdl_alias_seq*]:
|
||||||
| a[asdl_alias_seq*]=','.import_from_as_name+ { a }
|
| a[asdl_alias_seq*]=','.import_from_as_name+ { a }
|
||||||
import_from_as_name[alias_ty]:
|
import_from_as_name[alias_ty]:
|
||||||
| a=NAME b=['as' z=NAME { z }] { _Py_alias(a->v.Name.id,
|
| a=NAME b=['as' z=NAME { z }] { _PyAST_alias(a->v.Name.id,
|
||||||
(b) ? ((expr_ty) b)->v.Name.id : NULL,
|
(b) ? ((expr_ty) b)->v.Name.id : NULL,
|
||||||
p->arena) }
|
p->arena) }
|
||||||
dotted_as_names[asdl_alias_seq*]:
|
dotted_as_names[asdl_alias_seq*]:
|
||||||
| a[asdl_alias_seq*]=','.dotted_as_name+ { a }
|
| a[asdl_alias_seq*]=','.dotted_as_name+ { a }
|
||||||
dotted_as_name[alias_ty]:
|
dotted_as_name[alias_ty]:
|
||||||
| a=dotted_name b=['as' z=NAME { z }] { _Py_alias(a->v.Name.id,
|
| a=dotted_name b=['as' z=NAME { z }] { _PyAST_alias(a->v.Name.id,
|
||||||
(b) ? ((expr_ty) b)->v.Name.id : NULL,
|
(b) ? ((expr_ty) b)->v.Name.id : NULL,
|
||||||
p->arena) }
|
p->arena) }
|
||||||
dotted_name[expr_ty]:
|
dotted_name[expr_ty]:
|
||||||
|
@ -164,77 +164,77 @@ dotted_name[expr_ty]:
|
||||||
|
|
||||||
if_stmt[stmt_ty]:
|
if_stmt[stmt_ty]:
|
||||||
| 'if' a=named_expression &&':' b=block c=elif_stmt {
|
| 'if' a=named_expression &&':' b=block c=elif_stmt {
|
||||||
_Py_If(a, b, CHECK(asdl_stmt_seq*, _PyPegen_singleton_seq(p, c)), EXTRA) }
|
_PyAST_If(a, b, CHECK(asdl_stmt_seq*, _PyPegen_singleton_seq(p, c)), EXTRA) }
|
||||||
| 'if' a=named_expression &&':' b=block c=[else_block] { _Py_If(a, b, c, EXTRA) }
|
| 'if' a=named_expression &&':' b=block c=[else_block] { _PyAST_If(a, b, c, EXTRA) }
|
||||||
elif_stmt[stmt_ty]:
|
elif_stmt[stmt_ty]:
|
||||||
| 'elif' a=named_expression &&':' b=block c=elif_stmt {
|
| 'elif' a=named_expression &&':' b=block c=elif_stmt {
|
||||||
_Py_If(a, b, CHECK(asdl_stmt_seq*, _PyPegen_singleton_seq(p, c)), EXTRA) }
|
_PyAST_If(a, b, CHECK(asdl_stmt_seq*, _PyPegen_singleton_seq(p, c)), EXTRA) }
|
||||||
| 'elif' a=named_expression &&':' b=block c=[else_block] { _Py_If(a, b, c, EXTRA) }
|
| 'elif' a=named_expression &&':' b=block c=[else_block] { _PyAST_If(a, b, c, EXTRA) }
|
||||||
else_block[asdl_stmt_seq*]: 'else' &&':' b=block { b }
|
else_block[asdl_stmt_seq*]: 'else' &&':' b=block { b }
|
||||||
|
|
||||||
while_stmt[stmt_ty]:
|
while_stmt[stmt_ty]:
|
||||||
| 'while' a=named_expression &&':' b=block c=[else_block] { _Py_While(a, b, c, EXTRA) }
|
| 'while' a=named_expression &&':' b=block c=[else_block] { _PyAST_While(a, b, c, EXTRA) }
|
||||||
|
|
||||||
for_stmt[stmt_ty]:
|
for_stmt[stmt_ty]:
|
||||||
| 'for' t=star_targets 'in' ~ ex=star_expressions &&':' tc=[TYPE_COMMENT] b=block el=[else_block] {
|
| 'for' t=star_targets 'in' ~ ex=star_expressions &&':' tc=[TYPE_COMMENT] b=block el=[else_block] {
|
||||||
_Py_For(t, ex, b, el, NEW_TYPE_COMMENT(p, tc), EXTRA) }
|
_PyAST_For(t, ex, b, el, NEW_TYPE_COMMENT(p, tc), EXTRA) }
|
||||||
| ASYNC 'for' t=star_targets 'in' ~ ex=star_expressions &&':' tc=[TYPE_COMMENT] b=block el=[else_block] {
|
| ASYNC 'for' t=star_targets 'in' ~ ex=star_expressions &&':' tc=[TYPE_COMMENT] b=block el=[else_block] {
|
||||||
CHECK_VERSION(stmt_ty, 5, "Async for loops are", _Py_AsyncFor(t, ex, b, el, NEW_TYPE_COMMENT(p, tc), EXTRA)) }
|
CHECK_VERSION(stmt_ty, 5, "Async for loops are", _PyAST_AsyncFor(t, ex, b, el, NEW_TYPE_COMMENT(p, tc), EXTRA)) }
|
||||||
| invalid_for_target
|
| invalid_for_target
|
||||||
|
|
||||||
with_stmt[stmt_ty]:
|
with_stmt[stmt_ty]:
|
||||||
| 'with' '(' a[asdl_withitem_seq*]=','.with_item+ ','? ')' ':' b=block {
|
| 'with' '(' a[asdl_withitem_seq*]=','.with_item+ ','? ')' ':' b=block {
|
||||||
_Py_With(a, b, NULL, EXTRA) }
|
_PyAST_With(a, b, NULL, EXTRA) }
|
||||||
| 'with' a[asdl_withitem_seq*]=','.with_item+ ':' tc=[TYPE_COMMENT] b=block {
|
| 'with' a[asdl_withitem_seq*]=','.with_item+ ':' tc=[TYPE_COMMENT] b=block {
|
||||||
_Py_With(a, b, NEW_TYPE_COMMENT(p, tc), EXTRA) }
|
_PyAST_With(a, b, NEW_TYPE_COMMENT(p, tc), EXTRA) }
|
||||||
| ASYNC 'with' '(' a[asdl_withitem_seq*]=','.with_item+ ','? ')' ':' b=block {
|
| ASYNC 'with' '(' a[asdl_withitem_seq*]=','.with_item+ ','? ')' ':' b=block {
|
||||||
CHECK_VERSION(stmt_ty, 5, "Async with statements are", _Py_AsyncWith(a, b, NULL, EXTRA)) }
|
CHECK_VERSION(stmt_ty, 5, "Async with statements are", _PyAST_AsyncWith(a, b, NULL, EXTRA)) }
|
||||||
| ASYNC 'with' a[asdl_withitem_seq*]=','.with_item+ ':' tc=[TYPE_COMMENT] b=block {
|
| ASYNC 'with' a[asdl_withitem_seq*]=','.with_item+ ':' tc=[TYPE_COMMENT] b=block {
|
||||||
CHECK_VERSION(stmt_ty, 5, "Async with statements are", _Py_AsyncWith(a, b, NEW_TYPE_COMMENT(p, tc), EXTRA)) }
|
CHECK_VERSION(stmt_ty, 5, "Async with statements are", _PyAST_AsyncWith(a, b, NEW_TYPE_COMMENT(p, tc), EXTRA)) }
|
||||||
| invalid_with_stmt
|
| invalid_with_stmt
|
||||||
|
|
||||||
with_item[withitem_ty]:
|
with_item[withitem_ty]:
|
||||||
| e=expression 'as' t=star_target &(',' | ')' | ':') { _Py_withitem(e, t, p->arena) }
|
| e=expression 'as' t=star_target &(',' | ')' | ':') { _PyAST_withitem(e, t, p->arena) }
|
||||||
| invalid_with_item
|
| invalid_with_item
|
||||||
| e=expression { _Py_withitem(e, NULL, p->arena) }
|
| e=expression { _PyAST_withitem(e, NULL, p->arena) }
|
||||||
|
|
||||||
try_stmt[stmt_ty]:
|
try_stmt[stmt_ty]:
|
||||||
| 'try' &&':' b=block f=finally_block { _Py_Try(b, NULL, NULL, f, EXTRA) }
|
| 'try' &&':' b=block f=finally_block { _PyAST_Try(b, NULL, NULL, f, EXTRA) }
|
||||||
| 'try' &&':' b=block ex[asdl_excepthandler_seq*]=except_block+ el=[else_block] f=[finally_block] { _Py_Try(b, ex, el, f, EXTRA) }
|
| 'try' &&':' b=block ex[asdl_excepthandler_seq*]=except_block+ el=[else_block] f=[finally_block] { _PyAST_Try(b, ex, el, f, EXTRA) }
|
||||||
except_block[excepthandler_ty]:
|
except_block[excepthandler_ty]:
|
||||||
| 'except' e=expression t=['as' z=NAME { z }] ':' b=block {
|
| 'except' e=expression t=['as' z=NAME { z }] ':' b=block {
|
||||||
_Py_ExceptHandler(e, (t) ? ((expr_ty) t)->v.Name.id : NULL, b, EXTRA) }
|
_PyAST_ExceptHandler(e, (t) ? ((expr_ty) t)->v.Name.id : NULL, b, EXTRA) }
|
||||||
| 'except' ':' b=block { _Py_ExceptHandler(NULL, NULL, b, EXTRA) }
|
| 'except' ':' b=block { _PyAST_ExceptHandler(NULL, NULL, b, EXTRA) }
|
||||||
| invalid_except_block
|
| invalid_except_block
|
||||||
finally_block[asdl_stmt_seq*]: 'finally' ':' a=block { a }
|
finally_block[asdl_stmt_seq*]: 'finally' ':' a=block { a }
|
||||||
|
|
||||||
match_stmt[stmt_ty]:
|
match_stmt[stmt_ty]:
|
||||||
| "match" subject=subject_expr ':' NEWLINE INDENT cases[asdl_match_case_seq*]=case_block+ DEDENT {
|
| "match" subject=subject_expr ':' NEWLINE INDENT cases[asdl_match_case_seq*]=case_block+ DEDENT {
|
||||||
CHECK_VERSION(stmt_ty, 10, "Pattern matching is", _Py_Match(subject, cases, EXTRA)) }
|
CHECK_VERSION(stmt_ty, 10, "Pattern matching is", _PyAST_Match(subject, cases, EXTRA)) }
|
||||||
| invalid_match_stmt
|
| invalid_match_stmt
|
||||||
subject_expr[expr_ty]:
|
subject_expr[expr_ty]:
|
||||||
| value=star_named_expression ',' values=star_named_expressions? {
|
| value=star_named_expression ',' values=star_named_expressions? {
|
||||||
_Py_Tuple(CHECK(asdl_expr_seq*, _PyPegen_seq_insert_in_front(p, value, values)), Load, EXTRA) }
|
_PyAST_Tuple(CHECK(asdl_expr_seq*, _PyPegen_seq_insert_in_front(p, value, values)), Load, EXTRA) }
|
||||||
| named_expression
|
| named_expression
|
||||||
case_block[match_case_ty]:
|
case_block[match_case_ty]:
|
||||||
| "case" pattern=patterns guard=guard? ':' body=block {
|
| "case" pattern=patterns guard=guard? ':' body=block {
|
||||||
_Py_match_case(pattern, guard, body, p->arena) }
|
_PyAST_match_case(pattern, guard, body, p->arena) }
|
||||||
| invalid_case_block
|
| invalid_case_block
|
||||||
guard[expr_ty]: 'if' guard=named_expression { guard }
|
guard[expr_ty]: 'if' guard=named_expression { guard }
|
||||||
|
|
||||||
patterns[expr_ty]:
|
patterns[expr_ty]:
|
||||||
| values[asdl_expr_seq*]=open_sequence_pattern {
|
| values[asdl_expr_seq*]=open_sequence_pattern {
|
||||||
_Py_Tuple(values, Load, EXTRA) }
|
_PyAST_Tuple(values, Load, EXTRA) }
|
||||||
| pattern
|
| pattern
|
||||||
pattern[expr_ty]:
|
pattern[expr_ty]:
|
||||||
| as_pattern
|
| as_pattern
|
||||||
| or_pattern
|
| or_pattern
|
||||||
as_pattern[expr_ty]:
|
as_pattern[expr_ty]:
|
||||||
| pattern=or_pattern 'as' target=capture_pattern {
|
| pattern=or_pattern 'as' target=capture_pattern {
|
||||||
_Py_MatchAs(pattern, target->v.Name.id, EXTRA) }
|
_PyAST_MatchAs(pattern, target->v.Name.id, EXTRA) }
|
||||||
or_pattern[expr_ty]:
|
or_pattern[expr_ty]:
|
||||||
| patterns[asdl_expr_seq*]='|'.closed_pattern+ {
|
| patterns[asdl_expr_seq*]='|'.closed_pattern+ {
|
||||||
asdl_seq_LEN(patterns) == 1 ? asdl_seq_GET(patterns, 0) : _Py_MatchOr(patterns, EXTRA) }
|
asdl_seq_LEN(patterns) == 1 ? asdl_seq_GET(patterns, 0) : _PyAST_MatchOr(patterns, EXTRA) }
|
||||||
closed_pattern[expr_ty]:
|
closed_pattern[expr_ty]:
|
||||||
| literal_pattern
|
| literal_pattern
|
||||||
| capture_pattern
|
| capture_pattern
|
||||||
|
@ -247,28 +247,28 @@ closed_pattern[expr_ty]:
|
||||||
|
|
||||||
literal_pattern[expr_ty]:
|
literal_pattern[expr_ty]:
|
||||||
| signed_number !('+' | '-')
|
| signed_number !('+' | '-')
|
||||||
| real=signed_number '+' imag=NUMBER { _Py_BinOp(real, Add, imag, EXTRA) }
|
| real=signed_number '+' imag=NUMBER { _PyAST_BinOp(real, Add, imag, EXTRA) }
|
||||||
| real=signed_number '-' imag=NUMBER { _Py_BinOp(real, Sub, imag, EXTRA) }
|
| real=signed_number '-' imag=NUMBER { _PyAST_BinOp(real, Sub, imag, EXTRA) }
|
||||||
| strings
|
| strings
|
||||||
| 'None' { _Py_Constant(Py_None, NULL, EXTRA) }
|
| 'None' { _PyAST_Constant(Py_None, NULL, EXTRA) }
|
||||||
| 'True' { _Py_Constant(Py_True, NULL, EXTRA) }
|
| 'True' { _PyAST_Constant(Py_True, NULL, EXTRA) }
|
||||||
| 'False' { _Py_Constant(Py_False, NULL, EXTRA) }
|
| 'False' { _PyAST_Constant(Py_False, NULL, EXTRA) }
|
||||||
signed_number[expr_ty]:
|
signed_number[expr_ty]:
|
||||||
| NUMBER
|
| NUMBER
|
||||||
| '-' number=NUMBER { _Py_UnaryOp(USub, number, EXTRA) }
|
| '-' number=NUMBER { _PyAST_UnaryOp(USub, number, EXTRA) }
|
||||||
|
|
||||||
capture_pattern[expr_ty]:
|
capture_pattern[expr_ty]:
|
||||||
| !"_" name=NAME !('.' | '(' | '=') {
|
| !"_" name=NAME !('.' | '(' | '=') {
|
||||||
_PyPegen_set_expr_context(p, name, Store) }
|
_PyPegen_set_expr_context(p, name, Store) }
|
||||||
|
|
||||||
wildcard_pattern[expr_ty]:
|
wildcard_pattern[expr_ty]:
|
||||||
| "_" { _Py_Name(CHECK(PyObject*, _PyPegen_new_identifier(p, "_")), Store, EXTRA) }
|
| "_" { _PyAST_Name(CHECK(PyObject*, _PyPegen_new_identifier(p, "_")), Store, EXTRA) }
|
||||||
|
|
||||||
value_pattern[expr_ty]:
|
value_pattern[expr_ty]:
|
||||||
| attr=attr !('.' | '(' | '=') { attr }
|
| attr=attr !('.' | '(' | '=') { attr }
|
||||||
attr[expr_ty]:
|
attr[expr_ty]:
|
||||||
| value=name_or_attr '.' attr=NAME {
|
| value=name_or_attr '.' attr=NAME {
|
||||||
_Py_Attribute(value, attr->v.Name.id, Load, EXTRA) }
|
_PyAST_Attribute(value, attr->v.Name.id, Load, EXTRA) }
|
||||||
name_or_attr[expr_ty]:
|
name_or_attr[expr_ty]:
|
||||||
| attr
|
| attr
|
||||||
| NAME
|
| NAME
|
||||||
|
@ -277,8 +277,8 @@ group_pattern[expr_ty]:
|
||||||
| '(' pattern=pattern ')' { pattern }
|
| '(' pattern=pattern ')' { pattern }
|
||||||
|
|
||||||
sequence_pattern[expr_ty]:
|
sequence_pattern[expr_ty]:
|
||||||
| '[' values=maybe_sequence_pattern? ']' { _Py_List(values, Load, EXTRA) }
|
| '[' values=maybe_sequence_pattern? ']' { _PyAST_List(values, Load, EXTRA) }
|
||||||
| '(' values=open_sequence_pattern? ')' { _Py_Tuple(values, Load, EXTRA) }
|
| '(' values=open_sequence_pattern? ')' { _PyAST_Tuple(values, Load, EXTRA) }
|
||||||
open_sequence_pattern[asdl_seq*]:
|
open_sequence_pattern[asdl_seq*]:
|
||||||
| value=maybe_star_pattern ',' values=maybe_sequence_pattern? {
|
| value=maybe_star_pattern ',' values=maybe_sequence_pattern? {
|
||||||
_PyPegen_seq_insert_in_front(p, value, values) }
|
_PyPegen_seq_insert_in_front(p, value, values) }
|
||||||
|
@ -289,11 +289,11 @@ maybe_star_pattern[expr_ty]:
|
||||||
| pattern
|
| pattern
|
||||||
star_pattern[expr_ty]:
|
star_pattern[expr_ty]:
|
||||||
| '*' value=(capture_pattern | wildcard_pattern) {
|
| '*' value=(capture_pattern | wildcard_pattern) {
|
||||||
_Py_Starred(value, Store, EXTRA) }
|
_PyAST_Starred(value, Store, EXTRA) }
|
||||||
|
|
||||||
mapping_pattern[expr_ty]:
|
mapping_pattern[expr_ty]:
|
||||||
| '{' items=items_pattern? '}' {
|
| '{' items=items_pattern? '}' {
|
||||||
_Py_Dict(CHECK(asdl_expr_seq*, _PyPegen_get_keys(p, items)), CHECK(asdl_expr_seq*, _PyPegen_get_values(p, items)), EXTRA) }
|
_PyAST_Dict(CHECK(asdl_expr_seq*, _PyPegen_get_keys(p, items)), CHECK(asdl_expr_seq*, _PyPegen_get_values(p, items)), EXTRA) }
|
||||||
items_pattern[asdl_seq*]:
|
items_pattern[asdl_seq*]:
|
||||||
| items=','.key_value_pattern+ ','? { items }
|
| items=','.key_value_pattern+ ','? { items }
|
||||||
key_value_pattern[KeyValuePair*]:
|
key_value_pattern[KeyValuePair*]:
|
||||||
|
@ -304,26 +304,26 @@ double_star_pattern[KeyValuePair*]:
|
||||||
| '**' value=capture_pattern { _PyPegen_key_value_pair(p, NULL, value) }
|
| '**' value=capture_pattern { _PyPegen_key_value_pair(p, NULL, value) }
|
||||||
|
|
||||||
class_pattern[expr_ty]:
|
class_pattern[expr_ty]:
|
||||||
| func=name_or_attr '(' ')' { _Py_Call(func, NULL, NULL, EXTRA) }
|
| func=name_or_attr '(' ')' { _PyAST_Call(func, NULL, NULL, EXTRA) }
|
||||||
| func=name_or_attr '(' args=positional_patterns ','? ')' {
|
| func=name_or_attr '(' args=positional_patterns ','? ')' {
|
||||||
_Py_Call(func, args, NULL, EXTRA) }
|
_PyAST_Call(func, args, NULL, EXTRA) }
|
||||||
| func=name_or_attr '(' keywords=keyword_patterns ','? ')' {
|
| func=name_or_attr '(' keywords=keyword_patterns ','? ')' {
|
||||||
_Py_Call(func, NULL, keywords, EXTRA) }
|
_PyAST_Call(func, NULL, keywords, EXTRA) }
|
||||||
| func=name_or_attr '(' args=positional_patterns ',' keywords=keyword_patterns ','? ')' {
|
| func=name_or_attr '(' args=positional_patterns ',' keywords=keyword_patterns ','? ')' {
|
||||||
_Py_Call(func, args, keywords, EXTRA) }
|
_PyAST_Call(func, args, keywords, EXTRA) }
|
||||||
positional_patterns[asdl_expr_seq*]:
|
positional_patterns[asdl_expr_seq*]:
|
||||||
| args[asdl_expr_seq*]=','.pattern+ { args }
|
| args[asdl_expr_seq*]=','.pattern+ { args }
|
||||||
keyword_patterns[asdl_keyword_seq*]:
|
keyword_patterns[asdl_keyword_seq*]:
|
||||||
| keywords[asdl_keyword_seq*]=','.keyword_pattern+ { keywords }
|
| keywords[asdl_keyword_seq*]=','.keyword_pattern+ { keywords }
|
||||||
keyword_pattern[keyword_ty]:
|
keyword_pattern[keyword_ty]:
|
||||||
| arg=NAME '=' value=pattern { _Py_keyword(arg->v.Name.id, value, EXTRA) }
|
| arg=NAME '=' value=pattern { _PyAST_keyword(arg->v.Name.id, value, EXTRA) }
|
||||||
|
|
||||||
return_stmt[stmt_ty]:
|
return_stmt[stmt_ty]:
|
||||||
| 'return' a=[star_expressions] { _Py_Return(a, EXTRA) }
|
| 'return' a=[star_expressions] { _PyAST_Return(a, EXTRA) }
|
||||||
|
|
||||||
raise_stmt[stmt_ty]:
|
raise_stmt[stmt_ty]:
|
||||||
| 'raise' a=expression b=['from' z=expression { z }] { _Py_Raise(a, b, EXTRA) }
|
| 'raise' a=expression b=['from' z=expression { z }] { _PyAST_Raise(a, b, EXTRA) }
|
||||||
| 'raise' { _Py_Raise(NULL, NULL, EXTRA) }
|
| 'raise' { _PyAST_Raise(NULL, NULL, EXTRA) }
|
||||||
|
|
||||||
function_def[stmt_ty]:
|
function_def[stmt_ty]:
|
||||||
| d=decorators f=function_def_raw { _PyPegen_function_def_decorators(p, d, f) }
|
| d=decorators f=function_def_raw { _PyPegen_function_def_decorators(p, d, f) }
|
||||||
|
@ -331,7 +331,7 @@ function_def[stmt_ty]:
|
||||||
|
|
||||||
function_def_raw[stmt_ty]:
|
function_def_raw[stmt_ty]:
|
||||||
| 'def' n=NAME '(' params=[params] ')' a=['->' z=expression { z }] &&':' tc=[func_type_comment] b=block {
|
| 'def' n=NAME '(' params=[params] ')' a=['->' z=expression { z }] &&':' tc=[func_type_comment] b=block {
|
||||||
_Py_FunctionDef(n->v.Name.id,
|
_PyAST_FunctionDef(n->v.Name.id,
|
||||||
(params) ? params : CHECK(arguments_ty, _PyPegen_empty_arguments(p)),
|
(params) ? params : CHECK(arguments_ty, _PyPegen_empty_arguments(p)),
|
||||||
b, NULL, a, NEW_TYPE_COMMENT(p, tc), EXTRA) }
|
b, NULL, a, NEW_TYPE_COMMENT(p, tc), EXTRA) }
|
||||||
| ASYNC 'def' n=NAME '(' params=[params] ')' a=['->' z=expression { z }] &&':' tc=[func_type_comment] b=block {
|
| ASYNC 'def' n=NAME '(' params=[params] ')' a=['->' z=expression { z }] &&':' tc=[func_type_comment] b=block {
|
||||||
|
@ -339,7 +339,7 @@ function_def_raw[stmt_ty]:
|
||||||
stmt_ty,
|
stmt_ty,
|
||||||
5,
|
5,
|
||||||
"Async functions are",
|
"Async functions are",
|
||||||
_Py_AsyncFunctionDef(n->v.Name.id,
|
_PyAST_AsyncFunctionDef(n->v.Name.id,
|
||||||
(params) ? params : CHECK(arguments_ty, _PyPegen_empty_arguments(p)),
|
(params) ? params : CHECK(arguments_ty, _PyPegen_empty_arguments(p)),
|
||||||
b, NULL, a, NEW_TYPE_COMMENT(p, tc), EXTRA)
|
b, NULL, a, NEW_TYPE_COMMENT(p, tc), EXTRA)
|
||||||
) }
|
) }
|
||||||
|
@ -403,7 +403,7 @@ param_with_default[NameDefaultPair*]:
|
||||||
param_maybe_default[NameDefaultPair*]:
|
param_maybe_default[NameDefaultPair*]:
|
||||||
| a=param c=default? ',' tc=TYPE_COMMENT? { _PyPegen_name_default_pair(p, a, c, tc) }
|
| a=param c=default? ',' tc=TYPE_COMMENT? { _PyPegen_name_default_pair(p, a, c, tc) }
|
||||||
| a=param c=default? tc=TYPE_COMMENT? &')' { _PyPegen_name_default_pair(p, a, c, tc) }
|
| a=param c=default? tc=TYPE_COMMENT? &')' { _PyPegen_name_default_pair(p, a, c, tc) }
|
||||||
param[arg_ty]: a=NAME b=annotation? { _Py_arg(a->v.Name.id, b, NULL, EXTRA) }
|
param[arg_ty]: a=NAME b=annotation? { _PyAST_arg(a->v.Name.id, b, NULL, EXTRA) }
|
||||||
|
|
||||||
annotation[expr_ty]: ':' a=expression { a }
|
annotation[expr_ty]: ':' a=expression { a }
|
||||||
default[expr_ty]: '=' a=expression { a }
|
default[expr_ty]: '=' a=expression { a }
|
||||||
|
@ -415,7 +415,7 @@ class_def[stmt_ty]:
|
||||||
| class_def_raw
|
| class_def_raw
|
||||||
class_def_raw[stmt_ty]:
|
class_def_raw[stmt_ty]:
|
||||||
| 'class' a=NAME b=['(' z=[arguments] ')' { z }] &&':' c=block {
|
| 'class' a=NAME b=['(' z=[arguments] ')' { z }] &&':' c=block {
|
||||||
_Py_ClassDef(a->v.Name.id,
|
_PyAST_ClassDef(a->v.Name.id,
|
||||||
(b) ? ((expr_ty) b)->v.Call.args : NULL,
|
(b) ? ((expr_ty) b)->v.Call.args : NULL,
|
||||||
(b) ? ((expr_ty) b)->v.Call.keywords : NULL,
|
(b) ? ((expr_ty) b)->v.Call.keywords : NULL,
|
||||||
c, NULL, EXTRA) }
|
c, NULL, EXTRA) }
|
||||||
|
@ -427,19 +427,19 @@ block[asdl_stmt_seq*] (memo):
|
||||||
|
|
||||||
star_expressions[expr_ty]:
|
star_expressions[expr_ty]:
|
||||||
| a=star_expression b=(',' c=star_expression { c })+ [','] {
|
| a=star_expression b=(',' c=star_expression { c })+ [','] {
|
||||||
_Py_Tuple(CHECK(asdl_expr_seq*, _PyPegen_seq_insert_in_front(p, a, b)), Load, EXTRA) }
|
_PyAST_Tuple(CHECK(asdl_expr_seq*, _PyPegen_seq_insert_in_front(p, a, b)), Load, EXTRA) }
|
||||||
| a=star_expression ',' { _Py_Tuple(CHECK(asdl_expr_seq*, _PyPegen_singleton_seq(p, a)), Load, EXTRA) }
|
| a=star_expression ',' { _PyAST_Tuple(CHECK(asdl_expr_seq*, _PyPegen_singleton_seq(p, a)), Load, EXTRA) }
|
||||||
| star_expression
|
| star_expression
|
||||||
star_expression[expr_ty] (memo):
|
star_expression[expr_ty] (memo):
|
||||||
| '*' a=bitwise_or { _Py_Starred(a, Load, EXTRA) }
|
| '*' a=bitwise_or { _PyAST_Starred(a, Load, EXTRA) }
|
||||||
| expression
|
| expression
|
||||||
|
|
||||||
star_named_expressions[asdl_expr_seq*]: a[asdl_expr_seq*]=','.star_named_expression+ [','] { a }
|
star_named_expressions[asdl_expr_seq*]: a[asdl_expr_seq*]=','.star_named_expression+ [','] { a }
|
||||||
star_named_expression[expr_ty]:
|
star_named_expression[expr_ty]:
|
||||||
| '*' a=bitwise_or { _Py_Starred(a, Load, EXTRA) }
|
| '*' a=bitwise_or { _PyAST_Starred(a, Load, EXTRA) }
|
||||||
| named_expression
|
| named_expression
|
||||||
named_expression[expr_ty]:
|
named_expression[expr_ty]:
|
||||||
| a=NAME ':=' ~ b=expression { _Py_NamedExpr(CHECK(expr_ty, _PyPegen_set_expr_context(p, a, Store)), b, EXTRA) }
|
| a=NAME ':=' ~ b=expression { _PyAST_NamedExpr(CHECK(expr_ty, _PyPegen_set_expr_context(p, a, Store)), b, EXTRA) }
|
||||||
| expression !':='
|
| expression !':='
|
||||||
| invalid_named_expression
|
| invalid_named_expression
|
||||||
|
|
||||||
|
@ -447,17 +447,17 @@ annotated_rhs[expr_ty]: yield_expr | star_expressions
|
||||||
|
|
||||||
expressions[expr_ty]:
|
expressions[expr_ty]:
|
||||||
| a=expression b=(',' c=expression { c })+ [','] {
|
| a=expression b=(',' c=expression { c })+ [','] {
|
||||||
_Py_Tuple(CHECK(asdl_expr_seq*, _PyPegen_seq_insert_in_front(p, a, b)), Load, EXTRA) }
|
_PyAST_Tuple(CHECK(asdl_expr_seq*, _PyPegen_seq_insert_in_front(p, a, b)), Load, EXTRA) }
|
||||||
| a=expression ',' { _Py_Tuple(CHECK(asdl_expr_seq*, _PyPegen_singleton_seq(p, a)), Load, EXTRA) }
|
| a=expression ',' { _PyAST_Tuple(CHECK(asdl_expr_seq*, _PyPegen_singleton_seq(p, a)), Load, EXTRA) }
|
||||||
| expression
|
| expression
|
||||||
expression[expr_ty] (memo):
|
expression[expr_ty] (memo):
|
||||||
| a=disjunction 'if' b=disjunction 'else' c=expression { _Py_IfExp(b, a, c, EXTRA) }
|
| a=disjunction 'if' b=disjunction 'else' c=expression { _PyAST_IfExp(b, a, c, EXTRA) }
|
||||||
| disjunction
|
| disjunction
|
||||||
| lambdef
|
| lambdef
|
||||||
|
|
||||||
lambdef[expr_ty]:
|
lambdef[expr_ty]:
|
||||||
| 'lambda' a=[lambda_params] ':' b=expression {
|
| 'lambda' a=[lambda_params] ':' b=expression {
|
||||||
_Py_Lambda((a) ? a : CHECK(arguments_ty, _PyPegen_empty_arguments(p)), b, EXTRA) }
|
_PyAST_Lambda((a) ? a : CHECK(arguments_ty, _PyPegen_empty_arguments(p)), b, EXTRA) }
|
||||||
|
|
||||||
lambda_params[arguments_ty]:
|
lambda_params[arguments_ty]:
|
||||||
| invalid_lambda_parameters
|
| invalid_lambda_parameters
|
||||||
|
@ -503,26 +503,26 @@ lambda_param_with_default[NameDefaultPair*]:
|
||||||
lambda_param_maybe_default[NameDefaultPair*]:
|
lambda_param_maybe_default[NameDefaultPair*]:
|
||||||
| a=lambda_param c=default? ',' { _PyPegen_name_default_pair(p, a, c, NULL) }
|
| a=lambda_param c=default? ',' { _PyPegen_name_default_pair(p, a, c, NULL) }
|
||||||
| a=lambda_param c=default? &':' { _PyPegen_name_default_pair(p, a, c, NULL) }
|
| a=lambda_param c=default? &':' { _PyPegen_name_default_pair(p, a, c, NULL) }
|
||||||
lambda_param[arg_ty]: a=NAME { _Py_arg(a->v.Name.id, NULL, NULL, EXTRA) }
|
lambda_param[arg_ty]: a=NAME { _PyAST_arg(a->v.Name.id, NULL, NULL, EXTRA) }
|
||||||
|
|
||||||
disjunction[expr_ty] (memo):
|
disjunction[expr_ty] (memo):
|
||||||
| a=conjunction b=('or' c=conjunction { c })+ { _Py_BoolOp(
|
| a=conjunction b=('or' c=conjunction { c })+ { _PyAST_BoolOp(
|
||||||
Or,
|
Or,
|
||||||
CHECK(asdl_expr_seq*, _PyPegen_seq_insert_in_front(p, a, b)),
|
CHECK(asdl_expr_seq*, _PyPegen_seq_insert_in_front(p, a, b)),
|
||||||
EXTRA) }
|
EXTRA) }
|
||||||
| conjunction
|
| conjunction
|
||||||
conjunction[expr_ty] (memo):
|
conjunction[expr_ty] (memo):
|
||||||
| a=inversion b=('and' c=inversion { c })+ { _Py_BoolOp(
|
| a=inversion b=('and' c=inversion { c })+ { _PyAST_BoolOp(
|
||||||
And,
|
And,
|
||||||
CHECK(asdl_expr_seq*, _PyPegen_seq_insert_in_front(p, a, b)),
|
CHECK(asdl_expr_seq*, _PyPegen_seq_insert_in_front(p, a, b)),
|
||||||
EXTRA) }
|
EXTRA) }
|
||||||
| inversion
|
| inversion
|
||||||
inversion[expr_ty] (memo):
|
inversion[expr_ty] (memo):
|
||||||
| 'not' a=inversion { _Py_UnaryOp(Not, a, EXTRA) }
|
| 'not' a=inversion { _PyAST_UnaryOp(Not, a, EXTRA) }
|
||||||
| comparison
|
| comparison
|
||||||
comparison[expr_ty]:
|
comparison[expr_ty]:
|
||||||
| a=bitwise_or b=compare_op_bitwise_or_pair+ {
|
| a=bitwise_or b=compare_op_bitwise_or_pair+ {
|
||||||
_Py_Compare(
|
_PyAST_Compare(
|
||||||
a,
|
a,
|
||||||
CHECK(asdl_int_seq*, _PyPegen_get_cmpops(p, b)),
|
CHECK(asdl_int_seq*, _PyPegen_get_cmpops(p, b)),
|
||||||
CHECK(asdl_expr_seq*, _PyPegen_get_exprs(p, b)),
|
CHECK(asdl_expr_seq*, _PyPegen_get_exprs(p, b)),
|
||||||
|
@ -552,98 +552,98 @@ isnot_bitwise_or[CmpopExprPair*]: 'is' 'not' a=bitwise_or { _PyPegen_cmpop_expr_
|
||||||
is_bitwise_or[CmpopExprPair*]: 'is' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, Is, a) }
|
is_bitwise_or[CmpopExprPair*]: 'is' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, Is, a) }
|
||||||
|
|
||||||
bitwise_or[expr_ty]:
|
bitwise_or[expr_ty]:
|
||||||
| a=bitwise_or '|' b=bitwise_xor { _Py_BinOp(a, BitOr, b, EXTRA) }
|
| a=bitwise_or '|' b=bitwise_xor { _PyAST_BinOp(a, BitOr, b, EXTRA) }
|
||||||
| bitwise_xor
|
| bitwise_xor
|
||||||
bitwise_xor[expr_ty]:
|
bitwise_xor[expr_ty]:
|
||||||
| a=bitwise_xor '^' b=bitwise_and { _Py_BinOp(a, BitXor, b, EXTRA) }
|
| a=bitwise_xor '^' b=bitwise_and { _PyAST_BinOp(a, BitXor, b, EXTRA) }
|
||||||
| bitwise_and
|
| bitwise_and
|
||||||
bitwise_and[expr_ty]:
|
bitwise_and[expr_ty]:
|
||||||
| a=bitwise_and '&' b=shift_expr { _Py_BinOp(a, BitAnd, b, EXTRA) }
|
| a=bitwise_and '&' b=shift_expr { _PyAST_BinOp(a, BitAnd, b, EXTRA) }
|
||||||
| shift_expr
|
| shift_expr
|
||||||
shift_expr[expr_ty]:
|
shift_expr[expr_ty]:
|
||||||
| a=shift_expr '<<' b=sum { _Py_BinOp(a, LShift, b, EXTRA) }
|
| a=shift_expr '<<' b=sum { _PyAST_BinOp(a, LShift, b, EXTRA) }
|
||||||
| a=shift_expr '>>' b=sum { _Py_BinOp(a, RShift, b, EXTRA) }
|
| a=shift_expr '>>' b=sum { _PyAST_BinOp(a, RShift, b, EXTRA) }
|
||||||
| sum
|
| sum
|
||||||
|
|
||||||
sum[expr_ty]:
|
sum[expr_ty]:
|
||||||
| a=sum '+' b=term { _Py_BinOp(a, Add, b, EXTRA) }
|
| a=sum '+' b=term { _PyAST_BinOp(a, Add, b, EXTRA) }
|
||||||
| a=sum '-' b=term { _Py_BinOp(a, Sub, b, EXTRA) }
|
| a=sum '-' b=term { _PyAST_BinOp(a, Sub, b, EXTRA) }
|
||||||
| term
|
| term
|
||||||
term[expr_ty]:
|
term[expr_ty]:
|
||||||
| a=term '*' b=factor { _Py_BinOp(a, Mult, b, EXTRA) }
|
| a=term '*' b=factor { _PyAST_BinOp(a, Mult, b, EXTRA) }
|
||||||
| a=term '/' b=factor { _Py_BinOp(a, Div, b, EXTRA) }
|
| a=term '/' b=factor { _PyAST_BinOp(a, Div, b, EXTRA) }
|
||||||
| a=term '//' b=factor { _Py_BinOp(a, FloorDiv, b, EXTRA) }
|
| a=term '//' b=factor { _PyAST_BinOp(a, FloorDiv, b, EXTRA) }
|
||||||
| a=term '%' b=factor { _Py_BinOp(a, Mod, b, EXTRA) }
|
| a=term '%' b=factor { _PyAST_BinOp(a, Mod, b, EXTRA) }
|
||||||
| a=term '@' b=factor { CHECK_VERSION(expr_ty, 5, "The '@' operator is", _Py_BinOp(a, MatMult, b, EXTRA)) }
|
| a=term '@' b=factor { CHECK_VERSION(expr_ty, 5, "The '@' operator is", _PyAST_BinOp(a, MatMult, b, EXTRA)) }
|
||||||
| factor
|
| factor
|
||||||
factor[expr_ty] (memo):
|
factor[expr_ty] (memo):
|
||||||
| '+' a=factor { _Py_UnaryOp(UAdd, a, EXTRA) }
|
| '+' a=factor { _PyAST_UnaryOp(UAdd, a, EXTRA) }
|
||||||
| '-' a=factor { _Py_UnaryOp(USub, a, EXTRA) }
|
| '-' a=factor { _PyAST_UnaryOp(USub, a, EXTRA) }
|
||||||
| '~' a=factor { _Py_UnaryOp(Invert, a, EXTRA) }
|
| '~' a=factor { _PyAST_UnaryOp(Invert, a, EXTRA) }
|
||||||
| power
|
| power
|
||||||
power[expr_ty]:
|
power[expr_ty]:
|
||||||
| a=await_primary '**' b=factor { _Py_BinOp(a, Pow, b, EXTRA) }
|
| a=await_primary '**' b=factor { _PyAST_BinOp(a, Pow, b, EXTRA) }
|
||||||
| await_primary
|
| await_primary
|
||||||
await_primary[expr_ty] (memo):
|
await_primary[expr_ty] (memo):
|
||||||
| AWAIT a=primary { CHECK_VERSION(expr_ty, 5, "Await expressions are", _Py_Await(a, EXTRA)) }
|
| AWAIT a=primary { CHECK_VERSION(expr_ty, 5, "Await expressions are", _PyAST_Await(a, EXTRA)) }
|
||||||
| primary
|
| primary
|
||||||
primary[expr_ty]:
|
primary[expr_ty]:
|
||||||
| invalid_primary # must be before 'primay genexp' because of invalid_genexp
|
| invalid_primary # must be before 'primay genexp' because of invalid_genexp
|
||||||
| a=primary '.' b=NAME { _Py_Attribute(a, b->v.Name.id, Load, EXTRA) }
|
| a=primary '.' b=NAME { _PyAST_Attribute(a, b->v.Name.id, Load, EXTRA) }
|
||||||
| a=primary b=genexp { _Py_Call(a, CHECK(asdl_expr_seq*, (asdl_expr_seq*)_PyPegen_singleton_seq(p, b)), NULL, EXTRA) }
|
| a=primary b=genexp { _PyAST_Call(a, CHECK(asdl_expr_seq*, (asdl_expr_seq*)_PyPegen_singleton_seq(p, b)), NULL, EXTRA) }
|
||||||
| a=primary '(' b=[arguments] ')' {
|
| a=primary '(' b=[arguments] ')' {
|
||||||
_Py_Call(a,
|
_PyAST_Call(a,
|
||||||
(b) ? ((expr_ty) b)->v.Call.args : NULL,
|
(b) ? ((expr_ty) b)->v.Call.args : NULL,
|
||||||
(b) ? ((expr_ty) b)->v.Call.keywords : NULL,
|
(b) ? ((expr_ty) b)->v.Call.keywords : NULL,
|
||||||
EXTRA) }
|
EXTRA) }
|
||||||
| a=primary '[' b=slices ']' { _Py_Subscript(a, b, Load, EXTRA) }
|
| a=primary '[' b=slices ']' { _PyAST_Subscript(a, b, Load, EXTRA) }
|
||||||
| atom
|
| atom
|
||||||
|
|
||||||
slices[expr_ty]:
|
slices[expr_ty]:
|
||||||
| a=slice !',' { a }
|
| a=slice !',' { a }
|
||||||
| a[asdl_expr_seq*]=','.slice+ [','] { _Py_Tuple(a, Load, EXTRA) }
|
| a[asdl_expr_seq*]=','.slice+ [','] { _PyAST_Tuple(a, Load, EXTRA) }
|
||||||
slice[expr_ty]:
|
slice[expr_ty]:
|
||||||
| a=[expression] ':' b=[expression] c=[':' d=[expression] { d }] { _Py_Slice(a, b, c, EXTRA) }
|
| a=[expression] ':' b=[expression] c=[':' d=[expression] { d }] { _PyAST_Slice(a, b, c, EXTRA) }
|
||||||
| a=named_expression { a }
|
| a=named_expression { a }
|
||||||
atom[expr_ty]:
|
atom[expr_ty]:
|
||||||
| NAME
|
| NAME
|
||||||
| 'True' { _Py_Constant(Py_True, NULL, EXTRA) }
|
| 'True' { _PyAST_Constant(Py_True, NULL, EXTRA) }
|
||||||
| 'False' { _Py_Constant(Py_False, NULL, EXTRA) }
|
| 'False' { _PyAST_Constant(Py_False, NULL, EXTRA) }
|
||||||
| 'None' { _Py_Constant(Py_None, NULL, EXTRA) }
|
| 'None' { _PyAST_Constant(Py_None, NULL, EXTRA) }
|
||||||
| &STRING strings
|
| &STRING strings
|
||||||
| NUMBER
|
| NUMBER
|
||||||
| &'(' (tuple | group | genexp)
|
| &'(' (tuple | group | genexp)
|
||||||
| &'[' (list | listcomp)
|
| &'[' (list | listcomp)
|
||||||
| &'{' (dict | set | dictcomp | setcomp)
|
| &'{' (dict | set | dictcomp | setcomp)
|
||||||
| '...' { _Py_Constant(Py_Ellipsis, NULL, EXTRA) }
|
| '...' { _PyAST_Constant(Py_Ellipsis, NULL, EXTRA) }
|
||||||
|
|
||||||
strings[expr_ty] (memo): a=STRING+ { _PyPegen_concatenate_strings(p, a) }
|
strings[expr_ty] (memo): a=STRING+ { _PyPegen_concatenate_strings(p, a) }
|
||||||
list[expr_ty]:
|
list[expr_ty]:
|
||||||
| '[' a=[star_named_expressions] ']' { _Py_List(a, Load, EXTRA) }
|
| '[' a=[star_named_expressions] ']' { _PyAST_List(a, Load, EXTRA) }
|
||||||
listcomp[expr_ty]:
|
listcomp[expr_ty]:
|
||||||
| '[' a=named_expression b=for_if_clauses ']' { _Py_ListComp(a, b, EXTRA) }
|
| '[' a=named_expression b=for_if_clauses ']' { _PyAST_ListComp(a, b, EXTRA) }
|
||||||
| invalid_comprehension
|
| invalid_comprehension
|
||||||
tuple[expr_ty]:
|
tuple[expr_ty]:
|
||||||
| '(' a=[y=star_named_expression ',' z=[star_named_expressions] { _PyPegen_seq_insert_in_front(p, y, z) } ] ')' {
|
| '(' a=[y=star_named_expression ',' z=[star_named_expressions] { _PyPegen_seq_insert_in_front(p, y, z) } ] ')' {
|
||||||
_Py_Tuple(a, Load, EXTRA) }
|
_PyAST_Tuple(a, Load, EXTRA) }
|
||||||
group[expr_ty]:
|
group[expr_ty]:
|
||||||
| '(' a=(yield_expr | named_expression) ')' { a }
|
| '(' a=(yield_expr | named_expression) ')' { a }
|
||||||
| invalid_group
|
| invalid_group
|
||||||
genexp[expr_ty]:
|
genexp[expr_ty]:
|
||||||
| '(' a=named_expression b=for_if_clauses ')' { _Py_GeneratorExp(a, b, EXTRA) }
|
| '(' a=named_expression b=for_if_clauses ')' { _PyAST_GeneratorExp(a, b, EXTRA) }
|
||||||
| invalid_comprehension
|
| invalid_comprehension
|
||||||
set[expr_ty]: '{' a=star_named_expressions '}' { _Py_Set(a, EXTRA) }
|
set[expr_ty]: '{' a=star_named_expressions '}' { _PyAST_Set(a, EXTRA) }
|
||||||
setcomp[expr_ty]:
|
setcomp[expr_ty]:
|
||||||
| '{' a=named_expression b=for_if_clauses '}' { _Py_SetComp(a, b, EXTRA) }
|
| '{' a=named_expression b=for_if_clauses '}' { _PyAST_SetComp(a, b, EXTRA) }
|
||||||
| invalid_comprehension
|
| invalid_comprehension
|
||||||
dict[expr_ty]:
|
dict[expr_ty]:
|
||||||
| '{' a=[double_starred_kvpairs] '}' {
|
| '{' a=[double_starred_kvpairs] '}' {
|
||||||
_Py_Dict(
|
_PyAST_Dict(
|
||||||
CHECK(asdl_expr_seq*, _PyPegen_get_keys(p, a)),
|
CHECK(asdl_expr_seq*, _PyPegen_get_keys(p, a)),
|
||||||
CHECK(asdl_expr_seq*, _PyPegen_get_values(p, a)),
|
CHECK(asdl_expr_seq*, _PyPegen_get_values(p, a)),
|
||||||
EXTRA) }
|
EXTRA) }
|
||||||
dictcomp[expr_ty]:
|
dictcomp[expr_ty]:
|
||||||
| '{' a=kvpair b=for_if_clauses '}' { _Py_DictComp(a->key, a->value, b, EXTRA) }
|
| '{' a=kvpair b=for_if_clauses '}' { _PyAST_DictComp(a->key, a->value, b, EXTRA) }
|
||||||
| invalid_dict_comprehension
|
| invalid_dict_comprehension
|
||||||
double_starred_kvpairs[asdl_seq*]: a=','.double_starred_kvpair+ [','] { a }
|
double_starred_kvpairs[asdl_seq*]: a=','.double_starred_kvpair+ [','] { a }
|
||||||
double_starred_kvpair[KeyValuePair*]:
|
double_starred_kvpair[KeyValuePair*]:
|
||||||
|
@ -654,21 +654,21 @@ for_if_clauses[asdl_comprehension_seq*]:
|
||||||
| a[asdl_comprehension_seq*]=for_if_clause+ { a }
|
| a[asdl_comprehension_seq*]=for_if_clause+ { a }
|
||||||
for_if_clause[comprehension_ty]:
|
for_if_clause[comprehension_ty]:
|
||||||
| ASYNC 'for' a=star_targets 'in' ~ b=disjunction c[asdl_expr_seq*]=('if' z=disjunction { z })* {
|
| ASYNC 'for' a=star_targets 'in' ~ b=disjunction c[asdl_expr_seq*]=('if' z=disjunction { z })* {
|
||||||
CHECK_VERSION(comprehension_ty, 6, "Async comprehensions are", _Py_comprehension(a, b, c, 1, p->arena)) }
|
CHECK_VERSION(comprehension_ty, 6, "Async comprehensions are", _PyAST_comprehension(a, b, c, 1, p->arena)) }
|
||||||
| 'for' a=star_targets 'in' ~ b=disjunction c[asdl_expr_seq*]=('if' z=disjunction { z })* {
|
| 'for' a=star_targets 'in' ~ b=disjunction c[asdl_expr_seq*]=('if' z=disjunction { z })* {
|
||||||
_Py_comprehension(a, b, c, 0, p->arena) }
|
_PyAST_comprehension(a, b, c, 0, p->arena) }
|
||||||
| invalid_for_target
|
| invalid_for_target
|
||||||
|
|
||||||
yield_expr[expr_ty]:
|
yield_expr[expr_ty]:
|
||||||
| 'yield' 'from' a=expression { _Py_YieldFrom(a, EXTRA) }
|
| 'yield' 'from' a=expression { _PyAST_YieldFrom(a, EXTRA) }
|
||||||
| 'yield' a=[star_expressions] { _Py_Yield(a, EXTRA) }
|
| 'yield' a=[star_expressions] { _PyAST_Yield(a, EXTRA) }
|
||||||
|
|
||||||
arguments[expr_ty] (memo):
|
arguments[expr_ty] (memo):
|
||||||
| a=args [','] &')' { a }
|
| a=args [','] &')' { a }
|
||||||
| invalid_arguments
|
| invalid_arguments
|
||||||
args[expr_ty]:
|
args[expr_ty]:
|
||||||
| a[asdl_expr_seq*]=','.(starred_expression | named_expression !'=')+ b=[',' k=kwargs {k}] { _PyPegen_collect_call_seqs(p, a, b, EXTRA) }
|
| a[asdl_expr_seq*]=','.(starred_expression | named_expression !'=')+ b=[',' k=kwargs {k}] { _PyPegen_collect_call_seqs(p, a, b, EXTRA) }
|
||||||
| a=kwargs { _Py_Call(_PyPegen_dummy_name(p),
|
| a=kwargs { _PyAST_Call(_PyPegen_dummy_name(p),
|
||||||
CHECK_NULL_ALLOWED(asdl_expr_seq*, _PyPegen_seq_extract_starred_exprs(p, a)),
|
CHECK_NULL_ALLOWED(asdl_expr_seq*, _PyPegen_seq_extract_starred_exprs(p, a)),
|
||||||
CHECK_NULL_ALLOWED(asdl_keyword_seq*, _PyPegen_seq_delete_starred_exprs(p, a)),
|
CHECK_NULL_ALLOWED(asdl_keyword_seq*, _PyPegen_seq_delete_starred_exprs(p, a)),
|
||||||
EXTRA) }
|
EXTRA) }
|
||||||
|
@ -677,72 +677,72 @@ kwargs[asdl_seq*]:
|
||||||
| ','.kwarg_or_starred+
|
| ','.kwarg_or_starred+
|
||||||
| ','.kwarg_or_double_starred+
|
| ','.kwarg_or_double_starred+
|
||||||
starred_expression[expr_ty]:
|
starred_expression[expr_ty]:
|
||||||
| '*' a=expression { _Py_Starred(a, Load, EXTRA) }
|
| '*' a=expression { _PyAST_Starred(a, Load, EXTRA) }
|
||||||
kwarg_or_starred[KeywordOrStarred*]:
|
kwarg_or_starred[KeywordOrStarred*]:
|
||||||
| a=NAME '=' b=expression {
|
| a=NAME '=' b=expression {
|
||||||
_PyPegen_keyword_or_starred(p, CHECK(keyword_ty, _Py_keyword(a->v.Name.id, b, EXTRA)), 1) }
|
_PyPegen_keyword_or_starred(p, CHECK(keyword_ty, _PyAST_keyword(a->v.Name.id, b, EXTRA)), 1) }
|
||||||
| a=starred_expression { _PyPegen_keyword_or_starred(p, a, 0) }
|
| a=starred_expression { _PyPegen_keyword_or_starred(p, a, 0) }
|
||||||
| invalid_kwarg
|
| invalid_kwarg
|
||||||
kwarg_or_double_starred[KeywordOrStarred*]:
|
kwarg_or_double_starred[KeywordOrStarred*]:
|
||||||
| a=NAME '=' b=expression {
|
| a=NAME '=' b=expression {
|
||||||
_PyPegen_keyword_or_starred(p, CHECK(keyword_ty, _Py_keyword(a->v.Name.id, b, EXTRA)), 1) }
|
_PyPegen_keyword_or_starred(p, CHECK(keyword_ty, _PyAST_keyword(a->v.Name.id, b, EXTRA)), 1) }
|
||||||
| '**' a=expression { _PyPegen_keyword_or_starred(p, CHECK(keyword_ty, _Py_keyword(NULL, a, EXTRA)), 1) }
|
| '**' a=expression { _PyPegen_keyword_or_starred(p, CHECK(keyword_ty, _PyAST_keyword(NULL, a, EXTRA)), 1) }
|
||||||
| invalid_kwarg
|
| invalid_kwarg
|
||||||
|
|
||||||
# NOTE: star_targets may contain *bitwise_or, targets may not.
|
# NOTE: star_targets may contain *bitwise_or, targets may not.
|
||||||
star_targets[expr_ty]:
|
star_targets[expr_ty]:
|
||||||
| a=star_target !',' { a }
|
| a=star_target !',' { a }
|
||||||
| a=star_target b=(',' c=star_target { c })* [','] {
|
| a=star_target b=(',' c=star_target { c })* [','] {
|
||||||
_Py_Tuple(CHECK(asdl_expr_seq*, _PyPegen_seq_insert_in_front(p, a, b)), Store, EXTRA) }
|
_PyAST_Tuple(CHECK(asdl_expr_seq*, _PyPegen_seq_insert_in_front(p, a, b)), Store, EXTRA) }
|
||||||
star_targets_list_seq[asdl_expr_seq*]: a[asdl_expr_seq*]=','.star_target+ [','] { a }
|
star_targets_list_seq[asdl_expr_seq*]: a[asdl_expr_seq*]=','.star_target+ [','] { a }
|
||||||
star_targets_tuple_seq[asdl_expr_seq*]:
|
star_targets_tuple_seq[asdl_expr_seq*]:
|
||||||
| a=star_target b=(',' c=star_target { c })+ [','] { (asdl_expr_seq*) _PyPegen_seq_insert_in_front(p, a, b) }
|
| a=star_target b=(',' c=star_target { c })+ [','] { (asdl_expr_seq*) _PyPegen_seq_insert_in_front(p, a, b) }
|
||||||
| a=star_target ',' { (asdl_expr_seq*) _PyPegen_singleton_seq(p, a) }
|
| a=star_target ',' { (asdl_expr_seq*) _PyPegen_singleton_seq(p, a) }
|
||||||
star_target[expr_ty] (memo):
|
star_target[expr_ty] (memo):
|
||||||
| '*' a=(!'*' star_target) {
|
| '*' a=(!'*' star_target) {
|
||||||
_Py_Starred(CHECK(expr_ty, _PyPegen_set_expr_context(p, a, Store)), Store, EXTRA) }
|
_PyAST_Starred(CHECK(expr_ty, _PyPegen_set_expr_context(p, a, Store)), Store, EXTRA) }
|
||||||
| target_with_star_atom
|
| target_with_star_atom
|
||||||
target_with_star_atom[expr_ty] (memo):
|
target_with_star_atom[expr_ty] (memo):
|
||||||
| a=t_primary '.' b=NAME !t_lookahead { _Py_Attribute(a, b->v.Name.id, Store, EXTRA) }
|
| a=t_primary '.' b=NAME !t_lookahead { _PyAST_Attribute(a, b->v.Name.id, Store, EXTRA) }
|
||||||
| a=t_primary '[' b=slices ']' !t_lookahead { _Py_Subscript(a, b, Store, EXTRA) }
|
| a=t_primary '[' b=slices ']' !t_lookahead { _PyAST_Subscript(a, b, Store, EXTRA) }
|
||||||
| star_atom
|
| star_atom
|
||||||
star_atom[expr_ty]:
|
star_atom[expr_ty]:
|
||||||
| a=NAME { _PyPegen_set_expr_context(p, a, Store) }
|
| a=NAME { _PyPegen_set_expr_context(p, a, Store) }
|
||||||
| '(' a=target_with_star_atom ')' { _PyPegen_set_expr_context(p, a, Store) }
|
| '(' a=target_with_star_atom ')' { _PyPegen_set_expr_context(p, a, Store) }
|
||||||
| '(' a=[star_targets_tuple_seq] ')' { _Py_Tuple(a, Store, EXTRA) }
|
| '(' a=[star_targets_tuple_seq] ')' { _PyAST_Tuple(a, Store, EXTRA) }
|
||||||
| '[' a=[star_targets_list_seq] ']' { _Py_List(a, Store, EXTRA) }
|
| '[' a=[star_targets_list_seq] ']' { _PyAST_List(a, Store, EXTRA) }
|
||||||
|
|
||||||
single_target[expr_ty]:
|
single_target[expr_ty]:
|
||||||
| single_subscript_attribute_target
|
| single_subscript_attribute_target
|
||||||
| a=NAME { _PyPegen_set_expr_context(p, a, Store) }
|
| a=NAME { _PyPegen_set_expr_context(p, a, Store) }
|
||||||
| '(' a=single_target ')' { a }
|
| '(' a=single_target ')' { a }
|
||||||
single_subscript_attribute_target[expr_ty]:
|
single_subscript_attribute_target[expr_ty]:
|
||||||
| a=t_primary '.' b=NAME !t_lookahead { _Py_Attribute(a, b->v.Name.id, Store, EXTRA) }
|
| a=t_primary '.' b=NAME !t_lookahead { _PyAST_Attribute(a, b->v.Name.id, Store, EXTRA) }
|
||||||
| a=t_primary '[' b=slices ']' !t_lookahead { _Py_Subscript(a, b, Store, EXTRA) }
|
| a=t_primary '[' b=slices ']' !t_lookahead { _PyAST_Subscript(a, b, Store, EXTRA) }
|
||||||
|
|
||||||
del_targets[asdl_expr_seq*]: a[asdl_expr_seq*]=','.del_target+ [','] { a }
|
del_targets[asdl_expr_seq*]: a[asdl_expr_seq*]=','.del_target+ [','] { a }
|
||||||
del_target[expr_ty] (memo):
|
del_target[expr_ty] (memo):
|
||||||
| a=t_primary '.' b=NAME !t_lookahead { _Py_Attribute(a, b->v.Name.id, Del, EXTRA) }
|
| a=t_primary '.' b=NAME !t_lookahead { _PyAST_Attribute(a, b->v.Name.id, Del, EXTRA) }
|
||||||
| a=t_primary '[' b=slices ']' !t_lookahead { _Py_Subscript(a, b, Del, EXTRA) }
|
| a=t_primary '[' b=slices ']' !t_lookahead { _PyAST_Subscript(a, b, Del, EXTRA) }
|
||||||
| del_t_atom
|
| del_t_atom
|
||||||
del_t_atom[expr_ty]:
|
del_t_atom[expr_ty]:
|
||||||
| a=NAME { _PyPegen_set_expr_context(p, a, Del) }
|
| a=NAME { _PyPegen_set_expr_context(p, a, Del) }
|
||||||
| '(' a=del_target ')' { _PyPegen_set_expr_context(p, a, Del) }
|
| '(' a=del_target ')' { _PyPegen_set_expr_context(p, a, Del) }
|
||||||
| '(' a=[del_targets] ')' { _Py_Tuple(a, Del, EXTRA) }
|
| '(' a=[del_targets] ')' { _PyAST_Tuple(a, Del, EXTRA) }
|
||||||
| '[' a=[del_targets] ']' { _Py_List(a, Del, EXTRA) }
|
| '[' a=[del_targets] ']' { _PyAST_List(a, Del, EXTRA) }
|
||||||
|
|
||||||
targets[asdl_expr_seq*]: a[asdl_expr_seq*]=','.target+ [','] { a }
|
targets[asdl_expr_seq*]: a[asdl_expr_seq*]=','.target+ [','] { a }
|
||||||
target[expr_ty] (memo):
|
target[expr_ty] (memo):
|
||||||
| a=t_primary '.' b=NAME !t_lookahead { _Py_Attribute(a, b->v.Name.id, Store, EXTRA) }
|
| a=t_primary '.' b=NAME !t_lookahead { _PyAST_Attribute(a, b->v.Name.id, Store, EXTRA) }
|
||||||
| a=t_primary '[' b=slices ']' !t_lookahead { _Py_Subscript(a, b, Store, EXTRA) }
|
| a=t_primary '[' b=slices ']' !t_lookahead { _PyAST_Subscript(a, b, Store, EXTRA) }
|
||||||
| t_atom
|
| t_atom
|
||||||
t_primary[expr_ty]:
|
t_primary[expr_ty]:
|
||||||
| a=t_primary '.' b=NAME &t_lookahead { _Py_Attribute(a, b->v.Name.id, Load, EXTRA) }
|
| a=t_primary '.' b=NAME &t_lookahead { _PyAST_Attribute(a, b->v.Name.id, Load, EXTRA) }
|
||||||
| a=t_primary '[' b=slices ']' &t_lookahead { _Py_Subscript(a, b, Load, EXTRA) }
|
| a=t_primary '[' b=slices ']' &t_lookahead { _PyAST_Subscript(a, b, Load, EXTRA) }
|
||||||
| a=t_primary b=genexp &t_lookahead {
|
| a=t_primary b=genexp &t_lookahead {
|
||||||
_Py_Call(a, CHECK(asdl_expr_seq*, (asdl_expr_seq*)_PyPegen_singleton_seq(p, b)), NULL, EXTRA) }
|
_PyAST_Call(a, CHECK(asdl_expr_seq*, (asdl_expr_seq*)_PyPegen_singleton_seq(p, b)), NULL, EXTRA) }
|
||||||
| a=t_primary '(' b=[arguments] ')' &t_lookahead {
|
| a=t_primary '(' b=[arguments] ')' &t_lookahead {
|
||||||
_Py_Call(a,
|
_PyAST_Call(a,
|
||||||
(b) ? ((expr_ty) b)->v.Call.args : NULL,
|
(b) ? ((expr_ty) b)->v.Call.args : NULL,
|
||||||
(b) ? ((expr_ty) b)->v.Call.keywords : NULL,
|
(b) ? ((expr_ty) b)->v.Call.keywords : NULL,
|
||||||
EXTRA) }
|
EXTRA) }
|
||||||
|
@ -751,8 +751,8 @@ t_lookahead: '(' | '[' | '.'
|
||||||
t_atom[expr_ty]:
|
t_atom[expr_ty]:
|
||||||
| a=NAME { _PyPegen_set_expr_context(p, a, Store) }
|
| a=NAME { _PyPegen_set_expr_context(p, a, Store) }
|
||||||
| '(' a=target ')' { _PyPegen_set_expr_context(p, a, Store) }
|
| '(' a=target ')' { _PyPegen_set_expr_context(p, a, Store) }
|
||||||
| '(' b=[targets] ')' { _Py_Tuple(b, Store, EXTRA) }
|
| '(' b=[targets] ')' { _PyAST_Tuple(b, Store, EXTRA) }
|
||||||
| '[' b=[targets] ']' { _Py_List(b, Store, EXTRA) }
|
| '[' b=[targets] ']' { _PyAST_List(b, Store, EXTRA) }
|
||||||
|
|
||||||
|
|
||||||
# From here on, there are rules for invalid syntax with specialised error messages
|
# From here on, there are rules for invalid syntax with specialised error messages
|
||||||
|
@ -856,7 +856,7 @@ invalid_except_block:
|
||||||
| 'except' a=expression ',' expressions ['as' NAME ] ':' {
|
| 'except' a=expression ',' expressions ['as' NAME ] ':' {
|
||||||
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "exception group must be parenthesized") }
|
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "exception group must be parenthesized") }
|
||||||
| 'except' expression ['as' NAME ] &&':'
|
| 'except' expression ['as' NAME ] &&':'
|
||||||
| 'except' &&':'
|
| 'except' &&':'
|
||||||
|
|
||||||
invalid_match_stmt:
|
invalid_match_stmt:
|
||||||
| "match" subject_expr !':' { CHECK_VERSION(void*, 10, "Pattern matching is", RAISE_SYNTAX_ERROR("expected ':'") ) }
|
| "match" subject_expr !':' { CHECK_VERSION(void*, 10, "Pattern matching is", RAISE_SYNTAX_ERROR("expected ':'") ) }
|
||||||
|
|
|
@ -570,252 +570,193 @@ struct _type_ignore {
|
||||||
|
|
||||||
|
|
||||||
// Note: these macros affect function definitions, not only call sites.
|
// Note: these macros affect function definitions, not only call sites.
|
||||||
#define Module(a0, a1, a2) _Py_Module(a0, a1, a2)
|
mod_ty _PyAST_Module(asdl_stmt_seq * body, asdl_type_ignore_seq * type_ignores,
|
||||||
mod_ty _Py_Module(asdl_stmt_seq * body, asdl_type_ignore_seq * type_ignores,
|
|
||||||
PyArena *arena);
|
|
||||||
#define Interactive(a0, a1) _Py_Interactive(a0, a1)
|
|
||||||
mod_ty _Py_Interactive(asdl_stmt_seq * body, PyArena *arena);
|
|
||||||
#define Expression(a0, a1) _Py_Expression(a0, a1)
|
|
||||||
mod_ty _Py_Expression(expr_ty body, PyArena *arena);
|
|
||||||
#define FunctionType(a0, a1, a2) _Py_FunctionType(a0, a1, a2)
|
|
||||||
mod_ty _Py_FunctionType(asdl_expr_seq * argtypes, expr_ty returns, PyArena
|
|
||||||
*arena);
|
|
||||||
#define FunctionDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) _Py_FunctionDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
|
|
||||||
stmt_ty _Py_FunctionDef(identifier name, arguments_ty args, asdl_stmt_seq *
|
|
||||||
body, asdl_expr_seq * decorator_list, expr_ty returns,
|
|
||||||
string type_comment, int lineno, int col_offset, int
|
|
||||||
end_lineno, int end_col_offset, PyArena *arena);
|
|
||||||
#define AsyncFunctionDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) _Py_AsyncFunctionDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
|
|
||||||
stmt_ty _Py_AsyncFunctionDef(identifier name, arguments_ty args, asdl_stmt_seq
|
|
||||||
* body, asdl_expr_seq * decorator_list, expr_ty
|
|
||||||
returns, string type_comment, int lineno, int
|
|
||||||
col_offset, int end_lineno, int end_col_offset,
|
|
||||||
PyArena *arena);
|
|
||||||
#define ClassDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) _Py_ClassDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9)
|
|
||||||
stmt_ty _Py_ClassDef(identifier name, asdl_expr_seq * bases, asdl_keyword_seq *
|
|
||||||
keywords, asdl_stmt_seq * body, asdl_expr_seq *
|
|
||||||
decorator_list, int lineno, int col_offset, int
|
|
||||||
end_lineno, int end_col_offset, PyArena *arena);
|
|
||||||
#define Return(a0, a1, a2, a3, a4, a5) _Py_Return(a0, a1, a2, a3, a4, a5)
|
|
||||||
stmt_ty _Py_Return(expr_ty value, int lineno, int col_offset, int end_lineno,
|
|
||||||
int end_col_offset, PyArena *arena);
|
|
||||||
#define Delete(a0, a1, a2, a3, a4, a5) _Py_Delete(a0, a1, a2, a3, a4, a5)
|
|
||||||
stmt_ty _Py_Delete(asdl_expr_seq * targets, int lineno, int col_offset, int
|
|
||||||
end_lineno, int end_col_offset, PyArena *arena);
|
|
||||||
#define Assign(a0, a1, a2, a3, a4, a5, a6, a7) _Py_Assign(a0, a1, a2, a3, a4, a5, a6, a7)
|
|
||||||
stmt_ty _Py_Assign(asdl_expr_seq * targets, expr_ty value, string type_comment,
|
|
||||||
int lineno, int col_offset, int end_lineno, int
|
|
||||||
end_col_offset, PyArena *arena);
|
|
||||||
#define AugAssign(a0, a1, a2, a3, a4, a5, a6, a7) _Py_AugAssign(a0, a1, a2, a3, a4, a5, a6, a7)
|
|
||||||
stmt_ty _Py_AugAssign(expr_ty target, operator_ty op, expr_ty value, int
|
|
||||||
lineno, int col_offset, int end_lineno, int
|
|
||||||
end_col_offset, PyArena *arena);
|
|
||||||
#define AnnAssign(a0, a1, a2, a3, a4, a5, a6, a7, a8) _Py_AnnAssign(a0, a1, a2, a3, a4, a5, a6, a7, a8)
|
|
||||||
stmt_ty _Py_AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int
|
|
||||||
simple, int lineno, int col_offset, int end_lineno, int
|
|
||||||
end_col_offset, PyArena *arena);
|
|
||||||
#define For(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) _Py_For(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9)
|
|
||||||
stmt_ty _Py_For(expr_ty target, expr_ty iter, asdl_stmt_seq * body,
|
|
||||||
asdl_stmt_seq * orelse, string type_comment, int lineno, int
|
|
||||||
col_offset, int end_lineno, int end_col_offset, PyArena *arena);
|
|
||||||
#define AsyncFor(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) _Py_AsyncFor(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9)
|
|
||||||
stmt_ty _Py_AsyncFor(expr_ty target, expr_ty iter, asdl_stmt_seq * body,
|
|
||||||
asdl_stmt_seq * orelse, string type_comment, int lineno,
|
|
||||||
int col_offset, int end_lineno, int end_col_offset,
|
|
||||||
PyArena *arena);
|
PyArena *arena);
|
||||||
#define While(a0, a1, a2, a3, a4, a5, a6, a7) _Py_While(a0, a1, a2, a3, a4, a5, a6, a7)
|
mod_ty _PyAST_Interactive(asdl_stmt_seq * body, PyArena *arena);
|
||||||
stmt_ty _Py_While(expr_ty test, asdl_stmt_seq * body, asdl_stmt_seq * orelse,
|
mod_ty _PyAST_Expression(expr_ty body, PyArena *arena);
|
||||||
int lineno, int col_offset, int end_lineno, int
|
mod_ty _PyAST_FunctionType(asdl_expr_seq * argtypes, expr_ty returns, PyArena
|
||||||
end_col_offset, PyArena *arena);
|
*arena);
|
||||||
#define If(a0, a1, a2, a3, a4, a5, a6, a7) _Py_If(a0, a1, a2, a3, a4, a5, a6, a7)
|
stmt_ty _PyAST_FunctionDef(identifier name, arguments_ty args, asdl_stmt_seq *
|
||||||
stmt_ty _Py_If(expr_ty test, asdl_stmt_seq * body, asdl_stmt_seq * orelse, int
|
body, asdl_expr_seq * decorator_list, expr_ty
|
||||||
lineno, int col_offset, int end_lineno, int end_col_offset,
|
returns, string type_comment, int lineno, int
|
||||||
PyArena *arena);
|
col_offset, int end_lineno, int end_col_offset,
|
||||||
#define With(a0, a1, a2, a3, a4, a5, a6, a7) _Py_With(a0, a1, a2, a3, a4, a5, a6, a7)
|
PyArena *arena);
|
||||||
stmt_ty _Py_With(asdl_withitem_seq * items, asdl_stmt_seq * body, string
|
stmt_ty _PyAST_AsyncFunctionDef(identifier name, arguments_ty args,
|
||||||
type_comment, int lineno, int col_offset, int end_lineno, int
|
asdl_stmt_seq * body, asdl_expr_seq *
|
||||||
end_col_offset, PyArena *arena);
|
decorator_list, expr_ty returns, string
|
||||||
#define AsyncWith(a0, a1, a2, a3, a4, a5, a6, a7) _Py_AsyncWith(a0, a1, a2, a3, a4, a5, a6, a7)
|
type_comment, int lineno, int col_offset, int
|
||||||
stmt_ty _Py_AsyncWith(asdl_withitem_seq * items, asdl_stmt_seq * body, string
|
end_lineno, int end_col_offset, PyArena *arena);
|
||||||
|
stmt_ty _PyAST_ClassDef(identifier name, asdl_expr_seq * bases,
|
||||||
|
asdl_keyword_seq * keywords, asdl_stmt_seq * body,
|
||||||
|
asdl_expr_seq * decorator_list, int lineno, int
|
||||||
|
col_offset, int end_lineno, int end_col_offset, PyArena
|
||||||
|
*arena);
|
||||||
|
stmt_ty _PyAST_Return(expr_ty value, int lineno, int col_offset, int
|
||||||
|
end_lineno, int end_col_offset, PyArena *arena);
|
||||||
|
stmt_ty _PyAST_Delete(asdl_expr_seq * targets, int lineno, int col_offset, int
|
||||||
|
end_lineno, int end_col_offset, PyArena *arena);
|
||||||
|
stmt_ty _PyAST_Assign(asdl_expr_seq * targets, expr_ty value, string
|
||||||
type_comment, int lineno, int col_offset, int end_lineno,
|
type_comment, int lineno, int col_offset, int end_lineno,
|
||||||
int end_col_offset, PyArena *arena);
|
int end_col_offset, PyArena *arena);
|
||||||
#define Match(a0, a1, a2, a3, a4, a5, a6) _Py_Match(a0, a1, a2, a3, a4, a5, a6)
|
stmt_ty _PyAST_AugAssign(expr_ty target, operator_ty op, expr_ty value, int
|
||||||
stmt_ty _Py_Match(expr_ty subject, asdl_match_case_seq * cases, int lineno, int
|
|
||||||
col_offset, int end_lineno, int end_col_offset, PyArena
|
|
||||||
*arena);
|
|
||||||
#define Raise(a0, a1, a2, a3, a4, a5, a6) _Py_Raise(a0, a1, a2, a3, a4, a5, a6)
|
|
||||||
stmt_ty _Py_Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int
|
|
||||||
end_lineno, int end_col_offset, PyArena *arena);
|
|
||||||
#define Try(a0, a1, a2, a3, a4, a5, a6, a7, a8) _Py_Try(a0, a1, a2, a3, a4, a5, a6, a7, a8)
|
|
||||||
stmt_ty _Py_Try(asdl_stmt_seq * body, asdl_excepthandler_seq * handlers,
|
|
||||||
asdl_stmt_seq * orelse, asdl_stmt_seq * finalbody, int lineno,
|
|
||||||
int col_offset, int end_lineno, int end_col_offset, PyArena
|
|
||||||
*arena);
|
|
||||||
#define Assert(a0, a1, a2, a3, a4, a5, a6) _Py_Assert(a0, a1, a2, a3, a4, a5, a6)
|
|
||||||
stmt_ty _Py_Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int
|
|
||||||
end_lineno, int end_col_offset, PyArena *arena);
|
|
||||||
#define Import(a0, a1, a2, a3, a4, a5) _Py_Import(a0, a1, a2, a3, a4, a5)
|
|
||||||
stmt_ty _Py_Import(asdl_alias_seq * names, int lineno, int col_offset, int
|
|
||||||
end_lineno, int end_col_offset, PyArena *arena);
|
|
||||||
#define ImportFrom(a0, a1, a2, a3, a4, a5, a6, a7) _Py_ImportFrom(a0, a1, a2, a3, a4, a5, a6, a7)
|
|
||||||
stmt_ty _Py_ImportFrom(identifier module, asdl_alias_seq * names, int level,
|
|
||||||
int lineno, int col_offset, int end_lineno, int
|
|
||||||
end_col_offset, PyArena *arena);
|
|
||||||
#define Global(a0, a1, a2, a3, a4, a5) _Py_Global(a0, a1, a2, a3, a4, a5)
|
|
||||||
stmt_ty _Py_Global(asdl_identifier_seq * names, int lineno, int col_offset, int
|
|
||||||
end_lineno, int end_col_offset, PyArena *arena);
|
|
||||||
#define Nonlocal(a0, a1, a2, a3, a4, a5) _Py_Nonlocal(a0, a1, a2, a3, a4, a5)
|
|
||||||
stmt_ty _Py_Nonlocal(asdl_identifier_seq * names, int lineno, int col_offset,
|
|
||||||
int end_lineno, int end_col_offset, PyArena *arena);
|
|
||||||
#define Expr(a0, a1, a2, a3, a4, a5) _Py_Expr(a0, a1, a2, a3, a4, a5)
|
|
||||||
stmt_ty _Py_Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int
|
|
||||||
end_col_offset, PyArena *arena);
|
|
||||||
#define Pass(a0, a1, a2, a3, a4) _Py_Pass(a0, a1, a2, a3, a4)
|
|
||||||
stmt_ty _Py_Pass(int lineno, int col_offset, int end_lineno, int
|
|
||||||
end_col_offset, PyArena *arena);
|
|
||||||
#define Break(a0, a1, a2, a3, a4) _Py_Break(a0, a1, a2, a3, a4)
|
|
||||||
stmt_ty _Py_Break(int lineno, int col_offset, int end_lineno, int
|
|
||||||
end_col_offset, PyArena *arena);
|
|
||||||
#define Continue(a0, a1, a2, a3, a4) _Py_Continue(a0, a1, a2, a3, a4)
|
|
||||||
stmt_ty _Py_Continue(int lineno, int col_offset, int end_lineno, int
|
|
||||||
end_col_offset, PyArena *arena);
|
|
||||||
#define BoolOp(a0, a1, a2, a3, a4, a5, a6) _Py_BoolOp(a0, a1, a2, a3, a4, a5, a6)
|
|
||||||
expr_ty _Py_BoolOp(boolop_ty op, asdl_expr_seq * values, int lineno, int
|
|
||||||
col_offset, int end_lineno, int end_col_offset, PyArena
|
|
||||||
*arena);
|
|
||||||
#define NamedExpr(a0, a1, a2, a3, a4, a5, a6) _Py_NamedExpr(a0, a1, a2, a3, a4, a5, a6)
|
|
||||||
expr_ty _Py_NamedExpr(expr_ty target, expr_ty value, int lineno, int
|
|
||||||
col_offset, int end_lineno, int end_col_offset, PyArena
|
|
||||||
*arena);
|
|
||||||
#define BinOp(a0, a1, a2, a3, a4, a5, a6, a7) _Py_BinOp(a0, a1, a2, a3, a4, a5, a6, a7)
|
|
||||||
expr_ty _Py_BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int
|
|
||||||
col_offset, int end_lineno, int end_col_offset, PyArena
|
|
||||||
*arena);
|
|
||||||
#define UnaryOp(a0, a1, a2, a3, a4, a5, a6) _Py_UnaryOp(a0, a1, a2, a3, a4, a5, a6)
|
|
||||||
expr_ty _Py_UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset,
|
|
||||||
int end_lineno, int end_col_offset, PyArena *arena);
|
|
||||||
#define Lambda(a0, a1, a2, a3, a4, a5, a6) _Py_Lambda(a0, a1, a2, a3, a4, a5, a6)
|
|
||||||
expr_ty _Py_Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset,
|
|
||||||
int end_lineno, int end_col_offset, PyArena *arena);
|
|
||||||
#define IfExp(a0, a1, a2, a3, a4, a5, a6, a7) _Py_IfExp(a0, a1, a2, a3, a4, a5, a6, a7)
|
|
||||||
expr_ty _Py_IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int
|
|
||||||
col_offset, int end_lineno, int end_col_offset, PyArena
|
|
||||||
*arena);
|
|
||||||
#define Dict(a0, a1, a2, a3, a4, a5, a6) _Py_Dict(a0, a1, a2, a3, a4, a5, a6)
|
|
||||||
expr_ty _Py_Dict(asdl_expr_seq * keys, asdl_expr_seq * values, int lineno, int
|
|
||||||
col_offset, int end_lineno, int end_col_offset, PyArena
|
|
||||||
*arena);
|
|
||||||
#define Set(a0, a1, a2, a3, a4, a5) _Py_Set(a0, a1, a2, a3, a4, a5)
|
|
||||||
expr_ty _Py_Set(asdl_expr_seq * elts, int lineno, int col_offset, int
|
|
||||||
end_lineno, int end_col_offset, PyArena *arena);
|
|
||||||
#define ListComp(a0, a1, a2, a3, a4, a5, a6) _Py_ListComp(a0, a1, a2, a3, a4, a5, a6)
|
|
||||||
expr_ty _Py_ListComp(expr_ty elt, asdl_comprehension_seq * generators, int
|
|
||||||
lineno, int col_offset, int end_lineno, int
|
|
||||||
end_col_offset, PyArena *arena);
|
|
||||||
#define SetComp(a0, a1, a2, a3, a4, a5, a6) _Py_SetComp(a0, a1, a2, a3, a4, a5, a6)
|
|
||||||
expr_ty _Py_SetComp(expr_ty elt, asdl_comprehension_seq * generators, int
|
|
||||||
lineno, int col_offset, int end_lineno, int end_col_offset,
|
|
||||||
PyArena *arena);
|
|
||||||
#define DictComp(a0, a1, a2, a3, a4, a5, a6, a7) _Py_DictComp(a0, a1, a2, a3, a4, a5, a6, a7)
|
|
||||||
expr_ty _Py_DictComp(expr_ty key, expr_ty value, asdl_comprehension_seq *
|
|
||||||
generators, int lineno, int col_offset, int end_lineno,
|
|
||||||
int end_col_offset, PyArena *arena);
|
|
||||||
#define GeneratorExp(a0, a1, a2, a3, a4, a5, a6) _Py_GeneratorExp(a0, a1, a2, a3, a4, a5, a6)
|
|
||||||
expr_ty _Py_GeneratorExp(expr_ty elt, asdl_comprehension_seq * generators, int
|
|
||||||
lineno, int col_offset, int end_lineno, int
|
lineno, int col_offset, int end_lineno, int
|
||||||
end_col_offset, PyArena *arena);
|
end_col_offset, PyArena *arena);
|
||||||
#define Await(a0, a1, a2, a3, a4, a5) _Py_Await(a0, a1, a2, a3, a4, a5)
|
stmt_ty _PyAST_AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int
|
||||||
expr_ty _Py_Await(expr_ty value, int lineno, int col_offset, int end_lineno,
|
simple, int lineno, int col_offset, int end_lineno,
|
||||||
int end_col_offset, PyArena *arena);
|
int end_col_offset, PyArena *arena);
|
||||||
expr_ty _Py_Yield(expr_ty value, int lineno, int col_offset, int end_lineno,
|
stmt_ty _PyAST_For(expr_ty target, expr_ty iter, asdl_stmt_seq * body,
|
||||||
int end_col_offset, PyArena *arena);
|
asdl_stmt_seq * orelse, string type_comment, int lineno, int
|
||||||
#define YieldFrom(a0, a1, a2, a3, a4, a5) _Py_YieldFrom(a0, a1, a2, a3, a4, a5)
|
col_offset, int end_lineno, int end_col_offset, PyArena
|
||||||
expr_ty _Py_YieldFrom(expr_ty value, int lineno, int col_offset, int
|
*arena);
|
||||||
end_lineno, int end_col_offset, PyArena *arena);
|
stmt_ty _PyAST_AsyncFor(expr_ty target, expr_ty iter, asdl_stmt_seq * body,
|
||||||
#define Compare(a0, a1, a2, a3, a4, a5, a6, a7) _Py_Compare(a0, a1, a2, a3, a4, a5, a6, a7)
|
asdl_stmt_seq * orelse, string type_comment, int
|
||||||
expr_ty _Py_Compare(expr_ty left, asdl_int_seq * ops, asdl_expr_seq *
|
lineno, int col_offset, int end_lineno, int
|
||||||
comparators, int lineno, int col_offset, int end_lineno,
|
end_col_offset, PyArena *arena);
|
||||||
|
stmt_ty _PyAST_While(expr_ty test, asdl_stmt_seq * body, asdl_stmt_seq *
|
||||||
|
orelse, int lineno, int col_offset, int end_lineno, int
|
||||||
|
end_col_offset, PyArena *arena);
|
||||||
|
stmt_ty _PyAST_If(expr_ty test, asdl_stmt_seq * body, asdl_stmt_seq * orelse,
|
||||||
|
int lineno, int col_offset, int end_lineno, int
|
||||||
|
end_col_offset, PyArena *arena);
|
||||||
|
stmt_ty _PyAST_With(asdl_withitem_seq * items, asdl_stmt_seq * body, string
|
||||||
|
type_comment, int lineno, int col_offset, int end_lineno,
|
||||||
int end_col_offset, PyArena *arena);
|
int end_col_offset, PyArena *arena);
|
||||||
#define Call(a0, a1, a2, a3, a4, a5, a6, a7) _Py_Call(a0, a1, a2, a3, a4, a5, a6, a7)
|
stmt_ty _PyAST_AsyncWith(asdl_withitem_seq * items, asdl_stmt_seq * body,
|
||||||
expr_ty _Py_Call(expr_ty func, asdl_expr_seq * args, asdl_keyword_seq *
|
string type_comment, int lineno, int col_offset, int
|
||||||
keywords, int lineno, int col_offset, int end_lineno, int
|
end_lineno, int end_col_offset, PyArena *arena);
|
||||||
end_col_offset, PyArena *arena);
|
stmt_ty _PyAST_Match(expr_ty subject, asdl_match_case_seq * cases, int lineno,
|
||||||
#define FormattedValue(a0, a1, a2, a3, a4, a5, a6, a7) _Py_FormattedValue(a0, a1, a2, a3, a4, a5, a6, a7)
|
int col_offset, int end_lineno, int end_col_offset,
|
||||||
expr_ty _Py_FormattedValue(expr_ty value, int conversion, expr_ty format_spec,
|
PyArena *arena);
|
||||||
int lineno, int col_offset, int end_lineno, int
|
stmt_ty _PyAST_Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset,
|
||||||
end_col_offset, PyArena *arena);
|
|
||||||
#define JoinedStr(a0, a1, a2, a3, a4, a5) _Py_JoinedStr(a0, a1, a2, a3, a4, a5)
|
|
||||||
expr_ty _Py_JoinedStr(asdl_expr_seq * values, int lineno, int col_offset, int
|
|
||||||
end_lineno, int end_col_offset, PyArena *arena);
|
|
||||||
#define Constant(a0, a1, a2, a3, a4, a5, a6) _Py_Constant(a0, a1, a2, a3, a4, a5, a6)
|
|
||||||
expr_ty _Py_Constant(constant value, string kind, int lineno, int col_offset,
|
|
||||||
int end_lineno, int end_col_offset, PyArena *arena);
|
int end_lineno, int end_col_offset, PyArena *arena);
|
||||||
#define Attribute(a0, a1, a2, a3, a4, a5, a6, a7) _Py_Attribute(a0, a1, a2, a3, a4, a5, a6, a7)
|
stmt_ty _PyAST_Try(asdl_stmt_seq * body, asdl_excepthandler_seq * handlers,
|
||||||
expr_ty _Py_Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int
|
asdl_stmt_seq * orelse, asdl_stmt_seq * finalbody, int
|
||||||
lineno, int col_offset, int end_lineno, int
|
lineno, int col_offset, int end_lineno, int end_col_offset,
|
||||||
end_col_offset, PyArena *arena);
|
PyArena *arena);
|
||||||
#define Subscript(a0, a1, a2, a3, a4, a5, a6, a7) _Py_Subscript(a0, a1, a2, a3, a4, a5, a6, a7)
|
stmt_ty _PyAST_Assert(expr_ty test, expr_ty msg, int lineno, int col_offset,
|
||||||
expr_ty _Py_Subscript(expr_ty value, expr_ty slice, expr_context_ty ctx, int
|
int end_lineno, int end_col_offset, PyArena *arena);
|
||||||
lineno, int col_offset, int end_lineno, int
|
stmt_ty _PyAST_Import(asdl_alias_seq * names, int lineno, int col_offset, int
|
||||||
end_col_offset, PyArena *arena);
|
end_lineno, int end_col_offset, PyArena *arena);
|
||||||
#define Starred(a0, a1, a2, a3, a4, a5, a6) _Py_Starred(a0, a1, a2, a3, a4, a5, a6)
|
stmt_ty _PyAST_ImportFrom(identifier module, asdl_alias_seq * names, int level,
|
||||||
expr_ty _Py_Starred(expr_ty value, expr_context_ty ctx, int lineno, int
|
int lineno, int col_offset, int end_lineno, int
|
||||||
col_offset, int end_lineno, int end_col_offset, PyArena
|
end_col_offset, PyArena *arena);
|
||||||
*arena);
|
stmt_ty _PyAST_Global(asdl_identifier_seq * names, int lineno, int col_offset,
|
||||||
#define Name(a0, a1, a2, a3, a4, a5, a6) _Py_Name(a0, a1, a2, a3, a4, a5, a6)
|
int end_lineno, int end_col_offset, PyArena *arena);
|
||||||
expr_ty _Py_Name(identifier id, expr_context_ty ctx, int lineno, int
|
stmt_ty _PyAST_Nonlocal(asdl_identifier_seq * names, int lineno, int
|
||||||
col_offset, int end_lineno, int end_col_offset, PyArena
|
col_offset, int end_lineno, int end_col_offset, PyArena
|
||||||
*arena);
|
*arena);
|
||||||
#define List(a0, a1, a2, a3, a4, a5, a6) _Py_List(a0, a1, a2, a3, a4, a5, a6)
|
stmt_ty _PyAST_Expr(expr_ty value, int lineno, int col_offset, int end_lineno,
|
||||||
expr_ty _Py_List(asdl_expr_seq * elts, expr_context_ty ctx, int lineno, int
|
int end_col_offset, PyArena *arena);
|
||||||
col_offset, int end_lineno, int end_col_offset, PyArena
|
stmt_ty _PyAST_Pass(int lineno, int col_offset, int end_lineno, int
|
||||||
*arena);
|
end_col_offset, PyArena *arena);
|
||||||
#define Tuple(a0, a1, a2, a3, a4, a5, a6) _Py_Tuple(a0, a1, a2, a3, a4, a5, a6)
|
stmt_ty _PyAST_Break(int lineno, int col_offset, int end_lineno, int
|
||||||
expr_ty _Py_Tuple(asdl_expr_seq * elts, expr_context_ty ctx, int lineno, int
|
end_col_offset, PyArena *arena);
|
||||||
col_offset, int end_lineno, int end_col_offset, PyArena
|
stmt_ty _PyAST_Continue(int lineno, int col_offset, int end_lineno, int
|
||||||
*arena);
|
end_col_offset, PyArena *arena);
|
||||||
#define Slice(a0, a1, a2, a3, a4, a5, a6, a7) _Py_Slice(a0, a1, a2, a3, a4, a5, a6, a7)
|
expr_ty _PyAST_BoolOp(boolop_ty op, asdl_expr_seq * values, int lineno, int
|
||||||
expr_ty _Py_Slice(expr_ty lower, expr_ty upper, expr_ty step, int lineno, int
|
col_offset, int end_lineno, int end_col_offset, PyArena
|
||||||
col_offset, int end_lineno, int end_col_offset, PyArena
|
*arena);
|
||||||
*arena);
|
expr_ty _PyAST_NamedExpr(expr_ty target, expr_ty value, int lineno, int
|
||||||
#define MatchAs(a0, a1, a2, a3, a4, a5, a6) _Py_MatchAs(a0, a1, a2, a3, a4, a5, a6)
|
col_offset, int end_lineno, int end_col_offset,
|
||||||
expr_ty _Py_MatchAs(expr_ty pattern, identifier name, int lineno, int
|
PyArena *arena);
|
||||||
col_offset, int end_lineno, int end_col_offset, PyArena
|
expr_ty _PyAST_BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno,
|
||||||
*arena);
|
int col_offset, int end_lineno, int end_col_offset,
|
||||||
#define MatchOr(a0, a1, a2, a3, a4, a5) _Py_MatchOr(a0, a1, a2, a3, a4, a5)
|
PyArena *arena);
|
||||||
expr_ty _Py_MatchOr(asdl_expr_seq * patterns, int lineno, int col_offset, int
|
expr_ty _PyAST_UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int
|
||||||
end_lineno, int end_col_offset, PyArena *arena);
|
|
||||||
#define comprehension(a0, a1, a2, a3, a4) _Py_comprehension(a0, a1, a2, a3, a4)
|
|
||||||
comprehension_ty _Py_comprehension(expr_ty target, expr_ty iter, asdl_expr_seq
|
|
||||||
* ifs, int is_async, PyArena *arena);
|
|
||||||
#define ExceptHandler(a0, a1, a2, a3, a4, a5, a6, a7) _Py_ExceptHandler(a0, a1, a2, a3, a4, a5, a6, a7)
|
|
||||||
excepthandler_ty _Py_ExceptHandler(expr_ty type, identifier name, asdl_stmt_seq
|
|
||||||
* body, int lineno, int col_offset, int
|
|
||||||
end_lineno, int end_col_offset, PyArena
|
|
||||||
*arena);
|
|
||||||
#define arguments(a0, a1, a2, a3, a4, a5, a6, a7) _Py_arguments(a0, a1, a2, a3, a4, a5, a6, a7)
|
|
||||||
arguments_ty _Py_arguments(asdl_arg_seq * posonlyargs, asdl_arg_seq * args,
|
|
||||||
arg_ty vararg, asdl_arg_seq * kwonlyargs,
|
|
||||||
asdl_expr_seq * kw_defaults, arg_ty kwarg,
|
|
||||||
asdl_expr_seq * defaults, PyArena *arena);
|
|
||||||
#define arg(a0, a1, a2, a3, a4, a5, a6, a7) _Py_arg(a0, a1, a2, a3, a4, a5, a6, a7)
|
|
||||||
arg_ty _Py_arg(identifier arg, expr_ty annotation, string type_comment, int
|
|
||||||
lineno, int col_offset, int end_lineno, int end_col_offset,
|
|
||||||
PyArena *arena);
|
|
||||||
#define keyword(a0, a1, a2, a3, a4, a5, a6) _Py_keyword(a0, a1, a2, a3, a4, a5, a6)
|
|
||||||
keyword_ty _Py_keyword(identifier arg, expr_ty value, int lineno, int
|
|
||||||
col_offset, int end_lineno, int end_col_offset, PyArena
|
col_offset, int end_lineno, int end_col_offset, PyArena
|
||||||
*arena);
|
*arena);
|
||||||
#define alias(a0, a1, a2) _Py_alias(a0, a1, a2)
|
expr_ty _PyAST_Lambda(arguments_ty args, expr_ty body, int lineno, int
|
||||||
alias_ty _Py_alias(identifier name, identifier asname, PyArena *arena);
|
col_offset, int end_lineno, int end_col_offset, PyArena
|
||||||
#define withitem(a0, a1, a2) _Py_withitem(a0, a1, a2)
|
*arena);
|
||||||
withitem_ty _Py_withitem(expr_ty context_expr, expr_ty optional_vars, PyArena
|
expr_ty _PyAST_IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno,
|
||||||
*arena);
|
int col_offset, int end_lineno, int end_col_offset,
|
||||||
#define match_case(a0, a1, a2, a3) _Py_match_case(a0, a1, a2, a3)
|
PyArena *arena);
|
||||||
match_case_ty _Py_match_case(expr_ty pattern, expr_ty guard, asdl_stmt_seq *
|
expr_ty _PyAST_Dict(asdl_expr_seq * keys, asdl_expr_seq * values, int lineno,
|
||||||
body, PyArena *arena);
|
int col_offset, int end_lineno, int end_col_offset, PyArena
|
||||||
#define TypeIgnore(a0, a1, a2) _Py_TypeIgnore(a0, a1, a2)
|
*arena);
|
||||||
type_ignore_ty _Py_TypeIgnore(int lineno, string tag, PyArena *arena);
|
expr_ty _PyAST_Set(asdl_expr_seq * elts, int lineno, int col_offset, int
|
||||||
|
end_lineno, int end_col_offset, PyArena *arena);
|
||||||
|
expr_ty _PyAST_ListComp(expr_ty elt, asdl_comprehension_seq * generators, int
|
||||||
|
lineno, int col_offset, int end_lineno, int
|
||||||
|
end_col_offset, PyArena *arena);
|
||||||
|
expr_ty _PyAST_SetComp(expr_ty elt, asdl_comprehension_seq * generators, int
|
||||||
|
lineno, int col_offset, int end_lineno, int
|
||||||
|
end_col_offset, PyArena *arena);
|
||||||
|
expr_ty _PyAST_DictComp(expr_ty key, expr_ty value, asdl_comprehension_seq *
|
||||||
|
generators, int lineno, int col_offset, int end_lineno,
|
||||||
|
int end_col_offset, PyArena *arena);
|
||||||
|
expr_ty _PyAST_GeneratorExp(expr_ty elt, asdl_comprehension_seq * generators,
|
||||||
|
int lineno, int col_offset, int end_lineno, int
|
||||||
|
end_col_offset, PyArena *arena);
|
||||||
|
expr_ty _PyAST_Await(expr_ty value, int lineno, int col_offset, int end_lineno,
|
||||||
|
int end_col_offset, PyArena *arena);
|
||||||
|
expr_ty _PyAST_Yield(expr_ty value, int lineno, int col_offset, int end_lineno,
|
||||||
|
int end_col_offset, PyArena *arena);
|
||||||
|
expr_ty _PyAST_YieldFrom(expr_ty value, int lineno, int col_offset, int
|
||||||
|
end_lineno, int end_col_offset, PyArena *arena);
|
||||||
|
expr_ty _PyAST_Compare(expr_ty left, asdl_int_seq * ops, asdl_expr_seq *
|
||||||
|
comparators, int lineno, int col_offset, int end_lineno,
|
||||||
|
int end_col_offset, PyArena *arena);
|
||||||
|
expr_ty _PyAST_Call(expr_ty func, asdl_expr_seq * args, asdl_keyword_seq *
|
||||||
|
keywords, int lineno, int col_offset, int end_lineno, int
|
||||||
|
end_col_offset, PyArena *arena);
|
||||||
|
expr_ty _PyAST_FormattedValue(expr_ty value, int conversion, expr_ty
|
||||||
|
format_spec, int lineno, int col_offset, int
|
||||||
|
end_lineno, int end_col_offset, PyArena *arena);
|
||||||
|
expr_ty _PyAST_JoinedStr(asdl_expr_seq * values, int lineno, int col_offset,
|
||||||
|
int end_lineno, int end_col_offset, PyArena *arena);
|
||||||
|
expr_ty _PyAST_Constant(constant value, string kind, int lineno, int
|
||||||
|
col_offset, int end_lineno, int end_col_offset, PyArena
|
||||||
|
*arena);
|
||||||
|
expr_ty _PyAST_Attribute(expr_ty value, identifier attr, expr_context_ty ctx,
|
||||||
|
int lineno, int col_offset, int end_lineno, int
|
||||||
|
end_col_offset, PyArena *arena);
|
||||||
|
expr_ty _PyAST_Subscript(expr_ty value, expr_ty slice, expr_context_ty ctx, int
|
||||||
|
lineno, int col_offset, int end_lineno, int
|
||||||
|
end_col_offset, PyArena *arena);
|
||||||
|
expr_ty _PyAST_Starred(expr_ty value, expr_context_ty ctx, int lineno, int
|
||||||
|
col_offset, int end_lineno, int end_col_offset, PyArena
|
||||||
|
*arena);
|
||||||
|
expr_ty _PyAST_Name(identifier id, expr_context_ty ctx, int lineno, int
|
||||||
|
col_offset, int end_lineno, int end_col_offset, PyArena
|
||||||
|
*arena);
|
||||||
|
expr_ty _PyAST_List(asdl_expr_seq * elts, expr_context_ty ctx, int lineno, int
|
||||||
|
col_offset, int end_lineno, int end_col_offset, PyArena
|
||||||
|
*arena);
|
||||||
|
expr_ty _PyAST_Tuple(asdl_expr_seq * elts, expr_context_ty ctx, int lineno, int
|
||||||
|
col_offset, int end_lineno, int end_col_offset, PyArena
|
||||||
|
*arena);
|
||||||
|
expr_ty _PyAST_Slice(expr_ty lower, expr_ty upper, expr_ty step, int lineno,
|
||||||
|
int col_offset, int end_lineno, int end_col_offset,
|
||||||
|
PyArena *arena);
|
||||||
|
expr_ty _PyAST_MatchAs(expr_ty pattern, identifier name, int lineno, int
|
||||||
|
col_offset, int end_lineno, int end_col_offset, PyArena
|
||||||
|
*arena);
|
||||||
|
expr_ty _PyAST_MatchOr(asdl_expr_seq * patterns, int lineno, int col_offset,
|
||||||
|
int end_lineno, int end_col_offset, PyArena *arena);
|
||||||
|
comprehension_ty _PyAST_comprehension(expr_ty target, expr_ty iter,
|
||||||
|
asdl_expr_seq * ifs, int is_async,
|
||||||
|
PyArena *arena);
|
||||||
|
excepthandler_ty _PyAST_ExceptHandler(expr_ty type, identifier name,
|
||||||
|
asdl_stmt_seq * body, int lineno, int
|
||||||
|
col_offset, int end_lineno, int
|
||||||
|
end_col_offset, PyArena *arena);
|
||||||
|
arguments_ty _PyAST_arguments(asdl_arg_seq * posonlyargs, asdl_arg_seq * args,
|
||||||
|
arg_ty vararg, asdl_arg_seq * kwonlyargs,
|
||||||
|
asdl_expr_seq * kw_defaults, arg_ty kwarg,
|
||||||
|
asdl_expr_seq * defaults, PyArena *arena);
|
||||||
|
arg_ty _PyAST_arg(identifier arg, expr_ty annotation, string type_comment, int
|
||||||
|
lineno, int col_offset, int end_lineno, int end_col_offset,
|
||||||
|
PyArena *arena);
|
||||||
|
keyword_ty _PyAST_keyword(identifier arg, expr_ty value, int lineno, int
|
||||||
|
col_offset, int end_lineno, int end_col_offset,
|
||||||
|
PyArena *arena);
|
||||||
|
alias_ty _PyAST_alias(identifier name, identifier asname, PyArena *arena);
|
||||||
|
withitem_ty _PyAST_withitem(expr_ty context_expr, expr_ty optional_vars,
|
||||||
|
PyArena *arena);
|
||||||
|
match_case_ty _PyAST_match_case(expr_ty pattern, expr_ty guard, asdl_stmt_seq *
|
||||||
|
body, PyArena *arena);
|
||||||
|
type_ignore_ty _PyAST_TypeIgnore(int lineno, string tag, PyArena *arena);
|
||||||
|
|
||||||
|
|
||||||
PyObject* PyAST_mod2obj(mod_ty t);
|
PyObject* PyAST_mod2obj(mod_ty t);
|
||||||
|
|
|
@ -96,15 +96,15 @@ class TestCParser(TempdirManager, unittest.TestCase):
|
||||||
|
|
||||||
def test_c_parser(self) -> None:
|
def test_c_parser(self) -> None:
|
||||||
grammar_source = """
|
grammar_source = """
|
||||||
start[mod_ty]: a[asdl_stmt_seq*]=stmt* $ { Module(a, NULL, p->arena) }
|
start[mod_ty]: a[asdl_stmt_seq*]=stmt* $ { _PyAST_Module(a, NULL, p->arena) }
|
||||||
stmt[stmt_ty]: a=expr_stmt { a }
|
stmt[stmt_ty]: a=expr_stmt { a }
|
||||||
expr_stmt[stmt_ty]: a=expression NEWLINE { _Py_Expr(a, EXTRA) }
|
expr_stmt[stmt_ty]: a=expression NEWLINE { _PyAST_Expr(a, EXTRA) }
|
||||||
expression[expr_ty]: ( l=expression '+' r=term { _Py_BinOp(l, Add, r, EXTRA) }
|
expression[expr_ty]: ( l=expression '+' r=term { _PyAST_BinOp(l, Add, r, EXTRA) }
|
||||||
| l=expression '-' r=term { _Py_BinOp(l, Sub, r, EXTRA) }
|
| l=expression '-' r=term { _PyAST_BinOp(l, Sub, r, EXTRA) }
|
||||||
| t=term { t }
|
| t=term { t }
|
||||||
)
|
)
|
||||||
term[expr_ty]: ( l=term '*' r=factor { _Py_BinOp(l, Mult, r, EXTRA) }
|
term[expr_ty]: ( l=term '*' r=factor { _PyAST_BinOp(l, Mult, r, EXTRA) }
|
||||||
| l=term '/' r=factor { _Py_BinOp(l, Div, r, EXTRA) }
|
| l=term '/' r=factor { _PyAST_BinOp(l, Div, r, EXTRA) }
|
||||||
| f=factor { f }
|
| f=factor { f }
|
||||||
)
|
)
|
||||||
factor[expr_ty]: ('(' e=expression ')' { e }
|
factor[expr_ty]: ('(' e=expression ')' { e }
|
||||||
|
@ -237,12 +237,12 @@ class TestCParser(TempdirManager, unittest.TestCase):
|
||||||
|
|
||||||
def test_return_stmt_noexpr_action(self) -> None:
|
def test_return_stmt_noexpr_action(self) -> None:
|
||||||
grammar_source = """
|
grammar_source = """
|
||||||
start[mod_ty]: a=[statements] ENDMARKER { Module(a, NULL, p->arena) }
|
start[mod_ty]: a=[statements] ENDMARKER { _PyAST_Module(a, NULL, p->arena) }
|
||||||
statements[asdl_stmt_seq*]: a[asdl_stmt_seq*]=statement+ { a }
|
statements[asdl_stmt_seq*]: a[asdl_stmt_seq*]=statement+ { a }
|
||||||
statement[stmt_ty]: simple_stmt
|
statement[stmt_ty]: simple_stmt
|
||||||
simple_stmt[stmt_ty]: small_stmt
|
simple_stmt[stmt_ty]: small_stmt
|
||||||
small_stmt[stmt_ty]: return_stmt
|
small_stmt[stmt_ty]: return_stmt
|
||||||
return_stmt[stmt_ty]: a='return' NEWLINE { _Py_Return(NULL, EXTRA) }
|
return_stmt[stmt_ty]: a='return' NEWLINE { _PyAST_Return(NULL, EXTRA) }
|
||||||
"""
|
"""
|
||||||
test_source = """
|
test_source = """
|
||||||
stmt = "return"
|
stmt = "return"
|
||||||
|
@ -252,8 +252,8 @@ class TestCParser(TempdirManager, unittest.TestCase):
|
||||||
|
|
||||||
def test_gather_action_ast(self) -> None:
|
def test_gather_action_ast(self) -> None:
|
||||||
grammar_source = """
|
grammar_source = """
|
||||||
start[mod_ty]: a[asdl_stmt_seq*]=';'.pass_stmt+ NEWLINE ENDMARKER { Module(a, NULL, p->arena) }
|
start[mod_ty]: a[asdl_stmt_seq*]=';'.pass_stmt+ NEWLINE ENDMARKER { _PyAST_Module(a, NULL, p->arena) }
|
||||||
pass_stmt[stmt_ty]: a='pass' { _Py_Pass(EXTRA)}
|
pass_stmt[stmt_ty]: a='pass' { _PyAST_Pass(EXTRA)}
|
||||||
"""
|
"""
|
||||||
test_source = """
|
test_source = """
|
||||||
stmt = "pass; pass"
|
stmt = "pass; pass"
|
||||||
|
@ -263,12 +263,12 @@ class TestCParser(TempdirManager, unittest.TestCase):
|
||||||
|
|
||||||
def test_pass_stmt_action(self) -> None:
|
def test_pass_stmt_action(self) -> None:
|
||||||
grammar_source = """
|
grammar_source = """
|
||||||
start[mod_ty]: a=[statements] ENDMARKER { Module(a, NULL, p->arena) }
|
start[mod_ty]: a=[statements] ENDMARKER { _PyAST_Module(a, NULL, p->arena) }
|
||||||
statements[asdl_stmt_seq*]: a[asdl_stmt_seq*]=statement+ { a }
|
statements[asdl_stmt_seq*]: a[asdl_stmt_seq*]=statement+ { a }
|
||||||
statement[stmt_ty]: simple_stmt
|
statement[stmt_ty]: simple_stmt
|
||||||
simple_stmt[stmt_ty]: small_stmt
|
simple_stmt[stmt_ty]: small_stmt
|
||||||
small_stmt[stmt_ty]: pass_stmt
|
small_stmt[stmt_ty]: pass_stmt
|
||||||
pass_stmt[stmt_ty]: a='pass' NEWLINE { _Py_Pass(EXTRA) }
|
pass_stmt[stmt_ty]: a='pass' NEWLINE { _PyAST_Pass(EXTRA) }
|
||||||
"""
|
"""
|
||||||
test_source = """
|
test_source = """
|
||||||
stmt = "pass"
|
stmt = "pass"
|
||||||
|
@ -278,7 +278,7 @@ class TestCParser(TempdirManager, unittest.TestCase):
|
||||||
|
|
||||||
def test_if_stmt_action(self) -> None:
|
def test_if_stmt_action(self) -> None:
|
||||||
grammar_source = """
|
grammar_source = """
|
||||||
start[mod_ty]: a=[statements] ENDMARKER { Module(a, NULL, p->arena) }
|
start[mod_ty]: a=[statements] ENDMARKER { _PyAST_Module(a, NULL, p->arena) }
|
||||||
statements[asdl_stmt_seq*]: a=statement+ { (asdl_stmt_seq*)_PyPegen_seq_flatten(p, a) }
|
statements[asdl_stmt_seq*]: a=statement+ { (asdl_stmt_seq*)_PyPegen_seq_flatten(p, a) }
|
||||||
statement[asdl_stmt_seq*]: a=compound_stmt { (asdl_stmt_seq*)_PyPegen_singleton_seq(p, a) } | simple_stmt
|
statement[asdl_stmt_seq*]: a=compound_stmt { (asdl_stmt_seq*)_PyPegen_singleton_seq(p, a) } | simple_stmt
|
||||||
|
|
||||||
|
@ -290,11 +290,11 @@ class TestCParser(TempdirManager, unittest.TestCase):
|
||||||
|
|
||||||
compound_stmt: if_stmt
|
compound_stmt: if_stmt
|
||||||
|
|
||||||
if_stmt: 'if' a=full_expression ':' b=block { _Py_If(a, b, NULL, EXTRA) }
|
if_stmt: 'if' a=full_expression ':' b=block { _PyAST_If(a, b, NULL, EXTRA) }
|
||||||
|
|
||||||
small_stmt[stmt_ty]: pass_stmt
|
small_stmt[stmt_ty]: pass_stmt
|
||||||
|
|
||||||
pass_stmt[stmt_ty]: a='pass' { _Py_Pass(EXTRA) }
|
pass_stmt[stmt_ty]: a='pass' { _PyAST_Pass(EXTRA) }
|
||||||
|
|
||||||
full_expression: NAME
|
full_expression: NAME
|
||||||
"""
|
"""
|
||||||
|
@ -306,15 +306,15 @@ class TestCParser(TempdirManager, unittest.TestCase):
|
||||||
|
|
||||||
def test_same_name_different_types(self) -> None:
|
def test_same_name_different_types(self) -> None:
|
||||||
grammar_source = """
|
grammar_source = """
|
||||||
start[mod_ty]: a[asdl_stmt_seq*]=import_from+ NEWLINE ENDMARKER { Module(a, NULL, p->arena)}
|
start[mod_ty]: a[asdl_stmt_seq*]=import_from+ NEWLINE ENDMARKER { _PyAST_Module(a, NULL, p->arena)}
|
||||||
import_from[stmt_ty]: ( a='from' !'import' c=simple_name 'import' d=import_as_names_from {
|
import_from[stmt_ty]: ( a='from' !'import' c=simple_name 'import' d=import_as_names_from {
|
||||||
_Py_ImportFrom(c->v.Name.id, d, 0, EXTRA) }
|
_PyAST_ImportFrom(c->v.Name.id, d, 0, EXTRA) }
|
||||||
| a='from' '.' 'import' c=import_as_names_from {
|
| a='from' '.' 'import' c=import_as_names_from {
|
||||||
_Py_ImportFrom(NULL, c, 1, EXTRA) }
|
_PyAST_ImportFrom(NULL, c, 1, EXTRA) }
|
||||||
)
|
)
|
||||||
simple_name[expr_ty]: NAME
|
simple_name[expr_ty]: NAME
|
||||||
import_as_names_from[asdl_alias_seq*]: a[asdl_alias_seq*]=','.import_as_name_from+ { a }
|
import_as_names_from[asdl_alias_seq*]: a[asdl_alias_seq*]=','.import_as_name_from+ { a }
|
||||||
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) }
|
import_as_name_from[alias_ty]: a=NAME 'as' b=NAME { _PyAST_alias(((expr_ty) a)->v.Name.id, ((expr_ty) b)->v.Name.id, p->arena) }
|
||||||
"""
|
"""
|
||||||
test_source = """
|
test_source = """
|
||||||
for stmt in ("from a import b as c", "from . import a as b"):
|
for stmt in ("from a import b as c", "from . import a as b"):
|
||||||
|
@ -326,19 +326,19 @@ class TestCParser(TempdirManager, unittest.TestCase):
|
||||||
|
|
||||||
def test_with_stmt_with_paren(self) -> None:
|
def test_with_stmt_with_paren(self) -> None:
|
||||||
grammar_source = """
|
grammar_source = """
|
||||||
start[mod_ty]: a=[statements] ENDMARKER { Module(a, NULL, p->arena) }
|
start[mod_ty]: a=[statements] ENDMARKER { _PyAST_Module(a, NULL, p->arena) }
|
||||||
statements[asdl_stmt_seq*]: a=statement+ { (asdl_stmt_seq*)_PyPegen_seq_flatten(p, a) }
|
statements[asdl_stmt_seq*]: a=statement+ { (asdl_stmt_seq*)_PyPegen_seq_flatten(p, a) }
|
||||||
statement[asdl_stmt_seq*]: a=compound_stmt { (asdl_stmt_seq*)_PyPegen_singleton_seq(p, a) }
|
statement[asdl_stmt_seq*]: a=compound_stmt { (asdl_stmt_seq*)_PyPegen_singleton_seq(p, a) }
|
||||||
compound_stmt[stmt_ty]: with_stmt
|
compound_stmt[stmt_ty]: with_stmt
|
||||||
with_stmt[stmt_ty]: (
|
with_stmt[stmt_ty]: (
|
||||||
a='with' '(' b[asdl_withitem_seq*]=','.with_item+ ')' ':' c=block {
|
a='with' '(' b[asdl_withitem_seq*]=','.with_item+ ')' ':' c=block {
|
||||||
_Py_With(b, (asdl_stmt_seq*) _PyPegen_singleton_seq(p, c), NULL, EXTRA) }
|
_PyAST_With(b, (asdl_stmt_seq*) _PyPegen_singleton_seq(p, c), NULL, EXTRA) }
|
||||||
)
|
)
|
||||||
with_item[withitem_ty]: (
|
with_item[withitem_ty]: (
|
||||||
e=NAME o=['as' t=NAME { t }] { _Py_withitem(e, _PyPegen_set_expr_context(p, o, Store), p->arena) }
|
e=NAME o=['as' t=NAME { t }] { _PyAST_withitem(e, _PyPegen_set_expr_context(p, o, Store), p->arena) }
|
||||||
)
|
)
|
||||||
block[stmt_ty]: a=pass_stmt NEWLINE { a } | NEWLINE INDENT a=pass_stmt DEDENT { a }
|
block[stmt_ty]: a=pass_stmt NEWLINE { a } | NEWLINE INDENT a=pass_stmt DEDENT { a }
|
||||||
pass_stmt[stmt_ty]: a='pass' { _Py_Pass(EXTRA) }
|
pass_stmt[stmt_ty]: a='pass' { _PyAST_Pass(EXTRA) }
|
||||||
"""
|
"""
|
||||||
test_source = """
|
test_source = """
|
||||||
stmt = "with (\\n a as b,\\n c as d\\n): pass"
|
stmt = "with (\\n a as b,\\n c as d\\n): pass"
|
||||||
|
@ -352,14 +352,14 @@ class TestCParser(TempdirManager, unittest.TestCase):
|
||||||
|
|
||||||
def test_ternary_operator(self) -> None:
|
def test_ternary_operator(self) -> None:
|
||||||
grammar_source = """
|
grammar_source = """
|
||||||
start[mod_ty]: a=expr ENDMARKER { Module(a, NULL, p->arena) }
|
start[mod_ty]: a=expr ENDMARKER { _PyAST_Module(a, NULL, p->arena) }
|
||||||
expr[asdl_stmt_seq*]: a=listcomp NEWLINE { (asdl_stmt_seq*)_PyPegen_singleton_seq(p, _Py_Expr(a, EXTRA)) }
|
expr[asdl_stmt_seq*]: a=listcomp NEWLINE { (asdl_stmt_seq*)_PyPegen_singleton_seq(p, _PyAST_Expr(a, EXTRA)) }
|
||||||
listcomp[expr_ty]: (
|
listcomp[expr_ty]: (
|
||||||
a='[' b=NAME c=for_if_clauses d=']' { _Py_ListComp(b, c, EXTRA) }
|
a='[' b=NAME c=for_if_clauses d=']' { _PyAST_ListComp(b, c, EXTRA) }
|
||||||
)
|
)
|
||||||
for_if_clauses[asdl_comprehension_seq*]: (
|
for_if_clauses[asdl_comprehension_seq*]: (
|
||||||
a[asdl_comprehension_seq*]=(y=[ASYNC] 'for' a=NAME 'in' b=NAME c[asdl_expr_seq*]=('if' z=NAME { z })*
|
a[asdl_comprehension_seq*]=(y=[ASYNC] 'for' a=NAME 'in' b=NAME c[asdl_expr_seq*]=('if' z=NAME { z })*
|
||||||
{ _Py_comprehension(_Py_Name(((expr_ty) a)->v.Name.id, Store, EXTRA), b, c, (y == NULL) ? 0 : 1, p->arena) })+ { a }
|
{ _PyAST_comprehension(_PyAST_Name(((expr_ty) a)->v.Name.id, Store, EXTRA), b, c, (y == NULL) ? 0 : 1, p->arena) })+ { a }
|
||||||
)
|
)
|
||||||
"""
|
"""
|
||||||
test_source = """
|
test_source = """
|
||||||
|
|
|
@ -264,6 +264,10 @@ class StructVisitor(EmitVisitor):
|
||||||
self.emit("", depth)
|
self.emit("", depth)
|
||||||
|
|
||||||
|
|
||||||
|
def ast_func_name(name):
|
||||||
|
return f"_PyAST_{name}"
|
||||||
|
|
||||||
|
|
||||||
class PrototypeVisitor(EmitVisitor):
|
class PrototypeVisitor(EmitVisitor):
|
||||||
"""Generate function prototypes for the .h file"""
|
"""Generate function prototypes for the .h file"""
|
||||||
|
|
||||||
|
@ -322,16 +326,7 @@ class PrototypeVisitor(EmitVisitor):
|
||||||
argstr += ", PyArena *arena"
|
argstr += ", PyArena *arena"
|
||||||
else:
|
else:
|
||||||
argstr = "PyArena *arena"
|
argstr = "PyArena *arena"
|
||||||
margs = "a0"
|
self.emit("%s %s(%s);" % (ctype, ast_func_name(name), argstr), False)
|
||||||
for i in range(1, len(args)+1):
|
|
||||||
margs += ", a%d" % i
|
|
||||||
# bpo-43244: <winbase.h> defines Yield macro. Don't redefine it in
|
|
||||||
# pycore_ast.h: it is not needed outside Python-ast.c which calls
|
|
||||||
# directly _Py_Yield().
|
|
||||||
if name != "Yield":
|
|
||||||
self.emit("#define %s(%s) _Py_%s(%s)" % (name, margs, name, margs), 0,
|
|
||||||
reflow=False)
|
|
||||||
self.emit("%s _Py_%s(%s);" % (ctype, name, argstr), False)
|
|
||||||
|
|
||||||
def visitProduct(self, prod, name):
|
def visitProduct(self, prod, name):
|
||||||
self.emit_function(name, get_c_type(name),
|
self.emit_function(name, get_c_type(name),
|
||||||
|
@ -340,10 +335,6 @@ class PrototypeVisitor(EmitVisitor):
|
||||||
union=False)
|
union=False)
|
||||||
|
|
||||||
|
|
||||||
def pyfunc_name(name):
|
|
||||||
return f"_Py_{name}"
|
|
||||||
|
|
||||||
|
|
||||||
class FunctionVisitor(PrototypeVisitor):
|
class FunctionVisitor(PrototypeVisitor):
|
||||||
"""Visitor to generate constructor functions for AST."""
|
"""Visitor to generate constructor functions for AST."""
|
||||||
|
|
||||||
|
@ -357,7 +348,7 @@ class FunctionVisitor(PrototypeVisitor):
|
||||||
else:
|
else:
|
||||||
argstr = "PyArena *arena"
|
argstr = "PyArena *arena"
|
||||||
self.emit("%s" % ctype, 0)
|
self.emit("%s" % ctype, 0)
|
||||||
emit("%s(%s)" % (pyfunc_name(name), argstr))
|
emit("%s(%s)" % (ast_func_name(name), argstr))
|
||||||
emit("{")
|
emit("{")
|
||||||
emit("%s p;" % ctype, 1)
|
emit("%s p;" % ctype, 1)
|
||||||
for argtype, argname, opt in args:
|
for argtype, argname, opt in args:
|
||||||
|
@ -496,7 +487,7 @@ class Obj2ModVisitor(PickleVisitor):
|
||||||
for f in t.fields:
|
for f in t.fields:
|
||||||
self.visitField(f, t.name, sum=sum, depth=2)
|
self.visitField(f, t.name, sum=sum, depth=2)
|
||||||
args = [f.name for f in t.fields] + [a.name for a in sum.attributes]
|
args = [f.name for f in t.fields] + [a.name for a in sum.attributes]
|
||||||
self.emit("*out = %s(%s);" % (pyfunc_name(t.name), self.buildArgs(args)), 2)
|
self.emit("*out = %s(%s);" % (ast_func_name(t.name), self.buildArgs(args)), 2)
|
||||||
self.emit("if (*out == NULL) goto failed;", 2)
|
self.emit("if (*out == NULL) goto failed;", 2)
|
||||||
self.emit("return 0;", 2)
|
self.emit("return 0;", 2)
|
||||||
self.emit("}", 1)
|
self.emit("}", 1)
|
||||||
|
@ -529,7 +520,7 @@ class Obj2ModVisitor(PickleVisitor):
|
||||||
self.visitField(a, name, prod=prod, depth=1)
|
self.visitField(a, name, prod=prod, depth=1)
|
||||||
args = [f.name for f in prod.fields]
|
args = [f.name for f in prod.fields]
|
||||||
args.extend([a.name for a in prod.attributes])
|
args.extend([a.name for a in prod.attributes])
|
||||||
self.emit("*out = %s(%s);" % (pyfunc_name(name), self.buildArgs(args)), 1)
|
self.emit("*out = %s(%s);" % (ast_func_name(name), self.buildArgs(args)), 1)
|
||||||
self.emit("return 0;", 1)
|
self.emit("return 0;", 1)
|
||||||
self.emit("failed:", 0)
|
self.emit("failed:", 0)
|
||||||
self.emit("Py_XDECREF(tmp);", 1)
|
self.emit("Py_XDECREF(tmp);", 1)
|
||||||
|
|
294
Parser/parser.c
294
Parser/parser.c
File diff suppressed because it is too large
Load Diff
|
@ -34,9 +34,9 @@ _PyPegen_add_type_comment_to_arg(Parser *p, arg_ty a, Token *tc)
|
||||||
if (tco == NULL) {
|
if (tco == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return arg(a->arg, a->annotation, tco,
|
return _PyAST_arg(a->arg, a->annotation, tco,
|
||||||
a->lineno, a->col_offset, a->end_lineno, a->end_col_offset,
|
a->lineno, a->col_offset, a->end_lineno, a->end_col_offset,
|
||||||
p->arena);
|
p->arena);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -568,7 +568,7 @@ _PyPegen_dummy_name(Parser *p, ...)
|
||||||
if (!id) {
|
if (!id) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
cache = Name(id, Load, 1, 0, 1, 0, p->arena);
|
cache = _PyAST_Name(id, Load, 1, 0, 1, 0, p->arena);
|
||||||
return cache;
|
return cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -919,8 +919,8 @@ _PyPegen_name_token(Parser *p)
|
||||||
p->error_indicator = 1;
|
p->error_indicator = 1;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return Name(id, Load, t->lineno, t->col_offset, t->end_lineno, t->end_col_offset,
|
return _PyAST_Name(id, Load, t->lineno, t->col_offset, t->end_lineno,
|
||||||
p->arena);
|
t->end_col_offset, p->arena);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
|
@ -1035,8 +1035,8 @@ _PyPegen_number_token(Parser *p)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Constant(c, NULL, t->lineno, t->col_offset, t->end_lineno, t->end_col_offset,
|
return _PyAST_Constant(c, NULL, t->lineno, t->col_offset, t->end_lineno,
|
||||||
p->arena);
|
t->end_col_offset, p->arena);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int // bool
|
static int // bool
|
||||||
|
@ -1514,7 +1514,7 @@ _PyPegen_join_names_with_dot(Parser *p, expr_ty first_name, expr_ty second_name)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _Py_Name(uni, Load, EXTRA_EXPR(first_name, second_name));
|
return _PyAST_Name(uni, Load, EXTRA_EXPR(first_name, second_name));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Counts the total number of dots in seq's tokens */
|
/* Counts the total number of dots in seq's tokens */
|
||||||
|
@ -1551,7 +1551,7 @@ _PyPegen_alias_for_star(Parser *p)
|
||||||
Py_DECREF(str);
|
Py_DECREF(str);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return alias(str, NULL, p->arena);
|
return _PyAST_alias(str, NULL, p->arena);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Creates a new asdl_seq* with the identifiers of all the names in seq */
|
/* Creates a new asdl_seq* with the identifiers of all the names in seq */
|
||||||
|
@ -1643,13 +1643,13 @@ _set_seq_context(Parser *p, asdl_expr_seq *seq, expr_context_ty ctx)
|
||||||
static expr_ty
|
static expr_ty
|
||||||
_set_name_context(Parser *p, expr_ty e, expr_context_ty ctx)
|
_set_name_context(Parser *p, expr_ty e, expr_context_ty ctx)
|
||||||
{
|
{
|
||||||
return _Py_Name(e->v.Name.id, ctx, EXTRA_EXPR(e, e));
|
return _PyAST_Name(e->v.Name.id, ctx, EXTRA_EXPR(e, e));
|
||||||
}
|
}
|
||||||
|
|
||||||
static expr_ty
|
static expr_ty
|
||||||
_set_tuple_context(Parser *p, expr_ty e, expr_context_ty ctx)
|
_set_tuple_context(Parser *p, expr_ty e, expr_context_ty ctx)
|
||||||
{
|
{
|
||||||
return _Py_Tuple(
|
return _PyAST_Tuple(
|
||||||
_set_seq_context(p, e->v.Tuple.elts, ctx),
|
_set_seq_context(p, e->v.Tuple.elts, ctx),
|
||||||
ctx,
|
ctx,
|
||||||
EXTRA_EXPR(e, e));
|
EXTRA_EXPR(e, e));
|
||||||
|
@ -1658,7 +1658,7 @@ _set_tuple_context(Parser *p, expr_ty e, expr_context_ty ctx)
|
||||||
static expr_ty
|
static expr_ty
|
||||||
_set_list_context(Parser *p, expr_ty e, expr_context_ty ctx)
|
_set_list_context(Parser *p, expr_ty e, expr_context_ty ctx)
|
||||||
{
|
{
|
||||||
return _Py_List(
|
return _PyAST_List(
|
||||||
_set_seq_context(p, e->v.List.elts, ctx),
|
_set_seq_context(p, e->v.List.elts, ctx),
|
||||||
ctx,
|
ctx,
|
||||||
EXTRA_EXPR(e, e));
|
EXTRA_EXPR(e, e));
|
||||||
|
@ -1667,19 +1667,22 @@ _set_list_context(Parser *p, expr_ty e, expr_context_ty ctx)
|
||||||
static expr_ty
|
static expr_ty
|
||||||
_set_subscript_context(Parser *p, expr_ty e, expr_context_ty ctx)
|
_set_subscript_context(Parser *p, expr_ty e, expr_context_ty ctx)
|
||||||
{
|
{
|
||||||
return _Py_Subscript(e->v.Subscript.value, e->v.Subscript.slice, ctx, EXTRA_EXPR(e, e));
|
return _PyAST_Subscript(e->v.Subscript.value, e->v.Subscript.slice,
|
||||||
|
ctx, EXTRA_EXPR(e, e));
|
||||||
}
|
}
|
||||||
|
|
||||||
static expr_ty
|
static expr_ty
|
||||||
_set_attribute_context(Parser *p, expr_ty e, expr_context_ty ctx)
|
_set_attribute_context(Parser *p, expr_ty e, expr_context_ty ctx)
|
||||||
{
|
{
|
||||||
return _Py_Attribute(e->v.Attribute.value, e->v.Attribute.attr, ctx, EXTRA_EXPR(e, e));
|
return _PyAST_Attribute(e->v.Attribute.value, e->v.Attribute.attr,
|
||||||
|
ctx, EXTRA_EXPR(e, e));
|
||||||
}
|
}
|
||||||
|
|
||||||
static expr_ty
|
static expr_ty
|
||||||
_set_starred_context(Parser *p, expr_ty e, expr_context_ty ctx)
|
_set_starred_context(Parser *p, expr_ty e, expr_context_ty ctx)
|
||||||
{
|
{
|
||||||
return _Py_Starred(_PyPegen_set_expr_context(p, e->v.Starred.value, ctx), ctx, EXTRA_EXPR(e, e));
|
return _PyAST_Starred(_PyPegen_set_expr_context(p, e->v.Starred.value, ctx),
|
||||||
|
ctx, EXTRA_EXPR(e, e));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Creates an `expr_ty` equivalent to `expr` but with `ctx` as context */
|
/* Creates an `expr_ty` equivalent to `expr` but with `ctx` as context */
|
||||||
|
@ -1987,8 +1990,8 @@ _PyPegen_make_arguments(Parser *p, asdl_arg_seq *slash_without_default,
|
||||||
kwarg = star_etc->kwarg;
|
kwarg = star_etc->kwarg;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _Py_arguments(posonlyargs, posargs, vararg, kwonlyargs, kwdefaults, kwarg,
|
return _PyAST_arguments(posonlyargs, posargs, vararg, kwonlyargs,
|
||||||
posdefaults, p->arena);
|
kwdefaults, kwarg, posdefaults, p->arena);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Constructs an empty arguments_ty object, that gets used when a function accepts no
|
/* Constructs an empty arguments_ty object, that gets used when a function accepts no
|
||||||
|
@ -2017,8 +2020,8 @@ _PyPegen_empty_arguments(Parser *p)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _Py_arguments(posonlyargs, posargs, NULL, kwonlyargs, kwdefaults, NULL, posdefaults,
|
return _PyAST_arguments(posonlyargs, posargs, NULL, kwonlyargs,
|
||||||
p->arena);
|
kwdefaults, NULL, posdefaults, p->arena);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Encapsulates the value of an operator_ty into an AugOperator struct */
|
/* Encapsulates the value of an operator_ty into an AugOperator struct */
|
||||||
|
@ -2039,7 +2042,7 @@ _PyPegen_function_def_decorators(Parser *p, asdl_expr_seq *decorators, stmt_ty f
|
||||||
{
|
{
|
||||||
assert(function_def != NULL);
|
assert(function_def != NULL);
|
||||||
if (function_def->kind == AsyncFunctionDef_kind) {
|
if (function_def->kind == AsyncFunctionDef_kind) {
|
||||||
return _Py_AsyncFunctionDef(
|
return _PyAST_AsyncFunctionDef(
|
||||||
function_def->v.FunctionDef.name, function_def->v.FunctionDef.args,
|
function_def->v.FunctionDef.name, function_def->v.FunctionDef.args,
|
||||||
function_def->v.FunctionDef.body, decorators, function_def->v.FunctionDef.returns,
|
function_def->v.FunctionDef.body, decorators, function_def->v.FunctionDef.returns,
|
||||||
function_def->v.FunctionDef.type_comment, function_def->lineno,
|
function_def->v.FunctionDef.type_comment, function_def->lineno,
|
||||||
|
@ -2047,12 +2050,13 @@ _PyPegen_function_def_decorators(Parser *p, asdl_expr_seq *decorators, stmt_ty f
|
||||||
p->arena);
|
p->arena);
|
||||||
}
|
}
|
||||||
|
|
||||||
return _Py_FunctionDef(function_def->v.FunctionDef.name, function_def->v.FunctionDef.args,
|
return _PyAST_FunctionDef(
|
||||||
function_def->v.FunctionDef.body, decorators,
|
function_def->v.FunctionDef.name, function_def->v.FunctionDef.args,
|
||||||
function_def->v.FunctionDef.returns,
|
function_def->v.FunctionDef.body, decorators,
|
||||||
function_def->v.FunctionDef.type_comment, function_def->lineno,
|
function_def->v.FunctionDef.returns,
|
||||||
function_def->col_offset, function_def->end_lineno,
|
function_def->v.FunctionDef.type_comment, function_def->lineno,
|
||||||
function_def->end_col_offset, p->arena);
|
function_def->col_offset, function_def->end_lineno,
|
||||||
|
function_def->end_col_offset, p->arena);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Construct a ClassDef equivalent to class_def, but with decorators */
|
/* Construct a ClassDef equivalent to class_def, but with decorators */
|
||||||
|
@ -2060,10 +2064,11 @@ stmt_ty
|
||||||
_PyPegen_class_def_decorators(Parser *p, asdl_expr_seq *decorators, stmt_ty class_def)
|
_PyPegen_class_def_decorators(Parser *p, asdl_expr_seq *decorators, stmt_ty class_def)
|
||||||
{
|
{
|
||||||
assert(class_def != NULL);
|
assert(class_def != NULL);
|
||||||
return _Py_ClassDef(class_def->v.ClassDef.name, class_def->v.ClassDef.bases,
|
return _PyAST_ClassDef(
|
||||||
class_def->v.ClassDef.keywords, class_def->v.ClassDef.body, decorators,
|
class_def->v.ClassDef.name, class_def->v.ClassDef.bases,
|
||||||
class_def->lineno, class_def->col_offset, class_def->end_lineno,
|
class_def->v.ClassDef.keywords, class_def->v.ClassDef.body, decorators,
|
||||||
class_def->end_col_offset, p->arena);
|
class_def->lineno, class_def->col_offset, class_def->end_lineno,
|
||||||
|
class_def->end_col_offset, p->arena);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Construct a KeywordOrStarred */
|
/* Construct a KeywordOrStarred */
|
||||||
|
@ -2214,8 +2219,9 @@ _PyPegen_concatenate_strings(Parser *p, asdl_seq *strings)
|
||||||
if (_PyArena_AddPyObject(p->arena, bytes_str) < 0) {
|
if (_PyArena_AddPyObject(p->arena, bytes_str) < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
return Constant(bytes_str, NULL, first->lineno, first->col_offset, last->end_lineno,
|
return _PyAST_Constant(bytes_str, NULL, first->lineno,
|
||||||
last->end_col_offset, p->arena);
|
first->col_offset, last->end_lineno,
|
||||||
|
last->end_col_offset, p->arena);
|
||||||
}
|
}
|
||||||
|
|
||||||
return _PyPegen_FstringParser_Finish(p, &state, first, last);
|
return _PyPegen_FstringParser_Finish(p, &state, first, last);
|
||||||
|
@ -2244,14 +2250,15 @@ _PyPegen_make_module(Parser *p, asdl_stmt_seq *a) {
|
||||||
if (tag == NULL) {
|
if (tag == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
type_ignore_ty ti = TypeIgnore(p->type_ignore_comments.items[i].lineno, tag, p->arena);
|
type_ignore_ty ti = _PyAST_TypeIgnore(p->type_ignore_comments.items[i].lineno,
|
||||||
|
tag, p->arena);
|
||||||
if (ti == NULL) {
|
if (ti == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
asdl_seq_SET(type_ignores, i, ti);
|
asdl_seq_SET(type_ignores, i, ti);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Module(a, type_ignores, p->arena);
|
return _PyAST_Module(a, type_ignores, p->arena);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error reporting helpers
|
// Error reporting helpers
|
||||||
|
@ -2361,7 +2368,7 @@ expr_ty _PyPegen_collect_call_seqs(Parser *p, asdl_expr_seq *a, asdl_seq *b,
|
||||||
Py_ssize_t total_len = args_len;
|
Py_ssize_t total_len = args_len;
|
||||||
|
|
||||||
if (b == NULL) {
|
if (b == NULL) {
|
||||||
return _Py_Call(_PyPegen_dummy_name(p), a, NULL, lineno, col_offset,
|
return _PyAST_Call(_PyPegen_dummy_name(p), a, NULL, lineno, col_offset,
|
||||||
end_lineno, end_col_offset, arena);
|
end_lineno, end_col_offset, arena);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2383,6 +2390,6 @@ expr_ty _PyPegen_collect_call_seqs(Parser *p, asdl_expr_seq *a, asdl_seq *b,
|
||||||
asdl_seq_SET(args, i, asdl_seq_GET(starreds, i - args_len));
|
asdl_seq_SET(args, i, asdl_seq_GET(starreds, i - args_len));
|
||||||
}
|
}
|
||||||
|
|
||||||
return _Py_Call(_PyPegen_dummy_name(p), args, keywords, lineno,
|
return _PyAST_Call(_PyPegen_dummy_name(p), args, keywords, lineno,
|
||||||
col_offset, end_lineno, end_col_offset, arena);
|
col_offset, end_lineno, end_col_offset, arena);
|
||||||
}
|
}
|
||||||
|
|
|
@ -797,10 +797,11 @@ fstring_find_expr(Parser *p, const char **str, const char *end, int raw, int rec
|
||||||
/* And now create the FormattedValue node that represents this
|
/* And now create the FormattedValue node that represents this
|
||||||
entire expression with the conversion and format spec. */
|
entire expression with the conversion and format spec. */
|
||||||
//TODO: Fix this
|
//TODO: Fix this
|
||||||
*expression = FormattedValue(simple_expression, conversion,
|
*expression = _PyAST_FormattedValue(simple_expression, conversion,
|
||||||
format_spec, first_token->lineno,
|
format_spec, first_token->lineno,
|
||||||
first_token->col_offset, last_token->end_lineno,
|
first_token->col_offset,
|
||||||
last_token->end_col_offset, p->arena);
|
last_token->end_lineno,
|
||||||
|
last_token->end_col_offset, p->arena);
|
||||||
if (!*expression) {
|
if (!*expression) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
@ -1044,8 +1045,9 @@ make_str_node_and_del(Parser *p, PyObject **str, Token* first_token, Token *last
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Constant(s, kind, first_token->lineno, first_token->col_offset,
|
return _PyAST_Constant(s, kind, first_token->lineno, first_token->col_offset,
|
||||||
last_token->end_lineno, last_token->end_col_offset, p->arena);
|
last_token->end_lineno, last_token->end_col_offset,
|
||||||
|
p->arena);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1204,8 +1206,9 @@ _PyPegen_FstringParser_Finish(Parser *p, FstringParser *state, Token* first_toke
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _Py_JoinedStr(seq, first_token->lineno, first_token->col_offset,
|
return _PyAST_JoinedStr(seq, first_token->lineno, first_token->col_offset,
|
||||||
last_token->end_lineno, last_token->end_col_offset, p->arena);
|
last_token->end_lineno, last_token->end_col_offset,
|
||||||
|
p->arena);
|
||||||
|
|
||||||
error:
|
error:
|
||||||
_PyPegen_FstringParser_Dealloc(state);
|
_PyPegen_FstringParser_Dealloc(state);
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -451,8 +451,9 @@ astfold_body(asdl_stmt_seq *stmts, PyArena *ctx_, _PyASTOptimizeState *state)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
asdl_seq_SET(values, 0, st->v.Expr.value);
|
asdl_seq_SET(values, 0, st->v.Expr.value);
|
||||||
expr_ty expr = _Py_JoinedStr(values, st->lineno, st->col_offset,
|
expr_ty expr = _PyAST_JoinedStr(values, st->lineno, st->col_offset,
|
||||||
st->end_lineno, st->end_col_offset, ctx_);
|
st->end_lineno, st->end_col_offset,
|
||||||
|
ctx_);
|
||||||
if (!expr) {
|
if (!expr) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue