Python-checkins
Threads by month
- ----- 2024 -----
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2003 -----
- December
- November
- October
- September
- August
April 2020
- 1 participants
- 410 discussions
https://github.com/python/cpython/commit/b66c0ff8af0c1a4adc6908897b2d05afc7…
commit: b66c0ff8af0c1a4adc6908897b2d05afc78cc27e
branch: master
author: Victor Stinner <vstinner(a)python.org>
committer: GitHub <noreply(a)github.com>
date: 2020-05-01T00:44:03+02:00
summary:
bpo-1635741: Fix compiler warning in _stat.c (GH-19822)
Cast Py_ARRAY_LENGTH() size_t to int explicitly.
files:
M Modules/_stat.c
diff --git a/Modules/_stat.c b/Modules/_stat.c
index 45a4e080c7746..c7090c02688de 100644
--- a/Modules/_stat.c
+++ b/Modules/_stat.c
@@ -563,7 +563,7 @@ stat_exec(PyObject *module)
"ST_CTIME"
};
- for (int i = 0; i < Py_ARRAY_LENGTH(st_constants); i++) {
+ for (int i = 0; i < (int)Py_ARRAY_LENGTH(st_constants); i++) {
if (PyModule_AddIntConstant(module, st_constants[i], i) < 0) {
return -1;
}
1
0
Revert "bpo-29587: Enable implicit exception chaining with gen.throw() (GH-19811)" (#19821)
by Victor Stinner 30 Apr '20
by Victor Stinner 30 Apr '20
30 Apr '20
https://github.com/python/cpython/commit/3c7f9db85095952821f9d106dd874f7566…
commit: 3c7f9db85095952821f9d106dd874f75662ce7ec
branch: master
author: Victor Stinner <vstinner(a)python.org>
committer: GitHub <noreply(a)github.com>
date: 2020-04-30T22:44:24+02:00
summary:
Revert "bpo-29587: Enable implicit exception chaining with gen.throw() (GH-19811)" (#19821)
This reverts commit 2514a632fb7d37be24c2059d0e286d35600f9795.
files:
D Misc/NEWS.d/next/Core and Builtins/2020-04-30-00-50-25.bpo-29587.oEwSq.rst
M Lib/test/test_generators.py
M Objects/genobject.c
diff --git a/Lib/test/test_generators.py b/Lib/test/test_generators.py
index 4d96f44b15062..3e42bc6b69a81 100644
--- a/Lib/test/test_generators.py
+++ b/Lib/test/test_generators.py
@@ -316,23 +316,6 @@ def g():
self.assertEqual(cm.exception.value.value, 2)
-class GeneratorThrowTest(unittest.TestCase):
-
- def test_exception_context_set(self):
- def f():
- try:
- raise KeyError('a')
- except Exception:
- yield
-
- gen = f()
- gen.send(None)
- with self.assertRaises(ValueError) as cm:
- gen.throw(ValueError)
- context = cm.exception.__context__
- self.assertEqual((type(context), context.args), (KeyError, ('a',)))
-
-
class YieldFromTests(unittest.TestCase):
def test_generator_gi_yieldfrom(self):
def a():
diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-04-30-00-50-25.bpo-29587.oEwSq.rst b/Misc/NEWS.d/next/Core and Builtins/2020-04-30-00-50-25.bpo-29587.oEwSq.rst
deleted file mode 100644
index f44aa360cc2ef..0000000000000
--- a/Misc/NEWS.d/next/Core and Builtins/2020-04-30-00-50-25.bpo-29587.oEwSq.rst
+++ /dev/null
@@ -1 +0,0 @@
-Enable implicit exception chaining when calling :meth:`generator.throw`.
diff --git a/Objects/genobject.c b/Objects/genobject.c
index 289ed79aa28a6..6e36690b65148 100644
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -512,12 +512,6 @@ _gen_throw(PyGenObject *gen, int close_on_genexit,
}
PyErr_Restore(typ, val, tb);
- if (gen->gi_exc_state.exc_type) {
- Py_INCREF(gen->gi_exc_state.exc_type);
- Py_XINCREF(gen->gi_exc_state.exc_value);
- Py_XINCREF(gen->gi_exc_state.exc_traceback);
- _PyErr_ChainExceptions(gen->gi_exc_state.exc_type, gen->gi_exc_state.exc_value, gen->gi_exc_state.exc_traceback);
- }
return gen_send_ex(gen, Py_None, 1, 0);
failed_throw:
1
0
bpo-29587: Enable implicit exception chaining with gen.throw() (GH-19811)
by Chris Jerdonek 30 Apr '20
by Chris Jerdonek 30 Apr '20
30 Apr '20
https://github.com/python/cpython/commit/2514a632fb7d37be24c2059d0e286d3560…
commit: 2514a632fb7d37be24c2059d0e286d35600f9795
branch: master
author: Chris Jerdonek <chris.jerdonek(a)gmail.com>
committer: GitHub <noreply(a)github.com>
date: 2020-04-30T12:18:05-07:00
summary:
bpo-29587: Enable implicit exception chaining with gen.throw() (GH-19811)
Before this commit, if an exception was active inside a generator
when calling gen.throw(), then that exception was lost (i.e. there
was no implicit exception chaining). This commit fixes that.
files:
A Misc/NEWS.d/next/Core and Builtins/2020-04-30-00-50-25.bpo-29587.oEwSq.rst
M Lib/test/test_generators.py
M Objects/genobject.c
diff --git a/Lib/test/test_generators.py b/Lib/test/test_generators.py
index 3e42bc6b69a81..4d96f44b15062 100644
--- a/Lib/test/test_generators.py
+++ b/Lib/test/test_generators.py
@@ -316,6 +316,23 @@ def g():
self.assertEqual(cm.exception.value.value, 2)
+class GeneratorThrowTest(unittest.TestCase):
+
+ def test_exception_context_set(self):
+ def f():
+ try:
+ raise KeyError('a')
+ except Exception:
+ yield
+
+ gen = f()
+ gen.send(None)
+ with self.assertRaises(ValueError) as cm:
+ gen.throw(ValueError)
+ context = cm.exception.__context__
+ self.assertEqual((type(context), context.args), (KeyError, ('a',)))
+
+
class YieldFromTests(unittest.TestCase):
def test_generator_gi_yieldfrom(self):
def a():
diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-04-30-00-50-25.bpo-29587.oEwSq.rst b/Misc/NEWS.d/next/Core and Builtins/2020-04-30-00-50-25.bpo-29587.oEwSq.rst
new file mode 100644
index 0000000000000..f44aa360cc2ef
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2020-04-30-00-50-25.bpo-29587.oEwSq.rst
@@ -0,0 +1 @@
+Enable implicit exception chaining when calling :meth:`generator.throw`.
diff --git a/Objects/genobject.c b/Objects/genobject.c
index 6e36690b65148..289ed79aa28a6 100644
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -512,6 +512,12 @@ _gen_throw(PyGenObject *gen, int close_on_genexit,
}
PyErr_Restore(typ, val, tb);
+ if (gen->gi_exc_state.exc_type) {
+ Py_INCREF(gen->gi_exc_state.exc_type);
+ Py_XINCREF(gen->gi_exc_state.exc_value);
+ Py_XINCREF(gen->gi_exc_state.exc_traceback);
+ _PyErr_ChainExceptions(gen->gi_exc_state.exc_type, gen->gi_exc_state.exc_value, gen->gi_exc_state.exc_traceback);
+ }
return gen_send_ex(gen, Py_None, 1, 0);
failed_throw:
1
0
https://github.com/python/cpython/commit/c001c09e9059ba04bc088349cd87a1374d…
commit: c001c09e9059ba04bc088349cd87a1374dc0754f
branch: master
author: Guido van Rossum <guido(a)python.org>
committer: GitHub <noreply(a)github.com>
date: 2020-04-30T12:12:19-07:00
summary:
bpo-40334: Support type comments (GH-19780)
This implements full support for # type: <type> comments, # type: ignore <stuff> comments, and the func_type parsing mode for ast.parse() and compile().
Closes https://github.com/we-like-parsers/cpython/issues/95.
(For now, you need to use the master branch of mypy, since another issue unique to 3.9 had to be fixed there, and there's no mypy release yet.)
The only thing missing is `feature_version=N`, which is being tracked in https://github.com/we-like-parsers/cpython/issues/124.
files:
M Grammar/python.gram
M Lib/test/test_type_comments.py
M Parser/pegen/parse.c
M Parser/pegen/pegen.c
M Parser/pegen/pegen.h
M Python/bltinmodule.c
diff --git a/Grammar/python.gram b/Grammar/python.gram
index 0ff2dcca884f1..e1164d990aaa4 100644
--- a/Grammar/python.gram
+++ b/Grammar/python.gram
@@ -17,6 +17,8 @@ _PyPegen_parse(Parser *p)
result = interactive_rule(p);
} else if (p->start_rule == Py_eval_input) {
result = eval_rule(p);
+ } else if (p->start_rule == Py_func_type_input) {
+ result = func_type_rule(p);
} else if (p->start_rule == Py_fstring_input) {
result = fstring_rule(p);
}
@@ -26,11 +28,20 @@ _PyPegen_parse(Parser *p)
// The end
'''
-file[mod_ty]: a=[statements] ENDMARKER { Module(a, NULL, p->arena) }
+file[mod_ty]: a=[statements] ENDMARKER { _PyPegen_make_module(p, a) }
interactive[mod_ty]: a=statement_newline { Interactive(a, p->arena) }
eval[mod_ty]: a=expressions NEWLINE* ENDMARKER { Expression(a, p->arena) }
+func_type[mod_ty]: '(' a=[type_expressions] ')' '->' b=expression NEWLINE* ENDMARKER { FunctionType(a, b, p->arena) }
fstring[expr_ty]: star_expressions
+# type_expressions allow */** but ignore them
+type_expressions[asdl_seq*]:
+ | a=','.expression+ ',' '*' b=expression ',' '**' c=expression {
+ _PyPegen_seq_append_to_end(p, CHECK(_PyPegen_seq_append_to_end(p, a, b)), c) }
+ | a=','.expression+ ',' '*' b=expression { _PyPegen_seq_append_to_end(p, a, b) }
+ | a=','.expression+ ',' '**' b=expression { _PyPegen_seq_append_to_end(p, a, b) }
+ | ','.expression+
+
statements[asdl_seq*]: a=statement+ { _PyPegen_seq_flatten(p, a) }
statement[asdl_seq*]: a=compound_stmt { _PyPegen_singleton_seq(p, a) } | simple_stmt
statement_newline[asdl_seq*]:
@@ -73,8 +84,8 @@ assignment:
| a=('(' b=inside_paren_ann_assign_target ')' { b }
| ann_assign_subscript_attribute_target) ':' b=expression c=['=' d=annotated_rhs { d }] {
_Py_AnnAssign(a, b, c, 0, EXTRA)}
- | a=(z=star_targets '=' { z })+ b=(yield_expr | star_expressions) {
- _Py_Assign(a, b, NULL, EXTRA) }
+ | a=(z=star_targets '=' { z })+ b=(yield_expr | star_expressions) tc=[TYPE_COMMENT] {
+ _Py_Assign(a, b, NEW_TYPE_COMMENT(p, tc), EXTRA) }
| a=target b=augassign c=(yield_expr | star_expressions) {
_Py_AugAssign(a, b->kind, c, EXTRA) }
| invalid_assignment
@@ -145,14 +156,14 @@ while_stmt[stmt_ty]:
| 'while' a=named_expression ':' b=block c=[else_block] { _Py_While(a, b, c, EXTRA) }
for_stmt[stmt_ty]:
- | is_async=[ASYNC] 'for' t=star_targets 'in' ex=star_expressions ':' b=block el=[else_block] {
- (is_async ? _Py_AsyncFor : _Py_For)(t, ex, b, el, NULL, EXTRA) }
+ | is_async=[ASYNC] 'for' t=star_targets 'in' ex=star_expressions ':' tc=[TYPE_COMMENT] b=block el=[else_block] {
+ (is_async ? _Py_AsyncFor : _Py_For)(t, ex, b, el, NEW_TYPE_COMMENT(p, tc), EXTRA) }
with_stmt[stmt_ty]:
| is_async=[ASYNC] 'with' '(' a=','.with_item+ ')' ':' b=block {
(is_async ? _Py_AsyncWith : _Py_With)(a, b, NULL, EXTRA) }
- | is_async=[ASYNC] 'with' a=','.with_item+ ':' b=block {
- (is_async ? _Py_AsyncWith : _Py_With)(a, b, NULL, EXTRA) }
+ | is_async=[ASYNC] 'with' a=','.with_item+ ':' tc=[TYPE_COMMENT] b=block {
+ (is_async ? _Py_AsyncWith : _Py_With)(a, b, NEW_TYPE_COMMENT(p, tc), EXTRA) }
with_item[withitem_ty]:
| e=expression o=['as' t=target { t }] { _Py_withitem(e, o, p->arena) }
@@ -177,43 +188,74 @@ function_def[stmt_ty]:
| function_def_raw
function_def_raw[stmt_ty]:
- | is_async=[ASYNC] 'def' n=NAME '(' params=[params] ')' a=['->' z=annotation { z }] ':' b=block {
+ | is_async=[ASYNC] 'def' n=NAME '(' params=[params] ')' a=['->' z=expression { z }] ':' tc=[func_type_comment] b=block {
(is_async ? _Py_AsyncFunctionDef : _Py_FunctionDef)(n->v.Name.id,
(params) ? params : CHECK(_PyPegen_empty_arguments(p)),
- b, NULL, a, NULL, EXTRA) }
+ b, NULL, a, NEW_TYPE_COMMENT(p, tc), EXTRA) }
+func_type_comment[PyObject*]:
+ | NEWLINE t=TYPE_COMMENT &(NEWLINE INDENT) { t } # Must be followed by indented block
+ | invalid_double_type_comments
+ | TYPE_COMMENT
params[arguments_ty]:
| invalid_parameters
| parameters
+
parameters[arguments_ty]:
- | a=slash_without_default b=[',' x=plain_names { x }] c=[',' y=names_with_default { y }] d=[',' z=[star_etc] { z }] {
+ | a=slash_no_default b=param_no_default* c=param_with_default* d=[star_etc] {
_PyPegen_make_arguments(p, a, NULL, b, c, d) }
- | a=slash_with_default b=[',' y=names_with_default { y }] c=[',' z=[star_etc] { z }] {
+ | a=slash_with_default b=param_with_default* c=[star_etc] {
_PyPegen_make_arguments(p, NULL, a, NULL, b, c) }
- | a=plain_names b=[',' y=names_with_default { y }] c=[',' z=[star_etc] { z }] {
+ | a=param_no_default+ b=param_with_default* c=[star_etc] {
_PyPegen_make_arguments(p, NULL, NULL, a, b, c) }
- | a=names_with_default b=[',' z=[star_etc] { z }] { _PyPegen_make_arguments(p, NULL, NULL, NULL, a, b)}
+ | a=param_with_default+ b=[star_etc] { _PyPegen_make_arguments(p, NULL, NULL, NULL, a, b)}
| a=star_etc { _PyPegen_make_arguments(p, NULL, NULL, NULL, NULL, a) }
-slash_without_default[asdl_seq*]: a=plain_names ',' '/' { a }
-slash_with_default[SlashWithDefault*]: a=[n=plain_names ',' { n }] b=names_with_default ',' '/' {
- _PyPegen_slash_with_default(p, a, b) }
+
+# Some duplication here because we can't write (',' | &')'),
+# which is because we don't support empty alternatives (yet).
+#
+slash_no_default[asdl_seq*]:
+ | a=param_no_default+ '/' ',' { a }
+ | a=param_no_default+ '/' &')' { a }
+slash_with_default[SlashWithDefault*]:
+ | a=param_no_default* b=param_with_default+ '/' ',' { _PyPegen_slash_with_default(p, a, b) }
+ | a=param_no_default* b=param_with_default+ '/' &')' { _PyPegen_slash_with_default(p, a, b) }
+
star_etc[StarEtc*]:
- | '*' a=plain_name b=name_with_optional_default* c=[',' d=kwds { d }] [','] {
+ | '*' a=param_no_default b=param_maybe_default* c=[kwds] {
_PyPegen_star_etc(p, a, b, c) }
- | '*' b=name_with_optional_default+ c=[',' d=kwds { d }] [','] {
+ | '*' ',' b=param_maybe_default+ c=[kwds] {
_PyPegen_star_etc(p, NULL, b, c) }
- | a=kwds [','] { _PyPegen_star_etc(p, NULL, NULL, a) }
-name_with_optional_default[NameDefaultPair*]:
- | ',' a=plain_name b=['=' e=expression { e }] { _PyPegen_name_default_pair(p, a, b) }
-names_with_default[asdl_seq*]: a=','.name_with_default+ { a }
-name_with_default[NameDefaultPair*]:
- | n=plain_name '=' e=expression { _PyPegen_name_default_pair(p, n, e) }
-plain_names[asdl_seq*] (memo): a=','.(plain_name !'=')+ { a }
-plain_name[arg_ty]:
- | a=NAME b=[':' z=annotation { z }] { _Py_arg(a->v.Name.id, b, NULL, EXTRA) }
+ | a=kwds { _PyPegen_star_etc(p, NULL, NULL, a) }
+
kwds[arg_ty]:
- | '**' a=plain_name { a }
-annotation[expr_ty]: expression
+ | '**' a=param_no_default { a }
+
+# 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 }
decorators[asdl_seq*]: a=('@' f=named_expression NEWLINE { f })+ { a }
@@ -284,10 +326,10 @@ lambda_star_etc[StarEtc*]:
_PyPegen_star_etc(p, NULL, b, c) }
| a=lambda_kwds [','] { _PyPegen_star_etc(p, NULL, NULL, a) }
lambda_name_with_optional_default[NameDefaultPair*]:
- | ',' a=lambda_plain_name b=['=' e=expression { e }] { _PyPegen_name_default_pair(p, a, b) }
+ | ',' a=lambda_plain_name b=['=' e=expression { e }] { _PyPegen_name_default_pair(p, a, b, NULL) }
lambda_names_with_default[asdl_seq*]: a=','.lambda_name_with_default+ { a }
lambda_name_with_default[NameDefaultPair*]:
- | n=lambda_plain_name '=' e=expression { _PyPegen_name_default_pair(p, n, e) }
+ | n=lambda_plain_name '=' e=expression { _PyPegen_name_default_pair(p, n, e, NULL) }
lambda_plain_names[asdl_seq*]: a=','.(lambda_plain_name !'=')+ { a }
lambda_plain_name[arg_ty]: a=NAME { _Py_arg(a->v.Name.id, NULL, NULL, EXTRA) }
lambda_kwds[arg_ty]: '**' a=lambda_plain_name { a }
@@ -552,5 +594,8 @@ invalid_comprehension:
| ('[' | '(' | '{') '*' expression for_if_clauses {
RAISE_SYNTAX_ERROR("iterable unpacking cannot be used in comprehension") }
invalid_parameters:
- | [plain_names ','] (slash_with_default | names_with_default) ',' plain_names {
+ | param_no_default* (slash_with_default | param_with_default+) param_no_default {
RAISE_SYNTAX_ERROR("non-default argument follows default argument") }
+invalid_double_type_comments:
+ | TYPE_COMMENT NEWLINE TYPE_COMMENT NEWLINE INDENT {
+ RAISE_SYNTAX_ERROR("Cannot have two type comments on def") }
diff --git a/Lib/test/test_type_comments.py b/Lib/test/test_type_comments.py
index ce3b7985e62b2..6c3f6ed4ed209 100644
--- a/Lib/test/test_type_comments.py
+++ b/Lib/test/test_type_comments.py
@@ -219,7 +219,6 @@ def favk(
"""
-(a)support.skip_if_new_parser("Pegen does not support type comments yet")
class TypeCommentTests(unittest.TestCase):
lowest = 4 # Lowest minor version supported
@@ -253,6 +252,7 @@ def test_funcdef(self):
self.assertEqual(tree.body[0].type_comment, None)
self.assertEqual(tree.body[1].type_comment, None)
+ @support.skip_if_new_parser("Pegen does not support feature_version yet")
def test_asyncdef(self):
for tree in self.parse_all(asyncdef, minver=5):
self.assertEqual(tree.body[0].type_comment, "() -> int")
@@ -261,22 +261,27 @@ def test_asyncdef(self):
self.assertEqual(tree.body[0].type_comment, None)
self.assertEqual(tree.body[1].type_comment, None)
+ @support.skip_if_new_parser("Pegen does not support feature_version yet")
def test_asyncvar(self):
for tree in self.parse_all(asyncvar, maxver=6):
pass
+ @support.skip_if_new_parser("Pegen does not support feature_version yet")
def test_asynccomp(self):
for tree in self.parse_all(asynccomp, minver=6):
pass
+ @support.skip_if_new_parser("Pegen does not support feature_version yet")
def test_matmul(self):
for tree in self.parse_all(matmul, minver=5):
pass
+ @support.skip_if_new_parser("Pegen does not support feature_version yet")
def test_fstring(self):
for tree in self.parse_all(fstring, minver=6):
pass
+ @support.skip_if_new_parser("Pegen does not support feature_version yet")
def test_underscorednumber(self):
for tree in self.parse_all(underscorednumber, minver=6):
pass
diff --git a/Parser/pegen/parse.c b/Parser/pegen/parse.c
index 76dd6d31da05a..8ff9a70d3bb82 100644
--- a/Parser/pegen/parse.c
+++ b/Parser/pegen/parse.c
@@ -71,289 +71,300 @@ static KeywordToken *reserved_keywords[] = {
#define file_type 1000
#define interactive_type 1001
#define eval_type 1002
-#define fstring_type 1003
-#define statements_type 1004
-#define statement_type 1005
-#define statement_newline_type 1006
-#define simple_stmt_type 1007
-#define small_stmt_type 1008
-#define compound_stmt_type 1009
-#define assignment_type 1010
-#define augassign_type 1011
-#define global_stmt_type 1012
-#define nonlocal_stmt_type 1013
-#define yield_stmt_type 1014
-#define assert_stmt_type 1015
-#define del_stmt_type 1016
-#define import_stmt_type 1017
-#define import_name_type 1018
-#define import_from_type 1019
-#define import_from_targets_type 1020
-#define import_from_as_names_type 1021
-#define import_from_as_name_type 1022
-#define dotted_as_names_type 1023
-#define dotted_as_name_type 1024
-#define dotted_name_type 1025 // Left-recursive
-#define if_stmt_type 1026
-#define elif_stmt_type 1027
-#define else_block_type 1028
-#define while_stmt_type 1029
-#define for_stmt_type 1030
-#define with_stmt_type 1031
-#define with_item_type 1032
-#define try_stmt_type 1033
-#define except_block_type 1034
-#define finally_block_type 1035
-#define return_stmt_type 1036
-#define raise_stmt_type 1037
-#define function_def_type 1038
-#define function_def_raw_type 1039
-#define params_type 1040
-#define parameters_type 1041
-#define slash_without_default_type 1042
-#define slash_with_default_type 1043
-#define star_etc_type 1044
-#define name_with_optional_default_type 1045
-#define names_with_default_type 1046
-#define name_with_default_type 1047
-#define plain_names_type 1048
-#define plain_name_type 1049
-#define kwds_type 1050
-#define annotation_type 1051
-#define decorators_type 1052
-#define class_def_type 1053
-#define class_def_raw_type 1054
-#define block_type 1055
-#define expressions_list_type 1056
-#define star_expressions_type 1057
-#define star_expression_type 1058
-#define star_named_expressions_type 1059
-#define star_named_expression_type 1060
-#define named_expression_type 1061
-#define annotated_rhs_type 1062
-#define expressions_type 1063
-#define expression_type 1064
-#define lambdef_type 1065
-#define lambda_parameters_type 1066
-#define lambda_slash_without_default_type 1067
-#define lambda_slash_with_default_type 1068
-#define lambda_star_etc_type 1069
-#define lambda_name_with_optional_default_type 1070
-#define lambda_names_with_default_type 1071
-#define lambda_name_with_default_type 1072
-#define lambda_plain_names_type 1073
-#define lambda_plain_name_type 1074
-#define lambda_kwds_type 1075
-#define disjunction_type 1076
-#define conjunction_type 1077
-#define inversion_type 1078
-#define comparison_type 1079
-#define compare_op_bitwise_or_pair_type 1080
-#define eq_bitwise_or_type 1081
-#define noteq_bitwise_or_type 1082
-#define lte_bitwise_or_type 1083
-#define lt_bitwise_or_type 1084
-#define gte_bitwise_or_type 1085
-#define gt_bitwise_or_type 1086
-#define notin_bitwise_or_type 1087
-#define in_bitwise_or_type 1088
-#define isnot_bitwise_or_type 1089
-#define is_bitwise_or_type 1090
-#define bitwise_or_type 1091 // Left-recursive
-#define bitwise_xor_type 1092 // Left-recursive
-#define bitwise_and_type 1093 // Left-recursive
-#define shift_expr_type 1094 // Left-recursive
-#define sum_type 1095 // Left-recursive
-#define term_type 1096 // Left-recursive
-#define factor_type 1097
-#define power_type 1098
-#define await_primary_type 1099
-#define primary_type 1100 // Left-recursive
-#define slices_type 1101
-#define slice_type 1102
-#define atom_type 1103
-#define strings_type 1104
-#define list_type 1105
-#define listcomp_type 1106
-#define tuple_type 1107
-#define group_type 1108
-#define genexp_type 1109
-#define set_type 1110
-#define setcomp_type 1111
-#define dict_type 1112
-#define dictcomp_type 1113
-#define kvpairs_type 1114
-#define kvpair_type 1115
-#define for_if_clauses_type 1116
-#define yield_expr_type 1117
-#define arguments_type 1118
-#define args_type 1119
-#define kwargs_type 1120
-#define starred_expression_type 1121
-#define kwarg_or_starred_type 1122
-#define kwarg_or_double_starred_type 1123
-#define star_targets_type 1124
-#define star_targets_seq_type 1125
-#define star_target_type 1126
-#define star_atom_type 1127
-#define inside_paren_ann_assign_target_type 1128
-#define ann_assign_subscript_attribute_target_type 1129
-#define del_targets_type 1130
-#define del_target_type 1131
-#define del_t_atom_type 1132
-#define targets_type 1133
-#define target_type 1134
-#define t_primary_type 1135 // Left-recursive
-#define t_lookahead_type 1136
-#define t_atom_type 1137
-#define incorrect_arguments_type 1138
-#define invalid_named_expression_type 1139
-#define invalid_assignment_type 1140
-#define invalid_block_type 1141
-#define invalid_comprehension_type 1142
-#define invalid_parameters_type 1143
-#define _loop0_1_type 1144
-#define _loop1_2_type 1145
-#define _loop0_4_type 1146
-#define _gather_3_type 1147
-#define _tmp_5_type 1148
-#define _tmp_6_type 1149
-#define _tmp_7_type 1150
-#define _tmp_8_type 1151
-#define _tmp_9_type 1152
-#define _tmp_10_type 1153
-#define _tmp_11_type 1154
-#define _tmp_12_type 1155
-#define _loop1_13_type 1156
-#define _tmp_14_type 1157
-#define _tmp_15_type 1158
-#define _loop0_17_type 1159
-#define _gather_16_type 1160
-#define _loop0_19_type 1161
-#define _gather_18_type 1162
-#define _tmp_20_type 1163
-#define _loop0_21_type 1164
-#define _loop1_22_type 1165
-#define _loop0_24_type 1166
-#define _gather_23_type 1167
-#define _tmp_25_type 1168
-#define _loop0_27_type 1169
-#define _gather_26_type 1170
-#define _tmp_28_type 1171
-#define _loop0_30_type 1172
-#define _gather_29_type 1173
-#define _loop0_32_type 1174
-#define _gather_31_type 1175
-#define _tmp_33_type 1176
-#define _loop1_34_type 1177
-#define _tmp_35_type 1178
-#define _tmp_36_type 1179
-#define _tmp_37_type 1180
-#define _tmp_38_type 1181
-#define _tmp_39_type 1182
-#define _tmp_40_type 1183
-#define _tmp_41_type 1184
-#define _tmp_42_type 1185
-#define _tmp_43_type 1186
-#define _tmp_44_type 1187
-#define _tmp_45_type 1188
-#define _tmp_46_type 1189
-#define _loop0_47_type 1190
-#define _tmp_48_type 1191
-#define _loop1_49_type 1192
-#define _tmp_50_type 1193
-#define _tmp_51_type 1194
-#define _loop0_53_type 1195
-#define _gather_52_type 1196
-#define _loop0_55_type 1197
-#define _gather_54_type 1198
-#define _tmp_56_type 1199
-#define _loop1_57_type 1200
-#define _tmp_58_type 1201
-#define _loop0_60_type 1202
-#define _gather_59_type 1203
-#define _loop1_61_type 1204
-#define _loop0_63_type 1205
-#define _gather_62_type 1206
-#define _loop1_64_type 1207
-#define _tmp_65_type 1208
-#define _tmp_66_type 1209
-#define _tmp_67_type 1210
-#define _tmp_68_type 1211
-#define _tmp_69_type 1212
-#define _tmp_70_type 1213
-#define _tmp_71_type 1214
-#define _tmp_72_type 1215
-#define _tmp_73_type 1216
-#define _loop0_74_type 1217
-#define _tmp_75_type 1218
-#define _loop1_76_type 1219
-#define _tmp_77_type 1220
-#define _tmp_78_type 1221
-#define _loop0_80_type 1222
-#define _gather_79_type 1223
-#define _loop0_82_type 1224
-#define _gather_81_type 1225
-#define _loop1_83_type 1226
-#define _loop1_84_type 1227
-#define _loop1_85_type 1228
-#define _tmp_86_type 1229
-#define _loop0_88_type 1230
-#define _gather_87_type 1231
-#define _tmp_89_type 1232
-#define _tmp_90_type 1233
-#define _tmp_91_type 1234
-#define _tmp_92_type 1235
-#define _loop1_93_type 1236
-#define _tmp_94_type 1237
-#define _tmp_95_type 1238
-#define _loop0_97_type 1239
-#define _gather_96_type 1240
-#define _loop1_98_type 1241
-#define _tmp_99_type 1242
-#define _tmp_100_type 1243
-#define _loop0_102_type 1244
-#define _gather_101_type 1245
-#define _loop0_104_type 1246
-#define _gather_103_type 1247
-#define _loop0_106_type 1248
-#define _gather_105_type 1249
-#define _loop0_108_type 1250
-#define _gather_107_type 1251
-#define _loop0_109_type 1252
-#define _loop0_111_type 1253
-#define _gather_110_type 1254
-#define _tmp_112_type 1255
-#define _loop0_114_type 1256
-#define _gather_113_type 1257
-#define _loop0_116_type 1258
-#define _gather_115_type 1259
-#define _tmp_117_type 1260
-#define _tmp_118_type 1261
-#define _tmp_119_type 1262
-#define _tmp_120_type 1263
-#define _tmp_121_type 1264
-#define _tmp_122_type 1265
-#define _tmp_123_type 1266
-#define _tmp_124_type 1267
-#define _tmp_125_type 1268
-#define _tmp_126_type 1269
-#define _tmp_127_type 1270
-#define _tmp_128_type 1271
-#define _tmp_129_type 1272
-#define _tmp_130_type 1273
-#define _tmp_131_type 1274
-#define _tmp_132_type 1275
-#define _tmp_133_type 1276
-#define _tmp_134_type 1277
-#define _tmp_135_type 1278
-#define _loop0_136_type 1279
-#define _tmp_137_type 1280
+#define func_type_type 1003
+#define fstring_type 1004
+#define type_expressions_type 1005
+#define statements_type 1006
+#define statement_type 1007
+#define statement_newline_type 1008
+#define simple_stmt_type 1009
+#define small_stmt_type 1010
+#define compound_stmt_type 1011
+#define assignment_type 1012
+#define augassign_type 1013
+#define global_stmt_type 1014
+#define nonlocal_stmt_type 1015
+#define yield_stmt_type 1016
+#define assert_stmt_type 1017
+#define del_stmt_type 1018
+#define import_stmt_type 1019
+#define import_name_type 1020
+#define import_from_type 1021
+#define import_from_targets_type 1022
+#define import_from_as_names_type 1023
+#define import_from_as_name_type 1024
+#define dotted_as_names_type 1025
+#define dotted_as_name_type 1026
+#define dotted_name_type 1027 // Left-recursive
+#define if_stmt_type 1028
+#define elif_stmt_type 1029
+#define else_block_type 1030
+#define while_stmt_type 1031
+#define for_stmt_type 1032
+#define with_stmt_type 1033
+#define with_item_type 1034
+#define try_stmt_type 1035
+#define except_block_type 1036
+#define finally_block_type 1037
+#define return_stmt_type 1038
+#define raise_stmt_type 1039
+#define function_def_type 1040
+#define function_def_raw_type 1041
+#define func_type_comment_type 1042
+#define params_type 1043
+#define parameters_type 1044
+#define slash_no_default_type 1045
+#define slash_with_default_type 1046
+#define star_etc_type 1047
+#define kwds_type 1048
+#define param_no_default_type 1049
+#define param_with_default_type 1050
+#define param_maybe_default_type 1051
+#define param_type 1052
+#define annotation_type 1053
+#define default_type 1054
+#define decorators_type 1055
+#define class_def_type 1056
+#define class_def_raw_type 1057
+#define block_type 1058
+#define expressions_list_type 1059
+#define star_expressions_type 1060
+#define star_expression_type 1061
+#define star_named_expressions_type 1062
+#define star_named_expression_type 1063
+#define named_expression_type 1064
+#define annotated_rhs_type 1065
+#define expressions_type 1066
+#define expression_type 1067
+#define lambdef_type 1068
+#define lambda_parameters_type 1069
+#define lambda_slash_without_default_type 1070
+#define lambda_slash_with_default_type 1071
+#define lambda_star_etc_type 1072
+#define lambda_name_with_optional_default_type 1073
+#define lambda_names_with_default_type 1074
+#define lambda_name_with_default_type 1075
+#define lambda_plain_names_type 1076
+#define lambda_plain_name_type 1077
+#define lambda_kwds_type 1078
+#define disjunction_type 1079
+#define conjunction_type 1080
+#define inversion_type 1081
+#define comparison_type 1082
+#define compare_op_bitwise_or_pair_type 1083
+#define eq_bitwise_or_type 1084
+#define noteq_bitwise_or_type 1085
+#define lte_bitwise_or_type 1086
+#define lt_bitwise_or_type 1087
+#define gte_bitwise_or_type 1088
+#define gt_bitwise_or_type 1089
+#define notin_bitwise_or_type 1090
+#define in_bitwise_or_type 1091
+#define isnot_bitwise_or_type 1092
+#define is_bitwise_or_type 1093
+#define bitwise_or_type 1094 // Left-recursive
+#define bitwise_xor_type 1095 // Left-recursive
+#define bitwise_and_type 1096 // Left-recursive
+#define shift_expr_type 1097 // Left-recursive
+#define sum_type 1098 // Left-recursive
+#define term_type 1099 // Left-recursive
+#define factor_type 1100
+#define power_type 1101
+#define await_primary_type 1102
+#define primary_type 1103 // Left-recursive
+#define slices_type 1104
+#define slice_type 1105
+#define atom_type 1106
+#define strings_type 1107
+#define list_type 1108
+#define listcomp_type 1109
+#define tuple_type 1110
+#define group_type 1111
+#define genexp_type 1112
+#define set_type 1113
+#define setcomp_type 1114
+#define dict_type 1115
+#define dictcomp_type 1116
+#define kvpairs_type 1117
+#define kvpair_type 1118
+#define for_if_clauses_type 1119
+#define yield_expr_type 1120
+#define arguments_type 1121
+#define args_type 1122
+#define kwargs_type 1123
+#define starred_expression_type 1124
+#define kwarg_or_starred_type 1125
+#define kwarg_or_double_starred_type 1126
+#define star_targets_type 1127
+#define star_targets_seq_type 1128
+#define star_target_type 1129
+#define star_atom_type 1130
+#define inside_paren_ann_assign_target_type 1131
+#define ann_assign_subscript_attribute_target_type 1132
+#define del_targets_type 1133
+#define del_target_type 1134
+#define del_t_atom_type 1135
+#define targets_type 1136
+#define target_type 1137
+#define t_primary_type 1138 // Left-recursive
+#define t_lookahead_type 1139
+#define t_atom_type 1140
+#define incorrect_arguments_type 1141
+#define invalid_named_expression_type 1142
+#define invalid_assignment_type 1143
+#define invalid_block_type 1144
+#define invalid_comprehension_type 1145
+#define invalid_parameters_type 1146
+#define invalid_double_type_comments_type 1147
+#define _loop0_1_type 1148
+#define _loop0_2_type 1149
+#define _loop0_4_type 1150
+#define _gather_3_type 1151
+#define _loop0_6_type 1152
+#define _gather_5_type 1153
+#define _loop0_8_type 1154
+#define _gather_7_type 1155
+#define _loop0_10_type 1156
+#define _gather_9_type 1157
+#define _loop1_11_type 1158
+#define _loop0_13_type 1159
+#define _gather_12_type 1160
+#define _tmp_14_type 1161
+#define _tmp_15_type 1162
+#define _tmp_16_type 1163
+#define _tmp_17_type 1164
+#define _tmp_18_type 1165
+#define _tmp_19_type 1166
+#define _tmp_20_type 1167
+#define _tmp_21_type 1168
+#define _loop1_22_type 1169
+#define _tmp_23_type 1170
+#define _tmp_24_type 1171
+#define _loop0_26_type 1172
+#define _gather_25_type 1173
+#define _loop0_28_type 1174
+#define _gather_27_type 1175
+#define _tmp_29_type 1176
+#define _loop0_30_type 1177
+#define _loop1_31_type 1178
+#define _loop0_33_type 1179
+#define _gather_32_type 1180
+#define _tmp_34_type 1181
+#define _loop0_36_type 1182
+#define _gather_35_type 1183
+#define _tmp_37_type 1184
+#define _loop0_39_type 1185
+#define _gather_38_type 1186
+#define _loop0_41_type 1187
+#define _gather_40_type 1188
+#define _tmp_42_type 1189
+#define _loop1_43_type 1190
+#define _tmp_44_type 1191
+#define _tmp_45_type 1192
+#define _tmp_46_type 1193
+#define _tmp_47_type 1194
+#define _loop0_48_type 1195
+#define _loop0_49_type 1196
+#define _loop0_50_type 1197
+#define _loop1_51_type 1198
+#define _loop0_52_type 1199
+#define _loop1_53_type 1200
+#define _loop1_54_type 1201
+#define _loop1_55_type 1202
+#define _loop0_56_type 1203
+#define _loop1_57_type 1204
+#define _loop0_58_type 1205
+#define _loop1_59_type 1206
+#define _loop0_60_type 1207
+#define _loop1_61_type 1208
+#define _loop1_62_type 1209
+#define _tmp_63_type 1210
+#define _loop0_65_type 1211
+#define _gather_64_type 1212
+#define _loop1_66_type 1213
+#define _loop0_68_type 1214
+#define _gather_67_type 1215
+#define _loop1_69_type 1216
+#define _tmp_70_type 1217
+#define _tmp_71_type 1218
+#define _tmp_72_type 1219
+#define _tmp_73_type 1220
+#define _tmp_74_type 1221
+#define _tmp_75_type 1222
+#define _tmp_76_type 1223
+#define _tmp_77_type 1224
+#define _tmp_78_type 1225
+#define _loop0_79_type 1226
+#define _tmp_80_type 1227
+#define _loop1_81_type 1228
+#define _tmp_82_type 1229
+#define _tmp_83_type 1230
+#define _loop0_85_type 1231
+#define _gather_84_type 1232
+#define _loop0_87_type 1233
+#define _gather_86_type 1234
+#define _loop1_88_type 1235
+#define _loop1_89_type 1236
+#define _loop1_90_type 1237
+#define _tmp_91_type 1238
+#define _loop0_93_type 1239
+#define _gather_92_type 1240
+#define _tmp_94_type 1241
+#define _tmp_95_type 1242
+#define _tmp_96_type 1243
+#define _tmp_97_type 1244
+#define _loop1_98_type 1245
+#define _tmp_99_type 1246
+#define _tmp_100_type 1247
+#define _loop0_102_type 1248
+#define _gather_101_type 1249
+#define _loop1_103_type 1250
+#define _tmp_104_type 1251
+#define _tmp_105_type 1252
+#define _loop0_107_type 1253
+#define _gather_106_type 1254
+#define _loop0_109_type 1255
+#define _gather_108_type 1256
+#define _loop0_111_type 1257
+#define _gather_110_type 1258
+#define _loop0_113_type 1259
+#define _gather_112_type 1260
+#define _loop0_114_type 1261
+#define _loop0_116_type 1262
+#define _gather_115_type 1263
+#define _tmp_117_type 1264
+#define _loop0_119_type 1265
+#define _gather_118_type 1266
+#define _loop0_121_type 1267
+#define _gather_120_type 1268
+#define _tmp_122_type 1269
+#define _tmp_123_type 1270
+#define _tmp_124_type 1271
+#define _tmp_125_type 1272
+#define _tmp_126_type 1273
+#define _loop0_127_type 1274
+#define _tmp_128_type 1275
+#define _tmp_129_type 1276
+#define _tmp_130_type 1277
+#define _tmp_131_type 1278
+#define _tmp_132_type 1279
+#define _tmp_133_type 1280
+#define _tmp_134_type 1281
+#define _tmp_135_type 1282
+#define _tmp_136_type 1283
+#define _tmp_137_type 1284
+#define _tmp_138_type 1285
+#define _tmp_139_type 1286
+#define _loop1_140_type 1287
+#define _loop0_141_type 1288
+#define _tmp_142_type 1289
static mod_ty file_rule(Parser *p);
static mod_ty interactive_rule(Parser *p);
static mod_ty eval_rule(Parser *p);
+static mod_ty func_type_rule(Parser *p);
static expr_ty fstring_rule(Parser *p);
+static asdl_seq* type_expressions_rule(Parser *p);
static asdl_seq* statements_rule(Parser *p);
static asdl_seq* statement_rule(Parser *p);
static asdl_seq* statement_newline_rule(Parser *p);
@@ -390,18 +401,19 @@ static stmt_ty return_stmt_rule(Parser *p);
static stmt_ty raise_stmt_rule(Parser *p);
static stmt_ty function_def_rule(Parser *p);
static stmt_ty function_def_raw_rule(Parser *p);
+static PyObject* func_type_comment_rule(Parser *p);
static arguments_ty params_rule(Parser *p);
static arguments_ty parameters_rule(Parser *p);
-static asdl_seq* slash_without_default_rule(Parser *p);
+static asdl_seq* slash_no_default_rule(Parser *p);
static SlashWithDefault* slash_with_default_rule(Parser *p);
static StarEtc* star_etc_rule(Parser *p);
-static NameDefaultPair* name_with_optional_default_rule(Parser *p);
-static asdl_seq* names_with_default_rule(Parser *p);
-static NameDefaultPair* name_with_default_rule(Parser *p);
-static asdl_seq* plain_names_rule(Parser *p);
-static arg_ty plain_name_rule(Parser *p);
static arg_ty kwds_rule(Parser *p);
+static arg_ty param_no_default_rule(Parser *p);
+static NameDefaultPair* param_with_default_rule(Parser *p);
+static NameDefaultPair* param_maybe_default_rule(Parser *p);
+static arg_ty param_rule(Parser *p);
static expr_ty annotation_rule(Parser *p);
+static expr_ty default_rule(Parser *p);
static asdl_seq* decorators_rule(Parser *p);
static stmt_ty class_def_rule(Parser *p);
static stmt_ty class_def_raw_rule(Parser *p);
@@ -494,133 +506,134 @@ static void *invalid_assignment_rule(Parser *p);
static void *invalid_block_rule(Parser *p);
static void *invalid_comprehension_rule(Parser *p);
static void *invalid_parameters_rule(Parser *p);
+static void *invalid_double_type_comments_rule(Parser *p);
static asdl_seq *_loop0_1_rule(Parser *p);
-static asdl_seq *_loop1_2_rule(Parser *p);
+static asdl_seq *_loop0_2_rule(Parser *p);
static asdl_seq *_loop0_4_rule(Parser *p);
static asdl_seq *_gather_3_rule(Parser *p);
-static void *_tmp_5_rule(Parser *p);
-static void *_tmp_6_rule(Parser *p);
-static void *_tmp_7_rule(Parser *p);
-static void *_tmp_8_rule(Parser *p);
-static void *_tmp_9_rule(Parser *p);
-static void *_tmp_10_rule(Parser *p);
-static void *_tmp_11_rule(Parser *p);
-static void *_tmp_12_rule(Parser *p);
-static asdl_seq *_loop1_13_rule(Parser *p);
+static asdl_seq *_loop0_6_rule(Parser *p);
+static asdl_seq *_gather_5_rule(Parser *p);
+static asdl_seq *_loop0_8_rule(Parser *p);
+static asdl_seq *_gather_7_rule(Parser *p);
+static asdl_seq *_loop0_10_rule(Parser *p);
+static asdl_seq *_gather_9_rule(Parser *p);
+static asdl_seq *_loop1_11_rule(Parser *p);
+static asdl_seq *_loop0_13_rule(Parser *p);
+static asdl_seq *_gather_12_rule(Parser *p);
static void *_tmp_14_rule(Parser *p);
static void *_tmp_15_rule(Parser *p);
-static asdl_seq *_loop0_17_rule(Parser *p);
-static asdl_seq *_gather_16_rule(Parser *p);
-static asdl_seq *_loop0_19_rule(Parser *p);
-static asdl_seq *_gather_18_rule(Parser *p);
+static void *_tmp_16_rule(Parser *p);
+static void *_tmp_17_rule(Parser *p);
+static void *_tmp_18_rule(Parser *p);
+static void *_tmp_19_rule(Parser *p);
static void *_tmp_20_rule(Parser *p);
-static asdl_seq *_loop0_21_rule(Parser *p);
+static void *_tmp_21_rule(Parser *p);
static asdl_seq *_loop1_22_rule(Parser *p);
-static asdl_seq *_loop0_24_rule(Parser *p);
-static asdl_seq *_gather_23_rule(Parser *p);
-static void *_tmp_25_rule(Parser *p);
-static asdl_seq *_loop0_27_rule(Parser *p);
-static asdl_seq *_gather_26_rule(Parser *p);
-static void *_tmp_28_rule(Parser *p);
+static void *_tmp_23_rule(Parser *p);
+static void *_tmp_24_rule(Parser *p);
+static asdl_seq *_loop0_26_rule(Parser *p);
+static asdl_seq *_gather_25_rule(Parser *p);
+static asdl_seq *_loop0_28_rule(Parser *p);
+static asdl_seq *_gather_27_rule(Parser *p);
+static void *_tmp_29_rule(Parser *p);
static asdl_seq *_loop0_30_rule(Parser *p);
-static asdl_seq *_gather_29_rule(Parser *p);
-static asdl_seq *_loop0_32_rule(Parser *p);
-static asdl_seq *_gather_31_rule(Parser *p);
-static void *_tmp_33_rule(Parser *p);
-static asdl_seq *_loop1_34_rule(Parser *p);
-static void *_tmp_35_rule(Parser *p);
-static void *_tmp_36_rule(Parser *p);
+static asdl_seq *_loop1_31_rule(Parser *p);
+static asdl_seq *_loop0_33_rule(Parser *p);
+static asdl_seq *_gather_32_rule(Parser *p);
+static void *_tmp_34_rule(Parser *p);
+static asdl_seq *_loop0_36_rule(Parser *p);
+static asdl_seq *_gather_35_rule(Parser *p);
static void *_tmp_37_rule(Parser *p);
-static void *_tmp_38_rule(Parser *p);
-static void *_tmp_39_rule(Parser *p);
-static void *_tmp_40_rule(Parser *p);
-static void *_tmp_41_rule(Parser *p);
+static asdl_seq *_loop0_39_rule(Parser *p);
+static asdl_seq *_gather_38_rule(Parser *p);
+static asdl_seq *_loop0_41_rule(Parser *p);
+static asdl_seq *_gather_40_rule(Parser *p);
static void *_tmp_42_rule(Parser *p);
-static void *_tmp_43_rule(Parser *p);
+static asdl_seq *_loop1_43_rule(Parser *p);
static void *_tmp_44_rule(Parser *p);
static void *_tmp_45_rule(Parser *p);
static void *_tmp_46_rule(Parser *p);
-static asdl_seq *_loop0_47_rule(Parser *p);
-static void *_tmp_48_rule(Parser *p);
-static asdl_seq *_loop1_49_rule(Parser *p);
-static void *_tmp_50_rule(Parser *p);
-static void *_tmp_51_rule(Parser *p);
-static asdl_seq *_loop0_53_rule(Parser *p);
-static asdl_seq *_gather_52_rule(Parser *p);
-static asdl_seq *_loop0_55_rule(Parser *p);
-static asdl_seq *_gather_54_rule(Parser *p);
-static void *_tmp_56_rule(Parser *p);
+static void *_tmp_47_rule(Parser *p);
+static asdl_seq *_loop0_48_rule(Parser *p);
+static asdl_seq *_loop0_49_rule(Parser *p);
+static asdl_seq *_loop0_50_rule(Parser *p);
+static asdl_seq *_loop1_51_rule(Parser *p);
+static asdl_seq *_loop0_52_rule(Parser *p);
+static asdl_seq *_loop1_53_rule(Parser *p);
+static asdl_seq *_loop1_54_rule(Parser *p);
+static asdl_seq *_loop1_55_rule(Parser *p);
+static asdl_seq *_loop0_56_rule(Parser *p);
static asdl_seq *_loop1_57_rule(Parser *p);
-static void *_tmp_58_rule(Parser *p);
+static asdl_seq *_loop0_58_rule(Parser *p);
+static asdl_seq *_loop1_59_rule(Parser *p);
static asdl_seq *_loop0_60_rule(Parser *p);
-static asdl_seq *_gather_59_rule(Parser *p);
static asdl_seq *_loop1_61_rule(Parser *p);
-static asdl_seq *_loop0_63_rule(Parser *p);
-static asdl_seq *_gather_62_rule(Parser *p);
-static asdl_seq *_loop1_64_rule(Parser *p);
-static void *_tmp_65_rule(Parser *p);
-static void *_tmp_66_rule(Parser *p);
-static void *_tmp_67_rule(Parser *p);
-static void *_tmp_68_rule(Parser *p);
-static void *_tmp_69_rule(Parser *p);
+static asdl_seq *_loop1_62_rule(Parser *p);
+static void *_tmp_63_rule(Parser *p);
+static asdl_seq *_loop0_65_rule(Parser *p);
+static asdl_seq *_gather_64_rule(Parser *p);
+static asdl_seq *_loop1_66_rule(Parser *p);
+static asdl_seq *_loop0_68_rule(Parser *p);
+static asdl_seq *_gather_67_rule(Parser *p);
+static asdl_seq *_loop1_69_rule(Parser *p);
static void *_tmp_70_rule(Parser *p);
static void *_tmp_71_rule(Parser *p);
static void *_tmp_72_rule(Parser *p);
static void *_tmp_73_rule(Parser *p);
-static asdl_seq *_loop0_74_rule(Parser *p);
+static void *_tmp_74_rule(Parser *p);
static void *_tmp_75_rule(Parser *p);
-static asdl_seq *_loop1_76_rule(Parser *p);
+static void *_tmp_76_rule(Parser *p);
static void *_tmp_77_rule(Parser *p);
static void *_tmp_78_rule(Parser *p);
-static asdl_seq *_loop0_80_rule(Parser *p);
-static asdl_seq *_gather_79_rule(Parser *p);
-static asdl_seq *_loop0_82_rule(Parser *p);
-static asdl_seq *_gather_81_rule(Parser *p);
-static asdl_seq *_loop1_83_rule(Parser *p);
-static asdl_seq *_loop1_84_rule(Parser *p);
-static asdl_seq *_loop1_85_rule(Parser *p);
-static void *_tmp_86_rule(Parser *p);
-static asdl_seq *_loop0_88_rule(Parser *p);
-static asdl_seq *_gather_87_rule(Parser *p);
-static void *_tmp_89_rule(Parser *p);
-static void *_tmp_90_rule(Parser *p);
+static asdl_seq *_loop0_79_rule(Parser *p);
+static void *_tmp_80_rule(Parser *p);
+static asdl_seq *_loop1_81_rule(Parser *p);
+static void *_tmp_82_rule(Parser *p);
+static void *_tmp_83_rule(Parser *p);
+static asdl_seq *_loop0_85_rule(Parser *p);
+static asdl_seq *_gather_84_rule(Parser *p);
+static asdl_seq *_loop0_87_rule(Parser *p);
+static asdl_seq *_gather_86_rule(Parser *p);
+static asdl_seq *_loop1_88_rule(Parser *p);
+static asdl_seq *_loop1_89_rule(Parser *p);
+static asdl_seq *_loop1_90_rule(Parser *p);
static void *_tmp_91_rule(Parser *p);
-static void *_tmp_92_rule(Parser *p);
-static asdl_seq *_loop1_93_rule(Parser *p);
+static asdl_seq *_loop0_93_rule(Parser *p);
+static asdl_seq *_gather_92_rule(Parser *p);
static void *_tmp_94_rule(Parser *p);
static void *_tmp_95_rule(Parser *p);
-static asdl_seq *_loop0_97_rule(Parser *p);
-static asdl_seq *_gather_96_rule(Parser *p);
+static void *_tmp_96_rule(Parser *p);
+static void *_tmp_97_rule(Parser *p);
static asdl_seq *_loop1_98_rule(Parser *p);
static void *_tmp_99_rule(Parser *p);
static void *_tmp_100_rule(Parser *p);
static asdl_seq *_loop0_102_rule(Parser *p);
static asdl_seq *_gather_101_rule(Parser *p);
-static asdl_seq *_loop0_104_rule(Parser *p);
-static asdl_seq *_gather_103_rule(Parser *p);
-static asdl_seq *_loop0_106_rule(Parser *p);
-static asdl_seq *_gather_105_rule(Parser *p);
-static asdl_seq *_loop0_108_rule(Parser *p);
-static asdl_seq *_gather_107_rule(Parser *p);
+static asdl_seq *_loop1_103_rule(Parser *p);
+static void *_tmp_104_rule(Parser *p);
+static void *_tmp_105_rule(Parser *p);
+static asdl_seq *_loop0_107_rule(Parser *p);
+static asdl_seq *_gather_106_rule(Parser *p);
static asdl_seq *_loop0_109_rule(Parser *p);
+static asdl_seq *_gather_108_rule(Parser *p);
static asdl_seq *_loop0_111_rule(Parser *p);
static asdl_seq *_gather_110_rule(Parser *p);
-static void *_tmp_112_rule(Parser *p);
+static asdl_seq *_loop0_113_rule(Parser *p);
+static asdl_seq *_gather_112_rule(Parser *p);
static asdl_seq *_loop0_114_rule(Parser *p);
-static asdl_seq *_gather_113_rule(Parser *p);
static asdl_seq *_loop0_116_rule(Parser *p);
static asdl_seq *_gather_115_rule(Parser *p);
static void *_tmp_117_rule(Parser *p);
-static void *_tmp_118_rule(Parser *p);
-static void *_tmp_119_rule(Parser *p);
-static void *_tmp_120_rule(Parser *p);
-static void *_tmp_121_rule(Parser *p);
+static asdl_seq *_loop0_119_rule(Parser *p);
+static asdl_seq *_gather_118_rule(Parser *p);
+static asdl_seq *_loop0_121_rule(Parser *p);
+static asdl_seq *_gather_120_rule(Parser *p);
static void *_tmp_122_rule(Parser *p);
static void *_tmp_123_rule(Parser *p);
static void *_tmp_124_rule(Parser *p);
static void *_tmp_125_rule(Parser *p);
static void *_tmp_126_rule(Parser *p);
-static void *_tmp_127_rule(Parser *p);
+static asdl_seq *_loop0_127_rule(Parser *p);
static void *_tmp_128_rule(Parser *p);
static void *_tmp_129_rule(Parser *p);
static void *_tmp_130_rule(Parser *p);
@@ -629,8 +642,13 @@ static void *_tmp_132_rule(Parser *p);
static void *_tmp_133_rule(Parser *p);
static void *_tmp_134_rule(Parser *p);
static void *_tmp_135_rule(Parser *p);
-static asdl_seq *_loop0_136_rule(Parser *p);
+static void *_tmp_136_rule(Parser *p);
static void *_tmp_137_rule(Parser *p);
+static void *_tmp_138_rule(Parser *p);
+static void *_tmp_139_rule(Parser *p);
+static asdl_seq *_loop1_140_rule(Parser *p);
+static asdl_seq *_loop0_141_rule(Parser *p);
+static void *_tmp_142_rule(Parser *p);
// file: statements? $
@@ -651,7 +669,7 @@ file_rule(Parser *p)
(endmarker_var = _PyPegen_expect_token(p, ENDMARKER))
)
{
- res = Module ( a , NULL , p -> arena );
+ res = _PyPegen_make_module ( p , a );
if (res == NULL && PyErr_Occurred()) {
p->error_indicator = 1;
return NULL;
@@ -729,6 +747,53 @@ eval_rule(Parser *p)
return res;
}
+// func_type: '(' type_expressions? ')' '->' expression NEWLINE* $
+static mod_ty
+func_type_rule(Parser *p)
+{
+ if (p->error_indicator) {
+ return NULL;
+ }
+ mod_ty res = NULL;
+ int mark = p->mark;
+ { // '(' type_expressions? ')' '->' expression NEWLINE* $
+ asdl_seq * _loop0_2_var;
+ void *a;
+ expr_ty b;
+ void *endmarker_var;
+ void *literal;
+ void *literal_1;
+ void *literal_2;
+ if (
+ (literal = _PyPegen_expect_token(p, 7))
+ &&
+ (a = type_expressions_rule(p), 1)
+ &&
+ (literal_1 = _PyPegen_expect_token(p, 8))
+ &&
+ (literal_2 = _PyPegen_expect_token(p, 51))
+ &&
+ (b = expression_rule(p))
+ &&
+ (_loop0_2_var = _loop0_2_rule(p))
+ &&
+ (endmarker_var = _PyPegen_expect_token(p, ENDMARKER))
+ )
+ {
+ res = FunctionType ( a , b , p -> arena );
+ if (res == NULL && PyErr_Occurred()) {
+ p->error_indicator = 1;
+ return NULL;
+ }
+ goto done;
+ }
+ p->mark = mark;
+ }
+ res = NULL;
+ done:
+ return res;
+}
+
// fstring: star_expressions
static expr_ty
fstring_rule(Parser *p)
@@ -754,6 +819,116 @@ fstring_rule(Parser *p)
return res;
}
+// type_expressions:
+// | ','.expression+ ',' '*' expression ',' '**' expression
+// | ','.expression+ ',' '*' expression
+// | ','.expression+ ',' '**' expression
+// | ','.expression+
+static asdl_seq*
+type_expressions_rule(Parser *p)
+{
+ if (p->error_indicator) {
+ return NULL;
+ }
+ asdl_seq* res = NULL;
+ int mark = p->mark;
+ { // ','.expression+ ',' '*' expression ',' '**' expression
+ asdl_seq * a;
+ expr_ty b;
+ expr_ty c;
+ void *literal;
+ void *literal_1;
+ void *literal_2;
+ void *literal_3;
+ if (
+ (a = _gather_3_rule(p))
+ &&
+ (literal = _PyPegen_expect_token(p, 12))
+ &&
+ (literal_1 = _PyPegen_expect_token(p, 16))
+ &&
+ (b = expression_rule(p))
+ &&
+ (literal_2 = _PyPegen_expect_token(p, 12))
+ &&
+ (literal_3 = _PyPegen_expect_token(p, 35))
+ &&
+ (c = expression_rule(p))
+ )
+ {
+ res = _PyPegen_seq_append_to_end ( p , CHECK ( _PyPegen_seq_append_to_end ( p , a , b ) ) , c );
+ if (res == NULL && PyErr_Occurred()) {
+ p->error_indicator = 1;
+ return NULL;
+ }
+ goto done;
+ }
+ p->mark = mark;
+ }
+ { // ','.expression+ ',' '*' expression
+ asdl_seq * a;
+ expr_ty b;
+ void *literal;
+ void *literal_1;
+ if (
+ (a = _gather_5_rule(p))
+ &&
+ (literal = _PyPegen_expect_token(p, 12))
+ &&
+ (literal_1 = _PyPegen_expect_token(p, 16))
+ &&
+ (b = expression_rule(p))
+ )
+ {
+ res = _PyPegen_seq_append_to_end ( p , a , b );
+ if (res == NULL && PyErr_Occurred()) {
+ p->error_indicator = 1;
+ return NULL;
+ }
+ goto done;
+ }
+ p->mark = mark;
+ }
+ { // ','.expression+ ',' '**' expression
+ asdl_seq * a;
+ expr_ty b;
+ void *literal;
+ void *literal_1;
+ if (
+ (a = _gather_7_rule(p))
+ &&
+ (literal = _PyPegen_expect_token(p, 12))
+ &&
+ (literal_1 = _PyPegen_expect_token(p, 35))
+ &&
+ (b = expression_rule(p))
+ )
+ {
+ res = _PyPegen_seq_append_to_end ( p , a , b );
+ if (res == NULL && PyErr_Occurred()) {
+ p->error_indicator = 1;
+ return NULL;
+ }
+ goto done;
+ }
+ p->mark = mark;
+ }
+ { // ','.expression+
+ asdl_seq * _gather_9_var;
+ if (
+ (_gather_9_var = _gather_9_rule(p))
+ )
+ {
+ res = _gather_9_var;
+ goto done;
+ }
+ p->mark = mark;
+ }
+ res = NULL;
+ done:
+ return res;
+}
+
// statements: statement+
static asdl_seq*
statements_rule(Parser *p)
@@ -766,7 +941,7 @@ statements_rule(Parser *p)
{ // statement+
asdl_seq * a;
if (
- (a = _loop1_2_rule(p))
+ (a = _loop1_11_rule(p))
)
{
res = _PyPegen_seq_flatten ( p , a );
@@ -947,7 +1122,7 @@ simple_stmt_rule(Parser *p)
void *opt_var;
UNUSED(opt_var); // Silence compiler warnings
if (
- (a = _gather_3_rule(p))
+ (a = _gather_12_rule(p))
&&
(opt_var = _PyPegen_expect_token(p, 13), 1)
&&
@@ -1050,7 +1225,7 @@ small_stmt_rule(Parser *p)
{ // &('import' | 'from') import_stmt
stmt_ty import_stmt_var;
if (
- _PyPegen_lookahead(1, _tmp_5_rule, p)
+ _PyPegen_lookahead(1, _tmp_14_rule, p)
&&
(import_stmt_var = import_stmt_rule(p))
)
@@ -1232,7 +1407,7 @@ compound_stmt_rule(Parser *p)
{ // &('def' | '@' | ASYNC) function_def
stmt_ty function_def_var;
if (
- _PyPegen_lookahead(1, _tmp_6_rule, p)
+ _PyPegen_lookahead(1, _tmp_15_rule, p)
&&
(function_def_var = function_def_rule(p))
)
@@ -1258,7 +1433,7 @@ compound_stmt_rule(Parser *p)
{ // &('class' | '@') class_def
stmt_ty class_def_var;
if (
- _PyPegen_lookahead(1, _tmp_7_rule, p)
+ _PyPegen_lookahead(1, _tmp_16_rule, p)
&&
(class_def_var = class_def_rule(p))
)
@@ -1271,7 +1446,7 @@ compound_stmt_rule(Parser *p)
{ // &('with' | ASYNC) with_stmt
stmt_ty with_stmt_var;
if (
- _PyPegen_lookahead(1, _tmp_8_rule, p)
+ _PyPegen_lookahead(1, _tmp_17_rule, p)
&&
(with_stmt_var = with_stmt_rule(p))
)
@@ -1284,7 +1459,7 @@ compound_stmt_rule(Parser *p)
{ // &('for' | ASYNC) for_stmt
stmt_ty for_stmt_var;
if (
- _PyPegen_lookahead(1, _tmp_9_rule, p)
+ _PyPegen_lookahead(1, _tmp_18_rule, p)
&&
(for_stmt_var = for_stmt_rule(p))
)
@@ -1328,7 +1503,7 @@ compound_stmt_rule(Parser *p)
// assignment:
// | NAME ':' expression ['=' annotated_rhs]
// | ('(' inside_paren_ann_assign_target ')' | ann_assign_subscript_attribute_target) ':' expression ['=' annotated_rhs]
-// | ((star_targets '='))+ (yield_expr | star_expressions)
+// | ((star_targets '='))+ (yield_expr | star_expressions) TYPE_COMMENT?
// | target augassign (yield_expr | star_expressions)
// | invalid_assignment
static void *
@@ -1359,7 +1534,7 @@ assignment_rule(Parser *p)
&&
(b = expression_rule(p))
&&
- (c = _tmp_10_rule(p), 1)
+ (c = _tmp_19_rule(p), 1)
)
{
Token *token = _PyPegen_get_last_nonnwhitespace_token(p);
@@ -1385,13 +1560,13 @@ assignment_rule(Parser *p)
void *c;
void *literal;
if (
- (a = _tmp_11_rule(p))
+ (a = _tmp_20_rule(p))
&&
(literal = _PyPegen_expect_token(p, 11))
&&
(b = expression_rule(p))
&&
- (c = _tmp_12_rule(p), 1)
+ (c = _tmp_21_rule(p), 1)
)
{
Token *token = _PyPegen_get_last_nonnwhitespace_token(p);
@@ -1411,13 +1586,16 @@ assignment_rule(Parser *p)
}
p->mark = mark;
}
- { // ((star_targets '='))+ (yield_expr | star_expressions)
+ { // ((star_targets '='))+ (yield_expr | star_expressions) TYPE_COMMENT?
asdl_seq * a;
void *b;
+ void *tc;
if (
- (a = _loop1_13_rule(p))
+ (a = _loop1_22_rule(p))
+ &&
+ (b = _tmp_23_rule(p))
&&
- (b = _tmp_14_rule(p))
+ (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1)
)
{
Token *token = _PyPegen_get_last_nonnwhitespace_token(p);
@@ -1428,7 +1606,7 @@ assignment_rule(Parser *p)
UNUSED(end_lineno); // Only used by EXTRA macro
int end_col_offset = token->end_col_offset;
UNUSED(end_col_offset); // Only used by EXTRA macro
- res = _Py_Assign ( a , b , NULL , EXTRA );
+ res = _Py_Assign ( a , b , NEW_TYPE_COMMENT ( p , tc ) , EXTRA );
if (res == NULL && PyErr_Occurred()) {
p->error_indicator = 1;
return NULL;
@@ -1446,7 +1624,7 @@ assignment_rule(Parser *p)
&&
(b = augassign_rule(p))
&&
- (c = _tmp_15_rule(p))
+ (c = _tmp_24_rule(p))
)
{
Token *token = _PyPegen_get_last_nonnwhitespace_token(p);
@@ -1727,7 +1905,7 @@ global_stmt_rule(Parser *p)
if (
(keyword = _PyPegen_expect_token(p, 508))
&&
- (a = _gather_16_rule(p))
+ (a = _gather_25_rule(p))
)
{
Token *token = _PyPegen_get_last_nonnwhitespace_token(p);
@@ -1775,7 +1953,7 @@ nonlocal_stmt_rule(Parser *p)
if (
(keyword = _PyPegen_expect_token(p, 509))
&&
- (a = _gather_18_rule(p))
+ (a = _gather_27_rule(p))
)
{
Token *token = _PyPegen_get_last_nonnwhitespace_token(p);
@@ -1871,7 +2049,7 @@ assert_stmt_rule(Parser *p)
&&
(a = expression_rule(p))
&&
- (b = _tmp_20_rule(p), 1)
+ (b = _tmp_29_rule(p), 1)
)
{
Token *token = _PyPegen_get_last_nonnwhitespace_token(p);
@@ -2056,7 +2234,7 @@ import_from_rule(Parser *p)
if (
(keyword = _PyPegen_expect_token(p, 514))
&&
- (a = _loop0_21_rule(p))
+ (a = _loop0_30_rule(p))
&&
(b = dotted_name_rule(p))
&&
@@ -2090,7 +2268,7 @@ import_from_rule(Parser *p)
if (
(keyword = _PyPegen_expect_token(p, 514))
&&
- (a = _loop1_22_rule(p))
+ (a = _loop1_31_rule(p))
&&
(keyword_1 = _PyPegen_expect_token(p, 513))
&&
@@ -2196,7 +2374,7 @@ import_from_as_names_rule(Parser *p)
{ // ','.import_from_as_name+
asdl_seq * a;
if (
- (a = _gather_23_rule(p))
+ (a = _gather_32_rule(p))
)
{
res = a;
@@ -2228,7 +2406,7 @@ import_from_as_name_rule(Parser *p)
if (
(a = _PyPegen_name_token(p))
&&
- (b = _tmp_25_rule(p), 1)
+ (b = _tmp_34_rule(p), 1)
)
{
res = _Py_alias ( a -> v . Name . id , ( b ) ? ( ( expr_ty ) b ) -> v . Name . id : NULL , p -> arena );
@@ -2257,7 +2435,7 @@ dotted_as_names_rule(Parser *p)
{ // ','.dotted_as_name+
asdl_seq * a;
if (
- (a = _gather_26_rule(p))
+ (a = _gather_35_rule(p))
)
{
res = a;
@@ -2289,7 +2467,7 @@ dotted_as_name_rule(Parser *p)
if (
(a = dotted_name_rule(p))
&&
- (b = _tmp_28_rule(p), 1)
+ (b = _tmp_37_rule(p), 1)
)
{
res = _Py_alias ( a -> v . Name . id , ( b ) ? ( ( expr_ty ) b ) -> v . Name . id : NULL , p -> arena );
@@ -2657,7 +2835,8 @@ while_stmt_rule(Parser *p)
return res;
}
-// for_stmt: ASYNC? 'for' star_targets 'in' star_expressions ':' block else_block?
+// for_stmt:
+// | ASYNC? 'for' star_targets 'in' star_expressions ':' TYPE_COMMENT? block else_block?
static stmt_ty
for_stmt_rule(Parser *p)
{
@@ -2674,7 +2853,7 @@ for_stmt_rule(Parser *p)
UNUSED(start_lineno); // Only used by EXTRA macro
int start_col_offset = p->tokens[mark]->col_offset;
UNUSED(start_col_offset); // Only used by EXTRA macro
- { // ASYNC? 'for' star_targets 'in' star_expressions ':' block else_block?
+ { // ASYNC? 'for' star_targets 'in' star_expressions ':' TYPE_COMMENT? block else_block?
asdl_seq* b;
void *el;
expr_ty ex;
@@ -2683,6 +2862,7 @@ for_stmt_rule(Parser *p)
void *keyword_1;
void *literal;
expr_ty t;
+ void *tc;
if (
(is_async = _PyPegen_expect_token(p, ASYNC), 1)
&&
@@ -2696,6 +2876,8 @@ for_stmt_rule(Parser *p)
&&
(literal = _PyPegen_expect_token(p, 11))
&&
+ (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1)
+ &&
(b = block_rule(p))
&&
(el = else_block_rule(p), 1)
@@ -2709,7 +2891,7 @@ for_stmt_rule(Parser *p)
UNUSED(end_lineno); // Only used by EXTRA macro
int end_col_offset = token->end_col_offset;
UNUSED(end_col_offset); // Only used by EXTRA macro
- res = ( is_async ? _Py_AsyncFor : _Py_For ) ( t , ex , b , el , NULL , EXTRA );
+ res = ( is_async ? _Py_AsyncFor : _Py_For ) ( t , ex , b , el , NEW_TYPE_COMMENT ( p , tc ) , EXTRA );
if (res == NULL && PyErr_Occurred()) {
p->error_indicator = 1;
return NULL;
@@ -2725,7 +2907,7 @@ for_stmt_rule(Parser *p)
// with_stmt:
// | ASYNC? 'with' '(' ','.with_item+ ')' ':' block
-// | ASYNC? 'with' ','.with_item+ ':' block
+// | ASYNC? 'with' ','.with_item+ ':' TYPE_COMMENT? block
static stmt_ty
with_stmt_rule(Parser *p)
{
@@ -2757,7 +2939,7 @@ with_stmt_rule(Parser *p)
&&
(literal = _PyPegen_expect_token(p, 7))
&&
- (a = _gather_29_rule(p))
+ (a = _gather_38_rule(p))
&&
(literal_1 = _PyPegen_expect_token(p, 8))
&&
@@ -2783,21 +2965,24 @@ with_stmt_rule(Parser *p)
}
p->mark = mark;
}
- { // ASYNC? 'with' ','.with_item+ ':' block
+ { // ASYNC? 'with' ','.with_item+ ':' TYPE_COMMENT? block
asdl_seq * a;
asdl_seq* b;
void *is_async;
void *keyword;
void *literal;
+ void *tc;
if (
(is_async = _PyPegen_expect_token(p, ASYNC), 1)
&&
(keyword = _PyPegen_expect_token(p, 519))
&&
- (a = _gather_31_rule(p))
+ (a = _gather_40_rule(p))
&&
(literal = _PyPegen_expect_token(p, 11))
&&
+ (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1)
+ &&
(b = block_rule(p))
)
{
@@ -2809,7 +2994,7 @@ with_stmt_rule(Parser *p)
UNUSED(end_lineno); // Only used by EXTRA macro
int end_col_offset = token->end_col_offset;
UNUSED(end_col_offset); // Only used by EXTRA macro
- res = ( is_async ? _Py_AsyncWith : _Py_With ) ( a , b , NULL , EXTRA );
+ res = ( is_async ? _Py_AsyncWith : _Py_With ) ( a , b , NEW_TYPE_COMMENT ( p , tc ) , EXTRA );
if (res == NULL && PyErr_Occurred()) {
p->error_indicator = 1;
return NULL;
@@ -2838,7 +3023,7 @@ with_item_rule(Parser *p)
if (
(e = expression_rule(p))
&&
- (o = _tmp_33_rule(p), 1)
+ (o = _tmp_42_rule(p), 1)
)
{
res = _Py_withitem ( e , o , p -> arena );
@@ -2920,7 +3105,7 @@ try_stmt_rule(Parser *p)
&&
(b = block_rule(p))
&&
- (ex = _loop1_34_rule(p))
+ (ex = _loop1_43_rule(p))
&&
(el = else_block_rule(p), 1)
&&
@@ -2977,7 +3162,7 @@ except_block_rule(Parser *p)
&&
(e = expression_rule(p))
&&
- (t = _tmp_35_rule(p), 1)
+ (t = _tmp_44_rule(p), 1)
&&
(literal = _PyPegen_expect_token(p, 11))
&&
@@ -3144,7 +3329,7 @@ raise_stmt_rule(Parser *p)
&&
(a = expression_rule(p))
&&
- (b = _tmp_36_rule(p), 1)
+ (b = _tmp_45_rule(p), 1)
)
{
Token *token = _PyPegen_get_last_nonnwhitespace_token(p);
@@ -3235,7 +3420,8 @@ function_def_rule(Parser *p)
return res;
}
-// function_def_raw: ASYNC? 'def' NAME '(' params? ')' ['->' annotation] ':' block
+// function_def_raw:
+// | ASYNC? 'def' NAME '(' params? ')' ['->' expression] ':' func_type_comment? block
static stmt_ty
function_def_raw_rule(Parser *p)
{
@@ -3252,7 +3438,7 @@ function_def_raw_rule(Parser *p)
UNUSED(start_lineno); // Only used by EXTRA macro
int start_col_offset = p->tokens[mark]->col_offset;
UNUSED(start_col_offset); // Only used by EXTRA macro
- { // ASYNC? 'def' NAME '(' params? ')' ['->' annotation] ':' block
+ { // ASYNC? 'def' NAME '(' params? ')' ['->' expression] ':' func_type_comment? block
void *a;
asdl_seq* b;
void *is_async;
@@ -3262,6 +3448,7 @@ function_def_raw_rule(Parser *p)
void *literal_2;
expr_ty n;
void *params;
+ void *tc;
if (
(is_async = _PyPegen_expect_token(p, ASYNC), 1)
&&
@@ -3275,10 +3462,12 @@ function_def_raw_rule(Parser *p)
&&
(literal_1 = _PyPegen_expect_token(p, 8))
&&
- (a = _tmp_37_rule(p), 1)
+ (a = _tmp_46_rule(p), 1)
&&
(literal_2 = _PyPegen_expect_token(p, 11))
&&
+ (tc = func_type_comment_rule(p), 1)
+ &&
(b = block_rule(p))
)
{
@@ -3290,7 +3479,44 @@ function_def_raw_rule(Parser *p)
UNUSED(end_lineno); // Only used by EXTRA macro
int end_col_offset = token->end_col_offset;
UNUSED(end_col_offset); // Only used by EXTRA macro
- res = ( is_async ? _Py_AsyncFunctionDef : _Py_FunctionDef ) ( n -> v . Name . id , ( params ) ? params : CHECK ( _PyPegen_empty_arguments ( p ) ) , b , NULL , a , NULL , EXTRA );
+ res = ( is_async ? _Py_AsyncFunctionDef : _Py_FunctionDef ) ( n -> v . Name . id , ( params ) ? params : CHECK ( _PyPegen_empty_arguments ( p ) ) , b , NULL , a , NEW_TYPE_COMMENT ( p , tc ) , EXTRA );
+ if (res == NULL && PyErr_Occurred()) {
+ p->error_indicator = 1;
+ return NULL;
+ }
+ goto done;
+ }
+ p->mark = mark;
+ }
+ res = NULL;
+ done:
+ return res;
+}
+
+// func_type_comment:
+// | NEWLINE TYPE_COMMENT &(NEWLINE INDENT)
+// | invalid_double_type_comments
+// | TYPE_COMMENT
+static PyObject*
+func_type_comment_rule(Parser *p)
+{
+ if (p->error_indicator) {
+ return NULL;
+ }
+ PyObject* res = NULL;
+ int mark = p->mark;
+ { // NEWLINE TYPE_COMMENT &(NEWLINE INDENT)
+ void *newline_var;
+ void *t;
+ if (
+ (newline_var = _PyPegen_expect_token(p, NEWLINE))
+ &&
+ (t = _PyPegen_expect_token(p, TYPE_COMMENT))
+ &&
+ _PyPegen_lookahead(1, _tmp_47_rule, p)
+ )
+ {
+ res = t;
if (res == NULL && PyErr_Occurred()) {
p->error_indicator = 1;
return NULL;
@@ -3299,6 +3525,28 @@ function_def_raw_rule(Parser *p)
}
p->mark = mark;
}
+ { // invalid_double_type_comments
+ void *invalid_double_type_comments_var;
+ if (
+ (invalid_double_type_comments_var = invalid_double_type_comments_rule(p))
+ )
+ {
+ res = invalid_double_type_comments_var;
+ goto done;
+ }
+ p->mark = mark;
+ }
+ { // TYPE_COMMENT
+ void *type_comment_var;
+ if (
+ (type_comment_var = _PyPegen_expect_token(p, TYPE_COMMENT))
+ )
+ {
+ res = type_comment_var;
+ goto done;
+ }
+ p->mark = mark;
+ }
res = NULL;
done:
return res;
@@ -3341,10 +3589,10 @@ params_rule(Parser *p)
}
// parameters:
-// | slash_without_default [',' plain_names] [',' names_with_default] [',' star_etc?]
-// | slash_with_default [',' names_with_default] [',' star_etc?]
-// | plain_names [',' names_with_default] [',' star_etc?]
-// | names_with_default [',' star_etc?]
+// | slash_no_default param_no_default* param_with_default* star_etc?
+// | slash_with_default param_with_default* star_etc?
+// | param_no_default+ param_with_default* star_etc?
+// | param_with_default+ star_etc?
// | star_etc
static arguments_ty
parameters_rule(Parser *p)
@@ -3354,19 +3602,19 @@ parameters_rule(Parser *p)
}
arguments_ty res = NULL;
int mark = p->mark;
- { // slash_without_default [',' plain_names] [',' names_with_default] [',' star_etc?]
+ { // slash_no_default param_no_default* param_with_default* star_etc?
asdl_seq* a;
- void *b;
- void *c;
+ asdl_seq * b;
+ asdl_seq * c;
void *d;
if (
- (a = slash_without_default_rule(p))
+ (a = slash_no_default_rule(p))
&&
- (b = _tmp_38_rule(p), 1)
+ (b = _loop0_48_rule(p))
&&
- (c = _tmp_39_rule(p), 1)
+ (c = _loop0_49_rule(p))
&&
- (d = _tmp_40_rule(p), 1)
+ (d = star_etc_rule(p), 1)
)
{
res = _PyPegen_make_arguments ( p , a , NULL , b , c , d );
@@ -3378,16 +3626,16 @@ parameters_rule(Parser *p)
}
p->mark = mark;
}
- { // slash_with_default [',' names_with_default] [',' star_etc?]
+ { // slash_with_default param_with_default* star_etc?
SlashWithDefault* a;
- void *b;
+ asdl_seq * b;
void *c;
if (
(a = slash_with_default_rule(p))
&&
- (b = _tmp_41_rule(p), 1)
+ (b = _loop0_50_rule(p))
&&
- (c = _tmp_42_rule(p), 1)
+ (c = star_etc_rule(p), 1)
)
{
res = _PyPegen_make_arguments ( p , NULL , a , NULL , b , c );
@@ -3399,16 +3647,16 @@ parameters_rule(Parser *p)
}
p->mark = mark;
}
- { // plain_names [',' names_with_default] [',' star_etc?]
- asdl_seq* a;
- void *b;
+ { // param_no_default+ param_with_default* star_etc?
+ asdl_seq * a;
+ asdl_seq * b;
void *c;
if (
- (a = plain_names_rule(p))
+ (a = _loop1_51_rule(p))
&&
- (b = _tmp_43_rule(p), 1)
+ (b = _loop0_52_rule(p))
&&
- (c = _tmp_44_rule(p), 1)
+ (c = star_etc_rule(p), 1)
)
{
res = _PyPegen_make_arguments ( p , NULL , NULL , a , b , c );
@@ -3420,13 +3668,13 @@ parameters_rule(Parser *p)
}
p->mark = mark;
}
- { // names_with_default [',' star_etc?]
- asdl_seq* a;
+ { // param_with_default+ star_etc?
+ asdl_seq * a;
void *b;
if (
- (a = names_with_default_rule(p))
+ (a = _loop1_53_rule(p))
&&
- (b = _tmp_45_rule(p), 1)
+ (b = star_etc_rule(p), 1)
)
{
res = _PyPegen_make_arguments ( p , NULL , NULL , NULL , a , b );
@@ -3458,25 +3706,45 @@ parameters_rule(Parser *p)
return res;
}
-// slash_without_default: plain_names ',' '/'
+// slash_no_default: param_no_default+ '/' ',' | param_no_default+ '/' &')'
static asdl_seq*
-slash_without_default_rule(Parser *p)
+slash_no_default_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
asdl_seq* res = NULL;
int mark = p->mark;
- { // plain_names ',' '/'
- asdl_seq* a;
+ { // param_no_default+ '/' ','
+ asdl_seq * a;
void *literal;
void *literal_1;
if (
- (a = plain_names_rule(p))
+ (a = _loop1_54_rule(p))
&&
- (literal = _PyPegen_expect_token(p, 12))
+ (literal = _PyPegen_expect_token(p, 17))
&&
- (literal_1 = _PyPegen_expect_token(p, 17))
+ (literal_1 = _PyPegen_expect_token(p, 12))
+ )
+ {
+ res = a;
+ if (res == NULL && PyErr_Occurred()) {
+ p->error_indicator = 1;
+ return NULL;
+ }
+ goto done;
+ }
+ p->mark = mark;
+ }
+ { // param_no_default+ '/' &')'
+ asdl_seq * a;
+ void *literal;
+ if (
+ (a = _loop1_55_rule(p))
+ &&
+ (literal = _PyPegen_expect_token(p, 17))
+ &&
+ _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 8)
)
{
res = a;
@@ -3493,7 +3761,9 @@ slash_without_default_rule(Parser *p)
return res;
}
-// slash_with_default: [plain_names ','] names_with_default ',' '/'
+// slash_with_default:
+// | param_no_default* param_with_default+ '/' ','
+// | param_no_default* param_with_default+ '/' &')'
static SlashWithDefault*
slash_with_default_rule(Parser *p)
{
@@ -3502,19 +3772,42 @@ slash_with_default_rule(Parser *p)
}
SlashWithDefault* res = NULL;
int mark = p->mark;
- { // [plain_names ','] names_with_default ',' '/'
- void *a;
- asdl_seq* b;
+ { // param_no_default* param_with_default+ '/' ','
+ asdl_seq * a;
+ asdl_seq * b;
void *literal;
void *literal_1;
if (
- (a = _tmp_46_rule(p), 1)
+ (a = _loop0_56_rule(p))
&&
- (b = names_with_default_rule(p))
+ (b = _loop1_57_rule(p))
&&
- (literal = _PyPegen_expect_token(p, 12))
+ (literal = _PyPegen_expect_token(p, 17))
&&
- (literal_1 = _PyPegen_expect_token(p, 17))
+ (literal_1 = _PyPegen_expect_token(p, 12))
+ )
+ {
+ res = _PyPegen_slash_with_default ( p , a , b );
+ if (res == NULL && PyErr_Occurred()) {
+ p->error_indicator = 1;
+ return NULL;
+ }
+ goto done;
+ }
+ p->mark = mark;
+ }
+ { // param_no_default* param_with_default+ '/' &')'
+ asdl_seq * a;
+ asdl_seq * b;
+ void *literal;
+ if (
+ (a = _loop0_58_rule(p))
+ &&
+ (b = _loop1_59_rule(p))
+ &&
+ (literal = _PyPegen_expect_token(p, 17))
+ &&
+ _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 8)
)
{
res = _PyPegen_slash_with_default ( p , a , b );
@@ -3532,9 +3825,9 @@ slash_with_default_rule(Parser *p)
}
// star_etc:
-// | '*' plain_name name_with_optional_default* [',' kwds] ','?
-// | '*' name_with_optional_default+ [',' kwds] ','?
-// | kwds ','?
+// | '*' param_no_default param_maybe_default* kwds?
+// | '*' ',' param_maybe_default+ kwds?
+// | kwds
static StarEtc*
star_etc_rule(Parser *p)
{
@@ -3543,23 +3836,19 @@ star_etc_rule(Parser *p)
}
StarEtc* res = NULL;
int mark = p->mark;
- { // '*' plain_name name_with_optional_default* [',' kwds] ','?
+ { // '*' param_no_default param_maybe_default* kwds?
arg_ty a;
asdl_seq * b;
void *c;
void *literal;
- void *opt_var;
- UNUSED(opt_var); // Silence compiler warnings
if (
(literal = _PyPegen_expect_token(p, 16))
&&
- (a = plain_name_rule(p))
+ (a = param_no_default_rule(p))
&&
- (b = _loop0_47_rule(p))
+ (b = _loop0_60_rule(p))
&&
- (c = _tmp_48_rule(p), 1)
- &&
- (opt_var = _PyPegen_expect_token(p, 12), 1)
+ (c = kwds_rule(p), 1)
)
{
res = _PyPegen_star_etc ( p , a , b , c );
@@ -3571,20 +3860,19 @@ star_etc_rule(Parser *p)
}
p->mark = mark;
}
- { // '*' name_with_optional_default+ [',' kwds] ','?
+ { // '*' ',' param_maybe_default+ kwds?
asdl_seq * b;
void *c;
void *literal;
- void *opt_var;
- UNUSED(opt_var); // Silence compiler warnings
+ void *literal_1;
if (
(literal = _PyPegen_expect_token(p, 16))
&&
- (b = _loop1_49_rule(p))
+ (literal_1 = _PyPegen_expect_token(p, 12))
&&
- (c = _tmp_50_rule(p), 1)
+ (b = _loop1_61_rule(p))
&&
- (opt_var = _PyPegen_expect_token(p, 12), 1)
+ (c = kwds_rule(p), 1)
)
{
res = _PyPegen_star_etc ( p , NULL , b , c );
@@ -3596,14 +3884,10 @@ star_etc_rule(Parser *p)
}
p->mark = mark;
}
- { // kwds ','?
+ { // kwds
arg_ty a;
- void *opt_var;
- UNUSED(opt_var); // Silence compiler warnings
if (
(a = kwds_rule(p))
- &&
- (opt_var = _PyPegen_expect_token(p, 12), 1)
)
{
res = _PyPegen_star_etc ( p , NULL , NULL , a );
@@ -3620,28 +3904,25 @@ star_etc_rule(Parser *p)
return res;
}
-// name_with_optional_default: ',' plain_name ['=' expression]
-static NameDefaultPair*
-name_with_optional_default_rule(Parser *p)
+// kwds: '**' param_no_default
+static arg_ty
+kwds_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
- NameDefaultPair* res = NULL;
+ arg_ty res = NULL;
int mark = p->mark;
- { // ',' plain_name ['=' expression]
+ { // '**' param_no_default
arg_ty a;
- void *b;
void *literal;
if (
- (literal = _PyPegen_expect_token(p, 12))
- &&
- (a = plain_name_rule(p))
+ (literal = _PyPegen_expect_token(p, 35))
&&
- (b = _tmp_51_rule(p), 1)
+ (a = param_no_default_rule(p))
)
{
- res = _PyPegen_name_default_pair ( p , a , b );
+ res = a;
if (res == NULL && PyErr_Occurred()) {
p->error_indicator = 1;
return NULL;
@@ -3655,22 +3936,48 @@ name_with_optional_default_rule(Parser *p)
return res;
}
-// names_with_default: ','.name_with_default+
-static asdl_seq*
-names_with_default_rule(Parser *p)
+// param_no_default: param ',' TYPE_COMMENT? | param TYPE_COMMENT? &')'
+static arg_ty
+param_no_default_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
- asdl_seq* res = NULL;
+ arg_ty res = NULL;
int mark = p->mark;
- { // ','.name_with_default+
- asdl_seq * a;
+ { // param ',' TYPE_COMMENT?
+ arg_ty a;
+ void *literal;
+ void *tc;
if (
- (a = _gather_52_rule(p))
+ (a = param_rule(p))
+ &&
+ (literal = _PyPegen_expect_token(p, 12))
+ &&
+ (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1)
)
{
- res = a;
+ res = _PyPegen_add_type_comment_to_arg ( p , a , tc );
+ if (res == NULL && PyErr_Occurred()) {
+ p->error_indicator = 1;
+ return NULL;
+ }
+ goto done;
+ }
+ p->mark = mark;
+ }
+ { // param TYPE_COMMENT? &')'
+ arg_ty a;
+ void *tc;
+ if (
+ (a = param_rule(p))
+ &&
+ (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1)
+ &&
+ _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 8)
+ )
+ {
+ res = _PyPegen_add_type_comment_to_arg ( p , a , tc );
if (res == NULL && PyErr_Occurred()) {
p->error_indicator = 1;
return NULL;
@@ -3684,28 +3991,54 @@ names_with_default_rule(Parser *p)
return res;
}
-// name_with_default: plain_name '=' expression
+// param_with_default: param default ',' TYPE_COMMENT? | param default TYPE_COMMENT? &')'
static NameDefaultPair*
-name_with_default_rule(Parser *p)
+param_with_default_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
NameDefaultPair* res = NULL;
int mark = p->mark;
- { // plain_name '=' expression
- expr_ty e;
+ { // param default ',' TYPE_COMMENT?
+ arg_ty a;
+ expr_ty c;
void *literal;
- arg_ty n;
+ void *tc;
if (
- (n = plain_name_rule(p))
+ (a = param_rule(p))
&&
- (literal = _PyPegen_expect_token(p, 22))
+ (c = default_rule(p))
&&
- (e = expression_rule(p))
+ (literal = _PyPegen_expect_token(p, 12))
+ &&
+ (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1)
+ )
+ {
+ res = _PyPegen_name_default_pair ( p , a , c , tc );
+ if (res == NULL && PyErr_Occurred()) {
+ p->error_indicator = 1;
+ return NULL;
+ }
+ goto done;
+ }
+ p->mark = mark;
+ }
+ { // param default TYPE_COMMENT? &')'
+ arg_ty a;
+ expr_ty c;
+ void *tc;
+ if (
+ (a = param_rule(p))
+ &&
+ (c = default_rule(p))
+ &&
+ (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1)
+ &&
+ _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 8)
)
{
- res = _PyPegen_name_default_pair ( p , n , e );
+ res = _PyPegen_name_default_pair ( p , a , c , tc );
if (res == NULL && PyErr_Occurred()) {
p->error_indicator = 1;
return NULL;
@@ -3719,24 +4052,56 @@ name_with_default_rule(Parser *p)
return res;
}
-// plain_names: ','.(plain_name !'=')+
-static asdl_seq*
-plain_names_rule(Parser *p)
+// param_maybe_default:
+// | param default? ',' TYPE_COMMENT?
+// | param default? TYPE_COMMENT? &')'
+static NameDefaultPair*
+param_maybe_default_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
- asdl_seq* res = NULL;
- if (_PyPegen_is_memoized(p, plain_names_type, &res))
- return res;
+ NameDefaultPair* res = NULL;
int mark = p->mark;
- { // ','.(plain_name !'=')+
- asdl_seq * a;
+ { // param default? ',' TYPE_COMMENT?
+ arg_ty a;
+ void *c;
+ void *literal;
+ void *tc;
if (
- (a = _gather_54_rule(p))
+ (a = param_rule(p))
+ &&
+ (c = default_rule(p), 1)
+ &&
+ (literal = _PyPegen_expect_token(p, 12))
+ &&
+ (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1)
)
{
- res = a;
+ res = _PyPegen_name_default_pair ( p , a , c , tc );
+ if (res == NULL && PyErr_Occurred()) {
+ p->error_indicator = 1;
+ return NULL;
+ }
+ goto done;
+ }
+ p->mark = mark;
+ }
+ { // param default? TYPE_COMMENT? &')'
+ arg_ty a;
+ void *c;
+ void *tc;
+ if (
+ (a = param_rule(p))
+ &&
+ (c = default_rule(p), 1)
+ &&
+ (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1)
+ &&
+ _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 8)
+ )
+ {
+ res = _PyPegen_name_default_pair ( p , a , c , tc );
if (res == NULL && PyErr_Occurred()) {
p->error_indicator = 1;
return NULL;
@@ -3747,13 +4112,12 @@ plain_names_rule(Parser *p)
}
res = NULL;
done:
- _PyPegen_insert_memo(p, mark, plain_names_type, res);
return res;
}
-// plain_name: NAME [':' annotation]
+// param: NAME annotation?
static arg_ty
-plain_name_rule(Parser *p)
+param_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -3768,13 +4132,13 @@ plain_name_rule(Parser *p)
UNUSED(start_lineno); // Only used by EXTRA macro
int start_col_offset = p->tokens[mark]->col_offset;
UNUSED(start_col_offset); // Only used by EXTRA macro
- { // NAME [':' annotation]
+ { // NAME annotation?
expr_ty a;
void *b;
if (
(a = _PyPegen_name_token(p))
&&
- (b = _tmp_56_rule(p), 1)
+ (b = annotation_rule(p), 1)
)
{
Token *token = _PyPegen_get_last_nonnwhitespace_token(p);
@@ -3799,22 +4163,22 @@ plain_name_rule(Parser *p)
return res;
}
-// kwds: '**' plain_name
-static arg_ty
-kwds_rule(Parser *p)
+// annotation: ':' expression
+static expr_ty
+annotation_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
- arg_ty res = NULL;
+ expr_ty res = NULL;
int mark = p->mark;
- { // '**' plain_name
- arg_ty a;
+ { // ':' expression
+ expr_ty a;
void *literal;
if (
- (literal = _PyPegen_expect_token(p, 35))
+ (literal = _PyPegen_expect_token(p, 11))
&&
- (a = plain_name_rule(p))
+ (a = expression_rule(p))
)
{
res = a;
@@ -3831,22 +4195,29 @@ kwds_rule(Parser *p)
return res;
}
-// annotation: expression
+// default: '=' expression
static expr_ty
-annotation_rule(Parser *p)
+default_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
expr_ty res = NULL;
int mark = p->mark;
- { // expression
- expr_ty expression_var;
+ { // '=' expression
+ expr_ty a;
+ void *literal;
if (
- (expression_var = expression_rule(p))
+ (literal = _PyPegen_expect_token(p, 22))
+ &&
+ (a = expression_rule(p))
)
{
- res = expression_var;
+ res = a;
+ if (res == NULL && PyErr_Occurred()) {
+ p->error_indicator = 1;
+ return NULL;
+ }
goto done;
}
p->mark = mark;
@@ -3868,7 +4239,7 @@ decorators_rule(Parser *p)
{ // (('@' named_expression NEWLINE))+
asdl_seq * a;
if (
- (a = _loop1_57_rule(p))
+ (a = _loop1_62_rule(p))
)
{
res = a;
@@ -3956,7 +4327,7 @@ class_def_raw_rule(Parser *p)
&&
(a = _PyPegen_name_token(p))
&&
- (b = _tmp_58_rule(p), 1)
+ (b = _tmp_63_rule(p), 1)
&&
(literal = _PyPegen_expect_token(p, 11))
&&
@@ -4062,7 +4433,7 @@ expressions_list_rule(Parser *p)
void *opt_var;
UNUSED(opt_var); // Silence compiler warnings
if (
- (a = _gather_59_rule(p))
+ (a = _gather_64_rule(p))
&&
(opt_var = _PyPegen_expect_token(p, 12), 1)
)
@@ -4109,7 +4480,7 @@ star_expressions_rule(Parser *p)
if (
(a = star_expression_rule(p))
&&
- (b = _loop1_61_rule(p))
+ (b = _loop1_66_rule(p))
&&
(opt_var = _PyPegen_expect_token(p, 12), 1)
)
@@ -4249,7 +4620,7 @@ star_named_expressions_rule(Parser *p)
void *opt_var;
UNUSED(opt_var); // Silence compiler warnings
if (
- (a = _gather_62_rule(p))
+ (a = _gather_67_rule(p))
&&
(opt_var = _PyPegen_expect_token(p, 12), 1)
)
@@ -4463,7 +4834,7 @@ expressions_rule(Parser *p)
if (
(a = expression_rule(p))
&&
- (b = _loop1_64_rule(p))
+ (b = _loop1_69_rule(p))
&&
(opt_var = _PyPegen_expect_token(p, 12), 1)
)
@@ -4685,11 +5056,11 @@ lambda_parameters_rule(Parser *p)
if (
(a = lambda_slash_without_default_rule(p))
&&
- (b = _tmp_65_rule(p), 1)
+ (b = _tmp_70_rule(p), 1)
&&
- (c = _tmp_66_rule(p), 1)
+ (c = _tmp_71_rule(p), 1)
&&
- (d = _tmp_67_rule(p), 1)
+ (d = _tmp_72_rule(p), 1)
)
{
res = _PyPegen_make_arguments ( p , a , NULL , b , c , d );
@@ -4708,9 +5079,9 @@ lambda_parameters_rule(Parser *p)
if (
(a = lambda_slash_with_default_rule(p))
&&
- (b = _tmp_68_rule(p), 1)
+ (b = _tmp_73_rule(p), 1)
&&
- (c = _tmp_69_rule(p), 1)
+ (c = _tmp_74_rule(p), 1)
)
{
res = _PyPegen_make_arguments ( p , NULL , a , NULL , b , c );
@@ -4729,9 +5100,9 @@ lambda_parameters_rule(Parser *p)
if (
(a = lambda_plain_names_rule(p))
&&
- (b = _tmp_70_rule(p), 1)
+ (b = _tmp_75_rule(p), 1)
&&
- (c = _tmp_71_rule(p), 1)
+ (c = _tmp_76_rule(p), 1)
)
{
res = _PyPegen_make_arguments ( p , NULL , NULL , a , b , c );
@@ -4749,7 +5120,7 @@ lambda_parameters_rule(Parser *p)
if (
(a = lambda_names_with_default_rule(p))
&&
- (b = _tmp_72_rule(p), 1)
+ (b = _tmp_77_rule(p), 1)
)
{
res = _PyPegen_make_arguments ( p , NULL , NULL , NULL , a , b );
@@ -4831,7 +5202,7 @@ lambda_slash_with_default_rule(Parser *p)
void *literal;
void *literal_1;
if (
- (a = _tmp_73_rule(p), 1)
+ (a = _tmp_78_rule(p), 1)
&&
(b = lambda_names_with_default_rule(p))
&&
@@ -4878,9 +5249,9 @@ lambda_star_etc_rule(Parser *p)
&&
(a = lambda_plain_name_rule(p))
&&
- (b = _loop0_74_rule(p))
+ (b = _loop0_79_rule(p))
&&
- (c = _tmp_75_rule(p), 1)
+ (c = _tmp_80_rule(p), 1)
&&
(opt_var = _PyPegen_expect_token(p, 12), 1)
)
@@ -4903,9 +5274,9 @@ lambda_star_etc_rule(Parser *p)
if (
(literal = _PyPegen_expect_token(p, 16))
&&
- (b = _loop1_76_rule(p))
+ (b = _loop1_81_rule(p))
&&
- (c = _tmp_77_rule(p), 1)
+ (c = _tmp_82_rule(p), 1)
&&
(opt_var = _PyPegen_expect_token(p, 12), 1)
)
@@ -4961,10 +5332,10 @@ lambda_name_with_optional_default_rule(Parser *p)
&&
(a = lambda_plain_name_rule(p))
&&
- (b = _tmp_78_rule(p), 1)
+ (b = _tmp_83_rule(p), 1)
)
{
- res = _PyPegen_name_default_pair ( p , a , b );
+ res = _PyPegen_name_default_pair ( p , a , b , NULL );
if (res == NULL && PyErr_Occurred()) {
p->error_indicator = 1;
return NULL;
@@ -4990,7 +5361,7 @@ lambda_names_with_default_rule(Parser *p)
{ // ','.lambda_name_with_default+
asdl_seq * a;
if (
- (a = _gather_79_rule(p))
+ (a = _gather_84_rule(p))
)
{
res = a;
@@ -5028,7 +5399,7 @@ lambda_name_with_default_rule(Parser *p)
(e = expression_rule(p))
)
{
- res = _PyPegen_name_default_pair ( p , n , e );
+ res = _PyPegen_name_default_pair ( p , n , e , NULL );
if (res == NULL && PyErr_Occurred()) {
p->error_indicator = 1;
return NULL;
@@ -5054,7 +5425,7 @@ lambda_plain_names_rule(Parser *p)
{ // ','.(lambda_plain_name !'=')+
asdl_seq * a;
if (
- (a = _gather_81_rule(p))
+ (a = _gather_86_rule(p))
)
{
res = a;
@@ -5173,7 +5544,7 @@ disjunction_rule(Parser *p)
if (
(a = conjunction_rule(p))
&&
- (b = _loop1_83_rule(p))
+ (b = _loop1_88_rule(p))
)
{
Token *token = _PyPegen_get_last_nonnwhitespace_token(p);
@@ -5235,7 +5606,7 @@ conjunction_rule(Parser *p)
if (
(a = inversion_rule(p))
&&
- (b = _loop1_84_rule(p))
+ (b = _loop1_89_rule(p))
)
{
Token *token = _PyPegen_get_last_nonnwhitespace_token(p);
@@ -5357,7 +5728,7 @@ comparison_rule(Parser *p)
if (
(a = bitwise_or_rule(p))
&&
- (b = _loop1_85_rule(p))
+ (b = _loop1_90_rule(p))
)
{
Token *token = _PyPegen_get_last_nonnwhitespace_token(p);
@@ -5569,10 +5940,10 @@ noteq_bitwise_or_rule(Parser *p)
CmpopExprPair* res = NULL;
int mark = p->mark;
{ // ('!=') bitwise_or
- void *_tmp_86_var;
+ void *_tmp_91_var;
expr_ty a;
if (
- (_tmp_86_var = _tmp_86_rule(p))
+ (_tmp_91_var = _tmp_91_rule(p))
&&
(a = bitwise_or_rule(p))
)
@@ -7014,7 +7385,7 @@ slices_rule(Parser *p)
void *opt_var;
UNUSED(opt_var); // Silence compiler warnings
if (
- (a = _gather_87_rule(p))
+ (a = _gather_92_rule(p))
&&
(opt_var = _PyPegen_expect_token(p, 12), 1)
)
@@ -7070,7 +7441,7 @@ slice_rule(Parser *p)
&&
(b = expression_rule(p), 1)
&&
- (c = _tmp_89_rule(p), 1)
+ (c = _tmp_94_rule(p), 1)
)
{
Token *token = _PyPegen_get_last_nonnwhitespace_token(p);
@@ -7258,40 +7629,40 @@ atom_rule(Parser *p)
p->mark = mark;
}
{ // &'(' (tuple | group | genexp)
- void *_tmp_90_var;
+ void *_tmp_95_var;
if (
_PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 7)
&&
- (_tmp_90_var = _tmp_90_rule(p))
+ (_tmp_95_var = _tmp_95_rule(p))
)
{
- res = _tmp_90_var;
+ res = _tmp_95_var;
goto done;
}
p->mark = mark;
}
{ // &'[' (list | listcomp)
- void *_tmp_91_var;
+ void *_tmp_96_var;
if (
_PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 9)
&&
- (_tmp_91_var = _tmp_91_rule(p))
+ (_tmp_96_var = _tmp_96_rule(p))
)
{
- res = _tmp_91_var;
+ res = _tmp_96_var;
goto done;
}
p->mark = mark;
}
{ // &'{' (dict | set | dictcomp | setcomp)
- void *_tmp_92_var;
+ void *_tmp_97_var;
if (
_PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 25)
&&
- (_tmp_92_var = _tmp_92_rule(p))
+ (_tmp_97_var = _tmp_97_rule(p))
)
{
- res = _tmp_92_var;
+ res = _tmp_97_var;
goto done;
}
p->mark = mark;
@@ -7338,7 +7709,7 @@ strings_rule(Parser *p)
{ // STRING+
asdl_seq * a;
if (
- (a = _loop1_93_rule(p))
+ (a = _loop1_98_rule(p))
)
{
res = _PyPegen_concatenate_strings ( p , a );
@@ -7496,7 +7867,7 @@ tuple_rule(Parser *p)
if (
(literal = _PyPegen_expect_token(p, 7))
&&
- (a = _tmp_94_rule(p), 1)
+ (a = _tmp_99_rule(p), 1)
&&
(literal_1 = _PyPegen_expect_token(p, 8))
)
@@ -7539,7 +7910,7 @@ group_rule(Parser *p)
if (
(literal = _PyPegen_expect_token(p, 7))
&&
- (a = _tmp_95_rule(p))
+ (a = _tmp_100_rule(p))
&&
(literal_1 = _PyPegen_expect_token(p, 8))
)
@@ -7858,7 +8229,7 @@ kvpairs_rule(Parser *p)
void *opt_var;
UNUSED(opt_var); // Silence compiler warnings
if (
- (a = _gather_96_rule(p))
+ (a = _gather_101_rule(p))
&&
(opt_var = _PyPegen_expect_token(p, 12), 1)
)
@@ -7942,7 +8313,7 @@ for_if_clauses_rule(Parser *p)
{ // ((ASYNC? 'for' star_targets 'in' disjunction (('if' disjunction))*))+
asdl_seq * a;
if (
- (a = _loop1_98_rule(p))
+ (a = _loop1_103_rule(p))
)
{
res = a;
@@ -8108,7 +8479,7 @@ args_rule(Parser *p)
if (
(a = starred_expression_rule(p))
&&
- (b = _tmp_99_rule(p), 1)
+ (b = _tmp_104_rule(p), 1)
)
{
Token *token = _PyPegen_get_last_nonnwhitespace_token(p);
@@ -8157,7 +8528,7 @@ args_rule(Parser *p)
if (
(a = named_expression_rule(p))
&&
- (b = _tmp_100_rule(p), 1)
+ (b = _tmp_105_rule(p), 1)
)
{
Token *token = _PyPegen_get_last_nonnwhitespace_token(p);
@@ -8199,11 +8570,11 @@ kwargs_rule(Parser *p)
asdl_seq * b;
void *literal;
if (
- (a = _gather_101_rule(p))
+ (a = _gather_106_rule(p))
&&
(literal = _PyPegen_expect_token(p, 12))
&&
- (b = _gather_103_rule(p))
+ (b = _gather_108_rule(p))
)
{
res = _PyPegen_join_sequences ( p , a , b );
@@ -8216,23 +8587,23 @@ kwargs_rule(Parser *p)
p->mark = mark;
}
{ // ','.kwarg_or_starred+
- asdl_seq * _gather_105_var;
+ asdl_seq * _gather_110_var;
if (
- (_gather_105_var = _gather_105_rule(p))
+ (_gather_110_var = _gather_110_rule(p))
)
{
- res = _gather_105_var;
+ res = _gather_110_var;
goto done;
}
p->mark = mark;
}
{ // ','.kwarg_or_double_starred+
- asdl_seq * _gather_107_var;
+ asdl_seq * _gather_112_var;
if (
- (_gather_107_var = _gather_107_rule(p))
+ (_gather_112_var = _gather_112_rule(p))
)
{
- res = _gather_107_var;
+ res = _gather_112_var;
goto done;
}
p->mark = mark;
@@ -8475,7 +8846,7 @@ star_targets_rule(Parser *p)
if (
(a = star_target_rule(p))
&&
- (b = _loop0_109_rule(p))
+ (b = _loop0_114_rule(p))
&&
(opt_var = _PyPegen_expect_token(p, 12), 1)
)
@@ -8516,7 +8887,7 @@ star_targets_seq_rule(Parser *p)
void *opt_var;
UNUSED(opt_var); // Silence compiler warnings
if (
- (a = _gather_110_rule(p))
+ (a = _gather_115_rule(p))
&&
(opt_var = _PyPegen_expect_token(p, 12), 1)
)
@@ -8564,7 +8935,7 @@ star_target_rule(Parser *p)
if (
(literal = _PyPegen_expect_token(p, 16))
&&
- (a = _tmp_112_rule(p))
+ (a = _tmp_117_rule(p))
)
{
Token *token = _PyPegen_get_last_nonnwhitespace_token(p);
@@ -8953,7 +9324,7 @@ del_targets_rule(Parser *p)
void *opt_var;
UNUSED(opt_var); // Silence compiler warnings
if (
- (a = _gather_113_rule(p))
+ (a = _gather_118_rule(p))
&&
(opt_var = _PyPegen_expect_token(p, 12), 1)
)
@@ -9206,7 +9577,7 @@ targets_rule(Parser *p)
void *opt_var;
UNUSED(opt_var); // Silence compiler warnings
if (
- (a = _gather_115_rule(p))
+ (a = _gather_120_rule(p))
&&
(opt_var = _PyPegen_expect_token(p, 12), 1)
)
@@ -9734,7 +10105,7 @@ incorrect_arguments_rule(Parser *p)
&&
(literal = _PyPegen_expect_token(p, 12))
&&
- (opt_var = _tmp_117_rule(p), 1)
+ (opt_var = _tmp_122_rule(p), 1)
)
{
res = RAISE_SYNTAX_ERROR ( "Generator expression must be parenthesized" );
@@ -9869,7 +10240,7 @@ invalid_assignment_rule(Parser *p)
&&
(expression_var_1 = expression_rule(p))
&&
- (opt_var = _tmp_118_rule(p), 1)
+ (opt_var = _tmp_123_rule(p), 1)
)
{
res = RAISE_SYNTAX_ERROR ( "illegal target for annotation" );
@@ -9882,15 +10253,15 @@ invalid_assignment_rule(Parser *p)
p->mark = mark;
}
{ // expression ('=' | augassign) (yield_expr | star_expressions)
- void *_tmp_119_var;
- void *_tmp_120_var;
+ void *_tmp_124_var;
+ void *_tmp_125_var;
expr_ty a;
if (
(a = expression_rule(p))
&&
- (_tmp_119_var = _tmp_119_rule(p))
+ (_tmp_124_var = _tmp_124_rule(p))
&&
- (_tmp_120_var = _tmp_120_rule(p))
+ (_tmp_125_var = _tmp_125_rule(p))
)
{
res = RAISE_SYNTAX_ERROR ( "cannot assign to %s" , _PyPegen_get_expr_name ( a ) );
@@ -9948,12 +10319,12 @@ invalid_comprehension_rule(Parser *p)
void * res = NULL;
int mark = p->mark;
{ // ('[' | '(' | '{') '*' expression for_if_clauses
- void *_tmp_121_var;
+ void *_tmp_126_var;
expr_ty expression_var;
asdl_seq* for_if_clauses_var;
void *literal;
if (
- (_tmp_121_var = _tmp_121_rule(p))
+ (_tmp_126_var = _tmp_126_rule(p))
&&
(literal = _PyPegen_expect_token(p, 16))
&&
@@ -9977,7 +10348,7 @@ invalid_comprehension_rule(Parser *p)
}
// invalid_parameters:
-// | [plain_names ','] (slash_with_default | names_with_default) ',' plain_names
+// | param_no_default* (slash_with_default | param_with_default+) param_no_default
static void *
invalid_parameters_rule(Parser *p)
{
@@ -9986,20 +10357,16 @@ invalid_parameters_rule(Parser *p)
}
void * res = NULL;
int mark = p->mark;
- { // [plain_names ','] (slash_with_default | names_with_default) ',' plain_names
- void *_tmp_123_var;
- void *literal;
- void *opt_var;
- UNUSED(opt_var); // Silence compiler warnings
- asdl_seq* plain_names_var;
+ { // param_no_default* (slash_with_default | param_with_default+) param_no_default
+ asdl_seq * _loop0_127_var;
+ void *_tmp_128_var;
+ arg_ty param_no_default_var;
if (
- (opt_var = _tmp_122_rule(p), 1)
- &&
- (_tmp_123_var = _tmp_123_rule(p))
+ (_loop0_127_var = _loop0_127_rule(p))
&&
- (literal = _PyPegen_expect_token(p, 12))
+ (_tmp_128_var = _tmp_128_rule(p))
&&
- (plain_names_var = plain_names_rule(p))
+ (param_no_default_var = param_no_default_rule(p))
)
{
res = RAISE_SYNTAX_ERROR ( "non-default argument follows default argument" );
@@ -10016,6 +10383,47 @@ invalid_parameters_rule(Parser *p)
return res;
}
+// invalid_double_type_comments: TYPE_COMMENT NEWLINE TYPE_COMMENT NEWLINE INDENT
+static void *
+invalid_double_type_comments_rule(Parser *p)
+{
+ if (p->error_indicator) {
+ return NULL;
+ }
+ void * res = NULL;
+ int mark = p->mark;
+ { // TYPE_COMMENT NEWLINE TYPE_COMMENT NEWLINE INDENT
+ void *indent_var;
+ void *newline_var;
+ void *newline_var_1;
+ void *type_comment_var;
+ void *type_comment_var_1;
+ if (
+ (type_comment_var = _PyPegen_expect_token(p, TYPE_COMMENT))
+ &&
+ (newline_var = _PyPegen_expect_token(p, NEWLINE))
+ &&
+ (type_comment_var_1 = _PyPegen_expect_token(p, TYPE_COMMENT))
+ &&
+ (newline_var_1 = _PyPegen_expect_token(p, NEWLINE))
+ &&
+ (indent_var = _PyPegen_expect_token(p, INDENT))
+ )
+ {
+ res = RAISE_SYNTAX_ERROR ( "Cannot have two type comments on def" );
+ if (res == NULL && PyErr_Occurred()) {
+ p->error_indicator = 1;
+ return NULL;
+ }
+ goto done;
+ }
+ p->mark = mark;
+ }
+ res = NULL;
+ done:
+ return res;
+}
+
// _loop0_1: NEWLINE
static asdl_seq *
_loop0_1_rule(Parser *p)
@@ -10065,9 +10473,9 @@ _loop0_1_rule(Parser *p)
return seq;
}
-// _loop1_2: statement
+// _loop0_2: NEWLINE
static asdl_seq *
-_loop1_2_rule(Parser *p)
+_loop0_2_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -10082,13 +10490,13 @@ _loop1_2_rule(Parser *p)
}
ssize_t children_capacity = 1;
ssize_t n = 0;
- { // statement
- asdl_seq* statement_var;
+ { // NEWLINE
+ void *newline_var;
while (
- (statement_var = statement_rule(p))
+ (newline_var = _PyPegen_expect_token(p, NEWLINE))
)
{
- res = statement_var;
+ res = newline_var;
if (n == children_capacity) {
children_capacity *= 2;
children = PyMem_Realloc(children, children_capacity*sizeof(void *));
@@ -10102,23 +10510,19 @@ _loop1_2_rule(Parser *p)
}
p->mark = mark;
}
- if (n == 0) {
- PyMem_Free(children);
- return NULL;
- }
asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_2");
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_2");
PyMem_Free(children);
return NULL;
}
for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop1_2_type, seq);
+ _PyPegen_insert_memo(p, start_mark, _loop0_2_type, seq);
return seq;
}
-// _loop0_4: ';' small_stmt
+// _loop0_4: ',' expression
static asdl_seq *
_loop0_4_rule(Parser *p)
{
@@ -10135,13 +10539,13 @@ _loop0_4_rule(Parser *p)
}
ssize_t children_capacity = 1;
ssize_t n = 0;
- { // ';' small_stmt
- stmt_ty elem;
+ { // ',' expression
+ expr_ty elem;
void *literal;
while (
- (literal = _PyPegen_expect_token(p, 13))
+ (literal = _PyPegen_expect_token(p, 12))
&&
- (elem = small_stmt_rule(p))
+ (elem = expression_rule(p))
)
{
res = elem;
@@ -10175,7 +10579,7 @@ _loop0_4_rule(Parser *p)
return seq;
}
-// _gather_3: small_stmt _loop0_4
+// _gather_3: expression _loop0_4
static asdl_seq *
_gather_3_rule(Parser *p)
{
@@ -10184,11 +10588,11 @@ _gather_3_rule(Parser *p)
}
asdl_seq * res = NULL;
int mark = p->mark;
- { // small_stmt _loop0_4
- stmt_ty elem;
+ { // expression _loop0_4
+ expr_ty elem;
asdl_seq * seq;
if (
- (elem = small_stmt_rule(p))
+ (elem = expression_rule(p))
&&
(seq = _loop0_4_rule(p))
)
@@ -10203,116 +10607,82 @@ _gather_3_rule(Parser *p)
return res;
}
-// _tmp_5: 'import' | 'from'
-static void *
-_tmp_5_rule(Parser *p)
+// _loop0_6: ',' expression
+static asdl_seq *
+_loop0_6_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
- void * res = NULL;
+ void *res = NULL;
int mark = p->mark;
- { // 'import'
- void *keyword;
- if (
- (keyword = _PyPegen_expect_token(p, 513))
- )
- {
- res = keyword;
- goto done;
- }
- p->mark = mark;
+ int start_mark = p->mark;
+ void **children = PyMem_Malloc(sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "Parser out of memory");
+ return NULL;
}
- { // 'from'
- void *keyword;
- if (
- (keyword = _PyPegen_expect_token(p, 514))
+ ssize_t children_capacity = 1;
+ ssize_t n = 0;
+ { // ',' expression
+ expr_ty elem;
+ void *literal;
+ while (
+ (literal = _PyPegen_expect_token(p, 12))
+ &&
+ (elem = expression_rule(p))
)
{
- res = keyword;
- goto done;
+ res = elem;
+ if (res == NULL && PyErr_Occurred()) {
+ p->error_indicator = 1;
+ PyMem_Free(children);
+ return NULL;
+ }
+ if (n == children_capacity) {
+ children_capacity *= 2;
+ children = PyMem_Realloc(children, children_capacity*sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "realloc None");
+ return NULL;
+ }
+ }
+ children[n++] = res;
+ mark = p->mark;
}
p->mark = mark;
}
- res = NULL;
- done:
- return res;
-}
-
-// _tmp_6: 'def' | '@' | ASYNC
-static void *
-_tmp_6_rule(Parser *p)
-{
- if (p->error_indicator) {
+ asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
+ if (!seq) {
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_6");
+ PyMem_Free(children);
return NULL;
}
- void * res = NULL;
- int mark = p->mark;
- { // 'def'
- void *keyword;
- if (
- (keyword = _PyPegen_expect_token(p, 522))
- )
- {
- res = keyword;
- goto done;
- }
- p->mark = mark;
- }
- { // '@'
- void *literal;
- if (
- (literal = _PyPegen_expect_token(p, 49))
- )
- {
- res = literal;
- goto done;
- }
- p->mark = mark;
- }
- { // ASYNC
- void *async_var;
- if (
- (async_var = _PyPegen_expect_token(p, ASYNC))
- )
- {
- res = async_var;
- goto done;
- }
- p->mark = mark;
- }
- res = NULL;
- done:
- return res;
+ for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
+ PyMem_Free(children);
+ _PyPegen_insert_memo(p, start_mark, _loop0_6_type, seq);
+ return seq;
}
-// _tmp_7: 'class' | '@'
-static void *
-_tmp_7_rule(Parser *p)
+// _gather_5: expression _loop0_6
+static asdl_seq *
+_gather_5_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
- void * res = NULL;
+ asdl_seq * res = NULL;
int mark = p->mark;
- { // 'class'
- void *keyword;
- if (
- (keyword = _PyPegen_expect_token(p, 523))
- )
- {
- res = keyword;
- goto done;
- }
- p->mark = mark;
- }
- { // '@'
- void *literal;
+ { // expression _loop0_6
+ expr_ty elem;
+ asdl_seq * seq;
if (
- (literal = _PyPegen_expect_token(p, 49))
+ (elem = expression_rule(p))
+ &&
+ (seq = _loop0_6_rule(p))
)
{
- res = literal;
+ res = _PyPegen_seq_insert_in_front(p, elem, seq);
goto done;
}
p->mark = mark;
@@ -10322,101 +10692,82 @@ _tmp_7_rule(Parser *p)
return res;
}
-// _tmp_8: 'with' | ASYNC
-static void *
-_tmp_8_rule(Parser *p)
+// _loop0_8: ',' expression
+static asdl_seq *
+_loop0_8_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
- void * res = NULL;
+ void *res = NULL;
int mark = p->mark;
- { // 'with'
- void *keyword;
- if (
- (keyword = _PyPegen_expect_token(p, 519))
- )
- {
- res = keyword;
- goto done;
- }
- p->mark = mark;
- }
- { // ASYNC
- void *async_var;
- if (
- (async_var = _PyPegen_expect_token(p, ASYNC))
- )
- {
- res = async_var;
- goto done;
- }
- p->mark = mark;
- }
- res = NULL;
- done:
- return res;
-}
-
-// _tmp_9: 'for' | ASYNC
-static void *
-_tmp_9_rule(Parser *p)
-{
- if (p->error_indicator) {
+ int start_mark = p->mark;
+ void **children = PyMem_Malloc(sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "Parser out of memory");
return NULL;
}
- void * res = NULL;
- int mark = p->mark;
- { // 'for'
- void *keyword;
- if (
- (keyword = _PyPegen_expect_token(p, 517))
+ ssize_t children_capacity = 1;
+ ssize_t n = 0;
+ { // ',' expression
+ expr_ty elem;
+ void *literal;
+ while (
+ (literal = _PyPegen_expect_token(p, 12))
+ &&
+ (elem = expression_rule(p))
)
{
- res = keyword;
- goto done;
+ res = elem;
+ if (res == NULL && PyErr_Occurred()) {
+ p->error_indicator = 1;
+ PyMem_Free(children);
+ return NULL;
+ }
+ if (n == children_capacity) {
+ children_capacity *= 2;
+ children = PyMem_Realloc(children, children_capacity*sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "realloc None");
+ return NULL;
+ }
+ }
+ children[n++] = res;
+ mark = p->mark;
}
p->mark = mark;
}
- { // ASYNC
- void *async_var;
- if (
- (async_var = _PyPegen_expect_token(p, ASYNC))
- )
- {
- res = async_var;
- goto done;
- }
- p->mark = mark;
+ asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
+ if (!seq) {
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_8");
+ PyMem_Free(children);
+ return NULL;
}
- res = NULL;
- done:
- return res;
+ for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
+ PyMem_Free(children);
+ _PyPegen_insert_memo(p, start_mark, _loop0_8_type, seq);
+ return seq;
}
-// _tmp_10: '=' annotated_rhs
-static void *
-_tmp_10_rule(Parser *p)
+// _gather_7: expression _loop0_8
+static asdl_seq *
+_gather_7_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
- void * res = NULL;
+ asdl_seq * res = NULL;
int mark = p->mark;
- { // '=' annotated_rhs
- expr_ty d;
- void *literal;
+ { // expression _loop0_8
+ expr_ty elem;
+ asdl_seq * seq;
if (
- (literal = _PyPegen_expect_token(p, 22))
+ (elem = expression_rule(p))
&&
- (d = annotated_rhs_rule(p))
+ (seq = _loop0_8_rule(p))
)
{
- res = d;
- if (res == NULL && PyErr_Occurred()) {
- p->error_indicator = 1;
- return NULL;
- }
+ res = _PyPegen_seq_insert_in_front(p, elem, seq);
goto done;
}
p->mark = mark;
@@ -10426,75 +10777,82 @@ _tmp_10_rule(Parser *p)
return res;
}
-// _tmp_11: '(' inside_paren_ann_assign_target ')' | ann_assign_subscript_attribute_target
-static void *
-_tmp_11_rule(Parser *p)
+// _loop0_10: ',' expression
+static asdl_seq *
+_loop0_10_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
- void * res = NULL;
+ void *res = NULL;
int mark = p->mark;
- { // '(' inside_paren_ann_assign_target ')'
- expr_ty b;
+ int start_mark = p->mark;
+ void **children = PyMem_Malloc(sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "Parser out of memory");
+ return NULL;
+ }
+ ssize_t children_capacity = 1;
+ ssize_t n = 0;
+ { // ',' expression
+ expr_ty elem;
void *literal;
- void *literal_1;
- if (
- (literal = _PyPegen_expect_token(p, 7))
- &&
- (b = inside_paren_ann_assign_target_rule(p))
+ while (
+ (literal = _PyPegen_expect_token(p, 12))
&&
- (literal_1 = _PyPegen_expect_token(p, 8))
+ (elem = expression_rule(p))
)
{
- res = b;
+ res = elem;
if (res == NULL && PyErr_Occurred()) {
p->error_indicator = 1;
+ PyMem_Free(children);
return NULL;
}
- goto done;
+ if (n == children_capacity) {
+ children_capacity *= 2;
+ children = PyMem_Realloc(children, children_capacity*sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "realloc None");
+ return NULL;
+ }
+ }
+ children[n++] = res;
+ mark = p->mark;
}
p->mark = mark;
}
- { // ann_assign_subscript_attribute_target
- expr_ty ann_assign_subscript_attribute_target_var;
- if (
- (ann_assign_subscript_attribute_target_var = ann_assign_subscript_attribute_target_rule(p))
- )
- {
- res = ann_assign_subscript_attribute_target_var;
- goto done;
- }
- p->mark = mark;
+ asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
+ if (!seq) {
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_10");
+ PyMem_Free(children);
+ return NULL;
}
- res = NULL;
- done:
- return res;
+ for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
+ PyMem_Free(children);
+ _PyPegen_insert_memo(p, start_mark, _loop0_10_type, seq);
+ return seq;
}
-// _tmp_12: '=' annotated_rhs
-static void *
-_tmp_12_rule(Parser *p)
+// _gather_9: expression _loop0_10
+static asdl_seq *
+_gather_9_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
- void * res = NULL;
+ asdl_seq * res = NULL;
int mark = p->mark;
- { // '=' annotated_rhs
- expr_ty d;
- void *literal;
+ { // expression _loop0_10
+ expr_ty elem;
+ asdl_seq * seq;
if (
- (literal = _PyPegen_expect_token(p, 22))
+ (elem = expression_rule(p))
&&
- (d = annotated_rhs_rule(p))
+ (seq = _loop0_10_rule(p))
)
{
- res = d;
- if (res == NULL && PyErr_Occurred()) {
- p->error_indicator = 1;
- return NULL;
- }
+ res = _PyPegen_seq_insert_in_front(p, elem, seq);
goto done;
}
p->mark = mark;
@@ -10504,9 +10862,9 @@ _tmp_12_rule(Parser *p)
return res;
}
-// _loop1_13: (star_targets '=')
+// _loop1_11: statement
static asdl_seq *
-_loop1_13_rule(Parser *p)
+_loop1_11_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -10521,13 +10879,13 @@ _loop1_13_rule(Parser *p)
}
ssize_t children_capacity = 1;
ssize_t n = 0;
- { // (star_targets '=')
- void *_tmp_124_var;
+ { // statement
+ asdl_seq* statement_var;
while (
- (_tmp_124_var = _tmp_124_rule(p))
+ (statement_var = statement_rule(p))
)
{
- res = _tmp_124_var;
+ res = statement_var;
if (n == children_capacity) {
children_capacity *= 2;
children = PyMem_Realloc(children, children_capacity*sizeof(void *));
@@ -10547,91 +10905,19 @@ _loop1_13_rule(Parser *p)
}
asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_13");
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_11");
PyMem_Free(children);
return NULL;
}
for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop1_13_type, seq);
+ _PyPegen_insert_memo(p, start_mark, _loop1_11_type, seq);
return seq;
}
-// _tmp_14: yield_expr | star_expressions
-static void *
-_tmp_14_rule(Parser *p)
-{
- if (p->error_indicator) {
- return NULL;
- }
- void * res = NULL;
- int mark = p->mark;
- { // yield_expr
- expr_ty yield_expr_var;
- if (
- (yield_expr_var = yield_expr_rule(p))
- )
- {
- res = yield_expr_var;
- goto done;
- }
- p->mark = mark;
- }
- { // star_expressions
- expr_ty star_expressions_var;
- if (
- (star_expressions_var = star_expressions_rule(p))
- )
- {
- res = star_expressions_var;
- goto done;
- }
- p->mark = mark;
- }
- res = NULL;
- done:
- return res;
-}
-
-// _tmp_15: yield_expr | star_expressions
-static void *
-_tmp_15_rule(Parser *p)
-{
- if (p->error_indicator) {
- return NULL;
- }
- void * res = NULL;
- int mark = p->mark;
- { // yield_expr
- expr_ty yield_expr_var;
- if (
- (yield_expr_var = yield_expr_rule(p))
- )
- {
- res = yield_expr_var;
- goto done;
- }
- p->mark = mark;
- }
- { // star_expressions
- expr_ty star_expressions_var;
- if (
- (star_expressions_var = star_expressions_rule(p))
- )
- {
- res = star_expressions_var;
- goto done;
- }
- p->mark = mark;
- }
- res = NULL;
- done:
- return res;
-}
-
-// _loop0_17: ',' NAME
+// _loop0_13: ';' small_stmt
static asdl_seq *
-_loop0_17_rule(Parser *p)
+_loop0_13_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -10646,13 +10932,13 @@ _loop0_17_rule(Parser *p)
}
ssize_t children_capacity = 1;
ssize_t n = 0;
- { // ',' NAME
- expr_ty elem;
+ { // ';' small_stmt
+ stmt_ty elem;
void *literal;
while (
- (literal = _PyPegen_expect_token(p, 12))
+ (literal = _PyPegen_expect_token(p, 13))
&&
- (elem = _PyPegen_name_token(p))
+ (elem = small_stmt_rule(p))
)
{
res = elem;
@@ -10676,32 +10962,32 @@ _loop0_17_rule(Parser *p)
}
asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_17");
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_13");
PyMem_Free(children);
return NULL;
}
for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop0_17_type, seq);
+ _PyPegen_insert_memo(p, start_mark, _loop0_13_type, seq);
return seq;
}
-// _gather_16: NAME _loop0_17
+// _gather_12: small_stmt _loop0_13
static asdl_seq *
-_gather_16_rule(Parser *p)
+_gather_12_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
asdl_seq * res = NULL;
int mark = p->mark;
- { // NAME _loop0_17
- expr_ty elem;
+ { // small_stmt _loop0_13
+ stmt_ty elem;
asdl_seq * seq;
if (
- (elem = _PyPegen_name_token(p))
+ (elem = small_stmt_rule(p))
&&
- (seq = _loop0_17_rule(p))
+ (seq = _loop0_13_rule(p))
)
{
res = _PyPegen_seq_insert_in_front(p, elem, seq);
@@ -10714,82 +11000,80 @@ _gather_16_rule(Parser *p)
return res;
}
-// _loop0_19: ',' NAME
-static asdl_seq *
-_loop0_19_rule(Parser *p)
+// _tmp_14: 'import' | 'from'
+static void *
+_tmp_14_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
- void *res = NULL;
+ void * res = NULL;
int mark = p->mark;
- int start_mark = p->mark;
- void **children = PyMem_Malloc(sizeof(void *));
- if (!children) {
- PyErr_Format(PyExc_MemoryError, "Parser out of memory");
- return NULL;
- }
- ssize_t children_capacity = 1;
- ssize_t n = 0;
- { // ',' NAME
- expr_ty elem;
- void *literal;
- while (
- (literal = _PyPegen_expect_token(p, 12))
- &&
- (elem = _PyPegen_name_token(p))
+ { // 'import'
+ void *keyword;
+ if (
+ (keyword = _PyPegen_expect_token(p, 513))
)
{
- res = elem;
- if (res == NULL && PyErr_Occurred()) {
- p->error_indicator = 1;
- PyMem_Free(children);
- return NULL;
- }
- if (n == children_capacity) {
- children_capacity *= 2;
- children = PyMem_Realloc(children, children_capacity*sizeof(void *));
- if (!children) {
- PyErr_Format(PyExc_MemoryError, "realloc None");
- return NULL;
- }
- }
- children[n++] = res;
- mark = p->mark;
+ res = keyword;
+ goto done;
}
p->mark = mark;
}
- asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
- if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_19");
- PyMem_Free(children);
- return NULL;
+ { // 'from'
+ void *keyword;
+ if (
+ (keyword = _PyPegen_expect_token(p, 514))
+ )
+ {
+ res = keyword;
+ goto done;
+ }
+ p->mark = mark;
}
- for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
- PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop0_19_type, seq);
- return seq;
+ res = NULL;
+ done:
+ return res;
}
-// _gather_18: NAME _loop0_19
-static asdl_seq *
-_gather_18_rule(Parser *p)
+// _tmp_15: 'def' | '@' | ASYNC
+static void *
+_tmp_15_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
- asdl_seq * res = NULL;
+ void * res = NULL;
int mark = p->mark;
- { // NAME _loop0_19
- expr_ty elem;
- asdl_seq * seq;
+ { // 'def'
+ void *keyword;
if (
- (elem = _PyPegen_name_token(p))
- &&
- (seq = _loop0_19_rule(p))
+ (keyword = _PyPegen_expect_token(p, 522))
)
{
- res = _PyPegen_seq_insert_in_front(p, elem, seq);
+ res = keyword;
+ goto done;
+ }
+ p->mark = mark;
+ }
+ { // '@'
+ void *literal;
+ if (
+ (literal = _PyPegen_expect_token(p, 49))
+ )
+ {
+ res = literal;
+ goto done;
+ }
+ p->mark = mark;
+ }
+ { // ASYNC
+ void *async_var;
+ if (
+ (async_var = _PyPegen_expect_token(p, ASYNC))
+ )
+ {
+ res = async_var;
goto done;
}
p->mark = mark;
@@ -10799,29 +11083,33 @@ _gather_18_rule(Parser *p)
return res;
}
-// _tmp_20: ',' expression
+// _tmp_16: 'class' | '@'
static void *
-_tmp_20_rule(Parser *p)
+_tmp_16_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
void * res = NULL;
int mark = p->mark;
- { // ',' expression
+ { // 'class'
+ void *keyword;
+ if (
+ (keyword = _PyPegen_expect_token(p, 523))
+ )
+ {
+ res = keyword;
+ goto done;
+ }
+ p->mark = mark;
+ }
+ { // '@'
void *literal;
- expr_ty z;
if (
- (literal = _PyPegen_expect_token(p, 12))
- &&
- (z = expression_rule(p))
+ (literal = _PyPegen_expect_token(p, 49))
)
{
- res = z;
- if (res == NULL && PyErr_Occurred()) {
- p->error_indicator = 1;
- return NULL;
- }
+ res = literal;
goto done;
}
p->mark = mark;
@@ -10831,184 +11119,147 @@ _tmp_20_rule(Parser *p)
return res;
}
-// _loop0_21: ('.' | '...')
-static asdl_seq *
-_loop0_21_rule(Parser *p)
+// _tmp_17: 'with' | ASYNC
+static void *
+_tmp_17_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
- void *res = NULL;
+ void * res = NULL;
int mark = p->mark;
- int start_mark = p->mark;
- void **children = PyMem_Malloc(sizeof(void *));
- if (!children) {
- PyErr_Format(PyExc_MemoryError, "Parser out of memory");
- return NULL;
- }
- ssize_t children_capacity = 1;
- ssize_t n = 0;
- { // ('.' | '...')
- void *_tmp_125_var;
- while (
- (_tmp_125_var = _tmp_125_rule(p))
+ { // 'with'
+ void *keyword;
+ if (
+ (keyword = _PyPegen_expect_token(p, 519))
)
{
- res = _tmp_125_var;
- if (n == children_capacity) {
- children_capacity *= 2;
- children = PyMem_Realloc(children, children_capacity*sizeof(void *));
- if (!children) {
- PyErr_Format(PyExc_MemoryError, "realloc None");
- return NULL;
- }
- }
- children[n++] = res;
- mark = p->mark;
+ res = keyword;
+ goto done;
}
p->mark = mark;
}
- asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
- if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_21");
- PyMem_Free(children);
- return NULL;
+ { // ASYNC
+ void *async_var;
+ if (
+ (async_var = _PyPegen_expect_token(p, ASYNC))
+ )
+ {
+ res = async_var;
+ goto done;
+ }
+ p->mark = mark;
}
- for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
- PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop0_21_type, seq);
- return seq;
+ res = NULL;
+ done:
+ return res;
}
-// _loop1_22: ('.' | '...')
-static asdl_seq *
-_loop1_22_rule(Parser *p)
+// _tmp_18: 'for' | ASYNC
+static void *
+_tmp_18_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
- void *res = NULL;
+ void * res = NULL;
int mark = p->mark;
- int start_mark = p->mark;
- void **children = PyMem_Malloc(sizeof(void *));
- if (!children) {
- PyErr_Format(PyExc_MemoryError, "Parser out of memory");
- return NULL;
- }
- ssize_t children_capacity = 1;
- ssize_t n = 0;
- { // ('.' | '...')
- void *_tmp_126_var;
- while (
- (_tmp_126_var = _tmp_126_rule(p))
+ { // 'for'
+ void *keyword;
+ if (
+ (keyword = _PyPegen_expect_token(p, 517))
)
{
- res = _tmp_126_var;
- if (n == children_capacity) {
- children_capacity *= 2;
- children = PyMem_Realloc(children, children_capacity*sizeof(void *));
- if (!children) {
- PyErr_Format(PyExc_MemoryError, "realloc None");
- return NULL;
- }
- }
- children[n++] = res;
- mark = p->mark;
+ res = keyword;
+ goto done;
}
p->mark = mark;
}
- if (n == 0) {
- PyMem_Free(children);
- return NULL;
- }
- asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
- if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_22");
- PyMem_Free(children);
- return NULL;
+ { // ASYNC
+ void *async_var;
+ if (
+ (async_var = _PyPegen_expect_token(p, ASYNC))
+ )
+ {
+ res = async_var;
+ goto done;
+ }
+ p->mark = mark;
}
- for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
- PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop1_22_type, seq);
- return seq;
+ res = NULL;
+ done:
+ return res;
}
-// _loop0_24: ',' import_from_as_name
-static asdl_seq *
-_loop0_24_rule(Parser *p)
+// _tmp_19: '=' annotated_rhs
+static void *
+_tmp_19_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
- void *res = NULL;
+ void * res = NULL;
int mark = p->mark;
- int start_mark = p->mark;
- void **children = PyMem_Malloc(sizeof(void *));
- if (!children) {
- PyErr_Format(PyExc_MemoryError, "Parser out of memory");
- return NULL;
- }
- ssize_t children_capacity = 1;
- ssize_t n = 0;
- { // ',' import_from_as_name
- alias_ty elem;
+ { // '=' annotated_rhs
+ expr_ty d;
void *literal;
- while (
- (literal = _PyPegen_expect_token(p, 12))
+ if (
+ (literal = _PyPegen_expect_token(p, 22))
&&
- (elem = import_from_as_name_rule(p))
+ (d = annotated_rhs_rule(p))
)
{
- res = elem;
+ res = d;
if (res == NULL && PyErr_Occurred()) {
p->error_indicator = 1;
- PyMem_Free(children);
return NULL;
}
- if (n == children_capacity) {
- children_capacity *= 2;
- children = PyMem_Realloc(children, children_capacity*sizeof(void *));
- if (!children) {
- PyErr_Format(PyExc_MemoryError, "realloc None");
- return NULL;
- }
- }
- children[n++] = res;
- mark = p->mark;
+ goto done;
}
p->mark = mark;
}
- asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
- if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_24");
- PyMem_Free(children);
- return NULL;
- }
- for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
- PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop0_24_type, seq);
- return seq;
+ res = NULL;
+ done:
+ return res;
}
-// _gather_23: import_from_as_name _loop0_24
-static asdl_seq *
-_gather_23_rule(Parser *p)
+// _tmp_20: '(' inside_paren_ann_assign_target ')' | ann_assign_subscript_attribute_target
+static void *
+_tmp_20_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
- asdl_seq * res = NULL;
+ void * res = NULL;
int mark = p->mark;
- { // import_from_as_name _loop0_24
- alias_ty elem;
- asdl_seq * seq;
+ { // '(' inside_paren_ann_assign_target ')'
+ expr_ty b;
+ void *literal;
+ void *literal_1;
if (
- (elem = import_from_as_name_rule(p))
+ (literal = _PyPegen_expect_token(p, 7))
+ &&
+ (b = inside_paren_ann_assign_target_rule(p))
&&
- (seq = _loop0_24_rule(p))
+ (literal_1 = _PyPegen_expect_token(p, 8))
)
{
- res = _PyPegen_seq_insert_in_front(p, elem, seq);
+ res = b;
+ if (res == NULL && PyErr_Occurred()) {
+ p->error_indicator = 1;
+ return NULL;
+ }
+ goto done;
+ }
+ p->mark = mark;
+ }
+ { // ann_assign_subscript_attribute_target
+ expr_ty ann_assign_subscript_attribute_target_var;
+ if (
+ (ann_assign_subscript_attribute_target_var = ann_assign_subscript_attribute_target_rule(p))
+ )
+ {
+ res = ann_assign_subscript_attribute_target_var;
goto done;
}
p->mark = mark;
@@ -11018,25 +11269,25 @@ _gather_23_rule(Parser *p)
return res;
}
-// _tmp_25: 'as' NAME
+// _tmp_21: '=' annotated_rhs
static void *
-_tmp_25_rule(Parser *p)
+_tmp_21_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
void * res = NULL;
int mark = p->mark;
- { // 'as' NAME
- void *keyword;
- expr_ty z;
+ { // '=' annotated_rhs
+ expr_ty d;
+ void *literal;
if (
- (keyword = _PyPegen_expect_token(p, 531))
+ (literal = _PyPegen_expect_token(p, 22))
&&
- (z = _PyPegen_name_token(p))
+ (d = annotated_rhs_rule(p))
)
{
- res = z;
+ res = d;
if (res == NULL && PyErr_Occurred()) {
p->error_indicator = 1;
return NULL;
@@ -11050,9 +11301,9 @@ _tmp_25_rule(Parser *p)
return res;
}
-// _loop0_27: ',' dotted_as_name
+// _loop1_22: (star_targets '=')
static asdl_seq *
-_loop0_27_rule(Parser *p)
+_loop1_22_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -11067,21 +11318,13 @@ _loop0_27_rule(Parser *p)
}
ssize_t children_capacity = 1;
ssize_t n = 0;
- { // ',' dotted_as_name
- alias_ty elem;
- void *literal;
+ { // (star_targets '=')
+ void *_tmp_129_var;
while (
- (literal = _PyPegen_expect_token(p, 12))
- &&
- (elem = dotted_as_name_rule(p))
+ (_tmp_129_var = _tmp_129_rule(p))
)
{
- res = elem;
- if (res == NULL && PyErr_Occurred()) {
- p->error_indicator = 1;
- PyMem_Free(children);
- return NULL;
- }
+ res = _tmp_129_var;
if (n == children_capacity) {
children_capacity *= 2;
children = PyMem_Realloc(children, children_capacity*sizeof(void *));
@@ -11095,37 +11338,49 @@ _loop0_27_rule(Parser *p)
}
p->mark = mark;
}
+ if (n == 0) {
+ PyMem_Free(children);
+ return NULL;
+ }
asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_27");
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_22");
PyMem_Free(children);
return NULL;
}
for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop0_27_type, seq);
+ _PyPegen_insert_memo(p, start_mark, _loop1_22_type, seq);
return seq;
}
-// _gather_26: dotted_as_name _loop0_27
-static asdl_seq *
-_gather_26_rule(Parser *p)
+// _tmp_23: yield_expr | star_expressions
+static void *
+_tmp_23_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
- asdl_seq * res = NULL;
+ void * res = NULL;
int mark = p->mark;
- { // dotted_as_name _loop0_27
- alias_ty elem;
- asdl_seq * seq;
+ { // yield_expr
+ expr_ty yield_expr_var;
if (
- (elem = dotted_as_name_rule(p))
- &&
- (seq = _loop0_27_rule(p))
+ (yield_expr_var = yield_expr_rule(p))
)
{
- res = _PyPegen_seq_insert_in_front(p, elem, seq);
+ res = yield_expr_var;
+ goto done;
+ }
+ p->mark = mark;
+ }
+ { // star_expressions
+ expr_ty star_expressions_var;
+ if (
+ (star_expressions_var = star_expressions_rule(p))
+ )
+ {
+ res = star_expressions_var;
goto done;
}
p->mark = mark;
@@ -11135,29 +11390,33 @@ _gather_26_rule(Parser *p)
return res;
}
-// _tmp_28: 'as' NAME
+// _tmp_24: yield_expr | star_expressions
static void *
-_tmp_28_rule(Parser *p)
+_tmp_24_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
void * res = NULL;
int mark = p->mark;
- { // 'as' NAME
- void *keyword;
- expr_ty z;
+ { // yield_expr
+ expr_ty yield_expr_var;
if (
- (keyword = _PyPegen_expect_token(p, 531))
- &&
- (z = _PyPegen_name_token(p))
+ (yield_expr_var = yield_expr_rule(p))
)
{
- res = z;
- if (res == NULL && PyErr_Occurred()) {
- p->error_indicator = 1;
- return NULL;
- }
+ res = yield_expr_var;
+ goto done;
+ }
+ p->mark = mark;
+ }
+ { // star_expressions
+ expr_ty star_expressions_var;
+ if (
+ (star_expressions_var = star_expressions_rule(p))
+ )
+ {
+ res = star_expressions_var;
goto done;
}
p->mark = mark;
@@ -11167,9 +11426,9 @@ _tmp_28_rule(Parser *p)
return res;
}
-// _loop0_30: ',' with_item
+// _loop0_26: ',' NAME
static asdl_seq *
-_loop0_30_rule(Parser *p)
+_loop0_26_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -11184,13 +11443,13 @@ _loop0_30_rule(Parser *p)
}
ssize_t children_capacity = 1;
ssize_t n = 0;
- { // ',' with_item
- withitem_ty elem;
+ { // ',' NAME
+ expr_ty elem;
void *literal;
while (
(literal = _PyPegen_expect_token(p, 12))
&&
- (elem = with_item_rule(p))
+ (elem = _PyPegen_name_token(p))
)
{
res = elem;
@@ -11214,32 +11473,32 @@ _loop0_30_rule(Parser *p)
}
asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_30");
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_26");
PyMem_Free(children);
return NULL;
}
for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop0_30_type, seq);
+ _PyPegen_insert_memo(p, start_mark, _loop0_26_type, seq);
return seq;
}
-// _gather_29: with_item _loop0_30
+// _gather_25: NAME _loop0_26
static asdl_seq *
-_gather_29_rule(Parser *p)
+_gather_25_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
asdl_seq * res = NULL;
int mark = p->mark;
- { // with_item _loop0_30
- withitem_ty elem;
+ { // NAME _loop0_26
+ expr_ty elem;
asdl_seq * seq;
if (
- (elem = with_item_rule(p))
+ (elem = _PyPegen_name_token(p))
&&
- (seq = _loop0_30_rule(p))
+ (seq = _loop0_26_rule(p))
)
{
res = _PyPegen_seq_insert_in_front(p, elem, seq);
@@ -11252,9 +11511,9 @@ _gather_29_rule(Parser *p)
return res;
}
-// _loop0_32: ',' with_item
+// _loop0_28: ',' NAME
static asdl_seq *
-_loop0_32_rule(Parser *p)
+_loop0_28_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -11269,13 +11528,13 @@ _loop0_32_rule(Parser *p)
}
ssize_t children_capacity = 1;
ssize_t n = 0;
- { // ',' with_item
- withitem_ty elem;
+ { // ',' NAME
+ expr_ty elem;
void *literal;
while (
(literal = _PyPegen_expect_token(p, 12))
&&
- (elem = with_item_rule(p))
+ (elem = _PyPegen_name_token(p))
)
{
res = elem;
@@ -11299,32 +11558,32 @@ _loop0_32_rule(Parser *p)
}
asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_32");
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_28");
PyMem_Free(children);
return NULL;
}
for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop0_32_type, seq);
+ _PyPegen_insert_memo(p, start_mark, _loop0_28_type, seq);
return seq;
}
-// _gather_31: with_item _loop0_32
+// _gather_27: NAME _loop0_28
static asdl_seq *
-_gather_31_rule(Parser *p)
+_gather_27_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
asdl_seq * res = NULL;
int mark = p->mark;
- { // with_item _loop0_32
- withitem_ty elem;
+ { // NAME _loop0_28
+ expr_ty elem;
asdl_seq * seq;
if (
- (elem = with_item_rule(p))
+ (elem = _PyPegen_name_token(p))
&&
- (seq = _loop0_32_rule(p))
+ (seq = _loop0_28_rule(p))
)
{
res = _PyPegen_seq_insert_in_front(p, elem, seq);
@@ -11337,25 +11596,25 @@ _gather_31_rule(Parser *p)
return res;
}
-// _tmp_33: 'as' target
+// _tmp_29: ',' expression
static void *
-_tmp_33_rule(Parser *p)
+_tmp_29_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
void * res = NULL;
int mark = p->mark;
- { // 'as' target
- void *keyword;
- expr_ty t;
+ { // ',' expression
+ void *literal;
+ expr_ty z;
if (
- (keyword = _PyPegen_expect_token(p, 531))
+ (literal = _PyPegen_expect_token(p, 12))
&&
- (t = target_rule(p))
+ (z = expression_rule(p))
)
{
- res = t;
+ res = z;
if (res == NULL && PyErr_Occurred()) {
p->error_indicator = 1;
return NULL;
@@ -11369,9 +11628,9 @@ _tmp_33_rule(Parser *p)
return res;
}
-// _loop1_34: except_block
+// _loop0_30: ('.' | '...')
static asdl_seq *
-_loop1_34_rule(Parser *p)
+_loop0_30_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -11386,13 +11645,62 @@ _loop1_34_rule(Parser *p)
}
ssize_t children_capacity = 1;
ssize_t n = 0;
- { // except_block
- excepthandler_ty except_block_var;
+ { // ('.' | '...')
+ void *_tmp_130_var;
while (
- (except_block_var = except_block_rule(p))
+ (_tmp_130_var = _tmp_130_rule(p))
)
{
- res = except_block_var;
+ res = _tmp_130_var;
+ if (n == children_capacity) {
+ children_capacity *= 2;
+ children = PyMem_Realloc(children, children_capacity*sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "realloc None");
+ return NULL;
+ }
+ }
+ children[n++] = res;
+ mark = p->mark;
+ }
+ p->mark = mark;
+ }
+ asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
+ if (!seq) {
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_30");
+ PyMem_Free(children);
+ return NULL;
+ }
+ for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
+ PyMem_Free(children);
+ _PyPegen_insert_memo(p, start_mark, _loop0_30_type, seq);
+ return seq;
+}
+
+// _loop1_31: ('.' | '...')
+static asdl_seq *
+_loop1_31_rule(Parser *p)
+{
+ if (p->error_indicator) {
+ return NULL;
+ }
+ void *res = NULL;
+ int mark = p->mark;
+ int start_mark = p->mark;
+ void **children = PyMem_Malloc(sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "Parser out of memory");
+ return NULL;
+ }
+ ssize_t children_capacity = 1;
+ ssize_t n = 0;
+ { // ('.' | '...')
+ void *_tmp_131_var;
+ while (
+ (_tmp_131_var = _tmp_131_rule(p))
+ )
+ {
+ res = _tmp_131_var;
if (n == children_capacity) {
children_capacity *= 2;
children = PyMem_Realloc(children, children_capacity*sizeof(void *));
@@ -11412,71 +11720,92 @@ _loop1_34_rule(Parser *p)
}
asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_34");
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_31");
PyMem_Free(children);
return NULL;
}
for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop1_34_type, seq);
+ _PyPegen_insert_memo(p, start_mark, _loop1_31_type, seq);
return seq;
}
-// _tmp_35: 'as' target
-static void *
-_tmp_35_rule(Parser *p)
+// _loop0_33: ',' import_from_as_name
+static asdl_seq *
+_loop0_33_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
- void * res = NULL;
+ void *res = NULL;
int mark = p->mark;
- { // 'as' target
- void *keyword;
- expr_ty z;
- if (
- (keyword = _PyPegen_expect_token(p, 531))
+ int start_mark = p->mark;
+ void **children = PyMem_Malloc(sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "Parser out of memory");
+ return NULL;
+ }
+ ssize_t children_capacity = 1;
+ ssize_t n = 0;
+ { // ',' import_from_as_name
+ alias_ty elem;
+ void *literal;
+ while (
+ (literal = _PyPegen_expect_token(p, 12))
&&
- (z = target_rule(p))
+ (elem = import_from_as_name_rule(p))
)
{
- res = z;
+ res = elem;
if (res == NULL && PyErr_Occurred()) {
p->error_indicator = 1;
+ PyMem_Free(children);
return NULL;
}
- goto done;
+ if (n == children_capacity) {
+ children_capacity *= 2;
+ children = PyMem_Realloc(children, children_capacity*sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "realloc None");
+ return NULL;
+ }
+ }
+ children[n++] = res;
+ mark = p->mark;
}
p->mark = mark;
}
- res = NULL;
- done:
- return res;
+ asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
+ if (!seq) {
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_33");
+ PyMem_Free(children);
+ return NULL;
+ }
+ for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
+ PyMem_Free(children);
+ _PyPegen_insert_memo(p, start_mark, _loop0_33_type, seq);
+ return seq;
}
-// _tmp_36: 'from' expression
-static void *
-_tmp_36_rule(Parser *p)
+// _gather_32: import_from_as_name _loop0_33
+static asdl_seq *
+_gather_32_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
- void * res = NULL;
+ asdl_seq * res = NULL;
int mark = p->mark;
- { // 'from' expression
- void *keyword;
- expr_ty z;
+ { // import_from_as_name _loop0_33
+ alias_ty elem;
+ asdl_seq * seq;
if (
- (keyword = _PyPegen_expect_token(p, 514))
+ (elem = import_from_as_name_rule(p))
&&
- (z = expression_rule(p))
+ (seq = _loop0_33_rule(p))
)
{
- res = z;
- if (res == NULL && PyErr_Occurred()) {
- p->error_indicator = 1;
- return NULL;
- }
+ res = _PyPegen_seq_insert_in_front(p, elem, seq);
goto done;
}
p->mark = mark;
@@ -11486,22 +11815,22 @@ _tmp_36_rule(Parser *p)
return res;
}
-// _tmp_37: '->' annotation
+// _tmp_34: 'as' NAME
static void *
-_tmp_37_rule(Parser *p)
+_tmp_34_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
void * res = NULL;
int mark = p->mark;
- { // '->' annotation
- void *literal;
+ { // 'as' NAME
+ void *keyword;
expr_ty z;
if (
- (literal = _PyPegen_expect_token(p, 51))
+ (keyword = _PyPegen_expect_token(p, 531))
&&
- (z = annotation_rule(p))
+ (z = _PyPegen_name_token(p))
)
{
res = z;
@@ -11518,61 +11847,82 @@ _tmp_37_rule(Parser *p)
return res;
}
-// _tmp_38: ',' plain_names
-static void *
-_tmp_38_rule(Parser *p)
+// _loop0_36: ',' dotted_as_name
+static asdl_seq *
+_loop0_36_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
- void * res = NULL;
+ void *res = NULL;
int mark = p->mark;
- { // ',' plain_names
+ int start_mark = p->mark;
+ void **children = PyMem_Malloc(sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "Parser out of memory");
+ return NULL;
+ }
+ ssize_t children_capacity = 1;
+ ssize_t n = 0;
+ { // ',' dotted_as_name
+ alias_ty elem;
void *literal;
- asdl_seq* x;
- if (
+ while (
(literal = _PyPegen_expect_token(p, 12))
&&
- (x = plain_names_rule(p))
+ (elem = dotted_as_name_rule(p))
)
{
- res = x;
+ res = elem;
if (res == NULL && PyErr_Occurred()) {
p->error_indicator = 1;
+ PyMem_Free(children);
return NULL;
}
- goto done;
+ if (n == children_capacity) {
+ children_capacity *= 2;
+ children = PyMem_Realloc(children, children_capacity*sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "realloc None");
+ return NULL;
+ }
+ }
+ children[n++] = res;
+ mark = p->mark;
}
p->mark = mark;
}
- res = NULL;
- done:
- return res;
+ asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
+ if (!seq) {
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_36");
+ PyMem_Free(children);
+ return NULL;
+ }
+ for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
+ PyMem_Free(children);
+ _PyPegen_insert_memo(p, start_mark, _loop0_36_type, seq);
+ return seq;
}
-// _tmp_39: ',' names_with_default
-static void *
-_tmp_39_rule(Parser *p)
+// _gather_35: dotted_as_name _loop0_36
+static asdl_seq *
+_gather_35_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
- void * res = NULL;
+ asdl_seq * res = NULL;
int mark = p->mark;
- { // ',' names_with_default
- void *literal;
- asdl_seq* y;
+ { // dotted_as_name _loop0_36
+ alias_ty elem;
+ asdl_seq * seq;
if (
- (literal = _PyPegen_expect_token(p, 12))
+ (elem = dotted_as_name_rule(p))
&&
- (y = names_with_default_rule(p))
+ (seq = _loop0_36_rule(p))
)
{
- res = y;
- if (res == NULL && PyErr_Occurred()) {
- p->error_indicator = 1;
- return NULL;
- }
+ res = _PyPegen_seq_insert_in_front(p, elem, seq);
goto done;
}
p->mark = mark;
@@ -11582,22 +11932,22 @@ _tmp_39_rule(Parser *p)
return res;
}
-// _tmp_40: ',' star_etc?
+// _tmp_37: 'as' NAME
static void *
-_tmp_40_rule(Parser *p)
+_tmp_37_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
void * res = NULL;
int mark = p->mark;
- { // ',' star_etc?
- void *literal;
- void *z;
+ { // 'as' NAME
+ void *keyword;
+ expr_ty z;
if (
- (literal = _PyPegen_expect_token(p, 12))
+ (keyword = _PyPegen_expect_token(p, 531))
&&
- (z = star_etc_rule(p), 1)
+ (z = _PyPegen_name_token(p))
)
{
res = z;
@@ -11614,61 +11964,167 @@ _tmp_40_rule(Parser *p)
return res;
}
-// _tmp_41: ',' names_with_default
-static void *
-_tmp_41_rule(Parser *p)
+// _loop0_39: ',' with_item
+static asdl_seq *
+_loop0_39_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
- void * res = NULL;
+ void *res = NULL;
int mark = p->mark;
- { // ',' names_with_default
+ int start_mark = p->mark;
+ void **children = PyMem_Malloc(sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "Parser out of memory");
+ return NULL;
+ }
+ ssize_t children_capacity = 1;
+ ssize_t n = 0;
+ { // ',' with_item
+ withitem_ty elem;
void *literal;
- asdl_seq* y;
- if (
+ while (
(literal = _PyPegen_expect_token(p, 12))
&&
- (y = names_with_default_rule(p))
+ (elem = with_item_rule(p))
)
{
- res = y;
+ res = elem;
if (res == NULL && PyErr_Occurred()) {
p->error_indicator = 1;
+ PyMem_Free(children);
return NULL;
}
- goto done;
+ if (n == children_capacity) {
+ children_capacity *= 2;
+ children = PyMem_Realloc(children, children_capacity*sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "realloc None");
+ return NULL;
+ }
+ }
+ children[n++] = res;
+ mark = p->mark;
}
p->mark = mark;
}
- res = NULL;
- done:
- return res;
+ asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
+ if (!seq) {
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_39");
+ PyMem_Free(children);
+ return NULL;
+ }
+ for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
+ PyMem_Free(children);
+ _PyPegen_insert_memo(p, start_mark, _loop0_39_type, seq);
+ return seq;
}
-// _tmp_42: ',' star_etc?
-static void *
-_tmp_42_rule(Parser *p)
+// _gather_38: with_item _loop0_39
+static asdl_seq *
+_gather_38_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
- void * res = NULL;
+ asdl_seq * res = NULL;
int mark = p->mark;
- { // ',' star_etc?
- void *literal;
- void *z;
+ { // with_item _loop0_39
+ withitem_ty elem;
+ asdl_seq * seq;
if (
- (literal = _PyPegen_expect_token(p, 12))
+ (elem = with_item_rule(p))
&&
- (z = star_etc_rule(p), 1)
+ (seq = _loop0_39_rule(p))
)
{
- res = z;
+ res = _PyPegen_seq_insert_in_front(p, elem, seq);
+ goto done;
+ }
+ p->mark = mark;
+ }
+ res = NULL;
+ done:
+ return res;
+}
+
+// _loop0_41: ',' with_item
+static asdl_seq *
+_loop0_41_rule(Parser *p)
+{
+ if (p->error_indicator) {
+ return NULL;
+ }
+ void *res = NULL;
+ int mark = p->mark;
+ int start_mark = p->mark;
+ void **children = PyMem_Malloc(sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "Parser out of memory");
+ return NULL;
+ }
+ ssize_t children_capacity = 1;
+ ssize_t n = 0;
+ { // ',' with_item
+ withitem_ty elem;
+ void *literal;
+ while (
+ (literal = _PyPegen_expect_token(p, 12))
+ &&
+ (elem = with_item_rule(p))
+ )
+ {
+ res = elem;
if (res == NULL && PyErr_Occurred()) {
p->error_indicator = 1;
+ PyMem_Free(children);
return NULL;
}
+ if (n == children_capacity) {
+ children_capacity *= 2;
+ children = PyMem_Realloc(children, children_capacity*sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "realloc None");
+ return NULL;
+ }
+ }
+ children[n++] = res;
+ mark = p->mark;
+ }
+ p->mark = mark;
+ }
+ asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
+ if (!seq) {
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_41");
+ PyMem_Free(children);
+ return NULL;
+ }
+ for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
+ PyMem_Free(children);
+ _PyPegen_insert_memo(p, start_mark, _loop0_41_type, seq);
+ return seq;
+}
+
+// _gather_40: with_item _loop0_41
+static asdl_seq *
+_gather_40_rule(Parser *p)
+{
+ if (p->error_indicator) {
+ return NULL;
+ }
+ asdl_seq * res = NULL;
+ int mark = p->mark;
+ { // with_item _loop0_41
+ withitem_ty elem;
+ asdl_seq * seq;
+ if (
+ (elem = with_item_rule(p))
+ &&
+ (seq = _loop0_41_rule(p))
+ )
+ {
+ res = _PyPegen_seq_insert_in_front(p, elem, seq);
goto done;
}
p->mark = mark;
@@ -11678,25 +12134,25 @@ _tmp_42_rule(Parser *p)
return res;
}
-// _tmp_43: ',' names_with_default
+// _tmp_42: 'as' target
static void *
-_tmp_43_rule(Parser *p)
+_tmp_42_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
void * res = NULL;
int mark = p->mark;
- { // ',' names_with_default
- void *literal;
- asdl_seq* y;
+ { // 'as' target
+ void *keyword;
+ expr_ty t;
if (
- (literal = _PyPegen_expect_token(p, 12))
+ (keyword = _PyPegen_expect_token(p, 531))
&&
- (y = names_with_default_rule(p))
+ (t = target_rule(p))
)
{
- res = y;
+ res = t;
if (res == NULL && PyErr_Occurred()) {
p->error_indicator = 1;
return NULL;
@@ -11710,7 +12166,60 @@ _tmp_43_rule(Parser *p)
return res;
}
-// _tmp_44: ',' star_etc?
+// _loop1_43: except_block
+static asdl_seq *
+_loop1_43_rule(Parser *p)
+{
+ if (p->error_indicator) {
+ return NULL;
+ }
+ void *res = NULL;
+ int mark = p->mark;
+ int start_mark = p->mark;
+ void **children = PyMem_Malloc(sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "Parser out of memory");
+ return NULL;
+ }
+ ssize_t children_capacity = 1;
+ ssize_t n = 0;
+ { // except_block
+ excepthandler_ty except_block_var;
+ while (
+ (except_block_var = except_block_rule(p))
+ )
+ {
+ res = except_block_var;
+ if (n == children_capacity) {
+ children_capacity *= 2;
+ children = PyMem_Realloc(children, children_capacity*sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "realloc None");
+ return NULL;
+ }
+ }
+ children[n++] = res;
+ mark = p->mark;
+ }
+ p->mark = mark;
+ }
+ if (n == 0) {
+ PyMem_Free(children);
+ return NULL;
+ }
+ asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
+ if (!seq) {
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_43");
+ PyMem_Free(children);
+ return NULL;
+ }
+ for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
+ PyMem_Free(children);
+ _PyPegen_insert_memo(p, start_mark, _loop1_43_type, seq);
+ return seq;
+}
+
+// _tmp_44: 'as' target
static void *
_tmp_44_rule(Parser *p)
{
@@ -11719,13 +12228,13 @@ _tmp_44_rule(Parser *p)
}
void * res = NULL;
int mark = p->mark;
- { // ',' star_etc?
- void *literal;
- void *z;
+ { // 'as' target
+ void *keyword;
+ expr_ty z;
if (
- (literal = _PyPegen_expect_token(p, 12))
+ (keyword = _PyPegen_expect_token(p, 531))
&&
- (z = star_etc_rule(p), 1)
+ (z = target_rule(p))
)
{
res = z;
@@ -11742,7 +12251,7 @@ _tmp_44_rule(Parser *p)
return res;
}
-// _tmp_45: ',' star_etc?
+// _tmp_45: 'from' expression
static void *
_tmp_45_rule(Parser *p)
{
@@ -11751,13 +12260,13 @@ _tmp_45_rule(Parser *p)
}
void * res = NULL;
int mark = p->mark;
- { // ',' star_etc?
- void *literal;
- void *z;
+ { // 'from' expression
+ void *keyword;
+ expr_ty z;
if (
- (literal = _PyPegen_expect_token(p, 12))
+ (keyword = _PyPegen_expect_token(p, 514))
&&
- (z = star_etc_rule(p), 1)
+ (z = expression_rule(p))
)
{
res = z;
@@ -11774,7 +12283,7 @@ _tmp_45_rule(Parser *p)
return res;
}
-// _tmp_46: plain_names ','
+// _tmp_46: '->' expression
static void *
_tmp_46_rule(Parser *p)
{
@@ -11783,16 +12292,16 @@ _tmp_46_rule(Parser *p)
}
void * res = NULL;
int mark = p->mark;
- { // plain_names ','
+ { // '->' expression
void *literal;
- asdl_seq* n;
+ expr_ty z;
if (
- (n = plain_names_rule(p))
+ (literal = _PyPegen_expect_token(p, 51))
&&
- (literal = _PyPegen_expect_token(p, 12))
+ (z = expression_rule(p))
)
{
- res = n;
+ res = z;
if (res == NULL && PyErr_Occurred()) {
p->error_indicator = 1;
return NULL;
@@ -11806,9 +12315,339 @@ _tmp_46_rule(Parser *p)
return res;
}
-// _loop0_47: name_with_optional_default
+// _tmp_47: NEWLINE INDENT
+static void *
+_tmp_47_rule(Parser *p)
+{
+ if (p->error_indicator) {
+ return NULL;
+ }
+ void * res = NULL;
+ int mark = p->mark;
+ { // NEWLINE INDENT
+ void *indent_var;
+ void *newline_var;
+ if (
+ (newline_var = _PyPegen_expect_token(p, NEWLINE))
+ &&
+ (indent_var = _PyPegen_expect_token(p, INDENT))
+ )
+ {
+ res = _PyPegen_dummy_name(p, newline_var, indent_var);
+ goto done;
+ }
+ p->mark = mark;
+ }
+ res = NULL;
+ done:
+ return res;
+}
+
+// _loop0_48: param_no_default
+static asdl_seq *
+_loop0_48_rule(Parser *p)
+{
+ if (p->error_indicator) {
+ return NULL;
+ }
+ void *res = NULL;
+ int mark = p->mark;
+ int start_mark = p->mark;
+ void **children = PyMem_Malloc(sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "Parser out of memory");
+ return NULL;
+ }
+ ssize_t children_capacity = 1;
+ ssize_t n = 0;
+ { // param_no_default
+ arg_ty param_no_default_var;
+ while (
+ (param_no_default_var = param_no_default_rule(p))
+ )
+ {
+ res = param_no_default_var;
+ if (n == children_capacity) {
+ children_capacity *= 2;
+ children = PyMem_Realloc(children, children_capacity*sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "realloc None");
+ return NULL;
+ }
+ }
+ children[n++] = res;
+ mark = p->mark;
+ }
+ p->mark = mark;
+ }
+ asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
+ if (!seq) {
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_48");
+ PyMem_Free(children);
+ return NULL;
+ }
+ for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
+ PyMem_Free(children);
+ _PyPegen_insert_memo(p, start_mark, _loop0_48_type, seq);
+ return seq;
+}
+
+// _loop0_49: param_with_default
+static asdl_seq *
+_loop0_49_rule(Parser *p)
+{
+ if (p->error_indicator) {
+ return NULL;
+ }
+ void *res = NULL;
+ int mark = p->mark;
+ int start_mark = p->mark;
+ void **children = PyMem_Malloc(sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "Parser out of memory");
+ return NULL;
+ }
+ ssize_t children_capacity = 1;
+ ssize_t n = 0;
+ { // param_with_default
+ NameDefaultPair* param_with_default_var;
+ while (
+ (param_with_default_var = param_with_default_rule(p))
+ )
+ {
+ res = param_with_default_var;
+ if (n == children_capacity) {
+ children_capacity *= 2;
+ children = PyMem_Realloc(children, children_capacity*sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "realloc None");
+ return NULL;
+ }
+ }
+ children[n++] = res;
+ mark = p->mark;
+ }
+ p->mark = mark;
+ }
+ asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
+ if (!seq) {
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_49");
+ PyMem_Free(children);
+ return NULL;
+ }
+ for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
+ PyMem_Free(children);
+ _PyPegen_insert_memo(p, start_mark, _loop0_49_type, seq);
+ return seq;
+}
+
+// _loop0_50: param_with_default
+static asdl_seq *
+_loop0_50_rule(Parser *p)
+{
+ if (p->error_indicator) {
+ return NULL;
+ }
+ void *res = NULL;
+ int mark = p->mark;
+ int start_mark = p->mark;
+ void **children = PyMem_Malloc(sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "Parser out of memory");
+ return NULL;
+ }
+ ssize_t children_capacity = 1;
+ ssize_t n = 0;
+ { // param_with_default
+ NameDefaultPair* param_with_default_var;
+ while (
+ (param_with_default_var = param_with_default_rule(p))
+ )
+ {
+ res = param_with_default_var;
+ if (n == children_capacity) {
+ children_capacity *= 2;
+ children = PyMem_Realloc(children, children_capacity*sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "realloc None");
+ return NULL;
+ }
+ }
+ children[n++] = res;
+ mark = p->mark;
+ }
+ p->mark = mark;
+ }
+ asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
+ if (!seq) {
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_50");
+ PyMem_Free(children);
+ return NULL;
+ }
+ for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
+ PyMem_Free(children);
+ _PyPegen_insert_memo(p, start_mark, _loop0_50_type, seq);
+ return seq;
+}
+
+// _loop1_51: param_no_default
+static asdl_seq *
+_loop1_51_rule(Parser *p)
+{
+ if (p->error_indicator) {
+ return NULL;
+ }
+ void *res = NULL;
+ int mark = p->mark;
+ int start_mark = p->mark;
+ void **children = PyMem_Malloc(sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "Parser out of memory");
+ return NULL;
+ }
+ ssize_t children_capacity = 1;
+ ssize_t n = 0;
+ { // param_no_default
+ arg_ty param_no_default_var;
+ while (
+ (param_no_default_var = param_no_default_rule(p))
+ )
+ {
+ res = param_no_default_var;
+ if (n == children_capacity) {
+ children_capacity *= 2;
+ children = PyMem_Realloc(children, children_capacity*sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "realloc None");
+ return NULL;
+ }
+ }
+ children[n++] = res;
+ mark = p->mark;
+ }
+ p->mark = mark;
+ }
+ if (n == 0) {
+ PyMem_Free(children);
+ return NULL;
+ }
+ asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
+ if (!seq) {
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_51");
+ PyMem_Free(children);
+ return NULL;
+ }
+ for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
+ PyMem_Free(children);
+ _PyPegen_insert_memo(p, start_mark, _loop1_51_type, seq);
+ return seq;
+}
+
+// _loop0_52: param_with_default
+static asdl_seq *
+_loop0_52_rule(Parser *p)
+{
+ if (p->error_indicator) {
+ return NULL;
+ }
+ void *res = NULL;
+ int mark = p->mark;
+ int start_mark = p->mark;
+ void **children = PyMem_Malloc(sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "Parser out of memory");
+ return NULL;
+ }
+ ssize_t children_capacity = 1;
+ ssize_t n = 0;
+ { // param_with_default
+ NameDefaultPair* param_with_default_var;
+ while (
+ (param_with_default_var = param_with_default_rule(p))
+ )
+ {
+ res = param_with_default_var;
+ if (n == children_capacity) {
+ children_capacity *= 2;
+ children = PyMem_Realloc(children, children_capacity*sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "realloc None");
+ return NULL;
+ }
+ }
+ children[n++] = res;
+ mark = p->mark;
+ }
+ p->mark = mark;
+ }
+ asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
+ if (!seq) {
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_52");
+ PyMem_Free(children);
+ return NULL;
+ }
+ for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
+ PyMem_Free(children);
+ _PyPegen_insert_memo(p, start_mark, _loop0_52_type, seq);
+ return seq;
+}
+
+// _loop1_53: param_with_default
+static asdl_seq *
+_loop1_53_rule(Parser *p)
+{
+ if (p->error_indicator) {
+ return NULL;
+ }
+ void *res = NULL;
+ int mark = p->mark;
+ int start_mark = p->mark;
+ void **children = PyMem_Malloc(sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "Parser out of memory");
+ return NULL;
+ }
+ ssize_t children_capacity = 1;
+ ssize_t n = 0;
+ { // param_with_default
+ NameDefaultPair* param_with_default_var;
+ while (
+ (param_with_default_var = param_with_default_rule(p))
+ )
+ {
+ res = param_with_default_var;
+ if (n == children_capacity) {
+ children_capacity *= 2;
+ children = PyMem_Realloc(children, children_capacity*sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "realloc None");
+ return NULL;
+ }
+ }
+ children[n++] = res;
+ mark = p->mark;
+ }
+ p->mark = mark;
+ }
+ if (n == 0) {
+ PyMem_Free(children);
+ return NULL;
+ }
+ asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
+ if (!seq) {
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_53");
+ PyMem_Free(children);
+ return NULL;
+ }
+ for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
+ PyMem_Free(children);
+ _PyPegen_insert_memo(p, start_mark, _loop1_53_type, seq);
+ return seq;
+}
+
+// _loop1_54: param_no_default
static asdl_seq *
-_loop0_47_rule(Parser *p)
+_loop1_54_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -11823,13 +12662,13 @@ _loop0_47_rule(Parser *p)
}
ssize_t children_capacity = 1;
ssize_t n = 0;
- { // name_with_optional_default
- NameDefaultPair* name_with_optional_default_var;
+ { // param_no_default
+ arg_ty param_no_default_var;
while (
- (name_with_optional_default_var = name_with_optional_default_rule(p))
+ (param_no_default_var = param_no_default_rule(p))
)
{
- res = name_with_optional_default_var;
+ res = param_no_default_var;
if (n == children_capacity) {
children_capacity *= 2;
children = PyMem_Realloc(children, children_capacity*sizeof(void *));
@@ -11843,53 +12682,25 @@ _loop0_47_rule(Parser *p)
}
p->mark = mark;
}
+ if (n == 0) {
+ PyMem_Free(children);
+ return NULL;
+ }
asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_47");
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_54");
PyMem_Free(children);
return NULL;
}
for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop0_47_type, seq);
+ _PyPegen_insert_memo(p, start_mark, _loop1_54_type, seq);
return seq;
}
-// _tmp_48: ',' kwds
-static void *
-_tmp_48_rule(Parser *p)
-{
- if (p->error_indicator) {
- return NULL;
- }
- void * res = NULL;
- int mark = p->mark;
- { // ',' kwds
- arg_ty d;
- void *literal;
- if (
- (literal = _PyPegen_expect_token(p, 12))
- &&
- (d = kwds_rule(p))
- )
- {
- res = d;
- if (res == NULL && PyErr_Occurred()) {
- p->error_indicator = 1;
- return NULL;
- }
- goto done;
- }
- p->mark = mark;
- }
- res = NULL;
- done:
- return res;
-}
-
-// _loop1_49: name_with_optional_default
+// _loop1_55: param_no_default
static asdl_seq *
-_loop1_49_rule(Parser *p)
+_loop1_55_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -11904,13 +12715,13 @@ _loop1_49_rule(Parser *p)
}
ssize_t children_capacity = 1;
ssize_t n = 0;
- { // name_with_optional_default
- NameDefaultPair* name_with_optional_default_var;
+ { // param_no_default
+ arg_ty param_no_default_var;
while (
- (name_with_optional_default_var = name_with_optional_default_rule(p))
+ (param_no_default_var = param_no_default_rule(p))
)
{
- res = name_with_optional_default_var;
+ res = param_no_default_var;
if (n == children_capacity) {
children_capacity *= 2;
children = PyMem_Realloc(children, children_capacity*sizeof(void *));
@@ -11930,83 +12741,121 @@ _loop1_49_rule(Parser *p)
}
asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_49");
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_55");
PyMem_Free(children);
return NULL;
}
for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop1_49_type, seq);
+ _PyPegen_insert_memo(p, start_mark, _loop1_55_type, seq);
return seq;
}
-// _tmp_50: ',' kwds
-static void *
-_tmp_50_rule(Parser *p)
+// _loop0_56: param_no_default
+static asdl_seq *
+_loop0_56_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
- void * res = NULL;
+ void *res = NULL;
int mark = p->mark;
- { // ',' kwds
- arg_ty d;
- void *literal;
- if (
- (literal = _PyPegen_expect_token(p, 12))
- &&
- (d = kwds_rule(p))
+ int start_mark = p->mark;
+ void **children = PyMem_Malloc(sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "Parser out of memory");
+ return NULL;
+ }
+ ssize_t children_capacity = 1;
+ ssize_t n = 0;
+ { // param_no_default
+ arg_ty param_no_default_var;
+ while (
+ (param_no_default_var = param_no_default_rule(p))
)
{
- res = d;
- if (res == NULL && PyErr_Occurred()) {
- p->error_indicator = 1;
- return NULL;
+ res = param_no_default_var;
+ if (n == children_capacity) {
+ children_capacity *= 2;
+ children = PyMem_Realloc(children, children_capacity*sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "realloc None");
+ return NULL;
+ }
}
- goto done;
+ children[n++] = res;
+ mark = p->mark;
}
p->mark = mark;
}
- res = NULL;
- done:
- return res;
+ asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
+ if (!seq) {
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_56");
+ PyMem_Free(children);
+ return NULL;
+ }
+ for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
+ PyMem_Free(children);
+ _PyPegen_insert_memo(p, start_mark, _loop0_56_type, seq);
+ return seq;
}
-// _tmp_51: '=' expression
-static void *
-_tmp_51_rule(Parser *p)
+// _loop1_57: param_with_default
+static asdl_seq *
+_loop1_57_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
- void * res = NULL;
+ void *res = NULL;
int mark = p->mark;
- { // '=' expression
- expr_ty e;
- void *literal;
- if (
- (literal = _PyPegen_expect_token(p, 22))
- &&
- (e = expression_rule(p))
+ int start_mark = p->mark;
+ void **children = PyMem_Malloc(sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "Parser out of memory");
+ return NULL;
+ }
+ ssize_t children_capacity = 1;
+ ssize_t n = 0;
+ { // param_with_default
+ NameDefaultPair* param_with_default_var;
+ while (
+ (param_with_default_var = param_with_default_rule(p))
)
{
- res = e;
- if (res == NULL && PyErr_Occurred()) {
- p->error_indicator = 1;
- return NULL;
+ res = param_with_default_var;
+ if (n == children_capacity) {
+ children_capacity *= 2;
+ children = PyMem_Realloc(children, children_capacity*sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "realloc None");
+ return NULL;
+ }
}
- goto done;
+ children[n++] = res;
+ mark = p->mark;
}
p->mark = mark;
}
- res = NULL;
- done:
- return res;
+ if (n == 0) {
+ PyMem_Free(children);
+ return NULL;
+ }
+ asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
+ if (!seq) {
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_57");
+ PyMem_Free(children);
+ return NULL;
+ }
+ for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
+ PyMem_Free(children);
+ _PyPegen_insert_memo(p, start_mark, _loop1_57_type, seq);
+ return seq;
}
-// _loop0_53: ',' name_with_default
+// _loop0_58: param_no_default
static asdl_seq *
-_loop0_53_rule(Parser *p)
+_loop0_58_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -12021,21 +12870,13 @@ _loop0_53_rule(Parser *p)
}
ssize_t children_capacity = 1;
ssize_t n = 0;
- { // ',' name_with_default
- NameDefaultPair* elem;
- void *literal;
+ { // param_no_default
+ arg_ty param_no_default_var;
while (
- (literal = _PyPegen_expect_token(p, 12))
- &&
- (elem = name_with_default_rule(p))
+ (param_no_default_var = param_no_default_rule(p))
)
{
- res = elem;
- if (res == NULL && PyErr_Occurred()) {
- p->error_indicator = 1;
- PyMem_Free(children);
- return NULL;
- }
+ res = param_no_default_var;
if (n == children_capacity) {
children_capacity *= 2;
children = PyMem_Realloc(children, children_capacity*sizeof(void *));
@@ -12051,47 +12892,72 @@ _loop0_53_rule(Parser *p)
}
asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_53");
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_58");
PyMem_Free(children);
return NULL;
}
for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop0_53_type, seq);
+ _PyPegen_insert_memo(p, start_mark, _loop0_58_type, seq);
return seq;
}
-// _gather_52: name_with_default _loop0_53
+// _loop1_59: param_with_default
static asdl_seq *
-_gather_52_rule(Parser *p)
+_loop1_59_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
- asdl_seq * res = NULL;
+ void *res = NULL;
int mark = p->mark;
- { // name_with_default _loop0_53
- NameDefaultPair* elem;
- asdl_seq * seq;
- if (
- (elem = name_with_default_rule(p))
- &&
- (seq = _loop0_53_rule(p))
+ int start_mark = p->mark;
+ void **children = PyMem_Malloc(sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "Parser out of memory");
+ return NULL;
+ }
+ ssize_t children_capacity = 1;
+ ssize_t n = 0;
+ { // param_with_default
+ NameDefaultPair* param_with_default_var;
+ while (
+ (param_with_default_var = param_with_default_rule(p))
)
{
- res = _PyPegen_seq_insert_in_front(p, elem, seq);
- goto done;
+ res = param_with_default_var;
+ if (n == children_capacity) {
+ children_capacity *= 2;
+ children = PyMem_Realloc(children, children_capacity*sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "realloc None");
+ return NULL;
+ }
+ }
+ children[n++] = res;
+ mark = p->mark;
}
p->mark = mark;
}
- res = NULL;
- done:
- return res;
+ if (n == 0) {
+ PyMem_Free(children);
+ return NULL;
+ }
+ asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
+ if (!seq) {
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_59");
+ PyMem_Free(children);
+ return NULL;
+ }
+ for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
+ PyMem_Free(children);
+ _PyPegen_insert_memo(p, start_mark, _loop1_59_type, seq);
+ return seq;
}
-// _loop0_55: ',' (plain_name !'=')
+// _loop0_60: param_maybe_default
static asdl_seq *
-_loop0_55_rule(Parser *p)
+_loop0_60_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -12106,21 +12972,13 @@ _loop0_55_rule(Parser *p)
}
ssize_t children_capacity = 1;
ssize_t n = 0;
- { // ',' (plain_name !'=')
- void *elem;
- void *literal;
+ { // param_maybe_default
+ NameDefaultPair* param_maybe_default_var;
while (
- (literal = _PyPegen_expect_token(p, 12))
- &&
- (elem = _tmp_127_rule(p))
+ (param_maybe_default_var = param_maybe_default_rule(p))
)
{
- res = elem;
- if (res == NULL && PyErr_Occurred()) {
- p->error_indicator = 1;
- PyMem_Free(children);
- return NULL;
- }
+ res = param_maybe_default_var;
if (n == children_capacity) {
children_capacity *= 2;
children = PyMem_Realloc(children, children_capacity*sizeof(void *));
@@ -12136,79 +12994,72 @@ _loop0_55_rule(Parser *p)
}
asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_55");
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_60");
PyMem_Free(children);
return NULL;
}
for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop0_55_type, seq);
+ _PyPegen_insert_memo(p, start_mark, _loop0_60_type, seq);
return seq;
}
-// _gather_54: (plain_name !'=') _loop0_55
+// _loop1_61: param_maybe_default
static asdl_seq *
-_gather_54_rule(Parser *p)
+_loop1_61_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
- asdl_seq * res = NULL;
+ void *res = NULL;
int mark = p->mark;
- { // (plain_name !'=') _loop0_55
- void *elem;
- asdl_seq * seq;
- if (
- (elem = _tmp_127_rule(p))
- &&
- (seq = _loop0_55_rule(p))
- )
- {
- res = _PyPegen_seq_insert_in_front(p, elem, seq);
- goto done;
- }
- p->mark = mark;
- }
- res = NULL;
- done:
- return res;
-}
-
-// _tmp_56: ':' annotation
-static void *
-_tmp_56_rule(Parser *p)
-{
- if (p->error_indicator) {
+ int start_mark = p->mark;
+ void **children = PyMem_Malloc(sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "Parser out of memory");
return NULL;
}
- void * res = NULL;
- int mark = p->mark;
- { // ':' annotation
- void *literal;
- expr_ty z;
- if (
- (literal = _PyPegen_expect_token(p, 11))
- &&
- (z = annotation_rule(p))
+ ssize_t children_capacity = 1;
+ ssize_t n = 0;
+ { // param_maybe_default
+ NameDefaultPair* param_maybe_default_var;
+ while (
+ (param_maybe_default_var = param_maybe_default_rule(p))
)
{
- res = z;
- if (res == NULL && PyErr_Occurred()) {
- p->error_indicator = 1;
- return NULL;
+ res = param_maybe_default_var;
+ if (n == children_capacity) {
+ children_capacity *= 2;
+ children = PyMem_Realloc(children, children_capacity*sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "realloc None");
+ return NULL;
+ }
}
- goto done;
+ children[n++] = res;
+ mark = p->mark;
}
p->mark = mark;
}
- res = NULL;
- done:
- return res;
+ if (n == 0) {
+ PyMem_Free(children);
+ return NULL;
+ }
+ asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
+ if (!seq) {
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_61");
+ PyMem_Free(children);
+ return NULL;
+ }
+ for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
+ PyMem_Free(children);
+ _PyPegen_insert_memo(p, start_mark, _loop1_61_type, seq);
+ return seq;
}
-// _loop1_57: ('@' named_expression NEWLINE)
+// _loop1_62: ('@' named_expression NEWLINE)
static asdl_seq *
-_loop1_57_rule(Parser *p)
+_loop1_62_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -12224,12 +13075,12 @@ _loop1_57_rule(Parser *p)
ssize_t children_capacity = 1;
ssize_t n = 0;
{ // ('@' named_expression NEWLINE)
- void *_tmp_128_var;
+ void *_tmp_132_var;
while (
- (_tmp_128_var = _tmp_128_rule(p))
+ (_tmp_132_var = _tmp_132_rule(p))
)
{
- res = _tmp_128_var;
+ res = _tmp_132_var;
if (n == children_capacity) {
children_capacity *= 2;
children = PyMem_Realloc(children, children_capacity*sizeof(void *));
@@ -12249,19 +13100,19 @@ _loop1_57_rule(Parser *p)
}
asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_57");
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_62");
PyMem_Free(children);
return NULL;
}
for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop1_57_type, seq);
+ _PyPegen_insert_memo(p, start_mark, _loop1_62_type, seq);
return seq;
}
-// _tmp_58: '(' arguments? ')'
+// _tmp_63: '(' arguments? ')'
static void *
-_tmp_58_rule(Parser *p)
+_tmp_63_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -12294,9 +13145,9 @@ _tmp_58_rule(Parser *p)
return res;
}
-// _loop0_60: ',' star_expression
+// _loop0_65: ',' star_expression
static asdl_seq *
-_loop0_60_rule(Parser *p)
+_loop0_65_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -12341,32 +13192,32 @@ _loop0_60_rule(Parser *p)
}
asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_60");
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_65");
PyMem_Free(children);
return NULL;
}
for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop0_60_type, seq);
+ _PyPegen_insert_memo(p, start_mark, _loop0_65_type, seq);
return seq;
}
-// _gather_59: star_expression _loop0_60
+// _gather_64: star_expression _loop0_65
static asdl_seq *
-_gather_59_rule(Parser *p)
+_gather_64_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
asdl_seq * res = NULL;
int mark = p->mark;
- { // star_expression _loop0_60
+ { // star_expression _loop0_65
expr_ty elem;
asdl_seq * seq;
if (
(elem = star_expression_rule(p))
&&
- (seq = _loop0_60_rule(p))
+ (seq = _loop0_65_rule(p))
)
{
res = _PyPegen_seq_insert_in_front(p, elem, seq);
@@ -12379,9 +13230,9 @@ _gather_59_rule(Parser *p)
return res;
}
-// _loop1_61: (',' star_expression)
+// _loop1_66: (',' star_expression)
static asdl_seq *
-_loop1_61_rule(Parser *p)
+_loop1_66_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -12397,12 +13248,12 @@ _loop1_61_rule(Parser *p)
ssize_t children_capacity = 1;
ssize_t n = 0;
{ // (',' star_expression)
- void *_tmp_129_var;
+ void *_tmp_133_var;
while (
- (_tmp_129_var = _tmp_129_rule(p))
+ (_tmp_133_var = _tmp_133_rule(p))
)
{
- res = _tmp_129_var;
+ res = _tmp_133_var;
if (n == children_capacity) {
children_capacity *= 2;
children = PyMem_Realloc(children, children_capacity*sizeof(void *));
@@ -12422,19 +13273,19 @@ _loop1_61_rule(Parser *p)
}
asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_61");
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_66");
PyMem_Free(children);
return NULL;
}
for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop1_61_type, seq);
+ _PyPegen_insert_memo(p, start_mark, _loop1_66_type, seq);
return seq;
}
-// _loop0_63: ',' star_named_expression
+// _loop0_68: ',' star_named_expression
static asdl_seq *
-_loop0_63_rule(Parser *p)
+_loop0_68_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -12479,32 +13330,32 @@ _loop0_63_rule(Parser *p)
}
asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_63");
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_68");
PyMem_Free(children);
return NULL;
}
for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop0_63_type, seq);
+ _PyPegen_insert_memo(p, start_mark, _loop0_68_type, seq);
return seq;
}
-// _gather_62: star_named_expression _loop0_63
+// _gather_67: star_named_expression _loop0_68
static asdl_seq *
-_gather_62_rule(Parser *p)
+_gather_67_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
asdl_seq * res = NULL;
int mark = p->mark;
- { // star_named_expression _loop0_63
+ { // star_named_expression _loop0_68
expr_ty elem;
asdl_seq * seq;
if (
(elem = star_named_expression_rule(p))
&&
- (seq = _loop0_63_rule(p))
+ (seq = _loop0_68_rule(p))
)
{
res = _PyPegen_seq_insert_in_front(p, elem, seq);
@@ -12517,9 +13368,9 @@ _gather_62_rule(Parser *p)
return res;
}
-// _loop1_64: (',' expression)
+// _loop1_69: (',' expression)
static asdl_seq *
-_loop1_64_rule(Parser *p)
+_loop1_69_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -12535,12 +13386,12 @@ _loop1_64_rule(Parser *p)
ssize_t children_capacity = 1;
ssize_t n = 0;
{ // (',' expression)
- void *_tmp_130_var;
+ void *_tmp_134_var;
while (
- (_tmp_130_var = _tmp_130_rule(p))
+ (_tmp_134_var = _tmp_134_rule(p))
)
{
- res = _tmp_130_var;
+ res = _tmp_134_var;
if (n == children_capacity) {
children_capacity *= 2;
children = PyMem_Realloc(children, children_capacity*sizeof(void *));
@@ -12560,19 +13411,19 @@ _loop1_64_rule(Parser *p)
}
asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_64");
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_69");
PyMem_Free(children);
return NULL;
}
for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop1_64_type, seq);
+ _PyPegen_insert_memo(p, start_mark, _loop1_69_type, seq);
return seq;
}
-// _tmp_65: ',' lambda_plain_names
+// _tmp_70: ',' lambda_plain_names
static void *
-_tmp_65_rule(Parser *p)
+_tmp_70_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -12602,9 +13453,9 @@ _tmp_65_rule(Parser *p)
return res;
}
-// _tmp_66: ',' lambda_names_with_default
+// _tmp_71: ',' lambda_names_with_default
static void *
-_tmp_66_rule(Parser *p)
+_tmp_71_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -12634,9 +13485,9 @@ _tmp_66_rule(Parser *p)
return res;
}
-// _tmp_67: ',' lambda_star_etc?
+// _tmp_72: ',' lambda_star_etc?
static void *
-_tmp_67_rule(Parser *p)
+_tmp_72_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -12666,9 +13517,9 @@ _tmp_67_rule(Parser *p)
return res;
}
-// _tmp_68: ',' lambda_names_with_default
+// _tmp_73: ',' lambda_names_with_default
static void *
-_tmp_68_rule(Parser *p)
+_tmp_73_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -12698,9 +13549,9 @@ _tmp_68_rule(Parser *p)
return res;
}
-// _tmp_69: ',' lambda_star_etc?
+// _tmp_74: ',' lambda_star_etc?
static void *
-_tmp_69_rule(Parser *p)
+_tmp_74_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -12730,9 +13581,9 @@ _tmp_69_rule(Parser *p)
return res;
}
-// _tmp_70: ',' lambda_names_with_default
+// _tmp_75: ',' lambda_names_with_default
static void *
-_tmp_70_rule(Parser *p)
+_tmp_75_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -12762,9 +13613,9 @@ _tmp_70_rule(Parser *p)
return res;
}
-// _tmp_71: ',' lambda_star_etc?
+// _tmp_76: ',' lambda_star_etc?
static void *
-_tmp_71_rule(Parser *p)
+_tmp_76_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -12794,9 +13645,9 @@ _tmp_71_rule(Parser *p)
return res;
}
-// _tmp_72: ',' lambda_star_etc?
+// _tmp_77: ',' lambda_star_etc?
static void *
-_tmp_72_rule(Parser *p)
+_tmp_77_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -12826,9 +13677,9 @@ _tmp_72_rule(Parser *p)
return res;
}
-// _tmp_73: lambda_plain_names ','
+// _tmp_78: lambda_plain_names ','
static void *
-_tmp_73_rule(Parser *p)
+_tmp_78_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -12858,9 +13709,9 @@ _tmp_73_rule(Parser *p)
return res;
}
-// _loop0_74: lambda_name_with_optional_default
+// _loop0_79: lambda_name_with_optional_default
static asdl_seq *
-_loop0_74_rule(Parser *p)
+_loop0_79_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -12897,19 +13748,19 @@ _loop0_74_rule(Parser *p)
}
asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_74");
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_79");
PyMem_Free(children);
return NULL;
}
for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop0_74_type, seq);
+ _PyPegen_insert_memo(p, start_mark, _loop0_79_type, seq);
return seq;
}
-// _tmp_75: ',' lambda_kwds
+// _tmp_80: ',' lambda_kwds
static void *
-_tmp_75_rule(Parser *p)
+_tmp_80_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -12939,9 +13790,9 @@ _tmp_75_rule(Parser *p)
return res;
}
-// _loop1_76: lambda_name_with_optional_default
+// _loop1_81: lambda_name_with_optional_default
static asdl_seq *
-_loop1_76_rule(Parser *p)
+_loop1_81_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -12982,19 +13833,19 @@ _loop1_76_rule(Parser *p)
}
asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_76");
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_81");
PyMem_Free(children);
return NULL;
}
for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop1_76_type, seq);
+ _PyPegen_insert_memo(p, start_mark, _loop1_81_type, seq);
return seq;
}
-// _tmp_77: ',' lambda_kwds
+// _tmp_82: ',' lambda_kwds
static void *
-_tmp_77_rule(Parser *p)
+_tmp_82_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -13024,9 +13875,9 @@ _tmp_77_rule(Parser *p)
return res;
}
-// _tmp_78: '=' expression
+// _tmp_83: '=' expression
static void *
-_tmp_78_rule(Parser *p)
+_tmp_83_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -13056,9 +13907,9 @@ _tmp_78_rule(Parser *p)
return res;
}
-// _loop0_80: ',' lambda_name_with_default
+// _loop0_85: ',' lambda_name_with_default
static asdl_seq *
-_loop0_80_rule(Parser *p)
+_loop0_85_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -13103,32 +13954,32 @@ _loop0_80_rule(Parser *p)
}
asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_80");
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_85");
PyMem_Free(children);
return NULL;
}
for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop0_80_type, seq);
+ _PyPegen_insert_memo(p, start_mark, _loop0_85_type, seq);
return seq;
}
-// _gather_79: lambda_name_with_default _loop0_80
+// _gather_84: lambda_name_with_default _loop0_85
static asdl_seq *
-_gather_79_rule(Parser *p)
+_gather_84_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
asdl_seq * res = NULL;
int mark = p->mark;
- { // lambda_name_with_default _loop0_80
+ { // lambda_name_with_default _loop0_85
NameDefaultPair* elem;
asdl_seq * seq;
if (
(elem = lambda_name_with_default_rule(p))
&&
- (seq = _loop0_80_rule(p))
+ (seq = _loop0_85_rule(p))
)
{
res = _PyPegen_seq_insert_in_front(p, elem, seq);
@@ -13141,9 +13992,9 @@ _gather_79_rule(Parser *p)
return res;
}
-// _loop0_82: ',' (lambda_plain_name !'=')
+// _loop0_87: ',' (lambda_plain_name !'=')
static asdl_seq *
-_loop0_82_rule(Parser *p)
+_loop0_87_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -13164,7 +14015,7 @@ _loop0_82_rule(Parser *p)
while (
(literal = _PyPegen_expect_token(p, 12))
&&
- (elem = _tmp_131_rule(p))
+ (elem = _tmp_135_rule(p))
)
{
res = elem;
@@ -13188,32 +14039,32 @@ _loop0_82_rule(Parser *p)
}
asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_82");
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_87");
PyMem_Free(children);
return NULL;
}
for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop0_82_type, seq);
+ _PyPegen_insert_memo(p, start_mark, _loop0_87_type, seq);
return seq;
}
-// _gather_81: (lambda_plain_name !'=') _loop0_82
+// _gather_86: (lambda_plain_name !'=') _loop0_87
static asdl_seq *
-_gather_81_rule(Parser *p)
+_gather_86_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
asdl_seq * res = NULL;
int mark = p->mark;
- { // (lambda_plain_name !'=') _loop0_82
+ { // (lambda_plain_name !'=') _loop0_87
void *elem;
asdl_seq * seq;
if (
- (elem = _tmp_131_rule(p))
+ (elem = _tmp_135_rule(p))
&&
- (seq = _loop0_82_rule(p))
+ (seq = _loop0_87_rule(p))
)
{
res = _PyPegen_seq_insert_in_front(p, elem, seq);
@@ -13226,9 +14077,9 @@ _gather_81_rule(Parser *p)
return res;
}
-// _loop1_83: ('or' conjunction)
+// _loop1_88: ('or' conjunction)
static asdl_seq *
-_loop1_83_rule(Parser *p)
+_loop1_88_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -13244,12 +14095,12 @@ _loop1_83_rule(Parser *p)
ssize_t children_capacity = 1;
ssize_t n = 0;
{ // ('or' conjunction)
- void *_tmp_132_var;
+ void *_tmp_136_var;
while (
- (_tmp_132_var = _tmp_132_rule(p))
+ (_tmp_136_var = _tmp_136_rule(p))
)
{
- res = _tmp_132_var;
+ res = _tmp_136_var;
if (n == children_capacity) {
children_capacity *= 2;
children = PyMem_Realloc(children, children_capacity*sizeof(void *));
@@ -13269,19 +14120,19 @@ _loop1_83_rule(Parser *p)
}
asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_83");
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_88");
PyMem_Free(children);
return NULL;
}
for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop1_83_type, seq);
+ _PyPegen_insert_memo(p, start_mark, _loop1_88_type, seq);
return seq;
}
-// _loop1_84: ('and' inversion)
+// _loop1_89: ('and' inversion)
static asdl_seq *
-_loop1_84_rule(Parser *p)
+_loop1_89_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -13297,12 +14148,12 @@ _loop1_84_rule(Parser *p)
ssize_t children_capacity = 1;
ssize_t n = 0;
{ // ('and' inversion)
- void *_tmp_133_var;
+ void *_tmp_137_var;
while (
- (_tmp_133_var = _tmp_133_rule(p))
+ (_tmp_137_var = _tmp_137_rule(p))
)
{
- res = _tmp_133_var;
+ res = _tmp_137_var;
if (n == children_capacity) {
children_capacity *= 2;
children = PyMem_Realloc(children, children_capacity*sizeof(void *));
@@ -13322,19 +14173,19 @@ _loop1_84_rule(Parser *p)
}
asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_84");
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_89");
PyMem_Free(children);
return NULL;
}
for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop1_84_type, seq);
+ _PyPegen_insert_memo(p, start_mark, _loop1_89_type, seq);
return seq;
}
-// _loop1_85: compare_op_bitwise_or_pair
+// _loop1_90: compare_op_bitwise_or_pair
static asdl_seq *
-_loop1_85_rule(Parser *p)
+_loop1_90_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -13375,19 +14226,19 @@ _loop1_85_rule(Parser *p)
}
asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_85");
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_90");
PyMem_Free(children);
return NULL;
}
for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop1_85_type, seq);
+ _PyPegen_insert_memo(p, start_mark, _loop1_90_type, seq);
return seq;
}
-// _tmp_86: '!='
+// _tmp_91: '!='
static void *
-_tmp_86_rule(Parser *p)
+_tmp_91_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -13414,9 +14265,9 @@ _tmp_86_rule(Parser *p)
return res;
}
-// _loop0_88: ',' slice
+// _loop0_93: ',' slice
static asdl_seq *
-_loop0_88_rule(Parser *p)
+_loop0_93_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -13461,32 +14312,32 @@ _loop0_88_rule(Parser *p)
}
asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_88");
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_93");
PyMem_Free(children);
return NULL;
}
for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop0_88_type, seq);
+ _PyPegen_insert_memo(p, start_mark, _loop0_93_type, seq);
return seq;
}
-// _gather_87: slice _loop0_88
+// _gather_92: slice _loop0_93
static asdl_seq *
-_gather_87_rule(Parser *p)
+_gather_92_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
asdl_seq * res = NULL;
int mark = p->mark;
- { // slice _loop0_88
+ { // slice _loop0_93
expr_ty elem;
asdl_seq * seq;
if (
(elem = slice_rule(p))
&&
- (seq = _loop0_88_rule(p))
+ (seq = _loop0_93_rule(p))
)
{
res = _PyPegen_seq_insert_in_front(p, elem, seq);
@@ -13499,9 +14350,9 @@ _gather_87_rule(Parser *p)
return res;
}
-// _tmp_89: ':' expression?
+// _tmp_94: ':' expression?
static void *
-_tmp_89_rule(Parser *p)
+_tmp_94_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -13531,9 +14382,9 @@ _tmp_89_rule(Parser *p)
return res;
}
-// _tmp_90: tuple | group | genexp
+// _tmp_95: tuple | group | genexp
static void *
-_tmp_90_rule(Parser *p)
+_tmp_95_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -13578,9 +14429,9 @@ _tmp_90_rule(Parser *p)
return res;
}
-// _tmp_91: list | listcomp
+// _tmp_96: list | listcomp
static void *
-_tmp_91_rule(Parser *p)
+_tmp_96_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -13614,9 +14465,9 @@ _tmp_91_rule(Parser *p)
return res;
}
-// _tmp_92: dict | set | dictcomp | setcomp
+// _tmp_97: dict | set | dictcomp | setcomp
static void *
-_tmp_92_rule(Parser *p)
+_tmp_97_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -13672,9 +14523,9 @@ _tmp_92_rule(Parser *p)
return res;
}
-// _loop1_93: STRING
+// _loop1_98: STRING
static asdl_seq *
-_loop1_93_rule(Parser *p)
+_loop1_98_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -13715,19 +14566,19 @@ _loop1_93_rule(Parser *p)
}
asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_93");
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_98");
PyMem_Free(children);
return NULL;
}
for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop1_93_type, seq);
+ _PyPegen_insert_memo(p, start_mark, _loop1_98_type, seq);
return seq;
}
-// _tmp_94: star_named_expression ',' star_named_expressions?
+// _tmp_99: star_named_expression ',' star_named_expressions?
static void *
-_tmp_94_rule(Parser *p)
+_tmp_99_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -13760,9 +14611,9 @@ _tmp_94_rule(Parser *p)
return res;
}
-// _tmp_95: yield_expr | named_expression
+// _tmp_100: yield_expr | named_expression
static void *
-_tmp_95_rule(Parser *p)
+_tmp_100_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -13796,9 +14647,9 @@ _tmp_95_rule(Parser *p)
return res;
}
-// _loop0_97: ',' kvpair
+// _loop0_102: ',' kvpair
static asdl_seq *
-_loop0_97_rule(Parser *p)
+_loop0_102_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -13843,32 +14694,32 @@ _loop0_97_rule(Parser *p)
}
asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_97");
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_102");
PyMem_Free(children);
return NULL;
}
for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop0_97_type, seq);
+ _PyPegen_insert_memo(p, start_mark, _loop0_102_type, seq);
return seq;
}
-// _gather_96: kvpair _loop0_97
+// _gather_101: kvpair _loop0_102
static asdl_seq *
-_gather_96_rule(Parser *p)
+_gather_101_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
asdl_seq * res = NULL;
int mark = p->mark;
- { // kvpair _loop0_97
+ { // kvpair _loop0_102
KeyValuePair* elem;
asdl_seq * seq;
if (
(elem = kvpair_rule(p))
&&
- (seq = _loop0_97_rule(p))
+ (seq = _loop0_102_rule(p))
)
{
res = _PyPegen_seq_insert_in_front(p, elem, seq);
@@ -13881,9 +14732,9 @@ _gather_96_rule(Parser *p)
return res;
}
-// _loop1_98: (ASYNC? 'for' star_targets 'in' disjunction (('if' disjunction))*)
+// _loop1_103: (ASYNC? 'for' star_targets 'in' disjunction (('if' disjunction))*)
static asdl_seq *
-_loop1_98_rule(Parser *p)
+_loop1_103_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -13899,12 +14750,12 @@ _loop1_98_rule(Parser *p)
ssize_t children_capacity = 1;
ssize_t n = 0;
{ // (ASYNC? 'for' star_targets 'in' disjunction (('if' disjunction))*)
- void *_tmp_134_var;
+ void *_tmp_138_var;
while (
- (_tmp_134_var = _tmp_134_rule(p))
+ (_tmp_138_var = _tmp_138_rule(p))
)
{
- res = _tmp_134_var;
+ res = _tmp_138_var;
if (n == children_capacity) {
children_capacity *= 2;
children = PyMem_Realloc(children, children_capacity*sizeof(void *));
@@ -13924,19 +14775,19 @@ _loop1_98_rule(Parser *p)
}
asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_98");
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_103");
PyMem_Free(children);
return NULL;
}
for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop1_98_type, seq);
+ _PyPegen_insert_memo(p, start_mark, _loop1_103_type, seq);
return seq;
}
-// _tmp_99: ',' args
+// _tmp_104: ',' args
static void *
-_tmp_99_rule(Parser *p)
+_tmp_104_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -13966,9 +14817,9 @@ _tmp_99_rule(Parser *p)
return res;
}
-// _tmp_100: ',' args
+// _tmp_105: ',' args
static void *
-_tmp_100_rule(Parser *p)
+_tmp_105_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -13998,9 +14849,9 @@ _tmp_100_rule(Parser *p)
return res;
}
-// _loop0_102: ',' kwarg_or_starred
+// _loop0_107: ',' kwarg_or_starred
static asdl_seq *
-_loop0_102_rule(Parser *p)
+_loop0_107_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -14045,32 +14896,32 @@ _loop0_102_rule(Parser *p)
}
asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_102");
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_107");
PyMem_Free(children);
return NULL;
}
for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop0_102_type, seq);
+ _PyPegen_insert_memo(p, start_mark, _loop0_107_type, seq);
return seq;
}
-// _gather_101: kwarg_or_starred _loop0_102
+// _gather_106: kwarg_or_starred _loop0_107
static asdl_seq *
-_gather_101_rule(Parser *p)
+_gather_106_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
asdl_seq * res = NULL;
int mark = p->mark;
- { // kwarg_or_starred _loop0_102
+ { // kwarg_or_starred _loop0_107
KeywordOrStarred* elem;
asdl_seq * seq;
if (
(elem = kwarg_or_starred_rule(p))
&&
- (seq = _loop0_102_rule(p))
+ (seq = _loop0_107_rule(p))
)
{
res = _PyPegen_seq_insert_in_front(p, elem, seq);
@@ -14083,9 +14934,9 @@ _gather_101_rule(Parser *p)
return res;
}
-// _loop0_104: ',' kwarg_or_double_starred
+// _loop0_109: ',' kwarg_or_double_starred
static asdl_seq *
-_loop0_104_rule(Parser *p)
+_loop0_109_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -14130,32 +14981,32 @@ _loop0_104_rule(Parser *p)
}
asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_104");
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_109");
PyMem_Free(children);
return NULL;
}
for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop0_104_type, seq);
+ _PyPegen_insert_memo(p, start_mark, _loop0_109_type, seq);
return seq;
}
-// _gather_103: kwarg_or_double_starred _loop0_104
+// _gather_108: kwarg_or_double_starred _loop0_109
static asdl_seq *
-_gather_103_rule(Parser *p)
+_gather_108_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
asdl_seq * res = NULL;
int mark = p->mark;
- { // kwarg_or_double_starred _loop0_104
+ { // kwarg_or_double_starred _loop0_109
KeywordOrStarred* elem;
asdl_seq * seq;
if (
(elem = kwarg_or_double_starred_rule(p))
&&
- (seq = _loop0_104_rule(p))
+ (seq = _loop0_109_rule(p))
)
{
res = _PyPegen_seq_insert_in_front(p, elem, seq);
@@ -14168,9 +15019,9 @@ _gather_103_rule(Parser *p)
return res;
}
-// _loop0_106: ',' kwarg_or_starred
+// _loop0_111: ',' kwarg_or_starred
static asdl_seq *
-_loop0_106_rule(Parser *p)
+_loop0_111_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -14215,32 +15066,32 @@ _loop0_106_rule(Parser *p)
}
asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_106");
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_111");
PyMem_Free(children);
return NULL;
}
for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop0_106_type, seq);
+ _PyPegen_insert_memo(p, start_mark, _loop0_111_type, seq);
return seq;
}
-// _gather_105: kwarg_or_starred _loop0_106
+// _gather_110: kwarg_or_starred _loop0_111
static asdl_seq *
-_gather_105_rule(Parser *p)
+_gather_110_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
asdl_seq * res = NULL;
int mark = p->mark;
- { // kwarg_or_starred _loop0_106
+ { // kwarg_or_starred _loop0_111
KeywordOrStarred* elem;
asdl_seq * seq;
if (
(elem = kwarg_or_starred_rule(p))
&&
- (seq = _loop0_106_rule(p))
+ (seq = _loop0_111_rule(p))
)
{
res = _PyPegen_seq_insert_in_front(p, elem, seq);
@@ -14253,9 +15104,9 @@ _gather_105_rule(Parser *p)
return res;
}
-// _loop0_108: ',' kwarg_or_double_starred
+// _loop0_113: ',' kwarg_or_double_starred
static asdl_seq *
-_loop0_108_rule(Parser *p)
+_loop0_113_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -14300,32 +15151,32 @@ _loop0_108_rule(Parser *p)
}
asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_108");
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_113");
PyMem_Free(children);
return NULL;
}
for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop0_108_type, seq);
+ _PyPegen_insert_memo(p, start_mark, _loop0_113_type, seq);
return seq;
}
-// _gather_107: kwarg_or_double_starred _loop0_108
+// _gather_112: kwarg_or_double_starred _loop0_113
static asdl_seq *
-_gather_107_rule(Parser *p)
+_gather_112_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
asdl_seq * res = NULL;
int mark = p->mark;
- { // kwarg_or_double_starred _loop0_108
+ { // kwarg_or_double_starred _loop0_113
KeywordOrStarred* elem;
asdl_seq * seq;
if (
(elem = kwarg_or_double_starred_rule(p))
&&
- (seq = _loop0_108_rule(p))
+ (seq = _loop0_113_rule(p))
)
{
res = _PyPegen_seq_insert_in_front(p, elem, seq);
@@ -14338,9 +15189,9 @@ _gather_107_rule(Parser *p)
return res;
}
-// _loop0_109: (',' star_target)
+// _loop0_114: (',' star_target)
static asdl_seq *
-_loop0_109_rule(Parser *p)
+_loop0_114_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -14356,12 +15207,12 @@ _loop0_109_rule(Parser *p)
ssize_t children_capacity = 1;
ssize_t n = 0;
{ // (',' star_target)
- void *_tmp_135_var;
+ void *_tmp_139_var;
while (
- (_tmp_135_var = _tmp_135_rule(p))
+ (_tmp_139_var = _tmp_139_rule(p))
)
{
- res = _tmp_135_var;
+ res = _tmp_139_var;
if (n == children_capacity) {
children_capacity *= 2;
children = PyMem_Realloc(children, children_capacity*sizeof(void *));
@@ -14377,19 +15228,19 @@ _loop0_109_rule(Parser *p)
}
asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_109");
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_114");
PyMem_Free(children);
return NULL;
}
for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop0_109_type, seq);
+ _PyPegen_insert_memo(p, start_mark, _loop0_114_type, seq);
return seq;
}
-// _loop0_111: ',' star_target
+// _loop0_116: ',' star_target
static asdl_seq *
-_loop0_111_rule(Parser *p)
+_loop0_116_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -14434,32 +15285,32 @@ _loop0_111_rule(Parser *p)
}
asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_111");
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_116");
PyMem_Free(children);
return NULL;
}
for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop0_111_type, seq);
+ _PyPegen_insert_memo(p, start_mark, _loop0_116_type, seq);
return seq;
}
-// _gather_110: star_target _loop0_111
+// _gather_115: star_target _loop0_116
static asdl_seq *
-_gather_110_rule(Parser *p)
+_gather_115_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
asdl_seq * res = NULL;
int mark = p->mark;
- { // star_target _loop0_111
+ { // star_target _loop0_116
expr_ty elem;
asdl_seq * seq;
if (
(elem = star_target_rule(p))
&&
- (seq = _loop0_111_rule(p))
+ (seq = _loop0_116_rule(p))
)
{
res = _PyPegen_seq_insert_in_front(p, elem, seq);
@@ -14472,9 +15323,9 @@ _gather_110_rule(Parser *p)
return res;
}
-// _tmp_112: !'*' star_target
+// _tmp_117: !'*' star_target
static void *
-_tmp_112_rule(Parser *p)
+_tmp_117_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -14499,9 +15350,9 @@ _tmp_112_rule(Parser *p)
return res;
}
-// _loop0_114: ',' del_target
+// _loop0_119: ',' del_target
static asdl_seq *
-_loop0_114_rule(Parser *p)
+_loop0_119_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -14546,32 +15397,32 @@ _loop0_114_rule(Parser *p)
}
asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_114");
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_119");
PyMem_Free(children);
return NULL;
}
for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop0_114_type, seq);
+ _PyPegen_insert_memo(p, start_mark, _loop0_119_type, seq);
return seq;
}
-// _gather_113: del_target _loop0_114
+// _gather_118: del_target _loop0_119
static asdl_seq *
-_gather_113_rule(Parser *p)
+_gather_118_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
asdl_seq * res = NULL;
int mark = p->mark;
- { // del_target _loop0_114
+ { // del_target _loop0_119
expr_ty elem;
asdl_seq * seq;
if (
(elem = del_target_rule(p))
&&
- (seq = _loop0_114_rule(p))
+ (seq = _loop0_119_rule(p))
)
{
res = _PyPegen_seq_insert_in_front(p, elem, seq);
@@ -14584,9 +15435,9 @@ _gather_113_rule(Parser *p)
return res;
}
-// _loop0_116: ',' target
+// _loop0_121: ',' target
static asdl_seq *
-_loop0_116_rule(Parser *p)
+_loop0_121_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -14631,32 +15482,32 @@ _loop0_116_rule(Parser *p)
}
asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_116");
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_121");
PyMem_Free(children);
return NULL;
}
for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop0_116_type, seq);
+ _PyPegen_insert_memo(p, start_mark, _loop0_121_type, seq);
return seq;
}
-// _gather_115: target _loop0_116
+// _gather_120: target _loop0_121
static asdl_seq *
-_gather_115_rule(Parser *p)
+_gather_120_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
asdl_seq * res = NULL;
int mark = p->mark;
- { // target _loop0_116
+ { // target _loop0_121
expr_ty elem;
asdl_seq * seq;
if (
(elem = target_rule(p))
&&
- (seq = _loop0_116_rule(p))
+ (seq = _loop0_121_rule(p))
)
{
res = _PyPegen_seq_insert_in_front(p, elem, seq);
@@ -14669,9 +15520,9 @@ _gather_115_rule(Parser *p)
return res;
}
-// _tmp_117: args | expression for_if_clauses
+// _tmp_122: args | expression for_if_clauses
static void *
-_tmp_117_rule(Parser *p)
+_tmp_122_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -14708,9 +15559,9 @@ _tmp_117_rule(Parser *p)
return res;
}
-// _tmp_118: '=' annotated_rhs
+// _tmp_123: '=' annotated_rhs
static void *
-_tmp_118_rule(Parser *p)
+_tmp_123_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -14736,9 +15587,9 @@ _tmp_118_rule(Parser *p)
return res;
}
-// _tmp_119: '=' | augassign
+// _tmp_124: '=' | augassign
static void *
-_tmp_119_rule(Parser *p)
+_tmp_124_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -14772,9 +15623,9 @@ _tmp_119_rule(Parser *p)
return res;
}
-// _tmp_120: yield_expr | star_expressions
+// _tmp_125: yield_expr | star_expressions
static void *
-_tmp_120_rule(Parser *p)
+_tmp_125_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -14808,9 +15659,9 @@ _tmp_120_rule(Parser *p)
return res;
}
-// _tmp_121: '[' | '(' | '{'
+// _tmp_126: '[' | '(' | '{'
static void *
-_tmp_121_rule(Parser *p)
+_tmp_126_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -14855,37 +15706,58 @@ _tmp_121_rule(Parser *p)
return res;
}
-// _tmp_122: plain_names ','
-static void *
-_tmp_122_rule(Parser *p)
+// _loop0_127: param_no_default
+static asdl_seq *
+_loop0_127_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
}
- void * res = NULL;
+ void *res = NULL;
int mark = p->mark;
- { // plain_names ','
- void *literal;
- asdl_seq* plain_names_var;
- if (
- (plain_names_var = plain_names_rule(p))
- &&
- (literal = _PyPegen_expect_token(p, 12))
+ int start_mark = p->mark;
+ void **children = PyMem_Malloc(sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "Parser out of memory");
+ return NULL;
+ }
+ ssize_t children_capacity = 1;
+ ssize_t n = 0;
+ { // param_no_default
+ arg_ty param_no_default_var;
+ while (
+ (param_no_default_var = param_no_default_rule(p))
)
{
- res = _PyPegen_dummy_name(p, plain_names_var, literal);
- goto done;
+ res = param_no_default_var;
+ if (n == children_capacity) {
+ children_capacity *= 2;
+ children = PyMem_Realloc(children, children_capacity*sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "realloc None");
+ return NULL;
+ }
+ }
+ children[n++] = res;
+ mark = p->mark;
}
p->mark = mark;
}
- res = NULL;
- done:
- return res;
+ asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
+ if (!seq) {
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_127");
+ PyMem_Free(children);
+ return NULL;
+ }
+ for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
+ PyMem_Free(children);
+ _PyPegen_insert_memo(p, start_mark, _loop0_127_type, seq);
+ return seq;
}
-// _tmp_123: slash_with_default | names_with_default
+// _tmp_128: slash_with_default | param_with_default+
static void *
-_tmp_123_rule(Parser *p)
+_tmp_128_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -14903,13 +15775,13 @@ _tmp_123_rule(Parser *p)
}
p->mark = mark;
}
- { // names_with_default
- asdl_seq* names_with_default_var;
+ { // param_with_default+
+ asdl_seq * _loop1_140_var;
if (
- (names_with_default_var = names_with_default_rule(p))
+ (_loop1_140_var = _loop1_140_rule(p))
)
{
- res = names_with_default_var;
+ res = _loop1_140_var;
goto done;
}
p->mark = mark;
@@ -14919,9 +15791,9 @@ _tmp_123_rule(Parser *p)
return res;
}
-// _tmp_124: star_targets '='
+// _tmp_129: star_targets '='
static void *
-_tmp_124_rule(Parser *p)
+_tmp_129_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -14951,9 +15823,9 @@ _tmp_124_rule(Parser *p)
return res;
}
-// _tmp_125: '.' | '...'
+// _tmp_130: '.' | '...'
static void *
-_tmp_125_rule(Parser *p)
+_tmp_130_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -14987,9 +15859,9 @@ _tmp_125_rule(Parser *p)
return res;
}
-// _tmp_126: '.' | '...'
+// _tmp_131: '.' | '...'
static void *
-_tmp_126_rule(Parser *p)
+_tmp_131_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -15023,36 +15895,9 @@ _tmp_126_rule(Parser *p)
return res;
}
-// _tmp_127: plain_name !'='
-static void *
-_tmp_127_rule(Parser *p)
-{
- if (p->error_indicator) {
- return NULL;
- }
- void * res = NULL;
- int mark = p->mark;
- { // plain_name !'='
- arg_ty plain_name_var;
- if (
- (plain_name_var = plain_name_rule(p))
- &&
- _PyPegen_lookahead_with_int(0, _PyPegen_expect_token, p, 22)
- )
- {
- res = plain_name_var;
- goto done;
- }
- p->mark = mark;
- }
- res = NULL;
- done:
- return res;
-}
-
-// _tmp_128: '@' named_expression NEWLINE
+// _tmp_132: '@' named_expression NEWLINE
static void *
-_tmp_128_rule(Parser *p)
+_tmp_132_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -15085,9 +15930,9 @@ _tmp_128_rule(Parser *p)
return res;
}
-// _tmp_129: ',' star_expression
+// _tmp_133: ',' star_expression
static void *
-_tmp_129_rule(Parser *p)
+_tmp_133_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -15117,9 +15962,9 @@ _tmp_129_rule(Parser *p)
return res;
}
-// _tmp_130: ',' expression
+// _tmp_134: ',' expression
static void *
-_tmp_130_rule(Parser *p)
+_tmp_134_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -15149,9 +15994,9 @@ _tmp_130_rule(Parser *p)
return res;
}
-// _tmp_131: lambda_plain_name !'='
+// _tmp_135: lambda_plain_name !'='
static void *
-_tmp_131_rule(Parser *p)
+_tmp_135_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -15176,9 +16021,9 @@ _tmp_131_rule(Parser *p)
return res;
}
-// _tmp_132: 'or' conjunction
+// _tmp_136: 'or' conjunction
static void *
-_tmp_132_rule(Parser *p)
+_tmp_136_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -15208,9 +16053,9 @@ _tmp_132_rule(Parser *p)
return res;
}
-// _tmp_133: 'and' inversion
+// _tmp_137: 'and' inversion
static void *
-_tmp_133_rule(Parser *p)
+_tmp_137_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -15240,9 +16085,9 @@ _tmp_133_rule(Parser *p)
return res;
}
-// _tmp_134: ASYNC? 'for' star_targets 'in' disjunction (('if' disjunction))*
+// _tmp_138: ASYNC? 'for' star_targets 'in' disjunction (('if' disjunction))*
static void *
-_tmp_134_rule(Parser *p)
+_tmp_138_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -15267,7 +16112,7 @@ _tmp_134_rule(Parser *p)
&&
(b = disjunction_rule(p))
&&
- (c = _loop0_136_rule(p))
+ (c = _loop0_141_rule(p))
)
{
res = _Py_comprehension ( a , b , c , y != NULL , p -> arena );
@@ -15284,9 +16129,9 @@ _tmp_134_rule(Parser *p)
return res;
}
-// _tmp_135: ',' star_target
+// _tmp_139: ',' star_target
static void *
-_tmp_135_rule(Parser *p)
+_tmp_139_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -15316,9 +16161,62 @@ _tmp_135_rule(Parser *p)
return res;
}
-// _loop0_136: ('if' disjunction)
+// _loop1_140: param_with_default
+static asdl_seq *
+_loop1_140_rule(Parser *p)
+{
+ if (p->error_indicator) {
+ return NULL;
+ }
+ void *res = NULL;
+ int mark = p->mark;
+ int start_mark = p->mark;
+ void **children = PyMem_Malloc(sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "Parser out of memory");
+ return NULL;
+ }
+ ssize_t children_capacity = 1;
+ ssize_t n = 0;
+ { // param_with_default
+ NameDefaultPair* param_with_default_var;
+ while (
+ (param_with_default_var = param_with_default_rule(p))
+ )
+ {
+ res = param_with_default_var;
+ if (n == children_capacity) {
+ children_capacity *= 2;
+ children = PyMem_Realloc(children, children_capacity*sizeof(void *));
+ if (!children) {
+ PyErr_Format(PyExc_MemoryError, "realloc None");
+ return NULL;
+ }
+ }
+ children[n++] = res;
+ mark = p->mark;
+ }
+ p->mark = mark;
+ }
+ if (n == 0) {
+ PyMem_Free(children);
+ return NULL;
+ }
+ asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
+ if (!seq) {
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_140");
+ PyMem_Free(children);
+ return NULL;
+ }
+ for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
+ PyMem_Free(children);
+ _PyPegen_insert_memo(p, start_mark, _loop1_140_type, seq);
+ return seq;
+}
+
+// _loop0_141: ('if' disjunction)
static asdl_seq *
-_loop0_136_rule(Parser *p)
+_loop0_141_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -15334,12 +16232,12 @@ _loop0_136_rule(Parser *p)
ssize_t children_capacity = 1;
ssize_t n = 0;
{ // ('if' disjunction)
- void *_tmp_137_var;
+ void *_tmp_142_var;
while (
- (_tmp_137_var = _tmp_137_rule(p))
+ (_tmp_142_var = _tmp_142_rule(p))
)
{
- res = _tmp_137_var;
+ res = _tmp_142_var;
if (n == children_capacity) {
children_capacity *= 2;
children = PyMem_Realloc(children, children_capacity*sizeof(void *));
@@ -15355,19 +16253,19 @@ _loop0_136_rule(Parser *p)
}
asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);
if (!seq) {
- PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_136");
+ PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_141");
PyMem_Free(children);
return NULL;
}
for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);
PyMem_Free(children);
- _PyPegen_insert_memo(p, start_mark, _loop0_136_type, seq);
+ _PyPegen_insert_memo(p, start_mark, _loop0_141_type, seq);
return seq;
}
-// _tmp_137: 'if' disjunction
+// _tmp_142: 'if' disjunction
static void *
-_tmp_137_rule(Parser *p)
+_tmp_142_rule(Parser *p)
{
if (p->error_indicator) {
return NULL;
@@ -15412,6 +16310,8 @@ _PyPegen_parse(Parser *p)
result = interactive_rule(p);
} else if (p->start_rule == Py_eval_input) {
result = eval_rule(p);
+ } else if (p->start_rule == Py_func_type_input) {
+ result = func_type_rule(p);
} else if (p->start_rule == Py_fstring_input) {
result = fstring_rule(p);
}
diff --git a/Parser/pegen/pegen.c b/Parser/pegen/pegen.c
index 942447b0f8fd1..5a2491c181f98 100644
--- a/Parser/pegen/pegen.c
+++ b/Parser/pegen/pegen.c
@@ -5,6 +5,39 @@
#include "pegen.h"
#include "parse_string.h"
+PyObject *
+_PyPegen_new_type_comment(Parser *p, char *s)
+{
+ PyObject *res = PyUnicode_DecodeUTF8(s, strlen(s), NULL);
+ if (res == NULL) {
+ return NULL;
+ }
+ if (PyArena_AddPyObject(p->arena, res) < 0) {
+ Py_DECREF(res);
+ return NULL;
+ }
+ return res;
+}
+
+arg_ty
+_PyPegen_add_type_comment_to_arg(Parser *p, arg_ty a, Token *tc)
+{
+ if (tc == NULL) {
+ return a;
+ }
+ char *bytes = PyBytes_AsString(tc->bytes);
+ if (bytes == NULL) {
+ return NULL;
+ }
+ PyObject *tco = _PyPegen_new_type_comment(p, bytes);
+ if (tco == NULL) {
+ return NULL;
+ }
+ return arg(a->arg, a->annotation, tco,
+ a->lineno, a->col_offset, a->end_lineno, a->end_col_offset,
+ p->arena);
+}
+
static int
init_normalization(Parser *p)
{
@@ -539,11 +572,66 @@ _get_keyword_or_name_type(Parser *p, const char *name, int name_len)
return NAME;
}
+static int
+growable_comment_array_init(growable_comment_array *arr, size_t initial_size) {
+ assert(initial_size > 0);
+ arr->items = PyMem_Malloc(initial_size * sizeof(*arr->items));
+ arr->size = initial_size;
+ arr->num_items = 0;
+
+ return arr->items != NULL;
+}
+
+static int
+growable_comment_array_add(growable_comment_array *arr, int lineno, char *comment) {
+ if (arr->num_items >= arr->size) {
+ size_t new_size = arr->size * 2;
+ void *new_items_array = PyMem_Realloc(arr->items, new_size * sizeof(*arr->items));
+ if (!new_items_array) {
+ return 0;
+ }
+ arr->items = new_items_array;
+ arr->size = new_size;
+ }
+
+ arr->items[arr->num_items].lineno = lineno;
+ arr->items[arr->num_items].comment = comment; // Take ownership
+ arr->num_items++;
+ return 1;
+}
+
+static void
+growable_comment_array_deallocate(growable_comment_array *arr) {
+ for (unsigned i = 0; i < arr->num_items; i++) {
+ PyMem_Free(arr->items[i].comment);
+ }
+ PyMem_Free(arr->items);
+}
+
int
_PyPegen_fill_token(Parser *p)
{
const char *start, *end;
int type = PyTokenizer_Get(p->tok, &start, &end);
+
+ // Record and skip '# type: ignore' comments
+ while (type == TYPE_IGNORE) {
+ Py_ssize_t len = end - start;
+ char *tag = PyMem_Malloc(len + 1);
+ if (tag == NULL) {
+ PyErr_NoMemory();
+ return -1;
+ }
+ strncpy(tag, start, len);
+ tag[len] = '\0';
+ // Ownership of tag passes to the growable array
+ if (!growable_comment_array_add(&p->type_ignore_comments, p->tok->lineno, tag)) {
+ PyErr_NoMemory();
+ return -1;
+ }
+ type = PyTokenizer_Get(p->tok, &start, &end);
+ }
+
if (type == ERRORTOKEN) {
if (p->tok->done == E_DECODE) {
return raise_decode_error(p);
@@ -919,6 +1007,7 @@ _PyPegen_Parser_Free(Parser *p)
PyMem_Free(p->tokens[i]);
}
PyMem_Free(p->tokens);
+ growable_comment_array_deallocate(&p->type_ignore_comments);
PyMem_Free(p);
}
@@ -961,13 +1050,19 @@ _PyPegen_Parser_New(struct tok_state *tok, int start_rule, int flags,
PyMem_Free(p);
return (Parser *) PyErr_NoMemory();
}
- p->tokens[0] = PyMem_Malloc(sizeof(Token));
+ p->tokens[0] = PyMem_Calloc(1, sizeof(Token));
if (!p->tokens) {
PyMem_Free(p->tokens);
PyMem_Free(p);
return (Parser *) PyErr_NoMemory();
}
- memset(p->tokens[0], '\0', sizeof(Token));
+ if (!growable_comment_array_init(&p->type_ignore_comments, 10)) {
+ PyMem_Free(p->tokens[0]);
+ PyMem_Free(p->tokens);
+ PyMem_Free(p);
+ return (Parser *) PyErr_NoMemory();
+ }
+
p->mark = 0;
p->fill = 0;
p->size = 1;
@@ -1099,6 +1194,8 @@ _PyPegen_run_parser_from_string(const char *str, int start_rule, PyObject *filen
mod_ty result = NULL;
int parser_flags = compute_parser_flags(flags);
+ tok->type_comments = (parser_flags & PyPARSE_TYPE_COMMENTS) > 0;
+
Parser *p = _PyPegen_Parser_New(tok, start_rule, parser_flags, NULL, arena);
if (p == NULL) {
goto error;
@@ -1155,6 +1252,27 @@ _PyPegen_seq_insert_in_front(Parser *p, void *a, asdl_seq *seq)
return new_seq;
}
+/* Creates a copy of seq and appends a to it */
+asdl_seq *
+_PyPegen_seq_append_to_end(Parser *p, asdl_seq *seq, void *a)
+{
+ assert(a != NULL);
+ if (!seq) {
+ return _PyPegen_singleton_seq(p, a);
+ }
+
+ asdl_seq *new_seq = _Py_asdl_seq_new(asdl_seq_LEN(seq) + 1, p->arena);
+ if (!new_seq) {
+ return NULL;
+ }
+
+ for (Py_ssize_t i = 0, l = asdl_seq_LEN(new_seq); i + 1 < l; i++) {
+ asdl_seq_SET(new_seq, i, asdl_seq_GET(seq, i));
+ }
+ asdl_seq_SET(new_seq, asdl_seq_LEN(new_seq) - 1, a);
+ return new_seq;
+}
+
static Py_ssize_t
_get_flattened_seq_size(asdl_seq *seqs)
{
@@ -1483,13 +1601,13 @@ _PyPegen_get_values(Parser *p, asdl_seq *seq)
/* Constructs a NameDefaultPair */
NameDefaultPair *
-_PyPegen_name_default_pair(Parser *p, arg_ty arg, expr_ty value)
+_PyPegen_name_default_pair(Parser *p, arg_ty arg, expr_ty value, Token *tc)
{
NameDefaultPair *a = PyArena_Malloc(p->arena, sizeof(NameDefaultPair));
if (!a) {
return NULL;
}
- a->arg = arg;
+ a->arg = _PyPegen_add_type_comment_to_arg(p, arg, tc);
a->value = value;
return a;
}
@@ -1946,3 +2064,28 @@ _PyPegen_concatenate_strings(Parser *p, asdl_seq *strings)
}
return NULL;
}
+
+mod_ty
+_PyPegen_make_module(Parser *p, asdl_seq *a) {
+ asdl_seq *type_ignores = NULL;
+ Py_ssize_t num = p->type_ignore_comments.num_items;
+ if (num > 0) {
+ // Turn the raw (comment, lineno) pairs into TypeIgnore objects in the arena
+ type_ignores = _Py_asdl_seq_new(num, p->arena);
+ if (type_ignores == NULL) {
+ return NULL;
+ }
+ for (int i = 0; i < num; i++) {
+ PyObject *tag = _PyPegen_new_type_comment(p, p->type_ignore_comments.items[i].comment);
+ if (tag == NULL) {
+ return NULL;
+ }
+ type_ignore_ty ti = TypeIgnore(p->type_ignore_comments.items[i].lineno, tag, p->arena);
+ if (ti == NULL) {
+ return NULL;
+ }
+ asdl_seq_SET(type_ignores, i, ti);
+ }
+ }
+ return Module(a, type_ignores, p->arena);
+}
diff --git a/Parser/pegen/pegen.h b/Parser/pegen/pegen.h
index 99ec0f44e6518..3af4bb29aa177 100644
--- a/Parser/pegen/pegen.h
+++ b/Parser/pegen/pegen.h
@@ -43,6 +43,16 @@ typedef struct {
int type;
} KeywordToken;
+
+typedef struct {
+ struct {
+ int lineno;
+ char *comment; // The " <tag>" in "# type: ignore <tag>"
+ } *items;
+ size_t size;
+ size_t num_items;
+} growable_comment_array;
+
typedef struct {
struct tok_state *tok;
Token **tokens;
@@ -59,6 +69,7 @@ typedef struct {
int starting_col_offset;
int error_indicator;
int flags;
+ growable_comment_array type_ignore_comments;
} Parser;
typedef struct {
@@ -110,13 +121,7 @@ int _PyPegen_lookahead(int, void *(func)(Parser *), Parser *);
Token *_PyPegen_expect_token(Parser *p, int type);
Token *_PyPegen_get_last_nonnwhitespace_token(Parser *);
int _PyPegen_fill_token(Parser *p);
-void *_PyPegen_async_token(Parser *p);
-void *_PyPegen_await_token(Parser *p);
-void *_PyPegen_endmarker_token(Parser *p);
expr_ty _PyPegen_name_token(Parser *p);
-void *_PyPegen_newline_token(Parser *p);
-void *_PyPegen_indent_token(Parser *p);
-void *_PyPegen_dedent_token(Parser *p);
expr_ty _PyPegen_number_token(Parser *p);
void *_PyPegen_string_token(Parser *p);
const char *_PyPegen_get_expr_name(expr_ty);
@@ -153,6 +158,29 @@ CHECK_CALL_NULL_ALLOWED(Parser *p, void *result)
#define CHECK(result) CHECK_CALL(p, result)
#define CHECK_NULL_ALLOWED(result) CHECK_CALL_NULL_ALLOWED(p, result)
+PyObject *_PyPegen_new_type_comment(Parser *, char *);
+
+Py_LOCAL_INLINE(PyObject *)
+NEW_TYPE_COMMENT(Parser *p, Token *tc)
+{
+ if (tc == NULL) {
+ return NULL;
+ }
+ char *bytes = PyBytes_AsString(tc->bytes);
+ if (bytes == NULL) {
+ goto error;
+ }
+ PyObject *tco = _PyPegen_new_type_comment(p, bytes);
+ if (tco == NULL) {
+ goto error;
+ }
+ return tco;
+ error:
+ p->error_indicator = 1; // Inline CHECK_CALL
+ return NULL;
+}
+
+arg_ty _PyPegen_add_type_comment_to_arg(Parser *, arg_ty, Token *);
PyObject *_PyPegen_new_identifier(Parser *, char *);
Parser *_PyPegen_Parser_New(struct tok_state *, int, int, int *, PyArena *);
void _PyPegen_Parser_Free(Parser *);
@@ -164,6 +192,7 @@ mod_ty _PyPegen_run_parser_from_string(const char *, int, PyObject *, PyCompiler
void *_PyPegen_interactive_exit(Parser *);
asdl_seq *_PyPegen_singleton_seq(Parser *, void *);
asdl_seq *_PyPegen_seq_insert_in_front(Parser *, void *, asdl_seq *);
+asdl_seq *_PyPegen_seq_append_to_end(Parser *, asdl_seq *, void *);
asdl_seq *_PyPegen_seq_flatten(Parser *, asdl_seq *);
expr_ty _PyPegen_join_names_with_dot(Parser *, expr_ty, expr_ty);
int _PyPegen_seq_count_dots(asdl_seq *);
@@ -176,7 +205,7 @@ expr_ty _PyPegen_set_expr_context(Parser *, expr_ty, expr_context_ty);
KeyValuePair *_PyPegen_key_value_pair(Parser *, expr_ty, expr_ty);
asdl_seq *_PyPegen_get_keys(Parser *, asdl_seq *);
asdl_seq *_PyPegen_get_values(Parser *, asdl_seq *);
-NameDefaultPair *_PyPegen_name_default_pair(Parser *, arg_ty, expr_ty);
+NameDefaultPair *_PyPegen_name_default_pair(Parser *, arg_ty, expr_ty, Token *);
SlashWithDefault *_PyPegen_slash_with_default(Parser *, asdl_seq *, asdl_seq *);
StarEtc *_PyPegen_star_etc(Parser *, arg_ty, asdl_seq *, arg_ty);
arguments_ty _PyPegen_make_arguments(Parser *, asdl_seq *, SlashWithDefault *,
@@ -192,6 +221,7 @@ expr_ty _PyPegen_concatenate_strings(Parser *p, asdl_seq *);
asdl_seq *_PyPegen_join_sequences(Parser *, asdl_seq *, asdl_seq *);
void *_PyPegen_arguments_parsing_error(Parser *, expr_ty);
int _PyPegen_check_barry_as_flufl(Parser *);
+mod_ty _PyPegen_make_module(Parser *, asdl_seq *);
void *_PyPegen_parse(Parser *);
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 14c3e96fb51ab..82ca317c7e9c2 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -816,12 +816,8 @@ builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename,
if (str == NULL)
goto error;
- int current_use_peg = PyInterpreterState_Get()->config._use_peg_parser;
- if (flags & PyCF_TYPE_COMMENTS || feature_version >= 0 || compile_mode == 3) {
- PyInterpreterState_Get()->config._use_peg_parser = 0;
- }
result = Py_CompileStringObject(str, filename, start[compile_mode], &cf, optimize);
- PyInterpreterState_Get()->config._use_peg_parser = current_use_peg;
+
Py_XDECREF(source_copy);
goto finally;
1
0
https://github.com/python/cpython/commit/efb8dd5b3ec91f7d9458d3f203d748604d…
commit: efb8dd5b3ec91f7d9458d3f203d748604d52b121
branch: master
author: Jelle Zijlstra <jelle.zijlstra(a)gmail.com>
committer: GitHub <noreply(a)github.com>
date: 2020-04-30T16:09:11+05:30
summary:
compileall: Fix typos in docstring (GH-19810)
files:
M Lib/compileall.py
diff --git a/Lib/compileall.py b/Lib/compileall.py
index 1831ad749f2b1..abe6cffce59c5 100644
--- a/Lib/compileall.py
+++ b/Lib/compileall.py
@@ -66,7 +66,7 @@ def compile_dir(dir, maxlevels=None, ddir=None, force=False,
workers: maximum number of parallel workers
invalidation_mode: how the up-to-dateness of the pyc will be checked
stripdir: part of path to left-strip from source file path
- prependdir: path to prepend to beggining of original file path, applied
+ prependdir: path to prepend to beginning of original file path, applied
after stripdir
limit_sl_dest: ignore symlinks if they are pointing outside of
the defined path
@@ -136,7 +136,7 @@ def compile_file(fullname, ddir=None, force=False, rx=None, quiet=0,
files each with one optimization level.
invalidation_mode: how the up-to-dateness of the pyc will be checked
stripdir: part of path to left-strip from source file path
- prependdir: path to prepend to beggining of original file path, applied
+ prependdir: path to prepend to beginning of original file path, applied
after stripdir
limit_sl_dest: ignore symlinks if they are pointing outside of
the defined path.
1
0
https://github.com/python/cpython/commit/e488e300f5c01289c10906c2e53a8e43d6…
commit: e488e300f5c01289c10906c2e53a8e43d6de32d8
branch: master
author: Victor Stinner <vstinner(a)python.org>
committer: GitHub <noreply(a)github.com>
date: 2020-04-30T11:28:09+02:00
summary:
bpo-40443: Remove unused imports in distutils (GH-19802)
files:
M Lib/distutils/_msvccompiler.py
M Lib/distutils/bcppcompiler.py
M Lib/distutils/ccompiler.py
M Lib/distutils/command/bdist_rpm.py
M Lib/distutils/command/bdist_wininst.py
M Lib/distutils/command/check.py
M Lib/distutils/command/upload.py
M Lib/distutils/cygwinccompiler.py
M Lib/distutils/msvc9compiler.py
M Lib/distutils/msvccompiler.py
M Lib/distutils/sysconfig.py
diff --git a/Lib/distutils/_msvccompiler.py b/Lib/distutils/_msvccompiler.py
index 03a5986d984dc..af8099a407819 100644
--- a/Lib/distutils/_msvccompiler.py
+++ b/Lib/distutils/_msvccompiler.py
@@ -14,8 +14,6 @@
# ported to VS 2015 by Steve Dower
import os
-import shutil
-import stat
import subprocess
import winreg
@@ -65,8 +63,6 @@ def _find_vc2017():
If vswhere.exe is not available, by definition, VS 2017 is not
installed.
"""
- import json
-
root = os.environ.get("ProgramFiles(x86)") or os.environ.get("ProgramFiles")
if not root:
return None, None
diff --git a/Lib/distutils/bcppcompiler.py b/Lib/distutils/bcppcompiler.py
index 9f4c432d90e77..071fea5d038cb 100644
--- a/Lib/distutils/bcppcompiler.py
+++ b/Lib/distutils/bcppcompiler.py
@@ -14,10 +14,10 @@
import os
from distutils.errors import \
- DistutilsExecError, DistutilsPlatformError, \
+ DistutilsExecError, \
CompileError, LibError, LinkError, UnknownFileError
from distutils.ccompiler import \
- CCompiler, gen_preprocess_options, gen_lib_options
+ CCompiler, gen_preprocess_options
from distutils.file_util import write_file
from distutils.dep_util import newer
from distutils import log
diff --git a/Lib/distutils/ccompiler.py b/Lib/distutils/ccompiler.py
index 4cfc6c7065e92..b5ef143e72c56 100644
--- a/Lib/distutils/ccompiler.py
+++ b/Lib/distutils/ccompiler.py
@@ -8,7 +8,7 @@
from distutils.spawn import spawn
from distutils.file_util import move_file
from distutils.dir_util import mkpath
-from distutils.dep_util import newer_pairwise, newer_group
+from distutils.dep_util import newer_group
from distutils.util import split_quoted, execute
from distutils import log
diff --git a/Lib/distutils/command/bdist_rpm.py b/Lib/distutils/command/bdist_rpm.py
index 74381cc69a6ce..550cbfa1e28a2 100644
--- a/Lib/distutils/command/bdist_rpm.py
+++ b/Lib/distutils/command/bdist_rpm.py
@@ -6,7 +6,6 @@
import subprocess, sys, os
from distutils.core import Command
from distutils.debug import DEBUG
-from distutils.util import get_platform
from distutils.file_util import write_file
from distutils.errors import *
from distutils.sysconfig import get_python_version
diff --git a/Lib/distutils/command/bdist_wininst.py b/Lib/distutils/command/bdist_wininst.py
index b5ed6f041e19a..0e9ddaa21419e 100644
--- a/Lib/distutils/command/bdist_wininst.py
+++ b/Lib/distutils/command/bdist_wininst.py
@@ -8,7 +8,7 @@
import warnings
from distutils.core import Command
from distutils.util import get_platform
-from distutils.dir_util import create_tree, remove_tree
+from distutils.dir_util import remove_tree
from distutils.errors import *
from distutils.sysconfig import get_python_version
from distutils import log
diff --git a/Lib/distutils/command/check.py b/Lib/distutils/command/check.py
index 7ceabd3adf22d..ada250064678e 100644
--- a/Lib/distutils/command/check.py
+++ b/Lib/distutils/command/check.py
@@ -11,7 +11,6 @@
from docutils.parsers.rst import Parser
from docutils import frontend
from docutils import nodes
- from io import StringIO
class SilentReporter(Reporter):
diff --git a/Lib/distutils/command/upload.py b/Lib/distutils/command/upload.py
index 11afa24b777a1..d822ba01338af 100644
--- a/Lib/distutils/command/upload.py
+++ b/Lib/distutils/command/upload.py
@@ -7,7 +7,6 @@
import os
import io
-import platform
import hashlib
from base64 import standard_b64encode
from urllib.request import urlopen, Request, HTTPError
diff --git a/Lib/distutils/cygwinccompiler.py b/Lib/distutils/cygwinccompiler.py
index 6c5d77746b6f5..66c12dd35830b 100644
--- a/Lib/distutils/cygwinccompiler.py
+++ b/Lib/distutils/cygwinccompiler.py
@@ -51,12 +51,10 @@
from subprocess import Popen, PIPE, check_output
import re
-from distutils.ccompiler import gen_preprocess_options, gen_lib_options
from distutils.unixccompiler import UnixCCompiler
from distutils.file_util import write_file
from distutils.errors import (DistutilsExecError, CCompilerError,
CompileError, UnknownFileError)
-from distutils import log
from distutils.version import LooseVersion
from distutils.spawn import find_executable
diff --git a/Lib/distutils/msvc9compiler.py b/Lib/distutils/msvc9compiler.py
index 4c0036a0f1330..6934e964abd69 100644
--- a/Lib/distutils/msvc9compiler.py
+++ b/Lib/distutils/msvc9compiler.py
@@ -19,8 +19,7 @@
from distutils.errors import DistutilsExecError, DistutilsPlatformError, \
CompileError, LibError, LinkError
-from distutils.ccompiler import CCompiler, gen_preprocess_options, \
- gen_lib_options
+from distutils.ccompiler import CCompiler, gen_lib_options
from distutils import log
from distutils.util import get_platform
diff --git a/Lib/distutils/msvccompiler.py b/Lib/distutils/msvccompiler.py
index d1de2fbfcb947..d5857cb1ffe42 100644
--- a/Lib/distutils/msvccompiler.py
+++ b/Lib/distutils/msvccompiler.py
@@ -13,7 +13,7 @@
DistutilsExecError, DistutilsPlatformError, \
CompileError, LibError, LinkError
from distutils.ccompiler import \
- CCompiler, gen_preprocess_options, gen_lib_options
+ CCompiler, gen_lib_options
from distutils import log
_can_read_reg = False
diff --git a/Lib/distutils/sysconfig.py b/Lib/distutils/sysconfig.py
index 01ee519792932..37feae5df72c9 100644
--- a/Lib/distutils/sysconfig.py
+++ b/Lib/distutils/sysconfig.py
@@ -15,7 +15,6 @@
import sys
from .errors import DistutilsPlatformError
-from .util import get_platform, get_host_platform
# These are needed in a couple of spots, so just compute them once.
PREFIX = os.path.normpath(sys.prefix)
1
0
https://github.com/python/cpython/commit/90549676e063c2c818cfc14213d3adb7ed…
commit: 90549676e063c2c818cfc14213d3adb7edcc2bd5
branch: master
author: Victor Stinner <vstinner(a)python.org>
committer: GitHub <noreply(a)github.com>
date: 2020-04-30T11:26:33+02:00
summary:
bpo-40443: Remove unused imports in the stdlib (GH-19803)
files:
M Lib/asyncio/events.py
M Lib/asyncio/sslproto.py
M Lib/bz2.py
M Lib/concurrent/futures/process.py
M Lib/concurrent/futures/thread.py
M Lib/ctypes/test/test_loading.py
M Lib/modulefinder.py
M Lib/plistlib.py
M Lib/xml/dom/xmlbuilder.py
M Lib/zipfile.py
diff --git a/Lib/asyncio/events.py b/Lib/asyncio/events.py
index 16a6cfd438bdc..70017cb86a059 100644
--- a/Lib/asyncio/events.py
+++ b/Lib/asyncio/events.py
@@ -19,7 +19,6 @@
import threading
from . import format_helpers
-from . import exceptions
class Handle:
diff --git a/Lib/asyncio/sslproto.py b/Lib/asyncio/sslproto.py
index 3eca6b4a39128..cad25b26539f5 100644
--- a/Lib/asyncio/sslproto.py
+++ b/Lib/asyncio/sslproto.py
@@ -5,7 +5,6 @@
except ImportError: # pragma: no cover
ssl = None
-from . import base_events
from . import constants
from . import protocols
from . import transports
diff --git a/Lib/bz2.py b/Lib/bz2.py
index e094fbb548bc9..ce07ebeb142d9 100644
--- a/Lib/bz2.py
+++ b/Lib/bz2.py
@@ -12,7 +12,6 @@
from builtins import open as _builtin_open
import io
import os
-import warnings
import _compression
from threading import RLock
diff --git a/Lib/concurrent/futures/process.py b/Lib/concurrent/futures/process.py
index a76e2c9cf231a..90bc98bf2ecd1 100644
--- a/Lib/concurrent/futures/process.py
+++ b/Lib/concurrent/futures/process.py
@@ -45,7 +45,6 @@
__author__ = 'Brian Quinlan (brian(a)sweetapp.com)'
-import atexit
import os
from concurrent.futures import _base
import queue
diff --git a/Lib/concurrent/futures/thread.py b/Lib/concurrent/futures/thread.py
index 2810b357bc1e1..b7a2cac7f5701 100644
--- a/Lib/concurrent/futures/thread.py
+++ b/Lib/concurrent/futures/thread.py
@@ -5,7 +5,6 @@
__author__ = 'Brian Quinlan (brian(a)sweetapp.com)'
-import atexit
from concurrent.futures import _base
import itertools
import queue
diff --git a/Lib/ctypes/test/test_loading.py b/Lib/ctypes/test/test_loading.py
index 5c48b0db4c393..ba655bceb8b21 100644
--- a/Lib/ctypes/test/test_loading.py
+++ b/Lib/ctypes/test/test_loading.py
@@ -3,7 +3,6 @@
import shutil
import subprocess
import sys
-import sysconfig
import unittest
import test.support
from ctypes.util import find_library
diff --git a/Lib/modulefinder.py b/Lib/modulefinder.py
index aadcd23edbaaa..cb455f40c4d78 100644
--- a/Lib/modulefinder.py
+++ b/Lib/modulefinder.py
@@ -7,8 +7,6 @@
import os
import io
import sys
-import types
-import warnings
LOAD_CONST = dis.opmap['LOAD_CONST']
diff --git a/Lib/plistlib.py b/Lib/plistlib.py
index a84bb57371ef6..aff5fe36ca38b 100644
--- a/Lib/plistlib.py
+++ b/Lib/plistlib.py
@@ -51,7 +51,6 @@
import binascii
import codecs
-import contextlib
import datetime
import enum
from io import BytesIO
@@ -59,7 +58,6 @@
import os
import re
import struct
-from warnings import warn
from xml.parsers.expat import ParserCreate
diff --git a/Lib/xml/dom/xmlbuilder.py b/Lib/xml/dom/xmlbuilder.py
index 213ab14551c67..8a200263497b8 100644
--- a/Lib/xml/dom/xmlbuilder.py
+++ b/Lib/xml/dom/xmlbuilder.py
@@ -1,7 +1,6 @@
"""Implementation of the DOM Level 3 'LS-Load' feature."""
import copy
-import warnings
import xml.dom
from xml.dom.NodeFilter import NodeFilter
diff --git a/Lib/zipfile.py b/Lib/zipfile.py
index c3f814cc747e0..8903d6a42ee4e 100644
--- a/Lib/zipfile.py
+++ b/Lib/zipfile.py
@@ -4,7 +4,6 @@
XXX references to utf-8 need further investigation.
"""
import binascii
-import functools
import importlib.util
import io
import itertools
1
0
bpo-40394 - difflib.SequenceMatched.find_longest_match default args (GH-19742)
by lrjball 30 Apr '20
by lrjball 30 Apr '20
30 Apr '20
https://github.com/python/cpython/commit/3209cbd99b6d65aa18b3beb124fac9c792…
commit: 3209cbd99b6d65aa18b3beb124fac9c792b8993d
branch: master
author: lrjball <50599110+lrjball(a)users.noreply.github.com>
committer: GitHub <noreply(a)github.com>
date: 2020-04-29T22:42:45-05:00
summary:
bpo-40394 - difflib.SequenceMatched.find_longest_match default args (GH-19742)
* bpo-40394 - difflib.SequenceMatched.find_longest_match default args
Added default args to find_longest_match, as well as related tests.
files:
A Misc/NEWS.d/next/Library/2020-04-28-18-59-48.bpo-40394.Yi5uuM.rst
M Doc/library/difflib.rst
M Lib/difflib.py
M Lib/test/test_difflib.py
M Misc/ACKS
diff --git a/Doc/library/difflib.rst b/Doc/library/difflib.rst
index ada311bc3a205..7a898c21b52e0 100644
--- a/Doc/library/difflib.rst
+++ b/Doc/library/difflib.rst
@@ -421,7 +421,7 @@ The :class:`SequenceMatcher` class has this constructor:
is not changed.
- .. method:: find_longest_match(alo, ahi, blo, bhi)
+ .. method:: find_longest_match(alo=0, ahi=None, blo=0, bhi=None)
Find longest matching block in ``a[alo:ahi]`` and ``b[blo:bhi]``.
@@ -458,6 +458,9 @@ The :class:`SequenceMatcher` class has this constructor:
This method returns a :term:`named tuple` ``Match(a, b, size)``.
+ .. versionchanged:: 3.9
+ Added default arguments.
+
.. method:: get_matching_blocks()
diff --git a/Lib/difflib.py b/Lib/difflib.py
index f2215d8d4561c..0dda80d387573 100644
--- a/Lib/difflib.py
+++ b/Lib/difflib.py
@@ -130,7 +130,7 @@ class SequenceMatcher:
set_seq2(b)
Set the second sequence to be compared.
- find_longest_match(alo, ahi, blo, bhi)
+ find_longest_match(alo=0, ahi=None, blo=0, bhi=None)
Find longest matching block in a[alo:ahi] and b[blo:bhi].
get_matching_blocks()
@@ -334,9 +334,11 @@ def __chain_b(self):
for elt in popular: # ditto; as fast for 1% deletion
del b2j[elt]
- def find_longest_match(self, alo, ahi, blo, bhi):
+ def find_longest_match(self, alo=0, ahi=None, blo=0, bhi=None):
"""Find longest matching block in a[alo:ahi] and b[blo:bhi].
+ By default it will find the longest match in the entirety of a and b.
+
If isjunk is not defined:
Return (i,j,k) such that a[i:i+k] is equal to b[j:j+k], where
@@ -391,6 +393,10 @@ def find_longest_match(self, alo, ahi, blo, bhi):
# the unique 'b's and then matching the first two 'a's.
a, b, b2j, isbjunk = self.a, self.b, self.b2j, self.bjunk.__contains__
+ if ahi is None:
+ ahi = len(a)
+ if bhi is None:
+ bhi = len(b)
besti, bestj, bestsize = alo, blo, 0
# find longest junk-free match
# during an iteration of the loop, j2len[j] = length of longest
diff --git a/Lib/test/test_difflib.py b/Lib/test/test_difflib.py
index 5e2ca1a23b928..42ac1fdcd81cd 100644
--- a/Lib/test/test_difflib.py
+++ b/Lib/test/test_difflib.py
@@ -501,12 +501,58 @@ def test_is_character_junk_false(self):
for char in ['a', '#', '\n', '\f', '\r', '\v']:
self.assertFalse(difflib.IS_CHARACTER_JUNK(char), repr(char))
+class TestFindLongest(unittest.TestCase):
+ def longer_match_exists(self, a, b, n):
+ return any(b_part in a for b_part in
+ [b[i:i + n + 1] for i in range(0, len(b) - n - 1)])
+
+ def test_default_args(self):
+ a = 'foo bar'
+ b = 'foo baz bar'
+ sm = difflib.SequenceMatcher(a=a, b=b)
+ match = sm.find_longest_match()
+ self.assertEqual(match.a, 0)
+ self.assertEqual(match.b, 0)
+ self.assertEqual(match.size, 6)
+ self.assertEqual(a[match.a: match.a + match.size],
+ b[match.b: match.b + match.size])
+ self.assertFalse(self.longer_match_exists(a, b, match.size))
+
+ match = sm.find_longest_match(alo=2, blo=4)
+ self.assertEqual(match.a, 3)
+ self.assertEqual(match.b, 7)
+ self.assertEqual(match.size, 4)
+ self.assertEqual(a[match.a: match.a + match.size],
+ b[match.b: match.b + match.size])
+ self.assertFalse(self.longer_match_exists(a[2:], b[4:], match.size))
+
+ match = sm.find_longest_match(bhi=5, blo=1)
+ self.assertEqual(match.a, 1)
+ self.assertEqual(match.b, 1)
+ self.assertEqual(match.size, 4)
+ self.assertEqual(a[match.a: match.a + match.size],
+ b[match.b: match.b + match.size])
+ self.assertFalse(self.longer_match_exists(a, b[1:5], match.size))
+
+ def test_longest_match_with_popular_chars(self):
+ a = 'dabcd'
+ b = 'd'*100 + 'abc' + 'd'*100 # length over 200 so popular used
+ sm = difflib.SequenceMatcher(a=a, b=b)
+ match = sm.find_longest_match(0, len(a), 0, len(b))
+ self.assertEqual(match.a, 0)
+ self.assertEqual(match.b, 99)
+ self.assertEqual(match.size, 5)
+ self.assertEqual(a[match.a: match.a + match.size],
+ b[match.b: match.b + match.size])
+ self.assertFalse(self.longer_match_exists(a, b, match.size))
+
+
def test_main():
difflib.HtmlDiff._default_prefix = 0
Doctests = doctest.DocTestSuite(difflib)
run_unittest(
TestWithAscii, TestAutojunk, TestSFpatches, TestSFbugs,
- TestOutputFormat, TestBytes, TestJunkAPIs, Doctests)
+ TestOutputFormat, TestBytes, TestJunkAPIs, TestFindLongest, Doctests)
if __name__ == '__main__':
test_main()
diff --git a/Misc/ACKS b/Misc/ACKS
index 89f37e584ef8b..21822dd7524cf 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -88,6 +88,7 @@ Dwayne Bailey
Stig Bakken
Aleksandr Balezin
Greg Ball
+Lewis Ball
Luigi Ballabio
Thomas Ballinger
Jeff Balogh
diff --git a/Misc/NEWS.d/next/Library/2020-04-28-18-59-48.bpo-40394.Yi5uuM.rst b/Misc/NEWS.d/next/Library/2020-04-28-18-59-48.bpo-40394.Yi5uuM.rst
new file mode 100644
index 0000000000000..ef2e239b1e678
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2020-04-28-18-59-48.bpo-40394.Yi5uuM.rst
@@ -0,0 +1 @@
+Added default arguments to :meth:`difflib.SequenceMatcher.find_longest_match()`.
\ No newline at end of file
1
0
30 Apr '20
https://github.com/python/cpython/commit/95e208dce505c542b8e4f8f42c57e6d479…
commit: 95e208dce505c542b8e4f8f42c57e6d4793b6895
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: GitHub <noreply(a)github.com>
date: 2020-04-29T18:47:50-07:00
summary:
bpo-40443: Remove unused imports in idlelib (GH-19801)
(cherry picked from commit 6900f16d2207ca4fc252fa9d778ca0b13a3c95e0)
Co-authored-by: Victor Stinner <vstinner(a)python.org>
files:
M Lib/idlelib/autocomplete_w.py
M Lib/idlelib/config_key.py
M Lib/idlelib/configdialog.py
M Lib/idlelib/idle_test/test_sidebar.py
M Lib/idlelib/idle_test/test_squeezer.py
M Lib/idlelib/textview.py
diff --git a/Lib/idlelib/autocomplete_w.py b/Lib/idlelib/autocomplete_w.py
index 0643c092c6e54..fe7a6be83d586 100644
--- a/Lib/idlelib/autocomplete_w.py
+++ b/Lib/idlelib/autocomplete_w.py
@@ -4,7 +4,7 @@
import platform
from tkinter import *
-from tkinter.ttk import Frame, Scrollbar
+from tkinter.ttk import Scrollbar
from idlelib.autocomplete import FILES, ATTRS
from idlelib.multicall import MC_SHIFT
diff --git a/Lib/idlelib/config_key.py b/Lib/idlelib/config_key.py
index 4478323fcc2c5..7510aa9f3d878 100644
--- a/Lib/idlelib/config_key.py
+++ b/Lib/idlelib/config_key.py
@@ -1,7 +1,7 @@
"""
Dialog for building Tkinter accelerator key bindings
"""
-from tkinter import Toplevel, Listbox, Text, StringVar, TclError
+from tkinter import Toplevel, Listbox, StringVar, TclError
from tkinter.ttk import Frame, Button, Checkbutton, Entry, Label, Scrollbar
from tkinter import messagebox
import string
diff --git a/Lib/idlelib/configdialog.py b/Lib/idlelib/configdialog.py
index 9d5c2cde04b24..82596498d3461 100644
--- a/Lib/idlelib/configdialog.py
+++ b/Lib/idlelib/configdialog.py
@@ -11,7 +11,7 @@
"""
import re
-from tkinter import (Toplevel, Listbox, Text, Scale, Canvas,
+from tkinter import (Toplevel, Listbox, Scale, Canvas,
StringVar, BooleanVar, IntVar, TRUE, FALSE,
TOP, BOTTOM, RIGHT, LEFT, SOLID, GROOVE,
NONE, BOTH, X, Y, W, E, EW, NS, NSEW, NW,
diff --git a/Lib/idlelib/idle_test/test_sidebar.py b/Lib/idlelib/idle_test/test_sidebar.py
index 0f5b4c7122324..2974a9a7b0987 100644
--- a/Lib/idlelib/idle_test/test_sidebar.py
+++ b/Lib/idlelib/idle_test/test_sidebar.py
@@ -1,6 +1,5 @@
"""Test sidebar, coverage 93%"""
import idlelib.sidebar
-from sys import platform
from itertools import chain
import unittest
import unittest.mock
diff --git a/Lib/idlelib/idle_test/test_squeezer.py b/Lib/idlelib/idle_test/test_squeezer.py
index 1af2ce832845c..e3912f4bbbec8 100644
--- a/Lib/idlelib/idle_test/test_squeezer.py
+++ b/Lib/idlelib/idle_test/test_squeezer.py
@@ -1,6 +1,5 @@
"Test squeezer, coverage 95%"
-from collections import namedtuple
from textwrap import dedent
from tkinter import Text, Tk
import unittest
diff --git a/Lib/idlelib/textview.py b/Lib/idlelib/textview.py
index 808a2aefab4f7..a66c1a4309a61 100644
--- a/Lib/idlelib/textview.py
+++ b/Lib/idlelib/textview.py
@@ -6,7 +6,6 @@
from tkinter.ttk import Frame, Scrollbar, Button
from tkinter.messagebox import showerror
-from functools import update_wrapper
from idlelib.colorizer import color_config
1
0
30 Apr '20
https://github.com/python/cpython/commit/48ef06b62682c19b7860dcf5d9d610e589…
commit: 48ef06b62682c19b7860dcf5d9d610e589a49840
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: GitHub <noreply(a)github.com>
date: 2020-04-29T18:45:54-07:00
summary:
bpo-40443: Remove unused imports in idlelib (GH-19801)
(cherry picked from commit 6900f16d2207ca4fc252fa9d778ca0b13a3c95e0)
Co-authored-by: Victor Stinner <vstinner(a)python.org>
files:
M Lib/idlelib/autocomplete_w.py
M Lib/idlelib/config_key.py
M Lib/idlelib/configdialog.py
M Lib/idlelib/idle_test/test_sidebar.py
M Lib/idlelib/idle_test/test_squeezer.py
M Lib/idlelib/textview.py
diff --git a/Lib/idlelib/autocomplete_w.py b/Lib/idlelib/autocomplete_w.py
index 0643c092c6e54..fe7a6be83d586 100644
--- a/Lib/idlelib/autocomplete_w.py
+++ b/Lib/idlelib/autocomplete_w.py
@@ -4,7 +4,7 @@
import platform
from tkinter import *
-from tkinter.ttk import Frame, Scrollbar
+from tkinter.ttk import Scrollbar
from idlelib.autocomplete import FILES, ATTRS
from idlelib.multicall import MC_SHIFT
diff --git a/Lib/idlelib/config_key.py b/Lib/idlelib/config_key.py
index 4478323fcc2c5..7510aa9f3d878 100644
--- a/Lib/idlelib/config_key.py
+++ b/Lib/idlelib/config_key.py
@@ -1,7 +1,7 @@
"""
Dialog for building Tkinter accelerator key bindings
"""
-from tkinter import Toplevel, Listbox, Text, StringVar, TclError
+from tkinter import Toplevel, Listbox, StringVar, TclError
from tkinter.ttk import Frame, Button, Checkbutton, Entry, Label, Scrollbar
from tkinter import messagebox
import string
diff --git a/Lib/idlelib/configdialog.py b/Lib/idlelib/configdialog.py
index 9d5c2cde04b24..82596498d3461 100644
--- a/Lib/idlelib/configdialog.py
+++ b/Lib/idlelib/configdialog.py
@@ -11,7 +11,7 @@
"""
import re
-from tkinter import (Toplevel, Listbox, Text, Scale, Canvas,
+from tkinter import (Toplevel, Listbox, Scale, Canvas,
StringVar, BooleanVar, IntVar, TRUE, FALSE,
TOP, BOTTOM, RIGHT, LEFT, SOLID, GROOVE,
NONE, BOTH, X, Y, W, E, EW, NS, NSEW, NW,
diff --git a/Lib/idlelib/idle_test/test_sidebar.py b/Lib/idlelib/idle_test/test_sidebar.py
index 0f5b4c7122324..2974a9a7b0987 100644
--- a/Lib/idlelib/idle_test/test_sidebar.py
+++ b/Lib/idlelib/idle_test/test_sidebar.py
@@ -1,6 +1,5 @@
"""Test sidebar, coverage 93%"""
import idlelib.sidebar
-from sys import platform
from itertools import chain
import unittest
import unittest.mock
diff --git a/Lib/idlelib/idle_test/test_squeezer.py b/Lib/idlelib/idle_test/test_squeezer.py
index 1af2ce832845c..e3912f4bbbec8 100644
--- a/Lib/idlelib/idle_test/test_squeezer.py
+++ b/Lib/idlelib/idle_test/test_squeezer.py
@@ -1,6 +1,5 @@
"Test squeezer, coverage 95%"
-from collections import namedtuple
from textwrap import dedent
from tkinter import Text, Tk
import unittest
diff --git a/Lib/idlelib/textview.py b/Lib/idlelib/textview.py
index 808a2aefab4f7..a66c1a4309a61 100644
--- a/Lib/idlelib/textview.py
+++ b/Lib/idlelib/textview.py
@@ -6,7 +6,6 @@
from tkinter.ttk import Frame, Scrollbar, Button
from tkinter.messagebox import showerror
-from functools import update_wrapper
from idlelib.colorizer import color_config
1
0