blob: 9087c7aa718b17613d47b5d063aa3fe26c6f42a9 [file] [log] [blame]
Pablo Galindoc5fc1562020-04-22 23:29:27 +01001# Simplified grammar for Python
2
3@bytecode True
4@trailer '''
5void *
6_PyPegen_parse(Parser *p)
7{
8 // Initialize keywords
9 p->keywords = reserved_keywords;
10 p->n_keyword_lists = n_keyword_lists;
11
12 // Run parser
13 void *result = NULL;
14 if (p->start_rule == Py_file_input) {
15 result = file_rule(p);
16 } else if (p->start_rule == Py_single_input) {
17 result = interactive_rule(p);
18 } else if (p->start_rule == Py_eval_input) {
19 result = eval_rule(p);
Guido van Rossumc001c092020-04-30 12:12:19 -070020 } else if (p->start_rule == Py_func_type_input) {
21 result = func_type_rule(p);
Pablo Galindoc5fc1562020-04-22 23:29:27 +010022 } else if (p->start_rule == Py_fstring_input) {
23 result = fstring_rule(p);
24 }
25
26 return result;
27}
28
29// The end
30'''
Guido van Rossumc001c092020-04-30 12:12:19 -070031file[mod_ty]: a=[statements] ENDMARKER { _PyPegen_make_module(p, a) }
Pablo Galindoc5fc1562020-04-22 23:29:27 +010032interactive[mod_ty]: a=statement_newline { Interactive(a, p->arena) }
33eval[mod_ty]: a=expressions NEWLINE* ENDMARKER { Expression(a, p->arena) }
Guido van Rossumc001c092020-04-30 12:12:19 -070034func_type[mod_ty]: '(' a=[type_expressions] ')' '->' b=expression NEWLINE* ENDMARKER { FunctionType(a, b, p->arena) }
Pablo Galindoc5fc1562020-04-22 23:29:27 +010035fstring[expr_ty]: star_expressions
36
Guido van Rossumc001c092020-04-30 12:12:19 -070037# type_expressions allow */** but ignore them
38type_expressions[asdl_seq*]:
39 | a=','.expression+ ',' '*' b=expression ',' '**' c=expression {
40 _PyPegen_seq_append_to_end(p, CHECK(_PyPegen_seq_append_to_end(p, a, b)), c) }
41 | a=','.expression+ ',' '*' b=expression { _PyPegen_seq_append_to_end(p, a, b) }
42 | a=','.expression+ ',' '**' b=expression { _PyPegen_seq_append_to_end(p, a, b) }
Shantanu603d3542020-05-03 22:08:14 -070043 | '*' a=expression ',' '**' b=expression {
44 _PyPegen_seq_append_to_end(p, CHECK(_PyPegen_singleton_seq(p, a)), b) }
45 | '*' a=expression { _PyPegen_singleton_seq(p, a) }
46 | '**' a=expression { _PyPegen_singleton_seq(p, a) }
Guido van Rossumc001c092020-04-30 12:12:19 -070047 | ','.expression+
48
Pablo Galindoc5fc1562020-04-22 23:29:27 +010049statements[asdl_seq*]: a=statement+ { _PyPegen_seq_flatten(p, a) }
50statement[asdl_seq*]: a=compound_stmt { _PyPegen_singleton_seq(p, a) } | simple_stmt
51statement_newline[asdl_seq*]:
52 | a=compound_stmt NEWLINE { _PyPegen_singleton_seq(p, a) }
53 | simple_stmt
54 | NEWLINE { _PyPegen_singleton_seq(p, CHECK(_Py_Pass(EXTRA))) }
55 | ENDMARKER { _PyPegen_interactive_exit(p) }
56simple_stmt[asdl_seq*]:
57 | a=small_stmt !';' NEWLINE { _PyPegen_singleton_seq(p, a) } # Not needed, there for speedup
58 | a=';'.small_stmt+ [';'] NEWLINE { a }
59# NOTE: assignment MUST precede expression, else parsing a simple assignment
60# will throw a SyntaxError.
61small_stmt[stmt_ty] (memo):
62 | assignment
63 | e=star_expressions { _Py_Expr(e, EXTRA) }
64 | &'return' return_stmt
65 | &('import' | 'from') import_stmt
66 | &'raise' raise_stmt
67 | 'pass' { _Py_Pass(EXTRA) }
68 | &'del' del_stmt
69 | &'yield' yield_stmt
70 | &'assert' assert_stmt
71 | 'break' { _Py_Break(EXTRA) }
72 | 'continue' { _Py_Continue(EXTRA) }
73 | &'global' global_stmt
74 | &'nonlocal' nonlocal_stmt
75compound_stmt[stmt_ty]:
76 | &('def' | '@' | ASYNC) function_def
77 | &'if' if_stmt
78 | &('class' | '@') class_def
79 | &('with' | ASYNC) with_stmt
80 | &('for' | ASYNC) for_stmt
81 | &'try' try_stmt
82 | &'while' while_stmt
83
84# NOTE: annotated_rhs may start with 'yield'; yield_expr must start with 'yield'
Lysandros Nikolaou999ec9a2020-05-06 21:11:04 +030085assignment[stmt_ty]:
Pablo Galindoc5fc1562020-04-22 23:29:27 +010086 | a=NAME ':' b=expression c=['=' d=annotated_rhs { d }] {
Lysandros Nikolaou3e0a6f32020-05-01 06:27:52 +030087 CHECK_VERSION(
88 6,
89 "Variable annotation syntax is",
90 _Py_AnnAssign(CHECK(_PyPegen_set_expr_context(p, a, Store)), b, c, 1, EXTRA)
91 ) }
Lysandros Nikolaouce21cfc2020-05-14 23:13:50 +030092 | a=('(' b=single_target ')' { b }
93 | single_subscript_attribute_target) ':' b=expression c=['=' d=annotated_rhs { d }] {
Lysandros Nikolaou3e0a6f32020-05-01 06:27:52 +030094 CHECK_VERSION(6, "Variable annotations syntax is", _Py_AnnAssign(a, b, c, 0, EXTRA)) }
Guido van Rossumc001c092020-04-30 12:12:19 -070095 | a=(z=star_targets '=' { z })+ b=(yield_expr | star_expressions) tc=[TYPE_COMMENT] {
96 _Py_Assign(a, b, NEW_TYPE_COMMENT(p, tc), EXTRA) }
Lysandros Nikolaouce21cfc2020-05-14 23:13:50 +030097 | a=single_target b=augassign c=(yield_expr | star_expressions) {
Pablo Galindoc5fc1562020-04-22 23:29:27 +010098 _Py_AugAssign(a, b->kind, c, EXTRA) }
99 | invalid_assignment
100
101augassign[AugOperator*]:
Lysandros Nikolaou3e0a6f32020-05-01 06:27:52 +0300102 | '+=' { _PyPegen_augoperator(p, Add) }
103 | '-=' { _PyPegen_augoperator(p, Sub) }
104 | '*=' { _PyPegen_augoperator(p, Mult) }
105 | '@=' { CHECK_VERSION(5, "The '@' operator is", _PyPegen_augoperator(p, MatMult)) }
106 | '/=' { _PyPegen_augoperator(p, Div) }
107 | '%=' { _PyPegen_augoperator(p, Mod) }
108 | '&=' { _PyPegen_augoperator(p, BitAnd) }
109 | '|=' { _PyPegen_augoperator(p, BitOr) }
110 | '^=' { _PyPegen_augoperator(p, BitXor) }
111 | '<<=' { _PyPegen_augoperator(p, LShift) }
112 | '>>=' { _PyPegen_augoperator(p, RShift) }
113 | '**=' { _PyPegen_augoperator(p, Pow) }
114 | '//=' { _PyPegen_augoperator(p, FloorDiv) }
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100115
116global_stmt[stmt_ty]: 'global' a=','.NAME+ {
117 _Py_Global(CHECK(_PyPegen_map_names_to_ids(p, a)), EXTRA) }
118nonlocal_stmt[stmt_ty]: 'nonlocal' a=','.NAME+ {
119 _Py_Nonlocal(CHECK(_PyPegen_map_names_to_ids(p, a)), EXTRA) }
120
121yield_stmt[stmt_ty]: y=yield_expr { _Py_Expr(y, EXTRA) }
122
123assert_stmt[stmt_ty]: 'assert' a=expression b=[',' z=expression { z }] { _Py_Assert(a, b, EXTRA) }
124
125del_stmt[stmt_ty]: 'del' a=del_targets { _Py_Delete(a, EXTRA) }
126
127import_stmt[stmt_ty]: import_name | import_from
128import_name[stmt_ty]: 'import' a=dotted_as_names { _Py_Import(a, EXTRA) }
129# note below: the ('.' | '...') is necessary because '...' is tokenized as ELLIPSIS
130import_from[stmt_ty]:
131 | 'from' a=('.' | '...')* b=dotted_name 'import' c=import_from_targets {
132 _Py_ImportFrom(b->v.Name.id, c, _PyPegen_seq_count_dots(a), EXTRA) }
133 | 'from' a=('.' | '...')+ 'import' b=import_from_targets {
134 _Py_ImportFrom(NULL, b, _PyPegen_seq_count_dots(a), EXTRA) }
135import_from_targets[asdl_seq*]:
136 | '(' a=import_from_as_names [','] ')' { a }
137 | import_from_as_names
138 | '*' { _PyPegen_singleton_seq(p, CHECK(_PyPegen_alias_for_star(p))) }
139import_from_as_names[asdl_seq*]:
140 | a=','.import_from_as_name+ { a }
141import_from_as_name[alias_ty]:
142 | a=NAME b=['as' z=NAME { z }] { _Py_alias(a->v.Name.id,
143 (b) ? ((expr_ty) b)->v.Name.id : NULL,
144 p->arena) }
145dotted_as_names[asdl_seq*]:
146 | a=','.dotted_as_name+ { a }
147dotted_as_name[alias_ty]:
148 | a=dotted_name b=['as' z=NAME { z }] { _Py_alias(a->v.Name.id,
149 (b) ? ((expr_ty) b)->v.Name.id : NULL,
150 p->arena) }
151dotted_name[expr_ty]:
152 | a=dotted_name '.' b=NAME { _PyPegen_join_names_with_dot(p, a, b) }
153 | NAME
154
155if_stmt[stmt_ty]:
156 | 'if' a=named_expression ':' b=block c=elif_stmt { _Py_If(a, b, CHECK(_PyPegen_singleton_seq(p, c)), EXTRA) }
157 | 'if' a=named_expression ':' b=block c=[else_block] { _Py_If(a, b, c, EXTRA) }
158elif_stmt[stmt_ty]:
159 | 'elif' a=named_expression ':' b=block c=elif_stmt { _Py_If(a, b, CHECK(_PyPegen_singleton_seq(p, c)), EXTRA) }
160 | 'elif' a=named_expression ':' b=block c=[else_block] { _Py_If(a, b, c, EXTRA) }
161else_block[asdl_seq*]: 'else' ':' b=block { b }
162
163while_stmt[stmt_ty]:
164 | 'while' a=named_expression ':' b=block c=[else_block] { _Py_While(a, b, c, EXTRA) }
165
166for_stmt[stmt_ty]:
Lysandros Nikolaou3e0a6f32020-05-01 06:27:52 +0300167 | 'for' t=star_targets 'in' ex=star_expressions ':' tc=[TYPE_COMMENT] b=block el=[else_block] {
168 _Py_For(t, ex, b, el, NEW_TYPE_COMMENT(p, tc), EXTRA) }
169 | ASYNC 'for' t=star_targets 'in' ex=star_expressions ':' tc=[TYPE_COMMENT] b=block el=[else_block] {
170 CHECK_VERSION(5, "Async for loops are", _Py_AsyncFor(t, ex, b, el, NEW_TYPE_COMMENT(p, tc), EXTRA)) }
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100171
172with_stmt[stmt_ty]:
Pablo Galindo99db2a12020-05-06 22:54:34 +0100173 | 'with' '(' a=','.with_item+ ','? ')' ':' b=block {
Lysandros Nikolaou3e0a6f32020-05-01 06:27:52 +0300174 _Py_With(a, b, NULL, EXTRA) }
175 | 'with' a=','.with_item+ ':' tc=[TYPE_COMMENT] b=block {
176 _Py_With(a, b, NEW_TYPE_COMMENT(p, tc), EXTRA) }
Pablo Galindo99db2a12020-05-06 22:54:34 +0100177 | ASYNC 'with' '(' a=','.with_item+ ','? ')' ':' b=block {
Lysandros Nikolaou3e0a6f32020-05-01 06:27:52 +0300178 CHECK_VERSION(5, "Async with statements are", _Py_AsyncWith(a, b, NULL, EXTRA)) }
179 | ASYNC 'with' a=','.with_item+ ':' tc=[TYPE_COMMENT] b=block {
180 CHECK_VERSION(5, "Async with statements are", _Py_AsyncWith(a, b, NEW_TYPE_COMMENT(p, tc), EXTRA)) }
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100181with_item[withitem_ty]:
182 | e=expression o=['as' t=target { t }] { _Py_withitem(e, o, p->arena) }
183
184try_stmt[stmt_ty]:
185 | 'try' ':' b=block f=finally_block { _Py_Try(b, NULL, NULL, f, EXTRA) }
186 | 'try' ':' b=block ex=except_block+ el=[else_block] f=[finally_block] { _Py_Try(b, ex, el, f, EXTRA) }
187except_block[excepthandler_ty]:
Lysandros Nikolaouce21cfc2020-05-14 23:13:50 +0300188 | 'except' e=expression t=['as' z=NAME { z }] ':' b=block {
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100189 _Py_ExceptHandler(e, (t) ? ((expr_ty) t)->v.Name.id : NULL, b, EXTRA) }
190 | 'except' ':' b=block { _Py_ExceptHandler(NULL, NULL, b, EXTRA) }
191finally_block[asdl_seq*]: 'finally' ':' a=block { a }
192
193return_stmt[stmt_ty]:
194 | 'return' a=[star_expressions] { _Py_Return(a, EXTRA) }
195
196raise_stmt[stmt_ty]:
197 | 'raise' a=expression b=['from' z=expression { z }] { _Py_Raise(a, b, EXTRA) }
198 | 'raise' { _Py_Raise(NULL, NULL, EXTRA) }
199
200function_def[stmt_ty]:
201 | d=decorators f=function_def_raw { _PyPegen_function_def_decorators(p, d, f) }
202 | function_def_raw
203
204function_def_raw[stmt_ty]:
Lysandros Nikolaou3e0a6f32020-05-01 06:27:52 +0300205 | 'def' n=NAME '(' params=[params] ')' a=['->' z=expression { z }] ':' tc=[func_type_comment] b=block {
206 _Py_FunctionDef(n->v.Name.id,
207 (params) ? params : CHECK(_PyPegen_empty_arguments(p)),
208 b, NULL, a, NEW_TYPE_COMMENT(p, tc), EXTRA) }
209 | ASYNC 'def' n=NAME '(' params=[params] ')' a=['->' z=expression { z }] ':' tc=[func_type_comment] b=block {
210 CHECK_VERSION(
211 5,
212 "Async functions are",
213 _Py_AsyncFunctionDef(n->v.Name.id,
214 (params) ? params : CHECK(_PyPegen_empty_arguments(p)),
215 b, NULL, a, NEW_TYPE_COMMENT(p, tc), EXTRA)
216 ) }
Pablo Galindod9552412020-05-01 16:32:09 +0100217func_type_comment[Token*]:
Guido van Rossumc001c092020-04-30 12:12:19 -0700218 | NEWLINE t=TYPE_COMMENT &(NEWLINE INDENT) { t } # Must be followed by indented block
219 | invalid_double_type_comments
220 | TYPE_COMMENT
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100221
222params[arguments_ty]:
223 | invalid_parameters
224 | parameters
Guido van Rossumc001c092020-04-30 12:12:19 -0700225
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100226parameters[arguments_ty]:
Guido van Rossumc001c092020-04-30 12:12:19 -0700227 | a=slash_no_default b=param_no_default* c=param_with_default* d=[star_etc] {
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100228 _PyPegen_make_arguments(p, a, NULL, b, c, d) }
Guido van Rossumc001c092020-04-30 12:12:19 -0700229 | a=slash_with_default b=param_with_default* c=[star_etc] {
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100230 _PyPegen_make_arguments(p, NULL, a, NULL, b, c) }
Guido van Rossumc001c092020-04-30 12:12:19 -0700231 | a=param_no_default+ b=param_with_default* c=[star_etc] {
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100232 _PyPegen_make_arguments(p, NULL, NULL, a, b, c) }
Guido van Rossumc001c092020-04-30 12:12:19 -0700233 | a=param_with_default+ b=[star_etc] { _PyPegen_make_arguments(p, NULL, NULL, NULL, a, b)}
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100234 | a=star_etc { _PyPegen_make_arguments(p, NULL, NULL, NULL, NULL, a) }
Guido van Rossumc001c092020-04-30 12:12:19 -0700235
236# Some duplication here because we can't write (',' | &')'),
237# which is because we don't support empty alternatives (yet).
238#
239slash_no_default[asdl_seq*]:
240 | a=param_no_default+ '/' ',' { a }
241 | a=param_no_default+ '/' &')' { a }
242slash_with_default[SlashWithDefault*]:
243 | a=param_no_default* b=param_with_default+ '/' ',' { _PyPegen_slash_with_default(p, a, b) }
244 | a=param_no_default* b=param_with_default+ '/' &')' { _PyPegen_slash_with_default(p, a, b) }
245
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100246star_etc[StarEtc*]:
Guido van Rossumc001c092020-04-30 12:12:19 -0700247 | '*' a=param_no_default b=param_maybe_default* c=[kwds] {
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100248 _PyPegen_star_etc(p, a, b, c) }
Guido van Rossumc001c092020-04-30 12:12:19 -0700249 | '*' ',' b=param_maybe_default+ c=[kwds] {
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100250 _PyPegen_star_etc(p, NULL, b, c) }
Guido van Rossumc001c092020-04-30 12:12:19 -0700251 | a=kwds { _PyPegen_star_etc(p, NULL, NULL, a) }
Lysandros Nikolaoue10e7c72020-05-04 13:58:31 +0300252 | invalid_star_etc
Guido van Rossumc001c092020-04-30 12:12:19 -0700253
Guido van Rossum3941d972020-05-01 09:42:03 -0700254kwds[arg_ty]: '**' a=param_no_default { a }
Guido van Rossumc001c092020-04-30 12:12:19 -0700255
256# One parameter. This *includes* a following comma and type comment.
257#
258# There are three styles:
259# - No default
260# - With default
261# - Maybe with default
262#
263# There are two alternative forms of each, to deal with type comments:
264# - Ends in a comma followed by an optional type comment
265# - No comma, optional type comment, must be followed by close paren
266# The latter form is for a final parameter without trailing comma.
267#
268param_no_default[arg_ty]:
269 | a=param ',' tc=TYPE_COMMENT? { _PyPegen_add_type_comment_to_arg(p, a, tc) }
270 | a=param tc=TYPE_COMMENT? &')' { _PyPegen_add_type_comment_to_arg(p, a, tc) }
271param_with_default[NameDefaultPair*]:
272 | a=param c=default ',' tc=TYPE_COMMENT? { _PyPegen_name_default_pair(p, a, c, tc) }
273 | a=param c=default tc=TYPE_COMMENT? &')' { _PyPegen_name_default_pair(p, a, c, tc) }
274param_maybe_default[NameDefaultPair*]:
275 | a=param c=default? ',' tc=TYPE_COMMENT? { _PyPegen_name_default_pair(p, a, c, tc) }
276 | a=param c=default? tc=TYPE_COMMENT? &')' { _PyPegen_name_default_pair(p, a, c, tc) }
277param[arg_ty]: a=NAME b=annotation? { _Py_arg(a->v.Name.id, b, NULL, EXTRA) }
278
279annotation[expr_ty]: ':' a=expression { a }
280default[expr_ty]: '=' a=expression { a }
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100281
282decorators[asdl_seq*]: a=('@' f=named_expression NEWLINE { f })+ { a }
283
284class_def[stmt_ty]:
285 | a=decorators b=class_def_raw { _PyPegen_class_def_decorators(p, a, b) }
286 | class_def_raw
287class_def_raw[stmt_ty]:
288 | 'class' a=NAME b=['(' z=[arguments] ')' { z }] ':' c=block {
289 _Py_ClassDef(a->v.Name.id,
290 (b) ? ((expr_ty) b)->v.Call.args : NULL,
291 (b) ? ((expr_ty) b)->v.Call.keywords : NULL,
292 c, NULL, EXTRA) }
293
294block[asdl_seq*] (memo):
295 | NEWLINE INDENT a=statements DEDENT { a }
296 | simple_stmt
297 | invalid_block
298
299expressions_list[asdl_seq*]: a=','.star_expression+ [','] { a }
300star_expressions[expr_ty]:
301 | a=star_expression b=(',' c=star_expression { c })+ [','] {
302 _Py_Tuple(CHECK(_PyPegen_seq_insert_in_front(p, a, b)), Load, EXTRA) }
303 | a=star_expression ',' { _Py_Tuple(CHECK(_PyPegen_singleton_seq(p, a)), Load, EXTRA) }
304 | star_expression
305star_expression[expr_ty] (memo):
306 | '*' a=bitwise_or { _Py_Starred(a, Load, EXTRA) }
307 | expression
308
309star_named_expressions[asdl_seq*]: a=','.star_named_expression+ [','] { a }
310star_named_expression[expr_ty]:
311 | '*' a=bitwise_or { _Py_Starred(a, Load, EXTRA) }
312 | named_expression
313named_expression[expr_ty]:
314 | a=NAME ':=' b=expression { _Py_NamedExpr(CHECK(_PyPegen_set_expr_context(p, a, Store)), b, EXTRA) }
315 | expression !':='
316 | invalid_named_expression
317
318annotated_rhs[expr_ty]: yield_expr | star_expressions
319
320expressions[expr_ty]:
321 | a=expression b=(',' c=expression { c })+ [','] {
322 _Py_Tuple(CHECK(_PyPegen_seq_insert_in_front(p, a, b)), Load, EXTRA) }
323 | a=expression ',' { _Py_Tuple(CHECK(_PyPegen_singleton_seq(p, a)), Load, EXTRA) }
324 | expression
325expression[expr_ty] (memo):
326 | a=disjunction 'if' b=disjunction 'else' c=expression { _Py_IfExp(b, a, c, EXTRA) }
327 | disjunction
328 | lambdef
329
330lambdef[expr_ty]:
331 | 'lambda' a=[lambda_parameters] ':' b=expression { _Py_Lambda((a) ? a : CHECK(_PyPegen_empty_arguments(p)), b, EXTRA) }
Guido van Rossum3941d972020-05-01 09:42:03 -0700332
333# lambda_parameters etc. duplicates parameters but without annotations
334# or type comments, and if there's no comma after a parameter, we expect
335# a colon, not a close parenthesis. (For more, see parameters above.)
336#
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100337lambda_parameters[arguments_ty]:
Guido van Rossum3941d972020-05-01 09:42:03 -0700338 | a=lambda_slash_no_default b=lambda_param_no_default* c=lambda_param_with_default* d=[lambda_star_etc] {
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100339 _PyPegen_make_arguments(p, a, NULL, b, c, d) }
Guido van Rossum3941d972020-05-01 09:42:03 -0700340 | a=lambda_slash_with_default b=lambda_param_with_default* c=[lambda_star_etc] {
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100341 _PyPegen_make_arguments(p, NULL, a, NULL, b, c) }
Guido van Rossum3941d972020-05-01 09:42:03 -0700342 | a=lambda_param_no_default+ b=lambda_param_with_default* c=[lambda_star_etc] {
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100343 _PyPegen_make_arguments(p, NULL, NULL, a, b, c) }
Guido van Rossum3941d972020-05-01 09:42:03 -0700344 | a=lambda_param_with_default+ b=[lambda_star_etc] { _PyPegen_make_arguments(p, NULL, NULL, NULL, a, b)}
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100345 | a=lambda_star_etc { _PyPegen_make_arguments(p, NULL, NULL, NULL, NULL, a) }
Guido van Rossum3941d972020-05-01 09:42:03 -0700346
347lambda_slash_no_default[asdl_seq*]:
348 | a=lambda_param_no_default+ '/' ',' { a }
349 | a=lambda_param_no_default+ '/' &':' { a }
350lambda_slash_with_default[SlashWithDefault*]:
351 | a=lambda_param_no_default* b=lambda_param_with_default+ '/' ',' { _PyPegen_slash_with_default(p, a, b) }
352 | a=lambda_param_no_default* b=lambda_param_with_default+ '/' &':' { _PyPegen_slash_with_default(p, a, b) }
353
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100354lambda_star_etc[StarEtc*]:
Guido van Rossum3941d972020-05-01 09:42:03 -0700355 | '*' a=lambda_param_no_default b=lambda_param_maybe_default* c=[lambda_kwds] {
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100356 _PyPegen_star_etc(p, a, b, c) }
Guido van Rossum3941d972020-05-01 09:42:03 -0700357 | '*' ',' b=lambda_param_maybe_default+ c=[lambda_kwds] {
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100358 _PyPegen_star_etc(p, NULL, b, c) }
Guido van Rossum3941d972020-05-01 09:42:03 -0700359 | a=lambda_kwds { _PyPegen_star_etc(p, NULL, NULL, a) }
Lysandros Nikolaoue10e7c72020-05-04 13:58:31 +0300360 | invalid_lambda_star_etc
Guido van Rossum3941d972020-05-01 09:42:03 -0700361
362lambda_kwds[arg_ty]: '**' a=lambda_param_no_default { a }
363
364lambda_param_no_default[arg_ty]:
365 | a=lambda_param ',' { a }
366 | a=lambda_param &':' { a }
367lambda_param_with_default[NameDefaultPair*]:
368 | a=lambda_param c=default ',' { _PyPegen_name_default_pair(p, a, c, NULL) }
369 | a=lambda_param c=default &':' { _PyPegen_name_default_pair(p, a, c, NULL) }
370lambda_param_maybe_default[NameDefaultPair*]:
371 | a=lambda_param c=default? ',' { _PyPegen_name_default_pair(p, a, c, NULL) }
372 | a=lambda_param c=default? &':' { _PyPegen_name_default_pair(p, a, c, NULL) }
373lambda_param[arg_ty]: a=NAME { _Py_arg(a->v.Name.id, NULL, NULL, EXTRA) }
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100374
375disjunction[expr_ty] (memo):
376 | a=conjunction b=('or' c=conjunction { c })+ { _Py_BoolOp(
377 Or,
378 CHECK(_PyPegen_seq_insert_in_front(p, a, b)),
379 EXTRA) }
380 | conjunction
381conjunction[expr_ty] (memo):
382 | a=inversion b=('and' c=inversion { c })+ { _Py_BoolOp(
383 And,
384 CHECK(_PyPegen_seq_insert_in_front(p, a, b)),
385 EXTRA) }
386 | inversion
387inversion[expr_ty] (memo):
388 | 'not' a=inversion { _Py_UnaryOp(Not, a, EXTRA) }
389 | comparison
390comparison[expr_ty]:
391 | a=bitwise_or b=compare_op_bitwise_or_pair+ {
392 _Py_Compare(a, CHECK(_PyPegen_get_cmpops(p, b)), CHECK(_PyPegen_get_exprs(p, b)), EXTRA) }
393 | bitwise_or
394compare_op_bitwise_or_pair[CmpopExprPair*]:
395 | eq_bitwise_or
396 | noteq_bitwise_or
397 | lte_bitwise_or
398 | lt_bitwise_or
399 | gte_bitwise_or
400 | gt_bitwise_or
401 | notin_bitwise_or
402 | in_bitwise_or
403 | isnot_bitwise_or
404 | is_bitwise_or
405eq_bitwise_or[CmpopExprPair*]: '==' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, Eq, a) }
Pablo Galindo2b74c832020-04-27 18:02:07 +0100406noteq_bitwise_or[CmpopExprPair*]:
407 | (tok='!=' {_PyPegen_check_barry_as_flufl(p) ? NULL : tok}) a=bitwise_or {_PyPegen_cmpop_expr_pair(p, NotEq, a) }
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100408lte_bitwise_or[CmpopExprPair*]: '<=' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, LtE, a) }
409lt_bitwise_or[CmpopExprPair*]: '<' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, Lt, a) }
410gte_bitwise_or[CmpopExprPair*]: '>=' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, GtE, a) }
411gt_bitwise_or[CmpopExprPair*]: '>' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, Gt, a) }
412notin_bitwise_or[CmpopExprPair*]: 'not' 'in' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, NotIn, a) }
413in_bitwise_or[CmpopExprPair*]: 'in' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, In, a) }
414isnot_bitwise_or[CmpopExprPair*]: 'is' 'not' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, IsNot, a) }
415is_bitwise_or[CmpopExprPair*]: 'is' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, Is, a) }
416
417bitwise_or[expr_ty]:
418 | a=bitwise_or '|' b=bitwise_xor { _Py_BinOp(a, BitOr, b, EXTRA) }
419 | bitwise_xor
420bitwise_xor[expr_ty]:
421 | a=bitwise_xor '^' b=bitwise_and { _Py_BinOp(a, BitXor, b, EXTRA) }
422 | bitwise_and
423bitwise_and[expr_ty]:
424 | a=bitwise_and '&' b=shift_expr { _Py_BinOp(a, BitAnd, b, EXTRA) }
425 | shift_expr
426shift_expr[expr_ty]:
427 | a=shift_expr '<<' b=sum { _Py_BinOp(a, LShift, b, EXTRA) }
428 | a=shift_expr '>>' b=sum { _Py_BinOp(a, RShift, b, EXTRA) }
429 | sum
430
431sum[expr_ty]:
432 | a=sum '+' b=term { _Py_BinOp(a, Add, b, EXTRA) }
433 | a=sum '-' b=term { _Py_BinOp(a, Sub, b, EXTRA) }
434 | term
435term[expr_ty]:
436 | a=term '*' b=factor { _Py_BinOp(a, Mult, b, EXTRA) }
437 | a=term '/' b=factor { _Py_BinOp(a, Div, b, EXTRA) }
438 | a=term '//' b=factor { _Py_BinOp(a, FloorDiv, b, EXTRA) }
439 | a=term '%' b=factor { _Py_BinOp(a, Mod, b, EXTRA) }
Lysandros Nikolaou3e0a6f32020-05-01 06:27:52 +0300440 | a=term '@' b=factor { CHECK_VERSION(5, "The '@' operator is", _Py_BinOp(a, MatMult, b, EXTRA)) }
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100441 | factor
442factor[expr_ty] (memo):
443 | '+' a=factor { _Py_UnaryOp(UAdd, a, EXTRA) }
444 | '-' a=factor { _Py_UnaryOp(USub, a, EXTRA) }
445 | '~' a=factor { _Py_UnaryOp(Invert, a, EXTRA) }
446 | power
447power[expr_ty]:
448 | a=await_primary '**' b=factor { _Py_BinOp(a, Pow, b, EXTRA) }
449 | await_primary
450await_primary[expr_ty] (memo):
Lysandros Nikolaou3e0a6f32020-05-01 06:27:52 +0300451 | AWAIT a=primary { CHECK_VERSION(5, "Await expressions are", _Py_Await(a, EXTRA)) }
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100452 | primary
453primary[expr_ty]:
454 | a=primary '.' b=NAME { _Py_Attribute(a, b->v.Name.id, Load, EXTRA) }
455 | a=primary b=genexp { _Py_Call(a, CHECK(_PyPegen_singleton_seq(p, b)), NULL, EXTRA) }
456 | a=primary '(' b=[arguments] ')' {
457 _Py_Call(a,
458 (b) ? ((expr_ty) b)->v.Call.args : NULL,
459 (b) ? ((expr_ty) b)->v.Call.keywords : NULL,
460 EXTRA) }
461 | a=primary '[' b=slices ']' { _Py_Subscript(a, b, Load, EXTRA) }
462 | atom
463
464slices[expr_ty]:
465 | a=slice !',' { a }
466 | a=','.slice+ [','] { _Py_Tuple(a, Load, EXTRA) }
467slice[expr_ty]:
468 | a=[expression] ':' b=[expression] c=[':' d=[expression] { d }] { _Py_Slice(a, b, c, EXTRA) }
469 | a=expression { a }
470atom[expr_ty]:
471 | NAME
472 | 'True' { _Py_Constant(Py_True, NULL, EXTRA) }
473 | 'False' { _Py_Constant(Py_False, NULL, EXTRA) }
474 | 'None' { _Py_Constant(Py_None, NULL, EXTRA) }
475 | '__new_parser__' { RAISE_SYNTAX_ERROR("You found it!") }
476 | &STRING strings
477 | NUMBER
478 | &'(' (tuple | group | genexp)
479 | &'[' (list | listcomp)
480 | &'{' (dict | set | dictcomp | setcomp)
481 | '...' { _Py_Constant(Py_Ellipsis, NULL, EXTRA) }
482
483strings[expr_ty] (memo): a=STRING+ { _PyPegen_concatenate_strings(p, a) }
484list[expr_ty]:
485 | '[' a=[star_named_expressions] ']' { _Py_List(a, Load, EXTRA) }
486listcomp[expr_ty]:
487 | '[' a=named_expression b=for_if_clauses ']' { _Py_ListComp(a, b, EXTRA) }
488 | invalid_comprehension
489tuple[expr_ty]:
490 | '(' a=[y=star_named_expression ',' z=[star_named_expressions] { _PyPegen_seq_insert_in_front(p, y, z) } ] ')' {
491 _Py_Tuple(a, Load, EXTRA) }
492group[expr_ty]: '(' a=(yield_expr | named_expression) ')' { a }
493genexp[expr_ty]:
494 | '(' a=expression b=for_if_clauses ')' { _Py_GeneratorExp(a, b, EXTRA) }
495 | invalid_comprehension
496set[expr_ty]: '{' a=expressions_list '}' { _Py_Set(a, EXTRA) }
497setcomp[expr_ty]:
498 | '{' a=expression b=for_if_clauses '}' { _Py_SetComp(a, b, EXTRA) }
499 | invalid_comprehension
500dict[expr_ty]:
501 | '{' a=[kvpairs] '}' { _Py_Dict(CHECK(_PyPegen_get_keys(p, a)),
502 CHECK(_PyPegen_get_values(p, a)), EXTRA) }
503dictcomp[expr_ty]:
504 | '{' a=kvpair b=for_if_clauses '}' { _Py_DictComp(a->key, a->value, b, EXTRA) }
505kvpairs[asdl_seq*]: a=','.kvpair+ [','] { a }
506kvpair[KeyValuePair*]:
507 | '**' a=bitwise_or { _PyPegen_key_value_pair(p, NULL, a) }
508 | a=expression ':' b=expression { _PyPegen_key_value_pair(p, a, b) }
509for_if_clauses[asdl_seq*]:
Lysandros Nikolaou3e0a6f32020-05-01 06:27:52 +0300510 | for_if_clause+
511for_if_clause[comprehension_ty]:
512 | ASYNC 'for' a=star_targets 'in' b=disjunction c=('if' z=disjunction { z })* {
513 CHECK_VERSION(6, "Async comprehensions are", _Py_comprehension(a, b, c, 1, p->arena)) }
514 | 'for' a=star_targets 'in' b=disjunction c=('if' z=disjunction { z })* {
515 _Py_comprehension(a, b, c, 0, p->arena) }
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100516
517yield_expr[expr_ty]:
518 | 'yield' 'from' a=expression { _Py_YieldFrom(a, EXTRA) }
519 | 'yield' a=[star_expressions] { _Py_Yield(a, EXTRA) }
520
521arguments[expr_ty] (memo):
522 | a=args [','] &')' { a }
523 | incorrect_arguments
524args[expr_ty]:
525 | a=starred_expression b=[',' c=args { c }] {
526 _Py_Call(_PyPegen_dummy_name(p),
527 (b) ? CHECK(_PyPegen_seq_insert_in_front(p, a, ((expr_ty) b)->v.Call.args))
528 : CHECK(_PyPegen_singleton_seq(p, a)),
529 (b) ? ((expr_ty) b)->v.Call.keywords : NULL,
530 EXTRA) }
531 | a=kwargs { _Py_Call(_PyPegen_dummy_name(p),
532 CHECK_NULL_ALLOWED(_PyPegen_seq_extract_starred_exprs(p, a)),
533 CHECK_NULL_ALLOWED(_PyPegen_seq_delete_starred_exprs(p, a)),
534 EXTRA) }
535 | a=named_expression b=[',' c=args { c }] {
536 _Py_Call(_PyPegen_dummy_name(p),
537 (b) ? CHECK(_PyPegen_seq_insert_in_front(p, a, ((expr_ty) b)->v.Call.args))
538 : CHECK(_PyPegen_singleton_seq(p, a)),
539 (b) ? ((expr_ty) b)->v.Call.keywords : NULL,
540 EXTRA) }
541kwargs[asdl_seq*]:
542 | a=','.kwarg_or_starred+ ',' b=','.kwarg_or_double_starred+ { _PyPegen_join_sequences(p, a, b) }
543 | ','.kwarg_or_starred+
544 | ','.kwarg_or_double_starred+
545starred_expression[expr_ty]:
546 | '*' a=expression { _Py_Starred(a, Load, EXTRA) }
547kwarg_or_starred[KeywordOrStarred*]:
548 | a=NAME '=' b=expression {
549 _PyPegen_keyword_or_starred(p, CHECK(_Py_keyword(a->v.Name.id, b, EXTRA)), 1) }
550 | a=starred_expression { _PyPegen_keyword_or_starred(p, a, 0) }
Lysandros Nikolaou4638c642020-05-07 13:44:06 +0300551 | invalid_kwarg
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100552kwarg_or_double_starred[KeywordOrStarred*]:
553 | a=NAME '=' b=expression {
554 _PyPegen_keyword_or_starred(p, CHECK(_Py_keyword(a->v.Name.id, b, EXTRA)), 1) }
555 | '**' a=expression { _PyPegen_keyword_or_starred(p, CHECK(_Py_keyword(NULL, a, EXTRA)), 1) }
Lysandros Nikolaou4638c642020-05-07 13:44:06 +0300556 | invalid_kwarg
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100557
558# NOTE: star_targets may contain *bitwise_or, targets may not.
559star_targets[expr_ty]:
560 | a=star_target !',' { a }
561 | a=star_target b=(',' c=star_target { c })* [','] {
562 _Py_Tuple(CHECK(_PyPegen_seq_insert_in_front(p, a, b)), Store, EXTRA) }
563star_targets_seq[asdl_seq*]: a=','.star_target+ [','] { a }
564star_target[expr_ty] (memo):
565 | '*' a=(!'*' star_target) {
566 _Py_Starred(CHECK(_PyPegen_set_expr_context(p, a, Store)), Store, EXTRA) }
567 | a=t_primary '.' b=NAME !t_lookahead { _Py_Attribute(a, b->v.Name.id, Store, EXTRA) }
568 | a=t_primary '[' b=slices ']' !t_lookahead { _Py_Subscript(a, b, Store, EXTRA) }
569 | star_atom
570star_atom[expr_ty]:
571 | a=NAME { _PyPegen_set_expr_context(p, a, Store) }
572 | '(' a=star_target ')' { _PyPegen_set_expr_context(p, a, Store) }
573 | '(' a=[star_targets_seq] ')' { _Py_Tuple(a, Store, EXTRA) }
574 | '[' a=[star_targets_seq] ']' { _Py_List(a, Store, EXTRA) }
575
Lysandros Nikolaouce21cfc2020-05-14 23:13:50 +0300576single_target[expr_ty]:
577 | single_subscript_attribute_target
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100578 | a=NAME { _PyPegen_set_expr_context(p, a, Store) }
Lysandros Nikolaouce21cfc2020-05-14 23:13:50 +0300579 | '(' a=single_target ')' { a }
580single_subscript_attribute_target[expr_ty]:
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100581 | a=t_primary '.' b=NAME !t_lookahead { _Py_Attribute(a, b->v.Name.id, Store, EXTRA) }
582 | a=t_primary '[' b=slices ']' !t_lookahead { _Py_Subscript(a, b, Store, EXTRA) }
583
584del_targets[asdl_seq*]: a=','.del_target+ [','] { a }
Shantanu27c0d9b2020-05-11 14:53:58 -0700585# The lookaheads to del_target_end ensure that we don't match expressions where a prefix of the
586# expression matches our rule, thereby letting these cases fall through to invalid_del_target.
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100587del_target[expr_ty] (memo):
Shantanu27c0d9b2020-05-11 14:53:58 -0700588 | a=t_primary '.' b=NAME &del_target_end { _Py_Attribute(a, b->v.Name.id, Del, EXTRA) }
589 | a=t_primary '[' b=slices ']' &del_target_end { _Py_Subscript(a, b, Del, EXTRA) }
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100590 | del_t_atom
591del_t_atom[expr_ty]:
Shantanu27c0d9b2020-05-11 14:53:58 -0700592 | a=NAME &del_target_end { _PyPegen_set_expr_context(p, a, Del) }
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100593 | '(' a=del_target ')' { _PyPegen_set_expr_context(p, a, Del) }
594 | '(' a=[del_targets] ')' { _Py_Tuple(a, Del, EXTRA) }
595 | '[' a=[del_targets] ']' { _Py_List(a, Del, EXTRA) }
Shantanu27c0d9b2020-05-11 14:53:58 -0700596 | invalid_del_target
597del_target_end: ')' | ']' | ',' | ';' | NEWLINE
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100598
599targets[asdl_seq*]: a=','.target+ [','] { a }
600target[expr_ty] (memo):
601 | a=t_primary '.' b=NAME !t_lookahead { _Py_Attribute(a, b->v.Name.id, Store, EXTRA) }
602 | a=t_primary '[' b=slices ']' !t_lookahead { _Py_Subscript(a, b, Store, EXTRA) }
603 | t_atom
604t_primary[expr_ty]:
605 | a=t_primary '.' b=NAME &t_lookahead { _Py_Attribute(a, b->v.Name.id, Load, EXTRA) }
606 | a=t_primary '[' b=slices ']' &t_lookahead { _Py_Subscript(a, b, Load, EXTRA) }
607 | a=t_primary b=genexp &t_lookahead { _Py_Call(a, CHECK(_PyPegen_singleton_seq(p, b)), NULL, EXTRA) }
608 | a=t_primary '(' b=[arguments] ')' &t_lookahead {
609 _Py_Call(a,
610 (b) ? ((expr_ty) b)->v.Call.args : NULL,
611 (b) ? ((expr_ty) b)->v.Call.keywords : NULL,
612 EXTRA) }
613 | a=atom &t_lookahead { a }
614t_lookahead: '(' | '[' | '.'
615t_atom[expr_ty]:
616 | a=NAME { _PyPegen_set_expr_context(p, a, Store) }
617 | '(' a=target ')' { _PyPegen_set_expr_context(p, a, Store) }
618 | '(' b=[targets] ')' { _Py_Tuple(b, Store, EXTRA) }
619 | '[' b=[targets] ']' { _Py_List(b, Store, EXTRA) }
620
621
622# From here on, there are rules for invalid syntax with specialised error messages
623incorrect_arguments:
624 | args ',' '*' { RAISE_SYNTAX_ERROR("iterable argument unpacking follows keyword argument unpacking") }
Lysandros Nikolaoua15c9b32020-05-13 22:36:27 +0300625 | a=expression for_if_clauses ',' [args | expression for_if_clauses] {
626 RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "Generator expression must be parenthesized") }
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100627 | a=args ',' args { _PyPegen_arguments_parsing_error(p, a) }
Lysandros Nikolaou4638c642020-05-07 13:44:06 +0300628invalid_kwarg:
Lysandros Nikolaoua15c9b32020-05-13 22:36:27 +0300629 | a=expression '=' {
630 RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
631 a, "expression cannot contain assignment, perhaps you meant \"==\"?") }
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100632invalid_named_expression:
633 | a=expression ':=' expression {
Lysandros Nikolaoua15c9b32020-05-13 22:36:27 +0300634 RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
635 a, "cannot use assignment expressions with %s", _PyPegen_get_expr_name(a)) }
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100636invalid_assignment:
Lysandros Nikolaoua15c9b32020-05-13 22:36:27 +0300637 | a=list ':' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "only single target (not list) can be annotated") }
638 | a=tuple ':' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "only single target (not tuple) can be annotated") }
639 | a=star_named_expression ',' star_named_expressions* ':' {
640 RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "only single target (not tuple) can be annotated") }
641 | a=expression ':' expression ['=' annotated_rhs] {
642 RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "illegal target for annotation") }
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100643 | a=expression ('=' | augassign) (yield_expr | star_expressions) {
Lysandros Nikolaoua15c9b32020-05-13 22:36:27 +0300644 RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "cannot assign to %s", _PyPegen_get_expr_name(a)) }
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100645invalid_block:
646 | NEWLINE !INDENT { RAISE_INDENTATION_ERROR("expected an indented block") }
647invalid_comprehension:
Lysandros Nikolaoua15c9b32020-05-13 22:36:27 +0300648 | ('[' | '(' | '{') a=starred_expression for_if_clauses {
649 RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "iterable unpacking cannot be used in comprehension") }
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100650invalid_parameters:
Guido van Rossumc001c092020-04-30 12:12:19 -0700651 | param_no_default* (slash_with_default | param_with_default+) param_no_default {
Pablo Galindoc5fc1562020-04-22 23:29:27 +0100652 RAISE_SYNTAX_ERROR("non-default argument follows default argument") }
Lysandros Nikolaoue10e7c72020-05-04 13:58:31 +0300653invalid_star_etc:
654 | '*' (')' | ',' (')' | '**')) { RAISE_SYNTAX_ERROR("named arguments must follow bare *") }
655invalid_lambda_star_etc:
656 | '*' (':' | ',' (':' | '**')) { RAISE_SYNTAX_ERROR("named arguments must follow bare *") }
Guido van Rossumc001c092020-04-30 12:12:19 -0700657invalid_double_type_comments:
658 | TYPE_COMMENT NEWLINE TYPE_COMMENT NEWLINE INDENT {
659 RAISE_SYNTAX_ERROR("Cannot have two type comments on def") }
Shantanu27c0d9b2020-05-11 14:53:58 -0700660invalid_del_target:
661 | a=star_expression &del_target_end {
Lysandros Nikolaoua15c9b32020-05-13 22:36:27 +0300662 RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "cannot delete %s", _PyPegen_get_expr_name(a)) }