| 
									
										
										
										
											2020-06-12 00:51:44 +01:00
										 |  |  | # PEG grammar for Python | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | @trailer ''' | 
					
						
							|  |  |  | void * | 
					
						
							|  |  |  | _PyPegen_parse(Parser *p) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // Initialize keywords | 
					
						
							|  |  |  |     p->keywords = reserved_keywords; | 
					
						
							|  |  |  |     p->n_keyword_lists = n_keyword_lists; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Run parser | 
					
						
							|  |  |  |     void *result = NULL; | 
					
						
							|  |  |  |     if (p->start_rule == Py_file_input) { | 
					
						
							|  |  |  |         result = file_rule(p); | 
					
						
							|  |  |  |     } else if (p->start_rule == Py_single_input) { | 
					
						
							|  |  |  |         result = interactive_rule(p); | 
					
						
							|  |  |  |     } else if (p->start_rule == Py_eval_input) { | 
					
						
							|  |  |  |         result = eval_rule(p); | 
					
						
							| 
									
										
										
										
											2020-04-30 12:12:19 -07:00
										 |  |  |     } else if (p->start_rule == Py_func_type_input) { | 
					
						
							|  |  |  |         result = func_type_rule(p); | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |     } else if (p->start_rule == Py_fstring_input) { | 
					
						
							|  |  |  |         result = fstring_rule(p); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // The end | 
					
						
							|  |  |  | ''' | 
					
						
							| 
									
										
										
										
											2020-04-30 12:12:19 -07:00
										 |  |  | file[mod_ty]: a=[statements] ENDMARKER { _PyPegen_make_module(p, a) } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | interactive[mod_ty]: a=statement_newline { Interactive(a, p->arena) } | 
					
						
							|  |  |  | eval[mod_ty]: a=expressions NEWLINE* ENDMARKER { Expression(a, p->arena) } | 
					
						
							| 
									
										
										
										
											2020-04-30 12:12:19 -07:00
										 |  |  | func_type[mod_ty]: '(' a=[type_expressions] ')' '->' b=expression NEWLINE* ENDMARKER { FunctionType(a, b, p->arena) } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | fstring[expr_ty]: star_expressions | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-30 12:12:19 -07:00
										 |  |  | # type_expressions allow */** but ignore them | 
					
						
							| 
									
										
										
										
											2020-09-16 19:42:00 +01:00
										 |  |  | type_expressions[asdl_expr_seq*]: | 
					
						
							| 
									
										
										
										
											2020-04-30 12:12:19 -07:00
										 |  |  |     | a=','.expression+ ',' '*' b=expression ',' '**' c=expression { | 
					
						
							| 
									
										
										
										
											2020-10-21 22:53:14 +03:00
										 |  |  |         (asdl_expr_seq*)_PyPegen_seq_append_to_end( | 
					
						
							|  |  |  |             p, | 
					
						
							|  |  |  |             CHECK(asdl_seq*, _PyPegen_seq_append_to_end(p, a, b)), | 
					
						
							|  |  |  |             c) } | 
					
						
							| 
									
										
										
										
											2020-09-16 19:42:00 +01:00
										 |  |  |     | a=','.expression+ ',' '*' b=expression { (asdl_expr_seq*)_PyPegen_seq_append_to_end(p, a, b) } | 
					
						
							|  |  |  |     | a=','.expression+ ',' '**' b=expression { (asdl_expr_seq*)_PyPegen_seq_append_to_end(p, a, b) } | 
					
						
							| 
									
										
										
										
											2020-05-03 22:08:14 -07:00
										 |  |  |     | '*' a=expression ',' '**' b=expression { | 
					
						
							| 
									
										
										
										
											2020-10-21 22:53:14 +03:00
										 |  |  |         (asdl_expr_seq*)_PyPegen_seq_append_to_end( | 
					
						
							|  |  |  |             p, | 
					
						
							|  |  |  |             CHECK(asdl_seq*, _PyPegen_singleton_seq(p, a)), | 
					
						
							|  |  |  |             b) } | 
					
						
							| 
									
										
										
										
											2020-09-16 19:42:00 +01:00
										 |  |  |     | '*' a=expression { (asdl_expr_seq*)_PyPegen_singleton_seq(p, a) } | 
					
						
							|  |  |  |     | '**' a=expression { (asdl_expr_seq*)_PyPegen_singleton_seq(p, a) } | 
					
						
							|  |  |  |     | a[asdl_expr_seq*]=','.expression+ {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) } | a[asdl_stmt_seq*]=simple_stmt { a } | 
					
						
							|  |  |  | statement_newline[asdl_stmt_seq*]: | 
					
						
							|  |  |  |     | a=compound_stmt NEWLINE { (asdl_stmt_seq*)_PyPegen_singleton_seq(p, a) } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |     | simple_stmt | 
					
						
							| 
									
										
										
										
											2020-10-21 22:53:14 +03:00
										 |  |  |     | NEWLINE { (asdl_stmt_seq*)_PyPegen_singleton_seq(p, CHECK(stmt_ty, _Py_Pass(EXTRA))) } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |     | ENDMARKER { _PyPegen_interactive_exit(p) } | 
					
						
							| 
									
										
										
										
											2020-09-16 19:42:00 +01:00
										 |  |  | simple_stmt[asdl_stmt_seq*]: | 
					
						
							|  |  |  |     | a=small_stmt !';' NEWLINE { (asdl_stmt_seq*)_PyPegen_singleton_seq(p, a) } # Not needed, there for speedup | 
					
						
							|  |  |  |     | a[asdl_stmt_seq*]=';'.small_stmt+ [';'] NEWLINE { a } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | # NOTE: assignment MUST precede expression, else parsing a simple assignment | 
					
						
							|  |  |  | # will throw a SyntaxError. | 
					
						
							|  |  |  | small_stmt[stmt_ty] (memo): | 
					
						
							|  |  |  |     | assignment | 
					
						
							|  |  |  |     | e=star_expressions { _Py_Expr(e, EXTRA) } | 
					
						
							|  |  |  |     | &'return' return_stmt | 
					
						
							|  |  |  |     | &('import' | 'from') import_stmt | 
					
						
							|  |  |  |     | &'raise' raise_stmt | 
					
						
							|  |  |  |     | 'pass' { _Py_Pass(EXTRA) } | 
					
						
							|  |  |  |     | &'del' del_stmt | 
					
						
							|  |  |  |     | &'yield' yield_stmt | 
					
						
							|  |  |  |     | &'assert' assert_stmt | 
					
						
							|  |  |  |     | 'break' { _Py_Break(EXTRA) } | 
					
						
							|  |  |  |     | 'continue' { _Py_Continue(EXTRA) } | 
					
						
							|  |  |  |     | &'global' global_stmt | 
					
						
							|  |  |  |     | &'nonlocal' nonlocal_stmt | 
					
						
							|  |  |  | compound_stmt[stmt_ty]: | 
					
						
							|  |  |  |     | &('def' | '@' | ASYNC) function_def | 
					
						
							|  |  |  |     | &'if' if_stmt | 
					
						
							|  |  |  |     | &('class' | '@') class_def | 
					
						
							|  |  |  |     | &('with' | ASYNC) with_stmt | 
					
						
							|  |  |  |     | &('for' | ASYNC) for_stmt | 
					
						
							|  |  |  |     | &'try' try_stmt | 
					
						
							|  |  |  |     | &'while' while_stmt | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # NOTE: annotated_rhs may start with 'yield'; yield_expr must start with 'yield' | 
					
						
							| 
									
										
										
										
											2020-05-06 21:11:04 +03:00
										 |  |  | assignment[stmt_ty]: | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |     | a=NAME ':' b=expression c=['=' d=annotated_rhs { d }] { | 
					
						
							| 
									
										
										
										
											2020-05-01 06:27:52 +03:00
										 |  |  |         CHECK_VERSION( | 
					
						
							| 
									
										
										
										
											2020-10-21 22:53:14 +03:00
										 |  |  |             stmt_ty, | 
					
						
							| 
									
										
										
										
											2020-05-01 06:27:52 +03:00
										 |  |  |             6, | 
					
						
							|  |  |  |             "Variable annotation syntax is", | 
					
						
							| 
									
										
										
										
											2020-10-21 22:53:14 +03:00
										 |  |  |             _Py_AnnAssign(CHECK(expr_ty, _PyPegen_set_expr_context(p, a, Store)), b, c, 1, EXTRA) | 
					
						
							| 
									
										
										
										
											2020-05-01 06:27:52 +03:00
										 |  |  |         ) } | 
					
						
							| 
									
										
										
										
											2020-05-14 23:13:50 +03:00
										 |  |  |     | a=('(' b=single_target ')' { b } | 
					
						
							|  |  |  |          | single_subscript_attribute_target) ':' b=expression c=['=' d=annotated_rhs { d }] { | 
					
						
							| 
									
										
										
										
											2020-10-21 22:53:14 +03:00
										 |  |  |         CHECK_VERSION(stmt_ty, 6, "Variable annotations syntax is", _Py_AnnAssign(a, b, c, 0, EXTRA)) } | 
					
						
							| 
									
										
										
										
											2020-09-16 19:42:00 +01:00
										 |  |  |     | a[asdl_expr_seq*]=(z=star_targets '=' { z })+ b=(yield_expr | star_expressions) !'=' tc=[TYPE_COMMENT] { | 
					
						
							| 
									
										
										
										
											2020-04-30 12:12:19 -07:00
										 |  |  |          _Py_Assign(a, b, NEW_TYPE_COMMENT(p, tc), EXTRA) } | 
					
						
							| 
									
										
										
										
											2020-06-19 02:10:43 +03:00
										 |  |  |     | a=single_target b=augassign ~ c=(yield_expr | star_expressions) { | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |          _Py_AugAssign(a, b->kind, c, EXTRA) } | 
					
						
							|  |  |  |     | invalid_assignment | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | augassign[AugOperator*]: | 
					
						
							| 
									
										
										
										
											2020-05-01 06:27:52 +03:00
										 |  |  |     | '+=' { _PyPegen_augoperator(p, Add) } | 
					
						
							|  |  |  |     | '-=' { _PyPegen_augoperator(p, Sub) } | 
					
						
							|  |  |  |     | '*=' { _PyPegen_augoperator(p, Mult) } | 
					
						
							| 
									
										
										
										
											2020-10-21 22:53:14 +03:00
										 |  |  |     | '@=' { CHECK_VERSION(AugOperator*, 5, "The '@' operator is", _PyPegen_augoperator(p, MatMult)) } | 
					
						
							| 
									
										
										
										
											2020-05-01 06:27:52 +03:00
										 |  |  |     | '/=' { _PyPegen_augoperator(p, Div) } | 
					
						
							|  |  |  |     | '%=' { _PyPegen_augoperator(p, Mod) } | 
					
						
							|  |  |  |     | '&=' { _PyPegen_augoperator(p, BitAnd) } | 
					
						
							|  |  |  |     | '|=' { _PyPegen_augoperator(p, BitOr) } | 
					
						
							|  |  |  |     | '^=' { _PyPegen_augoperator(p, BitXor) } | 
					
						
							|  |  |  |     | '<<=' { _PyPegen_augoperator(p, LShift) } | 
					
						
							|  |  |  |     | '>>=' { _PyPegen_augoperator(p, RShift) } | 
					
						
							|  |  |  |     | '**=' { _PyPegen_augoperator(p, Pow) } | 
					
						
							|  |  |  |     | '//=' { _PyPegen_augoperator(p, FloorDiv) } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 19:42:00 +01:00
										 |  |  | global_stmt[stmt_ty]: 'global' a[asdl_expr_seq*]=','.NAME+ { | 
					
						
							| 
									
										
										
										
											2020-10-21 22:53:14 +03:00
										 |  |  |     _Py_Global(CHECK(asdl_identifier_seq*, _PyPegen_map_names_to_ids(p, a)), EXTRA) } | 
					
						
							| 
									
										
										
										
											2020-09-16 19:42:00 +01:00
										 |  |  | nonlocal_stmt[stmt_ty]: 'nonlocal' a[asdl_expr_seq*]=','.NAME+ { | 
					
						
							| 
									
										
										
										
											2020-10-21 22:53:14 +03:00
										 |  |  |     _Py_Nonlocal(CHECK(asdl_identifier_seq*, _PyPegen_map_names_to_ids(p, a)), EXTRA) } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | yield_stmt[stmt_ty]: y=yield_expr { _Py_Expr(y, EXTRA) } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | assert_stmt[stmt_ty]: 'assert' a=expression b=[',' z=expression { z }] { _Py_Assert(a, b, EXTRA) } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-19 02:10:43 +03:00
										 |  |  | del_stmt[stmt_ty]: | 
					
						
							|  |  |  |     | 'del' a=del_targets &(';' | NEWLINE) { _Py_Delete(a, EXTRA) } | 
					
						
							|  |  |  |     | invalid_del_stmt | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | import_stmt[stmt_ty]: import_name | import_from | 
					
						
							|  |  |  | import_name[stmt_ty]: 'import' a=dotted_as_names { _Py_Import(a, EXTRA) } | 
					
						
							|  |  |  | # note below: the ('.' | '...') is necessary because '...' is tokenized as ELLIPSIS | 
					
						
							|  |  |  | import_from[stmt_ty]: | 
					
						
							|  |  |  |     | 'from' a=('.' | '...')* b=dotted_name 'import' c=import_from_targets { | 
					
						
							|  |  |  |         _Py_ImportFrom(b->v.Name.id, c, _PyPegen_seq_count_dots(a), EXTRA) } | 
					
						
							|  |  |  |     | 'from' a=('.' | '...')+ 'import' b=import_from_targets { | 
					
						
							|  |  |  |         _Py_ImportFrom(NULL, b, _PyPegen_seq_count_dots(a), EXTRA) } | 
					
						
							| 
									
										
										
										
											2020-09-16 19:42:00 +01:00
										 |  |  | import_from_targets[asdl_alias_seq*]: | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |     | '(' a=import_from_as_names [','] ')' { a } | 
					
						
							| 
									
										
										
										
											2020-05-21 23:41:58 +03:00
										 |  |  |     | import_from_as_names !',' | 
					
						
							| 
									
										
										
										
											2020-10-21 22:53:14 +03:00
										 |  |  |     | '*' { (asdl_alias_seq*)_PyPegen_singleton_seq(p, CHECK(alias_ty, _PyPegen_alias_for_star(p))) } | 
					
						
							| 
									
										
										
										
											2020-05-21 23:41:58 +03:00
										 |  |  |     | invalid_import_from_targets | 
					
						
							| 
									
										
										
										
											2020-09-16 19:42:00 +01:00
										 |  |  | import_from_as_names[asdl_alias_seq*]: | 
					
						
							|  |  |  |     | a[asdl_alias_seq*]=','.import_from_as_name+ { a } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | import_from_as_name[alias_ty]: | 
					
						
							|  |  |  |     | a=NAME b=['as' z=NAME { z }] { _Py_alias(a->v.Name.id, | 
					
						
							|  |  |  |                                                (b) ? ((expr_ty) b)->v.Name.id : NULL, | 
					
						
							|  |  |  |                                                p->arena) } | 
					
						
							| 
									
										
										
										
											2020-09-16 19:42:00 +01:00
										 |  |  | dotted_as_names[asdl_alias_seq*]: | 
					
						
							|  |  |  |     | a[asdl_alias_seq*]=','.dotted_as_name+ { a } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | dotted_as_name[alias_ty]: | 
					
						
							|  |  |  |     | a=dotted_name b=['as' z=NAME { z }] { _Py_alias(a->v.Name.id, | 
					
						
							|  |  |  |                                                       (b) ? ((expr_ty) b)->v.Name.id : NULL, | 
					
						
							|  |  |  |                                                       p->arena) } | 
					
						
							|  |  |  | dotted_name[expr_ty]: | 
					
						
							|  |  |  |     | a=dotted_name '.' b=NAME { _PyPegen_join_names_with_dot(p, a, b) } | 
					
						
							|  |  |  |     | NAME | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if_stmt[stmt_ty]: | 
					
						
							| 
									
										
										
										
											2020-10-21 22:53:14 +03:00
										 |  |  |     | 'if' a=named_expression ':' b=block c=elif_stmt { | 
					
						
							|  |  |  |         _Py_If(a, b, CHECK(asdl_stmt_seq*, _PyPegen_singleton_seq(p, c)), EXTRA) } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |     | 'if' a=named_expression ':' b=block c=[else_block] { _Py_If(a, b, c, EXTRA) } | 
					
						
							|  |  |  | elif_stmt[stmt_ty]: | 
					
						
							| 
									
										
										
										
											2020-10-21 22:53:14 +03:00
										 |  |  |     | 'elif' a=named_expression ':' b=block c=elif_stmt { | 
					
						
							|  |  |  |         _Py_If(a, b, CHECK(asdl_stmt_seq*, _PyPegen_singleton_seq(p, c)), EXTRA) } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |     | 'elif' a=named_expression ':' b=block c=[else_block] { _Py_If(a, b, c, EXTRA) } | 
					
						
							| 
									
										
										
										
											2020-09-16 19:42:00 +01:00
										 |  |  | else_block[asdl_stmt_seq*]: 'else' ':' b=block { b } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | while_stmt[stmt_ty]: | 
					
						
							|  |  |  |     | 'while' a=named_expression ':' b=block c=[else_block] { _Py_While(a, b, c, EXTRA) } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | for_stmt[stmt_ty]: | 
					
						
							| 
									
										
										
										
											2020-06-19 02:10:43 +03:00
										 |  |  |     | 'for' t=star_targets 'in' ~ ex=star_expressions ':' tc=[TYPE_COMMENT] b=block el=[else_block] { | 
					
						
							| 
									
										
										
										
											2020-05-01 06:27:52 +03:00
										 |  |  |         _Py_For(t, ex, b, el, NEW_TYPE_COMMENT(p, tc), EXTRA) } | 
					
						
							| 
									
										
										
										
											2020-06-19 02:10:43 +03:00
										 |  |  |     | ASYNC 'for' t=star_targets 'in' ~ ex=star_expressions ':' tc=[TYPE_COMMENT] b=block el=[else_block] { | 
					
						
							| 
									
										
										
										
											2020-10-21 22:53:14 +03:00
										 |  |  |         CHECK_VERSION(stmt_ty, 5, "Async for loops are", _Py_AsyncFor(t, ex, b, el, NEW_TYPE_COMMENT(p, tc), EXTRA)) } | 
					
						
							| 
									
										
										
										
											2020-06-19 02:10:43 +03:00
										 |  |  |     | invalid_for_target | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | with_stmt[stmt_ty]: | 
					
						
							| 
									
										
										
										
											2020-09-16 19:42:00 +01:00
										 |  |  |     | 'with' '(' a[asdl_withitem_seq*]=','.with_item+ ','? ')' ':' b=block { | 
					
						
							| 
									
										
										
										
											2020-05-01 06:27:52 +03:00
										 |  |  |         _Py_With(a, b, NULL, EXTRA) } | 
					
						
							| 
									
										
										
										
											2020-09-16 19:42:00 +01:00
										 |  |  |     | 'with' a[asdl_withitem_seq*]=','.with_item+ ':' tc=[TYPE_COMMENT] b=block { | 
					
						
							| 
									
										
										
										
											2020-05-01 06:27:52 +03:00
										 |  |  |         _Py_With(a, b, NEW_TYPE_COMMENT(p, tc), EXTRA) } | 
					
						
							| 
									
										
										
										
											2020-09-16 19:42:00 +01:00
										 |  |  |     | ASYNC 'with' '(' a[asdl_withitem_seq*]=','.with_item+ ','? ')' ':' b=block { | 
					
						
							| 
									
										
										
										
											2020-10-21 22:53:14 +03:00
										 |  |  |        CHECK_VERSION(stmt_ty, 5, "Async with statements are", _Py_AsyncWith(a, b, NULL, EXTRA)) } | 
					
						
							| 
									
										
										
										
											2020-09-16 19:42:00 +01:00
										 |  |  |     | ASYNC 'with' a[asdl_withitem_seq*]=','.with_item+ ':' tc=[TYPE_COMMENT] b=block { | 
					
						
							| 
									
										
										
										
											2020-10-21 22:53:14 +03:00
										 |  |  |        CHECK_VERSION(stmt_ty, 5, "Async with statements are", _Py_AsyncWith(a, b, NEW_TYPE_COMMENT(p, tc), EXTRA)) } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | with_item[withitem_ty]: | 
					
						
							| 
									
										
										
										
											2020-10-09 12:56:48 +03:00
										 |  |  |     | e=expression 'as' t=star_target &(',' | ')' | ':') { _Py_withitem(e, t, p->arena) } | 
					
						
							| 
									
										
										
										
											2020-06-19 02:10:43 +03:00
										 |  |  |     | invalid_with_item | 
					
						
							|  |  |  |     | e=expression { _Py_withitem(e, NULL, p->arena) } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | try_stmt[stmt_ty]: | 
					
						
							|  |  |  |     | 'try' ':' b=block f=finally_block { _Py_Try(b, NULL, NULL, f, EXTRA) } | 
					
						
							| 
									
										
										
										
											2020-09-16 19:42:00 +01:00
										 |  |  |     | 'try' ':' b=block ex[asdl_excepthandler_seq*]=except_block+ el=[else_block] f=[finally_block] { _Py_Try(b, ex, el, f, EXTRA) } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | except_block[excepthandler_ty]: | 
					
						
							| 
									
										
										
										
											2020-05-14 23:13:50 +03:00
										 |  |  |     | 'except' e=expression t=['as' z=NAME { z }] ':' b=block { | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |         _Py_ExceptHandler(e, (t) ? ((expr_ty) t)->v.Name.id : NULL, b, EXTRA) } | 
					
						
							|  |  |  |     | 'except' ':' b=block { _Py_ExceptHandler(NULL, NULL, b, EXTRA) } | 
					
						
							| 
									
										
										
										
											2020-09-16 19:42:00 +01:00
										 |  |  | finally_block[asdl_stmt_seq*]: 'finally' ':' a=block { a } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | return_stmt[stmt_ty]: | 
					
						
							|  |  |  |     | 'return' a=[star_expressions] { _Py_Return(a, EXTRA) } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | raise_stmt[stmt_ty]: | 
					
						
							|  |  |  |     | 'raise' a=expression b=['from' z=expression { z }] { _Py_Raise(a, b, EXTRA) } | 
					
						
							|  |  |  |     | 'raise' { _Py_Raise(NULL, NULL, EXTRA) } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function_def[stmt_ty]: | 
					
						
							|  |  |  |     | d=decorators f=function_def_raw { _PyPegen_function_def_decorators(p, d, f) } | 
					
						
							|  |  |  |     | function_def_raw | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function_def_raw[stmt_ty]: | 
					
						
							| 
									
										
										
										
											2020-05-01 06:27:52 +03:00
										 |  |  |     | 'def' n=NAME '(' params=[params] ')' a=['->' z=expression { z }] ':' tc=[func_type_comment] b=block { | 
					
						
							|  |  |  |         _Py_FunctionDef(n->v.Name.id, | 
					
						
							| 
									
										
										
										
											2020-10-21 22:53:14 +03:00
										 |  |  |                         (params) ? params : CHECK(arguments_ty, _PyPegen_empty_arguments(p)), | 
					
						
							| 
									
										
										
										
											2020-05-01 06:27:52 +03:00
										 |  |  |                         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 { | 
					
						
							|  |  |  |         CHECK_VERSION( | 
					
						
							| 
									
										
										
										
											2020-10-21 22:53:14 +03:00
										 |  |  |             stmt_ty, | 
					
						
							| 
									
										
										
										
											2020-05-01 06:27:52 +03:00
										 |  |  |             5, | 
					
						
							|  |  |  |             "Async functions are", | 
					
						
							|  |  |  |             _Py_AsyncFunctionDef(n->v.Name.id, | 
					
						
							| 
									
										
										
										
											2020-10-21 22:53:14 +03:00
										 |  |  |                             (params) ? params : CHECK(arguments_ty, _PyPegen_empty_arguments(p)), | 
					
						
							| 
									
										
										
										
											2020-05-01 06:27:52 +03:00
										 |  |  |                             b, NULL, a, NEW_TYPE_COMMENT(p, tc), EXTRA) | 
					
						
							|  |  |  |         ) } | 
					
						
							| 
									
										
										
										
											2020-05-01 16:32:09 +01:00
										 |  |  | func_type_comment[Token*]: | 
					
						
							| 
									
										
										
										
											2020-04-30 12:12:19 -07:00
										 |  |  |     | NEWLINE t=TYPE_COMMENT &(NEWLINE INDENT) { t }  # Must be followed by indented block | 
					
						
							|  |  |  |     | invalid_double_type_comments | 
					
						
							|  |  |  |     | TYPE_COMMENT | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | params[arguments_ty]: | 
					
						
							|  |  |  |     | invalid_parameters | 
					
						
							|  |  |  |     | parameters | 
					
						
							| 
									
										
										
										
											2020-04-30 12:12:19 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | parameters[arguments_ty]: | 
					
						
							| 
									
										
										
										
											2020-09-16 19:42:00 +01:00
										 |  |  |     | a=slash_no_default b[asdl_arg_seq*]=param_no_default* c=param_with_default* d=[star_etc] { | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |         _PyPegen_make_arguments(p, a, NULL, b, c, d) } | 
					
						
							| 
									
										
										
										
											2020-04-30 12:12:19 -07:00
										 |  |  |     | a=slash_with_default b=param_with_default* c=[star_etc] { | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |         _PyPegen_make_arguments(p, NULL, a, NULL, b, c) } | 
					
						
							| 
									
										
										
										
											2020-09-16 19:42:00 +01:00
										 |  |  |     | a[asdl_arg_seq*]=param_no_default+ b=param_with_default* c=[star_etc] { | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |         _PyPegen_make_arguments(p, NULL, NULL, a, b, c) } | 
					
						
							| 
									
										
										
										
											2020-04-30 12:12:19 -07:00
										 |  |  |     | a=param_with_default+ b=[star_etc] { _PyPegen_make_arguments(p, NULL, NULL, NULL, a, b)} | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |     | a=star_etc { _PyPegen_make_arguments(p, NULL, NULL, NULL, NULL, a) } | 
					
						
							| 
									
										
										
										
											2020-04-30 12:12:19 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Some duplication here because we can't write (',' | &')'), | 
					
						
							|  |  |  | # which is because we don't support empty alternatives (yet). | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2020-09-16 19:42:00 +01:00
										 |  |  | slash_no_default[asdl_arg_seq*]: | 
					
						
							|  |  |  |     | a[asdl_arg_seq*]=param_no_default+ '/' ',' { a } | 
					
						
							|  |  |  |     | a[asdl_arg_seq*]=param_no_default+ '/' &')' { a } | 
					
						
							| 
									
										
										
										
											2020-04-30 12:12:19 -07:00
										 |  |  | slash_with_default[SlashWithDefault*]: | 
					
						
							| 
									
										
										
										
											2020-09-16 19:42:00 +01:00
										 |  |  |     | a=param_no_default* b=param_with_default+ '/' ',' { _PyPegen_slash_with_default(p, (asdl_arg_seq *)a, b) } | 
					
						
							|  |  |  |     | a=param_no_default* b=param_with_default+ '/' &')' { _PyPegen_slash_with_default(p, (asdl_arg_seq *)a, b) } | 
					
						
							| 
									
										
										
										
											2020-04-30 12:12:19 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | star_etc[StarEtc*]: | 
					
						
							| 
									
										
										
										
											2020-04-30 12:12:19 -07:00
										 |  |  |     | '*' a=param_no_default b=param_maybe_default* c=[kwds] { | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |         _PyPegen_star_etc(p, a, b, c) } | 
					
						
							| 
									
										
										
										
											2020-04-30 12:12:19 -07:00
										 |  |  |     | '*' ',' b=param_maybe_default+ c=[kwds] { | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |         _PyPegen_star_etc(p, NULL, b, c) } | 
					
						
							| 
									
										
										
										
											2020-04-30 12:12:19 -07:00
										 |  |  |     | a=kwds { _PyPegen_star_etc(p, NULL, NULL, a) } | 
					
						
							| 
									
										
										
										
											2020-05-04 13:58:31 +03:00
										 |  |  |     | invalid_star_etc | 
					
						
							| 
									
										
										
										
											2020-04-30 12:12:19 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-01 09:42:03 -07:00
										 |  |  | kwds[arg_ty]: '**' a=param_no_default { a } | 
					
						
							| 
									
										
										
										
											2020-04-30 12:12:19 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | # One parameter.  This *includes* a following comma and type comment. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # There are three styles: | 
					
						
							|  |  |  | # - No default | 
					
						
							|  |  |  | # - With default | 
					
						
							|  |  |  | # - Maybe with default | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # There are two alternative forms of each, to deal with type comments: | 
					
						
							|  |  |  | # - Ends in a comma followed by an optional type comment | 
					
						
							|  |  |  | # - No comma, optional type comment, must be followed by close paren | 
					
						
							|  |  |  | # The latter form is for a final parameter without trailing comma. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | param_no_default[arg_ty]: | 
					
						
							|  |  |  |     | a=param ',' tc=TYPE_COMMENT? { _PyPegen_add_type_comment_to_arg(p, a, tc) } | 
					
						
							|  |  |  |     | a=param tc=TYPE_COMMENT? &')' { _PyPegen_add_type_comment_to_arg(p, a, tc) } | 
					
						
							|  |  |  | param_with_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) } | 
					
						
							|  |  |  | 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) } | 
					
						
							|  |  |  | param[arg_ty]: a=NAME b=annotation? { _Py_arg(a->v.Name.id, b, NULL, EXTRA) } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | annotation[expr_ty]: ':' a=expression { a } | 
					
						
							|  |  |  | default[expr_ty]: '=' a=expression { a } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 19:42:00 +01:00
										 |  |  | decorators[asdl_expr_seq*]: a[asdl_expr_seq*]=('@' f=named_expression NEWLINE { f })+ { a } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | class_def[stmt_ty]: | 
					
						
							|  |  |  |     | a=decorators b=class_def_raw { _PyPegen_class_def_decorators(p, a, b) } | 
					
						
							|  |  |  |     | class_def_raw | 
					
						
							|  |  |  | class_def_raw[stmt_ty]: | 
					
						
							|  |  |  |     | 'class' a=NAME b=['(' z=[arguments] ')' { z }] ':' c=block { | 
					
						
							|  |  |  |         _Py_ClassDef(a->v.Name.id, | 
					
						
							|  |  |  |                      (b) ? ((expr_ty) b)->v.Call.args : NULL, | 
					
						
							|  |  |  |                      (b) ? ((expr_ty) b)->v.Call.keywords : NULL, | 
					
						
							|  |  |  |                      c, NULL, EXTRA) } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 19:42:00 +01:00
										 |  |  | block[asdl_stmt_seq*] (memo): | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |     | NEWLINE INDENT a=statements DEDENT { a } | 
					
						
							|  |  |  |     | simple_stmt | 
					
						
							|  |  |  |     | invalid_block | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 19:42:00 +01:00
										 |  |  | expressions_list[asdl_expr_seq*]: a[asdl_expr_seq*]=','.star_expression+ [','] { a } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | star_expressions[expr_ty]: | 
					
						
							|  |  |  |     | a=star_expression b=(',' c=star_expression { c })+ [','] { | 
					
						
							| 
									
										
										
										
											2020-10-21 22:53:14 +03:00
										 |  |  |         _Py_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) } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |     | star_expression | 
					
						
							|  |  |  | star_expression[expr_ty] (memo): | 
					
						
							|  |  |  |     | '*' a=bitwise_or { _Py_Starred(a, Load, EXTRA) } | 
					
						
							|  |  |  |     | expression | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 19:42:00 +01:00
										 |  |  | star_named_expressions[asdl_expr_seq*]: a[asdl_expr_seq*]=','.star_named_expression+ [','] { a } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | star_named_expression[expr_ty]: | 
					
						
							|  |  |  |     | '*' a=bitwise_or { _Py_Starred(a, Load, EXTRA) } | 
					
						
							|  |  |  |     | named_expression | 
					
						
							|  |  |  | named_expression[expr_ty]: | 
					
						
							| 
									
										
										
										
											2020-10-21 22:53:14 +03:00
										 |  |  |     | a=NAME ':=' ~ b=expression { _Py_NamedExpr(CHECK(expr_ty, _PyPegen_set_expr_context(p, a, Store)), b, EXTRA) } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |     | expression !':=' | 
					
						
							|  |  |  |     | invalid_named_expression | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | annotated_rhs[expr_ty]: yield_expr | star_expressions | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | expressions[expr_ty]: | 
					
						
							|  |  |  |     | a=expression b=(',' c=expression { c })+ [','] { | 
					
						
							| 
									
										
										
										
											2020-10-21 22:53:14 +03:00
										 |  |  |         _Py_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) } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |     | expression | 
					
						
							|  |  |  | expression[expr_ty] (memo): | 
					
						
							|  |  |  |     | a=disjunction 'if' b=disjunction 'else' c=expression { _Py_IfExp(b, a, c, EXTRA) } | 
					
						
							|  |  |  |     | disjunction | 
					
						
							|  |  |  |     | lambdef | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | lambdef[expr_ty]: | 
					
						
							| 
									
										
										
										
											2020-10-21 22:53:14 +03:00
										 |  |  |     | 'lambda' a=[lambda_params] ':' b=expression { | 
					
						
							|  |  |  |         _Py_Lambda((a) ? a : CHECK(arguments_ty, _PyPegen_empty_arguments(p)), b, EXTRA) } | 
					
						
							| 
									
										
										
										
											2020-06-10 14:07:06 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | lambda_params[arguments_ty]: | 
					
						
							|  |  |  |     | invalid_lambda_parameters | 
					
						
							|  |  |  |     | lambda_parameters | 
					
						
							| 
									
										
										
										
											2020-05-01 09:42:03 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | # lambda_parameters etc. duplicates parameters but without annotations | 
					
						
							|  |  |  | # or type comments, and if there's no comma after a parameter, we expect | 
					
						
							|  |  |  | # a colon, not a close parenthesis.  (For more, see parameters above.) | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | lambda_parameters[arguments_ty]: | 
					
						
							| 
									
										
										
										
											2020-09-16 19:42:00 +01:00
										 |  |  |     | a=lambda_slash_no_default b[asdl_arg_seq*]=lambda_param_no_default* c=lambda_param_with_default* d=[lambda_star_etc] { | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |         _PyPegen_make_arguments(p, a, NULL, b, c, d) } | 
					
						
							| 
									
										
										
										
											2020-05-01 09:42:03 -07:00
										 |  |  |     | a=lambda_slash_with_default b=lambda_param_with_default* c=[lambda_star_etc] { | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |         _PyPegen_make_arguments(p, NULL, a, NULL, b, c) } | 
					
						
							| 
									
										
										
										
											2020-09-16 19:42:00 +01:00
										 |  |  |     | a[asdl_arg_seq*]=lambda_param_no_default+ b=lambda_param_with_default* c=[lambda_star_etc] { | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |         _PyPegen_make_arguments(p, NULL, NULL, a, b, c) } | 
					
						
							| 
									
										
										
										
											2020-05-01 09:42:03 -07:00
										 |  |  |     | a=lambda_param_with_default+ b=[lambda_star_etc] { _PyPegen_make_arguments(p, NULL, NULL, NULL, a, b)} | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |     | a=lambda_star_etc { _PyPegen_make_arguments(p, NULL, NULL, NULL, NULL, a) } | 
					
						
							| 
									
										
										
										
											2020-05-01 09:42:03 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 19:42:00 +01:00
										 |  |  | lambda_slash_no_default[asdl_arg_seq*]: | 
					
						
							|  |  |  |     | a[asdl_arg_seq*]=lambda_param_no_default+ '/' ',' { a } | 
					
						
							|  |  |  |     | a[asdl_arg_seq*]=lambda_param_no_default+ '/' &':' { a } | 
					
						
							| 
									
										
										
										
											2020-05-01 09:42:03 -07:00
										 |  |  | lambda_slash_with_default[SlashWithDefault*]: | 
					
						
							| 
									
										
										
										
											2020-09-16 19:42:00 +01:00
										 |  |  |     | a=lambda_param_no_default* b=lambda_param_with_default+ '/' ',' { _PyPegen_slash_with_default(p, (asdl_arg_seq *)a, b) } | 
					
						
							|  |  |  |     | a=lambda_param_no_default* b=lambda_param_with_default+ '/' &':' { _PyPegen_slash_with_default(p, (asdl_arg_seq *)a, b) } | 
					
						
							| 
									
										
										
										
											2020-05-01 09:42:03 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | lambda_star_etc[StarEtc*]: | 
					
						
							| 
									
										
										
										
											2020-05-01 09:42:03 -07:00
										 |  |  |     | '*' a=lambda_param_no_default b=lambda_param_maybe_default* c=[lambda_kwds] { | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |         _PyPegen_star_etc(p, a, b, c) } | 
					
						
							| 
									
										
										
										
											2020-05-01 09:42:03 -07:00
										 |  |  |     | '*' ',' b=lambda_param_maybe_default+ c=[lambda_kwds] { | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |         _PyPegen_star_etc(p, NULL, b, c) } | 
					
						
							| 
									
										
										
										
											2020-05-01 09:42:03 -07:00
										 |  |  |     | a=lambda_kwds { _PyPegen_star_etc(p, NULL, NULL, a) } | 
					
						
							| 
									
										
										
										
											2020-05-04 13:58:31 +03:00
										 |  |  |     | invalid_lambda_star_etc | 
					
						
							| 
									
										
										
										
											2020-05-01 09:42:03 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | lambda_kwds[arg_ty]: '**' a=lambda_param_no_default { a } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | lambda_param_no_default[arg_ty]: | 
					
						
							|  |  |  |     | a=lambda_param ',' { a } | 
					
						
							|  |  |  |     | a=lambda_param &':' { a } | 
					
						
							|  |  |  | lambda_param_with_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) } | 
					
						
							|  |  |  | 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) } | 
					
						
							|  |  |  | lambda_param[arg_ty]: a=NAME { _Py_arg(a->v.Name.id, NULL, NULL, EXTRA) } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | disjunction[expr_ty] (memo): | 
					
						
							|  |  |  |     | a=conjunction b=('or' c=conjunction { c })+ { _Py_BoolOp( | 
					
						
							|  |  |  |         Or, | 
					
						
							| 
									
										
										
										
											2020-10-21 22:53:14 +03:00
										 |  |  |         CHECK(asdl_expr_seq*, _PyPegen_seq_insert_in_front(p, a, b)), | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |         EXTRA) } | 
					
						
							|  |  |  |     | conjunction | 
					
						
							|  |  |  | conjunction[expr_ty] (memo): | 
					
						
							|  |  |  |     | a=inversion b=('and' c=inversion { c })+ { _Py_BoolOp( | 
					
						
							|  |  |  |         And, | 
					
						
							| 
									
										
										
										
											2020-10-21 22:53:14 +03:00
										 |  |  |         CHECK(asdl_expr_seq*, _PyPegen_seq_insert_in_front(p, a, b)), | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |         EXTRA) } | 
					
						
							|  |  |  |     | inversion | 
					
						
							|  |  |  | inversion[expr_ty] (memo): | 
					
						
							|  |  |  |     | 'not' a=inversion { _Py_UnaryOp(Not, a, EXTRA) } | 
					
						
							|  |  |  |     | comparison | 
					
						
							|  |  |  | comparison[expr_ty]: | 
					
						
							|  |  |  |     | a=bitwise_or b=compare_op_bitwise_or_pair+ { | 
					
						
							| 
									
										
										
										
											2020-10-21 22:53:14 +03:00
										 |  |  |         _Py_Compare( | 
					
						
							|  |  |  |             a, | 
					
						
							|  |  |  |             CHECK(asdl_int_seq*, _PyPegen_get_cmpops(p, b)), | 
					
						
							|  |  |  |             CHECK(asdl_expr_seq*, _PyPegen_get_exprs(p, b)), | 
					
						
							|  |  |  |             EXTRA) } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |     | bitwise_or | 
					
						
							|  |  |  | compare_op_bitwise_or_pair[CmpopExprPair*]: | 
					
						
							|  |  |  |     | eq_bitwise_or | 
					
						
							|  |  |  |     | noteq_bitwise_or | 
					
						
							|  |  |  |     | lte_bitwise_or | 
					
						
							|  |  |  |     | lt_bitwise_or | 
					
						
							|  |  |  |     | gte_bitwise_or | 
					
						
							|  |  |  |     | gt_bitwise_or | 
					
						
							|  |  |  |     | notin_bitwise_or | 
					
						
							|  |  |  |     | in_bitwise_or | 
					
						
							|  |  |  |     | isnot_bitwise_or | 
					
						
							|  |  |  |     | is_bitwise_or | 
					
						
							|  |  |  | eq_bitwise_or[CmpopExprPair*]: '==' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, Eq, a) } | 
					
						
							| 
									
										
										
										
											2020-04-27 18:02:07 +01:00
										 |  |  | noteq_bitwise_or[CmpopExprPair*]: | 
					
						
							|  |  |  |     | (tok='!=' {_PyPegen_check_barry_as_flufl(p) ? NULL : tok}) a=bitwise_or {_PyPegen_cmpop_expr_pair(p, NotEq, a) } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | lte_bitwise_or[CmpopExprPair*]: '<=' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, LtE, a) } | 
					
						
							|  |  |  | lt_bitwise_or[CmpopExprPair*]: '<' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, Lt, a) } | 
					
						
							|  |  |  | gte_bitwise_or[CmpopExprPair*]: '>=' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, GtE, a) } | 
					
						
							|  |  |  | gt_bitwise_or[CmpopExprPair*]: '>' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, Gt, a) } | 
					
						
							|  |  |  | notin_bitwise_or[CmpopExprPair*]: 'not' 'in' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, NotIn, a) } | 
					
						
							|  |  |  | in_bitwise_or[CmpopExprPair*]: 'in' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, In, a) } | 
					
						
							|  |  |  | isnot_bitwise_or[CmpopExprPair*]: 'is' 'not' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, IsNot, a) } | 
					
						
							|  |  |  | is_bitwise_or[CmpopExprPair*]: 'is' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, Is, a) } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bitwise_or[expr_ty]: | 
					
						
							|  |  |  |     | a=bitwise_or '|' b=bitwise_xor { _Py_BinOp(a, BitOr, b, EXTRA) } | 
					
						
							|  |  |  |     | bitwise_xor | 
					
						
							|  |  |  | bitwise_xor[expr_ty]: | 
					
						
							|  |  |  |     | a=bitwise_xor '^' b=bitwise_and { _Py_BinOp(a, BitXor, b, EXTRA) } | 
					
						
							|  |  |  |     | bitwise_and | 
					
						
							|  |  |  | bitwise_and[expr_ty]: | 
					
						
							|  |  |  |     | a=bitwise_and '&' b=shift_expr { _Py_BinOp(a, BitAnd, b, EXTRA) } | 
					
						
							|  |  |  |     | shift_expr | 
					
						
							|  |  |  | shift_expr[expr_ty]: | 
					
						
							|  |  |  |     | a=shift_expr '<<' b=sum { _Py_BinOp(a, LShift, b, EXTRA) } | 
					
						
							|  |  |  |     | a=shift_expr '>>' b=sum { _Py_BinOp(a, RShift, b, EXTRA) } | 
					
						
							|  |  |  |     | sum | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | sum[expr_ty]: | 
					
						
							|  |  |  |     | a=sum '+' b=term { _Py_BinOp(a, Add, b, EXTRA) } | 
					
						
							|  |  |  |     | a=sum '-' b=term { _Py_BinOp(a, Sub, b, EXTRA) } | 
					
						
							|  |  |  |     | term | 
					
						
							|  |  |  | term[expr_ty]: | 
					
						
							|  |  |  |     | a=term '*' b=factor { _Py_BinOp(a, Mult, b, EXTRA) } | 
					
						
							|  |  |  |     | a=term '/' b=factor { _Py_BinOp(a, Div, b, EXTRA) } | 
					
						
							|  |  |  |     | a=term '//' b=factor { _Py_BinOp(a, FloorDiv, b, EXTRA) } | 
					
						
							|  |  |  |     | a=term '%' b=factor { _Py_BinOp(a, Mod, b, EXTRA) } | 
					
						
							| 
									
										
										
										
											2020-10-21 22:53:14 +03:00
										 |  |  |     | a=term '@' b=factor { CHECK_VERSION(expr_ty, 5, "The '@' operator is", _Py_BinOp(a, MatMult, b, EXTRA)) } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |     | factor | 
					
						
							|  |  |  | factor[expr_ty] (memo): | 
					
						
							|  |  |  |     | '+' a=factor { _Py_UnaryOp(UAdd, a, EXTRA) } | 
					
						
							|  |  |  |     | '-' a=factor { _Py_UnaryOp(USub, a, EXTRA) } | 
					
						
							|  |  |  |     | '~' a=factor { _Py_UnaryOp(Invert, a, EXTRA) } | 
					
						
							|  |  |  |     | power | 
					
						
							|  |  |  | power[expr_ty]: | 
					
						
							|  |  |  |     | a=await_primary '**' b=factor { _Py_BinOp(a, Pow, b, EXTRA) } | 
					
						
							|  |  |  |     | await_primary | 
					
						
							|  |  |  | await_primary[expr_ty] (memo): | 
					
						
							| 
									
										
										
										
											2020-10-21 22:53:14 +03:00
										 |  |  |     | AWAIT a=primary { CHECK_VERSION(expr_ty, 5, "Await expressions are", _Py_Await(a, EXTRA)) } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |     | primary | 
					
						
							|  |  |  | primary[expr_ty]: | 
					
						
							| 
									
										
										
										
											2020-10-27 20:54:20 +02:00
										 |  |  |     | invalid_primary  # must be before 'primay genexp' because of invalid_genexp | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |     | a=primary '.' b=NAME { _Py_Attribute(a, b->v.Name.id, Load, EXTRA) } | 
					
						
							| 
									
										
										
										
											2020-10-21 22:53:14 +03:00
										 |  |  |     | a=primary b=genexp { _Py_Call(a, CHECK(asdl_expr_seq*, (asdl_expr_seq*)_PyPegen_singleton_seq(p, b)), NULL, EXTRA) } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |     | a=primary '(' b=[arguments] ')' { | 
					
						
							|  |  |  |         _Py_Call(a, | 
					
						
							|  |  |  |                  (b) ? ((expr_ty) b)->v.Call.args : NULL, | 
					
						
							|  |  |  |                  (b) ? ((expr_ty) b)->v.Call.keywords : NULL, | 
					
						
							|  |  |  |                  EXTRA) } | 
					
						
							|  |  |  |     | a=primary '[' b=slices ']' { _Py_Subscript(a, b, Load, EXTRA) } | 
					
						
							|  |  |  |     | atom | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | slices[expr_ty]: | 
					
						
							|  |  |  |     | a=slice !',' { a } | 
					
						
							| 
									
										
										
										
											2020-09-16 19:42:00 +01:00
										 |  |  |     | a[asdl_expr_seq*]=','.slice+ [','] { _Py_Tuple(a, Load, EXTRA) } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | slice[expr_ty]: | 
					
						
							|  |  |  |     | a=[expression] ':' b=[expression] c=[':' d=[expression] { d }] { _Py_Slice(a, b, c, EXTRA) } | 
					
						
							|  |  |  |     | a=expression { a } | 
					
						
							|  |  |  | atom[expr_ty]: | 
					
						
							|  |  |  |     | NAME | 
					
						
							|  |  |  |     | 'True' { _Py_Constant(Py_True, NULL, EXTRA) } | 
					
						
							|  |  |  |     | 'False' { _Py_Constant(Py_False, NULL, EXTRA) } | 
					
						
							|  |  |  |     | 'None' { _Py_Constant(Py_None, NULL, EXTRA) } | 
					
						
							|  |  |  |     | &STRING strings | 
					
						
							|  |  |  |     | NUMBER | 
					
						
							|  |  |  |     | &'(' (tuple | group | genexp) | 
					
						
							|  |  |  |     | &'[' (list | listcomp) | 
					
						
							|  |  |  |     | &'{' (dict | set | dictcomp | setcomp) | 
					
						
							|  |  |  |     | '...' { _Py_Constant(Py_Ellipsis, NULL, EXTRA) } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | strings[expr_ty] (memo): a=STRING+ { _PyPegen_concatenate_strings(p, a) } | 
					
						
							|  |  |  | list[expr_ty]: | 
					
						
							|  |  |  |     | '[' a=[star_named_expressions] ']' { _Py_List(a, Load, EXTRA) } | 
					
						
							|  |  |  | listcomp[expr_ty]: | 
					
						
							| 
									
										
										
										
											2020-06-19 02:10:43 +03:00
										 |  |  |     | '[' a=named_expression ~ b=for_if_clauses ']' { _Py_ListComp(a, b, EXTRA) } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |     | invalid_comprehension | 
					
						
							|  |  |  | tuple[expr_ty]: | 
					
						
							|  |  |  |     | '(' a=[y=star_named_expression ',' z=[star_named_expressions] { _PyPegen_seq_insert_in_front(p, y, z) } ] ')' { | 
					
						
							|  |  |  |         _Py_Tuple(a, Load, EXTRA) } | 
					
						
							| 
									
										
										
										
											2020-06-19 02:10:43 +03:00
										 |  |  | group[expr_ty]: | 
					
						
							|  |  |  |     | '(' a=(yield_expr | named_expression) ')' { a } | 
					
						
							|  |  |  |     | invalid_group | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | genexp[expr_ty]: | 
					
						
							| 
									
										
										
										
											2020-06-19 02:10:43 +03:00
										 |  |  |     | '(' a=expression ~ b=for_if_clauses ')' { _Py_GeneratorExp(a, b, EXTRA) } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |     | invalid_comprehension | 
					
						
							|  |  |  | set[expr_ty]: '{' a=expressions_list '}' { _Py_Set(a, EXTRA) } | 
					
						
							|  |  |  | setcomp[expr_ty]: | 
					
						
							| 
									
										
										
										
											2020-06-19 02:10:43 +03:00
										 |  |  |     | '{' a=expression ~ b=for_if_clauses '}' { _Py_SetComp(a, b, EXTRA) } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |     | invalid_comprehension | 
					
						
							|  |  |  | dict[expr_ty]: | 
					
						
							| 
									
										
										
										
											2020-05-22 01:39:56 +03:00
										 |  |  |     | '{' a=[double_starred_kvpairs] '}' { | 
					
						
							| 
									
										
										
										
											2020-10-21 22:53:14 +03:00
										 |  |  |         _Py_Dict( | 
					
						
							|  |  |  |             CHECK(asdl_expr_seq*, _PyPegen_get_keys(p, a)), | 
					
						
							|  |  |  |             CHECK(asdl_expr_seq*, _PyPegen_get_values(p, a)), | 
					
						
							|  |  |  |             EXTRA) } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | dictcomp[expr_ty]: | 
					
						
							|  |  |  |     | '{' a=kvpair b=for_if_clauses '}' { _Py_DictComp(a->key, a->value, b, EXTRA) } | 
					
						
							| 
									
										
										
										
											2020-05-22 01:39:56 +03:00
										 |  |  |     | invalid_dict_comprehension | 
					
						
							|  |  |  | double_starred_kvpairs[asdl_seq*]: a=','.double_starred_kvpair+ [','] { a } | 
					
						
							|  |  |  | double_starred_kvpair[KeyValuePair*]: | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |     | '**' a=bitwise_or { _PyPegen_key_value_pair(p, NULL, a) } | 
					
						
							| 
									
										
										
										
											2020-05-22 01:39:56 +03:00
										 |  |  |     | kvpair | 
					
						
							|  |  |  | kvpair[KeyValuePair*]: a=expression ':' b=expression { _PyPegen_key_value_pair(p, a, b) } | 
					
						
							| 
									
										
										
										
											2020-09-16 19:42:00 +01:00
										 |  |  | for_if_clauses[asdl_comprehension_seq*]: | 
					
						
							|  |  |  |     | a[asdl_comprehension_seq*]=for_if_clause+ { a } | 
					
						
							| 
									
										
										
										
											2020-05-01 06:27:52 +03:00
										 |  |  | for_if_clause[comprehension_ty]: | 
					
						
							| 
									
										
										
										
											2020-09-16 19:42:00 +01:00
										 |  |  |     | ASYNC 'for' a=star_targets 'in' ~ b=disjunction c[asdl_expr_seq*]=('if' z=disjunction { z })* { | 
					
						
							| 
									
										
										
										
											2020-10-21 22:53:14 +03:00
										 |  |  |         CHECK_VERSION(comprehension_ty, 6, "Async comprehensions are", _Py_comprehension(a, b, c, 1, p->arena)) } | 
					
						
							| 
									
										
										
										
											2020-09-16 19:42:00 +01:00
										 |  |  |     | 'for' a=star_targets 'in' ~ b=disjunction c[asdl_expr_seq*]=('if' z=disjunction { z })* { | 
					
						
							| 
									
										
										
										
											2020-05-01 06:27:52 +03:00
										 |  |  |         _Py_comprehension(a, b, c, 0, p->arena) } | 
					
						
							| 
									
										
										
										
											2020-06-19 02:10:43 +03:00
										 |  |  |     | invalid_for_target | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | yield_expr[expr_ty]: | 
					
						
							|  |  |  |     | 'yield' 'from' a=expression { _Py_YieldFrom(a, EXTRA) } | 
					
						
							|  |  |  |     | 'yield' a=[star_expressions] { _Py_Yield(a, EXTRA) } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | arguments[expr_ty] (memo): | 
					
						
							|  |  |  |     | a=args [','] &')' { a } | 
					
						
							| 
									
										
										
										
											2020-10-27 00:42:04 +02:00
										 |  |  |     | invalid_arguments | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | args[expr_ty]: | 
					
						
							| 
									
										
										
										
											2020-09-16 19:42:00 +01:00
										 |  |  |     | a[asdl_expr_seq*]=','.(starred_expression | named_expression !'=')+ b=[',' k=kwargs {k}] { _PyPegen_collect_call_seqs(p, a, b, EXTRA) } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |     | a=kwargs { _Py_Call(_PyPegen_dummy_name(p), | 
					
						
							| 
									
										
										
										
											2020-10-21 22:53:14 +03:00
										 |  |  |                           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)), | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |                           EXTRA) } | 
					
						
							|  |  |  | kwargs[asdl_seq*]: | 
					
						
							|  |  |  |     | a=','.kwarg_or_starred+ ',' b=','.kwarg_or_double_starred+ { _PyPegen_join_sequences(p, a, b) } | 
					
						
							|  |  |  |     | ','.kwarg_or_starred+ | 
					
						
							|  |  |  |     | ','.kwarg_or_double_starred+ | 
					
						
							|  |  |  | starred_expression[expr_ty]: | 
					
						
							|  |  |  |     | '*' a=expression { _Py_Starred(a, Load, EXTRA) } | 
					
						
							|  |  |  | kwarg_or_starred[KeywordOrStarred*]: | 
					
						
							|  |  |  |     | a=NAME '=' b=expression { | 
					
						
							| 
									
										
										
										
											2020-10-21 22:53:14 +03:00
										 |  |  |         _PyPegen_keyword_or_starred(p, CHECK(keyword_ty, _Py_keyword(a->v.Name.id, b, EXTRA)), 1) } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |     | a=starred_expression { _PyPegen_keyword_or_starred(p, a, 0) } | 
					
						
							| 
									
										
										
										
											2020-05-07 13:44:06 +03:00
										 |  |  |     | invalid_kwarg | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | kwarg_or_double_starred[KeywordOrStarred*]: | 
					
						
							|  |  |  |     | a=NAME '=' b=expression { | 
					
						
							| 
									
										
										
										
											2020-10-21 22:53:14 +03:00
										 |  |  |         _PyPegen_keyword_or_starred(p, CHECK(keyword_ty, _Py_keyword(a->v.Name.id, b, EXTRA)), 1) } | 
					
						
							|  |  |  |     | '**' a=expression { _PyPegen_keyword_or_starred(p, CHECK(keyword_ty, _Py_keyword(NULL, a, EXTRA)), 1) } | 
					
						
							| 
									
										
										
										
											2020-05-07 13:44:06 +03:00
										 |  |  |     | invalid_kwarg | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | # NOTE: star_targets may contain *bitwise_or, targets may not. | 
					
						
							|  |  |  | star_targets[expr_ty]: | 
					
						
							|  |  |  |     | a=star_target !',' { a } | 
					
						
							|  |  |  |     | a=star_target b=(',' c=star_target { c })* [','] { | 
					
						
							| 
									
										
										
										
											2020-10-21 22:53:14 +03:00
										 |  |  |         _Py_Tuple(CHECK(asdl_expr_seq*, _PyPegen_seq_insert_in_front(p, a, b)), Store, EXTRA) } | 
					
						
							| 
									
										
										
										
											2020-09-16 19:42:00 +01:00
										 |  |  | star_targets_seq[asdl_expr_seq*]: a[asdl_expr_seq*]=','.star_target+ [','] { a } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | star_target[expr_ty] (memo): | 
					
						
							|  |  |  |     | '*' a=(!'*' star_target) { | 
					
						
							| 
									
										
										
										
											2020-10-21 22:53:14 +03:00
										 |  |  |         _Py_Starred(CHECK(expr_ty, _PyPegen_set_expr_context(p, a, Store)), Store, EXTRA) } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |     | a=t_primary '.' b=NAME !t_lookahead { _Py_Attribute(a, b->v.Name.id, Store, EXTRA) } | 
					
						
							|  |  |  |     | a=t_primary '[' b=slices ']' !t_lookahead { _Py_Subscript(a, b, Store, EXTRA) } | 
					
						
							|  |  |  |     | star_atom | 
					
						
							|  |  |  | star_atom[expr_ty]: | 
					
						
							|  |  |  |     | a=NAME { _PyPegen_set_expr_context(p, a, Store) } | 
					
						
							|  |  |  |     | '(' a=star_target ')' { _PyPegen_set_expr_context(p, a, Store) } | 
					
						
							|  |  |  |     | '(' a=[star_targets_seq] ')' { _Py_Tuple(a, Store, EXTRA) } | 
					
						
							|  |  |  |     | '[' a=[star_targets_seq] ']' { _Py_List(a, Store, EXTRA) } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 23:13:50 +03:00
										 |  |  | single_target[expr_ty]: | 
					
						
							|  |  |  |     | single_subscript_attribute_target | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |     | a=NAME { _PyPegen_set_expr_context(p, a, Store) } | 
					
						
							| 
									
										
										
										
											2020-05-14 23:13:50 +03:00
										 |  |  |     | '(' a=single_target ')' { a } | 
					
						
							|  |  |  | single_subscript_attribute_target[expr_ty]: | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |     | a=t_primary '.' b=NAME !t_lookahead { _Py_Attribute(a, b->v.Name.id, Store, EXTRA) } | 
					
						
							|  |  |  |     | a=t_primary '[' b=slices ']' !t_lookahead { _Py_Subscript(a, b, Store, EXTRA) } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 19:42:00 +01:00
										 |  |  | del_targets[asdl_expr_seq*]: a[asdl_expr_seq*]=','.del_target+ [','] { a } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | del_target[expr_ty] (memo): | 
					
						
							| 
									
										
										
										
											2020-06-19 02:10:43 +03:00
										 |  |  |     | a=t_primary '.' b=NAME !t_lookahead { _Py_Attribute(a, b->v.Name.id, Del, EXTRA) } | 
					
						
							|  |  |  |     | a=t_primary '[' b=slices ']' !t_lookahead { _Py_Subscript(a, b, Del, EXTRA) } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |     | del_t_atom | 
					
						
							|  |  |  | del_t_atom[expr_ty]: | 
					
						
							| 
									
										
										
										
											2020-06-19 02:10:43 +03:00
										 |  |  |     | a=NAME { _PyPegen_set_expr_context(p, a, Del) } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |     | '(' a=del_target ')' { _PyPegen_set_expr_context(p, a, Del) } | 
					
						
							|  |  |  |     | '(' a=[del_targets] ')' { _Py_Tuple(a, Del, EXTRA) } | 
					
						
							|  |  |  |     | '[' a=[del_targets] ']' { _Py_List(a, Del, EXTRA) } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 19:42:00 +01:00
										 |  |  | targets[asdl_expr_seq*]: a[asdl_expr_seq*]=','.target+ [','] { a } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | target[expr_ty] (memo): | 
					
						
							|  |  |  |     | a=t_primary '.' b=NAME !t_lookahead { _Py_Attribute(a, b->v.Name.id, Store, EXTRA) } | 
					
						
							|  |  |  |     | a=t_primary '[' b=slices ']' !t_lookahead { _Py_Subscript(a, b, Store, EXTRA) } | 
					
						
							|  |  |  |     | t_atom | 
					
						
							|  |  |  | t_primary[expr_ty]: | 
					
						
							|  |  |  |     | a=t_primary '.' b=NAME &t_lookahead { _Py_Attribute(a, b->v.Name.id, Load, EXTRA) } | 
					
						
							|  |  |  |     | a=t_primary '[' b=slices ']' &t_lookahead { _Py_Subscript(a, b, Load, EXTRA) } | 
					
						
							| 
									
										
										
										
											2020-10-21 22:53:14 +03:00
										 |  |  |     | a=t_primary b=genexp &t_lookahead { | 
					
						
							|  |  |  |         _Py_Call(a, CHECK(asdl_expr_seq*, (asdl_expr_seq*)_PyPegen_singleton_seq(p, b)), NULL, EXTRA) } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |     | a=t_primary '(' b=[arguments] ')' &t_lookahead { | 
					
						
							|  |  |  |         _Py_Call(a, | 
					
						
							|  |  |  |                  (b) ? ((expr_ty) b)->v.Call.args : NULL, | 
					
						
							|  |  |  |                  (b) ? ((expr_ty) b)->v.Call.keywords : NULL, | 
					
						
							|  |  |  |                  EXTRA) } | 
					
						
							|  |  |  |     | a=atom &t_lookahead { a } | 
					
						
							|  |  |  | t_lookahead: '(' | '[' | '.' | 
					
						
							|  |  |  | t_atom[expr_ty]: | 
					
						
							|  |  |  |     | a=NAME { _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] ']' { _Py_List(b, Store, EXTRA) } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # From here on, there are rules for invalid syntax with specialised error messages | 
					
						
							| 
									
										
										
										
											2020-10-27 00:42:04 +02:00
										 |  |  | invalid_arguments: | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |     | args ',' '*' { RAISE_SYNTAX_ERROR("iterable argument unpacking follows keyword argument unpacking") } | 
					
						
							| 
									
										
										
										
											2020-05-13 22:36:27 +03:00
										 |  |  |     | a=expression for_if_clauses ',' [args | expression for_if_clauses] { | 
					
						
							|  |  |  |         RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "Generator expression must be parenthesized") } | 
					
						
							| 
									
										
										
										
											2020-05-22 03:56:52 +03:00
										 |  |  |     | a=args for_if_clauses { _PyPegen_nonparen_genexp_in_call(p, a) } | 
					
						
							|  |  |  |     | args ',' a=expression for_if_clauses { | 
					
						
							|  |  |  |         RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "Generator expression must be parenthesized") } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |     | a=args ',' args { _PyPegen_arguments_parsing_error(p, a) } | 
					
						
							| 
									
										
										
										
											2020-05-07 13:44:06 +03:00
										 |  |  | invalid_kwarg: | 
					
						
							| 
									
										
										
										
											2020-05-13 22:36:27 +03:00
										 |  |  |     | a=expression '=' { | 
					
						
							|  |  |  |         RAISE_SYNTAX_ERROR_KNOWN_LOCATION( | 
					
						
							|  |  |  |             a, "expression cannot contain assignment, perhaps you meant \"==\"?") } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | invalid_named_expression: | 
					
						
							|  |  |  |     | a=expression ':=' expression { | 
					
						
							| 
									
										
										
										
											2020-05-13 22:36:27 +03:00
										 |  |  |         RAISE_SYNTAX_ERROR_KNOWN_LOCATION( | 
					
						
							|  |  |  |             a, "cannot use assignment expressions with %s", _PyPegen_get_expr_name(a)) } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | invalid_assignment: | 
					
						
							| 
									
										
										
										
											2020-06-27 21:33:08 +03:00
										 |  |  |     | a=invalid_ann_assign_target ':' expression { | 
					
						
							|  |  |  |         RAISE_SYNTAX_ERROR_KNOWN_LOCATION( | 
					
						
							|  |  |  |             a, | 
					
						
							|  |  |  |             "only single target (not %s) can be annotated", | 
					
						
							|  |  |  |             _PyPegen_get_expr_name(a) | 
					
						
							|  |  |  |         )} | 
					
						
							| 
									
										
										
										
											2020-06-26 02:22:36 +03:00
										 |  |  |     | a=star_named_expression ',' star_named_expressions* ':' expression { | 
					
						
							| 
									
										
										
										
											2020-05-13 22:36:27 +03:00
										 |  |  |         RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "only single target (not tuple) can be annotated") } | 
					
						
							| 
									
										
										
										
											2020-06-26 02:22:36 +03:00
										 |  |  |     | a=expression ':' expression { | 
					
						
							| 
									
										
										
										
											2020-05-13 22:36:27 +03:00
										 |  |  |         RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "illegal target for annotation") } | 
					
						
							| 
									
										
										
										
											2020-06-08 02:57:00 +01:00
										 |  |  |     | (star_targets '=')* a=star_expressions '=' { | 
					
						
							| 
									
										
										
										
											2020-06-21 05:18:01 +03:00
										 |  |  |         RAISE_SYNTAX_ERROR_INVALID_TARGET(STAR_TARGETS, a) } | 
					
						
							| 
									
										
										
										
											2020-06-08 02:57:00 +01:00
										 |  |  |     | (star_targets '=')* a=yield_expr '=' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "assignment to yield expression not possible") } | 
					
						
							| 
									
										
										
										
											2020-05-15 02:04:52 +01:00
										 |  |  |     | a=star_expressions augassign (yield_expr | star_expressions) { | 
					
						
							|  |  |  |         RAISE_SYNTAX_ERROR_KNOWN_LOCATION(  | 
					
						
							| 
									
										
										
										
											2020-06-26 02:22:36 +03:00
										 |  |  |             a, | 
					
						
							| 
									
										
										
										
											2020-05-15 02:04:52 +01:00
										 |  |  |             "'%s' is an illegal expression for augmented assignment", | 
					
						
							|  |  |  |             _PyPegen_get_expr_name(a) | 
					
						
							|  |  |  |         )} | 
					
						
							| 
									
										
										
										
											2020-06-27 21:33:08 +03:00
										 |  |  | invalid_ann_assign_target[expr_ty]: | 
					
						
							|  |  |  |     | list | 
					
						
							|  |  |  |     | tuple | 
					
						
							|  |  |  |     | '(' a=invalid_ann_assign_target ')' { a } | 
					
						
							| 
									
										
										
										
											2020-06-19 02:10:43 +03:00
										 |  |  | invalid_del_stmt: | 
					
						
							|  |  |  |     | 'del' a=star_expressions { | 
					
						
							| 
									
										
										
										
											2020-06-21 05:18:01 +03:00
										 |  |  |         RAISE_SYNTAX_ERROR_INVALID_TARGET(DEL_TARGETS, a) } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | invalid_block: | 
					
						
							|  |  |  |     | NEWLINE !INDENT { RAISE_INDENTATION_ERROR("expected an indented block") } | 
					
						
							| 
									
										
										
										
											2020-10-27 20:54:20 +02:00
										 |  |  | invalid_primary: | 
					
						
							|  |  |  |     | primary a='{' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "invalid syntax") } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | invalid_comprehension: | 
					
						
							| 
									
										
										
										
											2020-05-13 22:36:27 +03:00
										 |  |  |     | ('[' | '(' | '{') a=starred_expression for_if_clauses { | 
					
						
							|  |  |  |         RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "iterable unpacking cannot be used in comprehension") } | 
					
						
							| 
									
										
										
										
											2020-05-22 01:39:56 +03:00
										 |  |  | invalid_dict_comprehension: | 
					
						
							|  |  |  |     | '{' a='**' bitwise_or for_if_clauses '}' { | 
					
						
							|  |  |  |         RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "dict unpacking cannot be used in dict comprehension") } | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  | invalid_parameters: | 
					
						
							| 
									
										
										
										
											2020-04-30 12:12:19 -07:00
										 |  |  |     | param_no_default* (slash_with_default | param_with_default+) param_no_default { | 
					
						
							| 
									
										
										
										
											2020-04-22 23:29:27 +01:00
										 |  |  |         RAISE_SYNTAX_ERROR("non-default argument follows default argument") } | 
					
						
							| 
									
										
										
										
											2020-06-10 14:07:06 +01:00
										 |  |  | invalid_lambda_parameters: | 
					
						
							|  |  |  |     | lambda_param_no_default* (lambda_slash_with_default | lambda_param_with_default+) lambda_param_no_default { | 
					
						
							|  |  |  |         RAISE_SYNTAX_ERROR("non-default argument follows default argument") } | 
					
						
							| 
									
										
										
										
											2020-05-04 13:58:31 +03:00
										 |  |  | invalid_star_etc: | 
					
						
							|  |  |  |     | '*' (')' | ',' (')' | '**')) { RAISE_SYNTAX_ERROR("named arguments must follow bare *") } | 
					
						
							| 
									
										
										
										
											2020-05-18 22:14:47 +03:00
										 |  |  |     | '*' ',' TYPE_COMMENT { RAISE_SYNTAX_ERROR("bare * has associated type comment") } | 
					
						
							| 
									
										
										
										
											2020-05-04 13:58:31 +03:00
										 |  |  | invalid_lambda_star_etc: | 
					
						
							|  |  |  |     | '*' (':' | ',' (':' | '**')) { RAISE_SYNTAX_ERROR("named arguments must follow bare *") } | 
					
						
							| 
									
										
										
										
											2020-04-30 12:12:19 -07:00
										 |  |  | invalid_double_type_comments: | 
					
						
							|  |  |  |     | TYPE_COMMENT NEWLINE TYPE_COMMENT NEWLINE INDENT { | 
					
						
							|  |  |  |         RAISE_SYNTAX_ERROR("Cannot have two type comments on def") } | 
					
						
							| 
									
										
										
										
											2020-06-19 02:10:43 +03:00
										 |  |  | invalid_with_item: | 
					
						
							|  |  |  |     | expression 'as' a=expression { | 
					
						
							| 
									
										
										
										
											2020-06-21 05:18:01 +03:00
										 |  |  |         RAISE_SYNTAX_ERROR_INVALID_TARGET(STAR_TARGETS, a) } | 
					
						
							| 
									
										
										
										
											2020-06-19 02:10:43 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | invalid_for_target: | 
					
						
							|  |  |  |     | ASYNC? 'for' a=star_expressions { | 
					
						
							| 
									
										
										
										
											2020-06-21 05:18:01 +03:00
										 |  |  |         RAISE_SYNTAX_ERROR_INVALID_TARGET(FOR_TARGETS, a) } | 
					
						
							| 
									
										
										
										
											2020-06-19 02:10:43 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | invalid_group: | 
					
						
							|  |  |  |     | '(' a=starred_expression ')' { | 
					
						
							|  |  |  |         RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "can't use starred expression here") } | 
					
						
							| 
									
										
										
										
											2020-05-21 23:41:58 +03:00
										 |  |  | invalid_import_from_targets: | 
					
						
							|  |  |  |     | import_from_as_names ',' { | 
					
						
							|  |  |  |         RAISE_SYNTAX_ERROR("trailing comma not allowed without surrounding parentheses") } |