From 2b5b82c21237af35eae0d7d560724e330fab6be8 Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Sun, 10 May 2020 02:55:34 -0700 Subject: [PATCH 1/7] Import tools for new Python version --- tools/Grammar.patch | 78 ------ tools/Python-asdl.patch | 67 ----- tools/asdl_c.patch | 184 ++++++++++---- tools/ast.patch | 444 --------------------------------- tools/c_generator.patch | 13 + tools/find_exported_symbols | 9 +- tools/import_files.sh | 27 ++ tools/parse_string.c.patch | 22 ++ tools/parsetok.patch | 95 ------- tools/regen_parse.sh | 3 + tools/rename_symbols.sh | 18 ++ tools/script | 44 ---- tools/scripts | 7 + tools/ta3_compat.h.patch | 79 ++++++ tools/token.patch | 17 -- tools/tokenizer.patch | 80 ------ tools/update_ast3_grammar | 13 - tools/update_compiler_flags.sh | 5 + tools/update_exported_symbols | 8 +- tools/update_header_guards | 8 +- 20 files changed, 327 insertions(+), 894 deletions(-) delete mode 100644 tools/Grammar.patch delete mode 100644 tools/Python-asdl.patch delete mode 100644 tools/ast.patch create mode 100644 tools/c_generator.patch create mode 100755 tools/import_files.sh create mode 100644 tools/parse_string.c.patch delete mode 100644 tools/parsetok.patch create mode 100755 tools/regen_parse.sh create mode 100755 tools/rename_symbols.sh delete mode 100755 tools/script create mode 100755 tools/scripts create mode 100644 tools/ta3_compat.h.patch delete mode 100644 tools/token.patch delete mode 100644 tools/tokenizer.patch delete mode 100755 tools/update_ast3_grammar create mode 100755 tools/update_compiler_flags.sh diff --git a/tools/Grammar.patch b/tools/Grammar.patch deleted file mode 100644 index e8cb21cf..00000000 --- a/tools/Grammar.patch +++ /dev/null @@ -1,78 +0,0 @@ -diff --git a/ast3/Grammar/Grammar b/ast3/Grammar/Grammar -index b139e9f..dfd730f 100644 ---- a/ast3/Grammar/Grammar -+++ b/ast3/Grammar/Grammar -@@ -14,7 +14,10 @@ - # single_input is a single interactive statement; - # file_input is a module or sequence of commands read from an input file; - # eval_input is the input for the eval() functions. -+# func_type_input is a PEP 484 Python 2 function type comment - # NB: compound_stmt in single_input is followed by extra NEWLINE! -+# NB: due to the way TYPE_COMMENT is tokenized it will always be followed by a -+# NEWLINE - single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE - file_input: (NEWLINE | stmt)* ENDMARKER - eval_input: testlist NEWLINE* ENDMARKER -@@ -24,14 +27,14 @@ decorators: decorator+ - decorated: decorators (classdef | funcdef | async_funcdef) - - async_funcdef: ASYNC funcdef --funcdef: 'def' NAME parameters ['->' test] ':' suite -+funcdef: 'def' NAME parameters ['->' test] ':' [TYPE_COMMENT] suite - - parameters: '(' [typedargslist] ')' --typedargslist: (tfpdef ['=' test] (',' tfpdef ['=' test])* [',' [ -- '*' [tfpdef] (',' tfpdef ['=' test])* [',' ['**' tfpdef [',']]] -- | '**' tfpdef [',']]] -- | '*' [tfpdef] (',' tfpdef ['=' test])* [',' ['**' tfpdef [',']]] -- | '**' tfpdef [',']) -+typedargslist: (tfpdef ['=' test] (',' [TYPE_COMMENT] tfpdef ['=' test])* (TYPE_COMMENT | [',' [TYPE_COMMENT] [ -+ '*' [tfpdef] (',' [TYPE_COMMENT] tfpdef ['=' test])* (TYPE_COMMENT | [',' [TYPE_COMMENT] ['**' tfpdef [','] [TYPE_COMMENT]]]) -+ | '**' tfpdef [','] [TYPE_COMMENT]]]) -+ | '*' [tfpdef] (',' [TYPE_COMMENT] tfpdef ['=' test])* (TYPE_COMMENT | [',' [TYPE_COMMENT] ['**' tfpdef [','] [TYPE_COMMENT]]]) -+ | '**' tfpdef [','] [TYPE_COMMENT]) - tfpdef: NAME [':' test] - varargslist: (vfpdef ['=' test] (',' vfpdef ['=' test])* [',' [ - '*' [vfpdef] (',' vfpdef ['=' test])* [',' ['**' vfpdef [',']]] -@@ -46,7 +49,7 @@ simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE - small_stmt: (expr_stmt | del_stmt | pass_stmt | flow_stmt | - import_stmt | global_stmt | nonlocal_stmt | assert_stmt) - expr_stmt: testlist_star_expr (annassign | augassign (yield_expr|testlist) | -- ('=' (yield_expr|testlist_star_expr))*) -+ ('=' (yield_expr|testlist_star_expr))* [TYPE_COMMENT]) - annassign: ':' test ['=' test] - testlist_star_expr: (test|star_expr) (',' (test|star_expr))* [','] - augassign: ('+=' | '-=' | '*=' | '@=' | '/=' | '%=' | '&=' | '|=' | '^=' | -@@ -78,17 +81,18 @@ compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef - async_stmt: ASYNC (funcdef | with_stmt | for_stmt) - if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite] - while_stmt: 'while' test ':' suite ['else' ':' suite] --for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite] -+for_stmt: 'for' exprlist 'in' testlist ':' [TYPE_COMMENT] suite ['else' ':' suite] - try_stmt: ('try' ':' suite - ((except_clause ':' suite)+ - ['else' ':' suite] - ['finally' ':' suite] | - 'finally' ':' suite)) --with_stmt: 'with' with_item (',' with_item)* ':' suite -+with_stmt: 'with' with_item (',' with_item)* ':' [TYPE_COMMENT] suite - with_item: test ['as' expr] - # NB compile.c makes sure that the default except clause is last - except_clause: 'except' [test ['as' NAME]] --suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT -+# the TYPE_COMMENT in suites is only parsed for funcdefs, but can't go elsewhere due to ambiguity -+suite: simple_stmt | NEWLINE [TYPE_COMMENT NEWLINE] INDENT stmt+ DEDENT - - test: or_test ['if' or_test 'else' test] | lambdef - test_nocond: or_test | lambdef_nocond -@@ -154,3 +158,10 @@ encoding_decl: NAME - - yield_expr: 'yield' [yield_arg] - yield_arg: 'from' test | testlist -+ -+func_type_input: func_type NEWLINE* ENDMARKER -+func_type: '(' [typelist] ')' '->' test -+# typelist is a modified typedargslist (see above) -+typelist: (test (',' test)* [',' -+ ['*' [test] (',' test)* [',' '**' test] | '**' test]] -+ | '*' [test] (',' test)* [',' '**' test] | '**' test) diff --git a/tools/Python-asdl.patch b/tools/Python-asdl.patch deleted file mode 100644 index 25e9a7a4..00000000 --- a/tools/Python-asdl.patch +++ /dev/null @@ -1,67 +0,0 @@ -diff --git a/ast3/Parser/Python.asdl b/ast3/Parser/Python.asdl -index f470ad1..7bde99c 100644 ---- a/ast3/Parser/Python.asdl -+++ b/ast3/Parser/Python.asdl -@@ -6,17 +6,18 @@ - - module Python - { -- mod = Module(stmt* body) -+ mod = Module(stmt* body, type_ignore *type_ignores) - | Interactive(stmt* body) - | Expression(expr body) -+ | FunctionType(expr* argtypes, expr returns) - - -- not really an actual node but useful in Jython's typesystem. - | Suite(stmt* body) - - stmt = FunctionDef(identifier name, arguments args, -- stmt* body, expr* decorator_list, expr? returns) -+ stmt* body, expr* decorator_list, expr? returns, string? type_comment) - | AsyncFunctionDef(identifier name, arguments args, -- stmt* body, expr* decorator_list, expr? returns) -+ stmt* body, expr* decorator_list, expr? returns, string? type_comment) - - | ClassDef(identifier name, - expr* bases, -@@ -26,18 +27,18 @@ module Python - | Return(expr? value) - - | Delete(expr* targets) -- | Assign(expr* targets, expr value) -+ | Assign(expr* targets, expr value, string? type_comment) - | AugAssign(expr target, operator op, expr value) - -- 'simple' indicates that we annotate simple name without parens - | AnnAssign(expr target, expr annotation, expr? value, int simple) - - -- use 'orelse' because else is a keyword in target languages -- | For(expr target, expr iter, stmt* body, stmt* orelse) -- | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse) -+ | For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment) -+ | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment) - | While(expr test, stmt* body, stmt* orelse) - | If(expr test, stmt* body, stmt* orelse) -- | With(withitem* items, stmt* body) -- | AsyncWith(withitem* items, stmt* body) -+ | With(withitem* items, stmt* body, string? type_comment) -+ | AsyncWith(withitem* items, stmt* body, string? type_comment) - - | Raise(expr? exc, expr? cause) - | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody) -@@ -118,7 +119,7 @@ module Python - arguments = (arg* args, arg? vararg, arg* kwonlyargs, expr* kw_defaults, - arg? kwarg, expr* defaults) - -- arg = (identifier arg, expr? annotation) -+ arg = (identifier arg, expr? annotation, string? type_comment) - attributes (int lineno, int col_offset) - - -- keyword arguments supplied to call (NULL identifier for **kwargs) -@@ -128,5 +129,7 @@ module Python - alias = (identifier name, identifier? asname) - - withitem = (expr context_expr, expr? optional_vars) -+ -+ type_ignore = TypeIgnore(int lineno) - } - diff --git a/tools/asdl_c.patch b/tools/asdl_c.patch index 9258ca5c..a14123cd 100644 --- a/tools/asdl_c.patch +++ b/tools/asdl_c.patch @@ -1,6 +1,8 @@ ---- /Users/guido/src/cpython37/Parser/asdl_c.py 2018-09-10 08:18:23.000000000 -0700 -+++ ast3/Parser/asdl_c.py 2019-01-15 16:13:24.000000000 -0800 -@@ -270,9 +270,9 @@ +diff --git a/ast3/Parser/asdl_c.py b/ast3/Parser/asdl_c.py +index 59bf03e..adea54a 100755 +--- a/ast3/Parser/asdl_c.py ++++ b/ast3/Parser/asdl_c.py +@@ -292,9 +292,9 @@ class PrototypeVisitor(EmitVisitor): margs = "a0" for i in range(1, len(args)+1): margs += ", a%d" % i @@ -12,7 +14,24 @@ def visitProduct(self, prod, name): self.emit_function(name, get_c_type(name), -@@ -531,9 +531,9 @@ +@@ -520,7 +520,7 @@ class Obj2ModVisitor(PickleVisitor): + + def visitField(self, field, name, sum=None, prod=None, depth=0): + ctype = get_c_type(field.type) +- line = "if (_PyObject_LookupAttr(obj, astmodulestate_global->%s, &tmp) < 0) {" ++ line = "if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->%s, &tmp) < 0) {" + self.emit(line % field.name, depth) + self.emit("return 1;", depth+1) + self.emit("}", depth) +@@ -548,16 +548,16 @@ class Obj2ModVisitor(PickleVisitor): + self.emit("Py_ssize_t i;", depth+1) + self.emit("if (!PyList_Check(tmp)) {", depth+1) + self.emit("PyErr_Format(PyExc_TypeError, \"%s field \\\"%s\\\" must " +- "be a list, not a %%.200s\", _PyType_Name(Py_TYPE(tmp)));" % ++ "be a list, not a %%.200s\", _Ta3Type_Name(Py_TYPE(tmp)));" % + (name, field.name), + depth+2, reflow=False) + self.emit("goto failed;", depth+2) self.emit("}", depth+1) self.emit("len = PyList_GET_SIZE(tmp);", depth+1) if self.isSimpleType(field): @@ -24,55 +43,43 @@ self.emit("if (%s == NULL) goto failed;" % field.name, depth+1) self.emit("for (i = 0; i < len; i++) {", depth+1) self.emit("%s val;" % ctype, depth+2) -@@ -729,8 +729,8 @@ - }; - - static PyTypeObject AST_type = { -- PyVarObject_HEAD_INIT(&PyType_Type, 0) -- "_ast.AST", -+ PyVarObject_HEAD_INIT(NULL, 0) -+ "_ast3.AST", - sizeof(AST_object), - 0, - (destructor)ast_dealloc, /* tp_dealloc */ -@@ -774,7 +774,7 @@ - static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields) +@@ -685,7 +685,7 @@ ast_type_init(PyObject *self, PyObject *args, PyObject *kw) + Py_ssize_t i, numfields = 0; + int res = -1; + PyObject *key, *value, *fields; +- if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), astmodulestate_global->_fields, &fields) < 0) { ++ if (_Pegen_PyObject_LookupAttr((PyObject*)Py_TYPE(self), astmodulestate_global->_fields, &fields) < 0) { + goto cleanup; + } + if (fields) { +@@ -698,7 +698,7 @@ ast_type_init(PyObject *self, PyObject *args, PyObject *kw) + if (numfields < PyTuple_GET_SIZE(args)) { + PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most " + "%zd positional argument%s", +- _PyType_Name(Py_TYPE(self)), ++ _Ta3Type_Name(Py_TYPE(self)), + numfields, numfields == 1 ? "" : "s"); + res = -1; + goto cleanup; +@@ -733,7 +733,7 @@ static PyObject * + ast_type_reduce(PyObject *self, PyObject *unused) { - _Py_IDENTIFIER(__module__); -- _Py_IDENTIFIER(_ast); -+ _Py_IDENTIFIER(_ast3); - PyObject *fnames, *result; - int i; - fnames = PyTuple_New(num_fields); -@@ -791,7 +791,7 @@ - type, base, - _PyUnicode_FromId(&PyId__fields), fnames, - _PyUnicode_FromId(&PyId___module__), -- _PyUnicode_FromId(&PyId__ast)); -+ _PyUnicode_FromId(&PyId__ast3)); - Py_DECREF(fnames); - return (PyTypeObject*)result; - } -@@ -1010,11 +1010,16 @@ - class ASTModuleVisitor(PickleVisitor): + PyObject *dict; +- if (_PyObject_LookupAttr(self, astmodulestate_global->__dict__, &dict) < 0) { ++ if (_Pegen_PyObject_LookupAttr(self, astmodulestate_global->__dict__, &dict) < 0) { + return NULL; + } + if (dict) { +@@ -1023,7 +1023,7 @@ class ASTModuleVisitor(PickleVisitor): def visitModule(self, mod): -+ self.emit("PyObject *ast3_parse(PyObject *self, PyObject *args);", 0) -+ self.emit("static PyMethodDef ast3_methods[] = {", 0) -+ self.emit(' {"_parse", ast3_parse, METH_VARARGS, "Parse string into typed AST."},', 0) -+ self.emit(" {NULL, NULL, 0, NULL}", 0) -+ self.emit("};", 0) - self.emit("static struct PyModuleDef _astmodule = {", 0) -- self.emit(' PyModuleDef_HEAD_INIT, "_ast"', 0) -+ self.emit(' PyModuleDef_HEAD_INIT, "_ast3", NULL, 0, ast3_methods', 0) - self.emit("};", 0) self.emit("PyMODINIT_FUNC", 0) - self.emit("PyInit__ast(void)", 0) + self.emit("PyInit__ast3(void)", 0) self.emit("{", 0) - self.emit("PyObject *m, *d;", 1) + self.emit("PyObject *m;", 1) self.emit("if (!init_types()) return NULL;", 1) -@@ -1199,7 +1204,7 @@ +@@ -1223,7 +1223,7 @@ class ObjVisitor(PickleVisitor): class PartingShots(StaticVisitor): CODE = """ @@ -81,16 +88,34 @@ { if (!init_types()) return NULL; -@@ -1207,7 +1212,7 @@ +@@ -1231,16 +1231,12 @@ PyObject* PyAST_mod2obj(mod_ty t) } /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ -mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) +mod_ty Ta3AST_obj2mod(PyObject* ast, PyArena* arena, int mode) { - mod_ty res; PyObject *req_type[3]; -@@ -1237,7 +1242,7 @@ + const char * const req_name[] = {"Module", "Expression", "Interactive"}; + int isinstance; + +- if (PySys_Audit("compile", "OO", ast, Py_None) < 0) { +- return NULL; +- } +- + req_type[0] = astmodulestate_global->Module_type; + req_type[1] = astmodulestate_global->Expression_type; + req_type[2] = astmodulestate_global->Interactive_type; +@@ -1255,7 +1251,7 @@ mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) + return NULL; + if (!isinstance) { + PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", +- req_name[mode], _PyType_Name(Py_TYPE(ast))); ++ req_name[mode], _Ta3Type_Name(Py_TYPE(ast))); + return NULL; + } + +@@ -1266,7 +1262,7 @@ mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) return res; } @@ -99,16 +124,71 @@ { if (!init_types()) return -1; -@@ -1276,9 +1281,9 @@ - PrototypeVisitor(f), - ) - c.visit(mod) +@@ -1346,11 +1342,11 @@ static void astmodule_free(void* module) { + + static struct PyModuleDef _astmodule = { + PyModuleDef_HEAD_INIT, +- "_ast", ++ "_ast3", + NULL, + sizeof(astmodulestate), +- NULL, ++ ast3_methods, + NULL, + astmodule_traverse, + astmodule_clear, + astmodule_free, +@@ -1387,14 +1383,15 @@ def main(srcfile, dump_module=False): + if H_FILE: + with open(H_FILE, "w") as f: + f.write(auto_gen_msg) +- f.write('#ifndef Py_PYTHON_AST_H\n') +- f.write('#define Py_PYTHON_AST_H\n') ++ f.write('#ifndef Ta3_PYTHON_AST_H\n') ++ f.write('#define Ta3_PYTHON_AST_H\n') + f.write('#ifdef __cplusplus\n') + f.write('extern "C" {\n') + f.write('#endif\n') + f.write('\n') + f.write('#ifndef Py_LIMITED_API\n') + f.write('#include "asdl.h"\n') ++ f.write('#include "../Include/ta3_compat.h"') + f.write('\n') + f.write('#undef Yield /* undefine macro conflicting with */\n') + f.write('\n') +@@ -1405,15 +1402,15 @@ def main(srcfile, dump_module=False): + f.write("// Note: these macros affect function definitions, not only call sites.\n") + PrototypeVisitor(f).visit(mod) + f.write("\n") - f.write("PyObject* PyAST_mod2obj(mod_ty t);\n") - f.write("mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode);\n") - f.write("int PyAST_Check(PyObject* obj);\n") + f.write("PyObject* Ta3AST_mod2obj(mod_ty t);\n") + f.write("mod_ty Ta3AST_obj2mod(PyObject* ast, PyArena* arena, int mode);\n") + f.write("int Ta3AST_Check(PyObject* obj);\n") + f.write("#endif /* !Py_LIMITED_API */\n") + f.write('\n') + f.write('#ifdef __cplusplus\n') + f.write('}\n') + f.write('#endif\n') +- f.write('#endif /* !Py_PYTHON_AST_H */\n') ++ f.write('#endif /* !Ta3_PYTHON_AST_H */\n') if C_FILE: with open(C_FILE, "w") as f: +@@ -1421,9 +1418,14 @@ def main(srcfile, dump_module=False): + f.write('#include \n') + f.write('\n') + f.write('#include "Python.h"\n') +- f.write('#include "%s-ast.h"\n' % mod.name) ++ f.write('#include "../Include/%s-ast.h"\n' % mod.name) + f.write('#include "structmember.h" // PyMemberDef\n') + f.write('\n') ++ f.write("PyObject *ast3_parse(PyObject *self, PyObject *args);\n") ++ f.write("static PyMethodDef ast3_methods[] = {\n") ++ f.write(' {"_parse", ast3_parse, METH_VARARGS, "Parse string into typed AST."},\n') ++ f.write(" {NULL, NULL, NULL}\n") ++ f.write("};\n") + + generate_module_def(f, mod) + diff --git a/tools/ast.patch b/tools/ast.patch deleted file mode 100644 index b6854a47..00000000 --- a/tools/ast.patch +++ /dev/null @@ -1,444 +0,0 @@ -diff --git a/ast3/Python/ast.c b/ast3/Python/ast.c -index e12f8e6..1fa762d 100644 ---- a/ast3/Python/ast.c -+++ b/ast3/Python/ast.c -@@ -665,6 +665,13 @@ new_identifier(const char *n, struct compiling *c) - - #define NEW_IDENTIFIER(n) new_identifier(STR(n), c) - -+static string -+new_type_comment(const char *s, struct compiling *c) -+{ -+ return PyUnicode_DecodeUTF8(s, strlen(s), NULL); -+} -+#define NEW_TYPE_COMMENT(n) new_type_comment(STR(n), c) -+ - static int - ast_error(struct compiling *c, const node *n, const char *errmsg) - { -@@ -734,11 +741,15 @@ num_stmts(const node *n) - case simple_stmt: - return NCH(n) / 2; /* Divide by 2 to remove count of semi-colons */ - case suite: -+ /* suite: simple_stmt | NEWLINE [TYPE_COMMENT NEWLINE] INDENT stmt+ DEDENT */ - if (NCH(n) == 1) - return num_stmts(CHILD(n, 0)); - else { -+ i = 2; - l = 0; -- for (i = 2; i < (NCH(n) - 1); i++) -+ if (TYPE(CHILD(n, 1)) == TYPE_COMMENT) -+ i += 2; -+ for (; i < (NCH(n) - 1); i++) - l += num_stmts(CHILD(n, i)); - return l; - } -@@ -763,10 +774,13 @@ Ta3AST_FromNodeObject(const node *n, PyCompilerFlags *flags, - { - int i, j, k, num; - asdl_seq *stmts = NULL; -+ asdl_seq *type_ignores = NULL; - stmt_ty s; - node *ch; - struct compiling c; - mod_ty res = NULL; -+ asdl_seq *argtypes = NULL; -+ expr_ty ret, arg; - - c.c_arena = arena; - /* borrowed reference */ -@@ -806,7 +820,23 @@ Ta3AST_FromNodeObject(const node *n, PyCompilerFlags *flags, - } - } - } -- res = Module(stmts, arena); -+ -+ /* Type ignores are stored under the ENDMARKER in file_input. */ -+ ch = CHILD(n, NCH(n) - 1); -+ REQ(ch, ENDMARKER); -+ num = NCH(ch); -+ type_ignores = _Ta3_asdl_seq_new(num, arena); -+ if (!type_ignores) -+ goto out; -+ -+ for (i = 0; i < num; i++) { -+ type_ignore_ty ti = TypeIgnore(LINENO(CHILD(ch, i)), arena); -+ if (!ti) -+ goto out; -+ asdl_seq_SET(type_ignores, i, ti); -+ } -+ -+ res = Module(stmts, type_ignores, arena); - break; - case eval_input: { - expr_ty testlist_ast; -@@ -857,6 +887,40 @@ Ta3AST_FromNodeObject(const node *n, PyCompilerFlags *flags, - res = Interactive(stmts, arena); - } - break; -+ case func_type_input: -+ n = CHILD(n, 0); -+ REQ(n, func_type); -+ -+ if (TYPE(CHILD(n, 1)) == typelist) { -+ ch = CHILD(n, 1); -+ /* this is overly permissive -- we don't pay any attention to -+ * stars on the args -- just parse them into an ordered list */ -+ num = 0; -+ for (i = 0; i < NCH(ch); i++) { -+ if (TYPE(CHILD(ch, i)) == test) -+ num++; -+ } -+ -+ argtypes = _Ta3_asdl_seq_new(num, arena); -+ -+ j = 0; -+ for (i = 0; i < NCH(ch); i++) { -+ if (TYPE(CHILD(ch, i)) == test) { -+ arg = ast_for_expr(&c, CHILD(ch, i)); -+ if (!arg) -+ goto out; -+ asdl_seq_SET(argtypes, j++, arg); -+ } -+ } -+ } -+ else -+ argtypes = _Ta3_asdl_seq_new(0, arena); -+ -+ ret = ast_for_expr(&c, CHILD(n, NCH(n) - 1)); -+ if (!ret) -+ goto out; -+ res = FunctionType(argtypes, ret, arena); -+ break; - default: - PyErr_Format(PyExc_SystemError, - "invalid node %d for Ta3AST_FromNode", TYPE(n)); -@@ -1250,7 +1314,7 @@ ast_for_arg(struct compiling *c, const node *n) - return NULL; - } - -- ret = arg(name, annotation, LINENO(n), n->n_col_offset, c->c_arena); -+ ret = arg(name, annotation, NULL, LINENO(n), n->n_col_offset, c->c_arena); - if (!ret) - return NULL; - return ret; -@@ -1308,12 +1372,19 @@ handle_keywordonly_args(struct compiling *c, const node *n, int start, - goto error; - if (forbidden_name(c, argname, ch, 0)) - goto error; -- arg = arg(argname, annotation, LINENO(ch), ch->n_col_offset, -+ arg = arg(argname, annotation, NULL, LINENO(ch), ch->n_col_offset, - c->c_arena); - if (!arg) - goto error; - asdl_seq_SET(kwonlyargs, j++, arg); -- i += 2; /* the name and the comma */ -+ i += 1; /* the name */ -+ if (TYPE(CHILD(n, i)) == COMMA) -+ i += 1; /* the comma, if present */ -+ break; -+ case TYPE_COMMENT: -+ /* arg will be equal to the last argument processed */ -+ arg->type_comment = NEW_TYPE_COMMENT(ch); -+ i += 1; - break; - case DOUBLESTAR: - return i; -@@ -1448,11 +1519,14 @@ ast_for_arguments(struct compiling *c, const node *n) - if (!arg) - return NULL; - asdl_seq_SET(posargs, k++, arg); -- i += 2; /* the name and the comma */ -+ i += 1; /* the name */ -+ if (TYPE(CHILD(n, i)) == COMMA) -+ i += 1; /* the comma, if present */ - break; - case STAR: - if (i+1 >= NCH(n) || -- (i+2 == NCH(n) && TYPE(CHILD(n, i+1)) == COMMA)) { -+ (i+2 == NCH(n) && (TYPE(CHILD(n, i+1)) == COMMA -+ || TYPE(CHILD(n, i+1)) == TYPE_COMMENT))) { - ast_error(c, CHILD(n, i), - "named arguments must follow bare *"); - return NULL; -@@ -1461,6 +1535,13 @@ ast_for_arguments(struct compiling *c, const node *n) - if (TYPE(ch) == COMMA) { - int res = 0; - i += 2; /* now follows keyword only arguments */ -+ -+ if (TYPE(CHILD(n, i)) == TYPE_COMMENT) { -+ ast_error(c, CHILD(n, i), -+ "bare * has associated type comment"); -+ return NULL; -+ } -+ - res = handle_keywordonly_args(c, n, i, - kwonlyargs, kwdefaults); - if (res == -1) return NULL; -@@ -1471,7 +1552,15 @@ ast_for_arguments(struct compiling *c, const node *n) - if (!vararg) - return NULL; - -- i += 3; -+ i += 2; /* the star and the name */ -+ if (TYPE(CHILD(n, i)) == COMMA) -+ i += 1; /* the comma, if present */ -+ -+ if (TYPE(CHILD(n, i)) == TYPE_COMMENT) { -+ vararg->type_comment = NEW_TYPE_COMMENT(CHILD(n, i)); -+ i += 1; -+ } -+ - if (i < NCH(n) && (TYPE(CHILD(n, i)) == tfpdef - || TYPE(CHILD(n, i)) == vfpdef)) { - int res = 0; -@@ -1488,7 +1577,19 @@ ast_for_arguments(struct compiling *c, const node *n) - kwarg = ast_for_arg(c, ch); - if (!kwarg) - return NULL; -- i += 3; -+ i += 2; /* the double star and the name */ -+ if (TYPE(CHILD(n, i)) == COMMA) -+ i += 1; /* the comma, if present */ -+ break; -+ case TYPE_COMMENT: -+ assert(i); -+ -+ if (kwarg) -+ arg = kwarg; -+ -+ /* arg will be equal to the last argument processed */ -+ arg->type_comment = NEW_TYPE_COMMENT(ch); -+ i += 1; - break; - default: - PyErr_Format(PyExc_SystemError, -@@ -1593,12 +1694,14 @@ static stmt_ty - ast_for_funcdef_impl(struct compiling *c, const node *n, - asdl_seq *decorator_seq, int is_async) - { -- /* funcdef: 'def' NAME parameters ['->' test] ':' suite */ -+ /* funcdef: 'def' NAME parameters ['->' test] ':' [TYPE_COMMENT] suite */ - identifier name; - arguments_ty args; - asdl_seq *body; - expr_ty returns = NULL; - int name_i = 1; -+ node *tc; -+ string type_comment = NULL; - - REQ(n, funcdef); - -@@ -1616,17 +1719,30 @@ ast_for_funcdef_impl(struct compiling *c, const node *n, - return NULL; - name_i += 2; - } -+ if (TYPE(CHILD(n, name_i + 3)) == TYPE_COMMENT) { -+ type_comment = NEW_TYPE_COMMENT(CHILD(n, name_i + 3)); -+ name_i += 1; -+ } - body = ast_for_suite(c, CHILD(n, name_i + 3)); - if (!body) - return NULL; - -+ if (!type_comment && NCH(CHILD(n, name_i + 3)) > 1) { -+ /* If the function doesn't have a type comment on the same line, check -+ * if the suite has a type comment in it. */ -+ tc = CHILD(CHILD(n, name_i + 3), 1); -+ -+ if (TYPE(tc) == TYPE_COMMENT) -+ type_comment = NEW_TYPE_COMMENT(tc); -+ } -+ - if (is_async) - return AsyncFunctionDef(name, args, body, decorator_seq, returns, -- LINENO(n), -+ type_comment, LINENO(n), - n->n_col_offset, c->c_arena); - else - return FunctionDef(name, args, body, decorator_seq, returns, -- LINENO(n), -+ type_comment, LINENO(n), - n->n_col_offset, c->c_arena); - } - -@@ -2896,15 +3012,16 @@ ast_for_expr_stmt(struct compiling *c, const node *n) - { - REQ(n, expr_stmt); - /* expr_stmt: testlist_star_expr (annassign | augassign (yield_expr|testlist) | -- ('=' (yield_expr|testlist_star_expr))*) -+ ('=' (yield_expr|testlist_star_expr))* [TYPE_COMMENT]) - annassign: ':' test ['=' test] - testlist_star_expr: (test|star_expr) (',' test|star_expr)* [','] - augassign: '+=' | '-=' | '*=' | '@=' | '/=' | '%=' | '&=' | '|=' | '^=' - | '<<=' | '>>=' | '**=' | '//=' - test: ... here starts the operator precedence dance - */ -+ int num = NCH(n); - -- if (NCH(n) == 1) { -+ if (num == 1 || (num == 2 && TYPE(CHILD(n, 1)) == TYPE_COMMENT)) { - expr_ty e = ast_for_testlist(c, CHILD(n, 0)); - if (!e) - return NULL; -@@ -3020,17 +3137,22 @@ ast_for_expr_stmt(struct compiling *c, const node *n) - } - } - else { -- int i; -+ int i, nch_minus_type, has_type_comment; - asdl_seq *targets; - node *value; - expr_ty expression; -+ string type_comment; - - /* a normal assignment */ - REQ(CHILD(n, 1), EQUAL); -- targets = _Ta3_asdl_seq_new(NCH(n) / 2, c->c_arena); -+ -+ has_type_comment = TYPE(CHILD(n, num - 1)) == TYPE_COMMENT; -+ nch_minus_type = num - has_type_comment; -+ -+ targets = _Ta3_asdl_seq_new(nch_minus_type / 2, c->c_arena); - if (!targets) - return NULL; -- for (i = 0; i < NCH(n) - 2; i += 2) { -+ for (i = 0; i < nch_minus_type - 2; i += 2) { - expr_ty e; - node *ch = CHILD(n, i); - if (TYPE(ch) == yield_expr) { -@@ -3047,14 +3169,18 @@ ast_for_expr_stmt(struct compiling *c, const node *n) - - asdl_seq_SET(targets, i / 2, e); - } -- value = CHILD(n, NCH(n) - 1); -+ value = CHILD(n, nch_minus_type - 1); - if (TYPE(value) == testlist_star_expr) - expression = ast_for_testlist(c, value); - else - expression = ast_for_expr(c, value); - if (!expression) - return NULL; -- return Assign(targets, expression, LINENO(n), n->n_col_offset, c->c_arena); -+ if (has_type_comment) -+ type_comment = NEW_TYPE_COMMENT(CHILD(n, nch_minus_type)); -+ else -+ type_comment = NULL; -+ return Assign(targets, expression, type_comment, LINENO(n), n->n_col_offset, c->c_arena); - } - } - -@@ -3461,7 +3587,7 @@ ast_for_assert_stmt(struct compiling *c, const node *n) - static asdl_seq * - ast_for_suite(struct compiling *c, const node *n) - { -- /* suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT */ -+ /* suite: simple_stmt | NEWLINE [TYPE_COMMENT NEWLINE] INDENT stmt+ DEDENT */ - asdl_seq *seq; - stmt_ty s; - int i, total, num, end, pos = 0; -@@ -3491,7 +3617,11 @@ ast_for_suite(struct compiling *c, const node *n) - } - } - else { -- for (i = 2; i < (NCH(n) - 1); i++) { -+ i = 2; -+ if (TYPE(CHILD(n, 1)) == TYPE_COMMENT) -+ i += 2; -+ -+ for (; i < (NCH(n) - 1); i++) { - ch = CHILD(n, i); - REQ(ch, stmt); - num = num_stmts(ch); -@@ -3692,11 +3822,15 @@ ast_for_for_stmt(struct compiling *c, const node *n, int is_async) - expr_ty expression; - expr_ty target, first; - const node *node_target; -- /* for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite] */ -+ int has_type_comment; -+ string type_comment; -+ /* for_stmt: 'for' exprlist 'in' testlist ':' [TYPE_COMMENT] suite ['else' ':' suite] */ - REQ(n, for_stmt); - -- if (NCH(n) == 9) { -- seq = ast_for_suite(c, CHILD(n, 8)); -+ has_type_comment = TYPE(CHILD(n, 5)) == TYPE_COMMENT; -+ -+ if (NCH(n) == 9 + has_type_comment) { -+ seq = ast_for_suite(c, CHILD(n, 8 + has_type_comment)); - if (!seq) - return NULL; - } -@@ -3716,17 +3850,22 @@ ast_for_for_stmt(struct compiling *c, const node *n, int is_async) - expression = ast_for_testlist(c, CHILD(n, 3)); - if (!expression) - return NULL; -- suite_seq = ast_for_suite(c, CHILD(n, 5)); -+ suite_seq = ast_for_suite(c, CHILD(n, 5 + has_type_comment)); - if (!suite_seq) - return NULL; - -+ if (has_type_comment) -+ type_comment = NEW_TYPE_COMMENT(CHILD(n, 5)); -+ else -+ type_comment = NULL; -+ - if (is_async) - return AsyncFor(target, expression, suite_seq, seq, -- LINENO(n), n->n_col_offset, -+ type_comment, LINENO(n), n->n_col_offset, - c->c_arena); - else - return For(target, expression, suite_seq, seq, -- LINENO(n), n->n_col_offset, -+ type_comment, LINENO(n), n->n_col_offset, - c->c_arena); - } - -@@ -3872,20 +4011,24 @@ ast_for_with_item(struct compiling *c, const node *n) - return withitem(context_expr, optional_vars, c->c_arena); - } - --/* with_stmt: 'with' with_item (',' with_item)* ':' suite */ -+/* with_stmt: 'with' with_item (',' with_item)* ':' [TYPE_COMMENT] suite */ - static stmt_ty - ast_for_with_stmt(struct compiling *c, const node *n, int is_async) - { -- int i, n_items; -+ int i, n_items, nch_minus_type, has_type_comment; - asdl_seq *items, *body; -+ string type_comment; - - REQ(n, with_stmt); - -- n_items = (NCH(n) - 2) / 2; -+ has_type_comment = TYPE(CHILD(n, NCH(n) - 2)) == TYPE_COMMENT; -+ nch_minus_type = NCH(n) - has_type_comment; -+ -+ n_items = (nch_minus_type - 2) / 2; - items = _Ta3_asdl_seq_new(n_items, c->c_arena); - if (!items) - return NULL; -- for (i = 1; i < NCH(n) - 2; i += 2) { -+ for (i = 1; i < nch_minus_type - 2; i += 2) { - withitem_ty item = ast_for_with_item(c, CHILD(n, i)); - if (!item) - return NULL; -@@ -3896,10 +4039,15 @@ ast_for_with_stmt(struct compiling *c, const node *n, int is_async) - if (!body) - return NULL; - -+ if (has_type_comment) -+ type_comment = NEW_TYPE_COMMENT(CHILD(n, NCH(n) - 2)); -+ else -+ type_comment = NULL; -+ - if (is_async) -- return AsyncWith(items, body, LINENO(n), n->n_col_offset, c->c_arena); -+ return AsyncWith(items, body, type_comment, LINENO(n), n->n_col_offset, c->c_arena); - else -- return With(items, body, LINENO(n), n->n_col_offset, c->c_arena); -+ return With(items, body, type_comment, LINENO(n), n->n_col_offset, c->c_arena); - } - - static stmt_ty diff --git a/tools/c_generator.patch b/tools/c_generator.patch new file mode 100644 index 00000000..2e3227a5 --- /dev/null +++ b/tools/c_generator.patch @@ -0,0 +1,13 @@ +diff --git a/ast3/Tools/peg_generator/pegen/c_generator.py b/ast3/Tools/peg_generator/pegen/c_generator.py +index 3bf6d9e..ac6f9ae 100644 +--- a/ast3/Tools/peg_generator/pegen/c_generator.py ++++ b/ast3/Tools/peg_generator/pegen/c_generator.py +@@ -27,7 +27,7 @@ from pegen.parser_generator import ParserGenerator + + EXTENSION_PREFIX = """\ + #include "pegen.h" +- ++#include "ta3_compat.h" + """ + + diff --git a/tools/find_exported_symbols b/tools/find_exported_symbols index a70f7ce0..bd827ffb 100755 --- a/tools/find_exported_symbols +++ b/tools/find_exported_symbols @@ -2,11 +2,16 @@ PROJ_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/.." # This requires GNU binutils (e.g. brew install binutils). +if [ "$(uname)" == "Darwin" ]; then +OBJDUMP="/usr/local/opt/binutils/bin/gobjdump" +else +OBJDUMP="objdump" +fi -/usr/local/opt/binutils/bin/gobjdump -t $PROJ_DIR/build/lib*/_ast${1}.*.so \ +$OBJDUMP -t $PROJ_DIR/build/lib*/typed_ast/_ast${1}.*.so \ | grep ' g ' \ | grep -v UND \ - | sed 's/.* _//' \ + | sed -r 's/[[:xdigit:]]+ g .* +(.*)/\1/' \ | grep -v PyInit__ast \ | grep 'Py' \ > "exported_symbols${1}.txt" diff --git a/tools/import_files.sh b/tools/import_files.sh new file mode 100755 index 00000000..b7b00dcd --- /dev/null +++ b/tools/import_files.sh @@ -0,0 +1,27 @@ +#!/bin/bash -ex + +# Automate steps 1-4 of update_process.md (Mac). + +HERE=$(dirname ${BASH_SOURCE[0]}) +cd $HERE/.. +pwd + +CPYTHON=~/cpython + +DIRS="Grammar Include Parser Python Tools Parser/pegen" +C_FILES="Parser/pegen/parse.c Parser/pegen/parse_string.c Parser/pegen/peg_api.c Parser/pegen/pegen.c Parser/tokenizer.c Python/asdl.c Python/Python-ast.c" +H_FILES="Include/asdl.h Include/Python-ast.h Include/token.h Parser/tokenizer.h Parser/pegen/parse_string.h Parser/pegen/pegen.h" +OTHER_FILES="Grammar/python.gram Grammar/Tokens Parser/Python.asdl Parser/asdl.py Parser/asdl_c.py Tools/peg_generator" + +for dir in $DIRS +do + rm -rf ast3/$dir + mkdir -p ast3/$dir +done + +for file in $C_FILES $H_FILES $OTHER_FILES +do + cp -r $CPYTHON/$file ast3/$file +done + +cp $CPYTHON/Include/internal/pegen_interface.h ast3/Include/pegen_interface.h \ No newline at end of file diff --git a/tools/parse_string.c.patch b/tools/parse_string.c.patch new file mode 100644 index 00000000..b809986e --- /dev/null +++ b/tools/parse_string.c.patch @@ -0,0 +1,22 @@ +diff --git a/ast3/Parser/pegen/parse_string.c b/ast3/Parser/pegen/parse_string.c +index ca4b733..0a63686 100644 +--- a/ast3/Parser/pegen/parse_string.c ++++ b/ast3/Parser/pegen/parse_string.c +@@ -4,6 +4,8 @@ + #include "pegen.h" + #include "parse_string.h" + ++#include "../Include/ta3_compat.h" ++ + //// STRING HANDLING FUNCTIONS //// + + // These functions are ported directly from Python/ast.c with some modifications +@@ -131,7 +133,7 @@ static PyObject * + decode_bytes_with_escapes(Parser *p, const char *s, Py_ssize_t len, Token *t) + { + const char *first_invalid_escape; +- PyObject *result = _PyBytes_DecodeEscape(s, len, NULL, &first_invalid_escape); ++ PyObject *result = _PyBytes_DecodeEscape(s, len, NULL, 0, NULL, &first_invalid_escape); + if (result == NULL) { + return NULL; + } diff --git a/tools/parsetok.patch b/tools/parsetok.patch deleted file mode 100644 index ad0c7ddb..00000000 --- a/tools/parsetok.patch +++ /dev/null @@ -1,95 +0,0 @@ -diff --git a/ast3/Parser/parsetok.c b/ast3/Parser/parsetok.c -index 9f01a0d..5529feb 100644 ---- a/ast3/Parser/parsetok.c -+++ b/ast3/Parser/parsetok.c -@@ -177,6 +177,38 @@ warn(const char *msg, const char *filename, int lineno) - #endif - #endif - -+typedef struct { -+ int *items; -+ size_t size; -+ size_t num_items; -+} growable_int_array; -+ -+int growable_int_array_init(growable_int_array *arr, size_t initial_size) { -+ assert(initial_size > 0); -+ arr->items = malloc(initial_size * sizeof(*arr->items)); -+ arr->size = initial_size; -+ arr->num_items = 0; -+ -+ return arr->items != NULL; -+} -+ -+int growable_int_array_add(growable_int_array *arr, int item) { -+ if (arr->num_items >= arr->size) { -+ arr->size *= 2; -+ arr->items = realloc(arr->items, arr->size * sizeof(*arr->items)); -+ if (!arr->items) -+ return 0; -+ } -+ -+ arr->items[arr->num_items] = item; -+ arr->num_items++; -+ return 1; -+} -+ -+void growable_int_array_deallocate(growable_int_array *arr) { -+ free(arr->items); -+} -+ - /* Parse input coming from the given tokenizer structure. - Return error code. */ - -@@ -188,6 +220,13 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret, - node *n; - int started = 0; - -+ growable_int_array type_ignores; -+ if (!growable_int_array_init(&type_ignores, 10)) { -+ err_ret->error = E_NOMEM; -+ Ta3Tokenizer_Free(tok); -+ return NULL; -+ } -+ - if ((ps = Ta3Parser_New(g, start)) == NULL) { - err_ret->error = E_NOMEM; - Ta3Tokenizer_Free(tok); -@@ -259,6 +298,14 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret, - else - col_offset = -1; - -+ if (type == TYPE_IGNORE) { -+ if (!growable_int_array_add(&type_ignores, tok->lineno)) { -+ err_ret->error = E_NOMEM; -+ break; -+ } -+ continue; -+ } -+ - if ((err_ret->error = - Ta3Parser_AddToken(ps, (int)type, str, - tok->lineno, col_offset, -@@ -275,6 +322,22 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret, - n = ps->p_tree; - ps->p_tree = NULL; - -+ if (n->n_type == file_input) { -+ /* Put type_ignore nodes in the ENDMARKER of file_input. */ -+ int num; -+ node *ch; -+ size_t i; -+ -+ num = NCH(n); -+ ch = CHILD(n, num - 1); -+ REQ(ch, ENDMARKER); -+ -+ for (i = 0; i < type_ignores.num_items; i++) { -+ Ta3Node_AddChild(ch, TYPE_IGNORE, NULL, type_ignores.items[i], 0); -+ } -+ } -+ growable_int_array_deallocate(&type_ignores); -+ - #ifndef PGEN - /* Check that the source for a single input statement really - is a single statement by looking at what is left in the diff --git a/tools/regen_parse.sh b/tools/regen_parse.sh new file mode 100755 index 00000000..cf052579 --- /dev/null +++ b/tools/regen_parse.sh @@ -0,0 +1,3 @@ +cd ast3/Tools/peg_generator +python3 -m pegen -q c ../../Grammar/python.gram ../../Grammar/Tokens -o ../../Parser/pegen/parse.c +cd ../../.. diff --git a/tools/rename_symbols.sh b/tools/rename_symbols.sh new file mode 100755 index 00000000..a3afde42 --- /dev/null +++ b/tools/rename_symbols.sh @@ -0,0 +1,18 @@ +rm -rf build +grep -v ast3/Custom setup.py | python3 - build + +./tools/find_exported_symbols 3 +./tools/update_exported_symbols 3 + +patch ast3/Parser/asdl_c.py #ifndef Ta3_COMPAT_H +> #define Ta3_COMPAT_H +> +> // Various workarounds to make the parser compatible with older 3.x +> #include +> +> // f-string input is new in 3.9 +> #if PY_MINOR_VERSION < 9 +> #define Py_fstring_input 800 +> #endif +> +> // top level await new in 3.9 +> #if PY_MINOR_VERSION < 8 +> #define PyCF_ALLOW_TOP_LEVEL_AWAIT 0x2000 +> #endif +> +> // typed_ast was merged into Python in 3.8 +> #if PY_MINOR_VERSION < 8 +> #define PyCF_TYPE_COMMENTS 0x1000 +> #endif +> +> typedef struct { +> int cf_flags; /* bitmask of CO_xxx flags relevant to future */ +> int cf_feature_version; /* minor Python version (PyCF_ONLY_AST) */ +> } PegenCompilerFlags; +> +> #define _PegenCompilerFlags_INIT \ +> (PegenCompilerFlags){.cf_flags = 0, .cf_feature_version = PY_MINOR_VERSION} +> +> +> // Define 3.7+ input types +> #if PY_MINOR_VERSION < 8 +> /* These definitions must match corresponding definitions in graminit.h. */ +> #define Py_single_input 256 +> #define Py_file_input 257 +> #define Py_eval_input 258 +> #define Py_func_type_input 345 +> #endif +> +> // Py_UNREACHABLE was defined in 3.7 +> #if PY_MINOR_VERSION < 7 +> #if defined(RANDALL_WAS_HERE) +> # define Py_UNREACHABLE() \ +> Py_FatalError( \ +> "If you're seeing this, the code is in what I thought was\n" \ +> "an unreachable state.\n\n" \ +> "I could give you advice for what to do, but honestly, why\n" \ +> "should you trust me? I clearly screwed this up. I'm writing\n" \ +> "a message that should never appear, yet I know it will\n" \ +> "probably appear someday.\n\n" \ +> "On a deep level, I know I'm not up to this task.\n" \ +> "I'm so sorry.\n" \ +> "https://xkcd.com/2200") +> #elif defined(Py_DEBUG) +> # define Py_UNREACHABLE() \ +> Py_FatalError( \ +> "We've reached an unreachable state. Anything is possible.\n" \ +> "The limits were in our heads all along. Follow your dreams.\n" \ +> "https://xkcd.com/2200") +> #elif defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER) +> # define Py_UNREACHABLE() __builtin_unreachable() +> #elif defined(_MSC_VER) +> # define Py_UNREACHABLE() __assume(0) +> #else +> # define Py_UNREACHABLE() \ +> Py_FatalError("Unreachable C code path reached") +> #endif +> #endif +> +> // 3.7 also introduced _Py_TypeName, which we provide an alternative for it here +> const char * _Ta3Type_Name(PyTypeObject *); +> +> int _Pegen_PyObject_LookupAttr(PyObject *, PyObject *, PyObject **); +> +> const char * +> _Pegen_SourceAsString(PyObject *cmd, const char *funcname, const char *what, PegenCompilerFlags *cf, PyObject **cmd_copy); +> +> #endif // Ta3_COMPAT_H diff --git a/tools/token.patch b/tools/token.patch deleted file mode 100644 index b907c98c..00000000 --- a/tools/token.patch +++ /dev/null @@ -1,17 +0,0 @@ -diff --git a/ast3/Include/token.h b/ast3/Include/token.h -index a657fdd..d0b2b94 100644 ---- a/ast3/Include/token.h -+++ b/ast3/Include/token.h -@@ -68,8 +68,10 @@ extern "C" { - /* These aren't used by the C tokenizer but are needed for tokenize.py */ - #define COMMENT 55 - #define NL 56 --#define ENCODING 57 --#define N_TOKENS 58 -+#define ENCODING 57 -+#define TYPE_IGNORE 58 -+#define TYPE_COMMENT 59 -+#define N_TOKENS 60 - - /* Special definitions for cooperation with parser */ - diff --git a/tools/tokenizer.patch b/tools/tokenizer.patch deleted file mode 100644 index e9cfd803..00000000 --- a/tools/tokenizer.patch +++ /dev/null @@ -1,80 +0,0 @@ -diff --git a/ast3/Parser/tokenizer.c b/ast3/Parser/tokenizer.c -index 617a744..667fb4a 100644 ---- a/ast3/Parser/tokenizer.c -+++ b/ast3/Parser/tokenizer.c -@@ -105,10 +105,16 @@ const char *_Ta3Parser_TokenNames[] = { - "OP", - "AWAIT", - "ASYNC", -+ "TYPE_IGNORE", -+ "TYPE_COMMENT", - "", - "" - }; - -+/* Spaces in this constant are treated as "zero or more spaces or tabs" when -+ tokenizing. */ -+static const char* type_comment_prefix = "# type: "; -+ - - /* Create and initialize a new tok_state structure */ - -@@ -1493,10 +1499,56 @@ tok_get(struct tok_state *tok, char **p_start, char **p_end) - /* Set start of current token */ - tok->start = tok->cur - 1; - -- /* Skip comment */ -+ /* Skip comment, unless it's a type comment */ - if (c == '#') { -- while (c != EOF && c != '\n') { -+ const char *prefix, *p, *type_start; -+ -+ while (c != EOF && c != '\n') - c = tok_nextc(tok); -+ -+ p = tok->start; -+ prefix = type_comment_prefix; -+ while (*prefix && p < tok->cur) { -+ if (*prefix == ' ') { -+ while (*p == ' ' || *p == '\t') -+ p++; -+ } else if (*prefix == *p) { -+ p++; -+ } else { -+ break; -+ } -+ -+ prefix++; -+ } -+ -+ /* This is a type comment if we matched all of type_comment_prefix. */ -+ if (!*prefix) { -+ int is_type_ignore = 1; -+ tok_backup(tok, c); /* don't eat the newline or EOF */ -+ -+ type_start = p; -+ -+ is_type_ignore = tok->cur >= p + 6 && memcmp(p, "ignore", 6) == 0; -+ p += 6; -+ while (is_type_ignore && p < tok->cur) { -+ if (*p == '#') -+ break; -+ is_type_ignore = is_type_ignore && (*p == ' ' || *p == '\t'); -+ p++; -+ } -+ -+ if (is_type_ignore) { -+ /* If this type ignore is the only thing on the line, consume the newline also. */ -+ if (blankline) { -+ tok_nextc(tok); -+ tok->atbol = 1; -+ } -+ return TYPE_IGNORE; -+ } else { -+ *p_start = (char *) type_start; /* after type_comment_prefix */ -+ *p_end = tok->cur; -+ return TYPE_COMMENT; -+ } - } - } - diff --git a/tools/update_ast3_grammar b/tools/update_ast3_grammar deleted file mode 100755 index 5dfb1ff0..00000000 --- a/tools/update_ast3_grammar +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -eux - -# Run after changing `Grammar/Grammar` - -PROJ_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/.." - -echo 'Copying pgen' -cp ~/src/cpython37/Parser/pgen tools/pgen3 - -echo 'Updating graminit files' -tools/pgen3 ast3/Grammar/Grammar ast3/Include/graminit.h ast3/Python/graminit.c - -echo 'Grammar file update complete' diff --git a/tools/update_compiler_flags.sh b/tools/update_compiler_flags.sh new file mode 100755 index 00000000..1619e3fe --- /dev/null +++ b/tools/update_compiler_flags.sh @@ -0,0 +1,5 @@ +PROJ_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/.." + +for FILE in $(find "$PROJ_DIR/ast${1}" -type f -name "*.h" -or -name "*.c"); do + sed -i "s/PyCompilerFlags/PegenCompilerFlags/" $FILE +done \ No newline at end of file diff --git a/tools/update_exported_symbols b/tools/update_exported_symbols index e346b399..f595c393 100755 --- a/tools/update_exported_symbols +++ b/tools/update_exported_symbols @@ -7,7 +7,13 @@ for CHANGE in $( cat "$PROJ_DIR/exported_symbols${1}.txt" ); do else NEW="Ta${1}${CHANGE:2}" fi - find "$PROJ_DIR/ast${1}" -type f -name '*.h' -or -name '*.c' | xargs -n 1 sed -i '' "s/$CHANGE/$NEW/" + for FILE in $(find "$PROJ_DIR/ast${1}" -type f -name "*.h" -or -name "*.c" -or -name "*.gram"); do + sed -i "s/$CHANGE/$NEW/" $FILE + done + sed -i "s/$CHANGE/$NEW/" ast3/Tools/peg_generator/pegen/c_generator.py done +sed -i "s/_PyPegen_/_Ta3Pegen_/" ast3/Tools/peg_generator/pegen/c_generator.py +sed -i 's/_PyPegen/_Ta3Pegen/' ast3/Grammar/python.gram + echo "Symbols updated. Remember to also update autogeneration code like Parser/asdl_c.py." diff --git a/tools/update_header_guards b/tools/update_header_guards index 24d6c0ec..f799ee8d 100755 --- a/tools/update_header_guards +++ b/tools/update_header_guards @@ -9,4 +9,10 @@ FOLDER="ast$1" PATTERN='s/Py\([A-Z_]*_H\( \*\/\)\{0,1\}\)$/' PATTERN+="Ta$1" PATTERN+='\1/' -find "$FOLDER" -type f -name '*.h' | xargs -n 1 sed -i '' "$PATTERN" +find "$FOLDER" -type f -name '*.h' -exec sed -i "$PATTERN" {} \; +# manually update some headers +GUARDS='s/STRINGS_H/Ta3_STRINGS_H/ s/PEGEN_H/Ta3_PEGEN_H/ s/Py_PEGENINTERFACE/Ta3_PEGENINTERFACE/' +for GUARD in $GUARDS +do + find "$FOLDER" -type f -name '*.h' -exec sed -i "$GUARD" {} \; +done From a6f6b722c58ddfd3437c1fb288eca84f4d2689bf Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Sun, 10 May 2020 02:55:58 -0700 Subject: [PATCH 2/7] Import files for Python 3.9 --- ast3/Grammar/Grammar | 161 - ast3/Grammar/Tokens | 67 + ast3/Grammar/python.gram | 651 + ast3/Include/Python-ast.h | 530 +- ast3/Include/asdl.h | 16 +- ast3/Include/ast.h | 31 - ast3/Include/bitset.h | 32 - ast3/Include/errcode.h | 38 - ast3/Include/graminit.h | 92 - ast3/Include/grammar.h | 94 - ast3/Include/node.h | 44 - ast3/Include/parsetok.h | 109 - ast3/Include/pegen_interface.h | 46 + ast3/Include/pgenheaders.h | 10 - ast3/Include/token.h | 42 +- ast3/Parser/Python.asdl | 51 +- ast3/Parser/acceler.c | 125 - ast3/Parser/asdl.py | 13 +- ast3/Parser/asdl_c.py | 516 +- ast3/Parser/bitset.c | 66 - ast3/Parser/grammar.c | 273 - ast3/Parser/grammar1.c | 60 - ast3/Parser/node.c | 164 - ast3/Parser/parser.c | 447 - ast3/Parser/parser.h | 42 - ast3/Parser/parsetok.c | 470 - ast3/Parser/pegen/parse.c | 17280 ++++++++++++++++ ast3/Parser/pegen/parse_string.c | 1414 ++ ast3/Parser/pegen/parse_string.h | 46 + ast3/Parser/pegen/peg_api.c | 54 + ast3/Parser/pegen/pegen.c | 2064 ++ ast3/Parser/pegen/pegen.h | 248 + ast3/Parser/tokenizer.c | 655 +- ast3/Parser/tokenizer.h | 53 +- ast3/Python/Python-ast.c | 6377 +++--- ast3/Python/asdl.c | 6 +- ast3/Python/ast.c | 5609 ----- ast3/Python/graminit.c | 2451 --- ast3/Tools/peg_generator/.clang-format | 17 + ast3/Tools/peg_generator/.gitignore | 3 + ast3/Tools/peg_generator/Makefile | 119 + ast3/Tools/peg_generator/data/cprog.py | 11 + .../data/top-pypi-packages-365-days.json | 16011 ++++++++++++++ ast3/Tools/peg_generator/data/xxl.zip | Bin 0 -> 18771 bytes ast3/Tools/peg_generator/mypy.ini | 26 + .../peg_generator/peg_extension/__init__.py | 0 .../peg_extension/peg_extension.c | 154 + ast3/Tools/peg_generator/pegen/__init__.py | 0 ast3/Tools/peg_generator/pegen/__main__.py | 182 + ast3/Tools/peg_generator/pegen/ast_dump.py | 63 + ast3/Tools/peg_generator/pegen/build.py | 248 + ast3/Tools/peg_generator/pegen/c_generator.py | 729 + ast3/Tools/peg_generator/pegen/first_sets.py | 152 + ast3/Tools/peg_generator/pegen/grammar.py | 467 + .../peg_generator/pegen/grammar_parser.py | 677 + .../peg_generator/pegen/grammar_visualizer.py | 65 + .../peg_generator/pegen/metagrammar.gram | 123 + ast3/Tools/peg_generator/pegen/parser.py | 310 + .../peg_generator/pegen/parser_generator.py | 198 + .../peg_generator/pegen/python_generator.py | 232 + ast3/Tools/peg_generator/pegen/sccutils.py | 128 + ast3/Tools/peg_generator/pegen/testutil.py | 133 + ast3/Tools/peg_generator/pegen/tokenizer.py | 86 + ast3/Tools/peg_generator/pyproject.toml | 9 + ast3/Tools/peg_generator/requirements.pip | 2 + ast3/Tools/peg_generator/scripts/__init__.py | 1 + .../peg_generator/scripts/ast_timings.py | 26 + ast3/Tools/peg_generator/scripts/benchmark.py | 137 + .../scripts/download_pypi_packages.py | 86 + .../peg_generator/scripts/find_max_nesting.py | 57 + .../peg_generator/scripts/grammar_grapher.py | 111 + ast3/Tools/peg_generator/scripts/joinstats.py | 66 + .../Tools/peg_generator/scripts/show_parse.py | 120 + .../scripts/test_parse_directory.py | 296 + .../scripts/test_pypi_packages.py | 111 + 75 files changed, 47913 insertions(+), 13690 deletions(-) delete mode 100644 ast3/Grammar/Grammar create mode 100644 ast3/Grammar/Tokens create mode 100644 ast3/Grammar/python.gram delete mode 100644 ast3/Include/ast.h delete mode 100644 ast3/Include/bitset.h delete mode 100644 ast3/Include/errcode.h delete mode 100644 ast3/Include/graminit.h delete mode 100644 ast3/Include/grammar.h delete mode 100644 ast3/Include/node.h delete mode 100644 ast3/Include/parsetok.h create mode 100644 ast3/Include/pegen_interface.h delete mode 100644 ast3/Include/pgenheaders.h delete mode 100644 ast3/Parser/acceler.c mode change 100644 => 100755 ast3/Parser/asdl_c.py delete mode 100644 ast3/Parser/bitset.c delete mode 100644 ast3/Parser/grammar.c delete mode 100644 ast3/Parser/grammar1.c delete mode 100644 ast3/Parser/node.c delete mode 100644 ast3/Parser/parser.c delete mode 100644 ast3/Parser/parser.h delete mode 100644 ast3/Parser/parsetok.c create mode 100644 ast3/Parser/pegen/parse.c create mode 100644 ast3/Parser/pegen/parse_string.c create mode 100644 ast3/Parser/pegen/parse_string.h create mode 100644 ast3/Parser/pegen/peg_api.c create mode 100644 ast3/Parser/pegen/pegen.c create mode 100644 ast3/Parser/pegen/pegen.h delete mode 100644 ast3/Python/ast.c delete mode 100644 ast3/Python/graminit.c create mode 100644 ast3/Tools/peg_generator/.clang-format create mode 100644 ast3/Tools/peg_generator/.gitignore create mode 100644 ast3/Tools/peg_generator/Makefile create mode 100644 ast3/Tools/peg_generator/data/cprog.py create mode 100644 ast3/Tools/peg_generator/data/top-pypi-packages-365-days.json create mode 100644 ast3/Tools/peg_generator/data/xxl.zip create mode 100644 ast3/Tools/peg_generator/mypy.ini create mode 100644 ast3/Tools/peg_generator/peg_extension/__init__.py create mode 100644 ast3/Tools/peg_generator/peg_extension/peg_extension.c create mode 100644 ast3/Tools/peg_generator/pegen/__init__.py create mode 100755 ast3/Tools/peg_generator/pegen/__main__.py create mode 100644 ast3/Tools/peg_generator/pegen/ast_dump.py create mode 100644 ast3/Tools/peg_generator/pegen/build.py create mode 100644 ast3/Tools/peg_generator/pegen/c_generator.py create mode 100755 ast3/Tools/peg_generator/pegen/first_sets.py create mode 100644 ast3/Tools/peg_generator/pegen/grammar.py create mode 100644 ast3/Tools/peg_generator/pegen/grammar_parser.py create mode 100644 ast3/Tools/peg_generator/pegen/grammar_visualizer.py create mode 100644 ast3/Tools/peg_generator/pegen/metagrammar.gram create mode 100644 ast3/Tools/peg_generator/pegen/parser.py create mode 100644 ast3/Tools/peg_generator/pegen/parser_generator.py create mode 100644 ast3/Tools/peg_generator/pegen/python_generator.py create mode 100644 ast3/Tools/peg_generator/pegen/sccutils.py create mode 100644 ast3/Tools/peg_generator/pegen/testutil.py create mode 100644 ast3/Tools/peg_generator/pegen/tokenizer.py create mode 100644 ast3/Tools/peg_generator/pyproject.toml create mode 100644 ast3/Tools/peg_generator/requirements.pip create mode 100644 ast3/Tools/peg_generator/scripts/__init__.py create mode 100644 ast3/Tools/peg_generator/scripts/ast_timings.py create mode 100644 ast3/Tools/peg_generator/scripts/benchmark.py create mode 100755 ast3/Tools/peg_generator/scripts/download_pypi_packages.py create mode 100755 ast3/Tools/peg_generator/scripts/find_max_nesting.py create mode 100755 ast3/Tools/peg_generator/scripts/grammar_grapher.py create mode 100644 ast3/Tools/peg_generator/scripts/joinstats.py create mode 100755 ast3/Tools/peg_generator/scripts/show_parse.py create mode 100755 ast3/Tools/peg_generator/scripts/test_parse_directory.py create mode 100755 ast3/Tools/peg_generator/scripts/test_pypi_packages.py diff --git a/ast3/Grammar/Grammar b/ast3/Grammar/Grammar deleted file mode 100644 index 3e4b5661..00000000 --- a/ast3/Grammar/Grammar +++ /dev/null @@ -1,161 +0,0 @@ -# Grammar for Python - -# NOTE WELL: You should also follow all the steps listed at -# https://devguide.python.org/grammar/ - -# Start symbols for the grammar: -# single_input is a single interactive statement; -# file_input is a module or sequence of commands read from an input file; -# eval_input is the input for the eval() functions. -# func_type_input is a PEP 484 Python 2 function type comment -# NB: compound_stmt in single_input is followed by extra NEWLINE! -# NB: due to the way TYPE_COMMENT is tokenized it will always be followed by a -# NEWLINE -single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE -file_input: (NEWLINE | stmt)* ENDMARKER -eval_input: testlist NEWLINE* ENDMARKER - -decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE -decorators: decorator+ -decorated: decorators (classdef | funcdef | async_funcdef) - -async_funcdef: ASYNC funcdef -funcdef: 'def' NAME parameters ['->' test] ':' [TYPE_COMMENT] suite - -parameters: '(' [typedargslist] ')' -typedargslist: (tfpdef ['=' test] (',' [TYPE_COMMENT] tfpdef ['=' test])* (TYPE_COMMENT | [',' [TYPE_COMMENT] [ - '*' [tfpdef] (',' [TYPE_COMMENT] tfpdef ['=' test])* (TYPE_COMMENT | [',' [TYPE_COMMENT] ['**' tfpdef [','] [TYPE_COMMENT]]]) - | '**' tfpdef [','] [TYPE_COMMENT]]]) - | '*' [tfpdef] (',' [TYPE_COMMENT] tfpdef ['=' test])* (TYPE_COMMENT | [',' [TYPE_COMMENT] ['**' tfpdef [','] [TYPE_COMMENT]]]) - | '**' tfpdef [','] [TYPE_COMMENT]) -tfpdef: NAME [':' test] -varargslist: (vfpdef ['=' test] (',' vfpdef ['=' test])* [',' [ - '*' [vfpdef] (',' vfpdef ['=' test])* [',' ['**' vfpdef [',']]] - | '**' vfpdef [',']]] - | '*' [vfpdef] (',' vfpdef ['=' test])* [',' ['**' vfpdef [',']]] - | '**' vfpdef [','] -) -vfpdef: NAME - -stmt: simple_stmt | compound_stmt -simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE -small_stmt: (expr_stmt | del_stmt | pass_stmt | flow_stmt | - import_stmt | global_stmt | nonlocal_stmt | assert_stmt) -expr_stmt: testlist_star_expr (annassign | augassign (yield_expr|testlist) | - ('=' (yield_expr|testlist_star_expr))* [TYPE_COMMENT]) -annassign: ':' test ['=' test] -testlist_star_expr: (test|star_expr) (',' (test|star_expr))* [','] -augassign: ('+=' | '-=' | '*=' | '@=' | '/=' | '%=' | '&=' | '|=' | '^=' | - '<<=' | '>>=' | '**=' | '//=') -# For normal and annotated assignments, additional restrictions enforced by the interpreter -del_stmt: 'del' exprlist -pass_stmt: 'pass' -flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt | yield_stmt -break_stmt: 'break' -continue_stmt: 'continue' -return_stmt: 'return' [testlist] -yield_stmt: yield_expr -raise_stmt: 'raise' [test ['from' test]] -import_stmt: import_name | import_from -import_name: 'import' dotted_as_names -# note below: the ('.' | '...') is necessary because '...' is tokenized as ELLIPSIS -import_from: ('from' (('.' | '...')* dotted_name | ('.' | '...')+) - 'import' ('*' | '(' import_as_names ')' | import_as_names)) -import_as_name: NAME ['as' NAME] -dotted_as_name: dotted_name ['as' NAME] -import_as_names: import_as_name (',' import_as_name)* [','] -dotted_as_names: dotted_as_name (',' dotted_as_name)* -dotted_name: NAME ('.' NAME)* -global_stmt: 'global' NAME (',' NAME)* -nonlocal_stmt: 'nonlocal' NAME (',' NAME)* -assert_stmt: 'assert' test [',' test] - -compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef | classdef | decorated | async_stmt -async_stmt: ASYNC (funcdef | with_stmt | for_stmt) -if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite] -while_stmt: 'while' test ':' suite ['else' ':' suite] -for_stmt: 'for' exprlist 'in' testlist ':' [TYPE_COMMENT] suite ['else' ':' suite] -try_stmt: ('try' ':' suite - ((except_clause ':' suite)+ - ['else' ':' suite] - ['finally' ':' suite] | - 'finally' ':' suite)) -with_stmt: 'with' with_item (',' with_item)* ':' [TYPE_COMMENT] suite -with_item: test ['as' expr] -# NB compile.c makes sure that the default except clause is last -except_clause: 'except' [test ['as' NAME]] -# the TYPE_COMMENT in suites is only parsed for funcdefs, but can't go elsewhere due to ambiguity -suite: simple_stmt | NEWLINE [TYPE_COMMENT NEWLINE] INDENT stmt+ DEDENT - -test: or_test ['if' or_test 'else' test] | lambdef -test_nocond: or_test | lambdef_nocond -lambdef: 'lambda' [varargslist] ':' test -lambdef_nocond: 'lambda' [varargslist] ':' test_nocond -or_test: and_test ('or' and_test)* -and_test: not_test ('and' not_test)* -not_test: 'not' not_test | comparison -comparison: expr (comp_op expr)* -# <> isn't actually a valid comparison operator in Python. It's here for the -# sake of a __future__ import described in PEP 401 (which really works :-) -comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not' -star_expr: '*' expr -expr: xor_expr ('|' xor_expr)* -xor_expr: and_expr ('^' and_expr)* -and_expr: shift_expr ('&' shift_expr)* -shift_expr: arith_expr (('<<'|'>>') arith_expr)* -arith_expr: term (('+'|'-') term)* -term: factor (('*'|'@'|'/'|'%'|'//') factor)* -factor: ('+'|'-'|'~') factor | power -power: atom_expr ['**' factor] -atom_expr: [AWAIT] atom trailer* -atom: ('(' [yield_expr|testlist_comp] ')' | - '[' [testlist_comp] ']' | - '{' [dictorsetmaker] '}' | - NAME | NUMBER | STRING+ | '...' | 'None' | 'True' | 'False') -testlist_comp: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] ) -trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME -subscriptlist: subscript (',' subscript)* [','] -subscript: test | [test] ':' [test] [sliceop] -sliceop: ':' [test] -exprlist: (expr|star_expr) (',' (expr|star_expr))* [','] -testlist: test (',' test)* [','] -dictorsetmaker: ( ((test ':' test | '**' expr) - (comp_for | (',' (test ':' test | '**' expr))* [','])) | - ((test | star_expr) - (comp_for | (',' (test | star_expr))* [','])) ) - -classdef: 'class' NAME ['(' [arglist] ')'] ':' suite - -arglist: argument (',' argument)* [','] - -# The reason that keywords are test nodes instead of NAME is that using NAME -# results in an ambiguity. ast.c makes sure it's a NAME. -# "test '=' test" is really "keyword '=' test", but we have no such token. -# These need to be in a single rule to avoid grammar that is ambiguous -# to our LL(1) parser. Even though 'test' includes '*expr' in star_expr, -# we explicitly match '*' here, too, to give it proper precedence. -# Illegal combinations and orderings are blocked in ast.c: -# multiple (test comp_for) arguments are blocked; keyword unpackings -# that precede iterable unpackings are blocked; etc. -argument: ( test [comp_for] | - test '=' test | - '**' test | - '*' test ) - -comp_iter: comp_for | comp_if -sync_comp_for: 'for' exprlist 'in' or_test [comp_iter] -comp_for: [ASYNC] sync_comp_for -comp_if: 'if' test_nocond [comp_iter] - -# not used in grammar, but may appear in "node" passed from Parser to Compiler -encoding_decl: NAME - -yield_expr: 'yield' [yield_arg] -yield_arg: 'from' test | testlist - -func_type_input: func_type NEWLINE* ENDMARKER -func_type: '(' [typelist] ')' '->' test -# typelist is a modified typedargslist (see above) -typelist: (test (',' test)* [',' - ['*' [test] (',' test)* [',' '**' test] | '**' test]] - | '*' [test] (',' test)* [',' '**' test] | '**' test) diff --git a/ast3/Grammar/Tokens b/ast3/Grammar/Tokens new file mode 100644 index 00000000..9de2da5d --- /dev/null +++ b/ast3/Grammar/Tokens @@ -0,0 +1,67 @@ +ENDMARKER +NAME +NUMBER +STRING +NEWLINE +INDENT +DEDENT + +LPAR '(' +RPAR ')' +LSQB '[' +RSQB ']' +COLON ':' +COMMA ',' +SEMI ';' +PLUS '+' +MINUS '-' +STAR '*' +SLASH '/' +VBAR '|' +AMPER '&' +LESS '<' +GREATER '>' +EQUAL '=' +DOT '.' +PERCENT '%' +LBRACE '{' +RBRACE '}' +EQEQUAL '==' +NOTEQUAL '!=' +LESSEQUAL '<=' +GREATEREQUAL '>=' +TILDE '~' +CIRCUMFLEX '^' +LEFTSHIFT '<<' +RIGHTSHIFT '>>' +DOUBLESTAR '**' +PLUSEQUAL '+=' +MINEQUAL '-=' +STAREQUAL '*=' +SLASHEQUAL '/=' +PERCENTEQUAL '%=' +AMPEREQUAL '&=' +VBAREQUAL '|=' +CIRCUMFLEXEQUAL '^=' +LEFTSHIFTEQUAL '<<=' +RIGHTSHIFTEQUAL '>>=' +DOUBLESTAREQUAL '**=' +DOUBLESLASH '//' +DOUBLESLASHEQUAL '//=' +AT '@' +ATEQUAL '@=' +RARROW '->' +ELLIPSIS '...' +COLONEQUAL ':=' + +OP +AWAIT +ASYNC +TYPE_IGNORE +TYPE_COMMENT +ERRORTOKEN + +# These aren't used by the C tokenizer but are needed for tokenize.py +COMMENT +NL +ENCODING diff --git a/ast3/Grammar/python.gram b/ast3/Grammar/python.gram new file mode 100644 index 00000000..574e1e14 --- /dev/null +++ b/ast3/Grammar/python.gram @@ -0,0 +1,651 @@ +# Simplified grammar for Python + +@bytecode True +@trailer ''' +void * +_PyPegen_parse(Parser *p) +{ + // Initialize keywords + p->keywords = reserved_keywords; + p->n_keyword_lists = n_keyword_lists; + + // Run parser + void *result = NULL; + if (p->start_rule == Py_file_input) { + result = file_rule(p); + } else if (p->start_rule == Py_single_input) { + result = interactive_rule(p); + } else if (p->start_rule == Py_eval_input) { + result = eval_rule(p); + } 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); + } + + return result; +} + +// The end +''' +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) } + | '*' a=expression ',' '**' b=expression { + _PyPegen_seq_append_to_end(p, CHECK(_PyPegen_singleton_seq(p, a)), b) } + | '*' a=expression { _PyPegen_singleton_seq(p, a) } + | '**' a=expression { _PyPegen_singleton_seq(p, a) } + | ','.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*]: + | a=compound_stmt NEWLINE { _PyPegen_singleton_seq(p, a) } + | simple_stmt + | NEWLINE { _PyPegen_singleton_seq(p, CHECK(_Py_Pass(EXTRA))) } + | ENDMARKER { _PyPegen_interactive_exit(p) } +simple_stmt[asdl_seq*]: + | a=small_stmt !';' NEWLINE { _PyPegen_singleton_seq(p, a) } # Not needed, there for speedup + | a=';'.small_stmt+ [';'] NEWLINE { a } +# NOTE: assignment MUST precede expression, else parsing a simple assignment +# will throw a SyntaxError. +small_stmt[stmt_ty] (memo): + | assignment + | e=star_expressions { _Py_Expr(e, EXTRA) } + | &'return' return_stmt + | &('import' | 'from') import_stmt + | &'raise' raise_stmt + | 'pass' { _Py_Pass(EXTRA) } + | &'del' del_stmt + | &'yield' yield_stmt + | &'assert' assert_stmt + | 'break' { _Py_Break(EXTRA) } + | 'continue' { _Py_Continue(EXTRA) } + | &'global' global_stmt + | &'nonlocal' nonlocal_stmt +compound_stmt[stmt_ty]: + | &('def' | '@' | ASYNC) function_def + | &'if' if_stmt + | &('class' | '@') class_def + | &('with' | ASYNC) with_stmt + | &('for' | ASYNC) for_stmt + | &'try' try_stmt + | &'while' while_stmt + +# NOTE: annotated_rhs may start with 'yield'; yield_expr must start with 'yield' +assignment[stmt_ty]: + | a=NAME ':' b=expression c=['=' d=annotated_rhs { d }] { + CHECK_VERSION( + 6, + "Variable annotation syntax is", + _Py_AnnAssign(CHECK(_PyPegen_set_expr_context(p, a, Store)), b, c, 1, EXTRA) + ) } + | a=('(' b=inside_paren_ann_assign_target ')' { b } + | ann_assign_subscript_attribute_target) ':' b=expression c=['=' d=annotated_rhs { d }] { + CHECK_VERSION(6, "Variable annotations syntax is", _Py_AnnAssign(a, b, c, 0, 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 + +augassign[AugOperator*]: + | '+=' { _PyPegen_augoperator(p, Add) } + | '-=' { _PyPegen_augoperator(p, Sub) } + | '*=' { _PyPegen_augoperator(p, Mult) } + | '@=' { CHECK_VERSION(5, "The '@' operator is", _PyPegen_augoperator(p, MatMult)) } + | '/=' { _PyPegen_augoperator(p, Div) } + | '%=' { _PyPegen_augoperator(p, Mod) } + | '&=' { _PyPegen_augoperator(p, BitAnd) } + | '|=' { _PyPegen_augoperator(p, BitOr) } + | '^=' { _PyPegen_augoperator(p, BitXor) } + | '<<=' { _PyPegen_augoperator(p, LShift) } + | '>>=' { _PyPegen_augoperator(p, RShift) } + | '**=' { _PyPegen_augoperator(p, Pow) } + | '//=' { _PyPegen_augoperator(p, FloorDiv) } + +global_stmt[stmt_ty]: 'global' a=','.NAME+ { + _Py_Global(CHECK(_PyPegen_map_names_to_ids(p, a)), EXTRA) } +nonlocal_stmt[stmt_ty]: 'nonlocal' a=','.NAME+ { + _Py_Nonlocal(CHECK(_PyPegen_map_names_to_ids(p, a)), EXTRA) } + +yield_stmt[stmt_ty]: y=yield_expr { _Py_Expr(y, EXTRA) } + +assert_stmt[stmt_ty]: 'assert' a=expression b=[',' z=expression { z }] { _Py_Assert(a, b, EXTRA) } + +del_stmt[stmt_ty]: 'del' a=del_targets { _Py_Delete(a, EXTRA) } + +import_stmt[stmt_ty]: import_name | import_from +import_name[stmt_ty]: 'import' a=dotted_as_names { _Py_Import(a, EXTRA) } +# note below: the ('.' | '...') is necessary because '...' is tokenized as ELLIPSIS +import_from[stmt_ty]: + | 'from' a=('.' | '...')* b=dotted_name 'import' c=import_from_targets { + _Py_ImportFrom(b->v.Name.id, c, _PyPegen_seq_count_dots(a), EXTRA) } + | 'from' a=('.' | '...')+ 'import' b=import_from_targets { + _Py_ImportFrom(NULL, b, _PyPegen_seq_count_dots(a), EXTRA) } +import_from_targets[asdl_seq*]: + | '(' a=import_from_as_names [','] ')' { a } + | import_from_as_names + | '*' { _PyPegen_singleton_seq(p, CHECK(_PyPegen_alias_for_star(p))) } +import_from_as_names[asdl_seq*]: + | a=','.import_from_as_name+ { a } +import_from_as_name[alias_ty]: + | a=NAME b=['as' z=NAME { z }] { _Py_alias(a->v.Name.id, + (b) ? ((expr_ty) b)->v.Name.id : NULL, + p->arena) } +dotted_as_names[asdl_seq*]: + | a=','.dotted_as_name+ { a } +dotted_as_name[alias_ty]: + | a=dotted_name b=['as' z=NAME { z }] { _Py_alias(a->v.Name.id, + (b) ? ((expr_ty) b)->v.Name.id : NULL, + p->arena) } +dotted_name[expr_ty]: + | a=dotted_name '.' b=NAME { _PyPegen_join_names_with_dot(p, a, b) } + | NAME + +if_stmt[stmt_ty]: + | 'if' a=named_expression ':' b=block c=elif_stmt { _Py_If(a, b, CHECK(_PyPegen_singleton_seq(p, c)), EXTRA) } + | 'if' a=named_expression ':' b=block c=[else_block] { _Py_If(a, b, c, EXTRA) } +elif_stmt[stmt_ty]: + | 'elif' a=named_expression ':' b=block c=elif_stmt { _Py_If(a, b, CHECK(_PyPegen_singleton_seq(p, c)), EXTRA) } + | 'elif' a=named_expression ':' b=block c=[else_block] { _Py_If(a, b, c, EXTRA) } +else_block[asdl_seq*]: 'else' ':' b=block { b } + +while_stmt[stmt_ty]: + | 'while' a=named_expression ':' b=block c=[else_block] { _Py_While(a, b, c, EXTRA) } + +for_stmt[stmt_ty]: + | 'for' t=star_targets 'in' ex=star_expressions ':' tc=[TYPE_COMMENT] b=block el=[else_block] { + _Py_For(t, ex, b, el, NEW_TYPE_COMMENT(p, tc), EXTRA) } + | ASYNC 'for' t=star_targets 'in' ex=star_expressions ':' tc=[TYPE_COMMENT] b=block el=[else_block] { + CHECK_VERSION(5, "Async for loops are", _Py_AsyncFor(t, ex, b, el, NEW_TYPE_COMMENT(p, tc), EXTRA)) } + +with_stmt[stmt_ty]: + | 'with' '(' a=','.with_item+ ','? ')' ':' b=block { + _Py_With(a, b, NULL, EXTRA) } + | 'with' a=','.with_item+ ':' tc=[TYPE_COMMENT] b=block { + _Py_With(a, b, NEW_TYPE_COMMENT(p, tc), EXTRA) } + | ASYNC 'with' '(' a=','.with_item+ ','? ')' ':' b=block { + CHECK_VERSION(5, "Async with statements are", _Py_AsyncWith(a, b, NULL, EXTRA)) } + | ASYNC 'with' a=','.with_item+ ':' tc=[TYPE_COMMENT] b=block { + CHECK_VERSION(5, "Async with statements are", _Py_AsyncWith(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) } + +try_stmt[stmt_ty]: + | 'try' ':' b=block f=finally_block { _Py_Try(b, NULL, NULL, f, EXTRA) } + | 'try' ':' b=block ex=except_block+ el=[else_block] f=[finally_block] { _Py_Try(b, ex, el, f, EXTRA) } +except_block[excepthandler_ty]: + | 'except' e=expression t=['as' z=target { z }] ':' b=block { + _Py_ExceptHandler(e, (t) ? ((expr_ty) t)->v.Name.id : NULL, b, EXTRA) } + | 'except' ':' b=block { _Py_ExceptHandler(NULL, NULL, b, EXTRA) } +finally_block[asdl_seq*]: 'finally' ':' a=block { a } + +return_stmt[stmt_ty]: + | 'return' a=[star_expressions] { _Py_Return(a, EXTRA) } + +raise_stmt[stmt_ty]: + | 'raise' a=expression b=['from' z=expression { z }] { _Py_Raise(a, b, EXTRA) } + | 'raise' { _Py_Raise(NULL, NULL, EXTRA) } + +function_def[stmt_ty]: + | d=decorators f=function_def_raw { _PyPegen_function_def_decorators(p, d, f) } + | function_def_raw + +function_def_raw[stmt_ty]: + | 'def' n=NAME '(' params=[params] ')' a=['->' z=expression { z }] ':' tc=[func_type_comment] b=block { + _Py_FunctionDef(n->v.Name.id, + (params) ? params : CHECK(_PyPegen_empty_arguments(p)), + b, NULL, a, NEW_TYPE_COMMENT(p, tc), EXTRA) } + | ASYNC 'def' n=NAME '(' params=[params] ')' a=['->' z=expression { z }] ':' tc=[func_type_comment] b=block { + CHECK_VERSION( + 5, + "Async functions are", + _Py_AsyncFunctionDef(n->v.Name.id, + (params) ? params : CHECK(_PyPegen_empty_arguments(p)), + b, NULL, a, NEW_TYPE_COMMENT(p, tc), EXTRA) + ) } +func_type_comment[Token*]: + | 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_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=param_with_default* c=[star_etc] { + _PyPegen_make_arguments(p, NULL, a, NULL, b, c) } + | a=param_no_default+ b=param_with_default* c=[star_etc] { + _PyPegen_make_arguments(p, NULL, NULL, a, b, c) } + | 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) } + +# 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=param_no_default b=param_maybe_default* c=[kwds] { + _PyPegen_star_etc(p, a, b, c) } + | '*' ',' b=param_maybe_default+ c=[kwds] { + _PyPegen_star_etc(p, NULL, b, c) } + | a=kwds { _PyPegen_star_etc(p, NULL, NULL, a) } + | invalid_star_etc + +kwds[arg_ty]: '**' 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 } + +class_def[stmt_ty]: + | a=decorators b=class_def_raw { _PyPegen_class_def_decorators(p, a, b) } + | class_def_raw +class_def_raw[stmt_ty]: + | 'class' a=NAME b=['(' z=[arguments] ')' { z }] ':' c=block { + _Py_ClassDef(a->v.Name.id, + (b) ? ((expr_ty) b)->v.Call.args : NULL, + (b) ? ((expr_ty) b)->v.Call.keywords : NULL, + c, NULL, EXTRA) } + +block[asdl_seq*] (memo): + | NEWLINE INDENT a=statements DEDENT { a } + | simple_stmt + | invalid_block + +expressions_list[asdl_seq*]: a=','.star_expression+ [','] { a } +star_expressions[expr_ty]: + | a=star_expression b=(',' c=star_expression { c })+ [','] { + _Py_Tuple(CHECK(_PyPegen_seq_insert_in_front(p, a, b)), Load, EXTRA) } + | a=star_expression ',' { _Py_Tuple(CHECK(_PyPegen_singleton_seq(p, a)), Load, EXTRA) } + | star_expression +star_expression[expr_ty] (memo): + | '*' a=bitwise_or { _Py_Starred(a, Load, EXTRA) } + | expression + +star_named_expressions[asdl_seq*]: a=','.star_named_expression+ [','] { a } +star_named_expression[expr_ty]: + | '*' a=bitwise_or { _Py_Starred(a, Load, EXTRA) } + | named_expression +named_expression[expr_ty]: + | a=NAME ':=' b=expression { _Py_NamedExpr(CHECK(_PyPegen_set_expr_context(p, a, Store)), b, EXTRA) } + | expression !':=' + | invalid_named_expression + +annotated_rhs[expr_ty]: yield_expr | star_expressions + +expressions[expr_ty]: + | a=expression b=(',' c=expression { c })+ [','] { + _Py_Tuple(CHECK(_PyPegen_seq_insert_in_front(p, a, b)), Load, EXTRA) } + | a=expression ',' { _Py_Tuple(CHECK(_PyPegen_singleton_seq(p, a)), Load, EXTRA) } + | expression +expression[expr_ty] (memo): + | a=disjunction 'if' b=disjunction 'else' c=expression { _Py_IfExp(b, a, c, EXTRA) } + | disjunction + | lambdef + +lambdef[expr_ty]: + | 'lambda' a=[lambda_parameters] ':' b=expression { _Py_Lambda((a) ? a : CHECK(_PyPegen_empty_arguments(p)), b, EXTRA) } + +# lambda_parameters etc. duplicates parameters but without annotations +# or type comments, and if there's no comma after a parameter, we expect +# a colon, not a close parenthesis. (For more, see parameters above.) +# +lambda_parameters[arguments_ty]: + | a=lambda_slash_no_default b=lambda_param_no_default* c=lambda_param_with_default* d=[lambda_star_etc] { + _PyPegen_make_arguments(p, a, NULL, b, c, d) } + | a=lambda_slash_with_default b=lambda_param_with_default* c=[lambda_star_etc] { + _PyPegen_make_arguments(p, NULL, a, NULL, b, c) } + | a=lambda_param_no_default+ b=lambda_param_with_default* c=[lambda_star_etc] { + _PyPegen_make_arguments(p, NULL, NULL, a, b, c) } + | a=lambda_param_with_default+ b=[lambda_star_etc] { _PyPegen_make_arguments(p, NULL, NULL, NULL, a, b)} + | a=lambda_star_etc { _PyPegen_make_arguments(p, NULL, NULL, NULL, NULL, a) } + +lambda_slash_no_default[asdl_seq*]: + | a=lambda_param_no_default+ '/' ',' { a } + | a=lambda_param_no_default+ '/' &':' { a } +lambda_slash_with_default[SlashWithDefault*]: + | a=lambda_param_no_default* b=lambda_param_with_default+ '/' ',' { _PyPegen_slash_with_default(p, a, b) } + | a=lambda_param_no_default* b=lambda_param_with_default+ '/' &':' { _PyPegen_slash_with_default(p, a, b) } + +lambda_star_etc[StarEtc*]: + | '*' a=lambda_param_no_default b=lambda_param_maybe_default* c=[lambda_kwds] { + _PyPegen_star_etc(p, a, b, c) } + | '*' ',' b=lambda_param_maybe_default+ c=[lambda_kwds] { + _PyPegen_star_etc(p, NULL, b, c) } + | a=lambda_kwds { _PyPegen_star_etc(p, NULL, NULL, a) } + | invalid_lambda_star_etc + +lambda_kwds[arg_ty]: '**' a=lambda_param_no_default { a } + +lambda_param_no_default[arg_ty]: + | a=lambda_param ',' { a } + | a=lambda_param &':' { a } +lambda_param_with_default[NameDefaultPair*]: + | a=lambda_param c=default ',' { _PyPegen_name_default_pair(p, a, c, NULL) } + | a=lambda_param c=default &':' { _PyPegen_name_default_pair(p, a, c, NULL) } +lambda_param_maybe_default[NameDefaultPair*]: + | a=lambda_param c=default? ',' { _PyPegen_name_default_pair(p, a, c, NULL) } + | a=lambda_param c=default? &':' { _PyPegen_name_default_pair(p, a, c, NULL) } +lambda_param[arg_ty]: a=NAME { _Py_arg(a->v.Name.id, NULL, NULL, EXTRA) } + +disjunction[expr_ty] (memo): + | a=conjunction b=('or' c=conjunction { c })+ { _Py_BoolOp( + Or, + CHECK(_PyPegen_seq_insert_in_front(p, a, b)), + EXTRA) } + | conjunction +conjunction[expr_ty] (memo): + | a=inversion b=('and' c=inversion { c })+ { _Py_BoolOp( + And, + CHECK(_PyPegen_seq_insert_in_front(p, a, b)), + EXTRA) } + | inversion +inversion[expr_ty] (memo): + | 'not' a=inversion { _Py_UnaryOp(Not, a, EXTRA) } + | comparison +comparison[expr_ty]: + | a=bitwise_or b=compare_op_bitwise_or_pair+ { + _Py_Compare(a, CHECK(_PyPegen_get_cmpops(p, b)), CHECK(_PyPegen_get_exprs(p, b)), EXTRA) } + | bitwise_or +compare_op_bitwise_or_pair[CmpopExprPair*]: + | eq_bitwise_or + | noteq_bitwise_or + | lte_bitwise_or + | lt_bitwise_or + | gte_bitwise_or + | gt_bitwise_or + | notin_bitwise_or + | in_bitwise_or + | isnot_bitwise_or + | is_bitwise_or +eq_bitwise_or[CmpopExprPair*]: '==' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, Eq, a) } +noteq_bitwise_or[CmpopExprPair*]: + | (tok='!=' {_PyPegen_check_barry_as_flufl(p) ? NULL : tok}) a=bitwise_or {_PyPegen_cmpop_expr_pair(p, NotEq, a) } +lte_bitwise_or[CmpopExprPair*]: '<=' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, LtE, a) } +lt_bitwise_or[CmpopExprPair*]: '<' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, Lt, a) } +gte_bitwise_or[CmpopExprPair*]: '>=' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, GtE, a) } +gt_bitwise_or[CmpopExprPair*]: '>' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, Gt, a) } +notin_bitwise_or[CmpopExprPair*]: 'not' 'in' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, NotIn, a) } +in_bitwise_or[CmpopExprPair*]: 'in' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, In, a) } +isnot_bitwise_or[CmpopExprPair*]: 'is' 'not' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, IsNot, a) } +is_bitwise_or[CmpopExprPair*]: 'is' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, Is, a) } + +bitwise_or[expr_ty]: + | a=bitwise_or '|' b=bitwise_xor { _Py_BinOp(a, BitOr, b, EXTRA) } + | bitwise_xor +bitwise_xor[expr_ty]: + | a=bitwise_xor '^' b=bitwise_and { _Py_BinOp(a, BitXor, b, EXTRA) } + | bitwise_and +bitwise_and[expr_ty]: + | a=bitwise_and '&' b=shift_expr { _Py_BinOp(a, BitAnd, b, EXTRA) } + | shift_expr +shift_expr[expr_ty]: + | a=shift_expr '<<' b=sum { _Py_BinOp(a, LShift, b, EXTRA) } + | a=shift_expr '>>' b=sum { _Py_BinOp(a, RShift, b, EXTRA) } + | sum + +sum[expr_ty]: + | a=sum '+' b=term { _Py_BinOp(a, Add, b, EXTRA) } + | a=sum '-' b=term { _Py_BinOp(a, Sub, b, EXTRA) } + | term +term[expr_ty]: + | a=term '*' b=factor { _Py_BinOp(a, Mult, b, EXTRA) } + | a=term '/' b=factor { _Py_BinOp(a, Div, b, EXTRA) } + | a=term '//' b=factor { _Py_BinOp(a, FloorDiv, b, EXTRA) } + | a=term '%' b=factor { _Py_BinOp(a, Mod, b, EXTRA) } + | a=term '@' b=factor { CHECK_VERSION(5, "The '@' operator is", _Py_BinOp(a, MatMult, b, EXTRA)) } + | factor +factor[expr_ty] (memo): + | '+' a=factor { _Py_UnaryOp(UAdd, a, EXTRA) } + | '-' a=factor { _Py_UnaryOp(USub, a, EXTRA) } + | '~' a=factor { _Py_UnaryOp(Invert, a, EXTRA) } + | power +power[expr_ty]: + | a=await_primary '**' b=factor { _Py_BinOp(a, Pow, b, EXTRA) } + | await_primary +await_primary[expr_ty] (memo): + | AWAIT a=primary { CHECK_VERSION(5, "Await expressions are", _Py_Await(a, EXTRA)) } + | primary +primary[expr_ty]: + | a=primary '.' b=NAME { _Py_Attribute(a, b->v.Name.id, Load, EXTRA) } + | a=primary b=genexp { _Py_Call(a, CHECK(_PyPegen_singleton_seq(p, b)), NULL, EXTRA) } + | a=primary '(' b=[arguments] ')' { + _Py_Call(a, + (b) ? ((expr_ty) b)->v.Call.args : NULL, + (b) ? ((expr_ty) b)->v.Call.keywords : NULL, + EXTRA) } + | a=primary '[' b=slices ']' { _Py_Subscript(a, b, Load, EXTRA) } + | atom + +slices[expr_ty]: + | a=slice !',' { a } + | a=','.slice+ [','] { _Py_Tuple(a, Load, EXTRA) } +slice[expr_ty]: + | a=[expression] ':' b=[expression] c=[':' d=[expression] { d }] { _Py_Slice(a, b, c, EXTRA) } + | a=expression { a } +atom[expr_ty]: + | NAME + | 'True' { _Py_Constant(Py_True, NULL, EXTRA) } + | 'False' { _Py_Constant(Py_False, NULL, EXTRA) } + | 'None' { _Py_Constant(Py_None, NULL, EXTRA) } + | '__new_parser__' { RAISE_SYNTAX_ERROR("You found it!") } + | &STRING strings + | NUMBER + | &'(' (tuple | group | genexp) + | &'[' (list | listcomp) + | &'{' (dict | set | dictcomp | setcomp) + | '...' { _Py_Constant(Py_Ellipsis, NULL, EXTRA) } + +strings[expr_ty] (memo): a=STRING+ { _PyPegen_concatenate_strings(p, a) } +list[expr_ty]: + | '[' a=[star_named_expressions] ']' { _Py_List(a, Load, EXTRA) } +listcomp[expr_ty]: + | '[' a=named_expression b=for_if_clauses ']' { _Py_ListComp(a, b, EXTRA) } + | invalid_comprehension +tuple[expr_ty]: + | '(' a=[y=star_named_expression ',' z=[star_named_expressions] { _PyPegen_seq_insert_in_front(p, y, z) } ] ')' { + _Py_Tuple(a, Load, EXTRA) } +group[expr_ty]: '(' a=(yield_expr | named_expression) ')' { a } +genexp[expr_ty]: + | '(' a=expression b=for_if_clauses ')' { _Py_GeneratorExp(a, b, EXTRA) } + | invalid_comprehension +set[expr_ty]: '{' a=expressions_list '}' { _Py_Set(a, EXTRA) } +setcomp[expr_ty]: + | '{' a=expression b=for_if_clauses '}' { _Py_SetComp(a, b, EXTRA) } + | invalid_comprehension +dict[expr_ty]: + | '{' a=[kvpairs] '}' { _Py_Dict(CHECK(_PyPegen_get_keys(p, a)), + CHECK(_PyPegen_get_values(p, a)), EXTRA) } +dictcomp[expr_ty]: + | '{' a=kvpair b=for_if_clauses '}' { _Py_DictComp(a->key, a->value, b, EXTRA) } +kvpairs[asdl_seq*]: a=','.kvpair+ [','] { a } +kvpair[KeyValuePair*]: + | '**' a=bitwise_or { _PyPegen_key_value_pair(p, NULL, a) } + | a=expression ':' b=expression { _PyPegen_key_value_pair(p, a, b) } +for_if_clauses[asdl_seq*]: + | for_if_clause+ +for_if_clause[comprehension_ty]: + | ASYNC 'for' a=star_targets 'in' b=disjunction c=('if' z=disjunction { z })* { + CHECK_VERSION(6, "Async comprehensions are", _Py_comprehension(a, b, c, 1, p->arena)) } + | 'for' a=star_targets 'in' b=disjunction c=('if' z=disjunction { z })* { + _Py_comprehension(a, b, c, 0, p->arena) } + +yield_expr[expr_ty]: + | 'yield' 'from' a=expression { _Py_YieldFrom(a, EXTRA) } + | 'yield' a=[star_expressions] { _Py_Yield(a, EXTRA) } + +arguments[expr_ty] (memo): + | a=args [','] &')' { a } + | incorrect_arguments +args[expr_ty]: + | a=starred_expression b=[',' c=args { c }] { + _Py_Call(_PyPegen_dummy_name(p), + (b) ? CHECK(_PyPegen_seq_insert_in_front(p, a, ((expr_ty) b)->v.Call.args)) + : CHECK(_PyPegen_singleton_seq(p, a)), + (b) ? ((expr_ty) b)->v.Call.keywords : NULL, + EXTRA) } + | a=kwargs { _Py_Call(_PyPegen_dummy_name(p), + CHECK_NULL_ALLOWED(_PyPegen_seq_extract_starred_exprs(p, a)), + CHECK_NULL_ALLOWED(_PyPegen_seq_delete_starred_exprs(p, a)), + EXTRA) } + | a=named_expression b=[',' c=args { c }] { + _Py_Call(_PyPegen_dummy_name(p), + (b) ? CHECK(_PyPegen_seq_insert_in_front(p, a, ((expr_ty) b)->v.Call.args)) + : CHECK(_PyPegen_singleton_seq(p, a)), + (b) ? ((expr_ty) b)->v.Call.keywords : NULL, + EXTRA) } +kwargs[asdl_seq*]: + | a=','.kwarg_or_starred+ ',' b=','.kwarg_or_double_starred+ { _PyPegen_join_sequences(p, a, b) } + | ','.kwarg_or_starred+ + | ','.kwarg_or_double_starred+ +starred_expression[expr_ty]: + | '*' a=expression { _Py_Starred(a, Load, EXTRA) } +kwarg_or_starred[KeywordOrStarred*]: + | a=NAME '=' b=expression { + _PyPegen_keyword_or_starred(p, CHECK(_Py_keyword(a->v.Name.id, b, EXTRA)), 1) } + | a=starred_expression { _PyPegen_keyword_or_starred(p, a, 0) } + | invalid_kwarg +kwarg_or_double_starred[KeywordOrStarred*]: + | a=NAME '=' b=expression { + _PyPegen_keyword_or_starred(p, CHECK(_Py_keyword(a->v.Name.id, b, EXTRA)), 1) } + | '**' a=expression { _PyPegen_keyword_or_starred(p, CHECK(_Py_keyword(NULL, a, EXTRA)), 1) } + | invalid_kwarg + +# NOTE: star_targets may contain *bitwise_or, targets may not. +star_targets[expr_ty]: + | a=star_target !',' { a } + | a=star_target b=(',' c=star_target { c })* [','] { + _Py_Tuple(CHECK(_PyPegen_seq_insert_in_front(p, a, b)), Store, EXTRA) } +star_targets_seq[asdl_seq*]: a=','.star_target+ [','] { a } +star_target[expr_ty] (memo): + | '*' a=(!'*' star_target) { + _Py_Starred(CHECK(_PyPegen_set_expr_context(p, a, Store)), Store, EXTRA) } + | a=t_primary '.' b=NAME !t_lookahead { _Py_Attribute(a, b->v.Name.id, Store, EXTRA) } + | a=t_primary '[' b=slices ']' !t_lookahead { _Py_Subscript(a, b, Store, EXTRA) } + | star_atom +star_atom[expr_ty]: + | a=NAME { _PyPegen_set_expr_context(p, a, Store) } + | '(' a=star_target ')' { _PyPegen_set_expr_context(p, a, Store) } + | '(' a=[star_targets_seq] ')' { _Py_Tuple(a, Store, EXTRA) } + | '[' a=[star_targets_seq] ']' { _Py_List(a, Store, EXTRA) } + +inside_paren_ann_assign_target[expr_ty]: + | ann_assign_subscript_attribute_target + | a=NAME { _PyPegen_set_expr_context(p, a, Store) } + | '(' a=inside_paren_ann_assign_target ')' { a } + +ann_assign_subscript_attribute_target[expr_ty]: + | a=t_primary '.' b=NAME !t_lookahead { _Py_Attribute(a, b->v.Name.id, Store, EXTRA) } + | a=t_primary '[' b=slices ']' !t_lookahead { _Py_Subscript(a, b, Store, EXTRA) } + +del_targets[asdl_seq*]: a=','.del_target+ [','] { a } +del_target[expr_ty] (memo): + | a=t_primary '.' b=NAME !t_lookahead { _Py_Attribute(a, b->v.Name.id, Del, EXTRA) } + | a=t_primary '[' b=slices ']' !t_lookahead { _Py_Subscript(a, b, Del, EXTRA) } + | del_t_atom +del_t_atom[expr_ty]: + | a=NAME { _PyPegen_set_expr_context(p, a, Del) } + | '(' a=del_target ')' { _PyPegen_set_expr_context(p, a, Del) } + | '(' a=[del_targets] ')' { _Py_Tuple(a, Del, EXTRA) } + | '[' a=[del_targets] ']' { _Py_List(a, Del, EXTRA) } + +targets[asdl_seq*]: a=','.target+ [','] { a } +target[expr_ty] (memo): + | a=t_primary '.' b=NAME !t_lookahead { _Py_Attribute(a, b->v.Name.id, Store, EXTRA) } + | a=t_primary '[' b=slices ']' !t_lookahead { _Py_Subscript(a, b, Store, EXTRA) } + | t_atom +t_primary[expr_ty]: + | a=t_primary '.' b=NAME &t_lookahead { _Py_Attribute(a, b->v.Name.id, Load, EXTRA) } + | a=t_primary '[' b=slices ']' &t_lookahead { _Py_Subscript(a, b, Load, EXTRA) } + | a=t_primary b=genexp &t_lookahead { _Py_Call(a, CHECK(_PyPegen_singleton_seq(p, b)), NULL, EXTRA) } + | a=t_primary '(' b=[arguments] ')' &t_lookahead { + _Py_Call(a, + (b) ? ((expr_ty) b)->v.Call.args : NULL, + (b) ? ((expr_ty) b)->v.Call.keywords : NULL, + EXTRA) } + | a=atom &t_lookahead { a } +t_lookahead: '(' | '[' | '.' +t_atom[expr_ty]: + | a=NAME { _PyPegen_set_expr_context(p, a, Store) } + | '(' a=target ')' { _PyPegen_set_expr_context(p, a, Store) } + | '(' b=[targets] ')' { _Py_Tuple(b, Store, EXTRA) } + | '[' b=[targets] ']' { _Py_List(b, Store, EXTRA) } + + +# From here on, there are rules for invalid syntax with specialised error messages +incorrect_arguments: + | args ',' '*' { RAISE_SYNTAX_ERROR("iterable argument unpacking follows keyword argument unpacking") } + | expression for_if_clauses ',' [args | expression for_if_clauses] { + RAISE_SYNTAX_ERROR("Generator expression must be parenthesized") } + | a=args ',' args { _PyPegen_arguments_parsing_error(p, a) } +invalid_kwarg: + | expression '=' { RAISE_SYNTAX_ERROR("expression cannot contain assignment, perhaps you meant \"==\"?") } +invalid_named_expression: + | a=expression ':=' expression { + RAISE_SYNTAX_ERROR("cannot use assignment expressions with %s", _PyPegen_get_expr_name(a)) } +invalid_assignment: + | list ':' { RAISE_SYNTAX_ERROR("only single target (not list) can be annotated") } + | tuple ':' { RAISE_SYNTAX_ERROR("only single target (not tuple) can be annotated") } + | expression ':' expression ['=' annotated_rhs] { + RAISE_SYNTAX_ERROR("illegal target for annotation") } + | a=expression ('=' | augassign) (yield_expr | star_expressions) { + RAISE_SYNTAX_ERROR_NO_COL_OFFSET("cannot assign to %s", _PyPegen_get_expr_name(a)) } +invalid_block: + | NEWLINE !INDENT { RAISE_INDENTATION_ERROR("expected an indented block") } +invalid_comprehension: + | ('[' | '(' | '{') '*' expression for_if_clauses { + RAISE_SYNTAX_ERROR("iterable unpacking cannot be used in comprehension") } +invalid_parameters: + | param_no_default* (slash_with_default | param_with_default+) param_no_default { + RAISE_SYNTAX_ERROR("non-default argument follows default argument") } +invalid_star_etc: + | '*' (')' | ',' (')' | '**')) { RAISE_SYNTAX_ERROR("named arguments must follow bare *") } +invalid_lambda_star_etc: + | '*' (':' | ',' (':' | '**')) { RAISE_SYNTAX_ERROR("named arguments must follow bare *") } +invalid_double_type_comments: + | TYPE_COMMENT NEWLINE TYPE_COMMENT NEWLINE INDENT { + RAISE_SYNTAX_ERROR("Cannot have two type comments on def") } diff --git a/ast3/Include/Python-ast.h b/ast3/Include/Python-ast.h index b450d3ab..e7afa1e6 100644 --- a/ast3/Include/Python-ast.h +++ b/ast3/Include/Python-ast.h @@ -1,6 +1,15 @@ /* File automatically generated by Parser/asdl_c.py. */ -#include "../Include/asdl.h" +#ifndef Py_PYTHON_AST_H +#define Py_PYTHON_AST_H +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef Py_LIMITED_API +#include "asdl.h" + +#undef Yield /* undefine macro conflicting with */ typedef struct _mod *mod_ty; @@ -8,10 +17,7 @@ typedef struct _stmt *stmt_ty; typedef struct _expr *expr_ty; -typedef enum _expr_context { Load=1, Store=2, Del=3, AugLoad=4, AugStore=5, - Param=6 } expr_context_ty; - -typedef struct _slice *slice_ty; +typedef enum _expr_context { Load=1, Store=2, Del=3 } expr_context_ty; typedef enum _boolop { And=1, Or=2 } boolop_ty; @@ -42,7 +48,7 @@ typedef struct _type_ignore *type_ignore_ty; enum _mod_kind {Module_kind=1, Interactive_kind=2, Expression_kind=3, - FunctionType_kind=4, Suite_kind=5}; + FunctionType_kind=4}; struct _mod { enum _mod_kind kind; union { @@ -64,10 +70,6 @@ struct _mod { expr_ty returns; } FunctionType; - struct { - asdl_seq *body; - } Suite; - } v; }; @@ -217,17 +219,18 @@ struct _stmt { } v; int lineno; int col_offset; + int end_lineno; + int end_col_offset; }; -enum _expr_kind {BoolOp_kind=1, BinOp_kind=2, UnaryOp_kind=3, Lambda_kind=4, - IfExp_kind=5, Dict_kind=6, Set_kind=7, ListComp_kind=8, - SetComp_kind=9, DictComp_kind=10, GeneratorExp_kind=11, - Await_kind=12, Yield_kind=13, YieldFrom_kind=14, - Compare_kind=15, Call_kind=16, Num_kind=17, Str_kind=18, - FormattedValue_kind=19, JoinedStr_kind=20, Bytes_kind=21, - NameConstant_kind=22, Ellipsis_kind=23, Constant_kind=24, - Attribute_kind=25, Subscript_kind=26, Starred_kind=27, - Name_kind=28, List_kind=29, Tuple_kind=30}; +enum _expr_kind {BoolOp_kind=1, NamedExpr_kind=2, BinOp_kind=3, UnaryOp_kind=4, + Lambda_kind=5, IfExp_kind=6, Dict_kind=7, Set_kind=8, + ListComp_kind=9, SetComp_kind=10, DictComp_kind=11, + GeneratorExp_kind=12, Await_kind=13, Yield_kind=14, + YieldFrom_kind=15, Compare_kind=16, Call_kind=17, + FormattedValue_kind=18, JoinedStr_kind=19, Constant_kind=20, + Attribute_kind=21, Subscript_kind=22, Starred_kind=23, + Name_kind=24, List_kind=25, Tuple_kind=26, Slice_kind=27}; struct _expr { enum _expr_kind kind; union { @@ -236,6 +239,11 @@ struct _expr { asdl_seq *values; } BoolOp; + struct { + expr_ty target; + expr_ty value; + } NamedExpr; + struct { expr_ty left; operator_ty op; @@ -312,15 +320,6 @@ struct _expr { asdl_seq *keywords; } Call; - struct { - object n; - } Num; - - struct { - string s; - string kind; - } Str; - struct { expr_ty value; int conversion; @@ -331,17 +330,9 @@ struct _expr { asdl_seq *values; } JoinedStr; - struct { - bytes s; - string kind; - } Bytes; - - struct { - singleton value; - } NameConstant; - struct { constant value; + string kind; } Constant; struct { @@ -352,7 +343,7 @@ struct _expr { struct { expr_ty value; - slice_ty slice; + expr_ty slice; expr_context_ty ctx; } Subscript; @@ -376,30 +367,17 @@ struct _expr { expr_context_ty ctx; } Tuple; - } v; - int lineno; - int col_offset; -}; - -enum _slice_kind {Slice_kind=1, ExtSlice_kind=2, Index_kind=3}; -struct _slice { - enum _slice_kind kind; - union { struct { expr_ty lower; expr_ty upper; expr_ty step; } Slice; - struct { - asdl_seq *dims; - } ExtSlice; - - struct { - expr_ty value; - } Index; - } v; + int lineno; + int col_offset; + int end_lineno; + int end_col_offset; }; struct _comprehension { @@ -422,9 +400,12 @@ struct _excepthandler { } v; int lineno; int col_offset; + int end_lineno; + int end_col_offset; }; struct _arguments { + asdl_seq *posonlyargs; asdl_seq *args; arg_ty vararg; asdl_seq *kwonlyargs; @@ -439,11 +420,17 @@ struct _arg { string type_comment; int lineno; int col_offset; + int end_lineno; + int end_col_offset; }; struct _keyword { identifier arg; expr_ty value; + int lineno; + int col_offset; + int end_lineno; + int end_col_offset; }; struct _alias { @@ -469,209 +456,242 @@ struct _type_ignore { }; -#define Module(a0, a1, a2) _Ta3_Module(a0, a1, a2) -mod_ty _Ta3_Module(asdl_seq * body, asdl_seq * type_ignores, PyArena *arena); -#define Interactive(a0, a1) _Ta3_Interactive(a0, a1) -mod_ty _Ta3_Interactive(asdl_seq * body, PyArena *arena); -#define Expression(a0, a1) _Ta3_Expression(a0, a1) -mod_ty _Ta3_Expression(expr_ty body, PyArena *arena); -#define FunctionType(a0, a1, a2) _Ta3_FunctionType(a0, a1, a2) -mod_ty _Ta3_FunctionType(asdl_seq * argtypes, expr_ty returns, PyArena *arena); -#define Suite(a0, a1) _Ta3_Suite(a0, a1) -mod_ty _Ta3_Suite(asdl_seq * body, PyArena *arena); -#define FunctionDef(a0, a1, a2, a3, a4, a5, a6, a7, a8) _Ta3_FunctionDef(a0, a1, a2, a3, a4, a5, a6, a7, a8) -stmt_ty _Ta3_FunctionDef(identifier name, arguments_ty args, asdl_seq * body, - asdl_seq * decorator_list, expr_ty returns, string - type_comment, int lineno, int col_offset, PyArena - *arena); -#define AsyncFunctionDef(a0, a1, a2, a3, a4, a5, a6, a7, a8) _Ta3_AsyncFunctionDef(a0, a1, a2, a3, a4, a5, a6, a7, a8) -stmt_ty _Ta3_AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * - body, asdl_seq * decorator_list, expr_ty returns, - string type_comment, int lineno, int col_offset, - PyArena *arena); -#define ClassDef(a0, a1, a2, a3, a4, a5, a6, a7) _Ta3_ClassDef(a0, a1, a2, a3, a4, a5, a6, a7) -stmt_ty _Ta3_ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, - asdl_seq * body, asdl_seq * decorator_list, int lineno, - int col_offset, PyArena *arena); -#define Return(a0, a1, a2, a3) _Ta3_Return(a0, a1, a2, a3) -stmt_ty _Ta3_Return(expr_ty value, int lineno, int col_offset, PyArena *arena); -#define Delete(a0, a1, a2, a3) _Ta3_Delete(a0, a1, a2, a3) -stmt_ty _Ta3_Delete(asdl_seq * targets, int lineno, int col_offset, PyArena - *arena); -#define Assign(a0, a1, a2, a3, a4, a5) _Ta3_Assign(a0, a1, a2, a3, a4, a5) -stmt_ty _Ta3_Assign(asdl_seq * targets, expr_ty value, string type_comment, int - lineno, int col_offset, PyArena *arena); -#define AugAssign(a0, a1, a2, a3, a4, a5) _Ta3_AugAssign(a0, a1, a2, a3, a4, a5) -stmt_ty _Ta3_AugAssign(expr_ty target, operator_ty op, expr_ty value, int - lineno, int col_offset, PyArena *arena); -#define AnnAssign(a0, a1, a2, a3, a4, a5, a6) _Ta3_AnnAssign(a0, a1, a2, a3, a4, a5, a6) -stmt_ty _Ta3_AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int - simple, int lineno, int col_offset, PyArena *arena); -#define For(a0, a1, a2, a3, a4, a5, a6, a7) _Ta3_For(a0, a1, a2, a3, a4, a5, a6, a7) -stmt_ty _Ta3_For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * - orelse, string type_comment, int lineno, int col_offset, - PyArena *arena); -#define AsyncFor(a0, a1, a2, a3, a4, a5, a6, a7) _Ta3_AsyncFor(a0, a1, a2, a3, a4, a5, a6, a7) -stmt_ty _Ta3_AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * - orelse, string type_comment, int lineno, int col_offset, - PyArena *arena); -#define While(a0, a1, a2, a3, a4, a5) _Ta3_While(a0, a1, a2, a3, a4, a5) -stmt_ty _Ta3_While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int - lineno, int col_offset, PyArena *arena); -#define If(a0, a1, a2, a3, a4, a5) _Ta3_If(a0, a1, a2, a3, a4, a5) -stmt_ty _Ta3_If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, - int col_offset, PyArena *arena); -#define With(a0, a1, a2, a3, a4, a5) _Ta3_With(a0, a1, a2, a3, a4, a5) -stmt_ty _Ta3_With(asdl_seq * items, asdl_seq * body, string type_comment, int - lineno, int col_offset, PyArena *arena); -#define AsyncWith(a0, a1, a2, a3, a4, a5) _Ta3_AsyncWith(a0, a1, a2, a3, a4, a5) -stmt_ty _Ta3_AsyncWith(asdl_seq * items, asdl_seq * body, string type_comment, - int lineno, int col_offset, PyArena *arena); -#define Raise(a0, a1, a2, a3, a4) _Ta3_Raise(a0, a1, a2, a3, a4) -stmt_ty _Ta3_Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, +// Note: these macros affect function definitions, not only call sites. +#define Module(a0, a1, a2) _Py_Module(a0, a1, a2) +mod_ty _Py_Module(asdl_seq * body, asdl_seq * type_ignores, PyArena *arena); +#define Interactive(a0, a1) _Py_Interactive(a0, a1) +mod_ty _Py_Interactive(asdl_seq * body, PyArena *arena); +#define Expression(a0, a1) _Py_Expression(a0, a1) +mod_ty _Py_Expression(expr_ty body, PyArena *arena); +#define FunctionType(a0, a1, a2) _Py_FunctionType(a0, a1, a2) +mod_ty _Py_FunctionType(asdl_seq * argtypes, expr_ty returns, PyArena *arena); +#define FunctionDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) _Py_FunctionDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) +stmt_ty _Py_FunctionDef(identifier name, arguments_ty args, asdl_seq * body, + asdl_seq * decorator_list, expr_ty returns, string + type_comment, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena *arena); +#define AsyncFunctionDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) _Py_AsyncFunctionDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) +stmt_ty _Py_AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * + body, asdl_seq * decorator_list, expr_ty returns, + string type_comment, int lineno, int col_offset, + int end_lineno, int end_col_offset, PyArena + *arena); +#define ClassDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) _Py_ClassDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) +stmt_ty _Py_ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, + asdl_seq * body, asdl_seq * decorator_list, int lineno, + int col_offset, int end_lineno, int end_col_offset, + PyArena *arena); +#define Return(a0, a1, a2, a3, a4, a5) _Py_Return(a0, a1, a2, a3, a4, a5) +stmt_ty _Py_Return(expr_ty value, int lineno, int col_offset, int end_lineno, + int end_col_offset, PyArena *arena); +#define Delete(a0, a1, a2, a3, a4, a5) _Py_Delete(a0, a1, a2, a3, a4, a5) +stmt_ty _Py_Delete(asdl_seq * targets, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena *arena); +#define Assign(a0, a1, a2, a3, a4, a5, a6, a7) _Py_Assign(a0, a1, a2, a3, a4, a5, a6, a7) +stmt_ty _Py_Assign(asdl_seq * targets, expr_ty value, string type_comment, int + lineno, int col_offset, int end_lineno, int end_col_offset, PyArena *arena); -#define Try(a0, a1, a2, a3, a4, a5, a6) _Ta3_Try(a0, a1, a2, a3, a4, a5, a6) -stmt_ty _Ta3_Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, - asdl_seq * finalbody, int lineno, int col_offset, PyArena +#define AugAssign(a0, a1, a2, a3, a4, a5, a6, a7) _Py_AugAssign(a0, a1, a2, a3, a4, a5, a6, a7) +stmt_ty _Py_AugAssign(expr_ty target, operator_ty op, expr_ty value, int + lineno, int col_offset, int end_lineno, int + end_col_offset, PyArena *arena); +#define AnnAssign(a0, a1, a2, a3, a4, a5, a6, a7, a8) _Py_AnnAssign(a0, a1, a2, a3, a4, a5, a6, a7, a8) +stmt_ty _Py_AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int + simple, int lineno, int col_offset, int end_lineno, int + end_col_offset, PyArena *arena); +#define For(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) _Py_For(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) +stmt_ty _Py_For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * + orelse, string type_comment, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena *arena); +#define AsyncFor(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) _Py_AsyncFor(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) +stmt_ty _Py_AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * + orelse, string type_comment, int lineno, int col_offset, + int end_lineno, int end_col_offset, PyArena *arena); +#define While(a0, a1, a2, a3, a4, a5, a6, a7) _Py_While(a0, a1, a2, a3, a4, a5, a6, a7) +stmt_ty _Py_While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, + int col_offset, int end_lineno, int end_col_offset, PyArena + *arena); +#define If(a0, a1, a2, a3, a4, a5, a6, a7) _Py_If(a0, a1, a2, a3, a4, a5, a6, a7) +stmt_ty _Py_If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, + int col_offset, int end_lineno, int end_col_offset, PyArena + *arena); +#define With(a0, a1, a2, a3, a4, a5, a6, a7) _Py_With(a0, a1, a2, a3, a4, a5, a6, a7) +stmt_ty _Py_With(asdl_seq * items, asdl_seq * body, string type_comment, int + lineno, int col_offset, int end_lineno, int end_col_offset, + PyArena *arena); +#define AsyncWith(a0, a1, a2, a3, a4, a5, a6, a7) _Py_AsyncWith(a0, a1, a2, a3, a4, a5, a6, a7) +stmt_ty _Py_AsyncWith(asdl_seq * items, asdl_seq * body, string type_comment, + int lineno, int col_offset, int end_lineno, int + end_col_offset, PyArena *arena); +#define Raise(a0, a1, a2, a3, a4, a5, a6) _Py_Raise(a0, a1, a2, a3, a4, a5, a6) +stmt_ty _Py_Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena *arena); +#define Try(a0, a1, a2, a3, a4, a5, a6, a7, a8) _Py_Try(a0, a1, a2, a3, a4, a5, a6, a7, a8) +stmt_ty _Py_Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, + asdl_seq * finalbody, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena *arena); +#define Assert(a0, a1, a2, a3, a4, a5, a6) _Py_Assert(a0, a1, a2, a3, a4, a5, a6) +stmt_ty _Py_Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena *arena); +#define Import(a0, a1, a2, a3, a4, a5) _Py_Import(a0, a1, a2, a3, a4, a5) +stmt_ty _Py_Import(asdl_seq * names, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena *arena); +#define ImportFrom(a0, a1, a2, a3, a4, a5, a6, a7) _Py_ImportFrom(a0, a1, a2, a3, a4, a5, a6, a7) +stmt_ty _Py_ImportFrom(identifier module, asdl_seq * names, int level, int + lineno, int col_offset, int end_lineno, int + end_col_offset, PyArena *arena); +#define Global(a0, a1, a2, a3, a4, a5) _Py_Global(a0, a1, a2, a3, a4, a5) +stmt_ty _Py_Global(asdl_seq * names, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena *arena); +#define Nonlocal(a0, a1, a2, a3, a4, a5) _Py_Nonlocal(a0, a1, a2, a3, a4, a5) +stmt_ty _Py_Nonlocal(asdl_seq * names, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena *arena); +#define Expr(a0, a1, a2, a3, a4, a5) _Py_Expr(a0, a1, a2, a3, a4, a5) +stmt_ty _Py_Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int + end_col_offset, PyArena *arena); +#define Pass(a0, a1, a2, a3, a4) _Py_Pass(a0, a1, a2, a3, a4) +stmt_ty _Py_Pass(int lineno, int col_offset, int end_lineno, int + end_col_offset, PyArena *arena); +#define Break(a0, a1, a2, a3, a4) _Py_Break(a0, a1, a2, a3, a4) +stmt_ty _Py_Break(int lineno, int col_offset, int end_lineno, int + end_col_offset, PyArena *arena); +#define Continue(a0, a1, a2, a3, a4) _Py_Continue(a0, a1, a2, a3, a4) +stmt_ty _Py_Continue(int lineno, int col_offset, int end_lineno, int + end_col_offset, PyArena *arena); +#define BoolOp(a0, a1, a2, a3, a4, a5, a6) _Py_BoolOp(a0, a1, a2, a3, a4, a5, a6) +expr_ty _Py_BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, + int end_lineno, int end_col_offset, PyArena *arena); +#define NamedExpr(a0, a1, a2, a3, a4, a5, a6) _Py_NamedExpr(a0, a1, a2, a3, a4, a5, a6) +expr_ty _Py_NamedExpr(expr_ty target, expr_ty value, int lineno, int + col_offset, int end_lineno, int end_col_offset, PyArena + *arena); +#define BinOp(a0, a1, a2, a3, a4, a5, a6, a7) _Py_BinOp(a0, a1, a2, a3, a4, a5, a6, a7) +expr_ty _Py_BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int + col_offset, int end_lineno, int end_col_offset, PyArena + *arena); +#define UnaryOp(a0, a1, a2, a3, a4, a5, a6) _Py_UnaryOp(a0, a1, a2, a3, a4, a5, a6) +expr_ty _Py_UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, + int end_lineno, int end_col_offset, PyArena *arena); +#define Lambda(a0, a1, a2, a3, a4, a5, a6) _Py_Lambda(a0, a1, a2, a3, a4, a5, a6) +expr_ty _Py_Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, + int end_lineno, int end_col_offset, PyArena *arena); +#define IfExp(a0, a1, a2, a3, a4, a5, a6, a7) _Py_IfExp(a0, a1, a2, a3, a4, a5, a6, a7) +expr_ty _Py_IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int + col_offset, int end_lineno, int end_col_offset, PyArena + *arena); +#define Dict(a0, a1, a2, a3, a4, a5, a6) _Py_Dict(a0, a1, a2, a3, a4, a5, a6) +expr_ty _Py_Dict(asdl_seq * keys, asdl_seq * values, int lineno, int + col_offset, int end_lineno, int end_col_offset, PyArena *arena); -#define Assert(a0, a1, a2, a3, a4) _Ta3_Assert(a0, a1, a2, a3, a4) -stmt_ty _Ta3_Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, - PyArena *arena); -#define Import(a0, a1, a2, a3) _Ta3_Import(a0, a1, a2, a3) -stmt_ty _Ta3_Import(asdl_seq * names, int lineno, int col_offset, PyArena +#define Set(a0, a1, a2, a3, a4, a5) _Py_Set(a0, a1, a2, a3, a4, a5) +expr_ty _Py_Set(asdl_seq * elts, int lineno, int col_offset, int end_lineno, + int end_col_offset, PyArena *arena); +#define ListComp(a0, a1, a2, a3, a4, a5, a6) _Py_ListComp(a0, a1, a2, a3, a4, a5, a6) +expr_ty _Py_ListComp(expr_ty elt, asdl_seq * generators, int lineno, int + col_offset, int end_lineno, int end_col_offset, PyArena + *arena); +#define SetComp(a0, a1, a2, a3, a4, a5, a6) _Py_SetComp(a0, a1, a2, a3, a4, a5, a6) +expr_ty _Py_SetComp(expr_ty elt, asdl_seq * generators, int lineno, int + col_offset, int end_lineno, int end_col_offset, PyArena *arena); -#define ImportFrom(a0, a1, a2, a3, a4, a5) _Ta3_ImportFrom(a0, a1, a2, a3, a4, a5) -stmt_ty _Ta3_ImportFrom(identifier module, asdl_seq * names, int level, int - lineno, int col_offset, PyArena *arena); -#define Global(a0, a1, a2, a3) _Ta3_Global(a0, a1, a2, a3) -stmt_ty _Ta3_Global(asdl_seq * names, int lineno, int col_offset, PyArena +#define DictComp(a0, a1, a2, a3, a4, a5, a6, a7) _Py_DictComp(a0, a1, a2, a3, a4, a5, a6, a7) +expr_ty _Py_DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int + lineno, int col_offset, int end_lineno, int + end_col_offset, PyArena *arena); +#define GeneratorExp(a0, a1, a2, a3, a4, a5, a6) _Py_GeneratorExp(a0, a1, a2, a3, a4, a5, a6) +expr_ty _Py_GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int + col_offset, int end_lineno, int end_col_offset, + PyArena *arena); +#define Await(a0, a1, a2, a3, a4, a5) _Py_Await(a0, a1, a2, a3, a4, a5) +expr_ty _Py_Await(expr_ty value, int lineno, int col_offset, int end_lineno, + int end_col_offset, PyArena *arena); +#define Yield(a0, a1, a2, a3, a4, a5) _Py_Yield(a0, a1, a2, a3, a4, a5) +expr_ty _Py_Yield(expr_ty value, int lineno, int col_offset, int end_lineno, + int end_col_offset, PyArena *arena); +#define YieldFrom(a0, a1, a2, a3, a4, a5) _Py_YieldFrom(a0, a1, a2, a3, a4, a5) +expr_ty _Py_YieldFrom(expr_ty value, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena *arena); +#define Compare(a0, a1, a2, a3, a4, a5, a6, a7) _Py_Compare(a0, a1, a2, a3, a4, a5, a6, a7) +expr_ty _Py_Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, + int lineno, int col_offset, int end_lineno, int + end_col_offset, PyArena *arena); +#define Call(a0, a1, a2, a3, a4, a5, a6, a7) _Py_Call(a0, a1, a2, a3, a4, a5, a6, a7) +expr_ty _Py_Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, int + lineno, int col_offset, int end_lineno, int end_col_offset, + PyArena *arena); +#define FormattedValue(a0, a1, a2, a3, a4, a5, a6, a7) _Py_FormattedValue(a0, a1, a2, a3, a4, a5, a6, a7) +expr_ty _Py_FormattedValue(expr_ty value, int conversion, expr_ty format_spec, + int lineno, int col_offset, int end_lineno, int + end_col_offset, PyArena *arena); +#define JoinedStr(a0, a1, a2, a3, a4, a5) _Py_JoinedStr(a0, a1, a2, a3, a4, a5) +expr_ty _Py_JoinedStr(asdl_seq * values, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena *arena); +#define Constant(a0, a1, a2, a3, a4, a5, a6) _Py_Constant(a0, a1, a2, a3, a4, a5, a6) +expr_ty _Py_Constant(constant value, string kind, int lineno, int col_offset, + int end_lineno, int end_col_offset, PyArena *arena); +#define Attribute(a0, a1, a2, a3, a4, a5, a6, a7) _Py_Attribute(a0, a1, a2, a3, a4, a5, a6, a7) +expr_ty _Py_Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int + lineno, int col_offset, int end_lineno, int + end_col_offset, PyArena *arena); +#define Subscript(a0, a1, a2, a3, a4, a5, a6, a7) _Py_Subscript(a0, a1, a2, a3, a4, a5, a6, a7) +expr_ty _Py_Subscript(expr_ty value, expr_ty slice, expr_context_ty ctx, int + lineno, int col_offset, int end_lineno, int + end_col_offset, PyArena *arena); +#define Starred(a0, a1, a2, a3, a4, a5, a6) _Py_Starred(a0, a1, a2, a3, a4, a5, a6) +expr_ty _Py_Starred(expr_ty value, expr_context_ty ctx, int lineno, int + col_offset, int end_lineno, int end_col_offset, PyArena *arena); -#define Nonlocal(a0, a1, a2, a3) _Ta3_Nonlocal(a0, a1, a2, a3) -stmt_ty _Ta3_Nonlocal(asdl_seq * names, int lineno, int col_offset, PyArena - *arena); -#define Expr(a0, a1, a2, a3) _Ta3_Expr(a0, a1, a2, a3) -stmt_ty _Ta3_Expr(expr_ty value, int lineno, int col_offset, PyArena *arena); -#define Pass(a0, a1, a2) _Ta3_Pass(a0, a1, a2) -stmt_ty _Ta3_Pass(int lineno, int col_offset, PyArena *arena); -#define Break(a0, a1, a2) _Ta3_Break(a0, a1, a2) -stmt_ty _Ta3_Break(int lineno, int col_offset, PyArena *arena); -#define Continue(a0, a1, a2) _Ta3_Continue(a0, a1, a2) -stmt_ty _Ta3_Continue(int lineno, int col_offset, PyArena *arena); -#define BoolOp(a0, a1, a2, a3, a4) _Ta3_BoolOp(a0, a1, a2, a3, a4) -expr_ty _Ta3_BoolOp(boolop_ty op, asdl_seq * values, int lineno, int - col_offset, PyArena *arena); -#define BinOp(a0, a1, a2, a3, a4, a5) _Ta3_BinOp(a0, a1, a2, a3, a4, a5) -expr_ty _Ta3_BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int - col_offset, PyArena *arena); -#define UnaryOp(a0, a1, a2, a3, a4) _Ta3_UnaryOp(a0, a1, a2, a3, a4) -expr_ty _Ta3_UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int - col_offset, PyArena *arena); -#define Lambda(a0, a1, a2, a3, a4) _Ta3_Lambda(a0, a1, a2, a3, a4) -expr_ty _Ta3_Lambda(arguments_ty args, expr_ty body, int lineno, int - col_offset, PyArena *arena); -#define IfExp(a0, a1, a2, a3, a4, a5) _Ta3_IfExp(a0, a1, a2, a3, a4, a5) -expr_ty _Ta3_IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int - col_offset, PyArena *arena); -#define Dict(a0, a1, a2, a3, a4) _Ta3_Dict(a0, a1, a2, a3, a4) -expr_ty _Ta3_Dict(asdl_seq * keys, asdl_seq * values, int lineno, int - col_offset, PyArena *arena); -#define Set(a0, a1, a2, a3) _Ta3_Set(a0, a1, a2, a3) -expr_ty _Ta3_Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena); -#define ListComp(a0, a1, a2, a3, a4) _Ta3_ListComp(a0, a1, a2, a3, a4) -expr_ty _Ta3_ListComp(expr_ty elt, asdl_seq * generators, int lineno, int - col_offset, PyArena *arena); -#define SetComp(a0, a1, a2, a3, a4) _Ta3_SetComp(a0, a1, a2, a3, a4) -expr_ty _Ta3_SetComp(expr_ty elt, asdl_seq * generators, int lineno, int - col_offset, PyArena *arena); -#define DictComp(a0, a1, a2, a3, a4, a5) _Ta3_DictComp(a0, a1, a2, a3, a4, a5) -expr_ty _Ta3_DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int - lineno, int col_offset, PyArena *arena); -#define GeneratorExp(a0, a1, a2, a3, a4) _Ta3_GeneratorExp(a0, a1, a2, a3, a4) -expr_ty _Ta3_GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int - col_offset, PyArena *arena); -#define Await(a0, a1, a2, a3) _Ta3_Await(a0, a1, a2, a3) -expr_ty _Ta3_Await(expr_ty value, int lineno, int col_offset, PyArena *arena); -#define Yield(a0, a1, a2, a3) _Ta3_Yield(a0, a1, a2, a3) -expr_ty _Ta3_Yield(expr_ty value, int lineno, int col_offset, PyArena *arena); -#define YieldFrom(a0, a1, a2, a3) _Ta3_YieldFrom(a0, a1, a2, a3) -expr_ty _Ta3_YieldFrom(expr_ty value, int lineno, int col_offset, PyArena - *arena); -#define Compare(a0, a1, a2, a3, a4, a5) _Ta3_Compare(a0, a1, a2, a3, a4, a5) -expr_ty _Ta3_Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, - int lineno, int col_offset, PyArena *arena); -#define Call(a0, a1, a2, a3, a4, a5) _Ta3_Call(a0, a1, a2, a3, a4, a5) -expr_ty _Ta3_Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, int - lineno, int col_offset, PyArena *arena); -#define Num(a0, a1, a2, a3) _Ta3_Num(a0, a1, a2, a3) -expr_ty _Ta3_Num(object n, int lineno, int col_offset, PyArena *arena); -#define Str(a0, a1, a2, a3, a4) _Ta3_Str(a0, a1, a2, a3, a4) -expr_ty _Ta3_Str(string s, string kind, int lineno, int col_offset, PyArena +#define Name(a0, a1, a2, a3, a4, a5, a6) _Py_Name(a0, a1, a2, a3, a4, a5, a6) +expr_ty _Py_Name(identifier id, expr_context_ty ctx, int lineno, int + col_offset, int end_lineno, int end_col_offset, PyArena + *arena); +#define List(a0, a1, a2, a3, a4, a5, a6) _Py_List(a0, a1, a2, a3, a4, a5, a6) +expr_ty _Py_List(asdl_seq * elts, expr_context_ty ctx, int lineno, int + col_offset, int end_lineno, int end_col_offset, PyArena *arena); -#define FormattedValue(a0, a1, a2, a3, a4, a5) _Ta3_FormattedValue(a0, a1, a2, a3, a4, a5) -expr_ty _Ta3_FormattedValue(expr_ty value, int conversion, expr_ty format_spec, - int lineno, int col_offset, PyArena *arena); -#define JoinedStr(a0, a1, a2, a3) _Ta3_JoinedStr(a0, a1, a2, a3) -expr_ty _Ta3_JoinedStr(asdl_seq * values, int lineno, int col_offset, PyArena +#define Tuple(a0, a1, a2, a3, a4, a5, a6) _Py_Tuple(a0, a1, a2, a3, a4, a5, a6) +expr_ty _Py_Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int + col_offset, int end_lineno, int end_col_offset, PyArena + *arena); +#define Slice(a0, a1, a2, a3, a4, a5, a6, a7) _Py_Slice(a0, a1, a2, a3, a4, a5, a6, a7) +expr_ty _Py_Slice(expr_ty lower, expr_ty upper, expr_ty step, int lineno, int + col_offset, int end_lineno, int end_col_offset, PyArena + *arena); +#define comprehension(a0, a1, a2, a3, a4) _Py_comprehension(a0, a1, a2, a3, a4) +comprehension_ty _Py_comprehension(expr_ty target, expr_ty iter, asdl_seq * + ifs, int is_async, PyArena *arena); +#define ExceptHandler(a0, a1, a2, a3, a4, a5, a6, a7) _Py_ExceptHandler(a0, a1, a2, a3, a4, a5, a6, a7) +excepthandler_ty _Py_ExceptHandler(expr_ty type, identifier name, asdl_seq * + body, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena + *arena); +#define arguments(a0, a1, a2, a3, a4, a5, a6, a7) _Py_arguments(a0, a1, a2, a3, a4, a5, a6, a7) +arguments_ty _Py_arguments(asdl_seq * posonlyargs, asdl_seq * args, arg_ty + vararg, asdl_seq * kwonlyargs, asdl_seq * + kw_defaults, arg_ty kwarg, asdl_seq * defaults, + PyArena *arena); +#define arg(a0, a1, a2, a3, a4, a5, a6, a7) _Py_arg(a0, a1, a2, a3, a4, a5, a6, a7) +arg_ty _Py_arg(identifier arg, expr_ty annotation, string type_comment, int + lineno, int col_offset, int end_lineno, int end_col_offset, + PyArena *arena); +#define keyword(a0, a1, a2, a3, a4, a5, a6) _Py_keyword(a0, a1, a2, a3, a4, a5, a6) +keyword_ty _Py_keyword(identifier arg, expr_ty value, int lineno, int + col_offset, int end_lineno, int end_col_offset, PyArena *arena); -#define Bytes(a0, a1, a2, a3, a4) _Ta3_Bytes(a0, a1, a2, a3, a4) -expr_ty _Ta3_Bytes(bytes s, string kind, int lineno, int col_offset, PyArena - *arena); -#define NameConstant(a0, a1, a2, a3) _Ta3_NameConstant(a0, a1, a2, a3) -expr_ty _Ta3_NameConstant(singleton value, int lineno, int col_offset, PyArena - *arena); -#define Ellipsis(a0, a1, a2) _Ta3_Ellipsis(a0, a1, a2) -expr_ty _Ta3_Ellipsis(int lineno, int col_offset, PyArena *arena); -#define Constant(a0, a1, a2, a3) _Ta3_Constant(a0, a1, a2, a3) -expr_ty _Ta3_Constant(constant value, int lineno, int col_offset, PyArena - *arena); -#define Attribute(a0, a1, a2, a3, a4, a5) _Ta3_Attribute(a0, a1, a2, a3, a4, a5) -expr_ty _Ta3_Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int - lineno, int col_offset, PyArena *arena); -#define Subscript(a0, a1, a2, a3, a4, a5) _Ta3_Subscript(a0, a1, a2, a3, a4, a5) -expr_ty _Ta3_Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int - lineno, int col_offset, PyArena *arena); -#define Starred(a0, a1, a2, a3, a4) _Ta3_Starred(a0, a1, a2, a3, a4) -expr_ty _Ta3_Starred(expr_ty value, expr_context_ty ctx, int lineno, int - col_offset, PyArena *arena); -#define Name(a0, a1, a2, a3, a4) _Ta3_Name(a0, a1, a2, a3, a4) -expr_ty _Ta3_Name(identifier id, expr_context_ty ctx, int lineno, int - col_offset, PyArena *arena); -#define List(a0, a1, a2, a3, a4) _Ta3_List(a0, a1, a2, a3, a4) -expr_ty _Ta3_List(asdl_seq * elts, expr_context_ty ctx, int lineno, int - col_offset, PyArena *arena); -#define Tuple(a0, a1, a2, a3, a4) _Ta3_Tuple(a0, a1, a2, a3, a4) -expr_ty _Ta3_Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int - col_offset, PyArena *arena); -#define Slice(a0, a1, a2, a3) _Ta3_Slice(a0, a1, a2, a3) -slice_ty _Ta3_Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena); -#define ExtSlice(a0, a1) _Ta3_ExtSlice(a0, a1) -slice_ty _Ta3_ExtSlice(asdl_seq * dims, PyArena *arena); -#define Index(a0, a1) _Ta3_Index(a0, a1) -slice_ty _Ta3_Index(expr_ty value, PyArena *arena); -#define comprehension(a0, a1, a2, a3, a4) _Ta3_comprehension(a0, a1, a2, a3, a4) -comprehension_ty _Ta3_comprehension(expr_ty target, expr_ty iter, asdl_seq * - ifs, int is_async, PyArena *arena); -#define ExceptHandler(a0, a1, a2, a3, a4, a5) _Ta3_ExceptHandler(a0, a1, a2, a3, a4, a5) -excepthandler_ty _Ta3_ExceptHandler(expr_ty type, identifier name, asdl_seq * - body, int lineno, int col_offset, PyArena - *arena); -#define arguments(a0, a1, a2, a3, a4, a5, a6) _Ta3_arguments(a0, a1, a2, a3, a4, a5, a6) -arguments_ty _Ta3_arguments(asdl_seq * args, arg_ty vararg, asdl_seq * - kwonlyargs, asdl_seq * kw_defaults, arg_ty kwarg, - asdl_seq * defaults, PyArena *arena); -#define arg(a0, a1, a2, a3, a4, a5) _Ta3_arg(a0, a1, a2, a3, a4, a5) -arg_ty _Ta3_arg(identifier arg, expr_ty annotation, string type_comment, int - lineno, int col_offset, PyArena *arena); -#define keyword(a0, a1, a2) _Ta3_keyword(a0, a1, a2) -keyword_ty _Ta3_keyword(identifier arg, expr_ty value, PyArena *arena); -#define alias(a0, a1, a2) _Ta3_alias(a0, a1, a2) -alias_ty _Ta3_alias(identifier name, identifier asname, PyArena *arena); -#define withitem(a0, a1, a2) _Ta3_withitem(a0, a1, a2) -withitem_ty _Ta3_withitem(expr_ty context_expr, expr_ty optional_vars, PyArena - *arena); -#define TypeIgnore(a0, a1, a2) _Ta3_TypeIgnore(a0, a1, a2) -type_ignore_ty _Ta3_TypeIgnore(int lineno, string tag, PyArena *arena); - -PyObject* Ta3AST_mod2obj(mod_ty t); -mod_ty Ta3AST_obj2mod(PyObject* ast, PyArena* arena, int mode); -int Ta3AST_Check(PyObject* obj); +#define alias(a0, a1, a2) _Py_alias(a0, a1, a2) +alias_ty _Py_alias(identifier name, identifier asname, PyArena *arena); +#define withitem(a0, a1, a2) _Py_withitem(a0, a1, a2) +withitem_ty _Py_withitem(expr_ty context_expr, expr_ty optional_vars, PyArena + *arena); +#define TypeIgnore(a0, a1, a2) _Py_TypeIgnore(a0, a1, a2) +type_ignore_ty _Py_TypeIgnore(int lineno, string tag, PyArena *arena); + +PyObject* PyAST_mod2obj(mod_ty t); +mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode); +int PyAST_Check(PyObject* obj); +#endif /* !Py_LIMITED_API */ + +#ifdef __cplusplus +} +#endif +#endif /* !Py_PYTHON_AST_H */ diff --git a/ast3/Include/asdl.h b/ast3/Include/asdl.h index 2f39db8c..e962560b 100644 --- a/ast3/Include/asdl.h +++ b/ast3/Include/asdl.h @@ -1,11 +1,10 @@ -#ifndef Ta3_ASDL_H -#define Ta3_ASDL_H +#ifndef Py_LIMITED_API +#ifndef Py_ASDL_H +#define Py_ASDL_H typedef PyObject * identifier; typedef PyObject * string; -typedef PyObject * bytes; typedef PyObject * object; -typedef PyObject * singleton; typedef PyObject * constant; /* It would be nice if the code generated by asdl_c.py was completely @@ -26,8 +25,8 @@ typedef struct { int elements[1]; } asdl_int_seq; -asdl_seq *_Ta3_asdl_seq_new(Py_ssize_t size, PyArena *arena); -asdl_int_seq *_Ta3_asdl_int_seq_new(Py_ssize_t size, PyArena *arena); +asdl_seq *_Py_asdl_seq_new(Py_ssize_t size, PyArena *arena); +asdl_int_seq *_Py_asdl_int_seq_new(Py_ssize_t size, PyArena *arena); #define asdl_seq_GET(S, I) (S)->elements[(I)] #define asdl_seq_LEN(S) ((S) == NULL ? 0 : (S)->size) @@ -36,11 +35,12 @@ asdl_int_seq *_Ta3_asdl_int_seq_new(Py_ssize_t size, PyArena *arena); do { \ Py_ssize_t _asdl_i = (I); \ assert((S) != NULL); \ - assert(_asdl_i < (S)->size); \ + assert(0 <= _asdl_i && _asdl_i < (S)->size); \ (S)->elements[_asdl_i] = (V); \ } while (0) #else #define asdl_seq_SET(S, I, V) (S)->elements[I] = (V) #endif -#endif /* !Ta3_ASDL_H */ +#endif /* !Py_ASDL_H */ +#endif /* Py_LIMITED_API */ diff --git a/ast3/Include/ast.h b/ast3/Include/ast.h deleted file mode 100644 index 24a59f01..00000000 --- a/ast3/Include/ast.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef Ta3_AST_H -#define Ta3_AST_H -#ifdef __cplusplus -extern "C" { -#endif - -extern int Ta3AST_Validate(mod_ty); -extern mod_ty Ta3AST_FromNode( - const node *n, - PyCompilerFlags *flags, - const char *filename, /* decoded from the filesystem encoding */ - int feature_version, - PyArena *arena); -extern mod_ty Ta3AST_FromNodeObject( - const node *n, - PyCompilerFlags *flags, - PyObject *filename, - int feature_version, - PyArena *arena); - -#ifndef Py_LIMITED_API - -/* _PyAST_ExprAsUnicode is defined in ast_unparse.c */ -extern PyObject * _PyAST_ExprAsUnicode(expr_ty); - -#endif /* !Py_LIMITED_API */ - -#ifdef __cplusplus -} -#endif -#endif /* !Ta3_AST_H */ diff --git a/ast3/Include/bitset.h b/ast3/Include/bitset.h deleted file mode 100644 index b05c05f1..00000000 --- a/ast3/Include/bitset.h +++ /dev/null @@ -1,32 +0,0 @@ - -#ifndef Ta3_BITSET_H -#define Ta3_BITSET_H -#ifdef __cplusplus -extern "C" { -#endif - -/* Bitset interface */ - -#define BYTE char - -typedef BYTE *bitset; - -bitset newbitset(int nbits); -void delbitset(bitset bs); -#define testbit(ss, ibit) (((ss)[BIT2BYTE(ibit)] & BIT2MASK(ibit)) != 0) -int addbit(bitset bs, int ibit); /* Returns 0 if already set */ -int samebitset(bitset bs1, bitset bs2, int nbits); -void mergebitset(bitset bs1, bitset bs2, int nbits); - -#define BITSPERBYTE (8*sizeof(BYTE)) -#define NBYTES(nbits) (((nbits) + BITSPERBYTE - 1) / BITSPERBYTE) - -#define BIT2BYTE(ibit) ((ibit) / BITSPERBYTE) -#define BIT2SHIFT(ibit) ((ibit) % BITSPERBYTE) -#define BIT2MASK(ibit) (1 << BIT2SHIFT(ibit)) -#define BYTE2BIT(ibyte) ((ibyte) * BITSPERBYTE) - -#ifdef __cplusplus -} -#endif -#endif /* !Ta3_BITSET_H */ diff --git a/ast3/Include/errcode.h b/ast3/Include/errcode.h deleted file mode 100644 index 23bd69cb..00000000 --- a/ast3/Include/errcode.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef Ta3_ERRCODE_H -#define Ta3_ERRCODE_H -#ifdef __cplusplus -extern "C" { -#endif - - -/* Error codes passed around between file input, tokenizer, parser and - interpreter. This is necessary so we can turn them into Python - exceptions at a higher level. Note that some errors have a - slightly different meaning when passed from the tokenizer to the - parser than when passed from the parser to the interpreter; e.g. - the parser only returns E_EOF when it hits EOF immediately, and it - never returns E_OK. */ - -#define E_OK 10 /* No error */ -#define E_EOF 11 /* End Of File */ -#define E_INTR 12 /* Interrupted */ -#define E_TOKEN 13 /* Bad token */ -#define E_SYNTAX 14 /* Syntax error */ -#define E_NOMEM 15 /* Ran out of memory */ -#define E_DONE 16 /* Parsing complete */ -#define E_ERROR 17 /* Execution error */ -#define E_TABSPACE 18 /* Inconsistent mixing of tabs and spaces */ -#define E_OVERFLOW 19 /* Node had too many children */ -#define E_TOODEEP 20 /* Too many indentation levels */ -#define E_DEDENT 21 /* No matching outer block for dedent */ -#define E_DECODE 22 /* Error in decoding into Unicode */ -#define E_EOFS 23 /* EOF in triple-quoted string */ -#define E_EOLS 24 /* EOL in single-quoted string */ -#define E_LINECONT 25 /* Unexpected characters after a line continuation */ -#define E_IDENTIFIER 26 /* Invalid characters in identifier */ -#define E_BADSINGLE 27 /* Ill-formed single statement input */ - -#ifdef __cplusplus -} -#endif -#endif /* !Ta3_ERRCODE_H */ diff --git a/ast3/Include/graminit.h b/ast3/Include/graminit.h deleted file mode 100644 index 6f3232c4..00000000 --- a/ast3/Include/graminit.h +++ /dev/null @@ -1,92 +0,0 @@ -/* Generated by Parser/pgen */ - -#define single_input 256 -#define file_input 257 -#define eval_input 258 -#define decorator 259 -#define decorators 260 -#define decorated 261 -#define async_funcdef 262 -#define funcdef 263 -#define parameters 264 -#define typedargslist 265 -#define tfpdef 266 -#define varargslist 267 -#define vfpdef 268 -#define stmt 269 -#define simple_stmt 270 -#define small_stmt 271 -#define expr_stmt 272 -#define annassign 273 -#define testlist_star_expr 274 -#define augassign 275 -#define del_stmt 276 -#define pass_stmt 277 -#define flow_stmt 278 -#define break_stmt 279 -#define continue_stmt 280 -#define return_stmt 281 -#define yield_stmt 282 -#define raise_stmt 283 -#define import_stmt 284 -#define import_name 285 -#define import_from 286 -#define import_as_name 287 -#define dotted_as_name 288 -#define import_as_names 289 -#define dotted_as_names 290 -#define dotted_name 291 -#define global_stmt 292 -#define nonlocal_stmt 293 -#define assert_stmt 294 -#define compound_stmt 295 -#define async_stmt 296 -#define if_stmt 297 -#define while_stmt 298 -#define for_stmt 299 -#define try_stmt 300 -#define with_stmt 301 -#define with_item 302 -#define except_clause 303 -#define suite 304 -#define test 305 -#define test_nocond 306 -#define lambdef 307 -#define lambdef_nocond 308 -#define or_test 309 -#define and_test 310 -#define not_test 311 -#define comparison 312 -#define comp_op 313 -#define star_expr 314 -#define expr 315 -#define xor_expr 316 -#define and_expr 317 -#define shift_expr 318 -#define arith_expr 319 -#define term 320 -#define factor 321 -#define power 322 -#define atom_expr 323 -#define atom 324 -#define testlist_comp 325 -#define trailer 326 -#define subscriptlist 327 -#define subscript 328 -#define sliceop 329 -#define exprlist 330 -#define testlist 331 -#define dictorsetmaker 332 -#define classdef 333 -#define arglist 334 -#define argument 335 -#define comp_iter 336 -#define sync_comp_for 337 -#define comp_for 338 -#define comp_if 339 -#define encoding_decl 340 -#define yield_expr 341 -#define yield_arg 342 -#define func_type_input 343 -#define func_type 344 -#define typelist 345 diff --git a/ast3/Include/grammar.h b/ast3/Include/grammar.h deleted file mode 100644 index 16eaed6f..00000000 --- a/ast3/Include/grammar.h +++ /dev/null @@ -1,94 +0,0 @@ - -/* Grammar interface */ - -#ifndef Ta3_GRAMMAR_H -#define Ta3_GRAMMAR_H -#ifdef __cplusplus -extern "C" { -#endif - -#include "../Include/bitset.h" - -/* A label of an arc */ - -typedef struct { - int lb_type; - char *lb_str; -} label; - -#define EMPTY 0 /* Label number 0 is by definition the empty label */ - -/* A list of labels */ - -typedef struct { - int ll_nlabels; - label *ll_label; -} labellist; - -/* An arc from one state to another */ - -typedef struct { - short a_lbl; /* Label of this arc */ - short a_arrow; /* State where this arc goes to */ -} arc; - -/* A state in a DFA */ - -typedef struct { - int s_narcs; - arc *s_arc; /* Array of arcs */ - - /* Optional accelerators */ - int s_lower; /* Lowest label index */ - int s_upper; /* Highest label index */ - int *s_accel; /* Accelerator */ - int s_accept; /* Nonzero for accepting state */ -} state; - -/* A DFA */ - -typedef struct { - int d_type; /* Non-terminal this represents */ - char *d_name; /* For printing */ - int d_initial; /* Initial state */ - int d_nstates; - state *d_state; /* Array of states */ - bitset d_first; -} dfa; - -/* A grammar */ - -typedef struct { - int g_ndfas; - dfa *g_dfa; /* Array of DFAs */ - labellist g_ll; - int g_start; /* Start symbol of the grammar */ - int g_accel; /* Set if accelerators present */ -} grammar; - -/* FUNCTIONS */ - -grammar *newgrammar(int start); -void freegrammar(grammar *g); -dfa *adddfa(grammar *g, int type, const char *name); -int addstate(dfa *d); -void addarc(dfa *d, int from, int to, int lbl); -dfa *Ta3Grammar_FindDFA(grammar *g, int type); - -int addlabel(labellist *ll, int type, const char *str); -int findlabel(labellist *ll, int type, const char *str); -const char *Ta3Grammar_LabelRepr(label *lb); -void translatelabels(grammar *g); - -void addfirstsets(grammar *g); - -void Ta3Grammar_AddAccelerators(grammar *g); -void Ta3Grammar_RemoveAccelerators(grammar *); - -void printgrammar(grammar *g, FILE *fp); -void printnonterminals(grammar *g, FILE *fp); - -#ifdef __cplusplus -} -#endif -#endif /* !Ta3_GRAMMAR_H */ diff --git a/ast3/Include/node.h b/ast3/Include/node.h deleted file mode 100644 index 05095502..00000000 --- a/ast3/Include/node.h +++ /dev/null @@ -1,44 +0,0 @@ - -/* Parse tree node interface */ - -#ifndef Ta3_NODE_H -#define Ta3_NODE_H -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct _node { - short n_type; - char *n_str; - int n_lineno; - int n_col_offset; - int n_nchildren; - struct _node *n_child; -} node; - -extern node * Ta3Node_New(int type); -extern int Ta3Node_AddChild(node *n, int type, - char *str, int lineno, int col_offset); -extern void Ta3Node_Free(node *n); -#ifndef Py_LIMITED_API -extern Py_ssize_t _Ta3Node_SizeOf(node *n); -#endif - -/* Node access functions */ -#define NCH(n) ((n)->n_nchildren) - -#define CHILD(n, i) (&(n)->n_child[i]) -#define RCHILD(n, i) (CHILD(n, NCH(n) + i)) -#define TYPE(n) ((n)->n_type) -#define STR(n) ((n)->n_str) -#define LINENO(n) ((n)->n_lineno) - -/* Assert that the type of a node is what we expect */ -#define REQ(n, type) assert(TYPE(n) == (type)) - -extern void PyNode_ListTree(node *); - -#ifdef __cplusplus -} -#endif -#endif /* !Ta3_NODE_H */ diff --git a/ast3/Include/parsetok.h b/ast3/Include/parsetok.h deleted file mode 100644 index 46454d3f..00000000 --- a/ast3/Include/parsetok.h +++ /dev/null @@ -1,109 +0,0 @@ - -/* Parser-tokenizer link interface */ -#ifndef Py_LIMITED_API -#ifndef Ta3_PARSETOK_H -#define Ta3_PARSETOK_H -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - int error; -#ifndef PGEN - /* The filename is useless for pgen, see comment in tok_state structure */ - PyObject *filename; -#endif - int lineno; - int offset; - char *text; /* UTF-8-encoded string */ - int token; - int expected; -} perrdetail; - -#if 0 -#define PyPARSE_YIELD_IS_KEYWORD 0x0001 -#endif - -#define PyPARSE_DONT_IMPLY_DEDENT 0x0002 - -#if 0 -#define PyPARSE_WITH_IS_KEYWORD 0x0003 -#define PyPARSE_PRINT_IS_FUNCTION 0x0004 -#define PyPARSE_UNICODE_LITERALS 0x0008 -#endif - -#define PyPARSE_IGNORE_COOKIE 0x0010 -#define PyPARSE_BARRY_AS_BDFL 0x0020 -#define PyPARSE_ASYNC_ALWAYS 0x8000 - -extern node * Ta3Parser_ParseString(const char *, grammar *, int, - perrdetail *); -extern node * Ta3Parser_ParseFile (FILE *, const char *, grammar *, int, - const char *, const char *, - perrdetail *); - -extern node * Ta3Parser_ParseStringFlags(const char *, grammar *, int, - perrdetail *, int); -extern node * Ta3Parser_ParseFileFlags( - FILE *fp, - const char *filename, /* decoded from the filesystem encoding */ - const char *enc, - grammar *g, - int start, - const char *ps1, - const char *ps2, - perrdetail *err_ret, - int flags); -extern node * Ta3Parser_ParseFileFlagsEx( - FILE *fp, - const char *filename, /* decoded from the filesystem encoding */ - const char *enc, - grammar *g, - int start, - const char *ps1, - const char *ps2, - perrdetail *err_ret, - int *flags); -extern node * Ta3Parser_ParseFileObject( - FILE *fp, - PyObject *filename, - const char *enc, - grammar *g, - int start, - const char *ps1, - const char *ps2, - perrdetail *err_ret, - int *flags); - -extern node * Ta3Parser_ParseStringFlagsFilename( - const char *s, - const char *filename, /* decoded from the filesystem encoding */ - grammar *g, - int start, - perrdetail *err_ret, - int flags); -extern node * Ta3Parser_ParseStringFlagsFilenameEx( - const char *s, - const char *filename, /* decoded from the filesystem encoding */ - grammar *g, - int start, - perrdetail *err_ret, - int *flags); -extern node * Ta3Parser_ParseStringObject( - const char *s, - PyObject *filename, - grammar *g, - int start, - perrdetail *err_ret, - int *flags); - -/* Note that the following functions are defined in pythonrun.c, - not in parsetok.c */ -extern void PyParser_SetError(perrdetail *); -extern void PyParser_ClearError(perrdetail *); - -#ifdef __cplusplus -} -#endif -#endif /* !Ta3_PARSETOK_H */ -#endif /* !Py_LIMITED_API */ diff --git a/ast3/Include/pegen_interface.h b/ast3/Include/pegen_interface.h new file mode 100644 index 00000000..ee4c77ec --- /dev/null +++ b/ast3/Include/pegen_interface.h @@ -0,0 +1,46 @@ +#ifndef Py_PEGENINTERFACE +#define Py_PEGENINTERFACE +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef Py_BUILD_CORE +# error "this header requires Py_BUILD_CORE define" +#endif + +#include "Python.h" +#include "Python-ast.h" + +PyAPI_FUNC(mod_ty) PyPegen_ASTFromString( + const char *str, + const char *filename, + int mode, + PyCompilerFlags *flags, + PyArena *arena); +PyAPI_FUNC(mod_ty) PyPegen_ASTFromStringObject( + const char *str, + PyObject* filename, + int mode, + PyCompilerFlags *flags, + PyArena *arena); +PyAPI_FUNC(mod_ty) PyPegen_ASTFromFileObject( + FILE *fp, + PyObject *filename_ob, + int mode, + const char *enc, + const char *ps1, + const char *ps2, + PyCompilerFlags *flags, + int *errcode, + PyArena *arena); +PyAPI_FUNC(mod_ty) PyPegen_ASTFromFilename( + const char *filename, + int mode, + PyCompilerFlags *flags, + PyArena *arena); + + +#ifdef __cplusplus +} +#endif +#endif /* !Py_PEGENINTERFACE*/ diff --git a/ast3/Include/pgenheaders.h b/ast3/Include/pgenheaders.h deleted file mode 100644 index 11f2d0cb..00000000 --- a/ast3/Include/pgenheaders.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef DUMMY_Py_PGENHEADERS_H -#define DUMMY_Py_PGENHEADERS_H - -/* pgenheaders.h is included by a bunch of files but nothing in it is - * used except for the Python.h import, and it was removed in Python - * 3.8. Since some of those files are generated we provide a dummy - * pgenheaders.h. */ -#include "Python.h" - -#endif /* !DUMMY_Py_PGENHEADERS_H */ diff --git a/ast3/Include/token.h b/ast3/Include/token.h index 7b315a8e..9b8a3aae 100644 --- a/ast3/Include/token.h +++ b/ast3/Include/token.h @@ -1,8 +1,9 @@ +/* Auto-generated by Tools/scripts/generate_token.py */ /* Token types */ #ifndef Py_LIMITED_API -#ifndef Ta3_TOKEN_H -#define Ta3_TOKEN_H +#ifndef Py_TOKEN_H +#define Py_TOKEN_H #ifdef __cplusplus extern "C" { #endif @@ -62,35 +63,34 @@ extern "C" { #define ATEQUAL 50 #define RARROW 51 #define ELLIPSIS 52 -/* Don't forget to update the table _Ta3Parser_TokenNames in tokenizer.c! */ -#define OP 53 -#define AWAIT 54 -#define ASYNC 55 -#define TYPE_IGNORE 56 -#define TYPE_COMMENT 57 -#define ERRORTOKEN 58 -/* These aren't used by the C tokenizer but are needed for tokenize.py */ -#define COMMENT 59 -#define NL 60 -#define ENCODING 61 -#define N_TOKENS 62 +#define COLONEQUAL 53 +#define OP 54 +#define AWAIT 55 +#define ASYNC 56 +#define TYPE_IGNORE 57 +#define TYPE_COMMENT 58 +#define ERRORTOKEN 59 +#define N_TOKENS 63 +#define NT_OFFSET 256 /* Special definitions for cooperation with parser */ -#define NT_OFFSET 256 - #define ISTERMINAL(x) ((x) < NT_OFFSET) #define ISNONTERMINAL(x) ((x) >= NT_OFFSET) #define ISEOF(x) ((x) == ENDMARKER) +#define ISWHITESPACE(x) ((x) == ENDMARKER || \ + (x) == NEWLINE || \ + (x) == INDENT || \ + (x) == DEDENT) -extern const char * _Ta3Parser_TokenNames[]; /* Token names */ -extern int Ta3Token_OneChar(int); -extern int Ta3Token_TwoChars(int, int); -extern int Ta3Token_ThreeChars(int, int, int); +PyAPI_DATA(const char * const) _PyParser_TokenNames[]; /* Token names */ +PyAPI_FUNC(int) PyToken_OneChar(int); +PyAPI_FUNC(int) PyToken_TwoChars(int, int); +PyAPI_FUNC(int) PyToken_ThreeChars(int, int, int); #ifdef __cplusplus } #endif -#endif /* !Ta3_TOKEN_H */ +#endif /* !Py_TOKEN_H */ #endif /* Py_LIMITED_API */ diff --git a/ast3/Parser/Python.asdl b/ast3/Parser/Python.asdl index 99ba8eee..889712b4 100644 --- a/ast3/Parser/Python.asdl +++ b/ast3/Parser/Python.asdl @@ -1,23 +1,19 @@ --- ASDL's 7 builtin types are: --- identifier, int, string, bytes, object, singleton, constant --- --- singleton: None, True or False --- constant can be None, whereas None means "no value" for object. +-- ASDL's 4 builtin types are: +-- identifier, int, string, constant module Python { - mod = Module(stmt* body, type_ignore *type_ignores) + mod = Module(stmt* body, type_ignore* type_ignores) | Interactive(stmt* body) | Expression(expr body) | FunctionType(expr* argtypes, expr returns) - -- not really an actual node but useful in Jython's typesystem. - | Suite(stmt* body) - stmt = FunctionDef(identifier name, arguments args, - stmt* body, expr* decorator_list, expr? returns, string? type_comment) + stmt* body, expr* decorator_list, expr? returns, + string? type_comment) | AsyncFunctionDef(identifier name, arguments args, - stmt* body, expr* decorator_list, expr? returns, string? type_comment) + stmt* body, expr* decorator_list, expr? returns, + string? type_comment) | ClassDef(identifier name, expr* bases, @@ -52,12 +48,12 @@ module Python | Expr(expr value) | Pass | Break | Continue - -- XXX Jython will be different -- col_offset is the byte offset in the utf8 string the parser uses - attributes (int lineno, int col_offset) + attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset) -- BoolOp() can use left & right? expr = BoolOp(boolop op, expr* values) + | NamedExpr(expr target, expr value) | BinOp(expr left, operator op, expr right) | UnaryOp(unaryop op, expr operand) | Lambda(arguments args, expr body) @@ -76,31 +72,25 @@ module Python -- x < 4 < 3 and (x < 4) < 3 | Compare(expr left, cmpop* ops, expr* comparators) | Call(expr func, expr* args, keyword* keywords) - | Num(object n) -- a number as a PyObject. - | Str(string s, string kind) | FormattedValue(expr value, int? conversion, expr? format_spec) | JoinedStr(expr* values) - | Bytes(bytes s, string kind) - | NameConstant(singleton value) - | Ellipsis - | Constant(constant value) + | Constant(constant value, string? kind) -- the following expression can appear in assignment context | Attribute(expr value, identifier attr, expr_context ctx) - | Subscript(expr value, slice slice, expr_context ctx) + | Subscript(expr value, expr slice, expr_context ctx) | Starred(expr value, expr_context ctx) | Name(identifier id, expr_context ctx) | List(expr* elts, expr_context ctx) | Tuple(expr* elts, expr_context ctx) - -- col_offset is the byte offset in the utf8 string the parser uses - attributes (int lineno, int col_offset) + -- can appear only in Subscript + | Slice(expr? lower, expr? upper, expr? step) - expr_context = Load | Store | Del | AugLoad | AugStore | Param + -- col_offset is the byte offset in the utf8 string the parser uses + attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset) - slice = Slice(expr? lower, expr? upper, expr? step) - | ExtSlice(slice* dims) - | Index(expr value) + expr_context = Load | Store | Del boolop = And | Or @@ -114,16 +104,17 @@ module Python comprehension = (expr target, expr iter, expr* ifs, int is_async) excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body) - attributes (int lineno, int col_offset) + attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset) - arguments = (arg* args, arg? vararg, arg* kwonlyargs, expr* kw_defaults, - arg? kwarg, expr* defaults) + arguments = (arg* posonlyargs, arg* args, arg? vararg, arg* kwonlyargs, + expr* kw_defaults, arg? kwarg, expr* defaults) arg = (identifier arg, expr? annotation, string? type_comment) - attributes (int lineno, int col_offset) + attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset) -- keyword arguments supplied to call (NULL identifier for **kwargs) keyword = (identifier? arg, expr value) + attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset) -- import name with optional 'as' alias. alias = (identifier name, identifier? asname) diff --git a/ast3/Parser/acceler.c b/ast3/Parser/acceler.c deleted file mode 100644 index 7837332b..00000000 --- a/ast3/Parser/acceler.c +++ /dev/null @@ -1,125 +0,0 @@ - -/* Parser accelerator module */ - -/* The parser as originally conceived had disappointing performance. - This module does some precomputation that speeds up the selection - of a DFA based upon a token, turning a search through an array - into a simple indexing operation. The parser now cannot work - without the accelerators installed. Note that the accelerators - are installed dynamically when the parser is initialized, they - are not part of the static data structure written on graminit.[ch] - by the parser generator. */ - -#include "../Include/pgenheaders.h" -#include "../Include/grammar.h" -#include "../Include/node.h" -#include "../Include/token.h" -#include "parser.h" - -/* Forward references */ -static void fixdfa(grammar *, dfa *); -static void fixstate(grammar *, state *); - -void -Ta3Grammar_AddAccelerators(grammar *g) -{ - dfa *d; - int i; - d = g->g_dfa; - for (i = g->g_ndfas; --i >= 0; d++) - fixdfa(g, d); - g->g_accel = 1; -} - -void -Ta3Grammar_RemoveAccelerators(grammar *g) -{ - dfa *d; - int i; - g->g_accel = 0; - d = g->g_dfa; - for (i = g->g_ndfas; --i >= 0; d++) { - state *s; - int j; - s = d->d_state; - for (j = 0; j < d->d_nstates; j++, s++) { - if (s->s_accel) - PyObject_FREE(s->s_accel); - s->s_accel = NULL; - } - } -} - -static void -fixdfa(grammar *g, dfa *d) -{ - state *s; - int j; - s = d->d_state; - for (j = 0; j < d->d_nstates; j++, s++) - fixstate(g, s); -} - -static void -fixstate(grammar *g, state *s) -{ - arc *a; - int k; - int *accel; - int nl = g->g_ll.ll_nlabels; - s->s_accept = 0; - accel = (int *) PyObject_MALLOC(nl * sizeof(int)); - if (accel == NULL) { - fprintf(stderr, "no mem to build parser accelerators\n"); - exit(1); - } - for (k = 0; k < nl; k++) - accel[k] = -1; - a = s->s_arc; - for (k = s->s_narcs; --k >= 0; a++) { - int lbl = a->a_lbl; - label *l = &g->g_ll.ll_label[lbl]; - int type = l->lb_type; - if (a->a_arrow >= (1 << 7)) { - printf("XXX too many states!\n"); - continue; - } - if (ISNONTERMINAL(type)) { - dfa *d1 = Ta3Grammar_FindDFA(g, type); - int ibit; - if (type - NT_OFFSET >= (1 << 7)) { - printf("XXX too high nonterminal number!\n"); - continue; - } - for (ibit = 0; ibit < g->g_ll.ll_nlabels; ibit++) { - if (testbit(d1->d_first, ibit)) { - if (accel[ibit] != -1) - printf("XXX ambiguity!\n"); - accel[ibit] = a->a_arrow | (1 << 7) | - ((type - NT_OFFSET) << 8); - } - } - } - else if (lbl == EMPTY) - s->s_accept = 1; - else if (lbl >= 0 && lbl < nl) - accel[lbl] = a->a_arrow; - } - while (nl > 0 && accel[nl-1] == -1) - nl--; - for (k = 0; k < nl && accel[k] == -1;) - k++; - if (k < nl) { - int i; - s->s_accel = (int *) PyObject_MALLOC((nl-k) * sizeof(int)); - if (s->s_accel == NULL) { - fprintf(stderr, "no mem to add parser accelerators\n"); - exit(1); - } - s->s_lower = k; - s->s_upper = nl; - for (i = 0; k < nl; i++, k++) - s->s_accel[i] = accel[k]; - } - PyObject_FREE(accel); -} diff --git a/ast3/Parser/asdl.py b/ast3/Parser/asdl.py index 62f5c19c..7f509488 100644 --- a/ast3/Parser/asdl.py +++ b/ast3/Parser/asdl.py @@ -33,8 +33,7 @@ # See the EBNF at the top of the file to understand the logical connection # between the various node types. -builtin_types = {'identifier', 'string', 'bytes', 'int', 'object', 'singleton', - 'constant'} +builtin_types = {'identifier', 'string', 'int', 'constant'} class AST: def __repr__(self): @@ -72,6 +71,16 @@ def __init__(self, type, name=None, seq=False, opt=False): self.seq = seq self.opt = opt + def __str__(self): + if self.seq: + extra = "*" + elif self.opt: + extra = "?" + else: + extra = "" + + return "{}{} {}".format(self.type, extra, self.name) + def __repr__(self): if self.seq: extra = ", seq=True" diff --git a/ast3/Parser/asdl_c.py b/ast3/Parser/asdl_c.py old mode 100644 new mode 100755 index 0bf3393b..59bf03ef --- a/ast3/Parser/asdl_c.py +++ b/ast3/Parser/asdl_c.py @@ -60,6 +60,9 @@ def reflow_lines(s, depth): lines.append(padding + cur) return lines +def reflow_c_string(s, depth): + return '"%s"' % s.replace('\n', '\\n"\n%s"' % (' ' * depth * TABSIZE)) + def is_simple(sum): """Return True if a sum is a simple. @@ -71,6 +74,21 @@ def is_simple(sum): return False return True +def asdl_of(name, obj): + if isinstance(obj, asdl.Product) or isinstance(obj, asdl.Constructor): + fields = ", ".join(map(str, obj.fields)) + if fields: + fields = "({})".format(fields) + return "{}{}".format(name, fields) + else: + if is_simple(obj): + types = " | ".join(type.name for type in obj.types) + else: + sep = "\n{}| ".format(" " * (len(name) + 1)) + types = sep.join( + asdl_of(type.name, type) for type in obj.types + ) + return "{} = {}".format(name, types) class EmitVisitor(asdl.VisitorBase): """Visit that emits lines""" @@ -78,14 +96,18 @@ class EmitVisitor(asdl.VisitorBase): def __init__(self, file): self.file = file self.identifiers = set() + self.singletons = set() + self.types = set() super(EmitVisitor, self).__init__() def emit_identifier(self, name): - name = str(name) - if name in self.identifiers: - return - self.emit("_Py_IDENTIFIER(%s);" % name, 0) - self.identifiers.add(name) + self.identifiers.add(str(name)) + + def emit_singleton(self, name): + self.singletons.add(str(name)) + + def emit_type(self, name): + self.types.add(str(name)) def emit(self, s, depth, reflow=True): # XXX reflow long lines? @@ -270,9 +292,9 @@ def emit_function(self, name, ctype, args, attrs, union=True): margs = "a0" for i in range(1, len(args)+1): margs += ", a%d" % i - self.emit("#define %s(%s) _Ta3_%s(%s)" % (name, margs, name, margs), 0, + self.emit("#define %s(%s) _Py_%s(%s)" % (name, margs, name, margs), 0, reflow=False) - self.emit("%s _Ta3_%s(%s);" % (ctype, name, argstr), False) + self.emit("%s _Py_%s(%s);" % (ctype, name, argstr), False) def visitProduct(self, prod, name): self.emit_function(name, get_c_type(name), @@ -301,7 +323,7 @@ def emit(s, depth=0, reflow=True): if not opt and argtype != "int": emit("if (!%s) {" % argname, 1) emit("PyErr_SetString(PyExc_ValueError,", 2) - msg = "field %s is required for %s" % (argname, name) + msg = "field '%s' is required for %s" % (argname, name) emit(' "%s");' % msg, 2, reflow=False) emit('return NULL;', 2) @@ -392,7 +414,7 @@ def simpleSum(self, sum, name): self.funcHeader(name) for t in sum.types: line = ("isinstance = PyObject_IsInstance(obj, " - "(PyObject *)%s_type);") + "astmodulestate_global->%s_type);") self.emit(line % (t.name,), 1) self.emit("if (isinstance == -1) {", 1) self.emit("return 1;", 2) @@ -409,6 +431,7 @@ def buildArgs(self, fields): def complexSum(self, sum, name): self.funcHeader(name) self.emit("PyObject *tmp = NULL;", 1) + self.emit("PyObject *tp;", 1) for a in sum.attributes: self.visitAttributeDeclaration(a, name, sum=sum) self.emit("", 0) @@ -420,8 +443,8 @@ def complexSum(self, sum, name): for a in sum.attributes: self.visitField(a, name, sum=sum, depth=1) for t in sum.types: - line = "isinstance = PyObject_IsInstance(obj, (PyObject*)%s_type);" - self.emit(line % (t.name,), 1) + self.emit("tp = astmodulestate_global->%s_type;" % (t.name,), 1) + self.emit("isinstance = PyObject_IsInstance(obj, tp);", 1) self.emit("if (isinstance == -1) {", 1) self.emit("return 1;", 2) self.emit("}", 1) @@ -497,7 +520,8 @@ def isSimpleType(self, field): def visitField(self, field, name, sum=None, prod=None, depth=0): ctype = get_c_type(field.type) - self.emit("if (lookup_attr_id(obj, &PyId_%s, &tmp) < 0) {" % field.name, depth) + line = "if (_PyObject_LookupAttr(obj, astmodulestate_global->%s, &tmp) < 0) {" + self.emit(line % field.name, depth) self.emit("return 1;", depth+1) self.emit("}", depth) if not field.opt: @@ -524,21 +548,24 @@ def visitField(self, field, name, sum=None, prod=None, depth=0): self.emit("Py_ssize_t i;", depth+1) self.emit("if (!PyList_Check(tmp)) {", depth+1) self.emit("PyErr_Format(PyExc_TypeError, \"%s field \\\"%s\\\" must " - "be a list, not a %%.200s\", tmp->ob_type->tp_name);" % + "be a list, not a %%.200s\", _PyType_Name(Py_TYPE(tmp)));" % (name, field.name), depth+2, reflow=False) self.emit("goto failed;", depth+2) self.emit("}", depth+1) self.emit("len = PyList_GET_SIZE(tmp);", depth+1) if self.isSimpleType(field): - self.emit("%s = _Ta3_asdl_int_seq_new(len, arena);" % field.name, depth+1) + self.emit("%s = _Py_asdl_int_seq_new(len, arena);" % field.name, depth+1) else: - self.emit("%s = _Ta3_asdl_seq_new(len, arena);" % field.name, depth+1) + self.emit("%s = _Py_asdl_seq_new(len, arena);" % field.name, depth+1) self.emit("if (%s == NULL) goto failed;" % field.name, depth+1) self.emit("for (i = 0; i < len; i++) {", depth+1) self.emit("%s val;" % ctype, depth+2) - self.emit("res = obj2ast_%s(PyList_GET_ITEM(tmp, i), &val, arena);" % + self.emit("PyObject *tmp2 = PyList_GET_ITEM(tmp, i);", depth+2) + self.emit("Py_INCREF(tmp2);", depth+2) + self.emit("res = obj2ast_%s(tmp2, &val, arena);" % field.type, depth+2, reflow=False) + self.emit("Py_DECREF(tmp2);", depth+2) self.emit("if (res != 0) goto failed;", depth+2) self.emit("if (len != PyList_GET_SIZE(tmp)) {", depth+2) self.emit("PyErr_SetString(PyExc_RuntimeError, \"%s field \\\"%s\\\" " @@ -571,50 +598,46 @@ def prototype(self, sum, name): class PyTypesDeclareVisitor(PickleVisitor): def visitProduct(self, prod, name): - self.emit("static PyTypeObject *%s_type;" % name, 0) + self.emit_type("%s_type" % name) self.emit("static PyObject* ast2obj_%s(void*);" % name, 0) if prod.attributes: for a in prod.attributes: self.emit_identifier(a.name) - self.emit("static char *%s_attributes[] = {" % name, 0) + self.emit("static const char * const %s_attributes[] = {" % name, 0) for a in prod.attributes: self.emit('"%s",' % a.name, 1) self.emit("};", 0) if prod.fields: for f in prod.fields: self.emit_identifier(f.name) - self.emit("static char *%s_fields[]={" % name,0) + self.emit("static const char * const %s_fields[]={" % name,0) for f in prod.fields: self.emit('"%s",' % f.name, 1) self.emit("};", 0) def visitSum(self, sum, name): - self.emit("static PyTypeObject *%s_type;" % name, 0) + self.emit_type("%s_type" % name) if sum.attributes: for a in sum.attributes: self.emit_identifier(a.name) - self.emit("static char *%s_attributes[] = {" % name, 0) + self.emit("static const char * const %s_attributes[] = {" % name, 0) for a in sum.attributes: self.emit('"%s",' % a.name, 1) self.emit("};", 0) ptype = "void*" if is_simple(sum): ptype = get_c_type(name) - tnames = [] for t in sum.types: - tnames.append(str(t.name)+"_singleton") - tnames = ", *".join(tnames) - self.emit("static PyObject *%s;" % tnames, 0) + self.emit_singleton("%s_singleton" % t.name) self.emit("static PyObject* ast2obj_%s(%s);" % (name, ptype), 0) for t in sum.types: self.visitConstructor(t, name) def visitConstructor(self, cons, name): - self.emit("static PyTypeObject *%s_type;" % cons.name, 0) if cons.fields: for t in cons.fields: self.emit_identifier(t.name) - self.emit("static char *%s_fields[]={" % cons.name, 0) + self.emit("static const char * const %s_fields[]={" % cons.name, 0) for t in cons.fields: self.emit('"%s",' % t.name, 1) self.emit("};",0) @@ -623,8 +646,6 @@ class PyTypesVisitor(PickleVisitor): def visitModule(self, mod): self.emit(""" -_Py_IDENTIFIER(_fields); -_Py_IDENTIFIER(_attributes); typedef struct { PyObject_HEAD @@ -635,9 +656,13 @@ def visitModule(self, mod): ast_dealloc(AST_object *self) { /* bpo-31095: UnTrack is needed before calling any callbacks */ + PyTypeObject *tp = Py_TYPE(self); PyObject_GC_UnTrack(self); Py_CLEAR(self->dict); - Py_TYPE(self)->tp_free(self); + freefunc free_func = PyType_GetSlot(tp, Py_tp_free); + assert(free_func != NULL); + free_func(self); + Py_DECREF(tp); } static int @@ -654,30 +679,13 @@ def visitModule(self, mod): return 0; } -static int lookup_attr_id(PyObject *v, _Py_Identifier *name, PyObject **result) -{ - PyObject *oname = _PyUnicode_FromId(name); /* borrowed */ - if (!oname) { - *result = NULL; - return -1; - } - *result = PyObject_GetAttr(v, oname); - if (*result == NULL) { - if (!PyErr_ExceptionMatches(PyExc_AttributeError)) { - return -1; - } - PyErr_Clear(); - } - return 0; -} - static int ast_type_init(PyObject *self, PyObject *args, PyObject *kw) { Py_ssize_t i, numfields = 0; int res = -1; PyObject *key, *value, *fields; - if (lookup_attr_id((PyObject*)Py_TYPE(self), &PyId__fields, &fields) < 0) { + if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), astmodulestate_global->_fields, &fields) < 0) { goto cleanup; } if (fields) { @@ -690,7 +698,7 @@ def visitModule(self, mod): if (numfields < PyTuple_GET_SIZE(args)) { PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most " "%zd positional argument%s", - Py_TYPE(self)->tp_name, + _PyType_Name(Py_TYPE(self)), numfields, numfields == 1 ? "" : "s"); res = -1; goto cleanup; @@ -724,9 +732,8 @@ def visitModule(self, mod): static PyObject * ast_type_reduce(PyObject *self, PyObject *unused) { - _Py_IDENTIFIER(__dict__); PyObject *dict; - if (lookup_attr_id(self, &PyId___dict__, &dict) < 0) { + if (_PyObject_LookupAttr(self, astmodulestate_global->__dict__, &dict) < 0) { return NULL; } if (dict) { @@ -735,6 +742,11 @@ def visitModule(self, mod): return Py_BuildValue("O()", Py_TYPE(self)); } +static PyMemberDef ast_type_members[] = { + {"__dictoffset__", T_PYSSIZET, offsetof(AST_object, dict), READONLY}, + {NULL} /* Sentinel */ +}; + static PyMethodDef ast_type_methods[] = { {"__reduce__", ast_type_reduce, METH_NOARGS, NULL}, {NULL} @@ -745,89 +757,71 @@ def visitModule(self, mod): {NULL} }; -static PyTypeObject AST_type = { - PyVarObject_HEAD_INIT(NULL, 0) - "typed_ast._ast3.AST", +static PyType_Slot AST_type_slots[] = { + {Py_tp_dealloc, ast_dealloc}, + {Py_tp_getattro, PyObject_GenericGetAttr}, + {Py_tp_setattro, PyObject_GenericSetAttr}, + {Py_tp_traverse, ast_traverse}, + {Py_tp_clear, ast_clear}, + {Py_tp_members, ast_type_members}, + {Py_tp_methods, ast_type_methods}, + {Py_tp_getset, ast_type_getsets}, + {Py_tp_init, ast_type_init}, + {Py_tp_alloc, PyType_GenericAlloc}, + {Py_tp_new, PyType_GenericNew}, + {Py_tp_free, PyObject_GC_Del}, + {0, 0}, +}; + +static PyType_Spec AST_type_spec = { + "ast.AST", sizeof(AST_object), 0, - (destructor)ast_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - PyObject_GenericGetAttr, /* tp_getattro */ - PyObject_GenericSetAttr, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */ - 0, /* tp_doc */ - (traverseproc)ast_traverse, /* tp_traverse */ - (inquiry)ast_clear, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - ast_type_methods, /* tp_methods */ - 0, /* tp_members */ - ast_type_getsets, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - offsetof(AST_object, dict),/* tp_dictoffset */ - (initproc)ast_type_init, /* tp_init */ - PyType_GenericAlloc, /* tp_alloc */ - PyType_GenericNew, /* tp_new */ - PyObject_GC_Del, /* tp_free */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, + AST_type_slots }; - -static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields) +static PyObject * +make_type(const char *type, PyObject* base, const char* const* fields, int num_fields, const char *doc) { - _Py_IDENTIFIER(__module__); - _Py_static_string(PyId_typed_ast_ast3, "typed_ast._ast3"); PyObject *fnames, *result; int i; fnames = PyTuple_New(num_fields); if (!fnames) return NULL; for (i = 0; i < num_fields; i++) { - PyObject *field = PyUnicode_FromString(fields[i]); + PyObject *field = PyUnicode_InternFromString(fields[i]); if (!field) { Py_DECREF(fnames); return NULL; } PyTuple_SET_ITEM(fnames, i, field); } - result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOO}", + result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOOOs}", type, base, - _PyUnicode_FromId(&PyId__fields), fnames, - _PyUnicode_FromId(&PyId___module__), - _PyUnicode_FromId(&PyId_typed_ast_ast3)); + astmodulestate_global->_fields, fnames, + astmodulestate_global->__module__, + astmodulestate_global->ast, + astmodulestate_global->__doc__, doc); Py_DECREF(fnames); - return (PyTypeObject*)result; + return result; } -static int add_attributes(PyTypeObject* type, char**attrs, int num_fields) +static int +add_attributes(PyObject *type, const char * const *attrs, int num_fields) { int i, result; PyObject *s, *l = PyTuple_New(num_fields); if (!l) return 0; for (i = 0; i < num_fields; i++) { - s = PyUnicode_FromString(attrs[i]); + s = PyUnicode_InternFromString(attrs[i]); if (!s) { Py_DECREF(l); return 0; } PyTuple_SET_ITEM(l, i, s); } - result = _PyObject_SetAttrId((PyObject*)type, &PyId__attributes, l) >= 0; + result = PyObject_SetAttr(type, astmodulestate_global->_attributes, l) >= 0; Py_DECREF(l); return result; } @@ -859,11 +853,9 @@ def visitModule(self, mod): Py_INCREF((PyObject*)o); return (PyObject*)o; } -#define ast2obj_singleton ast2obj_object #define ast2obj_constant ast2obj_object #define ast2obj_identifier ast2obj_object #define ast2obj_string ast2obj_object -#define ast2obj_bytes ast2obj_object static PyObject* ast2obj_int(long b) { @@ -872,17 +864,6 @@ def visitModule(self, mod): /* Conversion Python -> AST */ -static int obj2ast_singleton(PyObject *obj, PyObject** out, PyArena* arena) -{ - if (obj != Py_None && obj != Py_True && obj != Py_False) { - PyErr_SetString(PyExc_ValueError, - "AST singleton must be True, False, or None"); - return 1; - } - *out = obj; - return 0; -} - static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) { if (obj == Py_None) @@ -900,13 +881,11 @@ def visitModule(self, mod): static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena) { - if (obj) { - if (PyArena_AddPyObject(arena, obj) < 0) { - *out = NULL; - return -1; - } - Py_INCREF(obj); + if (PyArena_AddPyObject(arena, obj) < 0) { + *out = NULL; + return -1; } + Py_INCREF(obj); *out = obj; return 0; } @@ -929,15 +908,6 @@ def visitModule(self, mod): return obj2ast_object(obj, out, arena); } -static int obj2ast_bytes(PyObject* obj, PyObject** out, PyArena* arena) -{ - if (!PyBytes_CheckExact(obj)) { - PyErr_SetString(PyExc_TypeError, "AST bytes must be of type bytes"); - return 1; - } - return obj2ast_object(obj, out, arena); -} - static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) { int i; @@ -955,14 +925,11 @@ def visitModule(self, mod): static int add_ast_fields(void) { - PyObject *empty_tuple, *d; - if (PyType_Ready(&AST_type) < 0) - return -1; - d = AST_type.tp_dict; + PyObject *empty_tuple; empty_tuple = PyTuple_New(0); if (!empty_tuple || - _PyDict_SetItemId(d, &PyId__fields, empty_tuple) < 0 || - _PyDict_SetItemId(d, &PyId__attributes, empty_tuple) < 0) { + PyObject_SetAttrString(astmodulestate_global->AST_type, "_fields", empty_tuple) < 0 || + PyObject_SetAttrString(astmodulestate_global->AST_type, "_attributes", empty_tuple) < 0) { Py_XDECREF(empty_tuple); return -1; } @@ -974,12 +941,21 @@ def visitModule(self, mod): self.emit("static int init_types(void)",0) self.emit("{", 0) - self.emit("static int initialized;", 1) - self.emit("if (initialized) return 1;", 1) + self.emit("PyObject *m;", 1) + self.emit("if (PyState_FindModule(&_astmodule) == NULL) {", 1) + self.emit("m = PyModule_Create(&_astmodule);", 2) + self.emit("if (!m) return 0;", 2) + self.emit("PyState_AddModule(m, &_astmodule);", 2) + self.emit("}", 1) + self.emit("astmodulestate *state = astmodulestate_global;", 1) + self.emit("if (state->initialized) return 1;", 1) + self.emit("if (init_identifiers() < 0) return 0;", 1) + self.emit("state->AST_type = PyType_FromSpec(&AST_type_spec);", 1) + self.emit("if (!state->AST_type) return 0;", 1) self.emit("if (add_ast_fields() < 0) return 0;", 1) for dfn in mod.dfns: self.visit(dfn) - self.emit("initialized = 1;", 1) + self.emit("state->initialized = 1;", 1) self.emit("return 1;", 1); self.emit("}", 0) @@ -988,24 +964,32 @@ def visitProduct(self, prod, name): fields = name+"_fields" else: fields = "NULL" - self.emit('%s_type = make_type("%s", &AST_type, %s, %d);' % + self.emit('state->%s_type = make_type("%s", state->AST_type, %s, %d,' % (name, name, fields, len(prod.fields)), 1) - self.emit("if (!%s_type) return 0;" % name, 1) + self.emit('%s);' % reflow_c_string(asdl_of(name, prod), 2), 2, reflow=False) + self.emit("if (!state->%s_type) return 0;" % name, 1) + self.emit_type("AST_type") + self.emit_type("%s_type" % name) if prod.attributes: - self.emit("if (!add_attributes(%s_type, %s_attributes, %d)) return 0;" % + self.emit("if (!add_attributes(state->%s_type, %s_attributes, %d)) return 0;" % (name, name, len(prod.attributes)), 1) else: - self.emit("if (!add_attributes(%s_type, NULL, 0)) return 0;" % name, 1) + self.emit("if (!add_attributes(state->%s_type, NULL, 0)) return 0;" % name, 1) + self.emit_defaults(name, prod.fields, 1) + self.emit_defaults(name, prod.attributes, 1) def visitSum(self, sum, name): - self.emit('%s_type = make_type("%s", &AST_type, NULL, 0);' % + self.emit('state->%s_type = make_type("%s", state->AST_type, NULL, 0,' % (name, name), 1) - self.emit("if (!%s_type) return 0;" % name, 1) + self.emit('%s);' % reflow_c_string(asdl_of(name, sum), 2), 2, reflow=False) + self.emit_type("%s_type" % name) + self.emit("if (!state->%s_type) return 0;" % name, 1) if sum.attributes: - self.emit("if (!add_attributes(%s_type, %s_attributes, %d)) return 0;" % + self.emit("if (!add_attributes(state->%s_type, %s_attributes, %d)) return 0;" % (name, name, len(sum.attributes)), 1) else: - self.emit("if (!add_attributes(%s_type, NULL, 0)) return 0;" % name, 1) + self.emit("if (!add_attributes(state->%s_type, NULL, 0)) return 0;" % name, 1) + self.emit_defaults(name, sum.attributes, 1) simple = is_simple(sum) for t in sum.types: self.visitConstructor(t, name, simple) @@ -1015,40 +999,55 @@ def visitConstructor(self, cons, name, simple): fields = cons.name+"_fields" else: fields = "NULL" - self.emit('%s_type = make_type("%s", %s_type, %s, %d);' % + self.emit('state->%s_type = make_type("%s", state->%s_type, %s, %d,' % (cons.name, cons.name, name, fields, len(cons.fields)), 1) - self.emit("if (!%s_type) return 0;" % cons.name, 1) + self.emit('%s);' % reflow_c_string(asdl_of(cons.name, cons), 2), 2, reflow=False) + self.emit("if (!state->%s_type) return 0;" % cons.name, 1) + self.emit_type("%s_type" % cons.name) + self.emit_defaults(cons.name, cons.fields, 1) if simple: - self.emit("%s_singleton = PyType_GenericNew(%s_type, NULL, NULL);" % + self.emit("state->%s_singleton = PyType_GenericNew((PyTypeObject *)" + "state->%s_type, NULL, NULL);" % (cons.name, cons.name), 1) - self.emit("if (!%s_singleton) return 0;" % cons.name, 1) + self.emit("if (!state->%s_singleton) return 0;" % cons.name, 1) + + def emit_defaults(self, name, fields, depth): + for field in fields: + if field.opt: + self.emit('if (PyObject_SetAttr(state->%s_type, state->%s, Py_None) == -1)' % + (name, field.name), depth) + self.emit("return 0;", depth+1) class ASTModuleVisitor(PickleVisitor): def visitModule(self, mod): - self.emit("PyObject *ast3_parse(PyObject *self, PyObject *args);", 0) - self.emit("static PyMethodDef ast3_methods[] = {", 0) - self.emit(' {"_parse", ast3_parse, METH_VARARGS, "Parse string into typed AST."},', 0) - self.emit(" {NULL, NULL, 0, NULL}", 0) - self.emit("};", 0) - self.emit("static struct PyModuleDef _astmodule = {", 0) - self.emit(' PyModuleDef_HEAD_INIT, "_ast3", NULL, 0, ast3_methods', 0) - self.emit("};", 0) self.emit("PyMODINIT_FUNC", 0) - self.emit("PyInit__ast3(void)", 0) + self.emit("PyInit__ast(void)", 0) self.emit("{", 0) - self.emit("PyObject *m, *d;", 1) + self.emit("PyObject *m;", 1) self.emit("if (!init_types()) return NULL;", 1) - self.emit('m = PyModule_Create(&_astmodule);', 1) + self.emit('m = PyState_FindModule(&_astmodule);', 1) self.emit("if (!m) return NULL;", 1) - self.emit("d = PyModule_GetDict(m);", 1) - self.emit('if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return NULL;', 1) - self.emit('if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0)', 1) - self.emit("return NULL;", 2) + self.emit('if (PyModule_AddObject(m, "AST", astmodulestate_global->AST_type) < 0) {', 1) + self.emit('goto error;', 2) + self.emit('}', 1) + self.emit('Py_INCREF(astmodulestate(m)->AST_type);', 1) + self.emit('if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) {', 1) + self.emit("goto error;", 2) + self.emit('}', 1) + self.emit('if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) {', 1) + self.emit("goto error;", 2) + self.emit('}', 1) + self.emit('if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) {', 1) + self.emit("goto error;", 2) + self.emit('}', 1) for dfn in mod.dfns: self.visit(dfn) self.emit("return m;", 1) + self.emit("error:", 0) + self.emit("Py_DECREF(m);", 1) + self.emit("return NULL;", 1) self.emit("}", 0) def visitProduct(self, prod, name): @@ -1063,7 +1062,11 @@ def visitConstructor(self, cons, name): self.addObj(cons.name) def addObj(self, name): - self.emit('if (PyDict_SetItemString(d, "%s", (PyObject*)%s_type) < 0) return NULL;' % (name, name), 1) + self.emit("if (PyModule_AddObject(m, \"%s\", " + "astmodulestate_global->%s_type) < 0) {" % (name, name), 1) + self.emit("goto error;", 2) + self.emit('}', 1) + self.emit("Py_INCREF(astmodulestate(m)->%s_type);" % name, 1) _SPECIALIZED_SEQUENCES = ('stmt', 'expr') @@ -1101,6 +1104,7 @@ def func_begin(self, name): self.emit("{", 0) self.emit("%s o = (%s)_o;" % (ctype, ctype), 1) self.emit("PyObject *result = NULL, *value = NULL;", 1) + self.emit("PyTypeObject *tp;", 1) self.emit('if (!o) {', 1) self.emit("Py_RETURN_NONE;", 2) self.emit("}", 1) @@ -1128,7 +1132,7 @@ def visitSum(self, sum, name): for a in sum.attributes: self.emit("value = ast2obj_%s(o->%s);" % (a.type, a.name), 1) self.emit("if (!value) goto failed;", 1) - self.emit('if (_PyObject_SetAttrId(result, &PyId_%s, value) < 0)' % a.name, 1) + self.emit('if (PyObject_SetAttr(result, astmodulestate_global->%s, value) < 0)' % a.name, 1) self.emit('goto failed;', 2) self.emit('Py_DECREF(value);', 1) self.func_end() @@ -1139,33 +1143,31 @@ def simpleSum(self, sum, name): self.emit("switch(o) {", 1) for t in sum.types: self.emit("case %s:" % t.name, 2) - self.emit("Py_INCREF(%s_singleton);" % t.name, 3) - self.emit("return %s_singleton;" % t.name, 3) - self.emit("default:", 2) - self.emit('/* should never happen, but just in case ... */', 3) - code = "PyErr_Format(PyExc_SystemError, \"unknown %s found\");" % name - self.emit(code, 3, reflow=False) - self.emit("return NULL;", 3) + self.emit("Py_INCREF(astmodulestate_global->%s_singleton);" % t.name, 3) + self.emit("return astmodulestate_global->%s_singleton;" % t.name, 3) self.emit("}", 1) + self.emit("Py_UNREACHABLE();", 1); self.emit("}", 0) def visitProduct(self, prod, name): self.func_begin(name) - self.emit("result = PyType_GenericNew(%s_type, NULL, NULL);" % name, 1); + self.emit("tp = (PyTypeObject *)astmodulestate_global->%s_type;" % name, 1) + self.emit("result = PyType_GenericNew(tp, NULL, NULL);", 1); self.emit("if (!result) return NULL;", 1) for field in prod.fields: self.visitField(field, name, 1, True) for a in prod.attributes: self.emit("value = ast2obj_%s(o->%s);" % (a.type, a.name), 1) self.emit("if (!value) goto failed;", 1) - self.emit('if (_PyObject_SetAttrId(result, &PyId_%s, value) < 0)' % a.name, 1) + self.emit("if (PyObject_SetAttr(result, astmodulestate_global->%s, value) < 0)" % a.name, 1) self.emit('goto failed;', 2) self.emit('Py_DECREF(value);', 1) self.func_end() def visitConstructor(self, cons, enum, name): self.emit("case %s_kind:" % cons.name, 1) - self.emit("result = PyType_GenericNew(%s_type, NULL, NULL);" % cons.name, 2); + self.emit("tp = (PyTypeObject *)astmodulestate_global->%s_type;" % cons.name, 2) + self.emit("result = PyType_GenericNew(tp, NULL, NULL);", 2); self.emit("if (!result) goto failed;", 2) for f in cons.fields: self.visitField(f, cons.name, 2, False) @@ -1180,7 +1182,7 @@ def emit(s, d): value = "o->v.%s.%s" % (name, field.name) self.set(field, value, depth) emit("if (!value) goto failed;", 0) - emit('if (_PyObject_SetAttrId(result, &PyId_%s, value) == -1)' % field.name, 0) + emit("if (PyObject_SetAttr(result, astmodulestate_global->%s, value) == -1)" % field.name, 0) emit("goto failed;", 1) emit("Py_DECREF(value);", 0) @@ -1221,7 +1223,7 @@ def set(self, field, value, depth): class PartingShots(StaticVisitor): CODE = """ -PyObject* Ta3AST_mod2obj(mod_ty t) +PyObject* PyAST_mod2obj(mod_ty t) { if (!init_types()) return NULL; @@ -1229,16 +1231,19 @@ class PartingShots(StaticVisitor): } /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ -mod_ty Ta3AST_obj2mod(PyObject* ast, PyArena* arena, int mode) +mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) { - mod_ty res; PyObject *req_type[3]; - char *req_name[] = {"Module", "Expression", "Interactive"}; + const char * const req_name[] = {"Module", "Expression", "Interactive"}; int isinstance; - req_type[0] = (PyObject*)Module_type; - req_type[1] = (PyObject*)Expression_type; - req_type[2] = (PyObject*)Interactive_type; + if (PySys_Audit("compile", "OO", ast, Py_None) < 0) { + return NULL; + } + + req_type[0] = astmodulestate_global->Module_type; + req_type[1] = astmodulestate_global->Expression_type; + req_type[2] = astmodulestate_global->Interactive_type; assert(0 <= mode && mode <= 2); @@ -1250,20 +1255,22 @@ class PartingShots(StaticVisitor): return NULL; if (!isinstance) { PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", - req_name[mode], Py_TYPE(ast)->tp_name); + req_name[mode], _PyType_Name(Py_TYPE(ast))); return NULL; } + + mod_ty res = NULL; if (obj2ast_mod(ast, &res, arena) != 0) return NULL; else return res; } -int Ta3AST_Check(PyObject* obj) +int PyAST_Check(PyObject* obj) { if (!init_types()) return -1; - return PyObject_IsInstance(obj, (PyObject*)&AST_type); + return PyObject_IsInstance(obj, astmodulestate_global->AST_type); } """ @@ -1276,12 +1283,100 @@ def visit(self, object): v.visit(object) v.emit("", 0) + +def generate_module_def(f, mod): + # Gather all the data needed for ModuleSpec + visitor_list = set() + with open(os.devnull, "w") as devnull: + visitor = PyTypesDeclareVisitor(devnull) + visitor.visit(mod) + visitor_list.add(visitor) + visitor = PyTypesVisitor(devnull) + visitor.visit(mod) + visitor_list.add(visitor) + + state_strings = { + "ast", + "_fields", + "__doc__", + "__dict__", + "__module__", + "_attributes", + } + module_state = state_strings.copy() + for visitor in visitor_list: + for identifier in visitor.identifiers: + module_state.add(identifier) + state_strings.add(identifier) + for singleton in visitor.singletons: + module_state.add(singleton) + for tp in visitor.types: + module_state.add(tp) + state_strings = sorted(state_strings) + module_state = sorted(module_state) + f.write('typedef struct {\n') + f.write(' int initialized;\n') + for s in module_state: + f.write(' PyObject *' + s + ';\n') + f.write('} astmodulestate;\n\n') + f.write(""" +#define astmodulestate(o) ((astmodulestate *)PyModule_GetState(o)) + +static int astmodule_clear(PyObject *module) +{ +""") + for s in module_state: + f.write(" Py_CLEAR(astmodulestate(module)->" + s + ');\n') + f.write(""" + return 0; +} + +static int astmodule_traverse(PyObject *module, visitproc visit, void* arg) +{ +""") + for s in module_state: + f.write(" Py_VISIT(astmodulestate(module)->" + s + ');\n') + f.write(""" + return 0; +} + +static void astmodule_free(void* module) { + astmodule_clear((PyObject*)module); +} + +static struct PyModuleDef _astmodule = { + PyModuleDef_HEAD_INIT, + "_ast", + NULL, + sizeof(astmodulestate), + NULL, + NULL, + astmodule_traverse, + astmodule_clear, + astmodule_free, +}; + +#define astmodulestate_global ((astmodulestate *)PyModule_GetState(PyState_FindModule(&_astmodule))) + +""") + f.write('static int init_identifiers(void)\n') + f.write('{\n') + f.write(' astmodulestate *state = astmodulestate_global;\n') + for identifier in state_strings: + f.write(' if ((state->' + identifier) + f.write(' = PyUnicode_InternFromString("') + f.write(identifier + '")) == NULL) return 0;\n') + f.write(' return 1;\n') + f.write('};\n\n') + + common_msg = "/* File automatically generated by %s. */\n\n" def main(srcfile, dump_module=False): argv0 = sys.argv[0] components = argv0.split(os.sep) - argv0 = os.sep.join(components[-2:]) + # Always join with '/' so different OS does not keep changing the file + argv0 = '/'.join(components[-2:]) auto_gen_msg = common_msg % argv0 mod = asdl.parse(srcfile) if dump_module: @@ -1292,15 +1387,33 @@ def main(srcfile, dump_module=False): if H_FILE: with open(H_FILE, "w") as f: f.write(auto_gen_msg) - f.write('#include "asdl.h"\n\n') + f.write('#ifndef Py_PYTHON_AST_H\n') + f.write('#define Py_PYTHON_AST_H\n') + f.write('#ifdef __cplusplus\n') + f.write('extern "C" {\n') + f.write('#endif\n') + f.write('\n') + f.write('#ifndef Py_LIMITED_API\n') + f.write('#include "asdl.h"\n') + f.write('\n') + f.write('#undef Yield /* undefine macro conflicting with */\n') + f.write('\n') c = ChainOfVisitors(TypeDefVisitor(f), - StructVisitor(f), - PrototypeVisitor(f), - ) + StructVisitor(f)) + c.visit(mod) - f.write("PyObject* Ta3AST_mod2obj(mod_ty t);\n") - f.write("mod_ty Ta3AST_obj2mod(PyObject* ast, PyArena* arena, int mode);\n") - f.write("int Ta3AST_Check(PyObject* obj);\n") + f.write("// Note: these macros affect function definitions, not only call sites.\n") + PrototypeVisitor(f).visit(mod) + f.write("\n") + f.write("PyObject* PyAST_mod2obj(mod_ty t);\n") + f.write("mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode);\n") + f.write("int PyAST_Check(PyObject* obj);\n") + f.write("#endif /* !Py_LIMITED_API */\n") + f.write('\n') + f.write('#ifdef __cplusplus\n') + f.write('}\n') + f.write('#endif\n') + f.write('#endif /* !Py_PYTHON_AST_H */\n') if C_FILE: with open(C_FILE, "w") as f: @@ -1309,8 +1422,11 @@ def main(srcfile, dump_module=False): f.write('\n') f.write('#include "Python.h"\n') f.write('#include "%s-ast.h"\n' % mod.name) + f.write('#include "structmember.h" // PyMemberDef\n') f.write('\n') - f.write("static PyTypeObject AST_type;\n") + + generate_module_def(f, mod) + v = ChainOfVisitors( PyTypesDeclareVisitor(f), PyTypesVisitor(f), @@ -1333,9 +1449,9 @@ def main(srcfile, dump_module=False): for o, v in opts: if o == '-h': H_FILE = v - if o == '-c': + elif o == '-c': C_FILE = v - if o == '-d': + elif o == '-d': dump_module = True if H_FILE and C_FILE: print('Must specify exactly one output file') diff --git a/ast3/Parser/bitset.c b/ast3/Parser/bitset.c deleted file mode 100644 index 049c2665..00000000 --- a/ast3/Parser/bitset.c +++ /dev/null @@ -1,66 +0,0 @@ - -/* Bitset primitives used by the parser generator */ - -#include "../Include/pgenheaders.h" -#include "../Include/bitset.h" - -bitset -newbitset(int nbits) -{ - int nbytes = NBYTES(nbits); - bitset ss = (char *)PyObject_MALLOC(sizeof(BYTE) * nbytes); - - if (ss == NULL) - Py_FatalError("no mem for bitset"); - - ss += nbytes; - while (--nbytes >= 0) - *--ss = 0; - return ss; -} - -void -delbitset(bitset ss) -{ - PyObject_FREE(ss); -} - -int -addbit(bitset ss, int ibit) -{ - int ibyte = BIT2BYTE(ibit); - BYTE mask = BIT2MASK(ibit); - - if (ss[ibyte] & mask) - return 0; /* Bit already set */ - ss[ibyte] |= mask; - return 1; -} - -#if 0 /* Now a macro */ -int -testbit(bitset ss, int ibit) -{ - return (ss[BIT2BYTE(ibit)] & BIT2MASK(ibit)) != 0; -} -#endif - -int -samebitset(bitset ss1, bitset ss2, int nbits) -{ - int i; - - for (i = NBYTES(nbits); --i >= 0; ) - if (*ss1++ != *ss2++) - return 0; - return 1; -} - -void -mergebitset(bitset ss1, bitset ss2, int nbits) -{ - int i; - - for (i = NBYTES(nbits); --i >= 0; ) - *ss1++ |= *ss2++; -} diff --git a/ast3/Parser/grammar.c b/ast3/Parser/grammar.c deleted file mode 100644 index 1c79204d..00000000 --- a/ast3/Parser/grammar.c +++ /dev/null @@ -1,273 +0,0 @@ - -/* Grammar implementation */ - -#include "Python.h" -#include "../Include/pgenheaders.h" - -#include - -#include "../Include/token.h" -#include "../Include/grammar.h" - -PyAPI_DATA(int) Py_DebugFlag; - -grammar * -newgrammar(int start) -{ - grammar *g; - - g = (grammar *)PyObject_MALLOC(sizeof(grammar)); - if (g == NULL) - Py_FatalError("no mem for new grammar"); - g->g_ndfas = 0; - g->g_dfa = NULL; - g->g_start = start; - g->g_ll.ll_nlabels = 0; - g->g_ll.ll_label = NULL; - g->g_accel = 0; - return g; -} - -void -freegrammar(grammar *g) -{ - int i, j; - for (i = 0; i < g->g_ndfas; i++) { - free(g->g_dfa[i].d_name); - for (j = 0; j < g->g_dfa[i].d_nstates; j++) - PyObject_FREE(g->g_dfa[i].d_state[j].s_arc); - PyObject_FREE(g->g_dfa[i].d_state); - } - PyObject_FREE(g->g_dfa); - for (i = 0; i < g->g_ll.ll_nlabels; i++) - free(g->g_ll.ll_label[i].lb_str); - PyObject_FREE(g->g_ll.ll_label); - PyObject_FREE(g); -} - -dfa * -adddfa(grammar *g, int type, const char *name) -{ - dfa *d; - - g->g_dfa = (dfa *)PyObject_REALLOC(g->g_dfa, - sizeof(dfa) * (g->g_ndfas + 1)); - if (g->g_dfa == NULL) - Py_FatalError("no mem to resize dfa in adddfa"); - d = &g->g_dfa[g->g_ndfas++]; - d->d_type = type; - d->d_name = strdup(name); - d->d_nstates = 0; - d->d_state = NULL; - d->d_initial = -1; - d->d_first = NULL; - return d; /* Only use while fresh! */ -} - -int -addstate(dfa *d) -{ - state *s; - - d->d_state = (state *)PyObject_REALLOC(d->d_state, - sizeof(state) * (d->d_nstates + 1)); - if (d->d_state == NULL) - Py_FatalError("no mem to resize state in addstate"); - s = &d->d_state[d->d_nstates++]; - s->s_narcs = 0; - s->s_arc = NULL; - s->s_lower = 0; - s->s_upper = 0; - s->s_accel = NULL; - s->s_accept = 0; - return Py_SAFE_DOWNCAST(s - d->d_state, intptr_t, int); -} - -void -addarc(dfa *d, int from, int to, int lbl) -{ - state *s; - arc *a; - - assert(0 <= from && from < d->d_nstates); - assert(0 <= to && to < d->d_nstates); - - s = &d->d_state[from]; - s->s_arc = (arc *)PyObject_REALLOC(s->s_arc, sizeof(arc) * (s->s_narcs + 1)); - if (s->s_arc == NULL) - Py_FatalError("no mem to resize arc list in addarc"); - a = &s->s_arc[s->s_narcs++]; - a->a_lbl = lbl; - a->a_arrow = to; -} - -int -addlabel(labellist *ll, int type, const char *str) -{ - int i; - label *lb; - - for (i = 0; i < ll->ll_nlabels; i++) { - if (ll->ll_label[i].lb_type == type && - strcmp(ll->ll_label[i].lb_str, str) == 0) - return i; - } - ll->ll_label = (label *)PyObject_REALLOC(ll->ll_label, - sizeof(label) * (ll->ll_nlabels + 1)); - if (ll->ll_label == NULL) - Py_FatalError("no mem to resize labellist in addlabel"); - lb = &ll->ll_label[ll->ll_nlabels++]; - lb->lb_type = type; - lb->lb_str = strdup(str); - if (Py_DebugFlag) - printf("Label @ %8p, %d: %s\n", ll, ll->ll_nlabels, - Ta3Grammar_LabelRepr(lb)); - return Py_SAFE_DOWNCAST(lb - ll->ll_label, intptr_t, int); -} - -/* Same, but rather dies than adds */ - -int -findlabel(labellist *ll, int type, const char *str) -{ - int i; - - for (i = 0; i < ll->ll_nlabels; i++) { - if (ll->ll_label[i].lb_type == type /*&& - strcmp(ll->ll_label[i].lb_str, str) == 0*/) - return i; - } - fprintf(stderr, "Label %d/'%s' not found\n", type, str); - Py_FatalError("grammar.c:findlabel()"); - - /* Py_FatalError() is declared with __attribute__((__noreturn__)). - GCC emits a warning without "return 0;" (compiler bug!), but Clang is - smarter and emits a warning on the return... */ -#ifndef __clang__ - return 0; /* Make gcc -Wall happy */ -#endif -} - -/* Forward */ -static void translabel(grammar *, label *); - -void -translatelabels(grammar *g) -{ - int i; - -#ifdef Py_DEBUG - printf("Translating labels ...\n"); -#endif - /* Don't translate EMPTY */ - for (i = EMPTY+1; i < g->g_ll.ll_nlabels; i++) - translabel(g, &g->g_ll.ll_label[i]); -} - -static void -translabel(grammar *g, label *lb) -{ - int i; - - if (Py_DebugFlag) - printf("Translating label %s ...\n", Ta3Grammar_LabelRepr(lb)); - - if (lb->lb_type == NAME) { - for (i = 0; i < g->g_ndfas; i++) { - if (strcmp(lb->lb_str, g->g_dfa[i].d_name) == 0) { - if (Py_DebugFlag) - printf( - "Label %s is non-terminal %d.\n", - lb->lb_str, - g->g_dfa[i].d_type); - lb->lb_type = g->g_dfa[i].d_type; - free(lb->lb_str); - lb->lb_str = NULL; - return; - } - } - for (i = 0; i < (int)N_TOKENS; i++) { - if (strcmp(lb->lb_str, _Ta3Parser_TokenNames[i]) == 0) { - if (Py_DebugFlag) - printf("Label %s is terminal %d.\n", - lb->lb_str, i); - lb->lb_type = i; - free(lb->lb_str); - lb->lb_str = NULL; - return; - } - } - printf("Can't translate NAME label '%s'\n", lb->lb_str); - return; - } - - if (lb->lb_type == STRING) { - if (isalpha(Py_CHARMASK(lb->lb_str[1])) || - lb->lb_str[1] == '_') { - char *p; - char *src; - char *dest; - size_t name_len; - if (Py_DebugFlag) - printf("Label %s is a keyword\n", lb->lb_str); - lb->lb_type = NAME; - src = lb->lb_str + 1; - p = strchr(src, '\''); - if (p) - name_len = p - src; - else - name_len = strlen(src); - dest = (char *)malloc(name_len + 1); - if (!dest) { - printf("Can't alloc dest '%s'\n", src); - return; - } - strncpy(dest, src, name_len); - dest[name_len] = '\0'; - free(lb->lb_str); - lb->lb_str = dest; - } - else if (lb->lb_str[2] == lb->lb_str[0]) { - int type = (int) Ta3Token_OneChar(lb->lb_str[1]); - if (type != OP) { - lb->lb_type = type; - free(lb->lb_str); - lb->lb_str = NULL; - } - else - printf("Unknown OP label %s\n", - lb->lb_str); - } - else if (lb->lb_str[2] && lb->lb_str[3] == lb->lb_str[0]) { - int type = (int) Ta3Token_TwoChars(lb->lb_str[1], - lb->lb_str[2]); - if (type != OP) { - lb->lb_type = type; - free(lb->lb_str); - lb->lb_str = NULL; - } - else - printf("Unknown OP label %s\n", - lb->lb_str); - } - else if (lb->lb_str[2] && lb->lb_str[3] && lb->lb_str[4] == lb->lb_str[0]) { - int type = (int) Ta3Token_ThreeChars(lb->lb_str[1], - lb->lb_str[2], - lb->lb_str[3]); - if (type != OP) { - lb->lb_type = type; - free(lb->lb_str); - lb->lb_str = NULL; - } - else - printf("Unknown OP label %s\n", - lb->lb_str); - } - else - printf("Can't translate STRING label %s\n", - lb->lb_str); - } - else - printf("Can't translate label '%s'\n", - Ta3Grammar_LabelRepr(lb)); -} diff --git a/ast3/Parser/grammar1.c b/ast3/Parser/grammar1.c deleted file mode 100644 index 8c48fb04..00000000 --- a/ast3/Parser/grammar1.c +++ /dev/null @@ -1,60 +0,0 @@ - -/* Grammar subroutines needed by parser */ - -#include "Python.h" -#include "../Include/pgenheaders.h" -#include "../Include/grammar.h" -#include "../Include/token.h" - -/* Return the DFA for the given type */ - -dfa * -Ta3Grammar_FindDFA(grammar *g, int type) -{ - dfa *d; -#if 1 - /* Massive speed-up */ - d = &g->g_dfa[type - NT_OFFSET]; - assert(d->d_type == type); - return d; -#else - /* Old, slow version */ - int i; - - for (i = g->g_ndfas, d = g->g_dfa; --i >= 0; d++) { - if (d->d_type == type) - return d; - } - abort(); -#endif -} - -const char * -Ta3Grammar_LabelRepr(label *lb) -{ - static char buf[100]; - - if (lb->lb_type == ENDMARKER) - return "EMPTY"; - else if (ISNONTERMINAL(lb->lb_type)) { - if (lb->lb_str == NULL) { - PyOS_snprintf(buf, sizeof(buf), "NT%d", lb->lb_type); - return buf; - } - else - return lb->lb_str; - } - else if (lb->lb_type < N_TOKENS) { - if (lb->lb_str == NULL) - return _Ta3Parser_TokenNames[lb->lb_type]; - else { - PyOS_snprintf(buf, sizeof(buf), "%.32s(%.32s)", - _Ta3Parser_TokenNames[lb->lb_type], lb->lb_str); - return buf; - } - } - else { - Py_FatalError("invalid label"); - return NULL; - } -} diff --git a/ast3/Parser/node.c b/ast3/Parser/node.c deleted file mode 100644 index 845eca62..00000000 --- a/ast3/Parser/node.c +++ /dev/null @@ -1,164 +0,0 @@ -/* Parse tree node implementation */ - -#include "Python.h" -#include "../Include/node.h" -#include "../Include/errcode.h" - -node * -Ta3Node_New(int type) -{ - node *n = (node *) PyObject_MALLOC(1 * sizeof(node)); - if (n == NULL) - return NULL; - n->n_type = type; - n->n_str = NULL; - n->n_lineno = 0; - n->n_nchildren = 0; - n->n_child = NULL; - return n; -} - -/* See comments at XXXROUNDUP below. Returns -1 on overflow. */ -static int -fancy_roundup(int n) -{ - /* Round up to the closest power of 2 >= n. */ - int result = 256; - assert(n > 128); - while (result < n) { - result <<= 1; - if (result <= 0) - return -1; - } - return result; -} - -/* A gimmick to make massive numbers of reallocs quicker. The result is - * a number >= the input. In Ta3Node_AddChild, it's used like so, when - * we're about to add child number current_size + 1: - * - * if XXXROUNDUP(current_size) < XXXROUNDUP(current_size + 1): - * allocate space for XXXROUNDUP(current_size + 1) total children - * else: - * we already have enough space - * - * Since a node starts out empty, we must have - * - * XXXROUNDUP(0) < XXXROUNDUP(1) - * - * so that we allocate space for the first child. One-child nodes are very - * common (presumably that would change if we used a more abstract form - * of syntax tree), so to avoid wasting memory it's desirable that - * XXXROUNDUP(1) == 1. That in turn forces XXXROUNDUP(0) == 0. - * - * Else for 2 <= n <= 128, we round up to the closest multiple of 4. Why 4? - * Rounding up to a multiple of an exact power of 2 is very efficient, and - * most nodes with more than one child have <= 4 kids. - * - * Else we call fancy_roundup() to grow proportionately to n. We've got an - * extreme case then (like test_longexp.py), and on many platforms doing - * anything less than proportional growth leads to exorbitant runtime - * (e.g., MacPython), or extreme fragmentation of user address space (e.g., - * Win98). - * - * In a run of compileall across the 2.3a0 Lib directory, Andrew MacIntyre - * reported that, with this scheme, 89% of PyObject_REALLOC calls in - * Ta3Node_AddChild passed 1 for the size, and 9% passed 4. So this usually - * wastes very little memory, but is very effective at sidestepping - * platform-realloc disasters on vulnerable platforms. - * - * Note that this would be straightforward if a node stored its current - * capacity. The code is tricky to avoid that. - */ -#define XXXROUNDUP(n) ((n) <= 1 ? (n) : \ - (n) <= 128 ? (int)_Py_SIZE_ROUND_UP((n), 4) : \ - fancy_roundup(n)) - - -int -Ta3Node_AddChild(node *n1, int type, char *str, int lineno, int col_offset) -{ - const int nch = n1->n_nchildren; - int current_capacity; - int required_capacity; - node *n; - - if (nch == INT_MAX || nch < 0) - return E_OVERFLOW; - - current_capacity = XXXROUNDUP(nch); - required_capacity = XXXROUNDUP(nch + 1); - if (current_capacity < 0 || required_capacity < 0) - return E_OVERFLOW; - if (current_capacity < required_capacity) { - if ((size_t)required_capacity > SIZE_MAX / sizeof(node)) { - return E_NOMEM; - } - n = n1->n_child; - n = (node *) PyObject_REALLOC(n, - required_capacity * sizeof(node)); - if (n == NULL) - return E_NOMEM; - n1->n_child = n; - } - - n = &n1->n_child[n1->n_nchildren++]; - n->n_type = type; - n->n_str = str; - n->n_lineno = lineno; - n->n_col_offset = col_offset; - n->n_nchildren = 0; - n->n_child = NULL; - return 0; -} - -/* Forward */ -static void freechildren(node *); -static Py_ssize_t sizeofchildren(node *n); - - -void -Ta3Node_Free(node *n) -{ - if (n != NULL) { - freechildren(n); - PyObject_FREE(n); - } -} - -Py_ssize_t -_Ta3Node_SizeOf(node *n) -{ - Py_ssize_t res = 0; - - if (n != NULL) - res = sizeof(node) + sizeofchildren(n); - return res; -} - -static void -freechildren(node *n) -{ - int i; - for (i = NCH(n); --i >= 0; ) - freechildren(CHILD(n, i)); - if (n->n_child != NULL) - PyObject_FREE(n->n_child); - if (STR(n) != NULL) - PyObject_FREE(STR(n)); -} - -static Py_ssize_t -sizeofchildren(node *n) -{ - Py_ssize_t res = 0; - int i; - for (i = NCH(n); --i >= 0; ) - res += sizeofchildren(CHILD(n, i)); - if (n->n_child != NULL) - /* allocated size of n->n_child array */ - res += XXXROUNDUP(NCH(n)) * sizeof(node); - if (STR(n) != NULL) - res += strlen(STR(n)) + 1; - return res; -} diff --git a/ast3/Parser/parser.c b/ast3/Parser/parser.c deleted file mode 100644 index 102a1698..00000000 --- a/ast3/Parser/parser.c +++ /dev/null @@ -1,447 +0,0 @@ - -/* Parser implementation */ - -/* For a description, see the comments at end of this file */ - -/* XXX To do: error recovery */ - -#include "Python.h" -#include "../Include/pgenheaders.h" -#include "../Include/token.h" -#include "../Include/grammar.h" -#include "../Include/node.h" -#include "parser.h" -#include "../Include/errcode.h" - - -#ifdef Py_DEBUG -PyAPI_DATA(int) Py_DebugFlag; -#define D(x) if (!Py_DebugFlag); else x -#else -#define D(x) -#endif - - -/* STACK DATA TYPE */ - -static void s_reset(stack *); - -static void -s_reset(stack *s) -{ - s->s_top = &s->s_base[MAXSTACK]; -} - -#define s_empty(s) ((s)->s_top == &(s)->s_base[MAXSTACK]) - -static int -s_push(stack *s, dfa *d, node *parent) -{ - stackentry *top; - if (s->s_top == s->s_base) { - fprintf(stderr, "s_push: parser stack overflow\n"); - return E_NOMEM; - } - top = --s->s_top; - top->s_dfa = d; - top->s_parent = parent; - top->s_state = 0; - return 0; -} - -#ifdef Py_DEBUG - -static void -s_pop(stack *s) -{ - if (s_empty(s)) - Py_FatalError("s_pop: parser stack underflow -- FATAL"); - s->s_top++; -} - -#else /* !Py_DEBUG */ - -#define s_pop(s) (s)->s_top++ - -#endif - - -/* PARSER CREATION */ - -parser_state * -Ta3Parser_New(grammar *g, int start) -{ - parser_state *ps; - - if (!g->g_accel) - Ta3Grammar_AddAccelerators(g); - ps = (parser_state *)PyMem_MALLOC(sizeof(parser_state)); - if (ps == NULL) - return NULL; - ps->p_grammar = g; -#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD - ps->p_flags = 0; -#endif - ps->p_tree = Ta3Node_New(start); - if (ps->p_tree == NULL) { - PyMem_FREE(ps); - return NULL; - } - s_reset(&ps->p_stack); - (void) s_push(&ps->p_stack, Ta3Grammar_FindDFA(g, start), ps->p_tree); - return ps; -} - -void -Ta3Parser_Delete(parser_state *ps) -{ - /* NB If you want to save the parse tree, - you must set p_tree to NULL before calling delparser! */ - Ta3Node_Free(ps->p_tree); - PyMem_FREE(ps); -} - - -/* PARSER STACK OPERATIONS */ - -static int -shift(stack *s, int type, char *str, int newstate, int lineno, int col_offset) -{ - int err; - assert(!s_empty(s)); - err = Ta3Node_AddChild(s->s_top->s_parent, type, str, lineno, col_offset); - if (err) - return err; - s->s_top->s_state = newstate; - return 0; -} - -static int -push(stack *s, int type, dfa *d, int newstate, int lineno, int col_offset) -{ - int err; - node *n; - n = s->s_top->s_parent; - assert(!s_empty(s)); - err = Ta3Node_AddChild(n, type, (char *)NULL, lineno, col_offset); - if (err) - return err; - s->s_top->s_state = newstate; - return s_push(s, d, CHILD(n, NCH(n)-1)); -} - - -/* PARSER PROPER */ - -static int -classify(parser_state *ps, int type, const char *str) -{ - grammar *g = ps->p_grammar; - int n = g->g_ll.ll_nlabels; - - if (type == NAME) { - label *l = g->g_ll.ll_label; - int i; - for (i = n; i > 0; i--, l++) { - if (l->lb_type != NAME || l->lb_str == NULL || - l->lb_str[0] != str[0] || - strcmp(l->lb_str, str) != 0) - continue; -#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD -#if 0 - /* Leaving this in as an example */ - if (!(ps->p_flags & CO_FUTURE_WITH_STATEMENT)) { - if (str[0] == 'w' && strcmp(str, "with") == 0) - break; /* not a keyword yet */ - else if (str[0] == 'a' && strcmp(str, "as") == 0) - break; /* not a keyword yet */ - } -#endif -#endif - D(printf("It's a keyword\n")); - return n - i; - } - } - - { - label *l = g->g_ll.ll_label; - int i; - for (i = n; i > 0; i--, l++) { - if (l->lb_type == type && l->lb_str == NULL) { - D(printf("It's a token we know\n")); - return n - i; - } - } - } - - D(printf("Illegal token\n")); - return -1; -} - -#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD -#if 0 -/* Leaving this in as an example */ -static void -future_hack(parser_state *ps) -{ - node *n = ps->p_stack.s_top->s_parent; - node *ch, *cch; - int i; - - /* from __future__ import ..., must have at least 4 children */ - n = CHILD(n, 0); - if (NCH(n) < 4) - return; - ch = CHILD(n, 0); - if (STR(ch) == NULL || strcmp(STR(ch), "from") != 0) - return; - ch = CHILD(n, 1); - if (NCH(ch) == 1 && STR(CHILD(ch, 0)) && - strcmp(STR(CHILD(ch, 0)), "__future__") != 0) - return; - ch = CHILD(n, 3); - /* ch can be a star, a parenthesis or import_as_names */ - if (TYPE(ch) == STAR) - return; - if (TYPE(ch) == LPAR) - ch = CHILD(n, 4); - - for (i = 0; i < NCH(ch); i += 2) { - cch = CHILD(ch, i); - if (NCH(cch) >= 1 && TYPE(CHILD(cch, 0)) == NAME) { - char *str_ch = STR(CHILD(cch, 0)); - if (strcmp(str_ch, FUTURE_WITH_STATEMENT) == 0) { - ps->p_flags |= CO_FUTURE_WITH_STATEMENT; - } else if (strcmp(str_ch, FUTURE_PRINT_FUNCTION) == 0) { - ps->p_flags |= CO_FUTURE_PRINT_FUNCTION; - } else if (strcmp(str_ch, FUTURE_UNICODE_LITERALS) == 0) { - ps->p_flags |= CO_FUTURE_UNICODE_LITERALS; - } - } - } -} -#endif -#endif /* future keyword */ - -int -Ta3Parser_AddToken(parser_state *ps, int type, char *str, - int lineno, int col_offset, int *expected_ret) -{ - int ilabel; - int err; - - D(printf("Token %s/'%s' ... ", _Ta3Parser_TokenNames[type], str)); - - /* Find out which label this token is */ - ilabel = classify(ps, type, str); - if (ilabel < 0) - return E_SYNTAX; - - /* Loop until the token is shifted or an error occurred */ - for (;;) { - /* Fetch the current dfa and state */ - dfa *d = ps->p_stack.s_top->s_dfa; - state *s = &d->d_state[ps->p_stack.s_top->s_state]; - - D(printf(" DFA '%s', state %d:", - d->d_name, ps->p_stack.s_top->s_state)); - - /* Check accelerator */ - if (s->s_lower <= ilabel && ilabel < s->s_upper) { - int x = s->s_accel[ilabel - s->s_lower]; - if (x != -1) { - if (x & (1<<7)) { - /* Push non-terminal */ - int nt = (x >> 8) + NT_OFFSET; - int arrow = x & ((1<<7)-1); - dfa *d1 = Ta3Grammar_FindDFA( - ps->p_grammar, nt); - if ((err = push(&ps->p_stack, nt, d1, - arrow, lineno, col_offset)) > 0) { - D(printf(" MemError: push\n")); - return err; - } - D(printf(" Push ...\n")); - continue; - } - - /* Shift the token */ - if ((err = shift(&ps->p_stack, type, str, - x, lineno, col_offset)) > 0) { - D(printf(" MemError: shift.\n")); - return err; - } - D(printf(" Shift.\n")); - /* Pop while we are in an accept-only state */ - while (s = &d->d_state - [ps->p_stack.s_top->s_state], - s->s_accept && s->s_narcs == 1) { - D(printf(" DFA '%s', state %d: " - "Direct pop.\n", - d->d_name, - ps->p_stack.s_top->s_state)); -#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD -#if 0 - if (d->d_name[0] == 'i' && - strcmp(d->d_name, - "import_stmt") == 0) - future_hack(ps); -#endif -#endif - s_pop(&ps->p_stack); - if (s_empty(&ps->p_stack)) { - D(printf(" ACCEPT.\n")); - return E_DONE; - } - d = ps->p_stack.s_top->s_dfa; - } - return E_OK; - } - } - - if (s->s_accept) { -#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD -#if 0 - if (d->d_name[0] == 'i' && - strcmp(d->d_name, "import_stmt") == 0) - future_hack(ps); -#endif -#endif - /* Pop this dfa and try again */ - s_pop(&ps->p_stack); - D(printf(" Pop ...\n")); - if (s_empty(&ps->p_stack)) { - D(printf(" Error: bottom of stack.\n")); - return E_SYNTAX; - } - continue; - } - - /* Stuck, report syntax error */ - D(printf(" Error.\n")); - if (expected_ret) { - if (s->s_lower == s->s_upper - 1) { - /* Only one possible expected token */ - *expected_ret = ps->p_grammar-> - g_ll.ll_label[s->s_lower].lb_type; - } - else - *expected_ret = -1; - } - return E_SYNTAX; - } -} - - -#ifdef Py_DEBUG - -/* DEBUG OUTPUT */ - -void -dumptree(grammar *g, node *n) -{ - int i; - - if (n == NULL) - printf("NIL"); - else { - label l; - l.lb_type = TYPE(n); - l.lb_str = STR(n); - printf("%s", Ta3Grammar_LabelRepr(&l)); - if (ISNONTERMINAL(TYPE(n))) { - printf("("); - for (i = 0; i < NCH(n); i++) { - if (i > 0) - printf(","); - dumptree(g, CHILD(n, i)); - } - printf(")"); - } - } -} - -void -showtree(grammar *g, node *n) -{ - int i; - - if (n == NULL) - return; - if (ISNONTERMINAL(TYPE(n))) { - for (i = 0; i < NCH(n); i++) - showtree(g, CHILD(n, i)); - } - else if (ISTERMINAL(TYPE(n))) { - printf("%s", _Ta3Parser_TokenNames[TYPE(n)]); - if (TYPE(n) == NUMBER || TYPE(n) == NAME) - printf("(%s)", STR(n)); - printf(" "); - } - else - printf("? "); -} - -void -printtree(parser_state *ps) -{ - if (Py_DebugFlag) { - printf("Parse tree:\n"); - dumptree(ps->p_grammar, ps->p_tree); - printf("\n"); - printf("Tokens:\n"); - showtree(ps->p_grammar, ps->p_tree); - printf("\n"); - } - printf("Listing:\n"); - PyNode_ListTree(ps->p_tree); - printf("\n"); -} - -#endif /* Py_DEBUG */ - -/* - -Description ------------ - -The parser's interface is different than usual: the function addtoken() -must be called for each token in the input. This makes it possible to -turn it into an incremental parsing system later. The parsing system -constructs a parse tree as it goes. - -A parsing rule is represented as a Deterministic Finite-state Automaton -(DFA). A node in a DFA represents a state of the parser; an arc represents -a transition. Transitions are either labeled with terminal symbols or -with non-terminals. When the parser decides to follow an arc labeled -with a non-terminal, it is invoked recursively with the DFA representing -the parsing rule for that as its initial state; when that DFA accepts, -the parser that invoked it continues. The parse tree constructed by the -recursively called parser is inserted as a child in the current parse tree. - -The DFA's can be constructed automatically from a more conventional -language description. An extended LL(1) grammar (ELL(1)) is suitable. -Certain restrictions make the parser's life easier: rules that can produce -the empty string should be outlawed (there are other ways to put loops -or optional parts in the language). To avoid the need to construct -FIRST sets, we can require that all but the last alternative of a rule -(really: arc going out of a DFA's state) must begin with a terminal -symbol. - -As an example, consider this grammar: - -expr: term (OP term)* -term: CONSTANT | '(' expr ')' - -The DFA corresponding to the rule for expr is: - -------->.---term-->.-------> - ^ | - | | - \----OP----/ - -The parse tree generated for the input a+b is: - -(expr: (term: (NAME: a)), (OP: +), (term: (NAME: b))) - -*/ diff --git a/ast3/Parser/parser.h b/ast3/Parser/parser.h deleted file mode 100644 index 32737a43..00000000 --- a/ast3/Parser/parser.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef Ta3_PARSER_H -#define Ta3_PARSER_H -#ifdef __cplusplus -extern "C" { -#endif - - -/* Parser interface */ - -#define MAXSTACK 1500 - -typedef struct { - int s_state; /* State in current DFA */ - dfa *s_dfa; /* Current DFA */ - struct _node *s_parent; /* Where to add next node */ -} stackentry; - -typedef struct { - stackentry *s_top; /* Top entry */ - stackentry s_base[MAXSTACK];/* Array of stack entries */ - /* NB The stack grows down */ -} stack; - -typedef struct { - stack p_stack; /* Stack of parser states */ - grammar *p_grammar; /* Grammar to use */ - node *p_tree; /* Top of parse tree */ -#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD - unsigned long p_flags; /* see co_flags in Include/code.h */ -#endif -} parser_state; - -parser_state *Ta3Parser_New(grammar *g, int start); -void Ta3Parser_Delete(parser_state *ps); -int Ta3Parser_AddToken(parser_state *ps, int type, char *str, int lineno, int col_offset, - int *expected_ret); -void Ta3Grammar_AddAccelerators(grammar *g); - -#ifdef __cplusplus -} -#endif -#endif /* !Ta3_PARSER_H */ diff --git a/ast3/Parser/parsetok.c b/ast3/Parser/parsetok.c deleted file mode 100644 index 4767f3d1..00000000 --- a/ast3/Parser/parsetok.c +++ /dev/null @@ -1,470 +0,0 @@ - -/* Parser-tokenizer link implementation */ - -#include "../Include/pgenheaders.h" -#include "tokenizer.h" -#include "../Include/node.h" -#include "../Include/grammar.h" -#include "parser.h" -#include "../Include/parsetok.h" -#include "../Include/errcode.h" -#include "../Include/graminit.h" - - -/* Forward */ -static node *parsetok(struct tok_state *, grammar *, int, perrdetail *, int *); -static int initerr(perrdetail *err_ret, PyObject * filename); - -/* Parse input coming from a string. Return error code, print some errors. */ -node * -Ta3Parser_ParseString(const char *s, grammar *g, int start, perrdetail *err_ret) -{ - return Ta3Parser_ParseStringFlagsFilename(s, NULL, g, start, err_ret, 0); -} - -node * -Ta3Parser_ParseStringFlags(const char *s, grammar *g, int start, - perrdetail *err_ret, int flags) -{ - return Ta3Parser_ParseStringFlagsFilename(s, NULL, - g, start, err_ret, flags); -} - -node * -Ta3Parser_ParseStringFlagsFilename(const char *s, const char *filename, - grammar *g, int start, - perrdetail *err_ret, int flags) -{ - int iflags = flags; - return Ta3Parser_ParseStringFlagsFilenameEx(s, filename, g, start, - err_ret, &iflags); -} - -node * -Ta3Parser_ParseStringObject(const char *s, PyObject *filename, - grammar *g, int start, - perrdetail *err_ret, int *flags) -{ - struct tok_state *tok; - int exec_input = start == file_input; - - if (initerr(err_ret, filename) < 0) - return NULL; - - if (*flags & PyPARSE_IGNORE_COOKIE) - tok = Ta3Tokenizer_FromUTF8(s, exec_input); - else - tok = Ta3Tokenizer_FromString(s, exec_input); - if (tok == NULL) { - err_ret->error = PyErr_Occurred() ? E_DECODE : E_NOMEM; - return NULL; - } - -#ifndef PGEN - Py_INCREF(err_ret->filename); - tok->filename = err_ret->filename; -#endif - if (*flags & PyPARSE_ASYNC_ALWAYS) - tok->async_always = 1; - return parsetok(tok, g, start, err_ret, flags); -} - -node * -Ta3Parser_ParseStringFlagsFilenameEx(const char *s, const char *filename_str, - grammar *g, int start, - perrdetail *err_ret, int *flags) -{ - node *n; - PyObject *filename = NULL; -#ifndef PGEN - if (filename_str != NULL) { - filename = PyUnicode_DecodeFSDefault(filename_str); - if (filename == NULL) { - err_ret->error = E_ERROR; - return NULL; - } - } -#endif - n = Ta3Parser_ParseStringObject(s, filename, g, start, err_ret, flags); -#ifndef PGEN - Py_XDECREF(filename); -#endif - return n; -} - -/* Parse input coming from a file. Return error code, print some errors. */ - -node * -Ta3Parser_ParseFile(FILE *fp, const char *filename, grammar *g, int start, - const char *ps1, const char *ps2, - perrdetail *err_ret) -{ - return Ta3Parser_ParseFileFlags(fp, filename, NULL, - g, start, ps1, ps2, err_ret, 0); -} - -node * -Ta3Parser_ParseFileFlags(FILE *fp, const char *filename, const char *enc, - grammar *g, int start, - const char *ps1, const char *ps2, - perrdetail *err_ret, int flags) -{ - int iflags = flags; - return Ta3Parser_ParseFileFlagsEx(fp, filename, enc, g, start, ps1, - ps2, err_ret, &iflags); -} - -node * -Ta3Parser_ParseFileObject(FILE *fp, PyObject *filename, - const char *enc, grammar *g, int start, - const char *ps1, const char *ps2, - perrdetail *err_ret, int *flags) -{ - struct tok_state *tok; - - if (initerr(err_ret, filename) < 0) - return NULL; - - if ((tok = Ta3Tokenizer_FromFile(fp, enc, ps1, ps2)) == NULL) { - err_ret->error = E_NOMEM; - return NULL; - } -#ifndef PGEN - Py_INCREF(err_ret->filename); - tok->filename = err_ret->filename; -#endif - return parsetok(tok, g, start, err_ret, flags); -} - -node * -Ta3Parser_ParseFileFlagsEx(FILE *fp, const char *filename, - const char *enc, grammar *g, int start, - const char *ps1, const char *ps2, - perrdetail *err_ret, int *flags) -{ - node *n; - PyObject *fileobj = NULL; -#ifndef PGEN - if (filename != NULL) { - fileobj = PyUnicode_DecodeFSDefault(filename); - if (fileobj == NULL) { - err_ret->error = E_ERROR; - return NULL; - } - } -#endif - n = Ta3Parser_ParseFileObject(fp, fileobj, enc, g, - start, ps1, ps2, err_ret, flags); -#ifndef PGEN - Py_XDECREF(fileobj); -#endif - return n; -} - -#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD -#if 0 -static const char with_msg[] = -"%s:%d: Warning: 'with' will become a reserved keyword in Python 2.6\n"; - -static const char as_msg[] = -"%s:%d: Warning: 'as' will become a reserved keyword in Python 2.6\n"; - -static void -warn(const char *msg, const char *filename, int lineno) -{ - if (filename == NULL) - filename = ""; - PySys_WriteStderr(msg, filename, lineno); -} -#endif -#endif - -typedef struct { - struct { - int lineno; - char *comment; - } *items; - size_t size; - size_t num_items; -} growable_comment_array; - -static int -growable_comment_array_init(growable_comment_array *arr, size_t initial_size) { - assert(initial_size > 0); - arr->items = 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) { - arr->size *= 2; - arr->items = realloc(arr->items, arr->size * sizeof(*arr->items)); - if (!arr->items) { - return 0; - } - } - - arr->items[arr->num_items].lineno = lineno; - arr->items[arr->num_items].comment = comment; - arr->num_items++; - return 1; -} - -static void -growable_comment_array_deallocate(growable_comment_array *arr) { - unsigned i; - for (i = 0; i < arr->num_items; i++) { - PyObject_FREE(arr->items[i].comment); - } - free(arr->items); -} - -/* Parse input coming from the given tokenizer structure. - Return error code. */ - -static node * -parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret, - int *flags) -{ - parser_state *ps; - node *n; - int started = 0; - - growable_comment_array type_ignores; - if (!growable_comment_array_init(&type_ignores, 10)) { - err_ret->error = E_NOMEM; - Ta3Tokenizer_Free(tok); - return NULL; - } - - if ((ps = Ta3Parser_New(g, start)) == NULL) { - err_ret->error = E_NOMEM; - Ta3Tokenizer_Free(tok); - return NULL; - } -#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD - if (*flags & PyPARSE_BARRY_AS_BDFL) - ps->p_flags |= CO_FUTURE_BARRY_AS_BDFL; -#endif - - for (;;) { - char *a, *b; - int type; - size_t len; - char *str; - int col_offset; - - type = Ta3Tokenizer_Get(tok, &a, &b); - if (type == ERRORTOKEN) { - err_ret->error = tok->done; - break; - } - if (type == ENDMARKER && started) { - type = NEWLINE; /* Add an extra newline */ - started = 0; - /* Add the right number of dedent tokens, - except if a certain flag is given -- - codeop.py uses this. */ - if (tok->indent && - !(*flags & PyPARSE_DONT_IMPLY_DEDENT)) - { - tok->pendin = -tok->indent; - tok->indent = 0; - } - } - else - started = 1; - len = (a != NULL && b != NULL) ? b - a : 0; - str = (char *) PyObject_MALLOC(len + 1); - if (str == NULL) { - err_ret->error = E_NOMEM; - break; - } - if (len > 0) - strncpy(str, a, len); - str[len] = '\0'; - -#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD - if (type == NOTEQUAL) { - if (!(ps->p_flags & CO_FUTURE_BARRY_AS_BDFL) && - strcmp(str, "!=")) { - PyObject_FREE(str); - err_ret->error = E_SYNTAX; - break; - } - else if ((ps->p_flags & CO_FUTURE_BARRY_AS_BDFL) && - strcmp(str, "<>")) { - PyObject_FREE(str); - err_ret->expected = NOTEQUAL; - err_ret->error = E_SYNTAX; - break; - } - } -#endif - if (a != NULL && a >= tok->line_start) { - col_offset = Py_SAFE_DOWNCAST(a - tok->line_start, - intptr_t, int); - } - else { - col_offset = -1; - } - - if (type == TYPE_IGNORE) { - if (!growable_comment_array_add(&type_ignores, tok->lineno, str)) { - err_ret->error = E_NOMEM; - break; - } - continue; - } - - if ((err_ret->error = - Ta3Parser_AddToken(ps, (int)type, str, - tok->lineno, col_offset, - &(err_ret->expected))) != E_OK) { - if (err_ret->error != E_DONE) { - PyObject_FREE(str); - err_ret->token = type; - } - break; - } - } - - if (err_ret->error == E_DONE) { - n = ps->p_tree; - ps->p_tree = NULL; - - if (n->n_type == file_input) { - /* Put type_ignore nodes in the ENDMARKER of file_input. */ - int num; - node *ch; - size_t i; - - num = NCH(n); - ch = CHILD(n, num - 1); - REQ(ch, ENDMARKER); - - for (i = 0; i < type_ignores.num_items; i++) { - int res = Ta3Node_AddChild(ch, TYPE_IGNORE, type_ignores.items[i].comment, - type_ignores.items[i].lineno, 0); - if (res != 0) { - err_ret->error = res; - Ta3Node_Free(n); - n = NULL; - break; - } - type_ignores.items[i].comment = NULL; - } - } - -#ifndef PGEN - /* Check that the source for a single input statement really - is a single statement by looking at what is left in the - buffer after parsing. Trailing whitespace and comments - are OK. */ - if (err_ret->error == E_DONE && start == single_input) { - char *cur = tok->cur; - char c = *tok->cur; - - for (;;) { - while (c == ' ' || c == '\t' || c == '\n' || c == '\014') - c = *++cur; - - if (!c) - break; - - if (c != '#') { - err_ret->error = E_BADSINGLE; - Ta3Node_Free(n); - n = NULL; - break; - } - - /* Suck up comment. */ - while (c && c != '\n') - c = *++cur; - } - } -#endif - } - else - n = NULL; - - growable_comment_array_deallocate(&type_ignores); - -#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD - *flags = ps->p_flags; -#endif - Ta3Parser_Delete(ps); - - if (n == NULL) { - if (tok->done == E_EOF) - err_ret->error = E_EOF; - err_ret->lineno = tok->lineno; - if (tok->buf != NULL) { - size_t len; - assert(tok->cur - tok->buf < INT_MAX); - err_ret->offset = (int)(tok->cur - tok->buf); - len = tok->inp - tok->buf; - err_ret->text = (char *) PyObject_MALLOC(len + 1); - if (err_ret->text != NULL) { - if (len > 0) - strncpy(err_ret->text, tok->buf, len); - err_ret->text[len] = '\0'; - } - } - } else if (tok->encoding != NULL) { - /* 'nodes->n_str' uses PyObject_*, while 'tok->encoding' was - * allocated using PyMem_ - */ - node* r = Ta3Node_New(encoding_decl); - if (r) - r->n_str = PyObject_MALLOC(strlen(tok->encoding)+1); - if (!r || !r->n_str) { - err_ret->error = E_NOMEM; - if (r) - PyObject_FREE(r); - n = NULL; - goto done; - } - strcpy(r->n_str, tok->encoding); - PyMem_FREE(tok->encoding); - tok->encoding = NULL; - r->n_nchildren = 1; - r->n_child = n; - n = r; - } - -done: - Ta3Tokenizer_Free(tok); - - return n; -} - -static int -initerr(perrdetail *err_ret, PyObject *filename) -{ - err_ret->error = E_OK; - err_ret->lineno = 0; - err_ret->offset = 0; - err_ret->text = NULL; - err_ret->token = -1; - err_ret->expected = -1; -#ifndef PGEN - if (filename) { - Py_INCREF(filename); - err_ret->filename = filename; - } - else { - err_ret->filename = PyUnicode_FromString(""); - if (err_ret->filename == NULL) { - err_ret->error = E_ERROR; - return -1; - } - } -#endif - return 0; -} diff --git a/ast3/Parser/pegen/parse.c b/ast3/Parser/pegen/parse.c new file mode 100644 index 00000000..3a08abbc --- /dev/null +++ b/ast3/Parser/pegen/parse.c @@ -0,0 +1,17280 @@ +// @generated by pegen.py from ./Grammar/python.gram +#include "pegen.h" +static const int n_keyword_lists = 15; +static KeywordToken *reserved_keywords[] = { + NULL, + NULL, + (KeywordToken[]) { + {"if", 510}, + {"in", 518}, + {"is", 526}, + {"as", 531}, + {"or", 532}, + {NULL, -1}, + }, + (KeywordToken[]) { + {"del", 503}, + {"try", 511}, + {"for", 517}, + {"def", 522}, + {"not", 525}, + {"and", 533}, + {NULL, -1}, + }, + (KeywordToken[]) { + {"pass", 502}, + {"from", 514}, + {"elif", 515}, + {"else", 516}, + {"with", 519}, + {"True", 527}, + {"None", 529}, + {NULL, -1}, + }, + (KeywordToken[]) { + {"raise", 501}, + {"yield", 504}, + {"break", 506}, + {"while", 512}, + {"class", 523}, + {"False", 528}, + {NULL, -1}, + }, + (KeywordToken[]) { + {"return", 500}, + {"assert", 505}, + {"global", 508}, + {"import", 513}, + {"except", 520}, + {"lambda", 524}, + {NULL, -1}, + }, + (KeywordToken[]) { + {"finally", 521}, + {NULL, -1}, + }, + (KeywordToken[]) { + {"continue", 507}, + {"nonlocal", 509}, + {NULL, -1}, + }, + NULL, + NULL, + NULL, + NULL, + NULL, + (KeywordToken[]) { + {"__new_parser__", 530}, + {NULL, -1}, + }, +}; +#define file_type 1000 +#define interactive_type 1001 +#define eval_type 1002 +#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_no_default_type 1070 +#define lambda_slash_with_default_type 1071 +#define lambda_star_etc_type 1072 +#define lambda_kwds_type 1073 +#define lambda_param_no_default_type 1074 +#define lambda_param_with_default_type 1075 +#define lambda_param_maybe_default_type 1076 +#define lambda_param_type 1077 +#define disjunction_type 1078 +#define conjunction_type 1079 +#define inversion_type 1080 +#define comparison_type 1081 +#define compare_op_bitwise_or_pair_type 1082 +#define eq_bitwise_or_type 1083 +#define noteq_bitwise_or_type 1084 +#define lte_bitwise_or_type 1085 +#define lt_bitwise_or_type 1086 +#define gte_bitwise_or_type 1087 +#define gt_bitwise_or_type 1088 +#define notin_bitwise_or_type 1089 +#define in_bitwise_or_type 1090 +#define isnot_bitwise_or_type 1091 +#define is_bitwise_or_type 1092 +#define bitwise_or_type 1093 // Left-recursive +#define bitwise_xor_type 1094 // Left-recursive +#define bitwise_and_type 1095 // Left-recursive +#define shift_expr_type 1096 // Left-recursive +#define sum_type 1097 // Left-recursive +#define term_type 1098 // Left-recursive +#define factor_type 1099 +#define power_type 1100 +#define await_primary_type 1101 +#define primary_type 1102 // Left-recursive +#define slices_type 1103 +#define slice_type 1104 +#define atom_type 1105 +#define strings_type 1106 +#define list_type 1107 +#define listcomp_type 1108 +#define tuple_type 1109 +#define group_type 1110 +#define genexp_type 1111 +#define set_type 1112 +#define setcomp_type 1113 +#define dict_type 1114 +#define dictcomp_type 1115 +#define kvpairs_type 1116 +#define kvpair_type 1117 +#define for_if_clauses_type 1118 +#define for_if_clause_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_kwarg_type 1142 +#define invalid_named_expression_type 1143 +#define invalid_assignment_type 1144 +#define invalid_block_type 1145 +#define invalid_comprehension_type 1146 +#define invalid_parameters_type 1147 +#define invalid_star_etc_type 1148 +#define invalid_lambda_star_etc_type 1149 +#define invalid_double_type_comments_type 1150 +#define _loop0_1_type 1151 +#define _loop0_2_type 1152 +#define _loop0_4_type 1153 +#define _gather_3_type 1154 +#define _loop0_6_type 1155 +#define _gather_5_type 1156 +#define _loop0_8_type 1157 +#define _gather_7_type 1158 +#define _loop0_10_type 1159 +#define _gather_9_type 1160 +#define _loop1_11_type 1161 +#define _loop0_13_type 1162 +#define _gather_12_type 1163 +#define _tmp_14_type 1164 +#define _tmp_15_type 1165 +#define _tmp_16_type 1166 +#define _tmp_17_type 1167 +#define _tmp_18_type 1168 +#define _tmp_19_type 1169 +#define _tmp_20_type 1170 +#define _tmp_21_type 1171 +#define _loop1_22_type 1172 +#define _tmp_23_type 1173 +#define _tmp_24_type 1174 +#define _loop0_26_type 1175 +#define _gather_25_type 1176 +#define _loop0_28_type 1177 +#define _gather_27_type 1178 +#define _tmp_29_type 1179 +#define _loop0_30_type 1180 +#define _loop1_31_type 1181 +#define _loop0_33_type 1182 +#define _gather_32_type 1183 +#define _tmp_34_type 1184 +#define _loop0_36_type 1185 +#define _gather_35_type 1186 +#define _tmp_37_type 1187 +#define _loop0_39_type 1188 +#define _gather_38_type 1189 +#define _loop0_41_type 1190 +#define _gather_40_type 1191 +#define _loop0_43_type 1192 +#define _gather_42_type 1193 +#define _loop0_45_type 1194 +#define _gather_44_type 1195 +#define _tmp_46_type 1196 +#define _loop1_47_type 1197 +#define _tmp_48_type 1198 +#define _tmp_49_type 1199 +#define _tmp_50_type 1200 +#define _tmp_51_type 1201 +#define _tmp_52_type 1202 +#define _loop0_53_type 1203 +#define _loop0_54_type 1204 +#define _loop0_55_type 1205 +#define _loop1_56_type 1206 +#define _loop0_57_type 1207 +#define _loop1_58_type 1208 +#define _loop1_59_type 1209 +#define _loop1_60_type 1210 +#define _loop0_61_type 1211 +#define _loop1_62_type 1212 +#define _loop0_63_type 1213 +#define _loop1_64_type 1214 +#define _loop0_65_type 1215 +#define _loop1_66_type 1216 +#define _loop1_67_type 1217 +#define _tmp_68_type 1218 +#define _loop0_70_type 1219 +#define _gather_69_type 1220 +#define _loop1_71_type 1221 +#define _loop0_73_type 1222 +#define _gather_72_type 1223 +#define _loop1_74_type 1224 +#define _loop0_75_type 1225 +#define _loop0_76_type 1226 +#define _loop0_77_type 1227 +#define _loop1_78_type 1228 +#define _loop0_79_type 1229 +#define _loop1_80_type 1230 +#define _loop1_81_type 1231 +#define _loop1_82_type 1232 +#define _loop0_83_type 1233 +#define _loop1_84_type 1234 +#define _loop0_85_type 1235 +#define _loop1_86_type 1236 +#define _loop0_87_type 1237 +#define _loop1_88_type 1238 +#define _loop1_89_type 1239 +#define _loop1_90_type 1240 +#define _loop1_91_type 1241 +#define _tmp_92_type 1242 +#define _loop0_94_type 1243 +#define _gather_93_type 1244 +#define _tmp_95_type 1245 +#define _tmp_96_type 1246 +#define _tmp_97_type 1247 +#define _tmp_98_type 1248 +#define _loop1_99_type 1249 +#define _tmp_100_type 1250 +#define _tmp_101_type 1251 +#define _loop0_103_type 1252 +#define _gather_102_type 1253 +#define _loop1_104_type 1254 +#define _loop0_105_type 1255 +#define _loop0_106_type 1256 +#define _tmp_107_type 1257 +#define _tmp_108_type 1258 +#define _loop0_110_type 1259 +#define _gather_109_type 1260 +#define _loop0_112_type 1261 +#define _gather_111_type 1262 +#define _loop0_114_type 1263 +#define _gather_113_type 1264 +#define _loop0_116_type 1265 +#define _gather_115_type 1266 +#define _loop0_117_type 1267 +#define _loop0_119_type 1268 +#define _gather_118_type 1269 +#define _tmp_120_type 1270 +#define _loop0_122_type 1271 +#define _gather_121_type 1272 +#define _loop0_124_type 1273 +#define _gather_123_type 1274 +#define _tmp_125_type 1275 +#define _tmp_126_type 1276 +#define _tmp_127_type 1277 +#define _tmp_128_type 1278 +#define _tmp_129_type 1279 +#define _loop0_130_type 1280 +#define _tmp_131_type 1281 +#define _tmp_132_type 1282 +#define _tmp_133_type 1283 +#define _tmp_134_type 1284 +#define _tmp_135_type 1285 +#define _tmp_136_type 1286 +#define _tmp_137_type 1287 +#define _tmp_138_type 1288 +#define _tmp_139_type 1289 +#define _tmp_140_type 1290 +#define _tmp_141_type 1291 +#define _tmp_142_type 1292 +#define _tmp_143_type 1293 +#define _tmp_144_type 1294 +#define _loop1_145_type 1295 +#define _tmp_146_type 1296 +#define _tmp_147_type 1297 + +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); +static asdl_seq* simple_stmt_rule(Parser *p); +static stmt_ty small_stmt_rule(Parser *p); +static stmt_ty compound_stmt_rule(Parser *p); +static stmt_ty assignment_rule(Parser *p); +static AugOperator* augassign_rule(Parser *p); +static stmt_ty global_stmt_rule(Parser *p); +static stmt_ty nonlocal_stmt_rule(Parser *p); +static stmt_ty yield_stmt_rule(Parser *p); +static stmt_ty assert_stmt_rule(Parser *p); +static stmt_ty del_stmt_rule(Parser *p); +static stmt_ty import_stmt_rule(Parser *p); +static stmt_ty import_name_rule(Parser *p); +static stmt_ty import_from_rule(Parser *p); +static asdl_seq* import_from_targets_rule(Parser *p); +static asdl_seq* import_from_as_names_rule(Parser *p); +static alias_ty import_from_as_name_rule(Parser *p); +static asdl_seq* dotted_as_names_rule(Parser *p); +static alias_ty dotted_as_name_rule(Parser *p); +static expr_ty dotted_name_rule(Parser *p); +static stmt_ty if_stmt_rule(Parser *p); +static stmt_ty elif_stmt_rule(Parser *p); +static asdl_seq* else_block_rule(Parser *p); +static stmt_ty while_stmt_rule(Parser *p); +static stmt_ty for_stmt_rule(Parser *p); +static stmt_ty with_stmt_rule(Parser *p); +static withitem_ty with_item_rule(Parser *p); +static stmt_ty try_stmt_rule(Parser *p); +static excepthandler_ty except_block_rule(Parser *p); +static asdl_seq* finally_block_rule(Parser *p); +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 Token* func_type_comment_rule(Parser *p); +static arguments_ty params_rule(Parser *p); +static arguments_ty parameters_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 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); +static asdl_seq* block_rule(Parser *p); +static asdl_seq* expressions_list_rule(Parser *p); +static expr_ty star_expressions_rule(Parser *p); +static expr_ty star_expression_rule(Parser *p); +static asdl_seq* star_named_expressions_rule(Parser *p); +static expr_ty star_named_expression_rule(Parser *p); +static expr_ty named_expression_rule(Parser *p); +static expr_ty annotated_rhs_rule(Parser *p); +static expr_ty expressions_rule(Parser *p); +static expr_ty expression_rule(Parser *p); +static expr_ty lambdef_rule(Parser *p); +static arguments_ty lambda_parameters_rule(Parser *p); +static asdl_seq* lambda_slash_no_default_rule(Parser *p); +static SlashWithDefault* lambda_slash_with_default_rule(Parser *p); +static StarEtc* lambda_star_etc_rule(Parser *p); +static arg_ty lambda_kwds_rule(Parser *p); +static arg_ty lambda_param_no_default_rule(Parser *p); +static NameDefaultPair* lambda_param_with_default_rule(Parser *p); +static NameDefaultPair* lambda_param_maybe_default_rule(Parser *p); +static arg_ty lambda_param_rule(Parser *p); +static expr_ty disjunction_rule(Parser *p); +static expr_ty conjunction_rule(Parser *p); +static expr_ty inversion_rule(Parser *p); +static expr_ty comparison_rule(Parser *p); +static CmpopExprPair* compare_op_bitwise_or_pair_rule(Parser *p); +static CmpopExprPair* eq_bitwise_or_rule(Parser *p); +static CmpopExprPair* noteq_bitwise_or_rule(Parser *p); +static CmpopExprPair* lte_bitwise_or_rule(Parser *p); +static CmpopExprPair* lt_bitwise_or_rule(Parser *p); +static CmpopExprPair* gte_bitwise_or_rule(Parser *p); +static CmpopExprPair* gt_bitwise_or_rule(Parser *p); +static CmpopExprPair* notin_bitwise_or_rule(Parser *p); +static CmpopExprPair* in_bitwise_or_rule(Parser *p); +static CmpopExprPair* isnot_bitwise_or_rule(Parser *p); +static CmpopExprPair* is_bitwise_or_rule(Parser *p); +static expr_ty bitwise_or_rule(Parser *p); +static expr_ty bitwise_xor_rule(Parser *p); +static expr_ty bitwise_and_rule(Parser *p); +static expr_ty shift_expr_rule(Parser *p); +static expr_ty sum_rule(Parser *p); +static expr_ty term_rule(Parser *p); +static expr_ty factor_rule(Parser *p); +static expr_ty power_rule(Parser *p); +static expr_ty await_primary_rule(Parser *p); +static expr_ty primary_rule(Parser *p); +static expr_ty slices_rule(Parser *p); +static expr_ty slice_rule(Parser *p); +static expr_ty atom_rule(Parser *p); +static expr_ty strings_rule(Parser *p); +static expr_ty list_rule(Parser *p); +static expr_ty listcomp_rule(Parser *p); +static expr_ty tuple_rule(Parser *p); +static expr_ty group_rule(Parser *p); +static expr_ty genexp_rule(Parser *p); +static expr_ty set_rule(Parser *p); +static expr_ty setcomp_rule(Parser *p); +static expr_ty dict_rule(Parser *p); +static expr_ty dictcomp_rule(Parser *p); +static asdl_seq* kvpairs_rule(Parser *p); +static KeyValuePair* kvpair_rule(Parser *p); +static asdl_seq* for_if_clauses_rule(Parser *p); +static comprehension_ty for_if_clause_rule(Parser *p); +static expr_ty yield_expr_rule(Parser *p); +static expr_ty arguments_rule(Parser *p); +static expr_ty args_rule(Parser *p); +static asdl_seq* kwargs_rule(Parser *p); +static expr_ty starred_expression_rule(Parser *p); +static KeywordOrStarred* kwarg_or_starred_rule(Parser *p); +static KeywordOrStarred* kwarg_or_double_starred_rule(Parser *p); +static expr_ty star_targets_rule(Parser *p); +static asdl_seq* star_targets_seq_rule(Parser *p); +static expr_ty star_target_rule(Parser *p); +static expr_ty star_atom_rule(Parser *p); +static expr_ty inside_paren_ann_assign_target_rule(Parser *p); +static expr_ty ann_assign_subscript_attribute_target_rule(Parser *p); +static asdl_seq* del_targets_rule(Parser *p); +static expr_ty del_target_rule(Parser *p); +static expr_ty del_t_atom_rule(Parser *p); +static asdl_seq* targets_rule(Parser *p); +static expr_ty target_rule(Parser *p); +static expr_ty t_primary_rule(Parser *p); +static void *t_lookahead_rule(Parser *p); +static expr_ty t_atom_rule(Parser *p); +static void *incorrect_arguments_rule(Parser *p); +static void *invalid_kwarg_rule(Parser *p); +static void *invalid_named_expression_rule(Parser *p); +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_star_etc_rule(Parser *p); +static void *invalid_lambda_star_etc_rule(Parser *p); +static void *invalid_double_type_comments_rule(Parser *p); +static asdl_seq *_loop0_1_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 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 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 void *_tmp_21_rule(Parser *p); +static asdl_seq *_loop1_22_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 *_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 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 asdl_seq *_loop0_43_rule(Parser *p); +static asdl_seq *_gather_42_rule(Parser *p); +static asdl_seq *_loop0_45_rule(Parser *p); +static asdl_seq *_gather_44_rule(Parser *p); +static void *_tmp_46_rule(Parser *p); +static asdl_seq *_loop1_47_rule(Parser *p); +static void *_tmp_48_rule(Parser *p); +static void *_tmp_49_rule(Parser *p); +static void *_tmp_50_rule(Parser *p); +static void *_tmp_51_rule(Parser *p); +static void *_tmp_52_rule(Parser *p); +static asdl_seq *_loop0_53_rule(Parser *p); +static asdl_seq *_loop0_54_rule(Parser *p); +static asdl_seq *_loop0_55_rule(Parser *p); +static asdl_seq *_loop1_56_rule(Parser *p); +static asdl_seq *_loop0_57_rule(Parser *p); +static asdl_seq *_loop1_58_rule(Parser *p); +static asdl_seq *_loop1_59_rule(Parser *p); +static asdl_seq *_loop1_60_rule(Parser *p); +static asdl_seq *_loop0_61_rule(Parser *p); +static asdl_seq *_loop1_62_rule(Parser *p); +static asdl_seq *_loop0_63_rule(Parser *p); +static asdl_seq *_loop1_64_rule(Parser *p); +static asdl_seq *_loop0_65_rule(Parser *p); +static asdl_seq *_loop1_66_rule(Parser *p); +static asdl_seq *_loop1_67_rule(Parser *p); +static void *_tmp_68_rule(Parser *p); +static asdl_seq *_loop0_70_rule(Parser *p); +static asdl_seq *_gather_69_rule(Parser *p); +static asdl_seq *_loop1_71_rule(Parser *p); +static asdl_seq *_loop0_73_rule(Parser *p); +static asdl_seq *_gather_72_rule(Parser *p); +static asdl_seq *_loop1_74_rule(Parser *p); +static asdl_seq *_loop0_75_rule(Parser *p); +static asdl_seq *_loop0_76_rule(Parser *p); +static asdl_seq *_loop0_77_rule(Parser *p); +static asdl_seq *_loop1_78_rule(Parser *p); +static asdl_seq *_loop0_79_rule(Parser *p); +static asdl_seq *_loop1_80_rule(Parser *p); +static asdl_seq *_loop1_81_rule(Parser *p); +static asdl_seq *_loop1_82_rule(Parser *p); +static asdl_seq *_loop0_83_rule(Parser *p); +static asdl_seq *_loop1_84_rule(Parser *p); +static asdl_seq *_loop0_85_rule(Parser *p); +static asdl_seq *_loop1_86_rule(Parser *p); +static asdl_seq *_loop0_87_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 asdl_seq *_loop1_91_rule(Parser *p); +static void *_tmp_92_rule(Parser *p); +static asdl_seq *_loop0_94_rule(Parser *p); +static asdl_seq *_gather_93_rule(Parser *p); +static void *_tmp_95_rule(Parser *p); +static void *_tmp_96_rule(Parser *p); +static void *_tmp_97_rule(Parser *p); +static void *_tmp_98_rule(Parser *p); +static asdl_seq *_loop1_99_rule(Parser *p); +static void *_tmp_100_rule(Parser *p); +static void *_tmp_101_rule(Parser *p); +static asdl_seq *_loop0_103_rule(Parser *p); +static asdl_seq *_gather_102_rule(Parser *p); +static asdl_seq *_loop1_104_rule(Parser *p); +static asdl_seq *_loop0_105_rule(Parser *p); +static asdl_seq *_loop0_106_rule(Parser *p); +static void *_tmp_107_rule(Parser *p); +static void *_tmp_108_rule(Parser *p); +static asdl_seq *_loop0_110_rule(Parser *p); +static asdl_seq *_gather_109_rule(Parser *p); +static asdl_seq *_loop0_112_rule(Parser *p); +static asdl_seq *_gather_111_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 asdl_seq *_loop0_117_rule(Parser *p); +static asdl_seq *_loop0_119_rule(Parser *p); +static asdl_seq *_gather_118_rule(Parser *p); +static void *_tmp_120_rule(Parser *p); +static asdl_seq *_loop0_122_rule(Parser *p); +static asdl_seq *_gather_121_rule(Parser *p); +static asdl_seq *_loop0_124_rule(Parser *p); +static asdl_seq *_gather_123_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 void *_tmp_128_rule(Parser *p); +static void *_tmp_129_rule(Parser *p); +static asdl_seq *_loop0_130_rule(Parser *p); +static void *_tmp_131_rule(Parser *p); +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 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 void *_tmp_140_rule(Parser *p); +static void *_tmp_141_rule(Parser *p); +static void *_tmp_142_rule(Parser *p); +static void *_tmp_143_rule(Parser *p); +static void *_tmp_144_rule(Parser *p); +static asdl_seq *_loop1_145_rule(Parser *p); +static void *_tmp_146_rule(Parser *p); +static void *_tmp_147_rule(Parser *p); + + +// file: statements? $ +static mod_ty +file_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + mod_ty res = NULL; + int mark = p->mark; + { // statements? $ + void *a; + Token * endmarker_var; + if ( + (a = statements_rule(p), 1) // statements? + && + (endmarker_var = _PyPegen_expect_token(p, ENDMARKER)) // token='ENDMARKER' + ) + { + res = _PyPegen_make_module ( p , a ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// interactive: statement_newline +static mod_ty +interactive_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + mod_ty res = NULL; + int mark = p->mark; + { // statement_newline + asdl_seq* a; + if ( + (a = statement_newline_rule(p)) // statement_newline + ) + { + res = Interactive ( a , p -> arena ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// eval: expressions NEWLINE* $ +static mod_ty +eval_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + mod_ty res = NULL; + int mark = p->mark; + { // expressions NEWLINE* $ + asdl_seq * _loop0_1_var; + expr_ty a; + Token * endmarker_var; + if ( + (a = expressions_rule(p)) // expressions + && + (_loop0_1_var = _loop0_1_rule(p)) // NEWLINE* + && + (endmarker_var = _PyPegen_expect_token(p, ENDMARKER)) // token='ENDMARKER' + ) + { + res = Expression ( a , p -> arena ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + 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; + Token * endmarker_var; + Token * literal; + Token * literal_1; + Token * literal_2; + if ( + (literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (a = type_expressions_rule(p), 1) // type_expressions? + && + (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + && + (literal_2 = _PyPegen_expect_token(p, 51)) // token='->' + && + (b = expression_rule(p)) // expression + && + (_loop0_2_var = _loop0_2_rule(p)) // NEWLINE* + && + (endmarker_var = _PyPegen_expect_token(p, ENDMARKER)) // token='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) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + { // star_expressions + expr_ty star_expressions_var; + if ( + (star_expressions_var = star_expressions_rule(p)) // star_expressions + ) + { + res = star_expressions_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// type_expressions: +// | ','.expression+ ',' '*' expression ',' '**' expression +// | ','.expression+ ',' '*' 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; + Token * literal; + Token * literal_1; + Token * literal_2; + Token * literal_3; + if ( + (a = _gather_3_rule(p)) // ','.expression+ + && + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (literal_1 = _PyPegen_expect_token(p, 16)) // token='*' + && + (b = expression_rule(p)) // expression + && + (literal_2 = _PyPegen_expect_token(p, 12)) // token=',' + && + (literal_3 = _PyPegen_expect_token(p, 35)) // token='**' + && + (c = expression_rule(p)) // expression + ) + { + 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; + Token * literal; + Token * literal_1; + if ( + (a = _gather_5_rule(p)) // ','.expression+ + && + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (literal_1 = _PyPegen_expect_token(p, 16)) // token='*' + && + (b = expression_rule(p)) // expression + ) + { + 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; + Token * literal; + Token * literal_1; + if ( + (a = _gather_7_rule(p)) // ','.expression+ + && + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (literal_1 = _PyPegen_expect_token(p, 35)) // token='**' + && + (b = expression_rule(p)) // expression + ) + { + 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 + expr_ty a; + expr_ty b; + Token * literal; + Token * literal_1; + Token * literal_2; + if ( + (literal = _PyPegen_expect_token(p, 16)) // token='*' + && + (a = expression_rule(p)) // expression + && + (literal_1 = _PyPegen_expect_token(p, 12)) // token=',' + && + (literal_2 = _PyPegen_expect_token(p, 35)) // token='**' + && + (b = expression_rule(p)) // expression + ) + { + res = _PyPegen_seq_append_to_end ( p , CHECK ( _PyPegen_singleton_seq ( p , a ) ) , b ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // '*' expression + expr_ty a; + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 16)) // token='*' + && + (a = expression_rule(p)) // expression + ) + { + res = _PyPegen_singleton_seq ( p , a ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // '**' expression + expr_ty a; + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 35)) // token='**' + && + (a = expression_rule(p)) // expression + ) + { + res = _PyPegen_singleton_seq ( p , a ); + 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)) // ','.expression+ + ) + { + res = _gather_9_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// statements: statement+ +static asdl_seq* +statements_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq* res = NULL; + int mark = p->mark; + { // statement+ + asdl_seq * a; + if ( + (a = _loop1_11_rule(p)) // statement+ + ) + { + res = _PyPegen_seq_flatten ( p , a ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// statement: compound_stmt | simple_stmt +static asdl_seq* +statement_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq* res = NULL; + int mark = p->mark; + { // compound_stmt + stmt_ty a; + if ( + (a = compound_stmt_rule(p)) // compound_stmt + ) + { + res = _PyPegen_singleton_seq ( p , a ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // simple_stmt + asdl_seq* simple_stmt_var; + if ( + (simple_stmt_var = simple_stmt_rule(p)) // simple_stmt + ) + { + res = simple_stmt_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// statement_newline: compound_stmt NEWLINE | simple_stmt | NEWLINE | $ +static asdl_seq* +statement_newline_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq* res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // compound_stmt NEWLINE + stmt_ty a; + Token * newline_var; + if ( + (a = compound_stmt_rule(p)) // compound_stmt + && + (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + ) + { + res = _PyPegen_singleton_seq ( p , a ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // simple_stmt + asdl_seq* simple_stmt_var; + if ( + (simple_stmt_var = simple_stmt_rule(p)) // simple_stmt + ) + { + res = simple_stmt_var; + goto done; + } + p->mark = mark; + } + { // NEWLINE + Token * newline_var; + if ( + (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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 = _PyPegen_singleton_seq ( p , CHECK ( _Py_Pass ( EXTRA ) ) ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // $ + Token * endmarker_var; + if ( + (endmarker_var = _PyPegen_expect_token(p, ENDMARKER)) // token='ENDMARKER' + ) + { + res = _PyPegen_interactive_exit ( p ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// simple_stmt: small_stmt !';' NEWLINE | ';'.small_stmt+ ';'? NEWLINE +static asdl_seq* +simple_stmt_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq* res = NULL; + int mark = p->mark; + { // small_stmt !';' NEWLINE + stmt_ty a; + Token * newline_var; + if ( + (a = small_stmt_rule(p)) // small_stmt + && + _PyPegen_lookahead_with_int(0, _PyPegen_expect_token, p, 13) // token=';' + && + (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + ) + { + res = _PyPegen_singleton_seq ( p , a ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // ';'.small_stmt+ ';'? NEWLINE + asdl_seq * a; + Token * newline_var; + void *opt_var; + UNUSED(opt_var); // Silence compiler warnings + if ( + (a = _gather_12_rule(p)) // ';'.small_stmt+ + && + (opt_var = _PyPegen_expect_token(p, 13), 1) // ';'? + && + (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + ) + { + res = a; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// small_stmt: +// | assignment +// | star_expressions +// | &'return' return_stmt +// | &('import' | 'from') import_stmt +// | &'raise' raise_stmt +// | 'pass' +// | &'del' del_stmt +// | &'yield' yield_stmt +// | &'assert' assert_stmt +// | 'break' +// | 'continue' +// | &'global' global_stmt +// | &'nonlocal' nonlocal_stmt +static stmt_ty +small_stmt_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + stmt_ty res = NULL; + if (_PyPegen_is_memoized(p, small_stmt_type, &res)) + return res; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // assignment + stmt_ty assignment_var; + if ( + (assignment_var = assignment_rule(p)) // assignment + ) + { + res = assignment_var; + goto done; + } + p->mark = mark; + } + { // star_expressions + expr_ty e; + if ( + (e = star_expressions_rule(p)) // star_expressions + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Expr ( e , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // &'return' return_stmt + stmt_ty return_stmt_var; + if ( + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 500) // token='return' + && + (return_stmt_var = return_stmt_rule(p)) // return_stmt + ) + { + res = return_stmt_var; + goto done; + } + p->mark = mark; + } + { // &('import' | 'from') import_stmt + stmt_ty import_stmt_var; + if ( + _PyPegen_lookahead(1, _tmp_14_rule, p) + && + (import_stmt_var = import_stmt_rule(p)) // import_stmt + ) + { + res = import_stmt_var; + goto done; + } + p->mark = mark; + } + { // &'raise' raise_stmt + stmt_ty raise_stmt_var; + if ( + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 501) // token='raise' + && + (raise_stmt_var = raise_stmt_rule(p)) // raise_stmt + ) + { + res = raise_stmt_var; + goto done; + } + p->mark = mark; + } + { // 'pass' + Token * keyword; + if ( + (keyword = _PyPegen_expect_token(p, 502)) // token='pass' + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Pass ( EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // &'del' del_stmt + stmt_ty del_stmt_var; + if ( + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 503) // token='del' + && + (del_stmt_var = del_stmt_rule(p)) // del_stmt + ) + { + res = del_stmt_var; + goto done; + } + p->mark = mark; + } + { // &'yield' yield_stmt + stmt_ty yield_stmt_var; + if ( + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 504) // token='yield' + && + (yield_stmt_var = yield_stmt_rule(p)) // yield_stmt + ) + { + res = yield_stmt_var; + goto done; + } + p->mark = mark; + } + { // &'assert' assert_stmt + stmt_ty assert_stmt_var; + if ( + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 505) // token='assert' + && + (assert_stmt_var = assert_stmt_rule(p)) // assert_stmt + ) + { + res = assert_stmt_var; + goto done; + } + p->mark = mark; + } + { // 'break' + Token * keyword; + if ( + (keyword = _PyPegen_expect_token(p, 506)) // token='break' + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Break ( EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // 'continue' + Token * keyword; + if ( + (keyword = _PyPegen_expect_token(p, 507)) // token='continue' + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Continue ( EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // &'global' global_stmt + stmt_ty global_stmt_var; + if ( + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 508) // token='global' + && + (global_stmt_var = global_stmt_rule(p)) // global_stmt + ) + { + res = global_stmt_var; + goto done; + } + p->mark = mark; + } + { // &'nonlocal' nonlocal_stmt + stmt_ty nonlocal_stmt_var; + if ( + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 509) // token='nonlocal' + && + (nonlocal_stmt_var = nonlocal_stmt_rule(p)) // nonlocal_stmt + ) + { + res = nonlocal_stmt_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + _PyPegen_insert_memo(p, mark, small_stmt_type, res); + return res; +} + +// compound_stmt: +// | &('def' | '@' | ASYNC) function_def +// | &'if' if_stmt +// | &('class' | '@') class_def +// | &('with' | ASYNC) with_stmt +// | &('for' | ASYNC) for_stmt +// | &'try' try_stmt +// | &'while' while_stmt +static stmt_ty +compound_stmt_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + stmt_ty res = NULL; + int mark = p->mark; + { // &('def' | '@' | ASYNC) function_def + stmt_ty function_def_var; + if ( + _PyPegen_lookahead(1, _tmp_15_rule, p) + && + (function_def_var = function_def_rule(p)) // function_def + ) + { + res = function_def_var; + goto done; + } + p->mark = mark; + } + { // &'if' if_stmt + stmt_ty if_stmt_var; + if ( + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 510) // token='if' + && + (if_stmt_var = if_stmt_rule(p)) // if_stmt + ) + { + res = if_stmt_var; + goto done; + } + p->mark = mark; + } + { // &('class' | '@') class_def + stmt_ty class_def_var; + if ( + _PyPegen_lookahead(1, _tmp_16_rule, p) + && + (class_def_var = class_def_rule(p)) // class_def + ) + { + res = class_def_var; + goto done; + } + p->mark = mark; + } + { // &('with' | ASYNC) with_stmt + stmt_ty with_stmt_var; + if ( + _PyPegen_lookahead(1, _tmp_17_rule, p) + && + (with_stmt_var = with_stmt_rule(p)) // with_stmt + ) + { + res = with_stmt_var; + goto done; + } + p->mark = mark; + } + { // &('for' | ASYNC) for_stmt + stmt_ty for_stmt_var; + if ( + _PyPegen_lookahead(1, _tmp_18_rule, p) + && + (for_stmt_var = for_stmt_rule(p)) // for_stmt + ) + { + res = for_stmt_var; + goto done; + } + p->mark = mark; + } + { // &'try' try_stmt + stmt_ty try_stmt_var; + if ( + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 511) // token='try' + && + (try_stmt_var = try_stmt_rule(p)) // try_stmt + ) + { + res = try_stmt_var; + goto done; + } + p->mark = mark; + } + { // &'while' while_stmt + stmt_ty while_stmt_var; + if ( + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 512) // token='while' + && + (while_stmt_var = while_stmt_rule(p)) // while_stmt + ) + { + res = while_stmt_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// assignment: +// | NAME ':' expression ['=' annotated_rhs] +// | ('(' inside_paren_ann_assign_target ')' | ann_assign_subscript_attribute_target) ':' expression ['=' annotated_rhs] +// | ((star_targets '='))+ (yield_expr | star_expressions) TYPE_COMMENT? +// | target augassign (yield_expr | star_expressions) +// | invalid_assignment +static stmt_ty +assignment_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + stmt_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 ':' expression ['=' annotated_rhs] + expr_ty a; + expr_ty b; + void *c; + Token * literal; + if ( + (a = _PyPegen_name_token(p)) // NAME + && + (literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (b = expression_rule(p)) // expression + && + (c = _tmp_19_rule(p), 1) // ['=' annotated_rhs] + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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 = CHECK_VERSION ( 6 , "Variable annotation syntax is" , _Py_AnnAssign ( CHECK ( _PyPegen_set_expr_context ( p , a , Store ) ) , b , c , 1 , EXTRA ) ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // ('(' inside_paren_ann_assign_target ')' | ann_assign_subscript_attribute_target) ':' expression ['=' annotated_rhs] + void *a; + expr_ty b; + void *c; + Token * literal; + if ( + (a = _tmp_20_rule(p)) // '(' inside_paren_ann_assign_target ')' | ann_assign_subscript_attribute_target + && + (literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (b = expression_rule(p)) // expression + && + (c = _tmp_21_rule(p), 1) // ['=' annotated_rhs] + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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 = CHECK_VERSION ( 6 , "Variable annotations syntax is" , _Py_AnnAssign ( a , b , c , 0 , EXTRA ) ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // ((star_targets '='))+ (yield_expr | star_expressions) TYPE_COMMENT? + asdl_seq * a; + void *b; + void *tc; + if ( + (a = _loop1_22_rule(p)) // ((star_targets '='))+ + && + (b = _tmp_23_rule(p)) // yield_expr | star_expressions + && + (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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 , NEW_TYPE_COMMENT ( p , tc ) , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // target augassign (yield_expr | star_expressions) + expr_ty a; + AugOperator* b; + void *c; + if ( + (a = target_rule(p)) // target + && + (b = augassign_rule(p)) // augassign + && + (c = _tmp_24_rule(p)) // yield_expr | star_expressions + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_AugAssign ( a , b -> kind , c , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // invalid_assignment + void *invalid_assignment_var; + if ( + (invalid_assignment_var = invalid_assignment_rule(p)) // invalid_assignment + ) + { + res = invalid_assignment_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// augassign: +// | '+=' +// | '-=' +// | '*=' +// | '@=' +// | '/=' +// | '%=' +// | '&=' +// | '|=' +// | '^=' +// | '<<=' +// | '>>=' +// | '**=' +// | '//=' +static AugOperator* +augassign_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + AugOperator* res = NULL; + int mark = p->mark; + { // '+=' + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 36)) // token='+=' + ) + { + res = _PyPegen_augoperator ( p , Add ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // '-=' + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 37)) // token='-=' + ) + { + res = _PyPegen_augoperator ( p , Sub ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // '*=' + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 38)) // token='*=' + ) + { + res = _PyPegen_augoperator ( p , Mult ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // '@=' + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 50)) // token='@=' + ) + { + res = CHECK_VERSION ( 5 , "The '@' operator is" , _PyPegen_augoperator ( p , MatMult ) ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // '/=' + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 39)) // token='/=' + ) + { + res = _PyPegen_augoperator ( p , Div ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // '%=' + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 40)) // token='%=' + ) + { + res = _PyPegen_augoperator ( p , Mod ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // '&=' + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 41)) // token='&=' + ) + { + res = _PyPegen_augoperator ( p , BitAnd ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // '|=' + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 42)) // token='|=' + ) + { + res = _PyPegen_augoperator ( p , BitOr ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // '^=' + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 43)) // token='^=' + ) + { + res = _PyPegen_augoperator ( p , BitXor ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // '<<=' + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 44)) // token='<<=' + ) + { + res = _PyPegen_augoperator ( p , LShift ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // '>>=' + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 45)) // token='>>=' + ) + { + res = _PyPegen_augoperator ( p , RShift ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // '**=' + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 46)) // token='**=' + ) + { + res = _PyPegen_augoperator ( p , Pow ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // '//=' + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 48)) // token='//=' + ) + { + res = _PyPegen_augoperator ( p , FloorDiv ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// global_stmt: 'global' ','.NAME+ +static stmt_ty +global_stmt_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + stmt_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // 'global' ','.NAME+ + asdl_seq * a; + Token * keyword; + if ( + (keyword = _PyPegen_expect_token(p, 508)) // token='global' + && + (a = _gather_25_rule(p)) // ','.NAME+ + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Global ( CHECK ( _PyPegen_map_names_to_ids ( p , a ) ) , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// nonlocal_stmt: 'nonlocal' ','.NAME+ +static stmt_ty +nonlocal_stmt_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + stmt_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // 'nonlocal' ','.NAME+ + asdl_seq * a; + Token * keyword; + if ( + (keyword = _PyPegen_expect_token(p, 509)) // token='nonlocal' + && + (a = _gather_27_rule(p)) // ','.NAME+ + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Nonlocal ( CHECK ( _PyPegen_map_names_to_ids ( p , a ) ) , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// yield_stmt: yield_expr +static stmt_ty +yield_stmt_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + stmt_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // yield_expr + expr_ty y; + if ( + (y = yield_expr_rule(p)) // yield_expr + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Expr ( y , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// assert_stmt: 'assert' expression [',' expression] +static stmt_ty +assert_stmt_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + stmt_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // 'assert' expression [',' expression] + expr_ty a; + void *b; + Token * keyword; + if ( + (keyword = _PyPegen_expect_token(p, 505)) // token='assert' + && + (a = expression_rule(p)) // expression + && + (b = _tmp_29_rule(p), 1) // [',' expression] + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Assert ( a , b , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// del_stmt: 'del' del_targets +static stmt_ty +del_stmt_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + stmt_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // 'del' del_targets + asdl_seq* a; + Token * keyword; + if ( + (keyword = _PyPegen_expect_token(p, 503)) // token='del' + && + (a = del_targets_rule(p)) // del_targets + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Delete ( a , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// import_stmt: import_name | import_from +static stmt_ty +import_stmt_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + stmt_ty res = NULL; + int mark = p->mark; + { // import_name + stmt_ty import_name_var; + if ( + (import_name_var = import_name_rule(p)) // import_name + ) + { + res = import_name_var; + goto done; + } + p->mark = mark; + } + { // import_from + stmt_ty import_from_var; + if ( + (import_from_var = import_from_rule(p)) // import_from + ) + { + res = import_from_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// import_name: 'import' dotted_as_names +static stmt_ty +import_name_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + stmt_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // 'import' dotted_as_names + asdl_seq* a; + Token * keyword; + if ( + (keyword = _PyPegen_expect_token(p, 513)) // token='import' + && + (a = dotted_as_names_rule(p)) // dotted_as_names + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Import ( a , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// import_from: +// | 'from' (('.' | '...'))* dotted_name 'import' import_from_targets +// | 'from' (('.' | '...'))+ 'import' import_from_targets +static stmt_ty +import_from_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + stmt_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // 'from' (('.' | '...'))* dotted_name 'import' import_from_targets + asdl_seq * a; + expr_ty b; + asdl_seq* c; + Token * keyword; + Token * keyword_1; + if ( + (keyword = _PyPegen_expect_token(p, 514)) // token='from' + && + (a = _loop0_30_rule(p)) // (('.' | '...'))* + && + (b = dotted_name_rule(p)) // dotted_name + && + (keyword_1 = _PyPegen_expect_token(p, 513)) // token='import' + && + (c = import_from_targets_rule(p)) // import_from_targets + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_ImportFrom ( b -> v . Name . id , c , _PyPegen_seq_count_dots ( a ) , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // 'from' (('.' | '...'))+ 'import' import_from_targets + asdl_seq * a; + asdl_seq* b; + Token * keyword; + Token * keyword_1; + if ( + (keyword = _PyPegen_expect_token(p, 514)) // token='from' + && + (a = _loop1_31_rule(p)) // (('.' | '...'))+ + && + (keyword_1 = _PyPegen_expect_token(p, 513)) // token='import' + && + (b = import_from_targets_rule(p)) // import_from_targets + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_ImportFrom ( NULL , b , _PyPegen_seq_count_dots ( a ) , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// import_from_targets: '(' import_from_as_names ','? ')' | import_from_as_names | '*' +static asdl_seq* +import_from_targets_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq* res = NULL; + int mark = p->mark; + { // '(' import_from_as_names ','? ')' + asdl_seq* a; + Token * literal; + Token * literal_1; + void *opt_var; + UNUSED(opt_var); // Silence compiler warnings + if ( + (literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (a = import_from_as_names_rule(p)) // import_from_as_names + && + (opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + && + (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + ) + { + res = a; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // import_from_as_names + asdl_seq* import_from_as_names_var; + if ( + (import_from_as_names_var = import_from_as_names_rule(p)) // import_from_as_names + ) + { + res = import_from_as_names_var; + goto done; + } + p->mark = mark; + } + { // '*' + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 16)) // token='*' + ) + { + res = _PyPegen_singleton_seq ( p , CHECK ( _PyPegen_alias_for_star ( p ) ) ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// import_from_as_names: ','.import_from_as_name+ +static asdl_seq* +import_from_as_names_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq* res = NULL; + int mark = p->mark; + { // ','.import_from_as_name+ + asdl_seq * a; + if ( + (a = _gather_32_rule(p)) // ','.import_from_as_name+ + ) + { + res = a; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// import_from_as_name: NAME ['as' NAME] +static alias_ty +import_from_as_name_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + alias_ty res = NULL; + int mark = p->mark; + { // NAME ['as' NAME] + expr_ty a; + void *b; + if ( + (a = _PyPegen_name_token(p)) // NAME + && + (b = _tmp_34_rule(p), 1) // ['as' NAME] + ) + { + res = _Py_alias ( a -> v . Name . id , ( b ) ? ( ( expr_ty ) b ) -> v . Name . id : NULL , p -> arena ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// dotted_as_names: ','.dotted_as_name+ +static asdl_seq* +dotted_as_names_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq* res = NULL; + int mark = p->mark; + { // ','.dotted_as_name+ + asdl_seq * a; + if ( + (a = _gather_35_rule(p)) // ','.dotted_as_name+ + ) + { + res = a; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// dotted_as_name: dotted_name ['as' NAME] +static alias_ty +dotted_as_name_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + alias_ty res = NULL; + int mark = p->mark; + { // dotted_name ['as' NAME] + expr_ty a; + void *b; + if ( + (a = dotted_name_rule(p)) // dotted_name + && + (b = _tmp_37_rule(p), 1) // ['as' NAME] + ) + { + res = _Py_alias ( a -> v . Name . id , ( b ) ? ( ( expr_ty ) b ) -> v . Name . id : NULL , p -> arena ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// Left-recursive +// dotted_name: dotted_name '.' NAME | NAME +static expr_ty dotted_name_raw(Parser *); +static expr_ty +dotted_name_rule(Parser *p) +{ + expr_ty res = NULL; + if (_PyPegen_is_memoized(p, dotted_name_type, &res)) + return res; + int mark = p->mark; + int resmark = p->mark; + while (1) { + int tmpvar_0 = _PyPegen_update_memo(p, mark, dotted_name_type, res); + if (tmpvar_0) { + return res; + } + p->mark = mark; + void *raw = dotted_name_raw(p); + if (raw == NULL || p->mark <= resmark) + break; + resmark = p->mark; + res = raw; + } + p->mark = resmark; + return res; +} +static expr_ty +dotted_name_raw(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + { // dotted_name '.' NAME + expr_ty a; + expr_ty b; + Token * literal; + if ( + (a = dotted_name_rule(p)) // dotted_name + && + (literal = _PyPegen_expect_token(p, 23)) // token='.' + && + (b = _PyPegen_name_token(p)) // NAME + ) + { + res = _PyPegen_join_names_with_dot ( p , a , b ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // NAME + expr_ty name_var; + if ( + (name_var = _PyPegen_name_token(p)) // NAME + ) + { + res = name_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// if_stmt: +// | 'if' named_expression ':' block elif_stmt +// | 'if' named_expression ':' block else_block? +static stmt_ty +if_stmt_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + stmt_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // 'if' named_expression ':' block elif_stmt + expr_ty a; + asdl_seq* b; + stmt_ty c; + Token * keyword; + Token * literal; + if ( + (keyword = _PyPegen_expect_token(p, 510)) // token='if' + && + (a = named_expression_rule(p)) // named_expression + && + (literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (b = block_rule(p)) // block + && + (c = elif_stmt_rule(p)) // elif_stmt + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_If ( a , b , CHECK ( _PyPegen_singleton_seq ( p , c ) ) , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // 'if' named_expression ':' block else_block? + expr_ty a; + asdl_seq* b; + void *c; + Token * keyword; + Token * literal; + if ( + (keyword = _PyPegen_expect_token(p, 510)) // token='if' + && + (a = named_expression_rule(p)) // named_expression + && + (literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (b = block_rule(p)) // block + && + (c = else_block_rule(p), 1) // else_block? + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_If ( a , b , c , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// elif_stmt: +// | 'elif' named_expression ':' block elif_stmt +// | 'elif' named_expression ':' block else_block? +static stmt_ty +elif_stmt_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + stmt_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // 'elif' named_expression ':' block elif_stmt + expr_ty a; + asdl_seq* b; + stmt_ty c; + Token * keyword; + Token * literal; + if ( + (keyword = _PyPegen_expect_token(p, 515)) // token='elif' + && + (a = named_expression_rule(p)) // named_expression + && + (literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (b = block_rule(p)) // block + && + (c = elif_stmt_rule(p)) // elif_stmt + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_If ( a , b , CHECK ( _PyPegen_singleton_seq ( p , c ) ) , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // 'elif' named_expression ':' block else_block? + expr_ty a; + asdl_seq* b; + void *c; + Token * keyword; + Token * literal; + if ( + (keyword = _PyPegen_expect_token(p, 515)) // token='elif' + && + (a = named_expression_rule(p)) // named_expression + && + (literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (b = block_rule(p)) // block + && + (c = else_block_rule(p), 1) // else_block? + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_If ( a , b , c , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// else_block: 'else' ':' block +static asdl_seq* +else_block_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq* res = NULL; + int mark = p->mark; + { // 'else' ':' block + asdl_seq* b; + Token * keyword; + Token * literal; + if ( + (keyword = _PyPegen_expect_token(p, 516)) // token='else' + && + (literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (b = block_rule(p)) // block + ) + { + res = b; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// while_stmt: 'while' named_expression ':' block else_block? +static stmt_ty +while_stmt_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + stmt_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // 'while' named_expression ':' block else_block? + expr_ty a; + asdl_seq* b; + void *c; + Token * keyword; + Token * literal; + if ( + (keyword = _PyPegen_expect_token(p, 512)) // token='while' + && + (a = named_expression_rule(p)) // named_expression + && + (literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (b = block_rule(p)) // block + && + (c = else_block_rule(p), 1) // else_block? + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_While ( a , b , c , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// for_stmt: +// | 'for' star_targets 'in' star_expressions ':' TYPE_COMMENT? block else_block? +// | ASYNC 'for' star_targets 'in' star_expressions ':' TYPE_COMMENT? block else_block? +static stmt_ty +for_stmt_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + stmt_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // 'for' star_targets 'in' star_expressions ':' TYPE_COMMENT? block else_block? + asdl_seq* b; + void *el; + expr_ty ex; + Token * keyword; + Token * keyword_1; + Token * literal; + expr_ty t; + void *tc; + if ( + (keyword = _PyPegen_expect_token(p, 517)) // token='for' + && + (t = star_targets_rule(p)) // star_targets + && + (keyword_1 = _PyPegen_expect_token(p, 518)) // token='in' + && + (ex = star_expressions_rule(p)) // star_expressions + && + (literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? + && + (b = block_rule(p)) // block + && + (el = else_block_rule(p), 1) // else_block? + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_For ( t , ex , b , el , NEW_TYPE_COMMENT ( p , tc ) , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // ASYNC 'for' star_targets 'in' star_expressions ':' TYPE_COMMENT? block else_block? + Token * async_var; + asdl_seq* b; + void *el; + expr_ty ex; + Token * keyword; + Token * keyword_1; + Token * literal; + expr_ty t; + void *tc; + if ( + (async_var = _PyPegen_expect_token(p, ASYNC)) // token='ASYNC' + && + (keyword = _PyPegen_expect_token(p, 517)) // token='for' + && + (t = star_targets_rule(p)) // star_targets + && + (keyword_1 = _PyPegen_expect_token(p, 518)) // token='in' + && + (ex = star_expressions_rule(p)) // star_expressions + && + (literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? + && + (b = block_rule(p)) // block + && + (el = else_block_rule(p), 1) // else_block? + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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 = CHECK_VERSION ( 5 , "Async for loops are" , _Py_AsyncFor ( t , ex , b , el , 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; +} + +// with_stmt: +// | 'with' '(' ','.with_item+ ','? ')' ':' block +// | 'with' ','.with_item+ ':' TYPE_COMMENT? block +// | ASYNC 'with' '(' ','.with_item+ ','? ')' ':' block +// | ASYNC 'with' ','.with_item+ ':' TYPE_COMMENT? block +static stmt_ty +with_stmt_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + stmt_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // 'with' '(' ','.with_item+ ','? ')' ':' block + asdl_seq * a; + asdl_seq* b; + Token * keyword; + Token * literal; + Token * literal_1; + Token * literal_2; + void *opt_var; + UNUSED(opt_var); // Silence compiler warnings + if ( + (keyword = _PyPegen_expect_token(p, 519)) // token='with' + && + (literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (a = _gather_38_rule(p)) // ','.with_item+ + && + (opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + && + (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + && + (literal_2 = _PyPegen_expect_token(p, 11)) // token=':' + && + (b = block_rule(p)) // block + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_With ( a , b , NULL , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // 'with' ','.with_item+ ':' TYPE_COMMENT? block + asdl_seq * a; + asdl_seq* b; + Token * keyword; + Token * literal; + void *tc; + if ( + (keyword = _PyPegen_expect_token(p, 519)) // token='with' + && + (a = _gather_40_rule(p)) // ','.with_item+ + && + (literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? + && + (b = block_rule(p)) // block + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_With ( a , b , NEW_TYPE_COMMENT ( p , tc ) , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // ASYNC 'with' '(' ','.with_item+ ','? ')' ':' block + asdl_seq * a; + Token * async_var; + asdl_seq* b; + Token * keyword; + Token * literal; + Token * literal_1; + Token * literal_2; + void *opt_var; + UNUSED(opt_var); // Silence compiler warnings + if ( + (async_var = _PyPegen_expect_token(p, ASYNC)) // token='ASYNC' + && + (keyword = _PyPegen_expect_token(p, 519)) // token='with' + && + (literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (a = _gather_42_rule(p)) // ','.with_item+ + && + (opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + && + (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + && + (literal_2 = _PyPegen_expect_token(p, 11)) // token=':' + && + (b = block_rule(p)) // block + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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 = CHECK_VERSION ( 5 , "Async with statements are" , _Py_AsyncWith ( a , b , NULL , EXTRA ) ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // ASYNC 'with' ','.with_item+ ':' TYPE_COMMENT? block + asdl_seq * a; + Token * async_var; + asdl_seq* b; + Token * keyword; + Token * literal; + void *tc; + if ( + (async_var = _PyPegen_expect_token(p, ASYNC)) // token='ASYNC' + && + (keyword = _PyPegen_expect_token(p, 519)) // token='with' + && + (a = _gather_44_rule(p)) // ','.with_item+ + && + (literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? + && + (b = block_rule(p)) // block + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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 = CHECK_VERSION ( 5 , "Async with statements are" , _Py_AsyncWith ( a , b , 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; +} + +// with_item: expression ['as' target] +static withitem_ty +with_item_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + withitem_ty res = NULL; + int mark = p->mark; + { // expression ['as' target] + expr_ty e; + void *o; + if ( + (e = expression_rule(p)) // expression + && + (o = _tmp_46_rule(p), 1) // ['as' target] + ) + { + res = _Py_withitem ( e , o , p -> arena ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// try_stmt: +// | 'try' ':' block finally_block +// | 'try' ':' block except_block+ else_block? finally_block? +static stmt_ty +try_stmt_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + stmt_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // 'try' ':' block finally_block + asdl_seq* b; + asdl_seq* f; + Token * keyword; + Token * literal; + if ( + (keyword = _PyPegen_expect_token(p, 511)) // token='try' + && + (literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (b = block_rule(p)) // block + && + (f = finally_block_rule(p)) // finally_block + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Try ( b , NULL , NULL , f , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // 'try' ':' block except_block+ else_block? finally_block? + asdl_seq* b; + void *el; + asdl_seq * ex; + void *f; + Token * keyword; + Token * literal; + if ( + (keyword = _PyPegen_expect_token(p, 511)) // token='try' + && + (literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (b = block_rule(p)) // block + && + (ex = _loop1_47_rule(p)) // except_block+ + && + (el = else_block_rule(p), 1) // else_block? + && + (f = finally_block_rule(p), 1) // finally_block? + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Try ( b , ex , el , f , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// except_block: 'except' expression ['as' target] ':' block | 'except' ':' block +static excepthandler_ty +except_block_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + excepthandler_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // 'except' expression ['as' target] ':' block + asdl_seq* b; + expr_ty e; + Token * keyword; + Token * literal; + void *t; + if ( + (keyword = _PyPegen_expect_token(p, 520)) // token='except' + && + (e = expression_rule(p)) // expression + && + (t = _tmp_48_rule(p), 1) // ['as' target] + && + (literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (b = block_rule(p)) // block + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_ExceptHandler ( e , ( t ) ? ( ( expr_ty ) t ) -> v . Name . id : NULL , b , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // 'except' ':' block + asdl_seq* b; + Token * keyword; + Token * literal; + if ( + (keyword = _PyPegen_expect_token(p, 520)) // token='except' + && + (literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (b = block_rule(p)) // block + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_ExceptHandler ( NULL , NULL , b , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// finally_block: 'finally' ':' block +static asdl_seq* +finally_block_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq* res = NULL; + int mark = p->mark; + { // 'finally' ':' block + asdl_seq* a; + Token * keyword; + Token * literal; + if ( + (keyword = _PyPegen_expect_token(p, 521)) // token='finally' + && + (literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (a = block_rule(p)) // block + ) + { + res = a; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// return_stmt: 'return' star_expressions? +static stmt_ty +return_stmt_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + stmt_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // 'return' star_expressions? + void *a; + Token * keyword; + if ( + (keyword = _PyPegen_expect_token(p, 500)) // token='return' + && + (a = star_expressions_rule(p), 1) // star_expressions? + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Return ( a , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// raise_stmt: 'raise' expression ['from' expression] | 'raise' +static stmt_ty +raise_stmt_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + stmt_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // 'raise' expression ['from' expression] + expr_ty a; + void *b; + Token * keyword; + if ( + (keyword = _PyPegen_expect_token(p, 501)) // token='raise' + && + (a = expression_rule(p)) // expression + && + (b = _tmp_49_rule(p), 1) // ['from' expression] + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Raise ( a , b , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // 'raise' + Token * keyword; + if ( + (keyword = _PyPegen_expect_token(p, 501)) // token='raise' + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Raise ( NULL , NULL , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// function_def: decorators function_def_raw | function_def_raw +static stmt_ty +function_def_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + stmt_ty res = NULL; + int mark = p->mark; + { // decorators function_def_raw + asdl_seq* d; + stmt_ty f; + if ( + (d = decorators_rule(p)) // decorators + && + (f = function_def_raw_rule(p)) // function_def_raw + ) + { + res = _PyPegen_function_def_decorators ( p , d , f ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // function_def_raw + stmt_ty function_def_raw_var; + if ( + (function_def_raw_var = function_def_raw_rule(p)) // function_def_raw + ) + { + res = function_def_raw_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// function_def_raw: +// | 'def' NAME '(' params? ')' ['->' expression] ':' func_type_comment? block +// | ASYNC 'def' NAME '(' params? ')' ['->' expression] ':' func_type_comment? block +static stmt_ty +function_def_raw_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + stmt_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // 'def' NAME '(' params? ')' ['->' expression] ':' func_type_comment? block + void *a; + asdl_seq* b; + Token * keyword; + Token * literal; + Token * literal_1; + Token * literal_2; + expr_ty n; + void *params; + void *tc; + if ( + (keyword = _PyPegen_expect_token(p, 522)) // token='def' + && + (n = _PyPegen_name_token(p)) // NAME + && + (literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (params = params_rule(p), 1) // params? + && + (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + && + (a = _tmp_50_rule(p), 1) // ['->' expression] + && + (literal_2 = _PyPegen_expect_token(p, 11)) // token=':' + && + (tc = func_type_comment_rule(p), 1) // func_type_comment? + && + (b = block_rule(p)) // block + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_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; + } + { // ASYNC 'def' NAME '(' params? ')' ['->' expression] ':' func_type_comment? block + void *a; + Token * async_var; + asdl_seq* b; + Token * keyword; + Token * literal; + Token * literal_1; + Token * literal_2; + expr_ty n; + void *params; + void *tc; + if ( + (async_var = _PyPegen_expect_token(p, ASYNC)) // token='ASYNC' + && + (keyword = _PyPegen_expect_token(p, 522)) // token='def' + && + (n = _PyPegen_name_token(p)) // NAME + && + (literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (params = params_rule(p), 1) // params? + && + (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + && + (a = _tmp_51_rule(p), 1) // ['->' expression] + && + (literal_2 = _PyPegen_expect_token(p, 11)) // token=':' + && + (tc = func_type_comment_rule(p), 1) // func_type_comment? + && + (b = block_rule(p)) // block + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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 = CHECK_VERSION ( 5 , "Async functions are" , _Py_AsyncFunctionDef ( 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 Token* +func_type_comment_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + Token* res = NULL; + int mark = p->mark; + { // NEWLINE TYPE_COMMENT &(NEWLINE INDENT) + Token * newline_var; + Token * t; + if ( + (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + && + (t = _PyPegen_expect_token(p, TYPE_COMMENT)) // token='TYPE_COMMENT' + && + _PyPegen_lookahead(1, _tmp_52_rule, p) + ) + { + res = t; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + 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)) // invalid_double_type_comments + ) + { + res = invalid_double_type_comments_var; + goto done; + } + p->mark = mark; + } + { // TYPE_COMMENT + Token * type_comment_var; + if ( + (type_comment_var = _PyPegen_expect_token(p, TYPE_COMMENT)) // token='TYPE_COMMENT' + ) + { + res = type_comment_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// params: invalid_parameters | parameters +static arguments_ty +params_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + arguments_ty res = NULL; + int mark = p->mark; + { // invalid_parameters + void *invalid_parameters_var; + if ( + (invalid_parameters_var = invalid_parameters_rule(p)) // invalid_parameters + ) + { + res = invalid_parameters_var; + goto done; + } + p->mark = mark; + } + { // parameters + arguments_ty parameters_var; + if ( + (parameters_var = parameters_rule(p)) // parameters + ) + { + res = parameters_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// parameters: +// | 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) +{ + if (p->error_indicator) { + return NULL; + } + arguments_ty res = NULL; + int mark = p->mark; + { // slash_no_default param_no_default* param_with_default* star_etc? + asdl_seq* a; + asdl_seq * b; + asdl_seq * c; + void *d; + if ( + (a = slash_no_default_rule(p)) // slash_no_default + && + (b = _loop0_53_rule(p)) // param_no_default* + && + (c = _loop0_54_rule(p)) // param_with_default* + && + (d = star_etc_rule(p), 1) // star_etc? + ) + { + res = _PyPegen_make_arguments ( p , a , NULL , b , c , d ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // slash_with_default param_with_default* star_etc? + SlashWithDefault* a; + asdl_seq * b; + void *c; + if ( + (a = slash_with_default_rule(p)) // slash_with_default + && + (b = _loop0_55_rule(p)) // param_with_default* + && + (c = star_etc_rule(p), 1) // star_etc? + ) + { + res = _PyPegen_make_arguments ( p , NULL , a , NULL , b , c ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // param_no_default+ param_with_default* star_etc? + asdl_seq * a; + asdl_seq * b; + void *c; + if ( + (a = _loop1_56_rule(p)) // param_no_default+ + && + (b = _loop0_57_rule(p)) // param_with_default* + && + (c = star_etc_rule(p), 1) // star_etc? + ) + { + res = _PyPegen_make_arguments ( p , NULL , NULL , a , b , c ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // param_with_default+ star_etc? + asdl_seq * a; + void *b; + if ( + (a = _loop1_58_rule(p)) // param_with_default+ + && + (b = star_etc_rule(p), 1) // star_etc? + ) + { + res = _PyPegen_make_arguments ( p , NULL , NULL , NULL , a , b ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // star_etc + StarEtc* a; + if ( + (a = star_etc_rule(p)) // star_etc + ) + { + res = _PyPegen_make_arguments ( p , NULL , NULL , NULL , NULL , a ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// slash_no_default: param_no_default+ '/' ',' | param_no_default+ '/' &')' +static asdl_seq* +slash_no_default_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq* res = NULL; + int mark = p->mark; + { // param_no_default+ '/' ',' + asdl_seq * a; + Token * literal; + Token * literal_1; + if ( + (a = _loop1_59_rule(p)) // param_no_default+ + && + (literal = _PyPegen_expect_token(p, 17)) // token='/' + && + (literal_1 = _PyPegen_expect_token(p, 12)) // token=',' + ) + { + res = a; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // param_no_default+ '/' &')' + asdl_seq * a; + Token * literal; + if ( + (a = _loop1_60_rule(p)) // param_no_default+ + && + (literal = _PyPegen_expect_token(p, 17)) // token='/' + && + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 8) // token=')' + ) + { + res = a; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// slash_with_default: +// | param_no_default* param_with_default+ '/' ',' +// | param_no_default* param_with_default+ '/' &')' +static SlashWithDefault* +slash_with_default_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + SlashWithDefault* res = NULL; + int mark = p->mark; + { // param_no_default* param_with_default+ '/' ',' + asdl_seq * a; + asdl_seq * b; + Token * literal; + Token * literal_1; + if ( + (a = _loop0_61_rule(p)) // param_no_default* + && + (b = _loop1_62_rule(p)) // param_with_default+ + && + (literal = _PyPegen_expect_token(p, 17)) // token='/' + && + (literal_1 = _PyPegen_expect_token(p, 12)) // token=',' + ) + { + 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; + Token * literal; + if ( + (a = _loop0_63_rule(p)) // param_no_default* + && + (b = _loop1_64_rule(p)) // param_with_default+ + && + (literal = _PyPegen_expect_token(p, 17)) // token='/' + && + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 8) // token=')' + ) + { + res = _PyPegen_slash_with_default ( p , a , b ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// star_etc: +// | '*' param_no_default param_maybe_default* kwds? +// | '*' ',' param_maybe_default+ kwds? +// | kwds +// | invalid_star_etc +static StarEtc* +star_etc_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + StarEtc* res = NULL; + int mark = p->mark; + { // '*' param_no_default param_maybe_default* kwds? + arg_ty a; + asdl_seq * b; + void *c; + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 16)) // token='*' + && + (a = param_no_default_rule(p)) // param_no_default + && + (b = _loop0_65_rule(p)) // param_maybe_default* + && + (c = kwds_rule(p), 1) // kwds? + ) + { + res = _PyPegen_star_etc ( p , a , b , c ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // '*' ',' param_maybe_default+ kwds? + asdl_seq * b; + void *c; + Token * literal; + Token * literal_1; + if ( + (literal = _PyPegen_expect_token(p, 16)) // token='*' + && + (literal_1 = _PyPegen_expect_token(p, 12)) // token=',' + && + (b = _loop1_66_rule(p)) // param_maybe_default+ + && + (c = kwds_rule(p), 1) // kwds? + ) + { + res = _PyPegen_star_etc ( p , NULL , b , c ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // kwds + arg_ty a; + if ( + (a = kwds_rule(p)) // kwds + ) + { + res = _PyPegen_star_etc ( p , NULL , NULL , a ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // invalid_star_etc + void *invalid_star_etc_var; + if ( + (invalid_star_etc_var = invalid_star_etc_rule(p)) // invalid_star_etc + ) + { + res = invalid_star_etc_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// kwds: '**' param_no_default +static arg_ty +kwds_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + arg_ty res = NULL; + int mark = p->mark; + { // '**' param_no_default + arg_ty a; + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 35)) // token='**' + && + (a = param_no_default_rule(p)) // param_no_default + ) + { + res = a; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// param_no_default: param ',' TYPE_COMMENT? | param TYPE_COMMENT? &')' +static arg_ty +param_no_default_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + arg_ty res = NULL; + int mark = p->mark; + { // param ',' TYPE_COMMENT? + arg_ty a; + Token * literal; + void *tc; + if ( + (a = param_rule(p)) // param + && + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? + ) + { + 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)) // param + && + (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? + && + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 8) // token=')' + ) + { + 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; + } + res = NULL; + done: + return res; +} + +// param_with_default: param default ',' TYPE_COMMENT? | param default TYPE_COMMENT? &')' +static NameDefaultPair* +param_with_default_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + NameDefaultPair* res = NULL; + int mark = p->mark; + { // param default ',' TYPE_COMMENT? + arg_ty a; + expr_ty c; + Token * literal; + void *tc; + if ( + (a = param_rule(p)) // param + && + (c = default_rule(p)) // default + && + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? + ) + { + 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)) // param + && + (c = default_rule(p)) // default + && + (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? + && + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 8) // token=')' + ) + { + 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; + } + res = NULL; + done: + return res; +} + +// 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; + } + NameDefaultPair* res = NULL; + int mark = p->mark; + { // param default? ',' TYPE_COMMENT? + arg_ty a; + void *c; + Token * literal; + void *tc; + if ( + (a = param_rule(p)) // param + && + (c = default_rule(p), 1) // default? + && + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? + ) + { + 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)) // param + && + (c = default_rule(p), 1) // default? + && + (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? + && + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 8) // token=')' + ) + { + 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; + } + res = NULL; + done: + return res; +} + +// param: NAME annotation? +static arg_ty +param_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + arg_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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? + expr_ty a; + void *b; + if ( + (a = _PyPegen_name_token(p)) // NAME + && + (b = annotation_rule(p), 1) // annotation? + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_arg ( a -> v . Name . id , b , NULL , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// annotation: ':' expression +static expr_ty +annotation_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + { // ':' expression + expr_ty a; + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (a = expression_rule(p)) // expression + ) + { + res = a; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// default: '=' expression +static expr_ty +default_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + { // '=' expression + expr_ty a; + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 22)) // token='=' + && + (a = expression_rule(p)) // expression + ) + { + res = a; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// decorators: (('@' named_expression NEWLINE))+ +static asdl_seq* +decorators_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq* res = NULL; + int mark = p->mark; + { // (('@' named_expression NEWLINE))+ + asdl_seq * a; + if ( + (a = _loop1_67_rule(p)) // (('@' named_expression NEWLINE))+ + ) + { + res = a; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// class_def: decorators class_def_raw | class_def_raw +static stmt_ty +class_def_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + stmt_ty res = NULL; + int mark = p->mark; + { // decorators class_def_raw + asdl_seq* a; + stmt_ty b; + if ( + (a = decorators_rule(p)) // decorators + && + (b = class_def_raw_rule(p)) // class_def_raw + ) + { + res = _PyPegen_class_def_decorators ( p , a , b ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // class_def_raw + stmt_ty class_def_raw_var; + if ( + (class_def_raw_var = class_def_raw_rule(p)) // class_def_raw + ) + { + res = class_def_raw_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// class_def_raw: 'class' NAME ['(' arguments? ')'] ':' block +static stmt_ty +class_def_raw_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + stmt_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // 'class' NAME ['(' arguments? ')'] ':' block + expr_ty a; + void *b; + asdl_seq* c; + Token * keyword; + Token * literal; + if ( + (keyword = _PyPegen_expect_token(p, 523)) // token='class' + && + (a = _PyPegen_name_token(p)) // NAME + && + (b = _tmp_68_rule(p), 1) // ['(' arguments? ')'] + && + (literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (c = block_rule(p)) // block + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_ClassDef ( a -> v . Name . id , ( b ) ? ( ( expr_ty ) b ) -> v . Call . args : NULL , ( b ) ? ( ( expr_ty ) b ) -> v . Call . keywords : NULL , c , NULL , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// block: NEWLINE INDENT statements DEDENT | simple_stmt | invalid_block +static asdl_seq* +block_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq* res = NULL; + if (_PyPegen_is_memoized(p, block_type, &res)) + return res; + int mark = p->mark; + { // NEWLINE INDENT statements DEDENT + asdl_seq* a; + Token * dedent_var; + Token * indent_var; + Token * newline_var; + if ( + (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + && + (indent_var = _PyPegen_expect_token(p, INDENT)) // token='INDENT' + && + (a = statements_rule(p)) // statements + && + (dedent_var = _PyPegen_expect_token(p, DEDENT)) // token='DEDENT' + ) + { + res = a; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // simple_stmt + asdl_seq* simple_stmt_var; + if ( + (simple_stmt_var = simple_stmt_rule(p)) // simple_stmt + ) + { + res = simple_stmt_var; + goto done; + } + p->mark = mark; + } + { // invalid_block + void *invalid_block_var; + if ( + (invalid_block_var = invalid_block_rule(p)) // invalid_block + ) + { + res = invalid_block_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + _PyPegen_insert_memo(p, mark, block_type, res); + return res; +} + +// expressions_list: ','.star_expression+ ','? +static asdl_seq* +expressions_list_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq* res = NULL; + int mark = p->mark; + { // ','.star_expression+ ','? + asdl_seq * a; + void *opt_var; + UNUSED(opt_var); // Silence compiler warnings + if ( + (a = _gather_69_rule(p)) // ','.star_expression+ + && + (opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + ) + { + res = a; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// star_expressions: +// | star_expression ((',' star_expression))+ ','? +// | star_expression ',' +// | star_expression +static expr_ty +star_expressions_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // star_expression ((',' star_expression))+ ','? + expr_ty a; + asdl_seq * b; + void *opt_var; + UNUSED(opt_var); // Silence compiler warnings + if ( + (a = star_expression_rule(p)) // star_expression + && + (b = _loop1_71_rule(p)) // ((',' star_expression))+ + && + (opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Tuple ( CHECK ( _PyPegen_seq_insert_in_front ( p , a , b ) ) , Load , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // star_expression ',' + expr_ty a; + Token * literal; + if ( + (a = star_expression_rule(p)) // star_expression + && + (literal = _PyPegen_expect_token(p, 12)) // token=',' + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Tuple ( CHECK ( _PyPegen_singleton_seq ( p , a ) ) , Load , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // star_expression + expr_ty star_expression_var; + if ( + (star_expression_var = star_expression_rule(p)) // star_expression + ) + { + res = star_expression_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// star_expression: '*' bitwise_or | expression +static expr_ty +star_expression_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + if (_PyPegen_is_memoized(p, star_expression_type, &res)) + return res; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // '*' bitwise_or + expr_ty a; + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 16)) // token='*' + && + (a = bitwise_or_rule(p)) // bitwise_or + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Starred ( a , Load , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // expression + expr_ty expression_var; + if ( + (expression_var = expression_rule(p)) // expression + ) + { + res = expression_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + _PyPegen_insert_memo(p, mark, star_expression_type, res); + return res; +} + +// star_named_expressions: ','.star_named_expression+ ','? +static asdl_seq* +star_named_expressions_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq* res = NULL; + int mark = p->mark; + { // ','.star_named_expression+ ','? + asdl_seq * a; + void *opt_var; + UNUSED(opt_var); // Silence compiler warnings + if ( + (a = _gather_72_rule(p)) // ','.star_named_expression+ + && + (opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + ) + { + res = a; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// star_named_expression: '*' bitwise_or | named_expression +static expr_ty +star_named_expression_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // '*' bitwise_or + expr_ty a; + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 16)) // token='*' + && + (a = bitwise_or_rule(p)) // bitwise_or + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Starred ( a , Load , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // named_expression + expr_ty named_expression_var; + if ( + (named_expression_var = named_expression_rule(p)) // named_expression + ) + { + res = named_expression_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// named_expression: NAME ':=' expression | expression !':=' | invalid_named_expression +static expr_ty +named_expression_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 ':=' expression + expr_ty a; + expr_ty b; + Token * literal; + if ( + (a = _PyPegen_name_token(p)) // NAME + && + (literal = _PyPegen_expect_token(p, 53)) // token=':=' + && + (b = expression_rule(p)) // expression + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_NamedExpr ( CHECK ( _PyPegen_set_expr_context ( p , a , Store ) ) , b , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // expression !':=' + expr_ty expression_var; + if ( + (expression_var = expression_rule(p)) // expression + && + _PyPegen_lookahead_with_int(0, _PyPegen_expect_token, p, 53) // token=':=' + ) + { + res = expression_var; + goto done; + } + p->mark = mark; + } + { // invalid_named_expression + void *invalid_named_expression_var; + if ( + (invalid_named_expression_var = invalid_named_expression_rule(p)) // invalid_named_expression + ) + { + res = invalid_named_expression_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// annotated_rhs: yield_expr | star_expressions +static expr_ty +annotated_rhs_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + { // yield_expr + expr_ty yield_expr_var; + if ( + (yield_expr_var = yield_expr_rule(p)) // yield_expr + ) + { + res = yield_expr_var; + goto done; + } + p->mark = mark; + } + { // star_expressions + expr_ty star_expressions_var; + if ( + (star_expressions_var = star_expressions_rule(p)) // star_expressions + ) + { + res = star_expressions_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// expressions: expression ((',' expression))+ ','? | expression ',' | expression +static expr_ty +expressions_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // expression ((',' expression))+ ','? + expr_ty a; + asdl_seq * b; + void *opt_var; + UNUSED(opt_var); // Silence compiler warnings + if ( + (a = expression_rule(p)) // expression + && + (b = _loop1_74_rule(p)) // ((',' expression))+ + && + (opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Tuple ( CHECK ( _PyPegen_seq_insert_in_front ( p , a , b ) ) , Load , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // expression ',' + expr_ty a; + Token * literal; + if ( + (a = expression_rule(p)) // expression + && + (literal = _PyPegen_expect_token(p, 12)) // token=',' + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Tuple ( CHECK ( _PyPegen_singleton_seq ( p , a ) ) , Load , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // expression + expr_ty expression_var; + if ( + (expression_var = expression_rule(p)) // expression + ) + { + res = expression_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// expression: disjunction 'if' disjunction 'else' expression | disjunction | lambdef +static expr_ty +expression_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + if (_PyPegen_is_memoized(p, expression_type, &res)) + return res; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // disjunction 'if' disjunction 'else' expression + expr_ty a; + expr_ty b; + expr_ty c; + Token * keyword; + Token * keyword_1; + if ( + (a = disjunction_rule(p)) // disjunction + && + (keyword = _PyPegen_expect_token(p, 510)) // token='if' + && + (b = disjunction_rule(p)) // disjunction + && + (keyword_1 = _PyPegen_expect_token(p, 516)) // token='else' + && + (c = expression_rule(p)) // expression + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_IfExp ( b , a , c , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // disjunction + expr_ty disjunction_var; + if ( + (disjunction_var = disjunction_rule(p)) // disjunction + ) + { + res = disjunction_var; + goto done; + } + p->mark = mark; + } + { // lambdef + expr_ty lambdef_var; + if ( + (lambdef_var = lambdef_rule(p)) // lambdef + ) + { + res = lambdef_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + _PyPegen_insert_memo(p, mark, expression_type, res); + return res; +} + +// lambdef: 'lambda' lambda_parameters? ':' expression +static expr_ty +lambdef_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // 'lambda' lambda_parameters? ':' expression + void *a; + expr_ty b; + Token * keyword; + Token * literal; + if ( + (keyword = _PyPegen_expect_token(p, 524)) // token='lambda' + && + (a = lambda_parameters_rule(p), 1) // lambda_parameters? + && + (literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (b = expression_rule(p)) // expression + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Lambda ( ( a ) ? a : CHECK ( _PyPegen_empty_arguments ( p ) ) , b , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// lambda_parameters: +// | lambda_slash_no_default lambda_param_no_default* lambda_param_with_default* lambda_star_etc? +// | lambda_slash_with_default lambda_param_with_default* lambda_star_etc? +// | lambda_param_no_default+ lambda_param_with_default* lambda_star_etc? +// | lambda_param_with_default+ lambda_star_etc? +// | lambda_star_etc +static arguments_ty +lambda_parameters_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + arguments_ty res = NULL; + int mark = p->mark; + { // lambda_slash_no_default lambda_param_no_default* lambda_param_with_default* lambda_star_etc? + asdl_seq* a; + asdl_seq * b; + asdl_seq * c; + void *d; + if ( + (a = lambda_slash_no_default_rule(p)) // lambda_slash_no_default + && + (b = _loop0_75_rule(p)) // lambda_param_no_default* + && + (c = _loop0_76_rule(p)) // lambda_param_with_default* + && + (d = lambda_star_etc_rule(p), 1) // lambda_star_etc? + ) + { + res = _PyPegen_make_arguments ( p , a , NULL , b , c , d ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // lambda_slash_with_default lambda_param_with_default* lambda_star_etc? + SlashWithDefault* a; + asdl_seq * b; + void *c; + if ( + (a = lambda_slash_with_default_rule(p)) // lambda_slash_with_default + && + (b = _loop0_77_rule(p)) // lambda_param_with_default* + && + (c = lambda_star_etc_rule(p), 1) // lambda_star_etc? + ) + { + res = _PyPegen_make_arguments ( p , NULL , a , NULL , b , c ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // lambda_param_no_default+ lambda_param_with_default* lambda_star_etc? + asdl_seq * a; + asdl_seq * b; + void *c; + if ( + (a = _loop1_78_rule(p)) // lambda_param_no_default+ + && + (b = _loop0_79_rule(p)) // lambda_param_with_default* + && + (c = lambda_star_etc_rule(p), 1) // lambda_star_etc? + ) + { + res = _PyPegen_make_arguments ( p , NULL , NULL , a , b , c ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // lambda_param_with_default+ lambda_star_etc? + asdl_seq * a; + void *b; + if ( + (a = _loop1_80_rule(p)) // lambda_param_with_default+ + && + (b = lambda_star_etc_rule(p), 1) // lambda_star_etc? + ) + { + res = _PyPegen_make_arguments ( p , NULL , NULL , NULL , a , b ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // lambda_star_etc + StarEtc* a; + if ( + (a = lambda_star_etc_rule(p)) // lambda_star_etc + ) + { + res = _PyPegen_make_arguments ( p , NULL , NULL , NULL , NULL , a ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// lambda_slash_no_default: +// | lambda_param_no_default+ '/' ',' +// | lambda_param_no_default+ '/' &':' +static asdl_seq* +lambda_slash_no_default_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq* res = NULL; + int mark = p->mark; + { // lambda_param_no_default+ '/' ',' + asdl_seq * a; + Token * literal; + Token * literal_1; + if ( + (a = _loop1_81_rule(p)) // lambda_param_no_default+ + && + (literal = _PyPegen_expect_token(p, 17)) // token='/' + && + (literal_1 = _PyPegen_expect_token(p, 12)) // token=',' + ) + { + res = a; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // lambda_param_no_default+ '/' &':' + asdl_seq * a; + Token * literal; + if ( + (a = _loop1_82_rule(p)) // lambda_param_no_default+ + && + (literal = _PyPegen_expect_token(p, 17)) // token='/' + && + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 11) // token=':' + ) + { + res = a; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// lambda_slash_with_default: +// | lambda_param_no_default* lambda_param_with_default+ '/' ',' +// | lambda_param_no_default* lambda_param_with_default+ '/' &':' +static SlashWithDefault* +lambda_slash_with_default_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + SlashWithDefault* res = NULL; + int mark = p->mark; + { // lambda_param_no_default* lambda_param_with_default+ '/' ',' + asdl_seq * a; + asdl_seq * b; + Token * literal; + Token * literal_1; + if ( + (a = _loop0_83_rule(p)) // lambda_param_no_default* + && + (b = _loop1_84_rule(p)) // lambda_param_with_default+ + && + (literal = _PyPegen_expect_token(p, 17)) // token='/' + && + (literal_1 = _PyPegen_expect_token(p, 12)) // token=',' + ) + { + res = _PyPegen_slash_with_default ( p , a , b ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // lambda_param_no_default* lambda_param_with_default+ '/' &':' + asdl_seq * a; + asdl_seq * b; + Token * literal; + if ( + (a = _loop0_85_rule(p)) // lambda_param_no_default* + && + (b = _loop1_86_rule(p)) // lambda_param_with_default+ + && + (literal = _PyPegen_expect_token(p, 17)) // token='/' + && + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 11) // token=':' + ) + { + res = _PyPegen_slash_with_default ( p , a , b ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// lambda_star_etc: +// | '*' lambda_param_no_default lambda_param_maybe_default* lambda_kwds? +// | '*' ',' lambda_param_maybe_default+ lambda_kwds? +// | lambda_kwds +// | invalid_lambda_star_etc +static StarEtc* +lambda_star_etc_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + StarEtc* res = NULL; + int mark = p->mark; + { // '*' lambda_param_no_default lambda_param_maybe_default* lambda_kwds? + arg_ty a; + asdl_seq * b; + void *c; + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 16)) // token='*' + && + (a = lambda_param_no_default_rule(p)) // lambda_param_no_default + && + (b = _loop0_87_rule(p)) // lambda_param_maybe_default* + && + (c = lambda_kwds_rule(p), 1) // lambda_kwds? + ) + { + res = _PyPegen_star_etc ( p , a , b , c ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // '*' ',' lambda_param_maybe_default+ lambda_kwds? + asdl_seq * b; + void *c; + Token * literal; + Token * literal_1; + if ( + (literal = _PyPegen_expect_token(p, 16)) // token='*' + && + (literal_1 = _PyPegen_expect_token(p, 12)) // token=',' + && + (b = _loop1_88_rule(p)) // lambda_param_maybe_default+ + && + (c = lambda_kwds_rule(p), 1) // lambda_kwds? + ) + { + res = _PyPegen_star_etc ( p , NULL , b , c ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // lambda_kwds + arg_ty a; + if ( + (a = lambda_kwds_rule(p)) // lambda_kwds + ) + { + res = _PyPegen_star_etc ( p , NULL , NULL , a ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // invalid_lambda_star_etc + void *invalid_lambda_star_etc_var; + if ( + (invalid_lambda_star_etc_var = invalid_lambda_star_etc_rule(p)) // invalid_lambda_star_etc + ) + { + res = invalid_lambda_star_etc_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// lambda_kwds: '**' lambda_param_no_default +static arg_ty +lambda_kwds_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + arg_ty res = NULL; + int mark = p->mark; + { // '**' lambda_param_no_default + arg_ty a; + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 35)) // token='**' + && + (a = lambda_param_no_default_rule(p)) // lambda_param_no_default + ) + { + res = a; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// lambda_param_no_default: lambda_param ',' | lambda_param &':' +static arg_ty +lambda_param_no_default_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + arg_ty res = NULL; + int mark = p->mark; + { // lambda_param ',' + arg_ty a; + Token * literal; + if ( + (a = lambda_param_rule(p)) // lambda_param + && + (literal = _PyPegen_expect_token(p, 12)) // token=',' + ) + { + res = a; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // lambda_param &':' + arg_ty a; + if ( + (a = lambda_param_rule(p)) // lambda_param + && + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 11) // token=':' + ) + { + res = a; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// lambda_param_with_default: lambda_param default ',' | lambda_param default &':' +static NameDefaultPair* +lambda_param_with_default_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + NameDefaultPair* res = NULL; + int mark = p->mark; + { // lambda_param default ',' + arg_ty a; + expr_ty c; + Token * literal; + if ( + (a = lambda_param_rule(p)) // lambda_param + && + (c = default_rule(p)) // default + && + (literal = _PyPegen_expect_token(p, 12)) // token=',' + ) + { + res = _PyPegen_name_default_pair ( p , a , c , NULL ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // lambda_param default &':' + arg_ty a; + expr_ty c; + if ( + (a = lambda_param_rule(p)) // lambda_param + && + (c = default_rule(p)) // default + && + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 11) // token=':' + ) + { + res = _PyPegen_name_default_pair ( p , a , c , NULL ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// lambda_param_maybe_default: lambda_param default? ',' | lambda_param default? &':' +static NameDefaultPair* +lambda_param_maybe_default_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + NameDefaultPair* res = NULL; + int mark = p->mark; + { // lambda_param default? ',' + arg_ty a; + void *c; + Token * literal; + if ( + (a = lambda_param_rule(p)) // lambda_param + && + (c = default_rule(p), 1) // default? + && + (literal = _PyPegen_expect_token(p, 12)) // token=',' + ) + { + res = _PyPegen_name_default_pair ( p , a , c , NULL ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // lambda_param default? &':' + arg_ty a; + void *c; + if ( + (a = lambda_param_rule(p)) // lambda_param + && + (c = default_rule(p), 1) // default? + && + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 11) // token=':' + ) + { + res = _PyPegen_name_default_pair ( p , a , c , NULL ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// lambda_param: NAME +static arg_ty +lambda_param_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + arg_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + expr_ty a; + if ( + (a = _PyPegen_name_token(p)) // NAME + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_arg ( a -> v . Name . id , NULL , NULL , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// disjunction: conjunction (('or' conjunction))+ | conjunction +static expr_ty +disjunction_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + if (_PyPegen_is_memoized(p, disjunction_type, &res)) + return res; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // conjunction (('or' conjunction))+ + expr_ty a; + asdl_seq * b; + if ( + (a = conjunction_rule(p)) // conjunction + && + (b = _loop1_89_rule(p)) // (('or' conjunction))+ + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_BoolOp ( Or , CHECK ( _PyPegen_seq_insert_in_front ( p , a , b ) ) , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // conjunction + expr_ty conjunction_var; + if ( + (conjunction_var = conjunction_rule(p)) // conjunction + ) + { + res = conjunction_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + _PyPegen_insert_memo(p, mark, disjunction_type, res); + return res; +} + +// conjunction: inversion (('and' inversion))+ | inversion +static expr_ty +conjunction_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + if (_PyPegen_is_memoized(p, conjunction_type, &res)) + return res; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // inversion (('and' inversion))+ + expr_ty a; + asdl_seq * b; + if ( + (a = inversion_rule(p)) // inversion + && + (b = _loop1_90_rule(p)) // (('and' inversion))+ + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_BoolOp ( And , CHECK ( _PyPegen_seq_insert_in_front ( p , a , b ) ) , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // inversion + expr_ty inversion_var; + if ( + (inversion_var = inversion_rule(p)) // inversion + ) + { + res = inversion_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + _PyPegen_insert_memo(p, mark, conjunction_type, res); + return res; +} + +// inversion: 'not' inversion | comparison +static expr_ty +inversion_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + if (_PyPegen_is_memoized(p, inversion_type, &res)) + return res; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // 'not' inversion + expr_ty a; + Token * keyword; + if ( + (keyword = _PyPegen_expect_token(p, 525)) // token='not' + && + (a = inversion_rule(p)) // inversion + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_UnaryOp ( Not , a , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // comparison + expr_ty comparison_var; + if ( + (comparison_var = comparison_rule(p)) // comparison + ) + { + res = comparison_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + _PyPegen_insert_memo(p, mark, inversion_type, res); + return res; +} + +// comparison: bitwise_or compare_op_bitwise_or_pair+ | bitwise_or +static expr_ty +comparison_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // bitwise_or compare_op_bitwise_or_pair+ + expr_ty a; + asdl_seq * b; + if ( + (a = bitwise_or_rule(p)) // bitwise_or + && + (b = _loop1_91_rule(p)) // compare_op_bitwise_or_pair+ + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Compare ( a , CHECK ( _PyPegen_get_cmpops ( p , b ) ) , CHECK ( _PyPegen_get_exprs ( p , b ) ) , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // bitwise_or + expr_ty bitwise_or_var; + if ( + (bitwise_or_var = bitwise_or_rule(p)) // bitwise_or + ) + { + res = bitwise_or_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// compare_op_bitwise_or_pair: +// | eq_bitwise_or +// | noteq_bitwise_or +// | lte_bitwise_or +// | lt_bitwise_or +// | gte_bitwise_or +// | gt_bitwise_or +// | notin_bitwise_or +// | in_bitwise_or +// | isnot_bitwise_or +// | is_bitwise_or +static CmpopExprPair* +compare_op_bitwise_or_pair_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + CmpopExprPair* res = NULL; + int mark = p->mark; + { // eq_bitwise_or + CmpopExprPair* eq_bitwise_or_var; + if ( + (eq_bitwise_or_var = eq_bitwise_or_rule(p)) // eq_bitwise_or + ) + { + res = eq_bitwise_or_var; + goto done; + } + p->mark = mark; + } + { // noteq_bitwise_or + CmpopExprPair* noteq_bitwise_or_var; + if ( + (noteq_bitwise_or_var = noteq_bitwise_or_rule(p)) // noteq_bitwise_or + ) + { + res = noteq_bitwise_or_var; + goto done; + } + p->mark = mark; + } + { // lte_bitwise_or + CmpopExprPair* lte_bitwise_or_var; + if ( + (lte_bitwise_or_var = lte_bitwise_or_rule(p)) // lte_bitwise_or + ) + { + res = lte_bitwise_or_var; + goto done; + } + p->mark = mark; + } + { // lt_bitwise_or + CmpopExprPair* lt_bitwise_or_var; + if ( + (lt_bitwise_or_var = lt_bitwise_or_rule(p)) // lt_bitwise_or + ) + { + res = lt_bitwise_or_var; + goto done; + } + p->mark = mark; + } + { // gte_bitwise_or + CmpopExprPair* gte_bitwise_or_var; + if ( + (gte_bitwise_or_var = gte_bitwise_or_rule(p)) // gte_bitwise_or + ) + { + res = gte_bitwise_or_var; + goto done; + } + p->mark = mark; + } + { // gt_bitwise_or + CmpopExprPair* gt_bitwise_or_var; + if ( + (gt_bitwise_or_var = gt_bitwise_or_rule(p)) // gt_bitwise_or + ) + { + res = gt_bitwise_or_var; + goto done; + } + p->mark = mark; + } + { // notin_bitwise_or + CmpopExprPair* notin_bitwise_or_var; + if ( + (notin_bitwise_or_var = notin_bitwise_or_rule(p)) // notin_bitwise_or + ) + { + res = notin_bitwise_or_var; + goto done; + } + p->mark = mark; + } + { // in_bitwise_or + CmpopExprPair* in_bitwise_or_var; + if ( + (in_bitwise_or_var = in_bitwise_or_rule(p)) // in_bitwise_or + ) + { + res = in_bitwise_or_var; + goto done; + } + p->mark = mark; + } + { // isnot_bitwise_or + CmpopExprPair* isnot_bitwise_or_var; + if ( + (isnot_bitwise_or_var = isnot_bitwise_or_rule(p)) // isnot_bitwise_or + ) + { + res = isnot_bitwise_or_var; + goto done; + } + p->mark = mark; + } + { // is_bitwise_or + CmpopExprPair* is_bitwise_or_var; + if ( + (is_bitwise_or_var = is_bitwise_or_rule(p)) // is_bitwise_or + ) + { + res = is_bitwise_or_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// eq_bitwise_or: '==' bitwise_or +static CmpopExprPair* +eq_bitwise_or_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + CmpopExprPair* res = NULL; + int mark = p->mark; + { // '==' bitwise_or + expr_ty a; + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 27)) // token='==' + && + (a = bitwise_or_rule(p)) // bitwise_or + ) + { + res = _PyPegen_cmpop_expr_pair ( p , Eq , a ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// noteq_bitwise_or: ('!=') bitwise_or +static CmpopExprPair* +noteq_bitwise_or_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + CmpopExprPair* res = NULL; + int mark = p->mark; + { // ('!=') bitwise_or + void *_tmp_92_var; + expr_ty a; + if ( + (_tmp_92_var = _tmp_92_rule(p)) // '!=' + && + (a = bitwise_or_rule(p)) // bitwise_or + ) + { + res = _PyPegen_cmpop_expr_pair ( p , NotEq , a ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// lte_bitwise_or: '<=' bitwise_or +static CmpopExprPair* +lte_bitwise_or_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + CmpopExprPair* res = NULL; + int mark = p->mark; + { // '<=' bitwise_or + expr_ty a; + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 29)) // token='<=' + && + (a = bitwise_or_rule(p)) // bitwise_or + ) + { + res = _PyPegen_cmpop_expr_pair ( p , LtE , a ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// lt_bitwise_or: '<' bitwise_or +static CmpopExprPair* +lt_bitwise_or_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + CmpopExprPair* res = NULL; + int mark = p->mark; + { // '<' bitwise_or + expr_ty a; + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 20)) // token='<' + && + (a = bitwise_or_rule(p)) // bitwise_or + ) + { + res = _PyPegen_cmpop_expr_pair ( p , Lt , a ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// gte_bitwise_or: '>=' bitwise_or +static CmpopExprPair* +gte_bitwise_or_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + CmpopExprPair* res = NULL; + int mark = p->mark; + { // '>=' bitwise_or + expr_ty a; + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 30)) // token='>=' + && + (a = bitwise_or_rule(p)) // bitwise_or + ) + { + res = _PyPegen_cmpop_expr_pair ( p , GtE , a ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// gt_bitwise_or: '>' bitwise_or +static CmpopExprPair* +gt_bitwise_or_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + CmpopExprPair* res = NULL; + int mark = p->mark; + { // '>' bitwise_or + expr_ty a; + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 21)) // token='>' + && + (a = bitwise_or_rule(p)) // bitwise_or + ) + { + res = _PyPegen_cmpop_expr_pair ( p , Gt , a ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// notin_bitwise_or: 'not' 'in' bitwise_or +static CmpopExprPair* +notin_bitwise_or_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + CmpopExprPair* res = NULL; + int mark = p->mark; + { // 'not' 'in' bitwise_or + expr_ty a; + Token * keyword; + Token * keyword_1; + if ( + (keyword = _PyPegen_expect_token(p, 525)) // token='not' + && + (keyword_1 = _PyPegen_expect_token(p, 518)) // token='in' + && + (a = bitwise_or_rule(p)) // bitwise_or + ) + { + res = _PyPegen_cmpop_expr_pair ( p , NotIn , a ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// in_bitwise_or: 'in' bitwise_or +static CmpopExprPair* +in_bitwise_or_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + CmpopExprPair* res = NULL; + int mark = p->mark; + { // 'in' bitwise_or + expr_ty a; + Token * keyword; + if ( + (keyword = _PyPegen_expect_token(p, 518)) // token='in' + && + (a = bitwise_or_rule(p)) // bitwise_or + ) + { + res = _PyPegen_cmpop_expr_pair ( p , In , a ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// isnot_bitwise_or: 'is' 'not' bitwise_or +static CmpopExprPair* +isnot_bitwise_or_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + CmpopExprPair* res = NULL; + int mark = p->mark; + { // 'is' 'not' bitwise_or + expr_ty a; + Token * keyword; + Token * keyword_1; + if ( + (keyword = _PyPegen_expect_token(p, 526)) // token='is' + && + (keyword_1 = _PyPegen_expect_token(p, 525)) // token='not' + && + (a = bitwise_or_rule(p)) // bitwise_or + ) + { + res = _PyPegen_cmpop_expr_pair ( p , IsNot , a ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// is_bitwise_or: 'is' bitwise_or +static CmpopExprPair* +is_bitwise_or_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + CmpopExprPair* res = NULL; + int mark = p->mark; + { // 'is' bitwise_or + expr_ty a; + Token * keyword; + if ( + (keyword = _PyPegen_expect_token(p, 526)) // token='is' + && + (a = bitwise_or_rule(p)) // bitwise_or + ) + { + res = _PyPegen_cmpop_expr_pair ( p , Is , a ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// Left-recursive +// bitwise_or: bitwise_or '|' bitwise_xor | bitwise_xor +static expr_ty bitwise_or_raw(Parser *); +static expr_ty +bitwise_or_rule(Parser *p) +{ + expr_ty res = NULL; + if (_PyPegen_is_memoized(p, bitwise_or_type, &res)) + return res; + int mark = p->mark; + int resmark = p->mark; + while (1) { + int tmpvar_1 = _PyPegen_update_memo(p, mark, bitwise_or_type, res); + if (tmpvar_1) { + return res; + } + p->mark = mark; + void *raw = bitwise_or_raw(p); + if (raw == NULL || p->mark <= resmark) + break; + resmark = p->mark; + res = raw; + } + p->mark = resmark; + return res; +} +static expr_ty +bitwise_or_raw(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // bitwise_or '|' bitwise_xor + expr_ty a; + expr_ty b; + Token * literal; + if ( + (a = bitwise_or_rule(p)) // bitwise_or + && + (literal = _PyPegen_expect_token(p, 18)) // token='|' + && + (b = bitwise_xor_rule(p)) // bitwise_xor + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_BinOp ( a , BitOr , b , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // bitwise_xor + expr_ty bitwise_xor_var; + if ( + (bitwise_xor_var = bitwise_xor_rule(p)) // bitwise_xor + ) + { + res = bitwise_xor_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// Left-recursive +// bitwise_xor: bitwise_xor '^' bitwise_and | bitwise_and +static expr_ty bitwise_xor_raw(Parser *); +static expr_ty +bitwise_xor_rule(Parser *p) +{ + expr_ty res = NULL; + if (_PyPegen_is_memoized(p, bitwise_xor_type, &res)) + return res; + int mark = p->mark; + int resmark = p->mark; + while (1) { + int tmpvar_2 = _PyPegen_update_memo(p, mark, bitwise_xor_type, res); + if (tmpvar_2) { + return res; + } + p->mark = mark; + void *raw = bitwise_xor_raw(p); + if (raw == NULL || p->mark <= resmark) + break; + resmark = p->mark; + res = raw; + } + p->mark = resmark; + return res; +} +static expr_ty +bitwise_xor_raw(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // bitwise_xor '^' bitwise_and + expr_ty a; + expr_ty b; + Token * literal; + if ( + (a = bitwise_xor_rule(p)) // bitwise_xor + && + (literal = _PyPegen_expect_token(p, 32)) // token='^' + && + (b = bitwise_and_rule(p)) // bitwise_and + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_BinOp ( a , BitXor , b , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // bitwise_and + expr_ty bitwise_and_var; + if ( + (bitwise_and_var = bitwise_and_rule(p)) // bitwise_and + ) + { + res = bitwise_and_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// Left-recursive +// bitwise_and: bitwise_and '&' shift_expr | shift_expr +static expr_ty bitwise_and_raw(Parser *); +static expr_ty +bitwise_and_rule(Parser *p) +{ + expr_ty res = NULL; + if (_PyPegen_is_memoized(p, bitwise_and_type, &res)) + return res; + int mark = p->mark; + int resmark = p->mark; + while (1) { + int tmpvar_3 = _PyPegen_update_memo(p, mark, bitwise_and_type, res); + if (tmpvar_3) { + return res; + } + p->mark = mark; + void *raw = bitwise_and_raw(p); + if (raw == NULL || p->mark <= resmark) + break; + resmark = p->mark; + res = raw; + } + p->mark = resmark; + return res; +} +static expr_ty +bitwise_and_raw(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // bitwise_and '&' shift_expr + expr_ty a; + expr_ty b; + Token * literal; + if ( + (a = bitwise_and_rule(p)) // bitwise_and + && + (literal = _PyPegen_expect_token(p, 19)) // token='&' + && + (b = shift_expr_rule(p)) // shift_expr + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_BinOp ( a , BitAnd , b , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // shift_expr + expr_ty shift_expr_var; + if ( + (shift_expr_var = shift_expr_rule(p)) // shift_expr + ) + { + res = shift_expr_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// Left-recursive +// shift_expr: shift_expr '<<' sum | shift_expr '>>' sum | sum +static expr_ty shift_expr_raw(Parser *); +static expr_ty +shift_expr_rule(Parser *p) +{ + expr_ty res = NULL; + if (_PyPegen_is_memoized(p, shift_expr_type, &res)) + return res; + int mark = p->mark; + int resmark = p->mark; + while (1) { + int tmpvar_4 = _PyPegen_update_memo(p, mark, shift_expr_type, res); + if (tmpvar_4) { + return res; + } + p->mark = mark; + void *raw = shift_expr_raw(p); + if (raw == NULL || p->mark <= resmark) + break; + resmark = p->mark; + res = raw; + } + p->mark = resmark; + return res; +} +static expr_ty +shift_expr_raw(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // shift_expr '<<' sum + expr_ty a; + expr_ty b; + Token * literal; + if ( + (a = shift_expr_rule(p)) // shift_expr + && + (literal = _PyPegen_expect_token(p, 33)) // token='<<' + && + (b = sum_rule(p)) // sum + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_BinOp ( a , LShift , b , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // shift_expr '>>' sum + expr_ty a; + expr_ty b; + Token * literal; + if ( + (a = shift_expr_rule(p)) // shift_expr + && + (literal = _PyPegen_expect_token(p, 34)) // token='>>' + && + (b = sum_rule(p)) // sum + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_BinOp ( a , RShift , b , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // sum + expr_ty sum_var; + if ( + (sum_var = sum_rule(p)) // sum + ) + { + res = sum_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// Left-recursive +// sum: sum '+' term | sum '-' term | term +static expr_ty sum_raw(Parser *); +static expr_ty +sum_rule(Parser *p) +{ + expr_ty res = NULL; + if (_PyPegen_is_memoized(p, sum_type, &res)) + return res; + int mark = p->mark; + int resmark = p->mark; + while (1) { + int tmpvar_5 = _PyPegen_update_memo(p, mark, sum_type, res); + if (tmpvar_5) { + return res; + } + p->mark = mark; + void *raw = sum_raw(p); + if (raw == NULL || p->mark <= resmark) + break; + resmark = p->mark; + res = raw; + } + p->mark = resmark; + return res; +} +static expr_ty +sum_raw(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // sum '+' term + expr_ty a; + expr_ty b; + Token * literal; + if ( + (a = sum_rule(p)) // sum + && + (literal = _PyPegen_expect_token(p, 14)) // token='+' + && + (b = term_rule(p)) // term + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_BinOp ( a , Add , b , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // sum '-' term + expr_ty a; + expr_ty b; + Token * literal; + if ( + (a = sum_rule(p)) // sum + && + (literal = _PyPegen_expect_token(p, 15)) // token='-' + && + (b = term_rule(p)) // term + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_BinOp ( a , Sub , b , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // term + expr_ty term_var; + if ( + (term_var = term_rule(p)) // term + ) + { + res = term_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// Left-recursive +// term: +// | term '*' factor +// | term '/' factor +// | term '//' factor +// | term '%' factor +// | term '@' factor +// | factor +static expr_ty term_raw(Parser *); +static expr_ty +term_rule(Parser *p) +{ + expr_ty res = NULL; + if (_PyPegen_is_memoized(p, term_type, &res)) + return res; + int mark = p->mark; + int resmark = p->mark; + while (1) { + int tmpvar_6 = _PyPegen_update_memo(p, mark, term_type, res); + if (tmpvar_6) { + return res; + } + p->mark = mark; + void *raw = term_raw(p); + if (raw == NULL || p->mark <= resmark) + break; + resmark = p->mark; + res = raw; + } + p->mark = resmark; + return res; +} +static expr_ty +term_raw(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // term '*' factor + expr_ty a; + expr_ty b; + Token * literal; + if ( + (a = term_rule(p)) // term + && + (literal = _PyPegen_expect_token(p, 16)) // token='*' + && + (b = factor_rule(p)) // factor + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_BinOp ( a , Mult , b , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // term '/' factor + expr_ty a; + expr_ty b; + Token * literal; + if ( + (a = term_rule(p)) // term + && + (literal = _PyPegen_expect_token(p, 17)) // token='/' + && + (b = factor_rule(p)) // factor + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_BinOp ( a , Div , b , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // term '//' factor + expr_ty a; + expr_ty b; + Token * literal; + if ( + (a = term_rule(p)) // term + && + (literal = _PyPegen_expect_token(p, 47)) // token='//' + && + (b = factor_rule(p)) // factor + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_BinOp ( a , FloorDiv , b , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // term '%' factor + expr_ty a; + expr_ty b; + Token * literal; + if ( + (a = term_rule(p)) // term + && + (literal = _PyPegen_expect_token(p, 24)) // token='%' + && + (b = factor_rule(p)) // factor + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_BinOp ( a , Mod , b , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // term '@' factor + expr_ty a; + expr_ty b; + Token * literal; + if ( + (a = term_rule(p)) // term + && + (literal = _PyPegen_expect_token(p, 49)) // token='@' + && + (b = factor_rule(p)) // factor + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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 = CHECK_VERSION ( 5 , "The '@' operator is" , _Py_BinOp ( a , MatMult , b , EXTRA ) ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // factor + expr_ty factor_var; + if ( + (factor_var = factor_rule(p)) // factor + ) + { + res = factor_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// factor: '+' factor | '-' factor | '~' factor | power +static expr_ty +factor_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + if (_PyPegen_is_memoized(p, factor_type, &res)) + return res; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // '+' factor + expr_ty a; + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 14)) // token='+' + && + (a = factor_rule(p)) // factor + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_UnaryOp ( UAdd , a , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // '-' factor + expr_ty a; + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 15)) // token='-' + && + (a = factor_rule(p)) // factor + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_UnaryOp ( USub , a , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // '~' factor + expr_ty a; + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 31)) // token='~' + && + (a = factor_rule(p)) // factor + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_UnaryOp ( Invert , a , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // power + expr_ty power_var; + if ( + (power_var = power_rule(p)) // power + ) + { + res = power_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + _PyPegen_insert_memo(p, mark, factor_type, res); + return res; +} + +// power: await_primary '**' factor | await_primary +static expr_ty +power_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // await_primary '**' factor + expr_ty a; + expr_ty b; + Token * literal; + if ( + (a = await_primary_rule(p)) // await_primary + && + (literal = _PyPegen_expect_token(p, 35)) // token='**' + && + (b = factor_rule(p)) // factor + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_BinOp ( a , Pow , b , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // await_primary + expr_ty await_primary_var; + if ( + (await_primary_var = await_primary_rule(p)) // await_primary + ) + { + res = await_primary_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// await_primary: AWAIT primary | primary +static expr_ty +await_primary_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + if (_PyPegen_is_memoized(p, await_primary_type, &res)) + return res; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // AWAIT primary + expr_ty a; + Token * await_var; + if ( + (await_var = _PyPegen_expect_token(p, AWAIT)) // token='AWAIT' + && + (a = primary_rule(p)) // primary + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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 = CHECK_VERSION ( 5 , "Await expressions are" , _Py_Await ( a , EXTRA ) ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // primary + expr_ty primary_var; + if ( + (primary_var = primary_rule(p)) // primary + ) + { + res = primary_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + _PyPegen_insert_memo(p, mark, await_primary_type, res); + return res; +} + +// Left-recursive +// primary: +// | primary '.' NAME +// | primary genexp +// | primary '(' arguments? ')' +// | primary '[' slices ']' +// | atom +static expr_ty primary_raw(Parser *); +static expr_ty +primary_rule(Parser *p) +{ + expr_ty res = NULL; + if (_PyPegen_is_memoized(p, primary_type, &res)) + return res; + int mark = p->mark; + int resmark = p->mark; + while (1) { + int tmpvar_7 = _PyPegen_update_memo(p, mark, primary_type, res); + if (tmpvar_7) { + return res; + } + p->mark = mark; + void *raw = primary_raw(p); + if (raw == NULL || p->mark <= resmark) + break; + resmark = p->mark; + res = raw; + } + p->mark = resmark; + return res; +} +static expr_ty +primary_raw(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // primary '.' NAME + expr_ty a; + expr_ty b; + Token * literal; + if ( + (a = primary_rule(p)) // primary + && + (literal = _PyPegen_expect_token(p, 23)) // token='.' + && + (b = _PyPegen_name_token(p)) // NAME + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Attribute ( a , b -> v . Name . id , Load , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // primary genexp + expr_ty a; + expr_ty b; + if ( + (a = primary_rule(p)) // primary + && + (b = genexp_rule(p)) // genexp + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Call ( a , CHECK ( _PyPegen_singleton_seq ( p , b ) ) , NULL , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // primary '(' arguments? ')' + expr_ty a; + void *b; + Token * literal; + Token * literal_1; + if ( + (a = primary_rule(p)) // primary + && + (literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (b = arguments_rule(p), 1) // arguments? + && + (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Call ( a , ( b ) ? ( ( expr_ty ) b ) -> v . Call . args : NULL , ( b ) ? ( ( expr_ty ) b ) -> v . Call . keywords : NULL , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // primary '[' slices ']' + expr_ty a; + expr_ty b; + Token * literal; + Token * literal_1; + if ( + (a = primary_rule(p)) // primary + && + (literal = _PyPegen_expect_token(p, 9)) // token='[' + && + (b = slices_rule(p)) // slices + && + (literal_1 = _PyPegen_expect_token(p, 10)) // token=']' + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Subscript ( a , b , Load , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // atom + expr_ty atom_var; + if ( + (atom_var = atom_rule(p)) // atom + ) + { + res = atom_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// slices: slice !',' | ','.slice+ ','? +static expr_ty +slices_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // slice !',' + expr_ty a; + if ( + (a = slice_rule(p)) // slice + && + _PyPegen_lookahead_with_int(0, _PyPegen_expect_token, p, 12) // token=',' + ) + { + res = a; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // ','.slice+ ','? + asdl_seq * a; + void *opt_var; + UNUSED(opt_var); // Silence compiler warnings + if ( + (a = _gather_93_rule(p)) // ','.slice+ + && + (opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Tuple ( a , Load , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// slice: expression? ':' expression? [':' expression?] | expression +static expr_ty +slice_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // expression? ':' expression? [':' expression?] + void *a; + void *b; + void *c; + Token * literal; + if ( + (a = expression_rule(p), 1) // expression? + && + (literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (b = expression_rule(p), 1) // expression? + && + (c = _tmp_95_rule(p), 1) // [':' expression?] + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Slice ( a , b , c , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // expression + expr_ty a; + if ( + (a = expression_rule(p)) // expression + ) + { + res = a; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// atom: +// | NAME +// | 'True' +// | 'False' +// | 'None' +// | '__new_parser__' +// | &STRING strings +// | NUMBER +// | &'(' (tuple | group | genexp) +// | &'[' (list | listcomp) +// | &'{' (dict | set | dictcomp | setcomp) +// | '...' +static expr_ty +atom_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + expr_ty name_var; + if ( + (name_var = _PyPegen_name_token(p)) // NAME + ) + { + res = name_var; + goto done; + } + p->mark = mark; + } + { // 'True' + Token * keyword; + if ( + (keyword = _PyPegen_expect_token(p, 527)) // token='True' + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Constant ( Py_True , NULL , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // 'False' + Token * keyword; + if ( + (keyword = _PyPegen_expect_token(p, 528)) // token='False' + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Constant ( Py_False , NULL , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // 'None' + Token * keyword; + if ( + (keyword = _PyPegen_expect_token(p, 529)) // token='None' + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Constant ( Py_None , NULL , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // '__new_parser__' + Token * keyword; + if ( + (keyword = _PyPegen_expect_token(p, 530)) // token='__new_parser__' + ) + { + res = RAISE_SYNTAX_ERROR ( "You found it!" ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // &STRING strings + expr_ty strings_var; + if ( + _PyPegen_lookahead(1, _PyPegen_string_token, p) + && + (strings_var = strings_rule(p)) // strings + ) + { + res = strings_var; + goto done; + } + p->mark = mark; + } + { // NUMBER + expr_ty number_var; + if ( + (number_var = _PyPegen_number_token(p)) // NUMBER + ) + { + res = number_var; + goto done; + } + p->mark = mark; + } + { // &'(' (tuple | group | genexp) + void *_tmp_96_var; + if ( + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 7) // token='(' + && + (_tmp_96_var = _tmp_96_rule(p)) // tuple | group | genexp + ) + { + res = _tmp_96_var; + goto done; + } + p->mark = mark; + } + { // &'[' (list | listcomp) + void *_tmp_97_var; + if ( + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 9) // token='[' + && + (_tmp_97_var = _tmp_97_rule(p)) // list | listcomp + ) + { + res = _tmp_97_var; + goto done; + } + p->mark = mark; + } + { // &'{' (dict | set | dictcomp | setcomp) + void *_tmp_98_var; + if ( + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 25) // token='{' + && + (_tmp_98_var = _tmp_98_rule(p)) // dict | set | dictcomp | setcomp + ) + { + res = _tmp_98_var; + goto done; + } + p->mark = mark; + } + { // '...' + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 52)) // token='...' + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Constant ( Py_Ellipsis , NULL , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// strings: STRING+ +static expr_ty +strings_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + if (_PyPegen_is_memoized(p, strings_type, &res)) + return res; + int mark = p->mark; + { // STRING+ + asdl_seq * a; + if ( + (a = _loop1_99_rule(p)) // STRING+ + ) + { + res = _PyPegen_concatenate_strings ( p , a ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + _PyPegen_insert_memo(p, mark, strings_type, res); + return res; +} + +// list: '[' star_named_expressions? ']' +static expr_ty +list_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // '[' star_named_expressions? ']' + void *a; + Token * literal; + Token * literal_1; + if ( + (literal = _PyPegen_expect_token(p, 9)) // token='[' + && + (a = star_named_expressions_rule(p), 1) // star_named_expressions? + && + (literal_1 = _PyPegen_expect_token(p, 10)) // token=']' + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_List ( a , Load , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// listcomp: '[' named_expression for_if_clauses ']' | invalid_comprehension +static expr_ty +listcomp_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // '[' named_expression for_if_clauses ']' + expr_ty a; + asdl_seq* b; + Token * literal; + Token * literal_1; + if ( + (literal = _PyPegen_expect_token(p, 9)) // token='[' + && + (a = named_expression_rule(p)) // named_expression + && + (b = for_if_clauses_rule(p)) // for_if_clauses + && + (literal_1 = _PyPegen_expect_token(p, 10)) // token=']' + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_ListComp ( a , b , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // invalid_comprehension + void *invalid_comprehension_var; + if ( + (invalid_comprehension_var = invalid_comprehension_rule(p)) // invalid_comprehension + ) + { + res = invalid_comprehension_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// tuple: '(' [star_named_expression ',' star_named_expressions?] ')' +static expr_ty +tuple_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // '(' [star_named_expression ',' star_named_expressions?] ')' + void *a; + Token * literal; + Token * literal_1; + if ( + (literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (a = _tmp_100_rule(p), 1) // [star_named_expression ',' star_named_expressions?] + && + (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Tuple ( a , Load , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// group: '(' (yield_expr | named_expression) ')' +static expr_ty +group_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + { // '(' (yield_expr | named_expression) ')' + void *a; + Token * literal; + Token * literal_1; + if ( + (literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (a = _tmp_101_rule(p)) // yield_expr | named_expression + && + (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + ) + { + res = a; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// genexp: '(' expression for_if_clauses ')' | invalid_comprehension +static expr_ty +genexp_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // '(' expression for_if_clauses ')' + expr_ty a; + asdl_seq* b; + Token * literal; + Token * literal_1; + if ( + (literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (a = expression_rule(p)) // expression + && + (b = for_if_clauses_rule(p)) // for_if_clauses + && + (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_GeneratorExp ( a , b , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // invalid_comprehension + void *invalid_comprehension_var; + if ( + (invalid_comprehension_var = invalid_comprehension_rule(p)) // invalid_comprehension + ) + { + res = invalid_comprehension_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// set: '{' expressions_list '}' +static expr_ty +set_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // '{' expressions_list '}' + asdl_seq* a; + Token * literal; + Token * literal_1; + if ( + (literal = _PyPegen_expect_token(p, 25)) // token='{' + && + (a = expressions_list_rule(p)) // expressions_list + && + (literal_1 = _PyPegen_expect_token(p, 26)) // token='}' + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Set ( a , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// setcomp: '{' expression for_if_clauses '}' | invalid_comprehension +static expr_ty +setcomp_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // '{' expression for_if_clauses '}' + expr_ty a; + asdl_seq* b; + Token * literal; + Token * literal_1; + if ( + (literal = _PyPegen_expect_token(p, 25)) // token='{' + && + (a = expression_rule(p)) // expression + && + (b = for_if_clauses_rule(p)) // for_if_clauses + && + (literal_1 = _PyPegen_expect_token(p, 26)) // token='}' + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_SetComp ( a , b , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // invalid_comprehension + void *invalid_comprehension_var; + if ( + (invalid_comprehension_var = invalid_comprehension_rule(p)) // invalid_comprehension + ) + { + res = invalid_comprehension_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// dict: '{' kvpairs? '}' +static expr_ty +dict_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // '{' kvpairs? '}' + void *a; + Token * literal; + Token * literal_1; + if ( + (literal = _PyPegen_expect_token(p, 25)) // token='{' + && + (a = kvpairs_rule(p), 1) // kvpairs? + && + (literal_1 = _PyPegen_expect_token(p, 26)) // token='}' + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Dict ( CHECK ( _PyPegen_get_keys ( p , a ) ) , CHECK ( _PyPegen_get_values ( p , a ) ) , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// dictcomp: '{' kvpair for_if_clauses '}' +static expr_ty +dictcomp_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // '{' kvpair for_if_clauses '}' + KeyValuePair* a; + asdl_seq* b; + Token * literal; + Token * literal_1; + if ( + (literal = _PyPegen_expect_token(p, 25)) // token='{' + && + (a = kvpair_rule(p)) // kvpair + && + (b = for_if_clauses_rule(p)) // for_if_clauses + && + (literal_1 = _PyPegen_expect_token(p, 26)) // token='}' + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_DictComp ( a -> key , a -> value , b , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// kvpairs: ','.kvpair+ ','? +static asdl_seq* +kvpairs_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq* res = NULL; + int mark = p->mark; + { // ','.kvpair+ ','? + asdl_seq * a; + void *opt_var; + UNUSED(opt_var); // Silence compiler warnings + if ( + (a = _gather_102_rule(p)) // ','.kvpair+ + && + (opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + ) + { + res = a; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// kvpair: '**' bitwise_or | expression ':' expression +static KeyValuePair* +kvpair_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + KeyValuePair* res = NULL; + int mark = p->mark; + { // '**' bitwise_or + expr_ty a; + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 35)) // token='**' + && + (a = bitwise_or_rule(p)) // bitwise_or + ) + { + res = _PyPegen_key_value_pair ( p , NULL , a ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // expression ':' expression + expr_ty a; + expr_ty b; + Token * literal; + if ( + (a = expression_rule(p)) // expression + && + (literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (b = expression_rule(p)) // expression + ) + { + res = _PyPegen_key_value_pair ( p , a , b ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// for_if_clauses: for_if_clause+ +static asdl_seq* +for_if_clauses_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq* res = NULL; + int mark = p->mark; + { // for_if_clause+ + asdl_seq * _loop1_104_var; + if ( + (_loop1_104_var = _loop1_104_rule(p)) // for_if_clause+ + ) + { + res = _loop1_104_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// for_if_clause: +// | ASYNC 'for' star_targets 'in' disjunction (('if' disjunction))* +// | 'for' star_targets 'in' disjunction (('if' disjunction))* +static comprehension_ty +for_if_clause_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + comprehension_ty res = NULL; + int mark = p->mark; + { // ASYNC 'for' star_targets 'in' disjunction (('if' disjunction))* + expr_ty a; + Token * async_var; + expr_ty b; + asdl_seq * c; + Token * keyword; + Token * keyword_1; + if ( + (async_var = _PyPegen_expect_token(p, ASYNC)) // token='ASYNC' + && + (keyword = _PyPegen_expect_token(p, 517)) // token='for' + && + (a = star_targets_rule(p)) // star_targets + && + (keyword_1 = _PyPegen_expect_token(p, 518)) // token='in' + && + (b = disjunction_rule(p)) // disjunction + && + (c = _loop0_105_rule(p)) // (('if' disjunction))* + ) + { + res = CHECK_VERSION ( 6 , "Async comprehensions are" , _Py_comprehension ( a , b , c , 1 , p -> arena ) ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // 'for' star_targets 'in' disjunction (('if' disjunction))* + expr_ty a; + expr_ty b; + asdl_seq * c; + Token * keyword; + Token * keyword_1; + if ( + (keyword = _PyPegen_expect_token(p, 517)) // token='for' + && + (a = star_targets_rule(p)) // star_targets + && + (keyword_1 = _PyPegen_expect_token(p, 518)) // token='in' + && + (b = disjunction_rule(p)) // disjunction + && + (c = _loop0_106_rule(p)) // (('if' disjunction))* + ) + { + res = _Py_comprehension ( a , b , c , 0 , p -> arena ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// yield_expr: 'yield' 'from' expression | 'yield' star_expressions? +static expr_ty +yield_expr_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // 'yield' 'from' expression + expr_ty a; + Token * keyword; + Token * keyword_1; + if ( + (keyword = _PyPegen_expect_token(p, 504)) // token='yield' + && + (keyword_1 = _PyPegen_expect_token(p, 514)) // token='from' + && + (a = expression_rule(p)) // expression + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_YieldFrom ( a , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // 'yield' star_expressions? + void *a; + Token * keyword; + if ( + (keyword = _PyPegen_expect_token(p, 504)) // token='yield' + && + (a = star_expressions_rule(p), 1) // star_expressions? + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Yield ( a , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// arguments: args ','? &')' | incorrect_arguments +static expr_ty +arguments_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + if (_PyPegen_is_memoized(p, arguments_type, &res)) + return res; + int mark = p->mark; + { // args ','? &')' + expr_ty a; + void *opt_var; + UNUSED(opt_var); // Silence compiler warnings + if ( + (a = args_rule(p)) // args + && + (opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + && + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 8) // token=')' + ) + { + res = a; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // incorrect_arguments + void *incorrect_arguments_var; + if ( + (incorrect_arguments_var = incorrect_arguments_rule(p)) // incorrect_arguments + ) + { + res = incorrect_arguments_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + _PyPegen_insert_memo(p, mark, arguments_type, res); + return res; +} + +// args: starred_expression [',' args] | kwargs | named_expression [',' args] +static expr_ty +args_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // starred_expression [',' args] + expr_ty a; + void *b; + if ( + (a = starred_expression_rule(p)) // starred_expression + && + (b = _tmp_107_rule(p), 1) // [',' args] + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Call ( _PyPegen_dummy_name ( p ) , ( b ) ? CHECK ( _PyPegen_seq_insert_in_front ( p , a , ( ( expr_ty ) b ) -> v . Call . args ) ) : CHECK ( _PyPegen_singleton_seq ( p , a ) ) , ( b ) ? ( ( expr_ty ) b ) -> v . Call . keywords : NULL , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // kwargs + asdl_seq* a; + if ( + (a = kwargs_rule(p)) // kwargs + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Call ( _PyPegen_dummy_name ( p ) , CHECK_NULL_ALLOWED ( _PyPegen_seq_extract_starred_exprs ( p , a ) ) , CHECK_NULL_ALLOWED ( _PyPegen_seq_delete_starred_exprs ( p , a ) ) , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // named_expression [',' args] + expr_ty a; + void *b; + if ( + (a = named_expression_rule(p)) // named_expression + && + (b = _tmp_108_rule(p), 1) // [',' args] + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Call ( _PyPegen_dummy_name ( p ) , ( b ) ? CHECK ( _PyPegen_seq_insert_in_front ( p , a , ( ( expr_ty ) b ) -> v . Call . args ) ) : CHECK ( _PyPegen_singleton_seq ( p , a ) ) , ( b ) ? ( ( expr_ty ) b ) -> v . Call . keywords : NULL , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// kwargs: +// | ','.kwarg_or_starred+ ',' ','.kwarg_or_double_starred+ +// | ','.kwarg_or_starred+ +// | ','.kwarg_or_double_starred+ +static asdl_seq* +kwargs_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq* res = NULL; + int mark = p->mark; + { // ','.kwarg_or_starred+ ',' ','.kwarg_or_double_starred+ + asdl_seq * a; + asdl_seq * b; + Token * literal; + if ( + (a = _gather_109_rule(p)) // ','.kwarg_or_starred+ + && + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (b = _gather_111_rule(p)) // ','.kwarg_or_double_starred+ + ) + { + res = _PyPegen_join_sequences ( p , a , b ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // ','.kwarg_or_starred+ + asdl_seq * _gather_113_var; + if ( + (_gather_113_var = _gather_113_rule(p)) // ','.kwarg_or_starred+ + ) + { + res = _gather_113_var; + goto done; + } + p->mark = mark; + } + { // ','.kwarg_or_double_starred+ + asdl_seq * _gather_115_var; + if ( + (_gather_115_var = _gather_115_rule(p)) // ','.kwarg_or_double_starred+ + ) + { + res = _gather_115_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// starred_expression: '*' expression +static expr_ty +starred_expression_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // '*' expression + expr_ty a; + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 16)) // token='*' + && + (a = expression_rule(p)) // expression + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Starred ( a , Load , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// kwarg_or_starred: NAME '=' expression | starred_expression | invalid_kwarg +static KeywordOrStarred* +kwarg_or_starred_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + KeywordOrStarred* res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 '=' expression + expr_ty a; + expr_ty b; + Token * literal; + if ( + (a = _PyPegen_name_token(p)) // NAME + && + (literal = _PyPegen_expect_token(p, 22)) // token='=' + && + (b = expression_rule(p)) // expression + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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 = _PyPegen_keyword_or_starred ( p , CHECK ( _Py_keyword ( a -> v . Name . id , b , EXTRA ) ) , 1 ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // starred_expression + expr_ty a; + if ( + (a = starred_expression_rule(p)) // starred_expression + ) + { + res = _PyPegen_keyword_or_starred ( p , a , 0 ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // invalid_kwarg + void *invalid_kwarg_var; + if ( + (invalid_kwarg_var = invalid_kwarg_rule(p)) // invalid_kwarg + ) + { + res = invalid_kwarg_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// kwarg_or_double_starred: NAME '=' expression | '**' expression | invalid_kwarg +static KeywordOrStarred* +kwarg_or_double_starred_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + KeywordOrStarred* res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 '=' expression + expr_ty a; + expr_ty b; + Token * literal; + if ( + (a = _PyPegen_name_token(p)) // NAME + && + (literal = _PyPegen_expect_token(p, 22)) // token='=' + && + (b = expression_rule(p)) // expression + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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 = _PyPegen_keyword_or_starred ( p , CHECK ( _Py_keyword ( a -> v . Name . id , b , EXTRA ) ) , 1 ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // '**' expression + expr_ty a; + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 35)) // token='**' + && + (a = expression_rule(p)) // expression + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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 = _PyPegen_keyword_or_starred ( p , CHECK ( _Py_keyword ( NULL , a , EXTRA ) ) , 1 ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // invalid_kwarg + void *invalid_kwarg_var; + if ( + (invalid_kwarg_var = invalid_kwarg_rule(p)) // invalid_kwarg + ) + { + res = invalid_kwarg_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// star_targets: star_target !',' | star_target ((',' star_target))* ','? +static expr_ty +star_targets_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // star_target !',' + expr_ty a; + if ( + (a = star_target_rule(p)) // star_target + && + _PyPegen_lookahead_with_int(0, _PyPegen_expect_token, p, 12) // token=',' + ) + { + res = a; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // star_target ((',' star_target))* ','? + expr_ty a; + asdl_seq * b; + void *opt_var; + UNUSED(opt_var); // Silence compiler warnings + if ( + (a = star_target_rule(p)) // star_target + && + (b = _loop0_117_rule(p)) // ((',' star_target))* + && + (opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Tuple ( CHECK ( _PyPegen_seq_insert_in_front ( p , a , b ) ) , Store , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// star_targets_seq: ','.star_target+ ','? +static asdl_seq* +star_targets_seq_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq* res = NULL; + int mark = p->mark; + { // ','.star_target+ ','? + asdl_seq * a; + void *opt_var; + UNUSED(opt_var); // Silence compiler warnings + if ( + (a = _gather_118_rule(p)) // ','.star_target+ + && + (opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + ) + { + res = a; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// star_target: +// | '*' (!'*' star_target) +// | t_primary '.' NAME !t_lookahead +// | t_primary '[' slices ']' !t_lookahead +// | star_atom +static expr_ty +star_target_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + if (_PyPegen_is_memoized(p, star_target_type, &res)) + return res; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // '*' (!'*' star_target) + void *a; + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 16)) // token='*' + && + (a = _tmp_120_rule(p)) // !'*' star_target + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Starred ( CHECK ( _PyPegen_set_expr_context ( p , a , Store ) ) , Store , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // t_primary '.' NAME !t_lookahead + expr_ty a; + expr_ty b; + Token * literal; + if ( + (a = t_primary_rule(p)) // t_primary + && + (literal = _PyPegen_expect_token(p, 23)) // token='.' + && + (b = _PyPegen_name_token(p)) // NAME + && + _PyPegen_lookahead(0, t_lookahead_rule, p) + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Attribute ( a , b -> v . Name . id , Store , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // t_primary '[' slices ']' !t_lookahead + expr_ty a; + expr_ty b; + Token * literal; + Token * literal_1; + if ( + (a = t_primary_rule(p)) // t_primary + && + (literal = _PyPegen_expect_token(p, 9)) // token='[' + && + (b = slices_rule(p)) // slices + && + (literal_1 = _PyPegen_expect_token(p, 10)) // token=']' + && + _PyPegen_lookahead(0, t_lookahead_rule, p) + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Subscript ( a , b , Store , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // star_atom + expr_ty star_atom_var; + if ( + (star_atom_var = star_atom_rule(p)) // star_atom + ) + { + res = star_atom_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + _PyPegen_insert_memo(p, mark, star_target_type, res); + return res; +} + +// star_atom: +// | NAME +// | '(' star_target ')' +// | '(' star_targets_seq? ')' +// | '[' star_targets_seq? ']' +static expr_ty +star_atom_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + expr_ty a; + if ( + (a = _PyPegen_name_token(p)) // NAME + ) + { + res = _PyPegen_set_expr_context ( p , a , Store ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // '(' star_target ')' + expr_ty a; + Token * literal; + Token * literal_1; + if ( + (literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (a = star_target_rule(p)) // star_target + && + (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + ) + { + res = _PyPegen_set_expr_context ( p , a , Store ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // '(' star_targets_seq? ')' + void *a; + Token * literal; + Token * literal_1; + if ( + (literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (a = star_targets_seq_rule(p), 1) // star_targets_seq? + && + (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Tuple ( a , Store , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // '[' star_targets_seq? ']' + void *a; + Token * literal; + Token * literal_1; + if ( + (literal = _PyPegen_expect_token(p, 9)) // token='[' + && + (a = star_targets_seq_rule(p), 1) // star_targets_seq? + && + (literal_1 = _PyPegen_expect_token(p, 10)) // token=']' + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_List ( a , Store , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// inside_paren_ann_assign_target: +// | ann_assign_subscript_attribute_target +// | NAME +// | '(' inside_paren_ann_assign_target ')' +static expr_ty +inside_paren_ann_assign_target_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->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)) // ann_assign_subscript_attribute_target + ) + { + res = ann_assign_subscript_attribute_target_var; + goto done; + } + p->mark = mark; + } + { // NAME + expr_ty a; + if ( + (a = _PyPegen_name_token(p)) // NAME + ) + { + res = _PyPegen_set_expr_context ( p , a , Store ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // '(' inside_paren_ann_assign_target ')' + expr_ty a; + Token * literal; + Token * literal_1; + if ( + (literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (a = inside_paren_ann_assign_target_rule(p)) // inside_paren_ann_assign_target + && + (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + ) + { + res = a; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// ann_assign_subscript_attribute_target: +// | t_primary '.' NAME !t_lookahead +// | t_primary '[' slices ']' !t_lookahead +static expr_ty +ann_assign_subscript_attribute_target_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // t_primary '.' NAME !t_lookahead + expr_ty a; + expr_ty b; + Token * literal; + if ( + (a = t_primary_rule(p)) // t_primary + && + (literal = _PyPegen_expect_token(p, 23)) // token='.' + && + (b = _PyPegen_name_token(p)) // NAME + && + _PyPegen_lookahead(0, t_lookahead_rule, p) + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Attribute ( a , b -> v . Name . id , Store , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // t_primary '[' slices ']' !t_lookahead + expr_ty a; + expr_ty b; + Token * literal; + Token * literal_1; + if ( + (a = t_primary_rule(p)) // t_primary + && + (literal = _PyPegen_expect_token(p, 9)) // token='[' + && + (b = slices_rule(p)) // slices + && + (literal_1 = _PyPegen_expect_token(p, 10)) // token=']' + && + _PyPegen_lookahead(0, t_lookahead_rule, p) + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Subscript ( a , b , Store , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// del_targets: ','.del_target+ ','? +static asdl_seq* +del_targets_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq* res = NULL; + int mark = p->mark; + { // ','.del_target+ ','? + asdl_seq * a; + void *opt_var; + UNUSED(opt_var); // Silence compiler warnings + if ( + (a = _gather_121_rule(p)) // ','.del_target+ + && + (opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + ) + { + res = a; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// del_target: +// | t_primary '.' NAME !t_lookahead +// | t_primary '[' slices ']' !t_lookahead +// | del_t_atom +static expr_ty +del_target_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + if (_PyPegen_is_memoized(p, del_target_type, &res)) + return res; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // t_primary '.' NAME !t_lookahead + expr_ty a; + expr_ty b; + Token * literal; + if ( + (a = t_primary_rule(p)) // t_primary + && + (literal = _PyPegen_expect_token(p, 23)) // token='.' + && + (b = _PyPegen_name_token(p)) // NAME + && + _PyPegen_lookahead(0, t_lookahead_rule, p) + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Attribute ( a , b -> v . Name . id , Del , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // t_primary '[' slices ']' !t_lookahead + expr_ty a; + expr_ty b; + Token * literal; + Token * literal_1; + if ( + (a = t_primary_rule(p)) // t_primary + && + (literal = _PyPegen_expect_token(p, 9)) // token='[' + && + (b = slices_rule(p)) // slices + && + (literal_1 = _PyPegen_expect_token(p, 10)) // token=']' + && + _PyPegen_lookahead(0, t_lookahead_rule, p) + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Subscript ( a , b , Del , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // del_t_atom + expr_ty del_t_atom_var; + if ( + (del_t_atom_var = del_t_atom_rule(p)) // del_t_atom + ) + { + res = del_t_atom_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + _PyPegen_insert_memo(p, mark, del_target_type, res); + return res; +} + +// del_t_atom: NAME | '(' del_target ')' | '(' del_targets? ')' | '[' del_targets? ']' +static expr_ty +del_t_atom_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + expr_ty a; + if ( + (a = _PyPegen_name_token(p)) // NAME + ) + { + res = _PyPegen_set_expr_context ( p , a , Del ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // '(' del_target ')' + expr_ty a; + Token * literal; + Token * literal_1; + if ( + (literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (a = del_target_rule(p)) // del_target + && + (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + ) + { + res = _PyPegen_set_expr_context ( p , a , Del ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // '(' del_targets? ')' + void *a; + Token * literal; + Token * literal_1; + if ( + (literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (a = del_targets_rule(p), 1) // del_targets? + && + (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Tuple ( a , Del , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // '[' del_targets? ']' + void *a; + Token * literal; + Token * literal_1; + if ( + (literal = _PyPegen_expect_token(p, 9)) // token='[' + && + (a = del_targets_rule(p), 1) // del_targets? + && + (literal_1 = _PyPegen_expect_token(p, 10)) // token=']' + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_List ( a , Del , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// targets: ','.target+ ','? +static asdl_seq* +targets_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq* res = NULL; + int mark = p->mark; + { // ','.target+ ','? + asdl_seq * a; + void *opt_var; + UNUSED(opt_var); // Silence compiler warnings + if ( + (a = _gather_123_rule(p)) // ','.target+ + && + (opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + ) + { + res = a; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// target: +// | t_primary '.' NAME !t_lookahead +// | t_primary '[' slices ']' !t_lookahead +// | t_atom +static expr_ty +target_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + if (_PyPegen_is_memoized(p, target_type, &res)) + return res; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // t_primary '.' NAME !t_lookahead + expr_ty a; + expr_ty b; + Token * literal; + if ( + (a = t_primary_rule(p)) // t_primary + && + (literal = _PyPegen_expect_token(p, 23)) // token='.' + && + (b = _PyPegen_name_token(p)) // NAME + && + _PyPegen_lookahead(0, t_lookahead_rule, p) + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Attribute ( a , b -> v . Name . id , Store , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // t_primary '[' slices ']' !t_lookahead + expr_ty a; + expr_ty b; + Token * literal; + Token * literal_1; + if ( + (a = t_primary_rule(p)) // t_primary + && + (literal = _PyPegen_expect_token(p, 9)) // token='[' + && + (b = slices_rule(p)) // slices + && + (literal_1 = _PyPegen_expect_token(p, 10)) // token=']' + && + _PyPegen_lookahead(0, t_lookahead_rule, p) + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Subscript ( a , b , Store , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // t_atom + expr_ty t_atom_var; + if ( + (t_atom_var = t_atom_rule(p)) // t_atom + ) + { + res = t_atom_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + _PyPegen_insert_memo(p, mark, target_type, res); + return res; +} + +// Left-recursive +// t_primary: +// | t_primary '.' NAME &t_lookahead +// | t_primary '[' slices ']' &t_lookahead +// | t_primary genexp &t_lookahead +// | t_primary '(' arguments? ')' &t_lookahead +// | atom &t_lookahead +static expr_ty t_primary_raw(Parser *); +static expr_ty +t_primary_rule(Parser *p) +{ + expr_ty res = NULL; + if (_PyPegen_is_memoized(p, t_primary_type, &res)) + return res; + int mark = p->mark; + int resmark = p->mark; + while (1) { + int tmpvar_8 = _PyPegen_update_memo(p, mark, t_primary_type, res); + if (tmpvar_8) { + return res; + } + p->mark = mark; + void *raw = t_primary_raw(p); + if (raw == NULL || p->mark <= resmark) + break; + resmark = p->mark; + res = raw; + } + p->mark = resmark; + return res; +} +static expr_ty +t_primary_raw(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + { // t_primary '.' NAME &t_lookahead + expr_ty a; + expr_ty b; + Token * literal; + if ( + (a = t_primary_rule(p)) // t_primary + && + (literal = _PyPegen_expect_token(p, 23)) // token='.' + && + (b = _PyPegen_name_token(p)) // NAME + && + _PyPegen_lookahead(1, t_lookahead_rule, p) + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Attribute ( a , b -> v . Name . id , Load , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // t_primary '[' slices ']' &t_lookahead + expr_ty a; + expr_ty b; + Token * literal; + Token * literal_1; + if ( + (a = t_primary_rule(p)) // t_primary + && + (literal = _PyPegen_expect_token(p, 9)) // token='[' + && + (b = slices_rule(p)) // slices + && + (literal_1 = _PyPegen_expect_token(p, 10)) // token=']' + && + _PyPegen_lookahead(1, t_lookahead_rule, p) + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Subscript ( a , b , Load , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // t_primary genexp &t_lookahead + expr_ty a; + expr_ty b; + if ( + (a = t_primary_rule(p)) // t_primary + && + (b = genexp_rule(p)) // genexp + && + _PyPegen_lookahead(1, t_lookahead_rule, p) + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Call ( a , CHECK ( _PyPegen_singleton_seq ( p , b ) ) , NULL , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // t_primary '(' arguments? ')' &t_lookahead + expr_ty a; + void *b; + Token * literal; + Token * literal_1; + if ( + (a = t_primary_rule(p)) // t_primary + && + (literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (b = arguments_rule(p), 1) // arguments? + && + (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + && + _PyPegen_lookahead(1, t_lookahead_rule, p) + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Call ( a , ( b ) ? ( ( expr_ty ) b ) -> v . Call . args : NULL , ( b ) ? ( ( expr_ty ) b ) -> v . Call . keywords : NULL , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // atom &t_lookahead + expr_ty a; + if ( + (a = atom_rule(p)) // atom + && + _PyPegen_lookahead(1, t_lookahead_rule, p) + ) + { + res = a; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// t_lookahead: '(' | '[' | '.' +static void * +t_lookahead_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // '(' + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 7)) // token='(' + ) + { + res = literal; + goto done; + } + p->mark = mark; + } + { // '[' + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 9)) // token='[' + ) + { + res = literal; + goto done; + } + p->mark = mark; + } + { // '.' + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 23)) // token='.' + ) + { + res = literal; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// t_atom: NAME | '(' target ')' | '(' targets? ')' | '[' targets? ']' +static expr_ty +t_atom_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + expr_ty res = NULL; + int mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + int start_lineno = p->tokens[mark]->lineno; + 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 + expr_ty a; + if ( + (a = _PyPegen_name_token(p)) // NAME + ) + { + res = _PyPegen_set_expr_context ( p , a , Store ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // '(' target ')' + expr_ty a; + Token * literal; + Token * literal_1; + if ( + (literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (a = target_rule(p)) // target + && + (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + ) + { + res = _PyPegen_set_expr_context ( p , a , Store ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // '(' targets? ')' + void *b; + Token * literal; + Token * literal_1; + if ( + (literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (b = targets_rule(p), 1) // targets? + && + (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_Tuple ( b , Store , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // '[' targets? ']' + void *b; + Token * literal; + Token * literal_1; + if ( + (literal = _PyPegen_expect_token(p, 9)) // token='[' + && + (b = targets_rule(p), 1) // targets? + && + (literal_1 = _PyPegen_expect_token(p, 10)) // token=']' + ) + { + Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + if (token == NULL) { + return NULL; + } + int end_lineno = token->end_lineno; + 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_List ( b , Store , EXTRA ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// incorrect_arguments: +// | args ',' '*' +// | expression for_if_clauses ',' [args | expression for_if_clauses] +// | args ',' args +static void * +incorrect_arguments_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // args ',' '*' + expr_ty args_var; + Token * literal; + Token * literal_1; + if ( + (args_var = args_rule(p)) // args + && + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (literal_1 = _PyPegen_expect_token(p, 16)) // token='*' + ) + { + res = RAISE_SYNTAX_ERROR ( "iterable argument unpacking follows keyword argument unpacking" ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // expression for_if_clauses ',' [args | expression for_if_clauses] + expr_ty expression_var; + asdl_seq* for_if_clauses_var; + Token * literal; + void *opt_var; + UNUSED(opt_var); // Silence compiler warnings + if ( + (expression_var = expression_rule(p)) // expression + && + (for_if_clauses_var = for_if_clauses_rule(p)) // for_if_clauses + && + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (opt_var = _tmp_125_rule(p), 1) // [args | expression for_if_clauses] + ) + { + res = RAISE_SYNTAX_ERROR ( "Generator expression must be parenthesized" ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // args ',' args + expr_ty a; + expr_ty args_var; + Token * literal; + if ( + (a = args_rule(p)) // args + && + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (args_var = args_rule(p)) // args + ) + { + res = _PyPegen_arguments_parsing_error ( p , a ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// invalid_kwarg: expression '=' +static void * +invalid_kwarg_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // expression '=' + expr_ty expression_var; + Token * literal; + if ( + (expression_var = expression_rule(p)) // expression + && + (literal = _PyPegen_expect_token(p, 22)) // token='=' + ) + { + res = RAISE_SYNTAX_ERROR ( "expression cannot contain assignment, perhaps you meant \"==\"?" ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// invalid_named_expression: expression ':=' expression +static void * +invalid_named_expression_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // expression ':=' expression + expr_ty a; + expr_ty expression_var; + Token * literal; + if ( + (a = expression_rule(p)) // expression + && + (literal = _PyPegen_expect_token(p, 53)) // token=':=' + && + (expression_var = expression_rule(p)) // expression + ) + { + res = RAISE_SYNTAX_ERROR ( "cannot use assignment expressions with %s" , _PyPegen_get_expr_name ( a ) ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// invalid_assignment: +// | list ':' +// | tuple ':' +// | expression ':' expression ['=' annotated_rhs] +// | expression ('=' | augassign) (yield_expr | star_expressions) +static void * +invalid_assignment_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // list ':' + expr_ty list_var; + Token * literal; + if ( + (list_var = list_rule(p)) // list + && + (literal = _PyPegen_expect_token(p, 11)) // token=':' + ) + { + res = RAISE_SYNTAX_ERROR ( "only single target (not list) can be annotated" ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // tuple ':' + Token * literal; + expr_ty tuple_var; + if ( + (tuple_var = tuple_rule(p)) // tuple + && + (literal = _PyPegen_expect_token(p, 11)) // token=':' + ) + { + res = RAISE_SYNTAX_ERROR ( "only single target (not tuple) can be annotated" ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // expression ':' expression ['=' annotated_rhs] + expr_ty expression_var; + expr_ty expression_var_1; + Token * literal; + void *opt_var; + UNUSED(opt_var); // Silence compiler warnings + if ( + (expression_var = expression_rule(p)) // expression + && + (literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (expression_var_1 = expression_rule(p)) // expression + && + (opt_var = _tmp_126_rule(p), 1) // ['=' annotated_rhs] + ) + { + res = RAISE_SYNTAX_ERROR ( "illegal target for annotation" ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + { // expression ('=' | augassign) (yield_expr | star_expressions) + void *_tmp_127_var; + void *_tmp_128_var; + expr_ty a; + if ( + (a = expression_rule(p)) // expression + && + (_tmp_127_var = _tmp_127_rule(p)) // '=' | augassign + && + (_tmp_128_var = _tmp_128_rule(p)) // yield_expr | star_expressions + ) + { + res = RAISE_SYNTAX_ERROR_NO_COL_OFFSET ( "cannot assign to %s" , _PyPegen_get_expr_name ( a ) ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// invalid_block: NEWLINE !INDENT +static void * +invalid_block_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // NEWLINE !INDENT + Token * newline_var; + if ( + (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + && + _PyPegen_lookahead_with_int(0, _PyPegen_expect_token, p, INDENT) // token=INDENT + ) + { + res = RAISE_INDENTATION_ERROR ( "expected an indented block" ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// invalid_comprehension: ('[' | '(' | '{') '*' expression for_if_clauses +static void * +invalid_comprehension_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // ('[' | '(' | '{') '*' expression for_if_clauses + void *_tmp_129_var; + expr_ty expression_var; + asdl_seq* for_if_clauses_var; + Token * literal; + if ( + (_tmp_129_var = _tmp_129_rule(p)) // '[' | '(' | '{' + && + (literal = _PyPegen_expect_token(p, 16)) // token='*' + && + (expression_var = expression_rule(p)) // expression + && + (for_if_clauses_var = for_if_clauses_rule(p)) // for_if_clauses + ) + { + res = RAISE_SYNTAX_ERROR ( "iterable unpacking cannot be used in comprehension" ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// invalid_parameters: +// | param_no_default* (slash_with_default | param_with_default+) param_no_default +static void * +invalid_parameters_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // param_no_default* (slash_with_default | param_with_default+) param_no_default + asdl_seq * _loop0_130_var; + void *_tmp_131_var; + arg_ty param_no_default_var; + if ( + (_loop0_130_var = _loop0_130_rule(p)) // param_no_default* + && + (_tmp_131_var = _tmp_131_rule(p)) // slash_with_default | param_with_default+ + && + (param_no_default_var = param_no_default_rule(p)) // param_no_default + ) + { + res = RAISE_SYNTAX_ERROR ( "non-default argument follows default argument" ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// invalid_star_etc: '*' (')' | ',' (')' | '**')) +static void * +invalid_star_etc_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // '*' (')' | ',' (')' | '**')) + void *_tmp_132_var; + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 16)) // token='*' + && + (_tmp_132_var = _tmp_132_rule(p)) // ')' | ',' (')' | '**') + ) + { + res = RAISE_SYNTAX_ERROR ( "named arguments must follow bare *" ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// invalid_lambda_star_etc: '*' (':' | ',' (':' | '**')) +static void * +invalid_lambda_star_etc_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // '*' (':' | ',' (':' | '**')) + void *_tmp_133_var; + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 16)) // token='*' + && + (_tmp_133_var = _tmp_133_rule(p)) // ':' | ',' (':' | '**') + ) + { + res = RAISE_SYNTAX_ERROR ( "named arguments must follow bare *" ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + 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 + Token * indent_var; + Token * newline_var; + Token * newline_var_1; + Token * type_comment_var; + Token * type_comment_var_1; + if ( + (type_comment_var = _PyPegen_expect_token(p, TYPE_COMMENT)) // token='TYPE_COMMENT' + && + (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + && + (type_comment_var_1 = _PyPegen_expect_token(p, TYPE_COMMENT)) // token='TYPE_COMMENT' + && + (newline_var_1 = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + && + (indent_var = _PyPegen_expect_token(p, INDENT)) // token='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) +{ + 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; + { // NEWLINE + Token * newline_var; + while ( + (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + ) + { + res = newline_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_1"); + 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_1_type, seq); + return seq; +} + +// _loop0_2: NEWLINE +static asdl_seq * +_loop0_2_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; + { // NEWLINE + Token * newline_var; + while ( + (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + ) + { + res = newline_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_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, _loop0_2_type, seq); + return seq; +} + +// _loop0_4: ',' expression +static asdl_seq * +_loop0_4_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; + { // ',' expression + expr_ty elem; + Token * literal; + while ( + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = expression_rule(p)) // expression + ) + { + 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_4"); + 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_4_type, seq); + return seq; +} + +// _gather_3: expression _loop0_4 +static asdl_seq * +_gather_3_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq * res = NULL; + int mark = p->mark; + { // expression _loop0_4 + expr_ty elem; + asdl_seq * seq; + if ( + (elem = expression_rule(p)) // expression + && + (seq = _loop0_4_rule(p)) // _loop0_4 + ) + { + res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _loop0_6: ',' expression +static asdl_seq * +_loop0_6_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; + { // ',' expression + expr_ty elem; + Token * literal; + while ( + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = expression_rule(p)) // expression + ) + { + 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_6"); + 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_6_type, seq); + return seq; +} + +// _gather_5: expression _loop0_6 +static asdl_seq * +_gather_5_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq * res = NULL; + int mark = p->mark; + { // expression _loop0_6 + expr_ty elem; + asdl_seq * seq; + if ( + (elem = expression_rule(p)) // expression + && + (seq = _loop0_6_rule(p)) // _loop0_6 + ) + { + res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _loop0_8: ',' expression +static asdl_seq * +_loop0_8_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; + { // ',' expression + expr_ty elem; + Token * literal; + while ( + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = expression_rule(p)) // expression + ) + { + 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_8"); + 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_8_type, seq); + return seq; +} + +// _gather_7: expression _loop0_8 +static asdl_seq * +_gather_7_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq * res = NULL; + int mark = p->mark; + { // expression _loop0_8 + expr_ty elem; + asdl_seq * seq; + if ( + (elem = expression_rule(p)) // expression + && + (seq = _loop0_8_rule(p)) // _loop0_8 + ) + { + res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _loop0_10: ',' expression +static asdl_seq * +_loop0_10_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; + { // ',' expression + expr_ty elem; + Token * literal; + while ( + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = expression_rule(p)) // expression + ) + { + 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_10"); + 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_10_type, seq); + return seq; +} + +// _gather_9: expression _loop0_10 +static asdl_seq * +_gather_9_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq * res = NULL; + int mark = p->mark; + { // expression _loop0_10 + expr_ty elem; + asdl_seq * seq; + if ( + (elem = expression_rule(p)) // expression + && + (seq = _loop0_10_rule(p)) // _loop0_10 + ) + { + res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _loop1_11: statement +static asdl_seq * +_loop1_11_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; + { // statement + asdl_seq* statement_var; + while ( + (statement_var = statement_rule(p)) // statement + ) + { + res = statement_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_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_11_type, seq); + return seq; +} + +// _loop0_13: ';' small_stmt +static asdl_seq * +_loop0_13_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; + { // ';' small_stmt + stmt_ty elem; + Token * literal; + while ( + (literal = _PyPegen_expect_token(p, 13)) // token=';' + && + (elem = small_stmt_rule(p)) // small_stmt + ) + { + 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_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_13_type, seq); + return seq; +} + +// _gather_12: small_stmt _loop0_13 +static asdl_seq * +_gather_12_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq * res = NULL; + int mark = p->mark; + { // small_stmt _loop0_13 + stmt_ty elem; + asdl_seq * seq; + if ( + (elem = small_stmt_rule(p)) // small_stmt + && + (seq = _loop0_13_rule(p)) // _loop0_13 + ) + { + res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_14: 'import' | 'from' +static void * +_tmp_14_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // 'import' + Token * keyword; + if ( + (keyword = _PyPegen_expect_token(p, 513)) // token='import' + ) + { + res = keyword; + goto done; + } + p->mark = mark; + } + { // 'from' + Token * keyword; + if ( + (keyword = _PyPegen_expect_token(p, 514)) // token='from' + ) + { + res = keyword; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_15: 'def' | '@' | ASYNC +static void * +_tmp_15_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // 'def' + Token * keyword; + if ( + (keyword = _PyPegen_expect_token(p, 522)) // token='def' + ) + { + res = keyword; + goto done; + } + p->mark = mark; + } + { // '@' + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 49)) // token='@' + ) + { + res = literal; + goto done; + } + p->mark = mark; + } + { // ASYNC + Token * async_var; + if ( + (async_var = _PyPegen_expect_token(p, ASYNC)) // token='ASYNC' + ) + { + res = async_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_16: 'class' | '@' +static void * +_tmp_16_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // 'class' + Token * keyword; + if ( + (keyword = _PyPegen_expect_token(p, 523)) // token='class' + ) + { + res = keyword; + goto done; + } + p->mark = mark; + } + { // '@' + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 49)) // token='@' + ) + { + res = literal; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_17: 'with' | ASYNC +static void * +_tmp_17_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // 'with' + Token * keyword; + if ( + (keyword = _PyPegen_expect_token(p, 519)) // token='with' + ) + { + res = keyword; + goto done; + } + p->mark = mark; + } + { // ASYNC + Token * async_var; + if ( + (async_var = _PyPegen_expect_token(p, ASYNC)) // token='ASYNC' + ) + { + res = async_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_18: 'for' | ASYNC +static void * +_tmp_18_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // 'for' + Token * keyword; + if ( + (keyword = _PyPegen_expect_token(p, 517)) // token='for' + ) + { + res = keyword; + goto done; + } + p->mark = mark; + } + { // ASYNC + Token * async_var; + if ( + (async_var = _PyPegen_expect_token(p, ASYNC)) // token='ASYNC' + ) + { + res = async_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_19: '=' annotated_rhs +static void * +_tmp_19_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // '=' annotated_rhs + expr_ty d; + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 22)) // token='=' + && + (d = annotated_rhs_rule(p)) // annotated_rhs + ) + { + res = d; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _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; + } + void * res = NULL; + int mark = p->mark; + { // '(' inside_paren_ann_assign_target ')' + expr_ty b; + Token * literal; + Token * literal_1; + if ( + (literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (b = inside_paren_ann_assign_target_rule(p)) // inside_paren_ann_assign_target + && + (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + ) + { + 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)) // ann_assign_subscript_attribute_target + ) + { + res = ann_assign_subscript_attribute_target_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_21: '=' annotated_rhs +static void * +_tmp_21_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // '=' annotated_rhs + expr_ty d; + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 22)) // token='=' + && + (d = annotated_rhs_rule(p)) // annotated_rhs + ) + { + res = d; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _loop1_22: (star_targets '=') +static asdl_seq * +_loop1_22_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; + { // (star_targets '=') + void *_tmp_134_var; + while ( + (_tmp_134_var = _tmp_134_rule(p)) // star_targets '=' + ) + { + res = _tmp_134_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_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, _loop1_22_type, seq); + return seq; +} + +// _tmp_23: yield_expr | star_expressions +static void * +_tmp_23_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)) // yield_expr + ) + { + res = yield_expr_var; + goto done; + } + p->mark = mark; + } + { // star_expressions + expr_ty star_expressions_var; + if ( + (star_expressions_var = star_expressions_rule(p)) // star_expressions + ) + { + res = star_expressions_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_24: yield_expr | star_expressions +static void * +_tmp_24_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)) // yield_expr + ) + { + res = yield_expr_var; + goto done; + } + p->mark = mark; + } + { // star_expressions + expr_ty star_expressions_var; + if ( + (star_expressions_var = star_expressions_rule(p)) // star_expressions + ) + { + res = star_expressions_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _loop0_26: ',' NAME +static asdl_seq * +_loop0_26_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; + { // ',' NAME + expr_ty elem; + Token * literal; + while ( + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = _PyPegen_name_token(p)) // NAME + ) + { + 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_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_26_type, seq); + return seq; +} + +// _gather_25: NAME _loop0_26 +static asdl_seq * +_gather_25_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq * res = NULL; + int mark = p->mark; + { // NAME _loop0_26 + expr_ty elem; + asdl_seq * seq; + if ( + (elem = _PyPegen_name_token(p)) // NAME + && + (seq = _loop0_26_rule(p)) // _loop0_26 + ) + { + res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _loop0_28: ',' NAME +static asdl_seq * +_loop0_28_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; + { // ',' NAME + expr_ty elem; + Token * literal; + while ( + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = _PyPegen_name_token(p)) // NAME + ) + { + 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_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_28_type, seq); + return seq; +} + +// _gather_27: NAME _loop0_28 +static asdl_seq * +_gather_27_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq * res = NULL; + int mark = p->mark; + { // NAME _loop0_28 + expr_ty elem; + asdl_seq * seq; + if ( + (elem = _PyPegen_name_token(p)) // NAME + && + (seq = _loop0_28_rule(p)) // _loop0_28 + ) + { + res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_29: ',' expression +static void * +_tmp_29_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // ',' expression + Token * literal; + expr_ty z; + if ( + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (z = expression_rule(p)) // expression + ) + { + res = z; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _loop0_30: ('.' | '...') +static asdl_seq * +_loop0_30_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_135_var; + while ( + (_tmp_135_var = _tmp_135_rule(p)) // '.' | '...' + ) + { + res = _tmp_135_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_136_var; + while ( + (_tmp_136_var = _tmp_136_rule(p)) // '.' | '...' + ) + { + res = _tmp_136_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_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_31_type, seq); + return seq; +} + +// _loop0_33: ',' import_from_as_name +static asdl_seq * +_loop0_33_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; + { // ',' import_from_as_name + alias_ty elem; + Token * literal; + while ( + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = import_from_as_name_rule(p)) // import_from_as_name + ) + { + 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_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; +} + +// _gather_32: import_from_as_name _loop0_33 +static asdl_seq * +_gather_32_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq * res = NULL; + int mark = p->mark; + { // import_from_as_name _loop0_33 + alias_ty elem; + asdl_seq * seq; + if ( + (elem = import_from_as_name_rule(p)) // import_from_as_name + && + (seq = _loop0_33_rule(p)) // _loop0_33 + ) + { + res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_34: 'as' NAME +static void * +_tmp_34_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // 'as' NAME + Token * keyword; + expr_ty z; + if ( + (keyword = _PyPegen_expect_token(p, 531)) // token='as' + && + (z = _PyPegen_name_token(p)) // NAME + ) + { + res = z; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _loop0_36: ',' dotted_as_name +static asdl_seq * +_loop0_36_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; + { // ',' dotted_as_name + alias_ty elem; + Token * literal; + while ( + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = dotted_as_name_rule(p)) // dotted_as_name + ) + { + 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_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; +} + +// _gather_35: dotted_as_name _loop0_36 +static asdl_seq * +_gather_35_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq * res = NULL; + int mark = p->mark; + { // dotted_as_name _loop0_36 + alias_ty elem; + asdl_seq * seq; + if ( + (elem = dotted_as_name_rule(p)) // dotted_as_name + && + (seq = _loop0_36_rule(p)) // _loop0_36 + ) + { + res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_37: 'as' NAME +static void * +_tmp_37_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // 'as' NAME + Token * keyword; + expr_ty z; + if ( + (keyword = _PyPegen_expect_token(p, 531)) // token='as' + && + (z = _PyPegen_name_token(p)) // NAME + ) + { + res = z; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _loop0_39: ',' with_item +static asdl_seq * +_loop0_39_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; + Token * literal; + while ( + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = with_item_rule(p)) // with_item + ) + { + 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_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; +} + +// _gather_38: with_item _loop0_39 +static asdl_seq * +_gather_38_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq * res = NULL; + int mark = p->mark; + { // with_item _loop0_39 + withitem_ty elem; + asdl_seq * seq; + if ( + (elem = with_item_rule(p)) // with_item + && + (seq = _loop0_39_rule(p)) // _loop0_39 + ) + { + 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; + Token * literal; + while ( + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = with_item_rule(p)) // with_item + ) + { + 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)) // with_item + && + (seq = _loop0_41_rule(p)) // _loop0_41 + ) + { + res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _loop0_43: ',' with_item +static asdl_seq * +_loop0_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; + { // ',' with_item + withitem_ty elem; + Token * literal; + while ( + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = with_item_rule(p)) // with_item + ) + { + 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_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, _loop0_43_type, seq); + return seq; +} + +// _gather_42: with_item _loop0_43 +static asdl_seq * +_gather_42_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq * res = NULL; + int mark = p->mark; + { // with_item _loop0_43 + withitem_ty elem; + asdl_seq * seq; + if ( + (elem = with_item_rule(p)) // with_item + && + (seq = _loop0_43_rule(p)) // _loop0_43 + ) + { + res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _loop0_45: ',' with_item +static asdl_seq * +_loop0_45_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; + Token * literal; + while ( + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = with_item_rule(p)) // with_item + ) + { + 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_45"); + 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_45_type, seq); + return seq; +} + +// _gather_44: with_item _loop0_45 +static asdl_seq * +_gather_44_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq * res = NULL; + int mark = p->mark; + { // with_item _loop0_45 + withitem_ty elem; + asdl_seq * seq; + if ( + (elem = with_item_rule(p)) // with_item + && + (seq = _loop0_45_rule(p)) // _loop0_45 + ) + { + res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_46: 'as' target +static void * +_tmp_46_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // 'as' target + Token * keyword; + expr_ty t; + if ( + (keyword = _PyPegen_expect_token(p, 531)) // token='as' + && + (t = target_rule(p)) // target + ) + { + res = t; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _loop1_47: except_block +static asdl_seq * +_loop1_47_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)) // except_block + ) + { + 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_47"); + 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_47_type, seq); + return seq; +} + +// _tmp_48: 'as' target +static void * +_tmp_48_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // 'as' target + Token * keyword; + expr_ty z; + if ( + (keyword = _PyPegen_expect_token(p, 531)) // token='as' + && + (z = target_rule(p)) // target + ) + { + res = z; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_49: 'from' expression +static void * +_tmp_49_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // 'from' expression + Token * keyword; + expr_ty z; + if ( + (keyword = _PyPegen_expect_token(p, 514)) // token='from' + && + (z = expression_rule(p)) // expression + ) + { + res = z; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_50: '->' expression +static void * +_tmp_50_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // '->' expression + Token * literal; + expr_ty z; + if ( + (literal = _PyPegen_expect_token(p, 51)) // token='->' + && + (z = expression_rule(p)) // expression + ) + { + res = z; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_51: '->' expression +static void * +_tmp_51_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // '->' expression + Token * literal; + expr_ty z; + if ( + (literal = _PyPegen_expect_token(p, 51)) // token='->' + && + (z = expression_rule(p)) // expression + ) + { + res = z; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_52: NEWLINE INDENT +static void * +_tmp_52_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // NEWLINE INDENT + Token * indent_var; + Token * newline_var; + if ( + (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + && + (indent_var = _PyPegen_expect_token(p, INDENT)) // token='INDENT' + ) + { + res = _PyPegen_dummy_name(p, newline_var, indent_var); + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _loop0_53: param_no_default +static asdl_seq * +_loop0_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_no_default + arg_ty param_no_default_var; + while ( + (param_no_default_var = param_no_default_rule(p)) // param_no_default + ) + { + 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_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, _loop0_53_type, seq); + return seq; +} + +// _loop0_54: param_with_default +static asdl_seq * +_loop0_54_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)) // param_with_default + ) + { + 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_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_54_type, seq); + return seq; +} + +// _loop0_55: param_with_default +static asdl_seq * +_loop0_55_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)) // param_with_default + ) + { + 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_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, _loop0_55_type, seq); + return seq; +} + +// _loop1_56: param_no_default +static asdl_seq * +_loop1_56_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)) // param_no_default + ) + { + 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_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, _loop1_56_type, seq); + return seq; +} + +// _loop0_57: param_with_default +static asdl_seq * +_loop0_57_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)) // param_with_default + ) + { + 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_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, _loop0_57_type, seq); + return seq; +} + +// _loop1_58: param_with_default +static asdl_seq * +_loop1_58_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)) // param_with_default + ) + { + 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_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, _loop1_58_type, seq); + return seq; +} + +// _loop1_59: param_no_default +static asdl_seq * +_loop1_59_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)) // param_no_default + ) + { + 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_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; +} + +// _loop1_60: param_no_default +static asdl_seq * +_loop1_60_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)) // param_no_default + ) + { + 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_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, _loop1_60_type, seq); + return seq; +} + +// _loop0_61: param_no_default +static asdl_seq * +_loop0_61_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)) // param_no_default + ) + { + 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_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, _loop0_61_type, seq); + return seq; +} + +// _loop1_62: param_with_default +static asdl_seq * +_loop1_62_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)) // param_with_default + ) + { + 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_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_62_type, seq); + return seq; +} + +// _loop0_63: param_no_default +static asdl_seq * +_loop0_63_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)) // param_no_default + ) + { + 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_63"); + 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); + return seq; +} + +// _loop1_64: param_with_default +static asdl_seq * +_loop1_64_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)) // param_with_default + ) + { + 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_64"); + 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); + return seq; +} + +// _loop0_65: param_maybe_default +static asdl_seq * +_loop0_65_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_maybe_default + NameDefaultPair* param_maybe_default_var; + while ( + (param_maybe_default_var = param_maybe_default_rule(p)) // param_maybe_default + ) + { + 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; + } + } + 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_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_65_type, seq); + return seq; +} + +// _loop1_66: param_maybe_default +static asdl_seq * +_loop1_66_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_maybe_default + NameDefaultPair* param_maybe_default_var; + while ( + (param_maybe_default_var = param_maybe_default_rule(p)) // param_maybe_default + ) + { + 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; + } + } + 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_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_66_type, seq); + return seq; +} + +// _loop1_67: ('@' named_expression NEWLINE) +static asdl_seq * +_loop1_67_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; + { // ('@' named_expression NEWLINE) + void *_tmp_137_var; + while ( + (_tmp_137_var = _tmp_137_rule(p)) // '@' named_expression NEWLINE + ) + { + res = _tmp_137_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_67"); + 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_67_type, seq); + return seq; +} + +// _tmp_68: '(' arguments? ')' +static void * +_tmp_68_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // '(' arguments? ')' + Token * literal; + Token * literal_1; + void *z; + if ( + (literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (z = arguments_rule(p), 1) // arguments? + && + (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + ) + { + res = z; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _loop0_70: ',' star_expression +static asdl_seq * +_loop0_70_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; + { // ',' star_expression + expr_ty elem; + Token * literal; + while ( + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = star_expression_rule(p)) // star_expression + ) + { + 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_70"); + 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_70_type, seq); + return seq; +} + +// _gather_69: star_expression _loop0_70 +static asdl_seq * +_gather_69_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq * res = NULL; + int mark = p->mark; + { // star_expression _loop0_70 + expr_ty elem; + asdl_seq * seq; + if ( + (elem = star_expression_rule(p)) // star_expression + && + (seq = _loop0_70_rule(p)) // _loop0_70 + ) + { + res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _loop1_71: (',' star_expression) +static asdl_seq * +_loop1_71_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; + { // (',' star_expression) + void *_tmp_138_var; + while ( + (_tmp_138_var = _tmp_138_rule(p)) // ',' star_expression + ) + { + res = _tmp_138_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_71"); + 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_71_type, seq); + return seq; +} + +// _loop0_73: ',' star_named_expression +static asdl_seq * +_loop0_73_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; + { // ',' star_named_expression + expr_ty elem; + Token * literal; + while ( + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = star_named_expression_rule(p)) // star_named_expression + ) + { + 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_73"); + 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_73_type, seq); + return seq; +} + +// _gather_72: star_named_expression _loop0_73 +static asdl_seq * +_gather_72_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq * res = NULL; + int mark = p->mark; + { // star_named_expression _loop0_73 + expr_ty elem; + asdl_seq * seq; + if ( + (elem = star_named_expression_rule(p)) // star_named_expression + && + (seq = _loop0_73_rule(p)) // _loop0_73 + ) + { + res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _loop1_74: (',' expression) +static asdl_seq * +_loop1_74_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; + { // (',' expression) + void *_tmp_139_var; + while ( + (_tmp_139_var = _tmp_139_rule(p)) // ',' expression + ) + { + res = _tmp_139_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_74"); + 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_74_type, seq); + return seq; +} + +// _loop0_75: lambda_param_no_default +static asdl_seq * +_loop0_75_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; + { // lambda_param_no_default + arg_ty lambda_param_no_default_var; + while ( + (lambda_param_no_default_var = lambda_param_no_default_rule(p)) // lambda_param_no_default + ) + { + res = lambda_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_75"); + 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_75_type, seq); + return seq; +} + +// _loop0_76: lambda_param_with_default +static asdl_seq * +_loop0_76_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; + { // lambda_param_with_default + NameDefaultPair* lambda_param_with_default_var; + while ( + (lambda_param_with_default_var = lambda_param_with_default_rule(p)) // lambda_param_with_default + ) + { + res = lambda_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_76"); + 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_76_type, seq); + return seq; +} + +// _loop0_77: lambda_param_with_default +static asdl_seq * +_loop0_77_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; + { // lambda_param_with_default + NameDefaultPair* lambda_param_with_default_var; + while ( + (lambda_param_with_default_var = lambda_param_with_default_rule(p)) // lambda_param_with_default + ) + { + res = lambda_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_77"); + 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_77_type, seq); + return seq; +} + +// _loop1_78: lambda_param_no_default +static asdl_seq * +_loop1_78_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; + { // lambda_param_no_default + arg_ty lambda_param_no_default_var; + while ( + (lambda_param_no_default_var = lambda_param_no_default_rule(p)) // lambda_param_no_default + ) + { + res = lambda_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_78"); + 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_78_type, seq); + return seq; +} + +// _loop0_79: lambda_param_with_default +static asdl_seq * +_loop0_79_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; + { // lambda_param_with_default + NameDefaultPair* lambda_param_with_default_var; + while ( + (lambda_param_with_default_var = lambda_param_with_default_rule(p)) // lambda_param_with_default + ) + { + res = lambda_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_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_79_type, seq); + return seq; +} + +// _loop1_80: lambda_param_with_default +static asdl_seq * +_loop1_80_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; + { // lambda_param_with_default + NameDefaultPair* lambda_param_with_default_var; + while ( + (lambda_param_with_default_var = lambda_param_with_default_rule(p)) // lambda_param_with_default + ) + { + res = lambda_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_80"); + 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_80_type, seq); + return seq; +} + +// _loop1_81: lambda_param_no_default +static asdl_seq * +_loop1_81_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; + { // lambda_param_no_default + arg_ty lambda_param_no_default_var; + while ( + (lambda_param_no_default_var = lambda_param_no_default_rule(p)) // lambda_param_no_default + ) + { + res = lambda_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_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_81_type, seq); + return seq; +} + +// _loop1_82: lambda_param_no_default +static asdl_seq * +_loop1_82_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; + { // lambda_param_no_default + arg_ty lambda_param_no_default_var; + while ( + (lambda_param_no_default_var = lambda_param_no_default_rule(p)) // lambda_param_no_default + ) + { + res = lambda_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_82"); + 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_82_type, seq); + return seq; +} + +// _loop0_83: lambda_param_no_default +static asdl_seq * +_loop0_83_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; + { // lambda_param_no_default + arg_ty lambda_param_no_default_var; + while ( + (lambda_param_no_default_var = lambda_param_no_default_rule(p)) // lambda_param_no_default + ) + { + res = lambda_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_83"); + 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_83_type, seq); + return seq; +} + +// _loop1_84: lambda_param_with_default +static asdl_seq * +_loop1_84_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; + { // lambda_param_with_default + NameDefaultPair* lambda_param_with_default_var; + while ( + (lambda_param_with_default_var = lambda_param_with_default_rule(p)) // lambda_param_with_default + ) + { + res = lambda_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_84"); + 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); + return seq; +} + +// _loop0_85: lambda_param_no_default +static asdl_seq * +_loop0_85_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; + { // lambda_param_no_default + arg_ty lambda_param_no_default_var; + while ( + (lambda_param_no_default_var = lambda_param_no_default_rule(p)) // lambda_param_no_default + ) + { + res = lambda_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_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_85_type, seq); + return seq; +} + +// _loop1_86: lambda_param_with_default +static asdl_seq * +_loop1_86_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; + { // lambda_param_with_default + NameDefaultPair* lambda_param_with_default_var; + while ( + (lambda_param_with_default_var = lambda_param_with_default_rule(p)) // lambda_param_with_default + ) + { + res = lambda_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_86"); + 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_86_type, seq); + return seq; +} + +// _loop0_87: lambda_param_maybe_default +static asdl_seq * +_loop0_87_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; + { // lambda_param_maybe_default + NameDefaultPair* lambda_param_maybe_default_var; + while ( + (lambda_param_maybe_default_var = lambda_param_maybe_default_rule(p)) // lambda_param_maybe_default + ) + { + res = lambda_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; + } + } + 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_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_87_type, seq); + return seq; +} + +// _loop1_88: lambda_param_maybe_default +static asdl_seq * +_loop1_88_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; + { // lambda_param_maybe_default + NameDefaultPair* lambda_param_maybe_default_var; + while ( + (lambda_param_maybe_default_var = lambda_param_maybe_default_rule(p)) // lambda_param_maybe_default + ) + { + res = lambda_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; + } + } + 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_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_88_type, seq); + return seq; +} + +// _loop1_89: ('or' conjunction) +static asdl_seq * +_loop1_89_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; + { // ('or' conjunction) + void *_tmp_140_var; + while ( + (_tmp_140_var = _tmp_140_rule(p)) // 'or' conjunction + ) + { + res = _tmp_140_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_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_89_type, seq); + return seq; +} + +// _loop1_90: ('and' inversion) +static asdl_seq * +_loop1_90_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; + { // ('and' inversion) + void *_tmp_141_var; + while ( + (_tmp_141_var = _tmp_141_rule(p)) // 'and' inversion + ) + { + res = _tmp_141_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_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_90_type, seq); + return seq; +} + +// _loop1_91: compare_op_bitwise_or_pair +static asdl_seq * +_loop1_91_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; + { // compare_op_bitwise_or_pair + CmpopExprPair* compare_op_bitwise_or_pair_var; + while ( + (compare_op_bitwise_or_pair_var = compare_op_bitwise_or_pair_rule(p)) // compare_op_bitwise_or_pair + ) + { + res = compare_op_bitwise_or_pair_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_91"); + 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_91_type, seq); + return seq; +} + +// _tmp_92: '!=' +static void * +_tmp_92_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // '!=' + Token * tok; + if ( + (tok = _PyPegen_expect_token(p, 28)) // token='!=' + ) + { + res = _PyPegen_check_barry_as_flufl ( p ) ? NULL : tok; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _loop0_94: ',' slice +static asdl_seq * +_loop0_94_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; + { // ',' slice + expr_ty elem; + Token * literal; + while ( + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = slice_rule(p)) // slice + ) + { + 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_94"); + 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_94_type, seq); + return seq; +} + +// _gather_93: slice _loop0_94 +static asdl_seq * +_gather_93_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq * res = NULL; + int mark = p->mark; + { // slice _loop0_94 + expr_ty elem; + asdl_seq * seq; + if ( + (elem = slice_rule(p)) // slice + && + (seq = _loop0_94_rule(p)) // _loop0_94 + ) + { + res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_95: ':' expression? +static void * +_tmp_95_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // ':' expression? + void *d; + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (d = expression_rule(p), 1) // expression? + ) + { + res = d; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_96: tuple | group | genexp +static void * +_tmp_96_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // tuple + expr_ty tuple_var; + if ( + (tuple_var = tuple_rule(p)) // tuple + ) + { + res = tuple_var; + goto done; + } + p->mark = mark; + } + { // group + expr_ty group_var; + if ( + (group_var = group_rule(p)) // group + ) + { + res = group_var; + goto done; + } + p->mark = mark; + } + { // genexp + expr_ty genexp_var; + if ( + (genexp_var = genexp_rule(p)) // genexp + ) + { + res = genexp_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_97: list | listcomp +static void * +_tmp_97_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // list + expr_ty list_var; + if ( + (list_var = list_rule(p)) // list + ) + { + res = list_var; + goto done; + } + p->mark = mark; + } + { // listcomp + expr_ty listcomp_var; + if ( + (listcomp_var = listcomp_rule(p)) // listcomp + ) + { + res = listcomp_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_98: dict | set | dictcomp | setcomp +static void * +_tmp_98_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // dict + expr_ty dict_var; + if ( + (dict_var = dict_rule(p)) // dict + ) + { + res = dict_var; + goto done; + } + p->mark = mark; + } + { // set + expr_ty set_var; + if ( + (set_var = set_rule(p)) // set + ) + { + res = set_var; + goto done; + } + p->mark = mark; + } + { // dictcomp + expr_ty dictcomp_var; + if ( + (dictcomp_var = dictcomp_rule(p)) // dictcomp + ) + { + res = dictcomp_var; + goto done; + } + p->mark = mark; + } + { // setcomp + expr_ty setcomp_var; + if ( + (setcomp_var = setcomp_rule(p)) // setcomp + ) + { + res = setcomp_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _loop1_99: STRING +static asdl_seq * +_loop1_99_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; + { // STRING + expr_ty string_var; + while ( + (string_var = _PyPegen_string_token(p)) // STRING + ) + { + res = string_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_99"); + 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_99_type, seq); + return seq; +} + +// _tmp_100: star_named_expression ',' star_named_expressions? +static void * +_tmp_100_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // star_named_expression ',' star_named_expressions? + Token * literal; + expr_ty y; + void *z; + if ( + (y = star_named_expression_rule(p)) // star_named_expression + && + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (z = star_named_expressions_rule(p), 1) // star_named_expressions? + ) + { + res = _PyPegen_seq_insert_in_front ( p , y , z ); + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_101: yield_expr | named_expression +static void * +_tmp_101_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)) // yield_expr + ) + { + res = yield_expr_var; + goto done; + } + p->mark = mark; + } + { // named_expression + expr_ty named_expression_var; + if ( + (named_expression_var = named_expression_rule(p)) // named_expression + ) + { + res = named_expression_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _loop0_103: ',' kvpair +static asdl_seq * +_loop0_103_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; + { // ',' kvpair + KeyValuePair* elem; + Token * literal; + while ( + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = kvpair_rule(p)) // kvpair + ) + { + 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_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, _loop0_103_type, seq); + return seq; +} + +// _gather_102: kvpair _loop0_103 +static asdl_seq * +_gather_102_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq * res = NULL; + int mark = p->mark; + { // kvpair _loop0_103 + KeyValuePair* elem; + asdl_seq * seq; + if ( + (elem = kvpair_rule(p)) // kvpair + && + (seq = _loop0_103_rule(p)) // _loop0_103 + ) + { + res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _loop1_104: for_if_clause +static asdl_seq * +_loop1_104_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; + { // for_if_clause + comprehension_ty for_if_clause_var; + while ( + (for_if_clause_var = for_if_clause_rule(p)) // for_if_clause + ) + { + res = for_if_clause_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_104"); + 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_104_type, seq); + return seq; +} + +// _loop0_105: ('if' disjunction) +static asdl_seq * +_loop0_105_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; + { // ('if' disjunction) + void *_tmp_142_var; + while ( + (_tmp_142_var = _tmp_142_rule(p)) // 'if' disjunction + ) + { + res = _tmp_142_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_105"); + 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_105_type, seq); + return seq; +} + +// _loop0_106: ('if' disjunction) +static asdl_seq * +_loop0_106_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; + { // ('if' disjunction) + void *_tmp_143_var; + while ( + (_tmp_143_var = _tmp_143_rule(p)) // 'if' disjunction + ) + { + res = _tmp_143_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_106"); + 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); + return seq; +} + +// _tmp_107: ',' args +static void * +_tmp_107_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // ',' args + expr_ty c; + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (c = args_rule(p)) // args + ) + { + res = c; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_108: ',' args +static void * +_tmp_108_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // ',' args + expr_ty c; + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (c = args_rule(p)) // args + ) + { + res = c; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _loop0_110: ',' kwarg_or_starred +static asdl_seq * +_loop0_110_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; + { // ',' kwarg_or_starred + KeywordOrStarred* elem; + Token * literal; + while ( + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = kwarg_or_starred_rule(p)) // kwarg_or_starred + ) + { + 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_110"); + 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_110_type, seq); + return seq; +} + +// _gather_109: kwarg_or_starred _loop0_110 +static asdl_seq * +_gather_109_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq * res = NULL; + int mark = p->mark; + { // kwarg_or_starred _loop0_110 + KeywordOrStarred* elem; + asdl_seq * seq; + if ( + (elem = kwarg_or_starred_rule(p)) // kwarg_or_starred + && + (seq = _loop0_110_rule(p)) // _loop0_110 + ) + { + res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _loop0_112: ',' kwarg_or_double_starred +static asdl_seq * +_loop0_112_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; + { // ',' kwarg_or_double_starred + KeywordOrStarred* elem; + Token * literal; + while ( + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = kwarg_or_double_starred_rule(p)) // kwarg_or_double_starred + ) + { + 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_112"); + 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_112_type, seq); + return seq; +} + +// _gather_111: kwarg_or_double_starred _loop0_112 +static asdl_seq * +_gather_111_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq * res = NULL; + int mark = p->mark; + { // kwarg_or_double_starred _loop0_112 + KeywordOrStarred* elem; + asdl_seq * seq; + if ( + (elem = kwarg_or_double_starred_rule(p)) // kwarg_or_double_starred + && + (seq = _loop0_112_rule(p)) // _loop0_112 + ) + { + res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _loop0_114: ',' kwarg_or_starred +static asdl_seq * +_loop0_114_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; + { // ',' kwarg_or_starred + KeywordOrStarred* elem; + Token * literal; + while ( + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = kwarg_or_starred_rule(p)) // kwarg_or_starred + ) + { + 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_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_114_type, seq); + return seq; +} + +// _gather_113: kwarg_or_starred _loop0_114 +static asdl_seq * +_gather_113_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq * res = NULL; + int mark = p->mark; + { // kwarg_or_starred _loop0_114 + KeywordOrStarred* elem; + asdl_seq * seq; + if ( + (elem = kwarg_or_starred_rule(p)) // kwarg_or_starred + && + (seq = _loop0_114_rule(p)) // _loop0_114 + ) + { + res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _loop0_116: ',' kwarg_or_double_starred +static asdl_seq * +_loop0_116_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; + { // ',' kwarg_or_double_starred + KeywordOrStarred* elem; + Token * literal; + while ( + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = kwarg_or_double_starred_rule(p)) // kwarg_or_double_starred + ) + { + 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_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_116_type, seq); + return seq; +} + +// _gather_115: kwarg_or_double_starred _loop0_116 +static asdl_seq * +_gather_115_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq * res = NULL; + int mark = p->mark; + { // kwarg_or_double_starred _loop0_116 + KeywordOrStarred* elem; + asdl_seq * seq; + if ( + (elem = kwarg_or_double_starred_rule(p)) // kwarg_or_double_starred + && + (seq = _loop0_116_rule(p)) // _loop0_116 + ) + { + res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _loop0_117: (',' star_target) +static asdl_seq * +_loop0_117_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; + { // (',' star_target) + void *_tmp_144_var; + while ( + (_tmp_144_var = _tmp_144_rule(p)) // ',' star_target + ) + { + res = _tmp_144_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_117"); + 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_117_type, seq); + return seq; +} + +// _loop0_119: ',' star_target +static asdl_seq * +_loop0_119_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; + { // ',' star_target + expr_ty elem; + Token * literal; + while ( + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = star_target_rule(p)) // star_target + ) + { + 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_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_119_type, seq); + return seq; +} + +// _gather_118: star_target _loop0_119 +static asdl_seq * +_gather_118_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq * res = NULL; + int mark = p->mark; + { // star_target _loop0_119 + expr_ty elem; + asdl_seq * seq; + if ( + (elem = star_target_rule(p)) // star_target + && + (seq = _loop0_119_rule(p)) // _loop0_119 + ) + { + res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_120: !'*' star_target +static void * +_tmp_120_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // !'*' star_target + expr_ty star_target_var; + if ( + _PyPegen_lookahead_with_int(0, _PyPegen_expect_token, p, 16) // token='*' + && + (star_target_var = star_target_rule(p)) // star_target + ) + { + res = star_target_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _loop0_122: ',' del_target +static asdl_seq * +_loop0_122_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; + { // ',' del_target + expr_ty elem; + Token * literal; + while ( + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = del_target_rule(p)) // del_target + ) + { + 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_122"); + 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_122_type, seq); + return seq; +} + +// _gather_121: del_target _loop0_122 +static asdl_seq * +_gather_121_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq * res = NULL; + int mark = p->mark; + { // del_target _loop0_122 + expr_ty elem; + asdl_seq * seq; + if ( + (elem = del_target_rule(p)) // del_target + && + (seq = _loop0_122_rule(p)) // _loop0_122 + ) + { + res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _loop0_124: ',' target +static asdl_seq * +_loop0_124_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; + { // ',' target + expr_ty elem; + Token * literal; + while ( + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = target_rule(p)) // target + ) + { + 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_124"); + 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_124_type, seq); + return seq; +} + +// _gather_123: target _loop0_124 +static asdl_seq * +_gather_123_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + asdl_seq * res = NULL; + int mark = p->mark; + { // target _loop0_124 + expr_ty elem; + asdl_seq * seq; + if ( + (elem = target_rule(p)) // target + && + (seq = _loop0_124_rule(p)) // _loop0_124 + ) + { + res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_125: args | expression for_if_clauses +static void * +_tmp_125_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // args + expr_ty args_var; + if ( + (args_var = args_rule(p)) // args + ) + { + res = args_var; + goto done; + } + p->mark = mark; + } + { // expression for_if_clauses + expr_ty expression_var; + asdl_seq* for_if_clauses_var; + if ( + (expression_var = expression_rule(p)) // expression + && + (for_if_clauses_var = for_if_clauses_rule(p)) // for_if_clauses + ) + { + res = _PyPegen_dummy_name(p, expression_var, for_if_clauses_var); + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_126: '=' annotated_rhs +static void * +_tmp_126_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // '=' annotated_rhs + expr_ty annotated_rhs_var; + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 22)) // token='=' + && + (annotated_rhs_var = annotated_rhs_rule(p)) // annotated_rhs + ) + { + res = _PyPegen_dummy_name(p, literal, annotated_rhs_var); + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_127: '=' | augassign +static void * +_tmp_127_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // '=' + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 22)) // token='=' + ) + { + res = literal; + goto done; + } + p->mark = mark; + } + { // augassign + AugOperator* augassign_var; + if ( + (augassign_var = augassign_rule(p)) // augassign + ) + { + res = augassign_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_128: yield_expr | star_expressions +static void * +_tmp_128_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)) // yield_expr + ) + { + res = yield_expr_var; + goto done; + } + p->mark = mark; + } + { // star_expressions + expr_ty star_expressions_var; + if ( + (star_expressions_var = star_expressions_rule(p)) // star_expressions + ) + { + res = star_expressions_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_129: '[' | '(' | '{' +static void * +_tmp_129_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // '[' + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 9)) // token='[' + ) + { + res = literal; + goto done; + } + p->mark = mark; + } + { // '(' + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 7)) // token='(' + ) + { + res = literal; + goto done; + } + p->mark = mark; + } + { // '{' + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 25)) // token='{' + ) + { + res = literal; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _loop0_130: param_no_default +static asdl_seq * +_loop0_130_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)) // param_no_default + ) + { + 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_130"); + 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_130_type, seq); + return seq; +} + +// _tmp_131: slash_with_default | param_with_default+ +static void * +_tmp_131_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // slash_with_default + SlashWithDefault* slash_with_default_var; + if ( + (slash_with_default_var = slash_with_default_rule(p)) // slash_with_default + ) + { + res = slash_with_default_var; + goto done; + } + p->mark = mark; + } + { // param_with_default+ + asdl_seq * _loop1_145_var; + if ( + (_loop1_145_var = _loop1_145_rule(p)) // param_with_default+ + ) + { + res = _loop1_145_var; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_132: ')' | ',' (')' | '**') +static void * +_tmp_132_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // ')' + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 8)) // token=')' + ) + { + res = literal; + goto done; + } + p->mark = mark; + } + { // ',' (')' | '**') + void *_tmp_146_var; + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (_tmp_146_var = _tmp_146_rule(p)) // ')' | '**' + ) + { + res = _PyPegen_dummy_name(p, literal, _tmp_146_var); + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_133: ':' | ',' (':' | '**') +static void * +_tmp_133_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // ':' + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 11)) // token=':' + ) + { + res = literal; + goto done; + } + p->mark = mark; + } + { // ',' (':' | '**') + void *_tmp_147_var; + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (_tmp_147_var = _tmp_147_rule(p)) // ':' | '**' + ) + { + res = _PyPegen_dummy_name(p, literal, _tmp_147_var); + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_134: star_targets '=' +static void * +_tmp_134_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // star_targets '=' + Token * literal; + expr_ty z; + if ( + (z = star_targets_rule(p)) // star_targets + && + (literal = _PyPegen_expect_token(p, 22)) // token='=' + ) + { + res = z; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_135: '.' | '...' +static void * +_tmp_135_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // '.' + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 23)) // token='.' + ) + { + res = literal; + goto done; + } + p->mark = mark; + } + { // '...' + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 52)) // token='...' + ) + { + res = literal; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_136: '.' | '...' +static void * +_tmp_136_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // '.' + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 23)) // token='.' + ) + { + res = literal; + goto done; + } + p->mark = mark; + } + { // '...' + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 52)) // token='...' + ) + { + res = literal; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_137: '@' named_expression NEWLINE +static void * +_tmp_137_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // '@' named_expression NEWLINE + expr_ty f; + Token * literal; + Token * newline_var; + if ( + (literal = _PyPegen_expect_token(p, 49)) // token='@' + && + (f = named_expression_rule(p)) // named_expression + && + (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + ) + { + res = f; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_138: ',' star_expression +static void * +_tmp_138_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // ',' star_expression + expr_ty c; + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (c = star_expression_rule(p)) // star_expression + ) + { + res = c; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_139: ',' expression +static void * +_tmp_139_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // ',' expression + expr_ty c; + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (c = expression_rule(p)) // expression + ) + { + res = c; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_140: 'or' conjunction +static void * +_tmp_140_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // 'or' conjunction + expr_ty c; + Token * keyword; + if ( + (keyword = _PyPegen_expect_token(p, 532)) // token='or' + && + (c = conjunction_rule(p)) // conjunction + ) + { + res = c; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_141: 'and' inversion +static void * +_tmp_141_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // 'and' inversion + expr_ty c; + Token * keyword; + if ( + (keyword = _PyPegen_expect_token(p, 533)) // token='and' + && + (c = inversion_rule(p)) // inversion + ) + { + res = c; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_142: 'if' disjunction +static void * +_tmp_142_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // 'if' disjunction + Token * keyword; + expr_ty z; + if ( + (keyword = _PyPegen_expect_token(p, 510)) // token='if' + && + (z = disjunction_rule(p)) // disjunction + ) + { + res = z; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_143: 'if' disjunction +static void * +_tmp_143_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // 'if' disjunction + Token * keyword; + expr_ty z; + if ( + (keyword = _PyPegen_expect_token(p, 510)) // token='if' + && + (z = disjunction_rule(p)) // disjunction + ) + { + res = z; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_144: ',' star_target +static void * +_tmp_144_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // ',' star_target + expr_ty c; + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (c = star_target_rule(p)) // star_target + ) + { + res = c; + if (res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + return NULL; + } + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _loop1_145: param_with_default +static asdl_seq * +_loop1_145_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)) // param_with_default + ) + { + 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_145"); + 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_145_type, seq); + return seq; +} + +// _tmp_146: ')' | '**' +static void * +_tmp_146_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // ')' + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 8)) // token=')' + ) + { + res = literal; + goto done; + } + p->mark = mark; + } + { // '**' + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 35)) // token='**' + ) + { + res = literal; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +// _tmp_147: ':' | '**' +static void * +_tmp_147_rule(Parser *p) +{ + if (p->error_indicator) { + return NULL; + } + void * res = NULL; + int mark = p->mark; + { // ':' + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 11)) // token=':' + ) + { + res = literal; + goto done; + } + p->mark = mark; + } + { // '**' + Token * literal; + if ( + (literal = _PyPegen_expect_token(p, 35)) // token='**' + ) + { + res = literal; + goto done; + } + p->mark = mark; + } + res = NULL; + done: + return res; +} + +void * +_PyPegen_parse(Parser *p) +{ + // Initialize keywords + p->keywords = reserved_keywords; + p->n_keyword_lists = n_keyword_lists; + + // Run parser + void *result = NULL; + if (p->start_rule == Py_file_input) { + result = file_rule(p); + } else if (p->start_rule == Py_single_input) { + result = interactive_rule(p); + } else if (p->start_rule == Py_eval_input) { + result = eval_rule(p); + } 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); + } + + return result; +} + +// The end diff --git a/ast3/Parser/pegen/parse_string.c b/ast3/Parser/pegen/parse_string.c new file mode 100644 index 00000000..ca4b733c --- /dev/null +++ b/ast3/Parser/pegen/parse_string.c @@ -0,0 +1,1414 @@ +#include + +#include "../tokenizer.h" +#include "pegen.h" +#include "parse_string.h" + +//// STRING HANDLING FUNCTIONS //// + +// These functions are ported directly from Python/ast.c with some modifications +// to account for the use of "Parser *p", the fact that don't have parser nodes +// to pass around and the usage of some specialized APIs present only in this +// file (like "_PyPegen_raise_syntax_error"). + +static int +warn_invalid_escape_sequence(Parser *p, unsigned char first_invalid_escape_char, Token *t) +{ + PyObject *msg = + PyUnicode_FromFormat("invalid escape sequence \\%c", first_invalid_escape_char); + if (msg == NULL) { + return -1; + } + if (PyErr_WarnExplicitObject(PyExc_DeprecationWarning, msg, p->tok->filename, + t->lineno, NULL, NULL) < 0) { + if (PyErr_ExceptionMatches(PyExc_DeprecationWarning)) { + /* Replace the DeprecationWarning exception with a SyntaxError + to get a more accurate error report */ + PyErr_Clear(); + + /* This is needed, in order for the SyntaxError to point to the token t, + since _PyPegen_raise_error uses p->tokens[p->fill - 1] for the + error location, if p->known_err_token is not set. */ + p->known_err_token = t; + RAISE_SYNTAX_ERROR("invalid escape sequence \\%c", first_invalid_escape_char); + } + Py_DECREF(msg); + return -1; + } + Py_DECREF(msg); + return 0; +} + +static PyObject * +decode_utf8(const char **sPtr, const char *end) +{ + const char *s, *t; + t = s = *sPtr; + while (s < end && (*s & 0x80)) { + s++; + } + *sPtr = s; + return PyUnicode_DecodeUTF8(t, s - t, NULL); +} + +static PyObject * +decode_unicode_with_escapes(Parser *parser, const char *s, size_t len, Token *t) +{ + PyObject *v, *u; + char *buf; + char *p; + const char *end; + + /* check for integer overflow */ + if (len > SIZE_MAX / 6) { + return NULL; + } + /* "ä" (2 bytes) may become "\U000000E4" (10 bytes), or 1:5 + "\ä" (3 bytes) may become "\u005c\U000000E4" (16 bytes), or ~1:6 */ + u = PyBytes_FromStringAndSize((char *)NULL, len * 6); + if (u == NULL) { + return NULL; + } + p = buf = PyBytes_AsString(u); + end = s + len; + while (s < end) { + if (*s == '\\') { + *p++ = *s++; + if (s >= end || *s & 0x80) { + strcpy(p, "u005c"); + p += 5; + if (s >= end) { + break; + } + } + } + if (*s & 0x80) { + PyObject *w; + int kind; + void *data; + Py_ssize_t len, i; + w = decode_utf8(&s, end); + if (w == NULL) { + Py_DECREF(u); + return NULL; + } + kind = PyUnicode_KIND(w); + data = PyUnicode_DATA(w); + len = PyUnicode_GET_LENGTH(w); + for (i = 0; i < len; i++) { + Py_UCS4 chr = PyUnicode_READ(kind, data, i); + sprintf(p, "\\U%08x", chr); + p += 10; + } + /* Should be impossible to overflow */ + assert(p - buf <= PyBytes_GET_SIZE(u)); + Py_DECREF(w); + } + else { + *p++ = *s++; + } + } + len = p - buf; + s = buf; + + const char *first_invalid_escape; + v = _PyUnicode_DecodeUnicodeEscape(s, len, NULL, &first_invalid_escape); + + if (v != NULL && first_invalid_escape != NULL) { + if (warn_invalid_escape_sequence(parser, *first_invalid_escape, t) < 0) { + /* We have not decref u before because first_invalid_escape points + inside u. */ + Py_XDECREF(u); + Py_DECREF(v); + return NULL; + } + } + Py_XDECREF(u); + return v; +} + +static PyObject * +decode_bytes_with_escapes(Parser *p, const char *s, Py_ssize_t len, Token *t) +{ + const char *first_invalid_escape; + PyObject *result = _PyBytes_DecodeEscape(s, len, NULL, &first_invalid_escape); + if (result == NULL) { + return NULL; + } + + if (first_invalid_escape != NULL) { + if (warn_invalid_escape_sequence(p, *first_invalid_escape, t) < 0) { + Py_DECREF(result); + return NULL; + } + } + return result; +} + +/* s must include the bracketing quote characters, and r, b, u, + &/or f prefixes (if any), and embedded escape sequences (if any). + _PyPegen_parsestr parses it, and sets *result to decoded Python string object. + If the string is an f-string, set *fstr and *fstrlen to the unparsed + string object. Return 0 if no errors occurred. */ +int +_PyPegen_parsestr(Parser *p, int *bytesmode, int *rawmode, PyObject **result, + const char **fstr, Py_ssize_t *fstrlen, Token *t) +{ + const char *s = PyBytes_AsString(t->bytes); + if (s == NULL) { + return -1; + } + + size_t len; + int quote = Py_CHARMASK(*s); + int fmode = 0; + *bytesmode = 0; + *rawmode = 0; + *result = NULL; + *fstr = NULL; + if (Py_ISALPHA(quote)) { + while (!*bytesmode || !*rawmode) { + if (quote == 'b' || quote == 'B') { + quote = *++s; + *bytesmode = 1; + } + else if (quote == 'u' || quote == 'U') { + quote = *++s; + } + else if (quote == 'r' || quote == 'R') { + quote = *++s; + *rawmode = 1; + } + else if (quote == 'f' || quote == 'F') { + quote = *++s; + fmode = 1; + } + else { + break; + } + } + } + + /* fstrings are only allowed in Python 3.6 and greater */ + if (fmode && p->feature_version < 6) { + p->error_indicator = 1; + RAISE_SYNTAX_ERROR("Format strings are only supported in Python 3.6 and greater"); + return -1; + } + + if (fmode && *bytesmode) { + PyErr_BadInternalCall(); + return -1; + } + if (quote != '\'' && quote != '\"') { + PyErr_BadInternalCall(); + return -1; + } + /* Skip the leading quote char. */ + s++; + len = strlen(s); + if (len > INT_MAX) { + PyErr_SetString(PyExc_OverflowError, "string to parse is too long"); + return -1; + } + if (s[--len] != quote) { + /* Last quote char must match the first. */ + PyErr_BadInternalCall(); + return -1; + } + if (len >= 4 && s[0] == quote && s[1] == quote) { + /* A triple quoted string. We've already skipped one quote at + the start and one at the end of the string. Now skip the + two at the start. */ + s += 2; + len -= 2; + /* And check that the last two match. */ + if (s[--len] != quote || s[--len] != quote) { + PyErr_BadInternalCall(); + return -1; + } + } + + if (fmode) { + /* Just return the bytes. The caller will parse the resulting + string. */ + *fstr = s; + *fstrlen = len; + return 0; + } + + /* Not an f-string. */ + /* Avoid invoking escape decoding routines if possible. */ + *rawmode = *rawmode || strchr(s, '\\') == NULL; + if (*bytesmode) { + /* Disallow non-ASCII characters. */ + const char *ch; + for (ch = s; *ch; ch++) { + if (Py_CHARMASK(*ch) >= 0x80) { + RAISE_SYNTAX_ERROR( + "bytes can only contain ASCII " + "literal characters."); + return -1; + } + } + if (*rawmode) { + *result = PyBytes_FromStringAndSize(s, len); + } + else { + *result = decode_bytes_with_escapes(p, s, len, t); + } + } + else { + if (*rawmode) { + *result = PyUnicode_DecodeUTF8Stateful(s, len, NULL, NULL); + } + else { + *result = decode_unicode_with_escapes(p, s, len, t); + } + } + return *result == NULL ? -1 : 0; +} + + + +// FSTRING STUFF + +static void fstring_shift_expr_locations(expr_ty n, int lineno, int col_offset); +static void fstring_shift_argument(expr_ty parent, arg_ty args, int lineno, int col_offset); + + +static inline void shift_expr(expr_ty parent, expr_ty n, int line, int col) { + if (parent->lineno < n->lineno) { + col = 0; + } + fstring_shift_expr_locations(n, line, col); +} + +static inline void shift_arg(expr_ty parent, arg_ty n, int line, int col) { + if (parent->lineno < n->lineno) { + col = 0; + } + fstring_shift_argument(parent, n, line, col); +} + +static void fstring_shift_seq_locations(expr_ty parent, asdl_seq *seq, int lineno, int col_offset) { + for (Py_ssize_t i = 0, l = asdl_seq_LEN(seq); i < l; i++) { + expr_ty expr = asdl_seq_GET(seq, i); + if (expr == NULL){ + continue; + } + shift_expr(parent, expr, lineno, col_offset); + } +} + +static void fstring_shift_slice_locations(expr_ty parent, expr_ty slice, int lineno, int col_offset) { + switch (slice->kind) { + case Slice_kind: + if (slice->v.Slice.lower) { + shift_expr(parent, slice->v.Slice.lower, lineno, col_offset); + } + if (slice->v.Slice.upper) { + shift_expr(parent, slice->v.Slice.upper, lineno, col_offset); + } + if (slice->v.Slice.step) { + shift_expr(parent, slice->v.Slice.step, lineno, col_offset); + } + break; + case Tuple_kind: + fstring_shift_seq_locations(parent, slice->v.Tuple.elts, lineno, col_offset); + break; + default: + break; + } +} + +static void fstring_shift_comprehension(expr_ty parent, comprehension_ty comp, int lineno, int col_offset) { + shift_expr(parent, comp->target, lineno, col_offset); + shift_expr(parent, comp->iter, lineno, col_offset); + fstring_shift_seq_locations(parent, comp->ifs, lineno, col_offset); +} + +static void fstring_shift_argument(expr_ty parent, arg_ty arg, int lineno, int col_offset) { + if (arg->annotation != NULL){ + shift_expr(parent, arg->annotation, lineno, col_offset); + } + arg->col_offset = arg->col_offset + col_offset; + arg->end_col_offset = arg->end_col_offset + col_offset; + arg->lineno = arg->lineno + lineno; + arg->end_lineno = arg->end_lineno + lineno; +} + +static void fstring_shift_arguments(expr_ty parent, arguments_ty args, int lineno, int col_offset) { + for (Py_ssize_t i = 0, l = asdl_seq_LEN(args->posonlyargs); i < l; i++) { + arg_ty arg = asdl_seq_GET(args->posonlyargs, i); + shift_arg(parent, arg, lineno, col_offset); + } + + for (Py_ssize_t i = 0, l = asdl_seq_LEN(args->args); i < l; i++) { + arg_ty arg = asdl_seq_GET(args->args, i); + shift_arg(parent, arg, lineno, col_offset); + } + + if (args->vararg != NULL) { + shift_arg(parent, args->vararg, lineno, col_offset); + } + + for (Py_ssize_t i = 0, l = asdl_seq_LEN(args->kwonlyargs); i < l; i++) { + arg_ty arg = asdl_seq_GET(args->kwonlyargs, i); + shift_arg(parent, arg, lineno, col_offset); + } + + fstring_shift_seq_locations(parent, args->kw_defaults, lineno, col_offset); + + if (args->kwarg != NULL) { + shift_arg(parent, args->kwarg, lineno, col_offset); + } + + fstring_shift_seq_locations(parent, args->defaults, lineno, col_offset); +} + +static void fstring_shift_children_locations(expr_ty n, int lineno, int col_offset) { + switch (n->kind) { + case BoolOp_kind: + fstring_shift_seq_locations(n, n->v.BoolOp.values, lineno, col_offset); + break; + case NamedExpr_kind: + shift_expr(n, n->v.NamedExpr.target, lineno, col_offset); + shift_expr(n, n->v.NamedExpr.value, lineno, col_offset); + break; + case BinOp_kind: + shift_expr(n, n->v.BinOp.left, lineno, col_offset); + shift_expr(n, n->v.BinOp.right, lineno, col_offset); + break; + case UnaryOp_kind: + shift_expr(n, n->v.UnaryOp.operand, lineno, col_offset); + break; + case Lambda_kind: + fstring_shift_arguments(n, n->v.Lambda.args, lineno, col_offset); + shift_expr(n, n->v.Lambda.body, lineno, col_offset); + break; + case IfExp_kind: + shift_expr(n, n->v.IfExp.test, lineno, col_offset); + shift_expr(n, n->v.IfExp.body, lineno, col_offset); + shift_expr(n, n->v.IfExp.orelse, lineno, col_offset); + break; + case Dict_kind: + fstring_shift_seq_locations(n, n->v.Dict.keys, lineno, col_offset); + fstring_shift_seq_locations(n, n->v.Dict.values, lineno, col_offset); + break; + case Set_kind: + fstring_shift_seq_locations(n, n->v.Set.elts, lineno, col_offset); + break; + case ListComp_kind: + shift_expr(n, n->v.ListComp.elt, lineno, col_offset); + for (Py_ssize_t i = 0, l = asdl_seq_LEN(n->v.ListComp.generators); i < l; i++) { + comprehension_ty comp = asdl_seq_GET(n->v.ListComp.generators, i); + fstring_shift_comprehension(n, comp, lineno, col_offset); + } + break; + case SetComp_kind: + shift_expr(n, n->v.SetComp.elt, lineno, col_offset); + for (Py_ssize_t i = 0, l = asdl_seq_LEN(n->v.SetComp.generators); i < l; i++) { + comprehension_ty comp = asdl_seq_GET(n->v.SetComp.generators, i); + fstring_shift_comprehension(n, comp, lineno, col_offset); + } + break; + case DictComp_kind: + shift_expr(n, n->v.DictComp.key, lineno, col_offset); + shift_expr(n, n->v.DictComp.value, lineno, col_offset); + for (Py_ssize_t i = 0, l = asdl_seq_LEN(n->v.DictComp.generators); i < l; i++) { + comprehension_ty comp = asdl_seq_GET(n->v.DictComp.generators, i); + fstring_shift_comprehension(n, comp, lineno, col_offset); + } + break; + case GeneratorExp_kind: + shift_expr(n, n->v.GeneratorExp.elt, lineno, col_offset); + for (Py_ssize_t i = 0, l = asdl_seq_LEN(n->v.GeneratorExp.generators); i < l; i++) { + comprehension_ty comp = asdl_seq_GET(n->v.GeneratorExp.generators, i); + fstring_shift_comprehension(n, comp, lineno, col_offset); + } + break; + case Await_kind: + shift_expr(n, n->v.Await.value, lineno, col_offset); + break; + case Yield_kind: + shift_expr(n, n->v.Yield.value, lineno, col_offset); + break; + case YieldFrom_kind: + shift_expr(n, n->v.YieldFrom.value, lineno, col_offset); + break; + case Compare_kind: + shift_expr(n, n->v.Compare.left, lineno, col_offset); + fstring_shift_seq_locations(n, n->v.Compare.comparators, lineno, col_offset); + break; + case Call_kind: + shift_expr(n, n->v.Call.func, lineno, col_offset); + fstring_shift_seq_locations(n, n->v.Call.args, lineno, col_offset); + for (Py_ssize_t i = 0, l = asdl_seq_LEN(n->v.Call.keywords); i < l; i++) { + keyword_ty keyword = asdl_seq_GET(n->v.Call.keywords, i); + shift_expr(n, keyword->value, lineno, col_offset); + } + break; + case Attribute_kind: + shift_expr(n, n->v.Attribute.value, lineno, col_offset); + break; + case Subscript_kind: + shift_expr(n, n->v.Subscript.value, lineno, col_offset); + fstring_shift_slice_locations(n, n->v.Subscript.slice, lineno, col_offset); + shift_expr(n, n->v.Subscript.slice, lineno, col_offset); + break; + case Starred_kind: + shift_expr(n, n->v.Starred.value, lineno, col_offset); + break; + case List_kind: + fstring_shift_seq_locations(n, n->v.List.elts, lineno, col_offset); + break; + case Tuple_kind: + fstring_shift_seq_locations(n, n->v.Tuple.elts, lineno, col_offset); + break; + case JoinedStr_kind: + fstring_shift_seq_locations(n, n->v.JoinedStr.values, lineno, col_offset); + break; + case FormattedValue_kind: + shift_expr(n, n->v.FormattedValue.value, lineno, col_offset); + if (n->v.FormattedValue.format_spec) { + shift_expr(n, n->v.FormattedValue.format_spec, lineno, col_offset); + } + break; + default: + return; + } +} + +/* Shift locations for the given node and all its children by adding `lineno` + and `col_offset` to existing locations. Note that n is the already parsed + expression. */ +static void fstring_shift_expr_locations(expr_ty n, int lineno, int col_offset) +{ + n->col_offset = n->col_offset + col_offset; + + // The following is needed, in order for nodes spanning across multiple lines + // to be shifted correctly. An example of such a node is a Call node, the closing + // parenthesis of which is not on the same line as its name. + if (n->lineno == n->end_lineno) { + n->end_col_offset = n->end_col_offset + col_offset; + } + + fstring_shift_children_locations(n, lineno, col_offset); + n->lineno = n->lineno + lineno; + n->end_lineno = n->end_lineno + lineno; +} + +/* Fix locations for the given node and its children. + + `parent` is the enclosing node. + `n` is the node which locations are going to be fixed relative to parent. + `expr_str` is the child node's string representation, including braces. +*/ +static void +fstring_fix_expr_location(Token *parent, expr_ty n, char *expr_str) +{ + char *substr = NULL; + char *start; + int lines = 0; + int cols = 0; + + if (parent && parent->bytes) { + char *parent_str = PyBytes_AsString(parent->bytes); + if (!parent_str) { + return; + } + substr = strstr(parent_str, expr_str); + if (substr) { + // The following is needed, in order to correctly shift the column + // offset, in the case that (disregarding any whitespace) a newline + // immediately follows the opening curly brace of the fstring expression. + int newline_after_brace = 1; + start = substr + 1; + while (start && *start != '}' && *start != '\n') { + if (*start != ' ' && *start != '\t' && *start != '\f') { + newline_after_brace = 0; + break; + } + start++; + } + + // Account for the characters from the last newline character to our + // left until the beginning of substr. + if (!newline_after_brace) { + start = substr; + while (start > parent_str && *start != '\n') { + start--; + } + cols += (int)(substr - start); + } + /* adjust the start based on the number of newlines encountered + before the f-string expression */ + for (char* p = parent_str; p < substr; p++) { + if (*p == '\n') { + lines++; + } + } + } + } + fstring_shift_expr_locations(n, lines, cols); +} + + +/* Compile this expression in to an expr_ty. Add parens around the + expression, in order to allow leading spaces in the expression. */ +static expr_ty +fstring_compile_expr(Parser *p, const char *expr_start, const char *expr_end, + Token *t) +{ + expr_ty expr = NULL; + char *str; + Py_ssize_t len; + const char *s; + expr_ty result = NULL; + + assert(expr_end >= expr_start); + assert(*(expr_start-1) == '{'); + assert(*expr_end == '}' || *expr_end == '!' || *expr_end == ':' || + *expr_end == '='); + + /* If the substring is all whitespace, it's an error. We need to catch this + here, and not when we call PyParser_SimpleParseStringFlagsFilename, + because turning the expression '' in to '()' would go from being invalid + to valid. */ + for (s = expr_start; s != expr_end; s++) { + char c = *s; + /* The Python parser ignores only the following whitespace + characters (\r already is converted to \n). */ + if (!(c == ' ' || c == '\t' || c == '\n' || c == '\f')) { + break; + } + } + if (s == expr_end) { + RAISE_SYNTAX_ERROR("f-string: empty expression not allowed"); + return NULL; + } + + len = expr_end - expr_start; + /* Allocate 3 extra bytes: open paren, close paren, null byte. */ + str = PyMem_RawMalloc(len + 3); + if (str == NULL) { + PyErr_NoMemory(); + return NULL; + } + + str[0] = '('; + memcpy(str+1, expr_start, len); + str[len+1] = ')'; + str[len+2] = 0; + + struct tok_state* tok = PyTokenizer_FromString(str, 1); + if (tok == NULL) { + return NULL; + } + tok->filename = PyUnicode_FromString(""); + if (!tok->filename) { + PyTokenizer_Free(tok); + return NULL; + } + + Parser *p2 = _PyPegen_Parser_New(tok, Py_fstring_input, p->flags, p->feature_version, + NULL, p->arena); + p2->starting_lineno = p->starting_lineno + p->tok->first_lineno - 1; + p2->starting_col_offset = p->tok->first_lineno == p->tok->lineno + ? p->starting_col_offset + t->col_offset : 0; + + expr = _PyPegen_run_parser(p2); + + if (expr == NULL) { + goto exit; + } + + /* Reuse str to find the correct column offset. */ + str[0] = '{'; + str[len+1] = '}'; + fstring_fix_expr_location(t, expr, str); + + result = expr; + +exit: + _PyPegen_Parser_Free(p2); + PyTokenizer_Free(tok); + return result; +} + +/* Return -1 on error. + + Return 0 if we reached the end of the literal. + + Return 1 if we haven't reached the end of the literal, but we want + the caller to process the literal up to this point. Used for + doubled braces. +*/ +static int +fstring_find_literal(Parser *p, const char **str, const char *end, int raw, + PyObject **literal, int recurse_lvl, Token *t) +{ + /* Get any literal string. It ends when we hit an un-doubled left + brace (which isn't part of a unicode name escape such as + "\N{EULER CONSTANT}"), or the end of the string. */ + + const char *s = *str; + const char *literal_start = s; + int result = 0; + + assert(*literal == NULL); + while (s < end) { + char ch = *s++; + if (!raw && ch == '\\' && s < end) { + ch = *s++; + if (ch == 'N') { + if (s < end && *s++ == '{') { + while (s < end && *s++ != '}') { + } + continue; + } + break; + } + if (ch == '{' && warn_invalid_escape_sequence(p, ch, t) < 0) { + return -1; + } + } + if (ch == '{' || ch == '}') { + /* Check for doubled braces, but only at the top level. If + we checked at every level, then f'{0:{3}}' would fail + with the two closing braces. */ + if (recurse_lvl == 0) { + if (s < end && *s == ch) { + /* We're going to tell the caller that the literal ends + here, but that they should continue scanning. But also + skip over the second brace when we resume scanning. */ + *str = s + 1; + result = 1; + goto done; + } + + /* Where a single '{' is the start of a new expression, a + single '}' is not allowed. */ + if (ch == '}') { + *str = s - 1; + RAISE_SYNTAX_ERROR("f-string: single '}' is not allowed"); + return -1; + } + } + /* We're either at a '{', which means we're starting another + expression; or a '}', which means we're at the end of this + f-string (for a nested format_spec). */ + s--; + break; + } + } + *str = s; + assert(s <= end); + assert(s == end || *s == '{' || *s == '}'); +done: + if (literal_start != s) { + if (raw) + *literal = PyUnicode_DecodeUTF8Stateful(literal_start, + s - literal_start, + NULL, NULL); + else + *literal = decode_unicode_with_escapes(p, literal_start, + s - literal_start, t); + if (!*literal) + return -1; + } + return result; +} + +/* Forward declaration because parsing is recursive. */ +static expr_ty +fstring_parse(Parser *p, const char **str, const char *end, int raw, int recurse_lvl, + Token *first_token, Token* t, Token *last_token); + +/* Parse the f-string at *str, ending at end. We know *str starts an + expression (so it must be a '{'). Returns the FormattedValue node, which + includes the expression, conversion character, format_spec expression, and + optionally the text of the expression (if = is used). + + Note that I don't do a perfect job here: I don't make sure that a + closing brace doesn't match an opening paren, for example. It + doesn't need to error on all invalid expressions, just correctly + find the end of all valid ones. Any errors inside the expression + will be caught when we parse it later. + + *expression is set to the expression. For an '=' "debug" expression, + *expr_text is set to the debug text (the original text of the expression, + including the '=' and any whitespace around it, as a string object). If + not a debug expression, *expr_text set to NULL. */ +static int +fstring_find_expr(Parser *p, const char **str, const char *end, int raw, int recurse_lvl, + PyObject **expr_text, expr_ty *expression, Token *first_token, + Token *t, Token *last_token) +{ + /* Return -1 on error, else 0. */ + + const char *expr_start; + const char *expr_end; + expr_ty simple_expression; + expr_ty format_spec = NULL; /* Optional format specifier. */ + int conversion = -1; /* The conversion char. Use default if not + specified, or !r if using = and no format + spec. */ + + /* 0 if we're not in a string, else the quote char we're trying to + match (single or double quote). */ + char quote_char = 0; + + /* If we're inside a string, 1=normal, 3=triple-quoted. */ + int string_type = 0; + + /* Keep track of nesting level for braces/parens/brackets in + expressions. */ + Py_ssize_t nested_depth = 0; + char parenstack[MAXLEVEL]; + + *expr_text = NULL; + + /* Can only nest one level deep. */ + if (recurse_lvl >= 2) { + RAISE_SYNTAX_ERROR("f-string: expressions nested too deeply"); + goto error; + } + + /* The first char must be a left brace, or we wouldn't have gotten + here. Skip over it. */ + assert(**str == '{'); + *str += 1; + + expr_start = *str; + for (; *str < end; (*str)++) { + char ch; + + /* Loop invariants. */ + assert(nested_depth >= 0); + assert(*str >= expr_start && *str < end); + if (quote_char) + assert(string_type == 1 || string_type == 3); + else + assert(string_type == 0); + + ch = **str; + /* Nowhere inside an expression is a backslash allowed. */ + if (ch == '\\') { + /* Error: can't include a backslash character, inside + parens or strings or not. */ + RAISE_SYNTAX_ERROR( + "f-string expression part " + "cannot include a backslash"); + goto error; + } + if (quote_char) { + /* We're inside a string. See if we're at the end. */ + /* This code needs to implement the same non-error logic + as tok_get from tokenizer.c, at the letter_quote + label. To actually share that code would be a + nightmare. But, it's unlikely to change and is small, + so duplicate it here. Note we don't need to catch all + of the errors, since they'll be caught when parsing the + expression. We just need to match the non-error + cases. Thus we can ignore \n in single-quoted strings, + for example. Or non-terminated strings. */ + if (ch == quote_char) { + /* Does this match the string_type (single or triple + quoted)? */ + if (string_type == 3) { + if (*str+2 < end && *(*str+1) == ch && *(*str+2) == ch) { + /* We're at the end of a triple quoted string. */ + *str += 2; + string_type = 0; + quote_char = 0; + continue; + } + } else { + /* We're at the end of a normal string. */ + quote_char = 0; + string_type = 0; + continue; + } + } + } else if (ch == '\'' || ch == '"') { + /* Is this a triple quoted string? */ + if (*str+2 < end && *(*str+1) == ch && *(*str+2) == ch) { + string_type = 3; + *str += 2; + } else { + /* Start of a normal string. */ + string_type = 1; + } + /* Start looking for the end of the string. */ + quote_char = ch; + } else if (ch == '[' || ch == '{' || ch == '(') { + if (nested_depth >= MAXLEVEL) { + RAISE_SYNTAX_ERROR("f-string: too many nested parenthesis"); + goto error; + } + parenstack[nested_depth] = ch; + nested_depth++; + } else if (ch == '#') { + /* Error: can't include a comment character, inside parens + or not. */ + RAISE_SYNTAX_ERROR("f-string expression part cannot include '#'"); + goto error; + } else if (nested_depth == 0 && + (ch == '!' || ch == ':' || ch == '}' || + ch == '=' || ch == '>' || ch == '<')) { + /* See if there's a next character. */ + if (*str+1 < end) { + char next = *(*str+1); + + /* For "!=". since '=' is not an allowed conversion character, + nothing is lost in this test. */ + if ((ch == '!' && next == '=') || /* != */ + (ch == '=' && next == '=') || /* == */ + (ch == '<' && next == '=') || /* <= */ + (ch == '>' && next == '=') /* >= */ + ) { + *str += 1; + continue; + } + /* Don't get out of the loop for these, if they're single + chars (not part of 2-char tokens). If by themselves, they + don't end an expression (unlike say '!'). */ + if (ch == '>' || ch == '<') { + continue; + } + } + + /* Normal way out of this loop. */ + break; + } else if (ch == ']' || ch == '}' || ch == ')') { + if (!nested_depth) { + RAISE_SYNTAX_ERROR("f-string: unmatched '%c'", ch); + goto error; + } + nested_depth--; + int opening = parenstack[nested_depth]; + if (!((opening == '(' && ch == ')') || + (opening == '[' && ch == ']') || + (opening == '{' && ch == '}'))) + { + RAISE_SYNTAX_ERROR( + "f-string: closing parenthesis '%c' " + "does not match opening parenthesis '%c'", + ch, opening); + goto error; + } + } else { + /* Just consume this char and loop around. */ + } + } + expr_end = *str; + /* If we leave this loop in a string or with mismatched parens, we + don't care. We'll get a syntax error when compiling the + expression. But, we can produce a better error message, so + let's just do that.*/ + if (quote_char) { + RAISE_SYNTAX_ERROR("f-string: unterminated string"); + goto error; + } + if (nested_depth) { + int opening = parenstack[nested_depth - 1]; + RAISE_SYNTAX_ERROR("f-string: unmatched '%c'", opening); + goto error; + } + + if (*str >= end) + goto unexpected_end_of_string; + + /* Compile the expression as soon as possible, so we show errors + related to the expression before errors related to the + conversion or format_spec. */ + simple_expression = fstring_compile_expr(p, expr_start, expr_end, t); + if (!simple_expression) + goto error; + + /* Check for =, which puts the text value of the expression in + expr_text. */ + if (**str == '=') { + *str += 1; + + /* Skip over ASCII whitespace. No need to test for end of string + here, since we know there's at least a trailing quote somewhere + ahead. */ + while (Py_ISSPACE(**str)) { + *str += 1; + } + + /* Set *expr_text to the text of the expression. */ + *expr_text = PyUnicode_FromStringAndSize(expr_start, *str-expr_start); + if (!*expr_text) { + goto error; + } + } + + /* Check for a conversion char, if present. */ + if (**str == '!') { + *str += 1; + if (*str >= end) + goto unexpected_end_of_string; + + conversion = **str; + *str += 1; + + /* Validate the conversion. */ + if (!(conversion == 's' || conversion == 'r' || conversion == 'a')) { + RAISE_SYNTAX_ERROR( + "f-string: invalid conversion character: " + "expected 's', 'r', or 'a'"); + goto error; + } + + } + + /* Check for the format spec, if present. */ + if (*str >= end) + goto unexpected_end_of_string; + if (**str == ':') { + *str += 1; + if (*str >= end) + goto unexpected_end_of_string; + + /* Parse the format spec. */ + format_spec = fstring_parse(p, str, end, raw, recurse_lvl+1, + first_token, t, last_token); + if (!format_spec) + goto error; + } + + if (*str >= end || **str != '}') + goto unexpected_end_of_string; + + /* We're at a right brace. Consume it. */ + assert(*str < end); + assert(**str == '}'); + *str += 1; + + /* If we're in = mode (detected by non-NULL expr_text), and have no format + spec and no explicit conversion, set the conversion to 'r'. */ + if (*expr_text && format_spec == NULL && conversion == -1) { + conversion = 'r'; + } + + /* And now create the FormattedValue node that represents this + entire expression with the conversion and format spec. */ + //TODO: Fix this + *expression = FormattedValue(simple_expression, conversion, + format_spec, first_token->lineno, + first_token->col_offset, last_token->end_lineno, + last_token->end_col_offset, p->arena); + if (!*expression) + goto error; + + return 0; + +unexpected_end_of_string: + RAISE_SYNTAX_ERROR("f-string: expecting '}'"); + /* Falls through to error. */ + +error: + Py_XDECREF(*expr_text); + return -1; + +} + +/* Return -1 on error. + + Return 0 if we have a literal (possible zero length) and an + expression (zero length if at the end of the string. + + Return 1 if we have a literal, but no expression, and we want the + caller to call us again. This is used to deal with doubled + braces. + + When called multiple times on the string 'a{{b{0}c', this function + will return: + + 1. the literal 'a{' with no expression, and a return value + of 1. Despite the fact that there's no expression, the return + value of 1 means we're not finished yet. + + 2. the literal 'b' and the expression '0', with a return value of + 0. The fact that there's an expression means we're not finished. + + 3. literal 'c' with no expression and a return value of 0. The + combination of the return value of 0 with no expression means + we're finished. +*/ +static int +fstring_find_literal_and_expr(Parser *p, const char **str, const char *end, int raw, + int recurse_lvl, PyObject **literal, + PyObject **expr_text, expr_ty *expression, + Token *first_token, Token *t, Token *last_token) +{ + int result; + + assert(*literal == NULL && *expression == NULL); + + /* Get any literal string. */ + result = fstring_find_literal(p, str, end, raw, literal, recurse_lvl, t); + if (result < 0) + goto error; + + assert(result == 0 || result == 1); + + if (result == 1) + /* We have a literal, but don't look at the expression. */ + return 1; + + if (*str >= end || **str == '}') + /* We're at the end of the string or the end of a nested + f-string: no expression. The top-level error case where we + expect to be at the end of the string but we're at a '}' is + handled later. */ + return 0; + + /* We must now be the start of an expression, on a '{'. */ + assert(**str == '{'); + + if (fstring_find_expr(p, str, end, raw, recurse_lvl, expr_text, + expression, first_token, t, last_token) < 0) + goto error; + + return 0; + +error: + Py_CLEAR(*literal); + return -1; +} + +#ifdef NDEBUG +#define ExprList_check_invariants(l) +#else +static void +ExprList_check_invariants(ExprList *l) +{ + /* Check our invariants. Make sure this object is "live", and + hasn't been deallocated. */ + assert(l->size >= 0); + assert(l->p != NULL); + if (l->size <= EXPRLIST_N_CACHED) + assert(l->data == l->p); +} +#endif + +static void +ExprList_Init(ExprList *l) +{ + l->allocated = EXPRLIST_N_CACHED; + l->size = 0; + + /* Until we start allocating dynamically, p points to data. */ + l->p = l->data; + + ExprList_check_invariants(l); +} + +static int +ExprList_Append(ExprList *l, expr_ty exp) +{ + ExprList_check_invariants(l); + if (l->size >= l->allocated) { + /* We need to alloc (or realloc) the memory. */ + Py_ssize_t new_size = l->allocated * 2; + + /* See if we've ever allocated anything dynamically. */ + if (l->p == l->data) { + Py_ssize_t i; + /* We're still using the cached data. Switch to + alloc-ing. */ + l->p = PyMem_RawMalloc(sizeof(expr_ty) * new_size); + if (!l->p) + return -1; + /* Copy the cached data into the new buffer. */ + for (i = 0; i < l->size; i++) + l->p[i] = l->data[i]; + } else { + /* Just realloc. */ + expr_ty *tmp = PyMem_RawRealloc(l->p, sizeof(expr_ty) * new_size); + if (!tmp) { + PyMem_RawFree(l->p); + l->p = NULL; + return -1; + } + l->p = tmp; + } + + l->allocated = new_size; + assert(l->allocated == 2 * l->size); + } + + l->p[l->size++] = exp; + + ExprList_check_invariants(l); + return 0; +} + +static void +ExprList_Dealloc(ExprList *l) +{ + ExprList_check_invariants(l); + + /* If there's been an error, or we've never dynamically allocated, + do nothing. */ + if (!l->p || l->p == l->data) { + /* Do nothing. */ + } else { + /* We have dynamically allocated. Free the memory. */ + PyMem_RawFree(l->p); + } + l->p = NULL; + l->size = -1; +} + +static asdl_seq * +ExprList_Finish(ExprList *l, PyArena *arena) +{ + asdl_seq *seq; + + ExprList_check_invariants(l); + + /* Allocate the asdl_seq and copy the expressions in to it. */ + seq = _Py_asdl_seq_new(l->size, arena); + if (seq) { + Py_ssize_t i; + for (i = 0; i < l->size; i++) + asdl_seq_SET(seq, i, l->p[i]); + } + ExprList_Dealloc(l); + return seq; +} + +#ifdef NDEBUG +#define FstringParser_check_invariants(state) +#else +static void +FstringParser_check_invariants(FstringParser *state) +{ + if (state->last_str) + assert(PyUnicode_CheckExact(state->last_str)); + ExprList_check_invariants(&state->expr_list); +} +#endif + +void +_PyPegen_FstringParser_Init(FstringParser *state) +{ + state->last_str = NULL; + state->fmode = 0; + ExprList_Init(&state->expr_list); + FstringParser_check_invariants(state); +} + +void +_PyPegen_FstringParser_Dealloc(FstringParser *state) +{ + FstringParser_check_invariants(state); + + Py_XDECREF(state->last_str); + ExprList_Dealloc(&state->expr_list); +} + +/* Make a Constant node, but decref the PyUnicode object being added. */ +static expr_ty +make_str_node_and_del(Parser *p, PyObject **str, Token* first_token, Token *last_token) +{ + PyObject *s = *str; + PyObject *kind = NULL; + *str = NULL; + assert(PyUnicode_CheckExact(s)); + if (PyArena_AddPyObject(p->arena, s) < 0) { + Py_DECREF(s); + return NULL; + } + const char* the_str = PyBytes_AsString(first_token->bytes); + if (the_str && the_str[0] == 'u') { + kind = _PyPegen_new_identifier(p, "u"); + } + + if (kind == NULL && PyErr_Occurred()) { + return NULL; + } + + return Constant(s, kind, first_token->lineno, first_token->col_offset, + last_token->end_lineno, last_token->end_col_offset, p->arena); + +} + + +/* Add a non-f-string (that is, a regular literal string). str is + decref'd. */ +int +_PyPegen_FstringParser_ConcatAndDel(FstringParser *state, PyObject *str) +{ + FstringParser_check_invariants(state); + + assert(PyUnicode_CheckExact(str)); + + if (PyUnicode_GET_LENGTH(str) == 0) { + Py_DECREF(str); + return 0; + } + + if (!state->last_str) { + /* We didn't have a string before, so just remember this one. */ + state->last_str = str; + } else { + /* Concatenate this with the previous string. */ + PyUnicode_AppendAndDel(&state->last_str, str); + if (!state->last_str) + return -1; + } + FstringParser_check_invariants(state); + return 0; +} + +/* Parse an f-string. The f-string is in *str to end, with no + 'f' or quotes. */ +int +_PyPegen_FstringParser_ConcatFstring(Parser *p, FstringParser *state, const char **str, + const char *end, int raw, int recurse_lvl, + Token *first_token, Token* t, Token *last_token) +{ + FstringParser_check_invariants(state); + state->fmode = 1; + + /* Parse the f-string. */ + while (1) { + PyObject *literal = NULL; + PyObject *expr_text = NULL; + expr_ty expression = NULL; + + /* If there's a zero length literal in front of the + expression, literal will be NULL. If we're at the end of + the f-string, expression will be NULL (unless result == 1, + see below). */ + int result = fstring_find_literal_and_expr(p, str, end, raw, recurse_lvl, + &literal, &expr_text, + &expression, first_token, t, last_token); + if (result < 0) + return -1; + + /* Add the literal, if any. */ + if (literal && _PyPegen_FstringParser_ConcatAndDel(state, literal) < 0) { + Py_XDECREF(expr_text); + return -1; + } + /* Add the expr_text, if any. */ + if (expr_text && _PyPegen_FstringParser_ConcatAndDel(state, expr_text) < 0) { + return -1; + } + + /* We've dealt with the literal and expr_text, their ownership has + been transferred to the state object. Don't look at them again. */ + + /* See if we should just loop around to get the next literal + and expression, while ignoring the expression this + time. This is used for un-doubling braces, as an + optimization. */ + if (result == 1) + continue; + + if (!expression) + /* We're done with this f-string. */ + break; + + /* We know we have an expression. Convert any existing string + to a Constant node. */ + if (!state->last_str) { + /* Do nothing. No previous literal. */ + } else { + /* Convert the existing last_str literal to a Constant node. */ + expr_ty str = make_str_node_and_del(p, &state->last_str, first_token, last_token); + if (!str || ExprList_Append(&state->expr_list, str) < 0) + return -1; + } + + if (ExprList_Append(&state->expr_list, expression) < 0) + return -1; + } + + /* If recurse_lvl is zero, then we must be at the end of the + string. Otherwise, we must be at a right brace. */ + + if (recurse_lvl == 0 && *str < end-1) { + RAISE_SYNTAX_ERROR("f-string: unexpected end of string"); + return -1; + } + if (recurse_lvl != 0 && **str != '}') { + RAISE_SYNTAX_ERROR("f-string: expecting '}'"); + return -1; + } + + FstringParser_check_invariants(state); + return 0; +} + +/* Convert the partial state reflected in last_str and expr_list to an + expr_ty. The expr_ty can be a Constant, or a JoinedStr. */ +expr_ty +_PyPegen_FstringParser_Finish(Parser *p, FstringParser *state, Token* first_token, + Token *last_token) +{ + asdl_seq *seq; + + FstringParser_check_invariants(state); + + /* If we're just a constant string with no expressions, return + that. */ + if (!state->fmode) { + assert(!state->expr_list.size); + if (!state->last_str) { + /* Create a zero length string. */ + state->last_str = PyUnicode_FromStringAndSize(NULL, 0); + if (!state->last_str) + goto error; + } + return make_str_node_and_del(p, &state->last_str, first_token, last_token); + } + + /* Create a Constant node out of last_str, if needed. It will be the + last node in our expression list. */ + if (state->last_str) { + expr_ty str = make_str_node_and_del(p, &state->last_str, first_token, last_token); + if (!str || ExprList_Append(&state->expr_list, str) < 0) + goto error; + } + /* This has already been freed. */ + assert(state->last_str == NULL); + + seq = ExprList_Finish(&state->expr_list, p->arena); + if (!seq) + goto error; + + return _Py_JoinedStr(seq, first_token->lineno, first_token->col_offset, + last_token->end_lineno, last_token->end_col_offset, p->arena); + +error: + _PyPegen_FstringParser_Dealloc(state); + return NULL; +} + +/* Given an f-string (with no 'f' or quotes) that's in *str and ends + at end, parse it into an expr_ty. Return NULL on error. Adjust + str to point past the parsed portion. */ +static expr_ty +fstring_parse(Parser *p, const char **str, const char *end, int raw, + int recurse_lvl, Token *first_token, Token* t, Token *last_token) +{ + FstringParser state; + + _PyPegen_FstringParser_Init(&state); + if (_PyPegen_FstringParser_ConcatFstring(p, &state, str, end, raw, recurse_lvl, + first_token, t, last_token) < 0) { + _PyPegen_FstringParser_Dealloc(&state); + return NULL; + } + + return _PyPegen_FstringParser_Finish(p, &state, t, t); +} diff --git a/ast3/Parser/pegen/parse_string.h b/ast3/Parser/pegen/parse_string.h new file mode 100644 index 00000000..cd85bd57 --- /dev/null +++ b/ast3/Parser/pegen/parse_string.h @@ -0,0 +1,46 @@ +#ifndef STRINGS_H +#define STRINGS_H + +#include +#include +#include "pegen.h" + +#define EXPRLIST_N_CACHED 64 + +typedef struct { + /* Incrementally build an array of expr_ty, so be used in an + asdl_seq. Cache some small but reasonably sized number of + expr_ty's, and then after that start dynamically allocating, + doubling the number allocated each time. Note that the f-string + f'{0}a{1}' contains 3 expr_ty's: 2 FormattedValue's, and one + Constant for the literal 'a'. So you add expr_ty's about twice as + fast as you add expressions in an f-string. */ + + Py_ssize_t allocated; /* Number we've allocated. */ + Py_ssize_t size; /* Number we've used. */ + expr_ty *p; /* Pointer to the memory we're actually + using. Will point to 'data' until we + start dynamically allocating. */ + expr_ty data[EXPRLIST_N_CACHED]; +} ExprList; + +/* The FstringParser is designed to add a mix of strings and + f-strings, and concat them together as needed. Ultimately, it + generates an expr_ty. */ +typedef struct { + PyObject *last_str; + ExprList expr_list; + int fmode; +} FstringParser; + +void _PyPegen_FstringParser_Init(FstringParser *); +int _PyPegen_parsestr(Parser *, int *, int *, PyObject **, + const char **, Py_ssize_t *, Token *); +int _PyPegen_FstringParser_ConcatFstring(Parser *, FstringParser *, const char **, + const char *, int, int, Token *, Token *, + Token *); +int _PyPegen_FstringParser_ConcatAndDel(FstringParser *, PyObject *); +expr_ty _PyPegen_FstringParser_Finish(Parser *, FstringParser *, Token *, Token *); +void _PyPegen_FstringParser_Dealloc(FstringParser *); + +#endif diff --git a/ast3/Parser/pegen/peg_api.c b/ast3/Parser/pegen/peg_api.c new file mode 100644 index 00000000..5e71ecdb --- /dev/null +++ b/ast3/Parser/pegen/peg_api.c @@ -0,0 +1,54 @@ +#include "pegen_interface.h" + +#include "../tokenizer.h" +#include "pegen.h" + +mod_ty +PyPegen_ASTFromString(const char *str, const char *filename, int mode, + PyCompilerFlags *flags, PyArena *arena) +{ + PyObject *filename_ob = PyUnicode_FromString(filename); + if (filename_ob == NULL) { + return NULL; + } + mod_ty result = PyPegen_ASTFromStringObject(str, filename_ob, mode, flags, arena); + Py_XDECREF(filename_ob); + return result; +} + +mod_ty +PyPegen_ASTFromStringObject(const char *str, PyObject* filename, int mode, + PyCompilerFlags *flags, PyArena *arena) +{ + if (PySys_Audit("compile", "yO", str, filename) < 0) { + return NULL; + } + + mod_ty result = _PyPegen_run_parser_from_string(str, mode, filename, flags, arena); + return result; +} + +mod_ty +PyPegen_ASTFromFilename(const char *filename, int mode, PyCompilerFlags *flags, PyArena *arena) +{ + PyObject *filename_ob = PyUnicode_FromString(filename); + if (filename_ob == NULL) { + return NULL; + } + + mod_ty result = _PyPegen_run_parser_from_file(filename, mode, filename_ob, flags, arena); + Py_XDECREF(filename_ob); + return result; +} + +mod_ty +PyPegen_ASTFromFileObject(FILE *fp, PyObject *filename_ob, int mode, + const char *enc, const char *ps1, const char* ps2, + PyCompilerFlags *flags, int *errcode, PyArena *arena) +{ + if (PySys_Audit("compile", "OO", Py_None, filename_ob) < 0) { + return NULL; + } + return _PyPegen_run_parser_from_file_pointer(fp, mode, filename_ob, enc, ps1, ps2, + flags, errcode, arena); +} diff --git a/ast3/Parser/pegen/pegen.c b/ast3/Parser/pegen/pegen.c new file mode 100644 index 00000000..06af53b3 --- /dev/null +++ b/ast3/Parser/pegen/pegen.c @@ -0,0 +1,2064 @@ +#include +#include +#include "../tokenizer.h" + +#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) +{ + if (p->normalize) { + return 1; + } + PyObject *m = PyImport_ImportModuleNoBlock("unicodedata"); + if (!m) + { + return 0; + } + p->normalize = PyObject_GetAttrString(m, "normalize"); + Py_DECREF(m); + if (!p->normalize) + { + return 0; + } + return 1; +} + +/* Checks if the NOTEQUAL token is valid given the current parser flags +0 indicates success and nonzero indicates failure (an exception may be set) */ +int +_PyPegen_check_barry_as_flufl(Parser *p) { + Token *t = p->tokens[p->fill - 1]; + assert(t->bytes != NULL); + assert(t->type == NOTEQUAL); + + char* tok_str = PyBytes_AS_STRING(t->bytes); + if (p->flags & PyPARSE_BARRY_AS_BDFL && strcmp(tok_str, "<>")){ + RAISE_SYNTAX_ERROR("with Barry as BDFL, use '<>' instead of '!='"); + return -1; + } else if (!(p->flags & PyPARSE_BARRY_AS_BDFL)) { + return strcmp(tok_str, "!="); + } + return 0; +} + +PyObject * +_PyPegen_new_identifier(Parser *p, char *n) +{ + PyObject *id = PyUnicode_DecodeUTF8(n, strlen(n), NULL); + if (!id) { + goto error; + } + /* PyUnicode_DecodeUTF8 should always return a ready string. */ + assert(PyUnicode_IS_READY(id)); + /* Check whether there are non-ASCII characters in the + identifier; if so, normalize to NFKC. */ + if (!PyUnicode_IS_ASCII(id)) + { + PyObject *id2; + if (!init_normalization(p)) + { + Py_DECREF(id); + goto error; + } + PyObject *form = PyUnicode_InternFromString("NFKC"); + if (form == NULL) + { + Py_DECREF(id); + goto error; + } + PyObject *args[2] = {form, id}; + id2 = _PyObject_FastCall(p->normalize, args, 2); + Py_DECREF(id); + Py_DECREF(form); + if (!id2) { + goto error; + } + if (!PyUnicode_Check(id2)) + { + PyErr_Format(PyExc_TypeError, + "unicodedata.normalize() must return a string, not " + "%.200s", + _PyType_Name(Py_TYPE(id2))); + Py_DECREF(id2); + goto error; + } + id = id2; + } + PyUnicode_InternInPlace(&id); + if (PyArena_AddPyObject(p->arena, id) < 0) + { + Py_DECREF(id); + goto error; + } + return id; + +error: + p->error_indicator = 1; + return NULL; +} + +static PyObject * +_create_dummy_identifier(Parser *p) +{ + return _PyPegen_new_identifier(p, ""); +} + +static inline Py_ssize_t +byte_offset_to_character_offset(PyObject *line, int col_offset) +{ + const char *str = PyUnicode_AsUTF8(line); + if (!str) { + return 0; + } + PyObject *text = PyUnicode_DecodeUTF8(str, col_offset, "replace"); + if (!text) { + return 0; + } + Py_ssize_t size = PyUnicode_GET_LENGTH(text); + str = PyUnicode_AsUTF8(text); + if (str != NULL && (int)strlen(str) == col_offset) { + size = strlen(str); + } + Py_DECREF(text); + return size; +} + +const char * +_PyPegen_get_expr_name(expr_ty e) +{ + switch (e->kind) { + case Attribute_kind: + return "attribute"; + case Subscript_kind: + return "subscript"; + case Starred_kind: + return "starred"; + case Name_kind: + return "name"; + case List_kind: + return "list"; + case Tuple_kind: + return "tuple"; + case Lambda_kind: + return "lambda"; + case Call_kind: + return "function call"; + case BoolOp_kind: + case BinOp_kind: + case UnaryOp_kind: + return "operator"; + case GeneratorExp_kind: + return "generator expression"; + case Yield_kind: + case YieldFrom_kind: + return "yield expression"; + case Await_kind: + return "await expression"; + case ListComp_kind: + return "list comprehension"; + case SetComp_kind: + return "set comprehension"; + case DictComp_kind: + return "dict comprehension"; + case Dict_kind: + return "dict display"; + case Set_kind: + return "set display"; + case JoinedStr_kind: + case FormattedValue_kind: + return "f-string expression"; + case Constant_kind: { + PyObject *value = e->v.Constant.value; + if (value == Py_None) { + return "None"; + } + if (value == Py_False) { + return "False"; + } + if (value == Py_True) { + return "True"; + } + if (value == Py_Ellipsis) { + return "Ellipsis"; + } + return "literal"; + } + case Compare_kind: + return "comparison"; + case IfExp_kind: + return "conditional expression"; + case NamedExpr_kind: + return "named expression"; + default: + PyErr_Format(PyExc_SystemError, + "unexpected expression in assignment %d (line %d)", + e->kind, e->lineno); + return NULL; + } +} + +static int +raise_decode_error(Parser *p) +{ + assert(PyErr_Occurred()); + const char *errtype = NULL; + if (PyErr_ExceptionMatches(PyExc_UnicodeError)) { + errtype = "unicode error"; + } + else if (PyErr_ExceptionMatches(PyExc_ValueError)) { + errtype = "value error"; + } + if (errtype) { + PyObject *type, *value, *tback, *errstr; + PyErr_Fetch(&type, &value, &tback); + errstr = PyObject_Str(value); + if (errstr) { + RAISE_SYNTAX_ERROR("(%s) %U", errtype, errstr); + Py_DECREF(errstr); + } + else { + PyErr_Clear(); + RAISE_SYNTAX_ERROR("(%s) unknown error", errtype); + } + Py_XDECREF(type); + Py_XDECREF(value); + Py_XDECREF(tback); + } + + return -1; +} + +static void +raise_tokenizer_init_error(PyObject *filename) +{ + if (!(PyErr_ExceptionMatches(PyExc_LookupError) + || PyErr_ExceptionMatches(PyExc_ValueError) + || PyErr_ExceptionMatches(PyExc_UnicodeDecodeError))) { + return; + } + PyObject *errstr = NULL; + PyObject *tuple = NULL; + PyObject *type, *value, *tback; + PyErr_Fetch(&type, &value, &tback); + errstr = PyObject_Str(value); + if (!errstr) { + goto error; + } + + PyObject *tmp = Py_BuildValue("(OiiO)", filename, 0, -1, Py_None); + if (!tmp) { + goto error; + } + + tuple = PyTuple_Pack(2, errstr, tmp); + Py_DECREF(tmp); + if (!value) { + goto error; + } + PyErr_SetObject(PyExc_SyntaxError, tuple); + +error: + Py_XDECREF(type); + Py_XDECREF(value); + Py_XDECREF(tback); + Py_XDECREF(errstr); + Py_XDECREF(tuple); +} + +static inline PyObject * +get_error_line(char *buffer, int is_file) +{ + const char *newline; + if (is_file) { + newline = strrchr(buffer, '\n'); + } else { + newline = strchr(buffer, '\n'); + } + + if (newline) { + return PyUnicode_DecodeUTF8(buffer, newline - buffer, "replace"); + } + else { + return PyUnicode_DecodeUTF8(buffer, strlen(buffer), "replace"); + } +} + +static int +tokenizer_error(Parser *p) +{ + if (PyErr_Occurred()) { + return -1; + } + + const char *msg = NULL; + PyObject* errtype = PyExc_SyntaxError; + switch (p->tok->done) { + case E_TOKEN: + msg = "invalid token"; + break; + case E_IDENTIFIER: + msg = "invalid character in identifier"; + break; + case E_EOFS: + RAISE_SYNTAX_ERROR("EOF while scanning triple-quoted string literal"); + return -1; + case E_EOLS: + RAISE_SYNTAX_ERROR("EOL while scanning string literal"); + return -1; + case E_EOF: + RAISE_SYNTAX_ERROR("unexpected EOF while parsing"); + return -1; + case E_DEDENT: + RAISE_INDENTATION_ERROR("unindent does not match any outer indentation level"); + return -1; + case E_INTR: + if (!PyErr_Occurred()) { + PyErr_SetNone(PyExc_KeyboardInterrupt); + } + return -1; + case E_NOMEM: + PyErr_NoMemory(); + return -1; + case E_TABSPACE: + errtype = PyExc_TabError; + msg = "inconsistent use of tabs and spaces in indentation"; + break; + case E_TOODEEP: + errtype = PyExc_IndentationError; + msg = "too many levels of indentation"; + break; + case E_LINECONT: + msg = "unexpected character after line continuation character"; + break; + default: + msg = "unknown parsing error"; + } + + PyErr_Format(errtype, msg); + // There is no reliable column information for this error + PyErr_SyntaxLocationObject(p->tok->filename, p->tok->lineno, 0); + + return -1; +} + +void * +_PyPegen_raise_error(Parser *p, PyObject *errtype, int with_col_number, const char *errmsg, ...) +{ + PyObject *value = NULL; + PyObject *errstr = NULL; + PyObject *loc = NULL; + PyObject *tmp = NULL; + Token *t = p->known_err_token != NULL ? p->known_err_token : p->tokens[p->fill - 1]; + Py_ssize_t col_number = !with_col_number; + va_list va; + p->error_indicator = 1; + + va_start(va, errmsg); + errstr = PyUnicode_FromFormatV(errmsg, va); + va_end(va); + if (!errstr) { + goto error; + } + + if (p->start_rule == Py_file_input) { + loc = PyErr_ProgramTextObject(p->tok->filename, t->lineno); + } + + if (!loc) { + loc = get_error_line(p->tok->buf, p->start_rule == Py_file_input); + } + + if (loc && with_col_number) { + int col_offset; + if (t->col_offset == -1) { + col_offset = Py_SAFE_DOWNCAST(p->tok->cur - p->tok->buf, + intptr_t, int); + } else { + col_offset = t->col_offset + 1; + } + col_number = byte_offset_to_character_offset(loc, col_offset); + } + else if (!loc) { + Py_INCREF(Py_None); + loc = Py_None; + } + + tmp = Py_BuildValue("(OiiN)", p->tok->filename, t->lineno, col_number, loc); + if (!tmp) { + goto error; + } + value = PyTuple_Pack(2, errstr, tmp); + Py_DECREF(tmp); + if (!value) { + goto error; + } + PyErr_SetObject(errtype, value); + + Py_DECREF(errstr); + Py_DECREF(value); + return NULL; + +error: + Py_XDECREF(errstr); + Py_XDECREF(loc); + return NULL; +} + +void *_PyPegen_arguments_parsing_error(Parser *p, expr_ty e) { + int kwarg_unpacking = 0; + for (Py_ssize_t i = 0, l = asdl_seq_LEN(e->v.Call.keywords); i < l; i++) { + keyword_ty keyword = asdl_seq_GET(e->v.Call.keywords, i); + if (!keyword->arg) { + kwarg_unpacking = 1; + } + } + + const char *msg = NULL; + if (kwarg_unpacking) { + msg = "positional argument follows keyword argument unpacking"; + } else { + msg = "positional argument follows keyword argument"; + } + + return RAISE_SYNTAX_ERROR(msg); +} + +#if 0 +static const char * +token_name(int type) +{ + if (0 <= type && type <= N_TOKENS) { + return _PyParser_TokenNames[type]; + } + return ""; +} +#endif + +// Here, mark is the start of the node, while p->mark is the end. +// If node==NULL, they should be the same. +int +_PyPegen_insert_memo(Parser *p, int mark, int type, void *node) +{ + // Insert in front + Memo *m = PyArena_Malloc(p->arena, sizeof(Memo)); + if (m == NULL) { + return -1; + } + m->type = type; + m->node = node; + m->mark = p->mark; + m->next = p->tokens[mark]->memo; + p->tokens[mark]->memo = m; + return 0; +} + +// Like _PyPegen_insert_memo(), but updates an existing node if found. +int +_PyPegen_update_memo(Parser *p, int mark, int type, void *node) +{ + for (Memo *m = p->tokens[mark]->memo; m != NULL; m = m->next) { + if (m->type == type) { + // Update existing node. + m->node = node; + m->mark = p->mark; + return 0; + } + } + // Insert new node. + return _PyPegen_insert_memo(p, mark, type, node); +} + +// Return dummy NAME. +void * +_PyPegen_dummy_name(Parser *p, ...) +{ + static void *cache = NULL; + + if (cache != NULL) { + return cache; + } + + PyObject *id = _create_dummy_identifier(p); + if (!id) { + return NULL; + } + cache = Name(id, Load, 1, 0, 1, 0, p->arena); + return cache; +} + +static int +_get_keyword_or_name_type(Parser *p, const char *name, int name_len) +{ + if (name_len >= p->n_keyword_lists || p->keywords[name_len] == NULL) { + return NAME; + } + for (KeywordToken *k = p->keywords[name_len]; k->type != -1; k++) { + if (strncmp(k->str, name, name_len) == 0) { + return k->type; + } + } + 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 == ENDMARKER && p->start_rule == Py_single_input && p->parsing_started) { + type = NEWLINE; /* Add an extra newline */ + p->parsing_started = 0; + + if (p->tok->indent && !(p->flags & PyPARSE_DONT_IMPLY_DEDENT)) { + p->tok->pendin = -p->tok->indent; + p->tok->indent = 0; + } + } + else { + p->parsing_started = 1; + } + + if (p->fill == p->size) { + int newsize = p->size * 2; + Token **new_tokens = PyMem_Realloc(p->tokens, newsize * sizeof(Token *)); + if (new_tokens == NULL) { + PyErr_NoMemory(); + return -1; + } + else { + p->tokens = new_tokens; + } + for (int i = p->size; i < newsize; i++) { + p->tokens[i] = PyMem_Malloc(sizeof(Token)); + if (p->tokens[i] == NULL) { + p->size = i; // Needed, in order to cleanup correctly after parser fails + PyErr_NoMemory(); + return -1; + } + memset(p->tokens[i], '\0', sizeof(Token)); + } + p->size = newsize; + } + + Token *t = p->tokens[p->fill]; + t->type = (type == NAME) ? _get_keyword_or_name_type(p, start, (int)(end - start)) : type; + t->bytes = PyBytes_FromStringAndSize(start, end - start); + if (t->bytes == NULL) { + return -1; + } + PyArena_AddPyObject(p->arena, t->bytes); + + int lineno = type == STRING ? p->tok->first_lineno : p->tok->lineno; + const char *line_start = type == STRING ? p->tok->multi_line_start : p->tok->line_start; + int end_lineno = p->tok->lineno; + int col_offset = -1, end_col_offset = -1; + if (start != NULL && start >= line_start) { + col_offset = (int)(start - line_start); + } + if (end != NULL && end >= p->tok->line_start) { + end_col_offset = (int)(end - p->tok->line_start); + } + + t->lineno = p->starting_lineno + lineno; + t->col_offset = p->tok->lineno == 1 ? p->starting_col_offset + col_offset : col_offset; + t->end_lineno = p->starting_lineno + end_lineno; + t->end_col_offset = p->tok->lineno == 1 ? p->starting_col_offset + end_col_offset : end_col_offset; + + p->fill += 1; + + if (type == ERRORTOKEN) { + if (p->tok->done == E_DECODE) { + return raise_decode_error(p); + } + else { + return tokenizer_error(p); + } + } + + return 0; +} + +// Instrumentation to count the effectiveness of memoization. +// The array counts the number of tokens skipped by memoization, +// indexed by type. + +#define NSTATISTICS 2000 +static long memo_statistics[NSTATISTICS]; + +void +_PyPegen_clear_memo_statistics() +{ + for (int i = 0; i < NSTATISTICS; i++) { + memo_statistics[i] = 0; + } +} + +PyObject * +_PyPegen_get_memo_statistics() +{ + PyObject *ret = PyList_New(NSTATISTICS); + if (ret == NULL) { + return NULL; + } + for (int i = 0; i < NSTATISTICS; i++) { + PyObject *value = PyLong_FromLong(memo_statistics[i]); + if (value == NULL) { + Py_DECREF(ret); + return NULL; + } + // PyList_SetItem borrows a reference to value. + if (PyList_SetItem(ret, i, value) < 0) { + Py_DECREF(ret); + return NULL; + } + } + return ret; +} + +int // bool +_PyPegen_is_memoized(Parser *p, int type, void *pres) +{ + if (p->mark == p->fill) { + if (_PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return -1; + } + } + + Token *t = p->tokens[p->mark]; + + for (Memo *m = t->memo; m != NULL; m = m->next) { + if (m->type == type) { + if (0 <= type && type < NSTATISTICS) { + long count = m->mark - p->mark; + // A memoized negative result counts for one. + if (count <= 0) { + count = 1; + } + memo_statistics[type] += count; + } + p->mark = m->mark; + *(void **)(pres) = m->node; + return 1; + } + } + return 0; +} + + +int +_PyPegen_lookahead_with_name(int positive, expr_ty (func)(Parser *), Parser *p) +{ + int mark = p->mark; + void *res = func(p); + p->mark = mark; + return (res != NULL) == positive; +} + +int +_PyPegen_lookahead_with_int(int positive, Token *(func)(Parser *, int), Parser *p, int arg) +{ + int mark = p->mark; + void *res = func(p, arg); + p->mark = mark; + return (res != NULL) == positive; +} + +int +_PyPegen_lookahead(int positive, void *(func)(Parser *), Parser *p) +{ + int mark = p->mark; + void *res = (void*)func(p); + p->mark = mark; + return (res != NULL) == positive; +} + +Token * +_PyPegen_expect_token(Parser *p, int type) +{ + if (p->mark == p->fill) { + if (_PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + } + Token *t = p->tokens[p->mark]; + if (t->type != type) { + return NULL; + } + p->mark += 1; + return t; +} + +Token * +_PyPegen_get_last_nonnwhitespace_token(Parser *p) +{ + assert(p->mark >= 0); + Token *token = NULL; + for (int m = p->mark - 1; m >= 0; m--) { + token = p->tokens[m]; + if (token->type != ENDMARKER && (token->type < NEWLINE || token->type > DEDENT)) { + break; + } + } + return token; +} + +expr_ty +_PyPegen_name_token(Parser *p) +{ + Token *t = _PyPegen_expect_token(p, NAME); + if (t == NULL) { + return NULL; + } + char* s = PyBytes_AsString(t->bytes); + if (!s) { + return NULL; + } + PyObject *id = _PyPegen_new_identifier(p, s); + if (id == NULL) { + return NULL; + } + return Name(id, Load, t->lineno, t->col_offset, t->end_lineno, t->end_col_offset, + p->arena); +} + +void * +_PyPegen_string_token(Parser *p) +{ + return _PyPegen_expect_token(p, STRING); +} + +static PyObject * +parsenumber_raw(const char *s) +{ + const char *end; + long x; + double dx; + Py_complex compl; + int imflag; + + assert(s != NULL); + errno = 0; + end = s + strlen(s) - 1; + imflag = *end == 'j' || *end == 'J'; + if (s[0] == '0') { + x = (long)PyOS_strtoul(s, (char **)&end, 0); + if (x < 0 && errno == 0) { + return PyLong_FromString(s, (char **)0, 0); + } + } + else + x = PyOS_strtol(s, (char **)&end, 0); + if (*end == '\0') { + if (errno != 0) + return PyLong_FromString(s, (char **)0, 0); + return PyLong_FromLong(x); + } + /* XXX Huge floats may silently fail */ + if (imflag) { + compl.real = 0.; + compl.imag = PyOS_string_to_double(s, (char **)&end, NULL); + if (compl.imag == -1.0 && PyErr_Occurred()) + return NULL; + return PyComplex_FromCComplex(compl); + } + else { + dx = PyOS_string_to_double(s, NULL, NULL); + if (dx == -1.0 && PyErr_Occurred()) + return NULL; + return PyFloat_FromDouble(dx); + } +} + +static PyObject * +parsenumber(const char *s) +{ + char *dup, *end; + PyObject *res = NULL; + + assert(s != NULL); + + if (strchr(s, '_') == NULL) { + return parsenumber_raw(s); + } + /* Create a duplicate without underscores. */ + dup = PyMem_Malloc(strlen(s) + 1); + if (dup == NULL) { + return PyErr_NoMemory(); + } + end = dup; + for (; *s; s++) { + if (*s != '_') { + *end++ = *s; + } + } + *end = '\0'; + res = parsenumber_raw(dup); + PyMem_Free(dup); + return res; +} + +expr_ty +_PyPegen_number_token(Parser *p) +{ + Token *t = _PyPegen_expect_token(p, NUMBER); + if (t == NULL) { + return NULL; + } + + char *num_raw = PyBytes_AsString(t->bytes); + if (num_raw == NULL) { + return NULL; + } + + if (p->feature_version < 6 && strchr(num_raw, '_') != NULL) { + p->error_indicator = 1; + return RAISE_SYNTAX_ERROR("Underscores in numeric literals are only supported " + "in Python 3.6 and greater"); + } + + PyObject *c = parsenumber(num_raw); + + if (c == NULL) { + return NULL; + } + + if (PyArena_AddPyObject(p->arena, c) < 0) { + Py_DECREF(c); + return NULL; + } + + return Constant(c, NULL, t->lineno, t->col_offset, t->end_lineno, t->end_col_offset, + p->arena); +} + +static int // bool +newline_in_string(Parser *p, const char *cur) +{ + for (char c = *cur; cur >= p->tok->buf; c = *--cur) { + if (c == '\'' || c == '"') { + return 1; + } + } + return 0; +} + +/* Check that the source for a single input statement really is a single + statement by looking at what is left in the buffer after parsing. + Trailing whitespace and comments are OK. */ +static int // bool +bad_single_statement(Parser *p) +{ + const char *cur = strchr(p->tok->buf, '\n'); + + /* Newlines are allowed if preceded by a line continuation character + or if they appear inside a string. */ + if (!cur || *(cur - 1) == '\\' || newline_in_string(p, cur)) { + return 0; + } + char c = *cur; + + for (;;) { + while (c == ' ' || c == '\t' || c == '\n' || c == '\014') { + c = *++cur; + } + + if (!c) { + return 0; + } + + if (c != '#') { + return 1; + } + + /* Suck up comment. */ + while (c && c != '\n') { + c = *++cur; + } + } +} + +void +_PyPegen_Parser_Free(Parser *p) +{ + Py_XDECREF(p->normalize); + for (int i = 0; i < p->size; i++) { + PyMem_Free(p->tokens[i]); + } + PyMem_Free(p->tokens); + growable_comment_array_deallocate(&p->type_ignore_comments); + PyMem_Free(p); +} + +static int +compute_parser_flags(PyCompilerFlags *flags) +{ + int parser_flags = 0; + if (!flags) { + return 0; + } + if (flags->cf_flags & PyCF_DONT_IMPLY_DEDENT) { + parser_flags |= PyPARSE_DONT_IMPLY_DEDENT; + } + if (flags->cf_flags & PyCF_IGNORE_COOKIE) { + parser_flags |= PyPARSE_IGNORE_COOKIE; + } + if (flags->cf_flags & CO_FUTURE_BARRY_AS_BDFL) { + parser_flags |= PyPARSE_BARRY_AS_BDFL; + } + if (flags->cf_flags & PyCF_TYPE_COMMENTS) { + parser_flags |= PyPARSE_TYPE_COMMENTS; + } + if (flags->cf_feature_version < 7) { + parser_flags |= PyPARSE_ASYNC_HACKS; + } + return parser_flags; +} + +Parser * +_PyPegen_Parser_New(struct tok_state *tok, int start_rule, int flags, + int feature_version, int *errcode, PyArena *arena) +{ + Parser *p = PyMem_Malloc(sizeof(Parser)); + if (p == NULL) { + return (Parser *) PyErr_NoMemory(); + } + assert(tok != NULL); + tok->type_comments = (flags & PyPARSE_TYPE_COMMENTS) > 0; + tok->async_hacks = (flags & PyPARSE_ASYNC_HACKS) > 0; + p->tok = tok; + p->keywords = NULL; + p->n_keyword_lists = -1; + p->tokens = PyMem_Malloc(sizeof(Token *)); + if (!p->tokens) { + PyMem_Free(p); + return (Parser *) PyErr_NoMemory(); + } + p->tokens[0] = PyMem_Calloc(1, sizeof(Token)); + if (!p->tokens) { + PyMem_Free(p->tokens); + PyMem_Free(p); + return (Parser *) PyErr_NoMemory(); + } + 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; + + p->errcode = errcode; + p->arena = arena; + p->start_rule = start_rule; + p->parsing_started = 0; + p->normalize = NULL; + p->error_indicator = 0; + + p->starting_lineno = 0; + p->starting_col_offset = 0; + p->flags = flags; + p->feature_version = feature_version; + p->known_err_token = NULL; + + return p; +} + +void * +_PyPegen_run_parser(Parser *p) +{ + void *res = _PyPegen_parse(p); + if (res == NULL) { + if (PyErr_Occurred()) { + return NULL; + } + if (p->fill == 0) { + RAISE_SYNTAX_ERROR("error at start before reading any input"); + } + else if (p->tok->done == E_EOF) { + RAISE_SYNTAX_ERROR("unexpected EOF while parsing"); + } + else { + if (p->tokens[p->fill-1]->type == INDENT) { + RAISE_INDENTATION_ERROR("unexpected indent"); + } + else if (p->tokens[p->fill-1]->type == DEDENT) { + RAISE_INDENTATION_ERROR("unexpected unindent"); + } + else { + RAISE_SYNTAX_ERROR("invalid syntax"); + } + } + return NULL; + } + + if (p->start_rule == Py_single_input && bad_single_statement(p)) { + p->tok->done = E_BADSINGLE; // This is not necessary for now, but might be in the future + return RAISE_SYNTAX_ERROR("multiple statements found while compiling a single statement"); + } + + return res; +} + +mod_ty +_PyPegen_run_parser_from_file_pointer(FILE *fp, int start_rule, PyObject *filename_ob, + const char *enc, const char *ps1, const char *ps2, + PyCompilerFlags *flags, int *errcode, PyArena *arena) +{ + struct tok_state *tok = PyTokenizer_FromFile(fp, enc, ps1, ps2); + if (tok == NULL) { + if (PyErr_Occurred()) { + raise_tokenizer_init_error(filename_ob); + return NULL; + } + return NULL; + } + // This transfers the ownership to the tokenizer + tok->filename = filename_ob; + Py_INCREF(filename_ob); + + // From here on we need to clean up even if there's an error + mod_ty result = NULL; + + int parser_flags = compute_parser_flags(flags); + Parser *p = _PyPegen_Parser_New(tok, start_rule, parser_flags, PY_MINOR_VERSION, + errcode, arena); + if (p == NULL) { + goto error; + } + + result = _PyPegen_run_parser(p); + _PyPegen_Parser_Free(p); + +error: + PyTokenizer_Free(tok); + return result; +} + +mod_ty +_PyPegen_run_parser_from_file(const char *filename, int start_rule, + PyObject *filename_ob, PyCompilerFlags *flags, PyArena *arena) +{ + FILE *fp = fopen(filename, "rb"); + if (fp == NULL) { + PyErr_SetFromErrnoWithFilename(PyExc_OSError, filename); + return NULL; + } + + mod_ty result = _PyPegen_run_parser_from_file_pointer(fp, start_rule, filename_ob, + NULL, NULL, NULL, flags, NULL, arena); + + fclose(fp); + return result; +} + +mod_ty +_PyPegen_run_parser_from_string(const char *str, int start_rule, PyObject *filename_ob, + PyCompilerFlags *flags, PyArena *arena) +{ + int exec_input = start_rule == Py_file_input; + + struct tok_state *tok; + if (flags == NULL || flags->cf_flags & PyCF_IGNORE_COOKIE) { + tok = PyTokenizer_FromUTF8(str, exec_input); + } else { + tok = PyTokenizer_FromString(str, exec_input); + } + if (tok == NULL) { + if (PyErr_Occurred()) { + raise_tokenizer_init_error(filename_ob); + } + return NULL; + } + // This transfers the ownership to the tokenizer + tok->filename = filename_ob; + Py_INCREF(filename_ob); + + // We need to clear up from here on + mod_ty result = NULL; + + int parser_flags = compute_parser_flags(flags); + int feature_version = flags ? flags->cf_feature_version : PY_MINOR_VERSION; + Parser *p = _PyPegen_Parser_New(tok, start_rule, parser_flags, feature_version, + NULL, arena); + if (p == NULL) { + goto error; + } + + result = _PyPegen_run_parser(p); + _PyPegen_Parser_Free(p); + +error: + PyTokenizer_Free(tok); + return result; +} + +void * +_PyPegen_interactive_exit(Parser *p) +{ + if (p->errcode) { + *(p->errcode) = E_EOF; + } + return NULL; +} + +/* Creates a single-element asdl_seq* that contains a */ +asdl_seq * +_PyPegen_singleton_seq(Parser *p, void *a) +{ + assert(a != NULL); + asdl_seq *seq = _Py_asdl_seq_new(1, p->arena); + if (!seq) { + return NULL; + } + asdl_seq_SET(seq, 0, a); + return seq; +} + +/* Creates a copy of seq and prepends a to it */ +asdl_seq * +_PyPegen_seq_insert_in_front(Parser *p, void *a, asdl_seq *seq) +{ + 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; + } + + asdl_seq_SET(new_seq, 0, a); + for (Py_ssize_t i = 1, l = asdl_seq_LEN(new_seq); i < l; i++) { + asdl_seq_SET(new_seq, i, asdl_seq_GET(seq, i - 1)); + } + 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) +{ + Py_ssize_t size = 0; + for (Py_ssize_t i = 0, l = asdl_seq_LEN(seqs); i < l; i++) { + asdl_seq *inner_seq = asdl_seq_GET(seqs, i); + size += asdl_seq_LEN(inner_seq); + } + return size; +} + +/* Flattens an asdl_seq* of asdl_seq*s */ +asdl_seq * +_PyPegen_seq_flatten(Parser *p, asdl_seq *seqs) +{ + Py_ssize_t flattened_seq_size = _get_flattened_seq_size(seqs); + assert(flattened_seq_size > 0); + + asdl_seq *flattened_seq = _Py_asdl_seq_new(flattened_seq_size, p->arena); + if (!flattened_seq) { + return NULL; + } + + int flattened_seq_idx = 0; + for (Py_ssize_t i = 0, l = asdl_seq_LEN(seqs); i < l; i++) { + asdl_seq *inner_seq = asdl_seq_GET(seqs, i); + for (Py_ssize_t j = 0, li = asdl_seq_LEN(inner_seq); j < li; j++) { + asdl_seq_SET(flattened_seq, flattened_seq_idx++, asdl_seq_GET(inner_seq, j)); + } + } + assert(flattened_seq_idx == flattened_seq_size); + + return flattened_seq; +} + +/* Creates a new name of the form . */ +expr_ty +_PyPegen_join_names_with_dot(Parser *p, expr_ty first_name, expr_ty second_name) +{ + assert(first_name != NULL && second_name != NULL); + PyObject *first_identifier = first_name->v.Name.id; + PyObject *second_identifier = second_name->v.Name.id; + + if (PyUnicode_READY(first_identifier) == -1) { + return NULL; + } + if (PyUnicode_READY(second_identifier) == -1) { + return NULL; + } + const char *first_str = PyUnicode_AsUTF8(first_identifier); + if (!first_str) { + return NULL; + } + const char *second_str = PyUnicode_AsUTF8(second_identifier); + if (!second_str) { + return NULL; + } + Py_ssize_t len = strlen(first_str) + strlen(second_str) + 1; // +1 for the dot + + PyObject *str = PyBytes_FromStringAndSize(NULL, len); + if (!str) { + return NULL; + } + + char *s = PyBytes_AS_STRING(str); + if (!s) { + return NULL; + } + + strcpy(s, first_str); + s += strlen(first_str); + *s++ = '.'; + strcpy(s, second_str); + s += strlen(second_str); + *s = '\0'; + + PyObject *uni = PyUnicode_DecodeUTF8(PyBytes_AS_STRING(str), PyBytes_GET_SIZE(str), NULL); + Py_DECREF(str); + if (!uni) { + return NULL; + } + PyUnicode_InternInPlace(&uni); + if (PyArena_AddPyObject(p->arena, uni) < 0) { + Py_DECREF(uni); + return NULL; + } + + return _Py_Name(uni, Load, EXTRA_EXPR(first_name, second_name)); +} + +/* Counts the total number of dots in seq's tokens */ +int +_PyPegen_seq_count_dots(asdl_seq *seq) +{ + int number_of_dots = 0; + for (Py_ssize_t i = 0, l = asdl_seq_LEN(seq); i < l; i++) { + Token *current_expr = asdl_seq_GET(seq, i); + switch (current_expr->type) { + case ELLIPSIS: + number_of_dots += 3; + break; + case DOT: + number_of_dots += 1; + break; + default: + Py_UNREACHABLE(); + } + } + + return number_of_dots; +} + +/* Creates an alias with '*' as the identifier name */ +alias_ty +_PyPegen_alias_for_star(Parser *p) +{ + PyObject *str = PyUnicode_InternFromString("*"); + if (!str) { + return NULL; + } + if (PyArena_AddPyObject(p->arena, str) < 0) { + Py_DECREF(str); + return NULL; + } + return alias(str, NULL, p->arena); +} + +/* Creates a new asdl_seq* with the identifiers of all the names in seq */ +asdl_seq * +_PyPegen_map_names_to_ids(Parser *p, asdl_seq *seq) +{ + Py_ssize_t len = asdl_seq_LEN(seq); + assert(len > 0); + + asdl_seq *new_seq = _Py_asdl_seq_new(len, p->arena); + if (!new_seq) { + return NULL; + } + for (Py_ssize_t i = 0; i < len; i++) { + expr_ty e = asdl_seq_GET(seq, i); + asdl_seq_SET(new_seq, i, e->v.Name.id); + } + return new_seq; +} + +/* Constructs a CmpopExprPair */ +CmpopExprPair * +_PyPegen_cmpop_expr_pair(Parser *p, cmpop_ty cmpop, expr_ty expr) +{ + assert(expr != NULL); + CmpopExprPair *a = PyArena_Malloc(p->arena, sizeof(CmpopExprPair)); + if (!a) { + return NULL; + } + a->cmpop = cmpop; + a->expr = expr; + return a; +} + +asdl_int_seq * +_PyPegen_get_cmpops(Parser *p, asdl_seq *seq) +{ + Py_ssize_t len = asdl_seq_LEN(seq); + assert(len > 0); + + asdl_int_seq *new_seq = _Py_asdl_int_seq_new(len, p->arena); + if (!new_seq) { + return NULL; + } + for (Py_ssize_t i = 0; i < len; i++) { + CmpopExprPair *pair = asdl_seq_GET(seq, i); + asdl_seq_SET(new_seq, i, pair->cmpop); + } + return new_seq; +} + +asdl_seq * +_PyPegen_get_exprs(Parser *p, asdl_seq *seq) +{ + Py_ssize_t len = asdl_seq_LEN(seq); + assert(len > 0); + + asdl_seq *new_seq = _Py_asdl_seq_new(len, p->arena); + if (!new_seq) { + return NULL; + } + for (Py_ssize_t i = 0; i < len; i++) { + CmpopExprPair *pair = asdl_seq_GET(seq, i); + asdl_seq_SET(new_seq, i, pair->expr); + } + return new_seq; +} + +/* Creates an asdl_seq* where all the elements have been changed to have ctx as context */ +static asdl_seq * +_set_seq_context(Parser *p, asdl_seq *seq, expr_context_ty ctx) +{ + Py_ssize_t len = asdl_seq_LEN(seq); + if (len == 0) { + return NULL; + } + + asdl_seq *new_seq = _Py_asdl_seq_new(len, p->arena); + if (!new_seq) { + return NULL; + } + for (Py_ssize_t i = 0; i < len; i++) { + expr_ty e = asdl_seq_GET(seq, i); + asdl_seq_SET(new_seq, i, _PyPegen_set_expr_context(p, e, ctx)); + } + return new_seq; +} + +static expr_ty +_set_name_context(Parser *p, expr_ty e, expr_context_ty ctx) +{ + return _Py_Name(e->v.Name.id, ctx, EXTRA_EXPR(e, e)); +} + +static expr_ty +_set_tuple_context(Parser *p, expr_ty e, expr_context_ty ctx) +{ + return _Py_Tuple(_set_seq_context(p, e->v.Tuple.elts, ctx), ctx, EXTRA_EXPR(e, e)); +} + +static expr_ty +_set_list_context(Parser *p, expr_ty e, expr_context_ty ctx) +{ + return _Py_List(_set_seq_context(p, e->v.List.elts, ctx), ctx, EXTRA_EXPR(e, e)); +} + +static expr_ty +_set_subscript_context(Parser *p, expr_ty e, expr_context_ty ctx) +{ + return _Py_Subscript(e->v.Subscript.value, e->v.Subscript.slice, ctx, EXTRA_EXPR(e, e)); +} + +static expr_ty +_set_attribute_context(Parser *p, expr_ty e, expr_context_ty ctx) +{ + return _Py_Attribute(e->v.Attribute.value, e->v.Attribute.attr, ctx, EXTRA_EXPR(e, e)); +} + +static expr_ty +_set_starred_context(Parser *p, expr_ty e, expr_context_ty ctx) +{ + return _Py_Starred(_PyPegen_set_expr_context(p, e->v.Starred.value, ctx), ctx, EXTRA_EXPR(e, e)); +} + +/* Creates an `expr_ty` equivalent to `expr` but with `ctx` as context */ +expr_ty +_PyPegen_set_expr_context(Parser *p, expr_ty expr, expr_context_ty ctx) +{ + assert(expr != NULL); + + expr_ty new = NULL; + switch (expr->kind) { + case Name_kind: + new = _set_name_context(p, expr, ctx); + break; + case Tuple_kind: + new = _set_tuple_context(p, expr, ctx); + break; + case List_kind: + new = _set_list_context(p, expr, ctx); + break; + case Subscript_kind: + new = _set_subscript_context(p, expr, ctx); + break; + case Attribute_kind: + new = _set_attribute_context(p, expr, ctx); + break; + case Starred_kind: + new = _set_starred_context(p, expr, ctx); + break; + default: + new = expr; + } + return new; +} + +/* Constructs a KeyValuePair that is used when parsing a dict's key value pairs */ +KeyValuePair * +_PyPegen_key_value_pair(Parser *p, expr_ty key, expr_ty value) +{ + KeyValuePair *a = PyArena_Malloc(p->arena, sizeof(KeyValuePair)); + if (!a) { + return NULL; + } + a->key = key; + a->value = value; + return a; +} + +/* Extracts all keys from an asdl_seq* of KeyValuePair*'s */ +asdl_seq * +_PyPegen_get_keys(Parser *p, asdl_seq *seq) +{ + Py_ssize_t len = asdl_seq_LEN(seq); + asdl_seq *new_seq = _Py_asdl_seq_new(len, p->arena); + if (!new_seq) { + return NULL; + } + for (Py_ssize_t i = 0; i < len; i++) { + KeyValuePair *pair = asdl_seq_GET(seq, i); + asdl_seq_SET(new_seq, i, pair->key); + } + return new_seq; +} + +/* Extracts all values from an asdl_seq* of KeyValuePair*'s */ +asdl_seq * +_PyPegen_get_values(Parser *p, asdl_seq *seq) +{ + Py_ssize_t len = asdl_seq_LEN(seq); + asdl_seq *new_seq = _Py_asdl_seq_new(len, p->arena); + if (!new_seq) { + return NULL; + } + for (Py_ssize_t i = 0; i < len; i++) { + KeyValuePair *pair = asdl_seq_GET(seq, i); + asdl_seq_SET(new_seq, i, pair->value); + } + return new_seq; +} + +/* Constructs a NameDefaultPair */ +NameDefaultPair * +_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 = _PyPegen_add_type_comment_to_arg(p, arg, tc); + a->value = value; + return a; +} + +/* Constructs a SlashWithDefault */ +SlashWithDefault * +_PyPegen_slash_with_default(Parser *p, asdl_seq *plain_names, asdl_seq *names_with_defaults) +{ + SlashWithDefault *a = PyArena_Malloc(p->arena, sizeof(SlashWithDefault)); + if (!a) { + return NULL; + } + a->plain_names = plain_names; + a->names_with_defaults = names_with_defaults; + return a; +} + +/* Constructs a StarEtc */ +StarEtc * +_PyPegen_star_etc(Parser *p, arg_ty vararg, asdl_seq *kwonlyargs, arg_ty kwarg) +{ + StarEtc *a = PyArena_Malloc(p->arena, sizeof(StarEtc)); + if (!a) { + return NULL; + } + a->vararg = vararg; + a->kwonlyargs = kwonlyargs; + a->kwarg = kwarg; + return a; +} + +asdl_seq * +_PyPegen_join_sequences(Parser *p, asdl_seq *a, asdl_seq *b) +{ + Py_ssize_t first_len = asdl_seq_LEN(a); + Py_ssize_t second_len = asdl_seq_LEN(b); + asdl_seq *new_seq = _Py_asdl_seq_new(first_len + second_len, p->arena); + if (!new_seq) { + return NULL; + } + + int k = 0; + for (Py_ssize_t i = 0; i < first_len; i++) { + asdl_seq_SET(new_seq, k++, asdl_seq_GET(a, i)); + } + for (Py_ssize_t i = 0; i < second_len; i++) { + asdl_seq_SET(new_seq, k++, asdl_seq_GET(b, i)); + } + + return new_seq; +} + +static asdl_seq * +_get_names(Parser *p, asdl_seq *names_with_defaults) +{ + Py_ssize_t len = asdl_seq_LEN(names_with_defaults); + asdl_seq *seq = _Py_asdl_seq_new(len, p->arena); + if (!seq) { + return NULL; + } + for (Py_ssize_t i = 0; i < len; i++) { + NameDefaultPair *pair = asdl_seq_GET(names_with_defaults, i); + asdl_seq_SET(seq, i, pair->arg); + } + return seq; +} + +static asdl_seq * +_get_defaults(Parser *p, asdl_seq *names_with_defaults) +{ + Py_ssize_t len = asdl_seq_LEN(names_with_defaults); + asdl_seq *seq = _Py_asdl_seq_new(len, p->arena); + if (!seq) { + return NULL; + } + for (Py_ssize_t i = 0; i < len; i++) { + NameDefaultPair *pair = asdl_seq_GET(names_with_defaults, i); + asdl_seq_SET(seq, i, pair->value); + } + return seq; +} + +/* Constructs an arguments_ty object out of all the parsed constructs in the parameters rule */ +arguments_ty +_PyPegen_make_arguments(Parser *p, asdl_seq *slash_without_default, + SlashWithDefault *slash_with_default, asdl_seq *plain_names, + asdl_seq *names_with_default, StarEtc *star_etc) +{ + asdl_seq *posonlyargs; + if (slash_without_default != NULL) { + posonlyargs = slash_without_default; + } + else if (slash_with_default != NULL) { + asdl_seq *slash_with_default_names = + _get_names(p, slash_with_default->names_with_defaults); + if (!slash_with_default_names) { + return NULL; + } + posonlyargs = _PyPegen_join_sequences(p, slash_with_default->plain_names, slash_with_default_names); + if (!posonlyargs) { + return NULL; + } + } + else { + posonlyargs = _Py_asdl_seq_new(0, p->arena); + if (!posonlyargs) { + return NULL; + } + } + + asdl_seq *posargs; + if (plain_names != NULL && names_with_default != NULL) { + asdl_seq *names_with_default_names = _get_names(p, names_with_default); + if (!names_with_default_names) { + return NULL; + } + posargs = _PyPegen_join_sequences(p, plain_names, names_with_default_names); + if (!posargs) { + return NULL; + } + } + else if (plain_names == NULL && names_with_default != NULL) { + posargs = _get_names(p, names_with_default); + if (!posargs) { + return NULL; + } + } + else if (plain_names != NULL && names_with_default == NULL) { + posargs = plain_names; + } + else { + posargs = _Py_asdl_seq_new(0, p->arena); + if (!posargs) { + return NULL; + } + } + + asdl_seq *posdefaults; + if (slash_with_default != NULL && names_with_default != NULL) { + asdl_seq *slash_with_default_values = + _get_defaults(p, slash_with_default->names_with_defaults); + if (!slash_with_default_values) { + return NULL; + } + asdl_seq *names_with_default_values = _get_defaults(p, names_with_default); + if (!names_with_default_values) { + return NULL; + } + posdefaults = _PyPegen_join_sequences(p, slash_with_default_values, names_with_default_values); + if (!posdefaults) { + return NULL; + } + } + else if (slash_with_default == NULL && names_with_default != NULL) { + posdefaults = _get_defaults(p, names_with_default); + if (!posdefaults) { + return NULL; + } + } + else if (slash_with_default != NULL && names_with_default == NULL) { + posdefaults = _get_defaults(p, slash_with_default->names_with_defaults); + if (!posdefaults) { + return NULL; + } + } + else { + posdefaults = _Py_asdl_seq_new(0, p->arena); + if (!posdefaults) { + return NULL; + } + } + + arg_ty vararg = NULL; + if (star_etc != NULL && star_etc->vararg != NULL) { + vararg = star_etc->vararg; + } + + asdl_seq *kwonlyargs; + if (star_etc != NULL && star_etc->kwonlyargs != NULL) { + kwonlyargs = _get_names(p, star_etc->kwonlyargs); + if (!kwonlyargs) { + return NULL; + } + } + else { + kwonlyargs = _Py_asdl_seq_new(0, p->arena); + if (!kwonlyargs) { + return NULL; + } + } + + asdl_seq *kwdefaults; + if (star_etc != NULL && star_etc->kwonlyargs != NULL) { + kwdefaults = _get_defaults(p, star_etc->kwonlyargs); + if (!kwdefaults) { + return NULL; + } + } + else { + kwdefaults = _Py_asdl_seq_new(0, p->arena); + if (!kwdefaults) { + return NULL; + } + } + + arg_ty kwarg = NULL; + if (star_etc != NULL && star_etc->kwarg != NULL) { + kwarg = star_etc->kwarg; + } + + return _Py_arguments(posonlyargs, posargs, vararg, kwonlyargs, kwdefaults, kwarg, + posdefaults, p->arena); +} + +/* Constructs an empty arguments_ty object, that gets used when a function accepts no + * arguments. */ +arguments_ty +_PyPegen_empty_arguments(Parser *p) +{ + asdl_seq *posonlyargs = _Py_asdl_seq_new(0, p->arena); + if (!posonlyargs) { + return NULL; + } + asdl_seq *posargs = _Py_asdl_seq_new(0, p->arena); + if (!posargs) { + return NULL; + } + asdl_seq *posdefaults = _Py_asdl_seq_new(0, p->arena); + if (!posdefaults) { + return NULL; + } + asdl_seq *kwonlyargs = _Py_asdl_seq_new(0, p->arena); + if (!kwonlyargs) { + return NULL; + } + asdl_seq *kwdefaults = _Py_asdl_seq_new(0, p->arena); + if (!kwdefaults) { + return NULL; + } + + return _Py_arguments(posonlyargs, posargs, NULL, kwonlyargs, kwdefaults, NULL, kwdefaults, + p->arena); +} + +/* Encapsulates the value of an operator_ty into an AugOperator struct */ +AugOperator * +_PyPegen_augoperator(Parser *p, operator_ty kind) +{ + AugOperator *a = PyArena_Malloc(p->arena, sizeof(AugOperator)); + if (!a) { + return NULL; + } + a->kind = kind; + return a; +} + +/* Construct a FunctionDef equivalent to function_def, but with decorators */ +stmt_ty +_PyPegen_function_def_decorators(Parser *p, asdl_seq *decorators, stmt_ty function_def) +{ + assert(function_def != NULL); + if (function_def->kind == AsyncFunctionDef_kind) { + return _Py_AsyncFunctionDef( + function_def->v.FunctionDef.name, function_def->v.FunctionDef.args, + function_def->v.FunctionDef.body, decorators, function_def->v.FunctionDef.returns, + function_def->v.FunctionDef.type_comment, function_def->lineno, + function_def->col_offset, function_def->end_lineno, function_def->end_col_offset, + p->arena); + } + + return _Py_FunctionDef(function_def->v.FunctionDef.name, function_def->v.FunctionDef.args, + function_def->v.FunctionDef.body, decorators, + function_def->v.FunctionDef.returns, + function_def->v.FunctionDef.type_comment, function_def->lineno, + function_def->col_offset, function_def->end_lineno, + function_def->end_col_offset, p->arena); +} + +/* Construct a ClassDef equivalent to class_def, but with decorators */ +stmt_ty +_PyPegen_class_def_decorators(Parser *p, asdl_seq *decorators, stmt_ty class_def) +{ + assert(class_def != NULL); + return _Py_ClassDef(class_def->v.ClassDef.name, class_def->v.ClassDef.bases, + class_def->v.ClassDef.keywords, class_def->v.ClassDef.body, decorators, + class_def->lineno, class_def->col_offset, class_def->end_lineno, + class_def->end_col_offset, p->arena); +} + +/* Construct a KeywordOrStarred */ +KeywordOrStarred * +_PyPegen_keyword_or_starred(Parser *p, void *element, int is_keyword) +{ + KeywordOrStarred *a = PyArena_Malloc(p->arena, sizeof(KeywordOrStarred)); + if (!a) { + return NULL; + } + a->element = element; + a->is_keyword = is_keyword; + return a; +} + +/* Get the number of starred expressions in an asdl_seq* of KeywordOrStarred*s */ +static int +_seq_number_of_starred_exprs(asdl_seq *seq) +{ + int n = 0; + for (Py_ssize_t i = 0, l = asdl_seq_LEN(seq); i < l; i++) { + KeywordOrStarred *k = asdl_seq_GET(seq, i); + if (!k->is_keyword) { + n++; + } + } + return n; +} + +/* Extract the starred expressions of an asdl_seq* of KeywordOrStarred*s */ +asdl_seq * +_PyPegen_seq_extract_starred_exprs(Parser *p, asdl_seq *kwargs) +{ + int new_len = _seq_number_of_starred_exprs(kwargs); + if (new_len == 0) { + return NULL; + } + asdl_seq *new_seq = _Py_asdl_seq_new(new_len, p->arena); + if (!new_seq) { + return NULL; + } + + int idx = 0; + for (Py_ssize_t i = 0, len = asdl_seq_LEN(kwargs); i < len; i++) { + KeywordOrStarred *k = asdl_seq_GET(kwargs, i); + if (!k->is_keyword) { + asdl_seq_SET(new_seq, idx++, k->element); + } + } + return new_seq; +} + +/* Return a new asdl_seq* with only the keywords in kwargs */ +asdl_seq * +_PyPegen_seq_delete_starred_exprs(Parser *p, asdl_seq *kwargs) +{ + Py_ssize_t len = asdl_seq_LEN(kwargs); + Py_ssize_t new_len = len - _seq_number_of_starred_exprs(kwargs); + if (new_len == 0) { + return NULL; + } + asdl_seq *new_seq = _Py_asdl_seq_new(new_len, p->arena); + if (!new_seq) { + return NULL; + } + + int idx = 0; + for (Py_ssize_t i = 0; i < len; i++) { + KeywordOrStarred *k = asdl_seq_GET(kwargs, i); + if (k->is_keyword) { + asdl_seq_SET(new_seq, idx++, k->element); + } + } + return new_seq; +} + +expr_ty +_PyPegen_concatenate_strings(Parser *p, asdl_seq *strings) +{ + Py_ssize_t len = asdl_seq_LEN(strings); + assert(len > 0); + + Token *first = asdl_seq_GET(strings, 0); + Token *last = asdl_seq_GET(strings, len - 1); + + int bytesmode = 0; + PyObject *bytes_str = NULL; + + FstringParser state; + _PyPegen_FstringParser_Init(&state); + + for (Py_ssize_t i = 0; i < len; i++) { + Token *t = asdl_seq_GET(strings, i); + + int this_bytesmode; + int this_rawmode; + PyObject *s; + const char *fstr; + Py_ssize_t fstrlen = -1; + + if (_PyPegen_parsestr(p, &this_bytesmode, &this_rawmode, &s, &fstr, &fstrlen, t) != 0) { + goto error; + } + + /* Check that we are not mixing bytes with unicode. */ + if (i != 0 && bytesmode != this_bytesmode) { + RAISE_SYNTAX_ERROR("cannot mix bytes and nonbytes literals"); + Py_XDECREF(s); + goto error; + } + bytesmode = this_bytesmode; + + if (fstr != NULL) { + assert(s == NULL && !bytesmode); + + int result = _PyPegen_FstringParser_ConcatFstring(p, &state, &fstr, fstr + fstrlen, + this_rawmode, 0, first, t, last); + if (result < 0) { + goto error; + } + } + else { + /* String or byte string. */ + assert(s != NULL && fstr == NULL); + assert(bytesmode ? PyBytes_CheckExact(s) : PyUnicode_CheckExact(s)); + + if (bytesmode) { + if (i == 0) { + bytes_str = s; + } + else { + PyBytes_ConcatAndDel(&bytes_str, s); + if (!bytes_str) { + goto error; + } + } + } + else { + /* This is a regular string. Concatenate it. */ + if (_PyPegen_FstringParser_ConcatAndDel(&state, s) < 0) { + goto error; + } + } + } + } + + if (bytesmode) { + if (PyArena_AddPyObject(p->arena, bytes_str) < 0) { + goto error; + } + return Constant(bytes_str, NULL, first->lineno, first->col_offset, last->end_lineno, + last->end_col_offset, p->arena); + } + + return _PyPegen_FstringParser_Finish(p, &state, first, last); + +error: + Py_XDECREF(bytes_str); + _PyPegen_FstringParser_Dealloc(&state); + if (PyErr_Occurred()) { + raise_decode_error(p); + } + 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/ast3/Parser/pegen/pegen.h b/ast3/Parser/pegen/pegen.h new file mode 100644 index 00000000..ffb18e47 --- /dev/null +++ b/ast3/Parser/pegen/pegen.h @@ -0,0 +1,248 @@ +#ifndef PEGEN_H +#define PEGEN_H + +#define PY_SSIZE_T_CLEAN +#include +#include +#include +#include + +#if 0 +#define PyPARSE_YIELD_IS_KEYWORD 0x0001 +#endif + +#define PyPARSE_DONT_IMPLY_DEDENT 0x0002 + +#if 0 +#define PyPARSE_WITH_IS_KEYWORD 0x0003 +#define PyPARSE_PRINT_IS_FUNCTION 0x0004 +#define PyPARSE_UNICODE_LITERALS 0x0008 +#endif + +#define PyPARSE_IGNORE_COOKIE 0x0010 +#define PyPARSE_BARRY_AS_BDFL 0x0020 +#define PyPARSE_TYPE_COMMENTS 0x0040 +#define PyPARSE_ASYNC_HACKS 0x0080 + +typedef struct _memo { + int type; + void *node; + int mark; + struct _memo *next; +} Memo; + +typedef struct { + int type; + PyObject *bytes; + int lineno, col_offset, end_lineno, end_col_offset; + Memo *memo; +} Token; + +typedef struct { + char *str; + int type; +} KeywordToken; + + +typedef struct { + struct { + int lineno; + char *comment; // The " " in "# type: ignore " + } *items; + size_t size; + size_t num_items; +} growable_comment_array; + +typedef struct { + struct tok_state *tok; + Token **tokens; + int mark; + int fill, size; + PyArena *arena; + KeywordToken **keywords; + int n_keyword_lists; + int start_rule; + int *errcode; + int parsing_started; + PyObject* normalize; + int starting_lineno; + int starting_col_offset; + int error_indicator; + int flags; + int feature_version; + growable_comment_array type_ignore_comments; + Token *known_err_token; +} Parser; + +typedef struct { + cmpop_ty cmpop; + expr_ty expr; +} CmpopExprPair; + +typedef struct { + expr_ty key; + expr_ty value; +} KeyValuePair; + +typedef struct { + arg_ty arg; + expr_ty value; +} NameDefaultPair; + +typedef struct { + asdl_seq *plain_names; + asdl_seq *names_with_defaults; // asdl_seq* of NameDefaultsPair's +} SlashWithDefault; + +typedef struct { + arg_ty vararg; + asdl_seq *kwonlyargs; // asdl_seq* of NameDefaultsPair's + arg_ty kwarg; +} StarEtc; + +typedef struct { + operator_ty kind; +} AugOperator; + +typedef struct { + void *element; + int is_keyword; +} KeywordOrStarred; + +void _PyPegen_clear_memo_statistics(void); +PyObject *_PyPegen_get_memo_statistics(void); + +int _PyPegen_insert_memo(Parser *p, int mark, int type, void *node); +int _PyPegen_update_memo(Parser *p, int mark, int type, void *node); +int _PyPegen_is_memoized(Parser *p, int type, void *pres); + +int _PyPegen_lookahead_with_name(int, expr_ty (func)(Parser *), Parser *); +int _PyPegen_lookahead_with_int(int, Token *(func)(Parser *, int), Parser *, int); +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); +expr_ty _PyPegen_name_token(Parser *p); +expr_ty _PyPegen_number_token(Parser *p); +void *_PyPegen_string_token(Parser *p); +const char *_PyPegen_get_expr_name(expr_ty); +void *_PyPegen_raise_error(Parser *p, PyObject *errtype, int with_col_number, const char *errmsg, ...); +void *_PyPegen_dummy_name(Parser *p, ...); + +#define UNUSED(expr) do { (void)(expr); } while (0) +#define EXTRA_EXPR(head, tail) head->lineno, head->col_offset, tail->end_lineno, tail->end_col_offset, p->arena +#define EXTRA start_lineno, start_col_offset, end_lineno, end_col_offset, p->arena +#define RAISE_SYNTAX_ERROR(msg, ...) _PyPegen_raise_error(p, PyExc_SyntaxError, 1, msg, ##__VA_ARGS__) +#define RAISE_INDENTATION_ERROR(msg, ...) _PyPegen_raise_error(p, PyExc_IndentationError, 1, msg, ##__VA_ARGS__) +#define RAISE_SYNTAX_ERROR_NO_COL_OFFSET(msg, ...) _PyPegen_raise_error(p, PyExc_SyntaxError, 0, msg, ##__VA_ARGS__) + +Py_LOCAL_INLINE(void *) +CHECK_CALL(Parser *p, void *result) +{ + if (result == NULL) { + assert(PyErr_Occurred()); + p->error_indicator = 1; + } + return result; +} + +/* This is needed for helper functions that are allowed to + return NULL without an error. Example: _PyPegen_seq_extract_starred_exprs */ +Py_LOCAL_INLINE(void *) +CHECK_CALL_NULL_ALLOWED(Parser *p, void *result) +{ + if (result == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + } + return 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; +} + +Py_LOCAL_INLINE(void *) +INVALID_VERSION_CHECK(Parser *p, int version, char *msg, void *node) +{ + if (node == NULL) { + p->error_indicator = 1; // Inline CHECK_CALL + return NULL; + } + if (p->feature_version < version) { + p->error_indicator = 1; + return RAISE_SYNTAX_ERROR("%s only supported in Python 3.%i and greater", + msg, version); + } + return node; +} + +#define CHECK_VERSION(version, msg, node) INVALID_VERSION_CHECK(p, version, msg, node) + +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, int *, PyArena *); +void _PyPegen_Parser_Free(Parser *); +mod_ty _PyPegen_run_parser_from_file_pointer(FILE *, int, PyObject *, const char *, + const char *, const char *, PyCompilerFlags *, int *, PyArena *); +void *_PyPegen_run_parser(Parser *); +mod_ty _PyPegen_run_parser_from_file(const char *, int, PyObject *, PyCompilerFlags *, PyArena *); +mod_ty _PyPegen_run_parser_from_string(const char *, int, PyObject *, PyCompilerFlags *, PyArena *); +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 *); +alias_ty _PyPegen_alias_for_star(Parser *); +asdl_seq *_PyPegen_map_names_to_ids(Parser *, asdl_seq *); +CmpopExprPair *_PyPegen_cmpop_expr_pair(Parser *, cmpop_ty, expr_ty); +asdl_int_seq *_PyPegen_get_cmpops(Parser *p, asdl_seq *); +asdl_seq *_PyPegen_get_exprs(Parser *, asdl_seq *); +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, 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 *, + asdl_seq *, asdl_seq *, StarEtc *); +arguments_ty _PyPegen_empty_arguments(Parser *); +AugOperator *_PyPegen_augoperator(Parser*, operator_ty type); +stmt_ty _PyPegen_function_def_decorators(Parser *, asdl_seq *, stmt_ty); +stmt_ty _PyPegen_class_def_decorators(Parser *, asdl_seq *, stmt_ty); +KeywordOrStarred *_PyPegen_keyword_or_starred(Parser *, void *, int); +asdl_seq *_PyPegen_seq_extract_starred_exprs(Parser *, asdl_seq *); +asdl_seq *_PyPegen_seq_delete_starred_exprs(Parser *, asdl_seq *); +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 *); + +#endif diff --git a/ast3/Parser/tokenizer.c b/ast3/Parser/tokenizer.c index 092f2690..0f2b6af5 100644 --- a/ast3/Parser/tokenizer.c +++ b/ast3/Parser/tokenizer.c @@ -1,35 +1,20 @@ /* Tokenizer implementation */ +#define PY_SSIZE_T_CLEAN #include "Python.h" -#include "../Include/pgenheaders.h" #include #include #include "tokenizer.h" -#include "../Include/errcode.h" +#include "errcode.h" -#ifndef PGEN #include "unicodeobject.h" #include "bytesobject.h" #include "fileobject.h" #include "codecs.h" #include "abstract.h" -#endif /* PGEN */ - -#ifndef Py_XSETREF -#define Py_XSETREF(op, op2) \ - do { \ - PyObject *_py_tmp = (PyObject *)(op); \ - (op) = (op2); \ - Py_XDECREF(_py_tmp); \ - } while (0) -#endif /* Py_XSETREF */ - -#ifndef _PyObject_CallNoArg -#define _PyObject_CallNoArg(func) PyObject_CallObject(func, NULL) -#endif /* Alternate tab spacing */ #define ALTTABSIZE 1 @@ -47,7 +32,7 @@ || c == '_'\ || (c >= 128)) -PyAPI_FUNC(char *) PyOS_Readline(FILE *, FILE *, const char *); +extern char *PyOS_Readline(FILE *, FILE *, const char *); /* Return malloc'ed string including trailing \n; empty malloc'ed string for EOF; NULL if interrupted */ @@ -61,80 +46,10 @@ static int tok_nextc(struct tok_state *tok); static void tok_backup(struct tok_state *tok, int c); -/* Token names */ - -const char *_Ta3Parser_TokenNames[] = { - "ENDMARKER", - "NAME", - "NUMBER", - "STRING", - "NEWLINE", - "INDENT", - "DEDENT", - "LPAR", - "RPAR", - "LSQB", - "RSQB", - "COLON", - "COMMA", - "SEMI", - "PLUS", - "MINUS", - "STAR", - "SLASH", - "VBAR", - "AMPER", - "LESS", - "GREATER", - "EQUAL", - "DOT", - "PERCENT", - "LBRACE", - "RBRACE", - "EQEQUAL", - "NOTEQUAL", - "LESSEQUAL", - "GREATEREQUAL", - "TILDE", - "CIRCUMFLEX", - "LEFTSHIFT", - "RIGHTSHIFT", - "DOUBLESTAR", - "PLUSEQUAL", - "MINEQUAL", - "STAREQUAL", - "SLASHEQUAL", - "PERCENTEQUAL", - "AMPEREQUAL", - "VBAREQUAL", - "CIRCUMFLEXEQUAL", - "LEFTSHIFTEQUAL", - "RIGHTSHIFTEQUAL", - "DOUBLESTAREQUAL", - "DOUBLESLASH", - "DOUBLESLASHEQUAL", - "AT", - "ATEQUAL", - "RARROW", - "ELLIPSIS", - /* This table must match the #defines in token.h! */ - "OP", - "AWAIT", - "ASYNC", - "TYPE_IGNORE", - "TYPE_COMMENT", - "", - "COMMENT", - "NL", - "ENCODING", - "" -}; - /* Spaces in this constant are treated as "zero or more spaces or tabs" when tokenizing. */ static const char* type_comment_prefix = "# type: "; - /* Create and initialize a new tok_state structure */ static struct tok_state * @@ -144,7 +59,9 @@ tok_new(void) sizeof(struct tok_state)); if (tok == NULL) return NULL; - tok->buf = tok->cur = tok->end = tok->inp = tok->start = NULL; + tok->buf = tok->cur = tok->inp = NULL; + tok->start = NULL; + tok->end = NULL; tok->done = E_OK; tok->fp = NULL; tok->input = NULL; @@ -164,16 +81,15 @@ tok_new(void) tok->enc = NULL; tok->encoding = NULL; tok->cont_line = 0; -#ifndef PGEN tok->filename = NULL; tok->decoding_readline = NULL; tok->decoding_buffer = NULL; -#endif + tok->type_comments = 0; + tok->async_hacks = 0; tok->async_def = 0; tok->async_def_indent = 0; tok->async_def_nl = 0; - tok->async_always = 0; return tok; } @@ -191,35 +107,15 @@ new_string(const char *s, Py_ssize_t len, struct tok_state *tok) return result; } -#ifdef PGEN - -static char * -decoding_fgets(char *s, int size, struct tok_state *tok) -{ - return fgets(s, size, tok->fp); -} - -static int -decoding_feof(struct tok_state *tok) -{ - return feof(tok->fp); -} - -static char * -decode_str(const char *str, int exec_input, struct tok_state *tok) -{ - return new_string(str, strlen(str), tok); -} - -#else /* PGEN */ - static char * error_ret(struct tok_state *tok) /* XXX */ { tok->decoding_erred = 1; - if (tok->fp != NULL && tok->buf != NULL) /* see Ta3Tokenizer_Free */ + if (tok->fp != NULL && tok->buf != NULL) /* see PyTokenizer_Free */ PyMem_FREE(tok->buf); - tok->buf = tok->cur = tok->end = tok->inp = tok->start = NULL; + tok->buf = tok->cur = tok->inp = NULL; + tok->start = NULL; + tok->end = NULL; tok->done = E_DECODE; return NULL; /* as if it were EOF */ } @@ -638,7 +534,6 @@ decoding_fgets(char *s, int size, struct tok_state *tok) return error_ret(tok); } } -#ifndef PGEN /* The default encoding is UTF-8, so make sure we don't have any non-UTF-8 sequences in it. */ if (line && !tok->encoding) { @@ -661,7 +556,6 @@ decoding_fgets(char *s, int size, struct tok_state *tok) badchar, tok->filename, tok->lineno + 1); return error_ret(tok); } -#endif return line; } @@ -759,9 +653,14 @@ translate_newlines(const char *s, int exec_input, struct tok_state *tok) { } *current = '\0'; final_length = current - buf + 1; - if (final_length < needed_length && final_length) + if (final_length < needed_length && final_length) { /* should never fail */ - buf = PyMem_REALLOC(buf, final_length); + char* result = PyMem_REALLOC(buf, final_length); + if (result == NULL) { + PyMem_FREE(buf); + } + buf = result; + } return buf; } @@ -769,11 +668,11 @@ translate_newlines(const char *s, int exec_input, struct tok_state *tok) { Look for encoding declarations inside STR, and record them inside TOK. */ -static const char * +static char * decode_str(const char *input, int single, struct tok_state *tok) { PyObject* utf8 = NULL; - const char *str; + char *str; const char *s; const char *newl[2] = {NULL, NULL}; int lineno = 0; @@ -825,67 +724,66 @@ decode_str(const char *input, int single, struct tok_state *tok) return str; } -#endif /* PGEN */ - /* Set up tokenizer for string */ struct tok_state * -Ta3Tokenizer_FromString(const char *str, int exec_input) +PyTokenizer_FromString(const char *str, int exec_input) { struct tok_state *tok = tok_new(); + char *decoded; + if (tok == NULL) return NULL; - str = decode_str(str, exec_input, tok); - if (str == NULL) { - Ta3Tokenizer_Free(tok); + decoded = decode_str(str, exec_input, tok); + if (decoded == NULL) { + PyTokenizer_Free(tok); return NULL; } - /* XXX: constify members. */ - tok->buf = tok->cur = tok->end = tok->inp = (char*)str; + tok->buf = tok->cur = tok->inp = decoded; + tok->end = decoded; return tok; } struct tok_state * -Ta3Tokenizer_FromUTF8(const char *str, int exec_input) +PyTokenizer_FromUTF8(const char *str, int exec_input) { struct tok_state *tok = tok_new(); + char *translated; if (tok == NULL) return NULL; -#ifndef PGEN - tok->input = str = translate_newlines(str, exec_input, tok); -#endif - if (str == NULL) { - Ta3Tokenizer_Free(tok); + tok->input = translated = translate_newlines(str, exec_input, tok); + if (translated == NULL) { + PyTokenizer_Free(tok); return NULL; } tok->decoding_state = STATE_RAW; tok->read_coding_spec = 1; tok->enc = NULL; - tok->str = str; + tok->str = translated; tok->encoding = (char *)PyMem_MALLOC(6); if (!tok->encoding) { - Ta3Tokenizer_Free(tok); + PyTokenizer_Free(tok); return NULL; } strcpy(tok->encoding, "utf-8"); - /* XXX: constify members. */ - tok->buf = tok->cur = tok->end = tok->inp = (char*)str; + tok->buf = tok->cur = tok->inp = translated; + tok->end = translated; return tok; } /* Set up tokenizer for file */ struct tok_state * -Ta3Tokenizer_FromFile(FILE *fp, const char* enc, +PyTokenizer_FromFile(FILE *fp, const char* enc, const char *ps1, const char *ps2) { struct tok_state *tok = tok_new(); if (tok == NULL) return NULL; if ((tok->buf = (char *)PyMem_MALLOC(BUFSIZ)) == NULL) { - Ta3Tokenizer_Free(tok); + PyTokenizer_Free(tok); return NULL; } tok->cur = tok->inp = tok->buf; @@ -898,7 +796,7 @@ Ta3Tokenizer_FromFile(FILE *fp, const char* enc, gets copied into the parse tree. */ tok->encoding = PyMem_MALLOC(strlen(enc)+1); if (!tok->encoding) { - Ta3Tokenizer_Free(tok); + PyTokenizer_Free(tok); return NULL; } strcpy(tok->encoding, enc); @@ -911,19 +809,17 @@ Ta3Tokenizer_FromFile(FILE *fp, const char* enc, /* Free a tok_state structure */ void -Ta3Tokenizer_Free(struct tok_state *tok) +PyTokenizer_Free(struct tok_state *tok) { if (tok->encoding != NULL) PyMem_FREE(tok->encoding); -#ifndef PGEN Py_XDECREF(tok->decoding_readline); Py_XDECREF(tok->decoding_buffer); Py_XDECREF(tok->filename); -#endif if (tok->fp != NULL && tok->buf != NULL) PyMem_FREE(tok->buf); if (tok->input) - PyMem_FREE((char *)tok->input); + PyMem_FREE(tok->input); PyMem_FREE(tok); } @@ -958,7 +854,6 @@ tok_nextc(struct tok_state *tok) } if (tok->prompt != NULL) { char *newtok = PyOS_Readline(stdin, stdout, tok->prompt); -#ifndef PGEN if (newtok != NULL) { char *translated = translate_newlines(newtok, 0, tok); PyMem_FREE(newtok); @@ -987,7 +882,6 @@ tok_nextc(struct tok_state *tok) strcpy(newtok, buf); Py_DECREF(u); } -#endif if (tok->nextprompt != NULL) tok->prompt = tok->nextprompt; if (newtok == NULL) @@ -1000,6 +894,7 @@ tok_nextc(struct tok_state *tok) size_t start = tok->start - tok->buf; size_t oldlen = tok->cur - tok->buf; size_t newlen = oldlen + strlen(newtok); + Py_ssize_t cur_multi_line_start = tok->multi_line_start - tok->buf; char *buf = tok->buf; buf = (char *)PyMem_REALLOC(buf, newlen+1); tok->lineno++; @@ -1012,6 +907,7 @@ tok_nextc(struct tok_state *tok) } tok->buf = buf; tok->cur = tok->buf + oldlen; + tok->multi_line_start = tok->buf + cur_multi_line_start; tok->line_start = tok->cur; strcpy(tok->buf + oldlen, newtok); PyMem_FREE(newtok); @@ -1070,6 +966,7 @@ tok_nextc(struct tok_state *tok) while (!done) { Py_ssize_t curstart = tok->start == NULL ? -1 : tok->start - tok->buf; + Py_ssize_t cur_multi_line_start = tok->multi_line_start - tok->buf; Py_ssize_t curvalid = tok->inp - tok->buf; Py_ssize_t newsize = curvalid + BUFSIZ; char *newbuf = tok->buf; @@ -1082,6 +979,7 @@ tok_nextc(struct tok_state *tok) } tok->buf = newbuf; tok->cur = tok->buf + cur; + tok->multi_line_start = tok->buf + cur_multi_line_start; tok->line_start = tok->cur; tok->inp = tok->buf + curvalid; tok->end = tok->buf + newsize; @@ -1097,7 +995,8 @@ tok_nextc(struct tok_state *tok) return EOF; /* Last line does not end in \n, fake one */ - strcpy(tok->inp, "\n"); + if (tok->inp[-1] != '\n') + strcpy(tok->inp, "\n"); } tok->inp = strchr(tok->inp, '\0'); done = tok->inp[-1] == '\n'; @@ -1132,183 +1031,59 @@ static void tok_backup(struct tok_state *tok, int c) { if (c != EOF) { - if (--tok->cur < tok->buf) - Py_FatalError("tok_backup: beginning of buffer"); - if (*tok->cur != c) + if (--tok->cur < tok->buf) { + Py_FatalError("tokenizer beginning of buffer"); + } + if (*tok->cur != c) { *tok->cur = c; + } } } -/* Return the token corresponding to a single character */ - -int -Ta3Token_OneChar(int c) +static int +syntaxerror(struct tok_state *tok, const char *format, ...) { - switch (c) { - case '(': return LPAR; - case ')': return RPAR; - case '[': return LSQB; - case ']': return RSQB; - case ':': return COLON; - case ',': return COMMA; - case ';': return SEMI; - case '+': return PLUS; - case '-': return MINUS; - case '*': return STAR; - case '/': return SLASH; - case '|': return VBAR; - case '&': return AMPER; - case '<': return LESS; - case '>': return GREATER; - case '=': return EQUAL; - case '.': return DOT; - case '%': return PERCENT; - case '{': return LBRACE; - case '}': return RBRACE; - case '^': return CIRCUMFLEX; - case '~': return TILDE; - case '@': return AT; - default: return OP; + PyObject *errmsg, *errtext, *args; + va_list vargs; +#ifdef HAVE_STDARG_PROTOTYPES + va_start(vargs, format); +#else + va_start(vargs); +#endif + errmsg = PyUnicode_FromFormatV(format, vargs); + va_end(vargs); + if (!errmsg) { + goto error; } -} - -int -Ta3Token_TwoChars(int c1, int c2) -{ - switch (c1) { - case '=': - switch (c2) { - case '=': return EQEQUAL; - } - break; - case '!': - switch (c2) { - case '=': return NOTEQUAL; - } - break; - case '<': - switch (c2) { - case '>': return NOTEQUAL; - case '=': return LESSEQUAL; - case '<': return LEFTSHIFT; - } - break; - case '>': - switch (c2) { - case '=': return GREATEREQUAL; - case '>': return RIGHTSHIFT; - } - break; - case '+': - switch (c2) { - case '=': return PLUSEQUAL; - } - break; - case '-': - switch (c2) { - case '=': return MINEQUAL; - case '>': return RARROW; - } - break; - case '*': - switch (c2) { - case '*': return DOUBLESTAR; - case '=': return STAREQUAL; - } - break; - case '/': - switch (c2) { - case '/': return DOUBLESLASH; - case '=': return SLASHEQUAL; - } - break; - case '|': - switch (c2) { - case '=': return VBAREQUAL; - } - break; - case '%': - switch (c2) { - case '=': return PERCENTEQUAL; - } - break; - case '&': - switch (c2) { - case '=': return AMPEREQUAL; - } - break; - case '^': - switch (c2) { - case '=': return CIRCUMFLEXEQUAL; - } - break; - case '@': - switch (c2) { - case '=': return ATEQUAL; - } - break; + errtext = PyUnicode_DecodeUTF8(tok->line_start, tok->cur - tok->line_start, + "replace"); + if (!errtext) { + goto error; + } + int offset = (int)PyUnicode_GET_LENGTH(errtext); + Py_ssize_t line_len = strcspn(tok->line_start, "\n"); + if (line_len != tok->cur - tok->line_start) { + Py_DECREF(errtext); + errtext = PyUnicode_DecodeUTF8(tok->line_start, line_len, + "replace"); + } + if (!errtext) { + goto error; } - return OP; -} -int -Ta3Token_ThreeChars(int c1, int c2, int c3) -{ - switch (c1) { - case '<': - switch (c2) { - case '<': - switch (c3) { - case '=': - return LEFTSHIFTEQUAL; - } - break; - } - break; - case '>': - switch (c2) { - case '>': - switch (c3) { - case '=': - return RIGHTSHIFTEQUAL; - } - break; - } - break; - case '*': - switch (c2) { - case '*': - switch (c3) { - case '=': - return DOUBLESTAREQUAL; - } - break; - } - break; - case '/': - switch (c2) { - case '/': - switch (c3) { - case '=': - return DOUBLESLASHEQUAL; - } - break; - } - break; - case '.': - switch (c2) { - case '.': - switch (c3) { - case '.': - return ELLIPSIS; - } - break; - } - break; + args = Py_BuildValue("(O(OiiN))", errmsg, + tok->filename, tok->lineno, offset, errtext); + if (args) { + PyErr_SetObject(PyExc_SyntaxError, args); + Py_DECREF(args); } - return OP; + +error: + Py_XDECREF(errmsg); + tok->done = E_ERROR; + return ERRORTOKEN; } static int @@ -1319,9 +1094,6 @@ indenterror(struct tok_state *tok) return ERRORTOKEN; } -#ifdef PGEN -#define verify_identifier(tok) 1 -#else /* Verify that the identifier follows PEP 3131. All identifier strings are guaranteed to be "ready" unicode objects. */ @@ -1333,7 +1105,7 @@ verify_identifier(struct tok_state *tok) if (tok->decoding_erred) return 0; s = PyUnicode_DecodeUTF8(tok->start, tok->cur - tok->start, NULL); - if (s == NULL || PyUnicode_READY(s) == -1) { + if (s == NULL) { if (PyErr_ExceptionMatches(PyExc_UnicodeDecodeError)) { PyErr_Clear(); tok->done = E_IDENTIFIER; @@ -1344,11 +1116,11 @@ verify_identifier(struct tok_state *tok) } result = PyUnicode_IsIdentifier(s); Py_DECREF(s); - if (result == 0) + if (result == 0) { tok->done = E_IDENTIFIER; + } return result; } -#endif static int tok_decimal_tail(struct tok_state *tok) @@ -1364,8 +1136,8 @@ tok_decimal_tail(struct tok_state *tok) } c = tok_nextc(tok); if (!isdigit(c)) { - tok->done = E_TOKEN; tok_backup(tok, c); + syntaxerror(tok, "invalid decimal literal"); return 0; } } @@ -1375,7 +1147,7 @@ tok_decimal_tail(struct tok_state *tok) /* Get next token, after space stripping etc. */ static int -tok_get(struct tok_state *tok, char **p_start, char **p_end) +tok_get(struct tok_state *tok, const char **p_start, const char **p_end) { int c; int blankline, nonascii; @@ -1416,6 +1188,12 @@ tok_get(struct tok_state *tok, char **p_start, char **p_end) if (col == 0 && c == '\n' && tok->prompt != NULL) { blankline = 0; /* Let it through */ } + else if (tok->prompt != NULL && tok->lineno == 1) { + /* In interactive mode, if the first line contains + only spaces and/or a comment, let it through. */ + blankline = 0; + col = altcol = 0; + } else { blankline = 1; /* Ignore completely */ } @@ -1515,53 +1293,57 @@ tok_get(struct tok_state *tok, char **p_start, char **p_end) if (c == '#') { const char *prefix, *p, *type_start; - while (c != EOF && c != '\n') + while (c != EOF && c != '\n') { c = tok_nextc(tok); - - p = tok->start; - prefix = type_comment_prefix; - while (*prefix && p < tok->cur) { - if (*prefix == ' ') { - while (*p == ' ' || *p == '\t') - p++; - } else if (*prefix == *p) { - p++; - } else { - break; - } - - prefix++; } - /* This is a type comment if we matched all of type_comment_prefix. */ - if (!*prefix) { - int is_type_ignore = 1; - const char *ignore_end = p + 6; - tok_backup(tok, c); /* don't eat the newline or EOF */ - - type_start = p; - - /* A TYPE_IGNORE is "type: ignore" followed by the end of the token - * or anything ASCII and non-alphanumeric. */ - is_type_ignore = ( - tok->cur >= ignore_end && memcmp(p, "ignore", 6) == 0 - && !(tok->cur > ignore_end - && ((unsigned char)ignore_end[0] >= 128 || Py_ISALNUM(ignore_end[0])))); + if (tok->type_comments) { + p = tok->start; + prefix = type_comment_prefix; + while (*prefix && p < tok->cur) { + if (*prefix == ' ') { + while (*p == ' ' || *p == '\t') { + p++; + } + } else if (*prefix == *p) { + p++; + } else { + break; + } - if (is_type_ignore) { - *p_start = (char *) ignore_end; - *p_end = tok->cur; + prefix++; + } - /* If this type ignore is the only thing on the line, consume the newline also. */ - if (blankline) { - tok_nextc(tok); - tok->atbol = 1; + /* This is a type comment if we matched all of type_comment_prefix. */ + if (!*prefix) { + int is_type_ignore = 1; + const char *ignore_end = p + 6; + tok_backup(tok, c); /* don't eat the newline or EOF */ + + type_start = p; + + /* A TYPE_IGNORE is "type: ignore" followed by the end of the token + * or anything ASCII and non-alphanumeric. */ + is_type_ignore = ( + tok->cur >= ignore_end && memcmp(p, "ignore", 6) == 0 + && !(tok->cur > ignore_end + && ((unsigned char)ignore_end[0] >= 128 || Py_ISALNUM(ignore_end[0])))); + + if (is_type_ignore) { + *p_start = ignore_end; + *p_end = tok->cur; + + /* If this type ignore is the only thing on the line, consume the newline also. */ + if (blankline) { + tok_nextc(tok); + tok->atbol = 1; + } + return TYPE_IGNORE; + } else { + *p_start = type_start; /* after type_comment_prefix */ + *p_end = tok->cur; + return TYPE_COMMENT; } - return TYPE_IGNORE; - } else { - *p_start = (char *) type_start; /* after type_comment_prefix */ - *p_end = tok->cur; - return TYPE_COMMENT; } } } @@ -1610,14 +1392,22 @@ tok_get(struct tok_state *tok, char **p_start, char **p_end) if (nonascii && !verify_identifier(tok)) { return ERRORTOKEN; } + *p_start = tok->start; *p_end = tok->cur; /* async/await parsing block. */ - if (tok->cur - tok->start == 5) { - /* Current token length is 5. */ - if (tok->async_always || tok->async_def) { - /* We're inside an 'async def' function. */ + if (tok->cur - tok->start == 5 && tok->start[0] == 'a') { + /* May be an 'async' or 'await' token. For Python 3.7 or + later we recognize them unconditionally. For Python + 3.5 or 3.6 we recognize 'async' in front of 'def', and + either one inside of 'async def'. (Technically we + shouldn't recognize these at all for 3.4 or earlier, + but there's no *valid* Python 3.4 code that would be + rejected, and async functions will be rejected in a + later phase.) */ + if (!tok->async_hacks || tok->async_def) { + /* Always recognize the keywords. */ if (memcmp(tok->start, "async", 5) == 0) { return ASYNC; } @@ -1627,10 +1417,11 @@ tok_get(struct tok_state *tok, char **p_start, char **p_end) } else if (memcmp(tok->start, "async", 5) == 0) { /* The current token is 'async'. - Look ahead one token.*/ + Look ahead one token to see if that is 'def'. */ struct tok_state ahead_tok; - char *ahead_tok_start = NULL, *ahead_tok_end = NULL; + const char *ahead_tok_start = NULL; + const char *ahead_tok_end = NULL; int ahead_tok_kind; memcpy(&ahead_tok, tok, sizeof(ahead_tok)); @@ -1642,7 +1433,7 @@ tok_get(struct tok_state *tok, char **p_start, char **p_end) && memcmp(ahead_tok.start, "def", 3) == 0) { /* The next token is going to be 'def', so instead of - returning 'async' NAME token, we return ASYNC. */ + returning a plain NAME token, return ASYNC. */ tok->async_def_indent = tok->indent; tok->async_def = 1; return ASYNC; @@ -1708,9 +1499,8 @@ tok_get(struct tok_state *tok, char **p_start, char **p_end) c = tok_nextc(tok); } if (!isxdigit(c)) { - tok->done = E_TOKEN; tok_backup(tok, c); - return ERRORTOKEN; + return syntaxerror(tok, "invalid hexadecimal literal"); } do { c = tok_nextc(tok); @@ -1725,14 +1515,23 @@ tok_get(struct tok_state *tok, char **p_start, char **p_end) c = tok_nextc(tok); } if (c < '0' || c >= '8') { - tok->done = E_TOKEN; tok_backup(tok, c); - return ERRORTOKEN; + if (isdigit(c)) { + return syntaxerror(tok, + "invalid digit '%c' in octal literal", c); + } + else { + return syntaxerror(tok, "invalid octal literal"); + } } do { c = tok_nextc(tok); } while ('0' <= c && c < '8'); } while (c == '_'); + if (isdigit(c)) { + return syntaxerror(tok, + "invalid digit '%c' in octal literal", c); + } } else if (c == 'b' || c == 'B') { /* Binary */ @@ -1742,14 +1541,23 @@ tok_get(struct tok_state *tok, char **p_start, char **p_end) c = tok_nextc(tok); } if (c != '0' && c != '1') { - tok->done = E_TOKEN; tok_backup(tok, c); - return ERRORTOKEN; + if (isdigit(c)) { + return syntaxerror(tok, + "invalid digit '%c' in binary literal", c); + } + else { + return syntaxerror(tok, "invalid binary literal"); + } } do { c = tok_nextc(tok); } while (c == '0' || c == '1'); } while (c == '_'); + if (isdigit(c)) { + return syntaxerror(tok, + "invalid digit '%c' in binary literal", c); + } } else { int nonzero = 0; @@ -1759,9 +1567,8 @@ tok_get(struct tok_state *tok, char **p_start, char **p_end) if (c == '_') { c = tok_nextc(tok); if (!isdigit(c)) { - tok->done = E_TOKEN; tok_backup(tok, c); - return ERRORTOKEN; + return syntaxerror(tok, "invalid decimal literal"); } } if (c != '0') { @@ -1788,9 +1595,11 @@ tok_get(struct tok_state *tok, char **p_start, char **p_end) } else if (nonzero) { /* Old-style octal: now disallowed. */ - tok->done = E_TOKEN; tok_backup(tok, c); - return ERRORTOKEN; + return syntaxerror(tok, + "leading zeros in decimal integer " + "literals are not permitted; " + "use an 0o prefix for octal integers"); } } } @@ -1822,9 +1631,8 @@ tok_get(struct tok_state *tok, char **p_start, char **p_end) if (c == '+' || c == '-') { c = tok_nextc(tok); if (!isdigit(c)) { - tok->done = E_TOKEN; tok_backup(tok, c); - return ERRORTOKEN; + return syntaxerror(tok, "invalid decimal literal"); } } else if (!isdigit(c)) { tok_backup(tok, c); @@ -1858,6 +1666,13 @@ tok_get(struct tok_state *tok, char **p_start, char **p_end) int quote_size = 1; /* 1 or 3 */ int end_quote_size = 0; + /* Nodes of type STRING, especially multi line strings + must be handled differently in order to get both + the starting line number and the column offset right. + (cf. issue 16806) */ + tok->first_lineno = tok->lineno; + tok->multi_line_start = tok->line_start; + /* Find the quote size and start of string */ c = tok_nextc(tok); if (c == quote) { @@ -1915,6 +1730,14 @@ tok_get(struct tok_state *tok, char **p_start, char **p_end) tok->cur = tok->inp; return ERRORTOKEN; } + c = tok_nextc(tok); + if (c == EOF) { + tok->done = E_EOF; + tok->cur = tok->inp; + return ERRORTOKEN; + } else { + tok_backup(tok, c); + } tok->cont_line = 1; goto again; /* Read next line */ } @@ -1922,10 +1745,10 @@ tok_get(struct tok_state *tok, char **p_start, char **p_end) /* Check for two-character token */ { int c2 = tok_nextc(tok); - int token = Ta3Token_TwoChars(c, c2); + int token = PyToken_TwoChars(c, c2); if (token != OP) { int c3 = tok_nextc(tok); - int token3 = Ta3Token_ThreeChars(c, c2, c3); + int token3 = PyToken_ThreeChars(c, c2, c3); if (token3 != OP) { token = token3; } @@ -1944,23 +1767,49 @@ tok_get(struct tok_state *tok, char **p_start, char **p_end) case '(': case '[': case '{': + if (tok->level >= MAXLEVEL) { + return syntaxerror(tok, "too many nested parentheses"); + } + tok->parenstack[tok->level] = c; + tok->parenlinenostack[tok->level] = tok->lineno; tok->level++; break; case ')': case ']': case '}': + if (!tok->level) { + return syntaxerror(tok, "unmatched '%c'", c); + } tok->level--; + int opening = tok->parenstack[tok->level]; + if (!((opening == '(' && c == ')') || + (opening == '[' && c == ']') || + (opening == '{' && c == '}'))) + { + if (tok->parenlinenostack[tok->level] != tok->lineno) { + return syntaxerror(tok, + "closing parenthesis '%c' does not match " + "opening parenthesis '%c' on line %d", + c, opening, tok->parenlinenostack[tok->level]); + } + else { + return syntaxerror(tok, + "closing parenthesis '%c' does not match " + "opening parenthesis '%c'", + c, opening); + } + } break; } /* Punctuation character */ *p_start = tok->start; *p_end = tok->cur; - return Ta3Token_OneChar(c); + return PyToken_OneChar(c); } int -Ta3Tokenizer_Get(struct tok_state *tok, char **p_start, char **p_end) +PyTokenizer_Get(struct tok_state *tok, const char **p_start, const char **p_end) { int result = tok_get(tok, p_start, p_end); if (tok->decoding_erred) { @@ -1973,7 +1822,7 @@ Ta3Tokenizer_Get(struct tok_state *tok, char **p_start, char **p_end) /* Get the encoding of a Python file. Check for the coding cookie and check if the file starts with a BOM. - Ta3Tokenizer_FindEncodingFilename() returns NULL when it can't find the + PyTokenizer_FindEncodingFilename() returns NULL when it can't find the encoding in the first or second line of the file (in which case the encoding should be assumed to be UTF-8). @@ -1981,17 +1830,15 @@ Ta3Tokenizer_Get(struct tok_state *tok, char **p_start, char **p_end) by the caller. */ char * -Ta3Tokenizer_FindEncodingFilename(int fd, PyObject *filename) +PyTokenizer_FindEncodingFilename(int fd, PyObject *filename) { struct tok_state *tok; FILE *fp; - char *p_start =NULL , *p_end =NULL , *encoding = NULL; + const char *p_start = NULL; + const char *p_end = NULL; + char *encoding = NULL; -#ifndef PGEN fd = _Py_dup(fd); -#else - fd = dup(fd); -#endif if (fd < 0) { return NULL; } @@ -2000,12 +1847,11 @@ Ta3Tokenizer_FindEncodingFilename(int fd, PyObject *filename) if (fp == NULL) { return NULL; } - tok = Ta3Tokenizer_FromFile(fp, NULL, NULL, NULL); + tok = PyTokenizer_FromFile(fp, NULL, NULL, NULL); if (tok == NULL) { fclose(fp); return NULL; } -#ifndef PGEN if (filename != NULL) { Py_INCREF(filename); tok->filename = filename; @@ -2014,28 +1860,27 @@ Ta3Tokenizer_FindEncodingFilename(int fd, PyObject *filename) tok->filename = PyUnicode_FromString(""); if (tok->filename == NULL) { fclose(fp); - Ta3Tokenizer_Free(tok); + PyTokenizer_Free(tok); return encoding; } } -#endif while (tok->lineno < 2 && tok->done == E_OK) { - Ta3Tokenizer_Get(tok, &p_start, &p_end); + PyTokenizer_Get(tok, &p_start, &p_end); } fclose(fp); if (tok->encoding) { encoding = (char *)PyMem_MALLOC(strlen(tok->encoding) + 1); if (encoding) - strcpy(encoding, tok->encoding); + strcpy(encoding, tok->encoding); } - Ta3Tokenizer_Free(tok); + PyTokenizer_Free(tok); return encoding; } char * -Ta3Tokenizer_FindEncoding(int fd) +PyTokenizer_FindEncoding(int fd) { - return Ta3Tokenizer_FindEncodingFilename(fd, NULL); + return PyTokenizer_FindEncodingFilename(fd, NULL); } #ifdef Py_DEBUG @@ -2043,7 +1888,7 @@ Ta3Tokenizer_FindEncoding(int fd) void tok_dump(int type, char *start, char *end) { - printf("%s", _Ta3Parser_TokenNames[type]); + printf("%s", _PyParser_TokenNames[type]); if (type == NAME || type == NUMBER || type == STRING || type == OP) printf("(%.*s)", (int)(end - start), start); } diff --git a/ast3/Parser/tokenizer.h b/ast3/Parser/tokenizer.h index c2a3a384..5660ea38 100644 --- a/ast3/Parser/tokenizer.h +++ b/ast3/Parser/tokenizer.h @@ -1,5 +1,5 @@ -#ifndef Ta3_TOKENIZER_H -#define Ta3_TOKENIZER_H +#ifndef Py_TOKENIZER_H +#define Py_TOKENIZER_H #ifdef __cplusplus extern "C" { #endif @@ -8,9 +8,10 @@ extern "C" { /* Tokenizer interface */ -#include "../Include/token.h" +#include "token.h" /* For token types */ #define MAXINDENT 100 /* Max indentation level */ +#define MAXLEVEL 200 /* Max parentheses level */ enum decoding_state { STATE_INIT, @@ -25,8 +26,8 @@ struct tok_state { char *buf; /* Input buffer, or NULL; malloc'ed if fp != NULL */ char *cur; /* Next character in buffer */ char *inp; /* End of data in buffer */ - char *end; /* End of input buffer if buf != NULL */ - char *start; /* Start of current token if not NULL */ + const char *end; /* End of input buffer if buf != NULL */ + const char *start; /* Start of current token if not NULL */ int done; /* E_OK normally, E_EOF at EOF, otherwise error code */ /* NB If done != E_OK, cur must be == inp!!! */ FILE *fp; /* Rest of input; NULL if tokenizing a string */ @@ -37,16 +38,14 @@ struct tok_state { int pendin; /* Pending indents (if > 0) or dedents (if < 0) */ const char *prompt, *nextprompt; /* For interactive prompting */ int lineno; /* Current line number */ + int first_lineno; /* First line of a single line or multi line string + expression (cf. issue 16806) */ int level; /* () [] {} Parentheses nesting level */ /* Used to allow free continuations inside them */ - /* Stuff for checking on different tab sizes */ -#ifndef PGEN - /* pgen doesn't have access to Python codecs, it cannot decode the input - filename. The bytes filename might be kept, but it is only used by - indenterror() and it is not really needed: pgen only compiles one file - (Grammar/Grammar). */ + char parenstack[MAXLEVEL]; + int parenlinenostack[MAXLEVEL]; PyObject *filename; -#endif + /* Stuff for checking on different tab sizes */ int altindstack[MAXINDENT]; /* Stack of alternate indents */ /* Stuff for PEP 0263 */ enum decoding_state decoding_state; @@ -55,31 +54,35 @@ struct tok_state { char *encoding; /* Source encoding. */ int cont_line; /* whether we are in a continuation line. */ const char* line_start; /* pointer to start of current line */ -#ifndef PGEN + const char* multi_line_start; /* pointer to start of first line of + a single line or multi line string + expression (cf. issue 16806) */ PyObject *decoding_readline; /* open(...).readline */ PyObject *decoding_buffer; -#endif const char* enc; /* Encoding for the current str. */ - const char* str; - const char* input; /* Tokenizer's newline translated copy of the string. */ + char* str; + char* input; /* Tokenizer's newline translated copy of the string. */ + + int type_comments; /* Whether to look for type comments */ - /* async/await related fields; can be removed in 3.7 when async and await - become normal keywords. */ + /* async/await related fields (still needed depending on feature_version) */ + int async_hacks; /* =1 if async/await aren't always keywords */ int async_def; /* =1 if tokens are inside an 'async def' body. */ int async_def_indent; /* Indentation level of the outermost 'async def'. */ int async_def_nl; /* =1 if the outermost 'async def' had at least one NEWLINE token after it. */ - int async_always; /* =1 if async/await are always keywords */ }; -extern struct tok_state *Ta3Tokenizer_FromString(const char *, int); -extern struct tok_state *Ta3Tokenizer_FromUTF8(const char *, int); -extern struct tok_state *Ta3Tokenizer_FromFile(FILE *, const char*, +extern struct tok_state *PyTokenizer_FromString(const char *, int); +extern struct tok_state *PyTokenizer_FromUTF8(const char *, int); +extern struct tok_state *PyTokenizer_FromFile(FILE *, const char*, const char *, const char *); -extern void Ta3Tokenizer_Free(struct tok_state *); -extern int Ta3Tokenizer_Get(struct tok_state *, char **, char **); +extern void PyTokenizer_Free(struct tok_state *); +extern int PyTokenizer_Get(struct tok_state *, const char **, const char **); + +#define tok_dump _Py_tok_dump #ifdef __cplusplus } #endif -#endif /* !Ta3_TOKENIZER_H */ +#endif /* !Py_TOKENIZER_H */ diff --git a/ast3/Python/Python-ast.c b/ast3/Python/Python-ast.c index 4359a488..f34b1450 100644 --- a/ast3/Python/Python-ast.c +++ b/ast3/Python/Python-ast.c @@ -3,51 +3,788 @@ #include #include "Python.h" -#include "../Include/Python-ast.h" +#include "Python-ast.h" +#include "structmember.h" // PyMemberDef + +typedef struct { + int initialized; + PyObject *AST_type; + PyObject *Add_singleton; + PyObject *Add_type; + PyObject *And_singleton; + PyObject *And_type; + PyObject *AnnAssign_type; + PyObject *Assert_type; + PyObject *Assign_type; + PyObject *AsyncFor_type; + PyObject *AsyncFunctionDef_type; + PyObject *AsyncWith_type; + PyObject *Attribute_type; + PyObject *AugAssign_type; + PyObject *Await_type; + PyObject *BinOp_type; + PyObject *BitAnd_singleton; + PyObject *BitAnd_type; + PyObject *BitOr_singleton; + PyObject *BitOr_type; + PyObject *BitXor_singleton; + PyObject *BitXor_type; + PyObject *BoolOp_type; + PyObject *Break_type; + PyObject *Call_type; + PyObject *ClassDef_type; + PyObject *Compare_type; + PyObject *Constant_type; + PyObject *Continue_type; + PyObject *Del_singleton; + PyObject *Del_type; + PyObject *Delete_type; + PyObject *DictComp_type; + PyObject *Dict_type; + PyObject *Div_singleton; + PyObject *Div_type; + PyObject *Eq_singleton; + PyObject *Eq_type; + PyObject *ExceptHandler_type; + PyObject *Expr_type; + PyObject *Expression_type; + PyObject *FloorDiv_singleton; + PyObject *FloorDiv_type; + PyObject *For_type; + PyObject *FormattedValue_type; + PyObject *FunctionDef_type; + PyObject *FunctionType_type; + PyObject *GeneratorExp_type; + PyObject *Global_type; + PyObject *GtE_singleton; + PyObject *GtE_type; + PyObject *Gt_singleton; + PyObject *Gt_type; + PyObject *IfExp_type; + PyObject *If_type; + PyObject *ImportFrom_type; + PyObject *Import_type; + PyObject *In_singleton; + PyObject *In_type; + PyObject *Interactive_type; + PyObject *Invert_singleton; + PyObject *Invert_type; + PyObject *IsNot_singleton; + PyObject *IsNot_type; + PyObject *Is_singleton; + PyObject *Is_type; + PyObject *JoinedStr_type; + PyObject *LShift_singleton; + PyObject *LShift_type; + PyObject *Lambda_type; + PyObject *ListComp_type; + PyObject *List_type; + PyObject *Load_singleton; + PyObject *Load_type; + PyObject *LtE_singleton; + PyObject *LtE_type; + PyObject *Lt_singleton; + PyObject *Lt_type; + PyObject *MatMult_singleton; + PyObject *MatMult_type; + PyObject *Mod_singleton; + PyObject *Mod_type; + PyObject *Module_type; + PyObject *Mult_singleton; + PyObject *Mult_type; + PyObject *Name_type; + PyObject *NamedExpr_type; + PyObject *Nonlocal_type; + PyObject *NotEq_singleton; + PyObject *NotEq_type; + PyObject *NotIn_singleton; + PyObject *NotIn_type; + PyObject *Not_singleton; + PyObject *Not_type; + PyObject *Or_singleton; + PyObject *Or_type; + PyObject *Pass_type; + PyObject *Pow_singleton; + PyObject *Pow_type; + PyObject *RShift_singleton; + PyObject *RShift_type; + PyObject *Raise_type; + PyObject *Return_type; + PyObject *SetComp_type; + PyObject *Set_type; + PyObject *Slice_type; + PyObject *Starred_type; + PyObject *Store_singleton; + PyObject *Store_type; + PyObject *Sub_singleton; + PyObject *Sub_type; + PyObject *Subscript_type; + PyObject *Try_type; + PyObject *Tuple_type; + PyObject *TypeIgnore_type; + PyObject *UAdd_singleton; + PyObject *UAdd_type; + PyObject *USub_singleton; + PyObject *USub_type; + PyObject *UnaryOp_type; + PyObject *While_type; + PyObject *With_type; + PyObject *YieldFrom_type; + PyObject *Yield_type; + PyObject *__dict__; + PyObject *__doc__; + PyObject *__module__; + PyObject *_attributes; + PyObject *_fields; + PyObject *alias_type; + PyObject *annotation; + PyObject *arg; + PyObject *arg_type; + PyObject *args; + PyObject *argtypes; + PyObject *arguments_type; + PyObject *asname; + PyObject *ast; + PyObject *attr; + PyObject *bases; + PyObject *body; + PyObject *boolop_type; + PyObject *cause; + PyObject *cmpop_type; + PyObject *col_offset; + PyObject *comparators; + PyObject *comprehension_type; + PyObject *context_expr; + PyObject *conversion; + PyObject *ctx; + PyObject *decorator_list; + PyObject *defaults; + PyObject *elt; + PyObject *elts; + PyObject *end_col_offset; + PyObject *end_lineno; + PyObject *exc; + PyObject *excepthandler_type; + PyObject *expr_context_type; + PyObject *expr_type; + PyObject *finalbody; + PyObject *format_spec; + PyObject *func; + PyObject *generators; + PyObject *handlers; + PyObject *id; + PyObject *ifs; + PyObject *is_async; + PyObject *items; + PyObject *iter; + PyObject *key; + PyObject *keys; + PyObject *keyword_type; + PyObject *keywords; + PyObject *kind; + PyObject *kw_defaults; + PyObject *kwarg; + PyObject *kwonlyargs; + PyObject *left; + PyObject *level; + PyObject *lineno; + PyObject *lower; + PyObject *mod_type; + PyObject *module; + PyObject *msg; + PyObject *name; + PyObject *names; + PyObject *op; + PyObject *operand; + PyObject *operator_type; + PyObject *ops; + PyObject *optional_vars; + PyObject *orelse; + PyObject *posonlyargs; + PyObject *returns; + PyObject *right; + PyObject *simple; + PyObject *slice; + PyObject *step; + PyObject *stmt_type; + PyObject *tag; + PyObject *target; + PyObject *targets; + PyObject *test; + PyObject *type; + PyObject *type_comment; + PyObject *type_ignore_type; + PyObject *type_ignores; + PyObject *unaryop_type; + PyObject *upper; + PyObject *value; + PyObject *values; + PyObject *vararg; + PyObject *withitem_type; +} astmodulestate; + + +#define astmodulestate(o) ((astmodulestate *)PyModule_GetState(o)) + +static int astmodule_clear(PyObject *module) +{ + Py_CLEAR(astmodulestate(module)->AST_type); + Py_CLEAR(astmodulestate(module)->Add_singleton); + Py_CLEAR(astmodulestate(module)->Add_type); + Py_CLEAR(astmodulestate(module)->And_singleton); + Py_CLEAR(astmodulestate(module)->And_type); + Py_CLEAR(astmodulestate(module)->AnnAssign_type); + Py_CLEAR(astmodulestate(module)->Assert_type); + Py_CLEAR(astmodulestate(module)->Assign_type); + Py_CLEAR(astmodulestate(module)->AsyncFor_type); + Py_CLEAR(astmodulestate(module)->AsyncFunctionDef_type); + Py_CLEAR(astmodulestate(module)->AsyncWith_type); + Py_CLEAR(astmodulestate(module)->Attribute_type); + Py_CLEAR(astmodulestate(module)->AugAssign_type); + Py_CLEAR(astmodulestate(module)->Await_type); + Py_CLEAR(astmodulestate(module)->BinOp_type); + Py_CLEAR(astmodulestate(module)->BitAnd_singleton); + Py_CLEAR(astmodulestate(module)->BitAnd_type); + Py_CLEAR(astmodulestate(module)->BitOr_singleton); + Py_CLEAR(astmodulestate(module)->BitOr_type); + Py_CLEAR(astmodulestate(module)->BitXor_singleton); + Py_CLEAR(astmodulestate(module)->BitXor_type); + Py_CLEAR(astmodulestate(module)->BoolOp_type); + Py_CLEAR(astmodulestate(module)->Break_type); + Py_CLEAR(astmodulestate(module)->Call_type); + Py_CLEAR(astmodulestate(module)->ClassDef_type); + Py_CLEAR(astmodulestate(module)->Compare_type); + Py_CLEAR(astmodulestate(module)->Constant_type); + Py_CLEAR(astmodulestate(module)->Continue_type); + Py_CLEAR(astmodulestate(module)->Del_singleton); + Py_CLEAR(astmodulestate(module)->Del_type); + Py_CLEAR(astmodulestate(module)->Delete_type); + Py_CLEAR(astmodulestate(module)->DictComp_type); + Py_CLEAR(astmodulestate(module)->Dict_type); + Py_CLEAR(astmodulestate(module)->Div_singleton); + Py_CLEAR(astmodulestate(module)->Div_type); + Py_CLEAR(astmodulestate(module)->Eq_singleton); + Py_CLEAR(astmodulestate(module)->Eq_type); + Py_CLEAR(astmodulestate(module)->ExceptHandler_type); + Py_CLEAR(astmodulestate(module)->Expr_type); + Py_CLEAR(astmodulestate(module)->Expression_type); + Py_CLEAR(astmodulestate(module)->FloorDiv_singleton); + Py_CLEAR(astmodulestate(module)->FloorDiv_type); + Py_CLEAR(astmodulestate(module)->For_type); + Py_CLEAR(astmodulestate(module)->FormattedValue_type); + Py_CLEAR(astmodulestate(module)->FunctionDef_type); + Py_CLEAR(astmodulestate(module)->FunctionType_type); + Py_CLEAR(astmodulestate(module)->GeneratorExp_type); + Py_CLEAR(astmodulestate(module)->Global_type); + Py_CLEAR(astmodulestate(module)->GtE_singleton); + Py_CLEAR(astmodulestate(module)->GtE_type); + Py_CLEAR(astmodulestate(module)->Gt_singleton); + Py_CLEAR(astmodulestate(module)->Gt_type); + Py_CLEAR(astmodulestate(module)->IfExp_type); + Py_CLEAR(astmodulestate(module)->If_type); + Py_CLEAR(astmodulestate(module)->ImportFrom_type); + Py_CLEAR(astmodulestate(module)->Import_type); + Py_CLEAR(astmodulestate(module)->In_singleton); + Py_CLEAR(astmodulestate(module)->In_type); + Py_CLEAR(astmodulestate(module)->Interactive_type); + Py_CLEAR(astmodulestate(module)->Invert_singleton); + Py_CLEAR(astmodulestate(module)->Invert_type); + Py_CLEAR(astmodulestate(module)->IsNot_singleton); + Py_CLEAR(astmodulestate(module)->IsNot_type); + Py_CLEAR(astmodulestate(module)->Is_singleton); + Py_CLEAR(astmodulestate(module)->Is_type); + Py_CLEAR(astmodulestate(module)->JoinedStr_type); + Py_CLEAR(astmodulestate(module)->LShift_singleton); + Py_CLEAR(astmodulestate(module)->LShift_type); + Py_CLEAR(astmodulestate(module)->Lambda_type); + Py_CLEAR(astmodulestate(module)->ListComp_type); + Py_CLEAR(astmodulestate(module)->List_type); + Py_CLEAR(astmodulestate(module)->Load_singleton); + Py_CLEAR(astmodulestate(module)->Load_type); + Py_CLEAR(astmodulestate(module)->LtE_singleton); + Py_CLEAR(astmodulestate(module)->LtE_type); + Py_CLEAR(astmodulestate(module)->Lt_singleton); + Py_CLEAR(astmodulestate(module)->Lt_type); + Py_CLEAR(astmodulestate(module)->MatMult_singleton); + Py_CLEAR(astmodulestate(module)->MatMult_type); + Py_CLEAR(astmodulestate(module)->Mod_singleton); + Py_CLEAR(astmodulestate(module)->Mod_type); + Py_CLEAR(astmodulestate(module)->Module_type); + Py_CLEAR(astmodulestate(module)->Mult_singleton); + Py_CLEAR(astmodulestate(module)->Mult_type); + Py_CLEAR(astmodulestate(module)->Name_type); + Py_CLEAR(astmodulestate(module)->NamedExpr_type); + Py_CLEAR(astmodulestate(module)->Nonlocal_type); + Py_CLEAR(astmodulestate(module)->NotEq_singleton); + Py_CLEAR(astmodulestate(module)->NotEq_type); + Py_CLEAR(astmodulestate(module)->NotIn_singleton); + Py_CLEAR(astmodulestate(module)->NotIn_type); + Py_CLEAR(astmodulestate(module)->Not_singleton); + Py_CLEAR(astmodulestate(module)->Not_type); + Py_CLEAR(astmodulestate(module)->Or_singleton); + Py_CLEAR(astmodulestate(module)->Or_type); + Py_CLEAR(astmodulestate(module)->Pass_type); + Py_CLEAR(astmodulestate(module)->Pow_singleton); + Py_CLEAR(astmodulestate(module)->Pow_type); + Py_CLEAR(astmodulestate(module)->RShift_singleton); + Py_CLEAR(astmodulestate(module)->RShift_type); + Py_CLEAR(astmodulestate(module)->Raise_type); + Py_CLEAR(astmodulestate(module)->Return_type); + Py_CLEAR(astmodulestate(module)->SetComp_type); + Py_CLEAR(astmodulestate(module)->Set_type); + Py_CLEAR(astmodulestate(module)->Slice_type); + Py_CLEAR(astmodulestate(module)->Starred_type); + Py_CLEAR(astmodulestate(module)->Store_singleton); + Py_CLEAR(astmodulestate(module)->Store_type); + Py_CLEAR(astmodulestate(module)->Sub_singleton); + Py_CLEAR(astmodulestate(module)->Sub_type); + Py_CLEAR(astmodulestate(module)->Subscript_type); + Py_CLEAR(astmodulestate(module)->Try_type); + Py_CLEAR(astmodulestate(module)->Tuple_type); + Py_CLEAR(astmodulestate(module)->TypeIgnore_type); + Py_CLEAR(astmodulestate(module)->UAdd_singleton); + Py_CLEAR(astmodulestate(module)->UAdd_type); + Py_CLEAR(astmodulestate(module)->USub_singleton); + Py_CLEAR(astmodulestate(module)->USub_type); + Py_CLEAR(astmodulestate(module)->UnaryOp_type); + Py_CLEAR(astmodulestate(module)->While_type); + Py_CLEAR(astmodulestate(module)->With_type); + Py_CLEAR(astmodulestate(module)->YieldFrom_type); + Py_CLEAR(astmodulestate(module)->Yield_type); + Py_CLEAR(astmodulestate(module)->__dict__); + Py_CLEAR(astmodulestate(module)->__doc__); + Py_CLEAR(astmodulestate(module)->__module__); + Py_CLEAR(astmodulestate(module)->_attributes); + Py_CLEAR(astmodulestate(module)->_fields); + Py_CLEAR(astmodulestate(module)->alias_type); + Py_CLEAR(astmodulestate(module)->annotation); + Py_CLEAR(astmodulestate(module)->arg); + Py_CLEAR(astmodulestate(module)->arg_type); + Py_CLEAR(astmodulestate(module)->args); + Py_CLEAR(astmodulestate(module)->argtypes); + Py_CLEAR(astmodulestate(module)->arguments_type); + Py_CLEAR(astmodulestate(module)->asname); + Py_CLEAR(astmodulestate(module)->ast); + Py_CLEAR(astmodulestate(module)->attr); + Py_CLEAR(astmodulestate(module)->bases); + Py_CLEAR(astmodulestate(module)->body); + Py_CLEAR(astmodulestate(module)->boolop_type); + Py_CLEAR(astmodulestate(module)->cause); + Py_CLEAR(astmodulestate(module)->cmpop_type); + Py_CLEAR(astmodulestate(module)->col_offset); + Py_CLEAR(astmodulestate(module)->comparators); + Py_CLEAR(astmodulestate(module)->comprehension_type); + Py_CLEAR(astmodulestate(module)->context_expr); + Py_CLEAR(astmodulestate(module)->conversion); + Py_CLEAR(astmodulestate(module)->ctx); + Py_CLEAR(astmodulestate(module)->decorator_list); + Py_CLEAR(astmodulestate(module)->defaults); + Py_CLEAR(astmodulestate(module)->elt); + Py_CLEAR(astmodulestate(module)->elts); + Py_CLEAR(astmodulestate(module)->end_col_offset); + Py_CLEAR(astmodulestate(module)->end_lineno); + Py_CLEAR(astmodulestate(module)->exc); + Py_CLEAR(astmodulestate(module)->excepthandler_type); + Py_CLEAR(astmodulestate(module)->expr_context_type); + Py_CLEAR(astmodulestate(module)->expr_type); + Py_CLEAR(astmodulestate(module)->finalbody); + Py_CLEAR(astmodulestate(module)->format_spec); + Py_CLEAR(astmodulestate(module)->func); + Py_CLEAR(astmodulestate(module)->generators); + Py_CLEAR(astmodulestate(module)->handlers); + Py_CLEAR(astmodulestate(module)->id); + Py_CLEAR(astmodulestate(module)->ifs); + Py_CLEAR(astmodulestate(module)->is_async); + Py_CLEAR(astmodulestate(module)->items); + Py_CLEAR(astmodulestate(module)->iter); + Py_CLEAR(astmodulestate(module)->key); + Py_CLEAR(astmodulestate(module)->keys); + Py_CLEAR(astmodulestate(module)->keyword_type); + Py_CLEAR(astmodulestate(module)->keywords); + Py_CLEAR(astmodulestate(module)->kind); + Py_CLEAR(astmodulestate(module)->kw_defaults); + Py_CLEAR(astmodulestate(module)->kwarg); + Py_CLEAR(astmodulestate(module)->kwonlyargs); + Py_CLEAR(astmodulestate(module)->left); + Py_CLEAR(astmodulestate(module)->level); + Py_CLEAR(astmodulestate(module)->lineno); + Py_CLEAR(astmodulestate(module)->lower); + Py_CLEAR(astmodulestate(module)->mod_type); + Py_CLEAR(astmodulestate(module)->module); + Py_CLEAR(astmodulestate(module)->msg); + Py_CLEAR(astmodulestate(module)->name); + Py_CLEAR(astmodulestate(module)->names); + Py_CLEAR(astmodulestate(module)->op); + Py_CLEAR(astmodulestate(module)->operand); + Py_CLEAR(astmodulestate(module)->operator_type); + Py_CLEAR(astmodulestate(module)->ops); + Py_CLEAR(astmodulestate(module)->optional_vars); + Py_CLEAR(astmodulestate(module)->orelse); + Py_CLEAR(astmodulestate(module)->posonlyargs); + Py_CLEAR(astmodulestate(module)->returns); + Py_CLEAR(astmodulestate(module)->right); + Py_CLEAR(astmodulestate(module)->simple); + Py_CLEAR(astmodulestate(module)->slice); + Py_CLEAR(astmodulestate(module)->step); + Py_CLEAR(astmodulestate(module)->stmt_type); + Py_CLEAR(astmodulestate(module)->tag); + Py_CLEAR(astmodulestate(module)->target); + Py_CLEAR(astmodulestate(module)->targets); + Py_CLEAR(astmodulestate(module)->test); + Py_CLEAR(astmodulestate(module)->type); + Py_CLEAR(astmodulestate(module)->type_comment); + Py_CLEAR(astmodulestate(module)->type_ignore_type); + Py_CLEAR(astmodulestate(module)->type_ignores); + Py_CLEAR(astmodulestate(module)->unaryop_type); + Py_CLEAR(astmodulestate(module)->upper); + Py_CLEAR(astmodulestate(module)->value); + Py_CLEAR(astmodulestate(module)->values); + Py_CLEAR(astmodulestate(module)->vararg); + Py_CLEAR(astmodulestate(module)->withitem_type); + + return 0; +} + +static int astmodule_traverse(PyObject *module, visitproc visit, void* arg) +{ + Py_VISIT(astmodulestate(module)->AST_type); + Py_VISIT(astmodulestate(module)->Add_singleton); + Py_VISIT(astmodulestate(module)->Add_type); + Py_VISIT(astmodulestate(module)->And_singleton); + Py_VISIT(astmodulestate(module)->And_type); + Py_VISIT(astmodulestate(module)->AnnAssign_type); + Py_VISIT(astmodulestate(module)->Assert_type); + Py_VISIT(astmodulestate(module)->Assign_type); + Py_VISIT(astmodulestate(module)->AsyncFor_type); + Py_VISIT(astmodulestate(module)->AsyncFunctionDef_type); + Py_VISIT(astmodulestate(module)->AsyncWith_type); + Py_VISIT(astmodulestate(module)->Attribute_type); + Py_VISIT(astmodulestate(module)->AugAssign_type); + Py_VISIT(astmodulestate(module)->Await_type); + Py_VISIT(astmodulestate(module)->BinOp_type); + Py_VISIT(astmodulestate(module)->BitAnd_singleton); + Py_VISIT(astmodulestate(module)->BitAnd_type); + Py_VISIT(astmodulestate(module)->BitOr_singleton); + Py_VISIT(astmodulestate(module)->BitOr_type); + Py_VISIT(astmodulestate(module)->BitXor_singleton); + Py_VISIT(astmodulestate(module)->BitXor_type); + Py_VISIT(astmodulestate(module)->BoolOp_type); + Py_VISIT(astmodulestate(module)->Break_type); + Py_VISIT(astmodulestate(module)->Call_type); + Py_VISIT(astmodulestate(module)->ClassDef_type); + Py_VISIT(astmodulestate(module)->Compare_type); + Py_VISIT(astmodulestate(module)->Constant_type); + Py_VISIT(astmodulestate(module)->Continue_type); + Py_VISIT(astmodulestate(module)->Del_singleton); + Py_VISIT(astmodulestate(module)->Del_type); + Py_VISIT(astmodulestate(module)->Delete_type); + Py_VISIT(astmodulestate(module)->DictComp_type); + Py_VISIT(astmodulestate(module)->Dict_type); + Py_VISIT(astmodulestate(module)->Div_singleton); + Py_VISIT(astmodulestate(module)->Div_type); + Py_VISIT(astmodulestate(module)->Eq_singleton); + Py_VISIT(astmodulestate(module)->Eq_type); + Py_VISIT(astmodulestate(module)->ExceptHandler_type); + Py_VISIT(astmodulestate(module)->Expr_type); + Py_VISIT(astmodulestate(module)->Expression_type); + Py_VISIT(astmodulestate(module)->FloorDiv_singleton); + Py_VISIT(astmodulestate(module)->FloorDiv_type); + Py_VISIT(astmodulestate(module)->For_type); + Py_VISIT(astmodulestate(module)->FormattedValue_type); + Py_VISIT(astmodulestate(module)->FunctionDef_type); + Py_VISIT(astmodulestate(module)->FunctionType_type); + Py_VISIT(astmodulestate(module)->GeneratorExp_type); + Py_VISIT(astmodulestate(module)->Global_type); + Py_VISIT(astmodulestate(module)->GtE_singleton); + Py_VISIT(astmodulestate(module)->GtE_type); + Py_VISIT(astmodulestate(module)->Gt_singleton); + Py_VISIT(astmodulestate(module)->Gt_type); + Py_VISIT(astmodulestate(module)->IfExp_type); + Py_VISIT(astmodulestate(module)->If_type); + Py_VISIT(astmodulestate(module)->ImportFrom_type); + Py_VISIT(astmodulestate(module)->Import_type); + Py_VISIT(astmodulestate(module)->In_singleton); + Py_VISIT(astmodulestate(module)->In_type); + Py_VISIT(astmodulestate(module)->Interactive_type); + Py_VISIT(astmodulestate(module)->Invert_singleton); + Py_VISIT(astmodulestate(module)->Invert_type); + Py_VISIT(astmodulestate(module)->IsNot_singleton); + Py_VISIT(astmodulestate(module)->IsNot_type); + Py_VISIT(astmodulestate(module)->Is_singleton); + Py_VISIT(astmodulestate(module)->Is_type); + Py_VISIT(astmodulestate(module)->JoinedStr_type); + Py_VISIT(astmodulestate(module)->LShift_singleton); + Py_VISIT(astmodulestate(module)->LShift_type); + Py_VISIT(astmodulestate(module)->Lambda_type); + Py_VISIT(astmodulestate(module)->ListComp_type); + Py_VISIT(astmodulestate(module)->List_type); + Py_VISIT(astmodulestate(module)->Load_singleton); + Py_VISIT(astmodulestate(module)->Load_type); + Py_VISIT(astmodulestate(module)->LtE_singleton); + Py_VISIT(astmodulestate(module)->LtE_type); + Py_VISIT(astmodulestate(module)->Lt_singleton); + Py_VISIT(astmodulestate(module)->Lt_type); + Py_VISIT(astmodulestate(module)->MatMult_singleton); + Py_VISIT(astmodulestate(module)->MatMult_type); + Py_VISIT(astmodulestate(module)->Mod_singleton); + Py_VISIT(astmodulestate(module)->Mod_type); + Py_VISIT(astmodulestate(module)->Module_type); + Py_VISIT(astmodulestate(module)->Mult_singleton); + Py_VISIT(astmodulestate(module)->Mult_type); + Py_VISIT(astmodulestate(module)->Name_type); + Py_VISIT(astmodulestate(module)->NamedExpr_type); + Py_VISIT(astmodulestate(module)->Nonlocal_type); + Py_VISIT(astmodulestate(module)->NotEq_singleton); + Py_VISIT(astmodulestate(module)->NotEq_type); + Py_VISIT(astmodulestate(module)->NotIn_singleton); + Py_VISIT(astmodulestate(module)->NotIn_type); + Py_VISIT(astmodulestate(module)->Not_singleton); + Py_VISIT(astmodulestate(module)->Not_type); + Py_VISIT(astmodulestate(module)->Or_singleton); + Py_VISIT(astmodulestate(module)->Or_type); + Py_VISIT(astmodulestate(module)->Pass_type); + Py_VISIT(astmodulestate(module)->Pow_singleton); + Py_VISIT(astmodulestate(module)->Pow_type); + Py_VISIT(astmodulestate(module)->RShift_singleton); + Py_VISIT(astmodulestate(module)->RShift_type); + Py_VISIT(astmodulestate(module)->Raise_type); + Py_VISIT(astmodulestate(module)->Return_type); + Py_VISIT(astmodulestate(module)->SetComp_type); + Py_VISIT(astmodulestate(module)->Set_type); + Py_VISIT(astmodulestate(module)->Slice_type); + Py_VISIT(astmodulestate(module)->Starred_type); + Py_VISIT(astmodulestate(module)->Store_singleton); + Py_VISIT(astmodulestate(module)->Store_type); + Py_VISIT(astmodulestate(module)->Sub_singleton); + Py_VISIT(astmodulestate(module)->Sub_type); + Py_VISIT(astmodulestate(module)->Subscript_type); + Py_VISIT(astmodulestate(module)->Try_type); + Py_VISIT(astmodulestate(module)->Tuple_type); + Py_VISIT(astmodulestate(module)->TypeIgnore_type); + Py_VISIT(astmodulestate(module)->UAdd_singleton); + Py_VISIT(astmodulestate(module)->UAdd_type); + Py_VISIT(astmodulestate(module)->USub_singleton); + Py_VISIT(astmodulestate(module)->USub_type); + Py_VISIT(astmodulestate(module)->UnaryOp_type); + Py_VISIT(astmodulestate(module)->While_type); + Py_VISIT(astmodulestate(module)->With_type); + Py_VISIT(astmodulestate(module)->YieldFrom_type); + Py_VISIT(astmodulestate(module)->Yield_type); + Py_VISIT(astmodulestate(module)->__dict__); + Py_VISIT(astmodulestate(module)->__doc__); + Py_VISIT(astmodulestate(module)->__module__); + Py_VISIT(astmodulestate(module)->_attributes); + Py_VISIT(astmodulestate(module)->_fields); + Py_VISIT(astmodulestate(module)->alias_type); + Py_VISIT(astmodulestate(module)->annotation); + Py_VISIT(astmodulestate(module)->arg); + Py_VISIT(astmodulestate(module)->arg_type); + Py_VISIT(astmodulestate(module)->args); + Py_VISIT(astmodulestate(module)->argtypes); + Py_VISIT(astmodulestate(module)->arguments_type); + Py_VISIT(astmodulestate(module)->asname); + Py_VISIT(astmodulestate(module)->ast); + Py_VISIT(astmodulestate(module)->attr); + Py_VISIT(astmodulestate(module)->bases); + Py_VISIT(astmodulestate(module)->body); + Py_VISIT(astmodulestate(module)->boolop_type); + Py_VISIT(astmodulestate(module)->cause); + Py_VISIT(astmodulestate(module)->cmpop_type); + Py_VISIT(astmodulestate(module)->col_offset); + Py_VISIT(astmodulestate(module)->comparators); + Py_VISIT(astmodulestate(module)->comprehension_type); + Py_VISIT(astmodulestate(module)->context_expr); + Py_VISIT(astmodulestate(module)->conversion); + Py_VISIT(astmodulestate(module)->ctx); + Py_VISIT(astmodulestate(module)->decorator_list); + Py_VISIT(astmodulestate(module)->defaults); + Py_VISIT(astmodulestate(module)->elt); + Py_VISIT(astmodulestate(module)->elts); + Py_VISIT(astmodulestate(module)->end_col_offset); + Py_VISIT(astmodulestate(module)->end_lineno); + Py_VISIT(astmodulestate(module)->exc); + Py_VISIT(astmodulestate(module)->excepthandler_type); + Py_VISIT(astmodulestate(module)->expr_context_type); + Py_VISIT(astmodulestate(module)->expr_type); + Py_VISIT(astmodulestate(module)->finalbody); + Py_VISIT(astmodulestate(module)->format_spec); + Py_VISIT(astmodulestate(module)->func); + Py_VISIT(astmodulestate(module)->generators); + Py_VISIT(astmodulestate(module)->handlers); + Py_VISIT(astmodulestate(module)->id); + Py_VISIT(astmodulestate(module)->ifs); + Py_VISIT(astmodulestate(module)->is_async); + Py_VISIT(astmodulestate(module)->items); + Py_VISIT(astmodulestate(module)->iter); + Py_VISIT(astmodulestate(module)->key); + Py_VISIT(astmodulestate(module)->keys); + Py_VISIT(astmodulestate(module)->keyword_type); + Py_VISIT(astmodulestate(module)->keywords); + Py_VISIT(astmodulestate(module)->kind); + Py_VISIT(astmodulestate(module)->kw_defaults); + Py_VISIT(astmodulestate(module)->kwarg); + Py_VISIT(astmodulestate(module)->kwonlyargs); + Py_VISIT(astmodulestate(module)->left); + Py_VISIT(astmodulestate(module)->level); + Py_VISIT(astmodulestate(module)->lineno); + Py_VISIT(astmodulestate(module)->lower); + Py_VISIT(astmodulestate(module)->mod_type); + Py_VISIT(astmodulestate(module)->module); + Py_VISIT(astmodulestate(module)->msg); + Py_VISIT(astmodulestate(module)->name); + Py_VISIT(astmodulestate(module)->names); + Py_VISIT(astmodulestate(module)->op); + Py_VISIT(astmodulestate(module)->operand); + Py_VISIT(astmodulestate(module)->operator_type); + Py_VISIT(astmodulestate(module)->ops); + Py_VISIT(astmodulestate(module)->optional_vars); + Py_VISIT(astmodulestate(module)->orelse); + Py_VISIT(astmodulestate(module)->posonlyargs); + Py_VISIT(astmodulestate(module)->returns); + Py_VISIT(astmodulestate(module)->right); + Py_VISIT(astmodulestate(module)->simple); + Py_VISIT(astmodulestate(module)->slice); + Py_VISIT(astmodulestate(module)->step); + Py_VISIT(astmodulestate(module)->stmt_type); + Py_VISIT(astmodulestate(module)->tag); + Py_VISIT(astmodulestate(module)->target); + Py_VISIT(astmodulestate(module)->targets); + Py_VISIT(astmodulestate(module)->test); + Py_VISIT(astmodulestate(module)->type); + Py_VISIT(astmodulestate(module)->type_comment); + Py_VISIT(astmodulestate(module)->type_ignore_type); + Py_VISIT(astmodulestate(module)->type_ignores); + Py_VISIT(astmodulestate(module)->unaryop_type); + Py_VISIT(astmodulestate(module)->upper); + Py_VISIT(astmodulestate(module)->value); + Py_VISIT(astmodulestate(module)->values); + Py_VISIT(astmodulestate(module)->vararg); + Py_VISIT(astmodulestate(module)->withitem_type); + + return 0; +} + +static void astmodule_free(void* module) { + astmodule_clear((PyObject*)module); +} + +static struct PyModuleDef _astmodule = { + PyModuleDef_HEAD_INIT, + "_ast", + NULL, + sizeof(astmodulestate), + NULL, + NULL, + astmodule_traverse, + astmodule_clear, + astmodule_free, +}; + +#define astmodulestate_global ((astmodulestate *)PyModule_GetState(PyState_FindModule(&_astmodule))) + +static int init_identifiers(void) +{ + astmodulestate *state = astmodulestate_global; + if ((state->__dict__ = PyUnicode_InternFromString("__dict__")) == NULL) return 0; + if ((state->__doc__ = PyUnicode_InternFromString("__doc__")) == NULL) return 0; + if ((state->__module__ = PyUnicode_InternFromString("__module__")) == NULL) return 0; + if ((state->_attributes = PyUnicode_InternFromString("_attributes")) == NULL) return 0; + if ((state->_fields = PyUnicode_InternFromString("_fields")) == NULL) return 0; + if ((state->annotation = PyUnicode_InternFromString("annotation")) == NULL) return 0; + if ((state->arg = PyUnicode_InternFromString("arg")) == NULL) return 0; + if ((state->args = PyUnicode_InternFromString("args")) == NULL) return 0; + if ((state->argtypes = PyUnicode_InternFromString("argtypes")) == NULL) return 0; + if ((state->asname = PyUnicode_InternFromString("asname")) == NULL) return 0; + if ((state->ast = PyUnicode_InternFromString("ast")) == NULL) return 0; + if ((state->attr = PyUnicode_InternFromString("attr")) == NULL) return 0; + if ((state->bases = PyUnicode_InternFromString("bases")) == NULL) return 0; + if ((state->body = PyUnicode_InternFromString("body")) == NULL) return 0; + if ((state->cause = PyUnicode_InternFromString("cause")) == NULL) return 0; + if ((state->col_offset = PyUnicode_InternFromString("col_offset")) == NULL) return 0; + if ((state->comparators = PyUnicode_InternFromString("comparators")) == NULL) return 0; + if ((state->context_expr = PyUnicode_InternFromString("context_expr")) == NULL) return 0; + if ((state->conversion = PyUnicode_InternFromString("conversion")) == NULL) return 0; + if ((state->ctx = PyUnicode_InternFromString("ctx")) == NULL) return 0; + if ((state->decorator_list = PyUnicode_InternFromString("decorator_list")) == NULL) return 0; + if ((state->defaults = PyUnicode_InternFromString("defaults")) == NULL) return 0; + if ((state->elt = PyUnicode_InternFromString("elt")) == NULL) return 0; + if ((state->elts = PyUnicode_InternFromString("elts")) == NULL) return 0; + if ((state->end_col_offset = PyUnicode_InternFromString("end_col_offset")) == NULL) return 0; + if ((state->end_lineno = PyUnicode_InternFromString("end_lineno")) == NULL) return 0; + if ((state->exc = PyUnicode_InternFromString("exc")) == NULL) return 0; + if ((state->finalbody = PyUnicode_InternFromString("finalbody")) == NULL) return 0; + if ((state->format_spec = PyUnicode_InternFromString("format_spec")) == NULL) return 0; + if ((state->func = PyUnicode_InternFromString("func")) == NULL) return 0; + if ((state->generators = PyUnicode_InternFromString("generators")) == NULL) return 0; + if ((state->handlers = PyUnicode_InternFromString("handlers")) == NULL) return 0; + if ((state->id = PyUnicode_InternFromString("id")) == NULL) return 0; + if ((state->ifs = PyUnicode_InternFromString("ifs")) == NULL) return 0; + if ((state->is_async = PyUnicode_InternFromString("is_async")) == NULL) return 0; + if ((state->items = PyUnicode_InternFromString("items")) == NULL) return 0; + if ((state->iter = PyUnicode_InternFromString("iter")) == NULL) return 0; + if ((state->key = PyUnicode_InternFromString("key")) == NULL) return 0; + if ((state->keys = PyUnicode_InternFromString("keys")) == NULL) return 0; + if ((state->keywords = PyUnicode_InternFromString("keywords")) == NULL) return 0; + if ((state->kind = PyUnicode_InternFromString("kind")) == NULL) return 0; + if ((state->kw_defaults = PyUnicode_InternFromString("kw_defaults")) == NULL) return 0; + if ((state->kwarg = PyUnicode_InternFromString("kwarg")) == NULL) return 0; + if ((state->kwonlyargs = PyUnicode_InternFromString("kwonlyargs")) == NULL) return 0; + if ((state->left = PyUnicode_InternFromString("left")) == NULL) return 0; + if ((state->level = PyUnicode_InternFromString("level")) == NULL) return 0; + if ((state->lineno = PyUnicode_InternFromString("lineno")) == NULL) return 0; + if ((state->lower = PyUnicode_InternFromString("lower")) == NULL) return 0; + if ((state->module = PyUnicode_InternFromString("module")) == NULL) return 0; + if ((state->msg = PyUnicode_InternFromString("msg")) == NULL) return 0; + if ((state->name = PyUnicode_InternFromString("name")) == NULL) return 0; + if ((state->names = PyUnicode_InternFromString("names")) == NULL) return 0; + if ((state->op = PyUnicode_InternFromString("op")) == NULL) return 0; + if ((state->operand = PyUnicode_InternFromString("operand")) == NULL) return 0; + if ((state->ops = PyUnicode_InternFromString("ops")) == NULL) return 0; + if ((state->optional_vars = PyUnicode_InternFromString("optional_vars")) == NULL) return 0; + if ((state->orelse = PyUnicode_InternFromString("orelse")) == NULL) return 0; + if ((state->posonlyargs = PyUnicode_InternFromString("posonlyargs")) == NULL) return 0; + if ((state->returns = PyUnicode_InternFromString("returns")) == NULL) return 0; + if ((state->right = PyUnicode_InternFromString("right")) == NULL) return 0; + if ((state->simple = PyUnicode_InternFromString("simple")) == NULL) return 0; + if ((state->slice = PyUnicode_InternFromString("slice")) == NULL) return 0; + if ((state->step = PyUnicode_InternFromString("step")) == NULL) return 0; + if ((state->tag = PyUnicode_InternFromString("tag")) == NULL) return 0; + if ((state->target = PyUnicode_InternFromString("target")) == NULL) return 0; + if ((state->targets = PyUnicode_InternFromString("targets")) == NULL) return 0; + if ((state->test = PyUnicode_InternFromString("test")) == NULL) return 0; + if ((state->type = PyUnicode_InternFromString("type")) == NULL) return 0; + if ((state->type_comment = PyUnicode_InternFromString("type_comment")) == NULL) return 0; + if ((state->type_ignores = PyUnicode_InternFromString("type_ignores")) == NULL) return 0; + if ((state->upper = PyUnicode_InternFromString("upper")) == NULL) return 0; + if ((state->value = PyUnicode_InternFromString("value")) == NULL) return 0; + if ((state->values = PyUnicode_InternFromString("values")) == NULL) return 0; + if ((state->vararg = PyUnicode_InternFromString("vararg")) == NULL) return 0; + return 1; +}; -static PyTypeObject AST_type; -static PyTypeObject *mod_type; static PyObject* ast2obj_mod(void*); -static PyTypeObject *Module_type; -_Py_IDENTIFIER(body); -_Py_IDENTIFIER(type_ignores); -static char *Module_fields[]={ +static const char * const Module_fields[]={ "body", "type_ignores", }; -static PyTypeObject *Interactive_type; -static char *Interactive_fields[]={ +static const char * const Interactive_fields[]={ "body", }; -static PyTypeObject *Expression_type; -static char *Expression_fields[]={ +static const char * const Expression_fields[]={ "body", }; -static PyTypeObject *FunctionType_type; -_Py_IDENTIFIER(argtypes); -_Py_IDENTIFIER(returns); -static char *FunctionType_fields[]={ +static const char * const FunctionType_fields[]={ "argtypes", "returns", }; -static PyTypeObject *Suite_type; -static char *Suite_fields[]={ - "body", -}; -static PyTypeObject *stmt_type; -_Py_IDENTIFIER(lineno); -_Py_IDENTIFIER(col_offset); -static char *stmt_attributes[] = { +static const char * const stmt_attributes[] = { "lineno", "col_offset", + "end_lineno", + "end_col_offset", }; static PyObject* ast2obj_stmt(void*); -static PyTypeObject *FunctionDef_type; -_Py_IDENTIFIER(name); -_Py_IDENTIFIER(args); -_Py_IDENTIFIER(decorator_list); -_Py_IDENTIFIER(type_comment); -static char *FunctionDef_fields[]={ +static const char * const FunctionDef_fields[]={ "name", "args", "body", @@ -55,8 +792,7 @@ static char *FunctionDef_fields[]={ "returns", "type_comment", }; -static PyTypeObject *AsyncFunctionDef_type; -static char *AsyncFunctionDef_fields[]={ +static const char * const AsyncFunctionDef_fields[]={ "name", "args", "body", @@ -64,424 +800,246 @@ static char *AsyncFunctionDef_fields[]={ "returns", "type_comment", }; -static PyTypeObject *ClassDef_type; -_Py_IDENTIFIER(bases); -_Py_IDENTIFIER(keywords); -static char *ClassDef_fields[]={ +static const char * const ClassDef_fields[]={ "name", "bases", "keywords", "body", "decorator_list", }; -static PyTypeObject *Return_type; -_Py_IDENTIFIER(value); -static char *Return_fields[]={ +static const char * const Return_fields[]={ "value", }; -static PyTypeObject *Delete_type; -_Py_IDENTIFIER(targets); -static char *Delete_fields[]={ +static const char * const Delete_fields[]={ "targets", }; -static PyTypeObject *Assign_type; -static char *Assign_fields[]={ +static const char * const Assign_fields[]={ "targets", "value", "type_comment", }; -static PyTypeObject *AugAssign_type; -_Py_IDENTIFIER(target); -_Py_IDENTIFIER(op); -static char *AugAssign_fields[]={ +static const char * const AugAssign_fields[]={ "target", "op", "value", }; -static PyTypeObject *AnnAssign_type; -_Py_IDENTIFIER(annotation); -_Py_IDENTIFIER(simple); -static char *AnnAssign_fields[]={ +static const char * const AnnAssign_fields[]={ "target", "annotation", "value", "simple", }; -static PyTypeObject *For_type; -_Py_IDENTIFIER(iter); -_Py_IDENTIFIER(orelse); -static char *For_fields[]={ +static const char * const For_fields[]={ "target", "iter", "body", "orelse", "type_comment", }; -static PyTypeObject *AsyncFor_type; -static char *AsyncFor_fields[]={ +static const char * const AsyncFor_fields[]={ "target", "iter", "body", "orelse", "type_comment", }; -static PyTypeObject *While_type; -_Py_IDENTIFIER(test); -static char *While_fields[]={ +static const char * const While_fields[]={ "test", "body", "orelse", }; -static PyTypeObject *If_type; -static char *If_fields[]={ +static const char * const If_fields[]={ "test", "body", "orelse", }; -static PyTypeObject *With_type; -_Py_IDENTIFIER(items); -static char *With_fields[]={ +static const char * const With_fields[]={ "items", "body", "type_comment", }; -static PyTypeObject *AsyncWith_type; -static char *AsyncWith_fields[]={ +static const char * const AsyncWith_fields[]={ "items", "body", "type_comment", }; -static PyTypeObject *Raise_type; -_Py_IDENTIFIER(exc); -_Py_IDENTIFIER(cause); -static char *Raise_fields[]={ +static const char * const Raise_fields[]={ "exc", "cause", }; -static PyTypeObject *Try_type; -_Py_IDENTIFIER(handlers); -_Py_IDENTIFIER(finalbody); -static char *Try_fields[]={ +static const char * const Try_fields[]={ "body", "handlers", "orelse", "finalbody", }; -static PyTypeObject *Assert_type; -_Py_IDENTIFIER(msg); -static char *Assert_fields[]={ +static const char * const Assert_fields[]={ "test", "msg", }; -static PyTypeObject *Import_type; -_Py_IDENTIFIER(names); -static char *Import_fields[]={ +static const char * const Import_fields[]={ "names", }; -static PyTypeObject *ImportFrom_type; -_Py_IDENTIFIER(module); -_Py_IDENTIFIER(level); -static char *ImportFrom_fields[]={ +static const char * const ImportFrom_fields[]={ "module", "names", "level", }; -static PyTypeObject *Global_type; -static char *Global_fields[]={ +static const char * const Global_fields[]={ "names", }; -static PyTypeObject *Nonlocal_type; -static char *Nonlocal_fields[]={ +static const char * const Nonlocal_fields[]={ "names", }; -static PyTypeObject *Expr_type; -static char *Expr_fields[]={ +static const char * const Expr_fields[]={ "value", }; -static PyTypeObject *Pass_type; -static PyTypeObject *Break_type; -static PyTypeObject *Continue_type; -static PyTypeObject *expr_type; -static char *expr_attributes[] = { +static const char * const expr_attributes[] = { "lineno", "col_offset", + "end_lineno", + "end_col_offset", }; static PyObject* ast2obj_expr(void*); -static PyTypeObject *BoolOp_type; -_Py_IDENTIFIER(values); -static char *BoolOp_fields[]={ +static const char * const BoolOp_fields[]={ "op", "values", }; -static PyTypeObject *BinOp_type; -_Py_IDENTIFIER(left); -_Py_IDENTIFIER(right); -static char *BinOp_fields[]={ +static const char * const NamedExpr_fields[]={ + "target", + "value", +}; +static const char * const BinOp_fields[]={ "left", "op", "right", }; -static PyTypeObject *UnaryOp_type; -_Py_IDENTIFIER(operand); -static char *UnaryOp_fields[]={ +static const char * const UnaryOp_fields[]={ "op", "operand", }; -static PyTypeObject *Lambda_type; -static char *Lambda_fields[]={ +static const char * const Lambda_fields[]={ "args", "body", }; -static PyTypeObject *IfExp_type; -static char *IfExp_fields[]={ +static const char * const IfExp_fields[]={ "test", "body", "orelse", }; -static PyTypeObject *Dict_type; -_Py_IDENTIFIER(keys); -static char *Dict_fields[]={ +static const char * const Dict_fields[]={ "keys", "values", }; -static PyTypeObject *Set_type; -_Py_IDENTIFIER(elts); -static char *Set_fields[]={ +static const char * const Set_fields[]={ "elts", }; -static PyTypeObject *ListComp_type; -_Py_IDENTIFIER(elt); -_Py_IDENTIFIER(generators); -static char *ListComp_fields[]={ +static const char * const ListComp_fields[]={ "elt", "generators", }; -static PyTypeObject *SetComp_type; -static char *SetComp_fields[]={ +static const char * const SetComp_fields[]={ "elt", "generators", }; -static PyTypeObject *DictComp_type; -_Py_IDENTIFIER(key); -static char *DictComp_fields[]={ +static const char * const DictComp_fields[]={ "key", "value", "generators", }; -static PyTypeObject *GeneratorExp_type; -static char *GeneratorExp_fields[]={ +static const char * const GeneratorExp_fields[]={ "elt", "generators", }; -static PyTypeObject *Await_type; -static char *Await_fields[]={ +static const char * const Await_fields[]={ "value", }; -static PyTypeObject *Yield_type; -static char *Yield_fields[]={ +static const char * const Yield_fields[]={ "value", }; -static PyTypeObject *YieldFrom_type; -static char *YieldFrom_fields[]={ +static const char * const YieldFrom_fields[]={ "value", }; -static PyTypeObject *Compare_type; -_Py_IDENTIFIER(ops); -_Py_IDENTIFIER(comparators); -static char *Compare_fields[]={ +static const char * const Compare_fields[]={ "left", "ops", "comparators", }; -static PyTypeObject *Call_type; -_Py_IDENTIFIER(func); -static char *Call_fields[]={ +static const char * const Call_fields[]={ "func", "args", "keywords", }; -static PyTypeObject *Num_type; -_Py_IDENTIFIER(n); -static char *Num_fields[]={ - "n", -}; -static PyTypeObject *Str_type; -_Py_IDENTIFIER(s); -_Py_IDENTIFIER(kind); -static char *Str_fields[]={ - "s", - "kind", -}; -static PyTypeObject *FormattedValue_type; -_Py_IDENTIFIER(conversion); -_Py_IDENTIFIER(format_spec); -static char *FormattedValue_fields[]={ +static const char * const FormattedValue_fields[]={ "value", "conversion", "format_spec", }; -static PyTypeObject *JoinedStr_type; -static char *JoinedStr_fields[]={ +static const char * const JoinedStr_fields[]={ "values", }; -static PyTypeObject *Bytes_type; -static char *Bytes_fields[]={ - "s", - "kind", -}; -static PyTypeObject *NameConstant_type; -static char *NameConstant_fields[]={ - "value", -}; -static PyTypeObject *Ellipsis_type; -static PyTypeObject *Constant_type; -static char *Constant_fields[]={ +static const char * const Constant_fields[]={ "value", + "kind", }; -static PyTypeObject *Attribute_type; -_Py_IDENTIFIER(attr); -_Py_IDENTIFIER(ctx); -static char *Attribute_fields[]={ +static const char * const Attribute_fields[]={ "value", "attr", "ctx", }; -static PyTypeObject *Subscript_type; -_Py_IDENTIFIER(slice); -static char *Subscript_fields[]={ +static const char * const Subscript_fields[]={ "value", "slice", "ctx", }; -static PyTypeObject *Starred_type; -static char *Starred_fields[]={ +static const char * const Starred_fields[]={ "value", "ctx", }; -static PyTypeObject *Name_type; -_Py_IDENTIFIER(id); -static char *Name_fields[]={ +static const char * const Name_fields[]={ "id", "ctx", }; -static PyTypeObject *List_type; -static char *List_fields[]={ +static const char * const List_fields[]={ "elts", "ctx", }; -static PyTypeObject *Tuple_type; -static char *Tuple_fields[]={ +static const char * const Tuple_fields[]={ "elts", "ctx", }; -static PyTypeObject *expr_context_type; -static PyObject *Load_singleton, *Store_singleton, *Del_singleton, -*AugLoad_singleton, *AugStore_singleton, *Param_singleton; -static PyObject* ast2obj_expr_context(expr_context_ty); -static PyTypeObject *Load_type; -static PyTypeObject *Store_type; -static PyTypeObject *Del_type; -static PyTypeObject *AugLoad_type; -static PyTypeObject *AugStore_type; -static PyTypeObject *Param_type; -static PyTypeObject *slice_type; -static PyObject* ast2obj_slice(void*); -static PyTypeObject *Slice_type; -_Py_IDENTIFIER(lower); -_Py_IDENTIFIER(upper); -_Py_IDENTIFIER(step); -static char *Slice_fields[]={ +static const char * const Slice_fields[]={ "lower", "upper", "step", }; -static PyTypeObject *ExtSlice_type; -_Py_IDENTIFIER(dims); -static char *ExtSlice_fields[]={ - "dims", -}; -static PyTypeObject *Index_type; -static char *Index_fields[]={ - "value", -}; -static PyTypeObject *boolop_type; -static PyObject *And_singleton, *Or_singleton; +static PyObject* ast2obj_expr_context(expr_context_ty); static PyObject* ast2obj_boolop(boolop_ty); -static PyTypeObject *And_type; -static PyTypeObject *Or_type; -static PyTypeObject *operator_type; -static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton, -*MatMult_singleton, *Div_singleton, *Mod_singleton, *Pow_singleton, -*LShift_singleton, *RShift_singleton, *BitOr_singleton, *BitXor_singleton, -*BitAnd_singleton, *FloorDiv_singleton; static PyObject* ast2obj_operator(operator_ty); -static PyTypeObject *Add_type; -static PyTypeObject *Sub_type; -static PyTypeObject *Mult_type; -static PyTypeObject *MatMult_type; -static PyTypeObject *Div_type; -static PyTypeObject *Mod_type; -static PyTypeObject *Pow_type; -static PyTypeObject *LShift_type; -static PyTypeObject *RShift_type; -static PyTypeObject *BitOr_type; -static PyTypeObject *BitXor_type; -static PyTypeObject *BitAnd_type; -static PyTypeObject *FloorDiv_type; -static PyTypeObject *unaryop_type; -static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton, -*USub_singleton; static PyObject* ast2obj_unaryop(unaryop_ty); -static PyTypeObject *Invert_type; -static PyTypeObject *Not_type; -static PyTypeObject *UAdd_type; -static PyTypeObject *USub_type; -static PyTypeObject *cmpop_type; -static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton, -*Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton, -*NotIn_singleton; static PyObject* ast2obj_cmpop(cmpop_ty); -static PyTypeObject *Eq_type; -static PyTypeObject *NotEq_type; -static PyTypeObject *Lt_type; -static PyTypeObject *LtE_type; -static PyTypeObject *Gt_type; -static PyTypeObject *GtE_type; -static PyTypeObject *Is_type; -static PyTypeObject *IsNot_type; -static PyTypeObject *In_type; -static PyTypeObject *NotIn_type; -static PyTypeObject *comprehension_type; static PyObject* ast2obj_comprehension(void*); -_Py_IDENTIFIER(ifs); -_Py_IDENTIFIER(is_async); -static char *comprehension_fields[]={ +static const char * const comprehension_fields[]={ "target", "iter", "ifs", "is_async", }; -static PyTypeObject *excepthandler_type; -static char *excepthandler_attributes[] = { +static const char * const excepthandler_attributes[] = { "lineno", "col_offset", + "end_lineno", + "end_col_offset", }; static PyObject* ast2obj_excepthandler(void*); -static PyTypeObject *ExceptHandler_type; -_Py_IDENTIFIER(type); -static char *ExceptHandler_fields[]={ +static const char * const ExceptHandler_fields[]={ "type", "name", "body", }; -static PyTypeObject *arguments_type; static PyObject* ast2obj_arguments(void*); -_Py_IDENTIFIER(vararg); -_Py_IDENTIFIER(kwonlyargs); -_Py_IDENTIFIER(kw_defaults); -_Py_IDENTIFIER(kwarg); -_Py_IDENTIFIER(defaults); -static char *arguments_fields[]={ +static const char * const arguments_fields[]={ + "posonlyargs", "args", "vararg", "kwonlyargs", @@ -489,51 +1047,46 @@ static char *arguments_fields[]={ "kwarg", "defaults", }; -static PyTypeObject *arg_type; static PyObject* ast2obj_arg(void*); -static char *arg_attributes[] = { +static const char * const arg_attributes[] = { "lineno", "col_offset", + "end_lineno", + "end_col_offset", }; -_Py_IDENTIFIER(arg); -static char *arg_fields[]={ +static const char * const arg_fields[]={ "arg", "annotation", "type_comment", }; -static PyTypeObject *keyword_type; static PyObject* ast2obj_keyword(void*); -static char *keyword_fields[]={ +static const char * const keyword_attributes[] = { + "lineno", + "col_offset", + "end_lineno", + "end_col_offset", +}; +static const char * const keyword_fields[]={ "arg", "value", }; -static PyTypeObject *alias_type; static PyObject* ast2obj_alias(void*); -_Py_IDENTIFIER(asname); -static char *alias_fields[]={ +static const char * const alias_fields[]={ "name", "asname", }; -static PyTypeObject *withitem_type; static PyObject* ast2obj_withitem(void*); -_Py_IDENTIFIER(context_expr); -_Py_IDENTIFIER(optional_vars); -static char *withitem_fields[]={ +static const char * const withitem_fields[]={ "context_expr", "optional_vars", }; -static PyTypeObject *type_ignore_type; static PyObject* ast2obj_type_ignore(void*); -static PyTypeObject *TypeIgnore_type; -_Py_IDENTIFIER(tag); -static char *TypeIgnore_fields[]={ +static const char * const TypeIgnore_fields[]={ "lineno", "tag", }; -_Py_IDENTIFIER(_fields); -_Py_IDENTIFIER(_attributes); typedef struct { PyObject_HEAD @@ -544,9 +1097,13 @@ static void ast_dealloc(AST_object *self) { /* bpo-31095: UnTrack is needed before calling any callbacks */ + PyTypeObject *tp = Py_TYPE(self); PyObject_GC_UnTrack(self); Py_CLEAR(self->dict); - Py_TYPE(self)->tp_free(self); + freefunc free_func = PyType_GetSlot(tp, Py_tp_free); + assert(free_func != NULL); + free_func(self); + Py_DECREF(tp); } static int @@ -563,30 +1120,13 @@ ast_clear(AST_object *self) return 0; } -static int lookup_attr_id(PyObject *v, _Py_Identifier *name, PyObject **result) -{ - PyObject *oname = _PyUnicode_FromId(name); /* borrowed */ - if (!oname) { - *result = NULL; - return -1; - } - *result = PyObject_GetAttr(v, oname); - if (*result == NULL) { - if (!PyErr_ExceptionMatches(PyExc_AttributeError)) { - return -1; - } - PyErr_Clear(); - } - return 0; -} - static int ast_type_init(PyObject *self, PyObject *args, PyObject *kw) { Py_ssize_t i, numfields = 0; int res = -1; PyObject *key, *value, *fields; - if (lookup_attr_id((PyObject*)Py_TYPE(self), &PyId__fields, &fields) < 0) { + if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), astmodulestate_global->_fields, &fields) < 0) { goto cleanup; } if (fields) { @@ -599,7 +1139,7 @@ ast_type_init(PyObject *self, PyObject *args, PyObject *kw) if (numfields < PyTuple_GET_SIZE(args)) { PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most " "%zd positional argument%s", - Py_TYPE(self)->tp_name, + _PyType_Name(Py_TYPE(self)), numfields, numfields == 1 ? "" : "s"); res = -1; goto cleanup; @@ -633,9 +1173,8 @@ ast_type_init(PyObject *self, PyObject *args, PyObject *kw) static PyObject * ast_type_reduce(PyObject *self, PyObject *unused) { - _Py_IDENTIFIER(__dict__); PyObject *dict; - if (lookup_attr_id(self, &PyId___dict__, &dict) < 0) { + if (_PyObject_LookupAttr(self, astmodulestate_global->__dict__, &dict) < 0) { return NULL; } if (dict) { @@ -644,6 +1183,11 @@ ast_type_reduce(PyObject *self, PyObject *unused) return Py_BuildValue("O()", Py_TYPE(self)); } +static PyMemberDef ast_type_members[] = { + {"__dictoffset__", T_PYSSIZET, offsetof(AST_object, dict), READONLY}, + {NULL} /* Sentinel */ +}; + static PyMethodDef ast_type_methods[] = { {"__reduce__", ast_type_reduce, METH_NOARGS, NULL}, {NULL} @@ -654,89 +1198,71 @@ static PyGetSetDef ast_type_getsets[] = { {NULL} }; -static PyTypeObject AST_type = { - PyVarObject_HEAD_INIT(NULL, 0) - "typed_ast._ast3.AST", +static PyType_Slot AST_type_slots[] = { + {Py_tp_dealloc, ast_dealloc}, + {Py_tp_getattro, PyObject_GenericGetAttr}, + {Py_tp_setattro, PyObject_GenericSetAttr}, + {Py_tp_traverse, ast_traverse}, + {Py_tp_clear, ast_clear}, + {Py_tp_members, ast_type_members}, + {Py_tp_methods, ast_type_methods}, + {Py_tp_getset, ast_type_getsets}, + {Py_tp_init, ast_type_init}, + {Py_tp_alloc, PyType_GenericAlloc}, + {Py_tp_new, PyType_GenericNew}, + {Py_tp_free, PyObject_GC_Del}, + {0, 0}, +}; + +static PyType_Spec AST_type_spec = { + "ast.AST", sizeof(AST_object), 0, - (destructor)ast_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - PyObject_GenericGetAttr, /* tp_getattro */ - PyObject_GenericSetAttr, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */ - 0, /* tp_doc */ - (traverseproc)ast_traverse, /* tp_traverse */ - (inquiry)ast_clear, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - ast_type_methods, /* tp_methods */ - 0, /* tp_members */ - ast_type_getsets, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - offsetof(AST_object, dict),/* tp_dictoffset */ - (initproc)ast_type_init, /* tp_init */ - PyType_GenericAlloc, /* tp_alloc */ - PyType_GenericNew, /* tp_new */ - PyObject_GC_Del, /* tp_free */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, + AST_type_slots }; - -static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields) +static PyObject * +make_type(const char *type, PyObject* base, const char* const* fields, int num_fields, const char *doc) { - _Py_IDENTIFIER(__module__); - _Py_static_string(PyId_typed_ast_ast3, "typed_ast._ast3"); PyObject *fnames, *result; int i; fnames = PyTuple_New(num_fields); if (!fnames) return NULL; for (i = 0; i < num_fields; i++) { - PyObject *field = PyUnicode_FromString(fields[i]); + PyObject *field = PyUnicode_InternFromString(fields[i]); if (!field) { Py_DECREF(fnames); return NULL; } PyTuple_SET_ITEM(fnames, i, field); } - result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOO}", + result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOOOs}", type, base, - _PyUnicode_FromId(&PyId__fields), fnames, - _PyUnicode_FromId(&PyId___module__), - _PyUnicode_FromId(&PyId_typed_ast_ast3)); + astmodulestate_global->_fields, fnames, + astmodulestate_global->__module__, + astmodulestate_global->ast, + astmodulestate_global->__doc__, doc); Py_DECREF(fnames); - return (PyTypeObject*)result; + return result; } -static int add_attributes(PyTypeObject* type, char**attrs, int num_fields) +static int +add_attributes(PyObject *type, const char * const *attrs, int num_fields) { int i, result; PyObject *s, *l = PyTuple_New(num_fields); if (!l) return 0; for (i = 0; i < num_fields; i++) { - s = PyUnicode_FromString(attrs[i]); + s = PyUnicode_InternFromString(attrs[i]); if (!s) { Py_DECREF(l); return 0; } PyTuple_SET_ITEM(l, i, s); } - result = _PyObject_SetAttrId((PyObject*)type, &PyId__attributes, l) >= 0; + result = PyObject_SetAttr(type, astmodulestate_global->_attributes, l) >= 0; Py_DECREF(l); return result; } @@ -768,11 +1294,9 @@ static PyObject* ast2obj_object(void *o) Py_INCREF((PyObject*)o); return (PyObject*)o; } -#define ast2obj_singleton ast2obj_object #define ast2obj_constant ast2obj_object #define ast2obj_identifier ast2obj_object #define ast2obj_string ast2obj_object -#define ast2obj_bytes ast2obj_object static PyObject* ast2obj_int(long b) { @@ -781,17 +1305,6 @@ static PyObject* ast2obj_int(long b) /* Conversion Python -> AST */ -static int obj2ast_singleton(PyObject *obj, PyObject** out, PyArena* arena) -{ - if (obj != Py_None && obj != Py_True && obj != Py_False) { - PyErr_SetString(PyExc_ValueError, - "AST singleton must be True, False, or None"); - return 1; - } - *out = obj; - return 0; -} - static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) { if (obj == Py_None) @@ -809,13 +1322,11 @@ static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena) { - if (obj) { - if (PyArena_AddPyObject(arena, obj) < 0) { - *out = NULL; - return -1; - } - Py_INCREF(obj); + if (PyArena_AddPyObject(arena, obj) < 0) { + *out = NULL; + return -1; } + Py_INCREF(obj); *out = obj; return 0; } @@ -838,15 +1349,6 @@ static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) return obj2ast_object(obj, out, arena); } -static int obj2ast_bytes(PyObject* obj, PyObject** out, PyArena* arena) -{ - if (!PyBytes_CheckExact(obj)) { - PyErr_SetString(PyExc_TypeError, "AST bytes must be of type bytes"); - return 1; - } - return obj2ast_object(obj, out, arena); -} - static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) { int i; @@ -864,14 +1366,11 @@ static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) static int add_ast_fields(void) { - PyObject *empty_tuple, *d; - if (PyType_Ready(&AST_type) < 0) - return -1; - d = AST_type.tp_dict; + PyObject *empty_tuple; empty_tuple = PyTuple_New(0); if (!empty_tuple || - _PyDict_SetItemId(d, &PyId__fields, empty_tuple) < 0 || - _PyDict_SetItemId(d, &PyId__attributes, empty_tuple) < 0) { + PyObject_SetAttrString(astmodulestate_global->AST_type, "_fields", empty_tuple) < 0 || + PyObject_SetAttrString(astmodulestate_global->AST_type, "_attributes", empty_tuple) < 0) { Py_XDECREF(empty_tuple); return -1; } @@ -882,342 +1381,645 @@ static int add_ast_fields(void) static int init_types(void) { - static int initialized; - if (initialized) return 1; + PyObject *m; + if (PyState_FindModule(&_astmodule) == NULL) { + m = PyModule_Create(&_astmodule); + if (!m) return 0; + PyState_AddModule(m, &_astmodule); + } + astmodulestate *state = astmodulestate_global; + if (state->initialized) return 1; + if (init_identifiers() < 0) return 0; + state->AST_type = PyType_FromSpec(&AST_type_spec); + if (!state->AST_type) return 0; if (add_ast_fields() < 0) return 0; - mod_type = make_type("mod", &AST_type, NULL, 0); - if (!mod_type) return 0; - if (!add_attributes(mod_type, NULL, 0)) return 0; - Module_type = make_type("Module", mod_type, Module_fields, 2); - if (!Module_type) return 0; - Interactive_type = make_type("Interactive", mod_type, Interactive_fields, - 1); - if (!Interactive_type) return 0; - Expression_type = make_type("Expression", mod_type, Expression_fields, 1); - if (!Expression_type) return 0; - FunctionType_type = make_type("FunctionType", mod_type, - FunctionType_fields, 2); - if (!FunctionType_type) return 0; - Suite_type = make_type("Suite", mod_type, Suite_fields, 1); - if (!Suite_type) return 0; - stmt_type = make_type("stmt", &AST_type, NULL, 0); - if (!stmt_type) return 0; - if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0; - FunctionDef_type = make_type("FunctionDef", stmt_type, FunctionDef_fields, - 6); - if (!FunctionDef_type) return 0; - AsyncFunctionDef_type = make_type("AsyncFunctionDef", stmt_type, - AsyncFunctionDef_fields, 6); - if (!AsyncFunctionDef_type) return 0; - ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 5); - if (!ClassDef_type) return 0; - Return_type = make_type("Return", stmt_type, Return_fields, 1); - if (!Return_type) return 0; - Delete_type = make_type("Delete", stmt_type, Delete_fields, 1); - if (!Delete_type) return 0; - Assign_type = make_type("Assign", stmt_type, Assign_fields, 3); - if (!Assign_type) return 0; - AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3); - if (!AugAssign_type) return 0; - AnnAssign_type = make_type("AnnAssign", stmt_type, AnnAssign_fields, 4); - if (!AnnAssign_type) return 0; - For_type = make_type("For", stmt_type, For_fields, 5); - if (!For_type) return 0; - AsyncFor_type = make_type("AsyncFor", stmt_type, AsyncFor_fields, 5); - if (!AsyncFor_type) return 0; - While_type = make_type("While", stmt_type, While_fields, 3); - if (!While_type) return 0; - If_type = make_type("If", stmt_type, If_fields, 3); - if (!If_type) return 0; - With_type = make_type("With", stmt_type, With_fields, 3); - if (!With_type) return 0; - AsyncWith_type = make_type("AsyncWith", stmt_type, AsyncWith_fields, 3); - if (!AsyncWith_type) return 0; - Raise_type = make_type("Raise", stmt_type, Raise_fields, 2); - if (!Raise_type) return 0; - Try_type = make_type("Try", stmt_type, Try_fields, 4); - if (!Try_type) return 0; - Assert_type = make_type("Assert", stmt_type, Assert_fields, 2); - if (!Assert_type) return 0; - Import_type = make_type("Import", stmt_type, Import_fields, 1); - if (!Import_type) return 0; - ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields, 3); - if (!ImportFrom_type) return 0; - Global_type = make_type("Global", stmt_type, Global_fields, 1); - if (!Global_type) return 0; - Nonlocal_type = make_type("Nonlocal", stmt_type, Nonlocal_fields, 1); - if (!Nonlocal_type) return 0; - Expr_type = make_type("Expr", stmt_type, Expr_fields, 1); - if (!Expr_type) return 0; - Pass_type = make_type("Pass", stmt_type, NULL, 0); - if (!Pass_type) return 0; - Break_type = make_type("Break", stmt_type, NULL, 0); - if (!Break_type) return 0; - Continue_type = make_type("Continue", stmt_type, NULL, 0); - if (!Continue_type) return 0; - expr_type = make_type("expr", &AST_type, NULL, 0); - if (!expr_type) return 0; - if (!add_attributes(expr_type, expr_attributes, 2)) return 0; - BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2); - if (!BoolOp_type) return 0; - BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3); - if (!BinOp_type) return 0; - UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2); - if (!UnaryOp_type) return 0; - Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2); - if (!Lambda_type) return 0; - IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3); - if (!IfExp_type) return 0; - Dict_type = make_type("Dict", expr_type, Dict_fields, 2); - if (!Dict_type) return 0; - Set_type = make_type("Set", expr_type, Set_fields, 1); - if (!Set_type) return 0; - ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2); - if (!ListComp_type) return 0; - SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2); - if (!SetComp_type) return 0; - DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3); - if (!DictComp_type) return 0; - GeneratorExp_type = make_type("GeneratorExp", expr_type, - GeneratorExp_fields, 2); - if (!GeneratorExp_type) return 0; - Await_type = make_type("Await", expr_type, Await_fields, 1); - if (!Await_type) return 0; - Yield_type = make_type("Yield", expr_type, Yield_fields, 1); - if (!Yield_type) return 0; - YieldFrom_type = make_type("YieldFrom", expr_type, YieldFrom_fields, 1); - if (!YieldFrom_type) return 0; - Compare_type = make_type("Compare", expr_type, Compare_fields, 3); - if (!Compare_type) return 0; - Call_type = make_type("Call", expr_type, Call_fields, 3); - if (!Call_type) return 0; - Num_type = make_type("Num", expr_type, Num_fields, 1); - if (!Num_type) return 0; - Str_type = make_type("Str", expr_type, Str_fields, 2); - if (!Str_type) return 0; - FormattedValue_type = make_type("FormattedValue", expr_type, - FormattedValue_fields, 3); - if (!FormattedValue_type) return 0; - JoinedStr_type = make_type("JoinedStr", expr_type, JoinedStr_fields, 1); - if (!JoinedStr_type) return 0; - Bytes_type = make_type("Bytes", expr_type, Bytes_fields, 2); - if (!Bytes_type) return 0; - NameConstant_type = make_type("NameConstant", expr_type, - NameConstant_fields, 1); - if (!NameConstant_type) return 0; - Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0); - if (!Ellipsis_type) return 0; - Constant_type = make_type("Constant", expr_type, Constant_fields, 1); - if (!Constant_type) return 0; - Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3); - if (!Attribute_type) return 0; - Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3); - if (!Subscript_type) return 0; - Starred_type = make_type("Starred", expr_type, Starred_fields, 2); - if (!Starred_type) return 0; - Name_type = make_type("Name", expr_type, Name_fields, 2); - if (!Name_type) return 0; - List_type = make_type("List", expr_type, List_fields, 2); - if (!List_type) return 0; - Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2); - if (!Tuple_type) return 0; - expr_context_type = make_type("expr_context", &AST_type, NULL, 0); - if (!expr_context_type) return 0; - if (!add_attributes(expr_context_type, NULL, 0)) return 0; - Load_type = make_type("Load", expr_context_type, NULL, 0); - if (!Load_type) return 0; - Load_singleton = PyType_GenericNew(Load_type, NULL, NULL); - if (!Load_singleton) return 0; - Store_type = make_type("Store", expr_context_type, NULL, 0); - if (!Store_type) return 0; - Store_singleton = PyType_GenericNew(Store_type, NULL, NULL); - if (!Store_singleton) return 0; - Del_type = make_type("Del", expr_context_type, NULL, 0); - if (!Del_type) return 0; - Del_singleton = PyType_GenericNew(Del_type, NULL, NULL); - if (!Del_singleton) return 0; - AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0); - if (!AugLoad_type) return 0; - AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL); - if (!AugLoad_singleton) return 0; - AugStore_type = make_type("AugStore", expr_context_type, NULL, 0); - if (!AugStore_type) return 0; - AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL); - if (!AugStore_singleton) return 0; - Param_type = make_type("Param", expr_context_type, NULL, 0); - if (!Param_type) return 0; - Param_singleton = PyType_GenericNew(Param_type, NULL, NULL); - if (!Param_singleton) return 0; - slice_type = make_type("slice", &AST_type, NULL, 0); - if (!slice_type) return 0; - if (!add_attributes(slice_type, NULL, 0)) return 0; - Slice_type = make_type("Slice", slice_type, Slice_fields, 3); - if (!Slice_type) return 0; - ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1); - if (!ExtSlice_type) return 0; - Index_type = make_type("Index", slice_type, Index_fields, 1); - if (!Index_type) return 0; - boolop_type = make_type("boolop", &AST_type, NULL, 0); - if (!boolop_type) return 0; - if (!add_attributes(boolop_type, NULL, 0)) return 0; - And_type = make_type("And", boolop_type, NULL, 0); - if (!And_type) return 0; - And_singleton = PyType_GenericNew(And_type, NULL, NULL); - if (!And_singleton) return 0; - Or_type = make_type("Or", boolop_type, NULL, 0); - if (!Or_type) return 0; - Or_singleton = PyType_GenericNew(Or_type, NULL, NULL); - if (!Or_singleton) return 0; - operator_type = make_type("operator", &AST_type, NULL, 0); - if (!operator_type) return 0; - if (!add_attributes(operator_type, NULL, 0)) return 0; - Add_type = make_type("Add", operator_type, NULL, 0); - if (!Add_type) return 0; - Add_singleton = PyType_GenericNew(Add_type, NULL, NULL); - if (!Add_singleton) return 0; - Sub_type = make_type("Sub", operator_type, NULL, 0); - if (!Sub_type) return 0; - Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL); - if (!Sub_singleton) return 0; - Mult_type = make_type("Mult", operator_type, NULL, 0); - if (!Mult_type) return 0; - Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL); - if (!Mult_singleton) return 0; - MatMult_type = make_type("MatMult", operator_type, NULL, 0); - if (!MatMult_type) return 0; - MatMult_singleton = PyType_GenericNew(MatMult_type, NULL, NULL); - if (!MatMult_singleton) return 0; - Div_type = make_type("Div", operator_type, NULL, 0); - if (!Div_type) return 0; - Div_singleton = PyType_GenericNew(Div_type, NULL, NULL); - if (!Div_singleton) return 0; - Mod_type = make_type("Mod", operator_type, NULL, 0); - if (!Mod_type) return 0; - Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL); - if (!Mod_singleton) return 0; - Pow_type = make_type("Pow", operator_type, NULL, 0); - if (!Pow_type) return 0; - Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL); - if (!Pow_singleton) return 0; - LShift_type = make_type("LShift", operator_type, NULL, 0); - if (!LShift_type) return 0; - LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL); - if (!LShift_singleton) return 0; - RShift_type = make_type("RShift", operator_type, NULL, 0); - if (!RShift_type) return 0; - RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL); - if (!RShift_singleton) return 0; - BitOr_type = make_type("BitOr", operator_type, NULL, 0); - if (!BitOr_type) return 0; - BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL); - if (!BitOr_singleton) return 0; - BitXor_type = make_type("BitXor", operator_type, NULL, 0); - if (!BitXor_type) return 0; - BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL); - if (!BitXor_singleton) return 0; - BitAnd_type = make_type("BitAnd", operator_type, NULL, 0); - if (!BitAnd_type) return 0; - BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL); - if (!BitAnd_singleton) return 0; - FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0); - if (!FloorDiv_type) return 0; - FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL); - if (!FloorDiv_singleton) return 0; - unaryop_type = make_type("unaryop", &AST_type, NULL, 0); - if (!unaryop_type) return 0; - if (!add_attributes(unaryop_type, NULL, 0)) return 0; - Invert_type = make_type("Invert", unaryop_type, NULL, 0); - if (!Invert_type) return 0; - Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL); - if (!Invert_singleton) return 0; - Not_type = make_type("Not", unaryop_type, NULL, 0); - if (!Not_type) return 0; - Not_singleton = PyType_GenericNew(Not_type, NULL, NULL); - if (!Not_singleton) return 0; - UAdd_type = make_type("UAdd", unaryop_type, NULL, 0); - if (!UAdd_type) return 0; - UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL); - if (!UAdd_singleton) return 0; - USub_type = make_type("USub", unaryop_type, NULL, 0); - if (!USub_type) return 0; - USub_singleton = PyType_GenericNew(USub_type, NULL, NULL); - if (!USub_singleton) return 0; - cmpop_type = make_type("cmpop", &AST_type, NULL, 0); - if (!cmpop_type) return 0; - if (!add_attributes(cmpop_type, NULL, 0)) return 0; - Eq_type = make_type("Eq", cmpop_type, NULL, 0); - if (!Eq_type) return 0; - Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL); - if (!Eq_singleton) return 0; - NotEq_type = make_type("NotEq", cmpop_type, NULL, 0); - if (!NotEq_type) return 0; - NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL); - if (!NotEq_singleton) return 0; - Lt_type = make_type("Lt", cmpop_type, NULL, 0); - if (!Lt_type) return 0; - Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL); - if (!Lt_singleton) return 0; - LtE_type = make_type("LtE", cmpop_type, NULL, 0); - if (!LtE_type) return 0; - LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL); - if (!LtE_singleton) return 0; - Gt_type = make_type("Gt", cmpop_type, NULL, 0); - if (!Gt_type) return 0; - Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL); - if (!Gt_singleton) return 0; - GtE_type = make_type("GtE", cmpop_type, NULL, 0); - if (!GtE_type) return 0; - GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL); - if (!GtE_singleton) return 0; - Is_type = make_type("Is", cmpop_type, NULL, 0); - if (!Is_type) return 0; - Is_singleton = PyType_GenericNew(Is_type, NULL, NULL); - if (!Is_singleton) return 0; - IsNot_type = make_type("IsNot", cmpop_type, NULL, 0); - if (!IsNot_type) return 0; - IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL); - if (!IsNot_singleton) return 0; - In_type = make_type("In", cmpop_type, NULL, 0); - if (!In_type) return 0; - In_singleton = PyType_GenericNew(In_type, NULL, NULL); - if (!In_singleton) return 0; - NotIn_type = make_type("NotIn", cmpop_type, NULL, 0); - if (!NotIn_type) return 0; - NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL); - if (!NotIn_singleton) return 0; - comprehension_type = make_type("comprehension", &AST_type, - comprehension_fields, 4); - if (!comprehension_type) return 0; - if (!add_attributes(comprehension_type, NULL, 0)) return 0; - excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0); - if (!excepthandler_type) return 0; - if (!add_attributes(excepthandler_type, excepthandler_attributes, 2)) - return 0; - ExceptHandler_type = make_type("ExceptHandler", excepthandler_type, - ExceptHandler_fields, 3); - if (!ExceptHandler_type) return 0; - arguments_type = make_type("arguments", &AST_type, arguments_fields, 6); - if (!arguments_type) return 0; - if (!add_attributes(arguments_type, NULL, 0)) return 0; - arg_type = make_type("arg", &AST_type, arg_fields, 3); - if (!arg_type) return 0; - if (!add_attributes(arg_type, arg_attributes, 2)) return 0; - keyword_type = make_type("keyword", &AST_type, keyword_fields, 2); - if (!keyword_type) return 0; - if (!add_attributes(keyword_type, NULL, 0)) return 0; - alias_type = make_type("alias", &AST_type, alias_fields, 2); - if (!alias_type) return 0; - if (!add_attributes(alias_type, NULL, 0)) return 0; - withitem_type = make_type("withitem", &AST_type, withitem_fields, 2); - if (!withitem_type) return 0; - if (!add_attributes(withitem_type, NULL, 0)) return 0; - type_ignore_type = make_type("type_ignore", &AST_type, NULL, 0); - if (!type_ignore_type) return 0; - if (!add_attributes(type_ignore_type, NULL, 0)) return 0; - TypeIgnore_type = make_type("TypeIgnore", type_ignore_type, - TypeIgnore_fields, 2); - if (!TypeIgnore_type) return 0; - initialized = 1; + state->mod_type = make_type("mod", state->AST_type, NULL, 0, + "mod = Module(stmt* body, type_ignore* type_ignores)\n" + " | Interactive(stmt* body)\n" + " | Expression(expr body)\n" + " | FunctionType(expr* argtypes, expr returns)"); + if (!state->mod_type) return 0; + if (!add_attributes(state->mod_type, NULL, 0)) return 0; + state->Module_type = make_type("Module", state->mod_type, Module_fields, 2, + "Module(stmt* body, type_ignore* type_ignores)"); + if (!state->Module_type) return 0; + state->Interactive_type = make_type("Interactive", state->mod_type, + Interactive_fields, 1, + "Interactive(stmt* body)"); + if (!state->Interactive_type) return 0; + state->Expression_type = make_type("Expression", state->mod_type, + Expression_fields, 1, + "Expression(expr body)"); + if (!state->Expression_type) return 0; + state->FunctionType_type = make_type("FunctionType", state->mod_type, + FunctionType_fields, 2, + "FunctionType(expr* argtypes, expr returns)"); + if (!state->FunctionType_type) return 0; + state->stmt_type = make_type("stmt", state->AST_type, NULL, 0, + "stmt = FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)\n" + " | AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)\n" + " | ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)\n" + " | Return(expr? value)\n" + " | Delete(expr* targets)\n" + " | Assign(expr* targets, expr value, string? type_comment)\n" + " | AugAssign(expr target, operator op, expr value)\n" + " | AnnAssign(expr target, expr annotation, expr? value, int simple)\n" + " | For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n" + " | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n" + " | While(expr test, stmt* body, stmt* orelse)\n" + " | If(expr test, stmt* body, stmt* orelse)\n" + " | With(withitem* items, stmt* body, string? type_comment)\n" + " | AsyncWith(withitem* items, stmt* body, string? type_comment)\n" + " | Raise(expr? exc, expr? cause)\n" + " | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)\n" + " | Assert(expr test, expr? msg)\n" + " | Import(alias* names)\n" + " | ImportFrom(identifier? module, alias* names, int? level)\n" + " | Global(identifier* names)\n" + " | Nonlocal(identifier* names)\n" + " | Expr(expr value)\n" + " | Pass\n" + " | Break\n" + " | Continue"); + if (!state->stmt_type) return 0; + if (!add_attributes(state->stmt_type, stmt_attributes, 4)) return 0; + if (PyObject_SetAttr(state->stmt_type, state->end_lineno, Py_None) == -1) + return 0; + if (PyObject_SetAttr(state->stmt_type, state->end_col_offset, Py_None) == + -1) + return 0; + state->FunctionDef_type = make_type("FunctionDef", state->stmt_type, + FunctionDef_fields, 6, + "FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)"); + if (!state->FunctionDef_type) return 0; + if (PyObject_SetAttr(state->FunctionDef_type, state->returns, Py_None) == + -1) + return 0; + if (PyObject_SetAttr(state->FunctionDef_type, state->type_comment, Py_None) + == -1) + return 0; + state->AsyncFunctionDef_type = make_type("AsyncFunctionDef", + state->stmt_type, + AsyncFunctionDef_fields, 6, + "AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)"); + if (!state->AsyncFunctionDef_type) return 0; + if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->returns, Py_None) + == -1) + return 0; + if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->type_comment, + Py_None) == -1) + return 0; + state->ClassDef_type = make_type("ClassDef", state->stmt_type, + ClassDef_fields, 5, + "ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)"); + if (!state->ClassDef_type) return 0; + state->Return_type = make_type("Return", state->stmt_type, Return_fields, 1, + "Return(expr? value)"); + if (!state->Return_type) return 0; + if (PyObject_SetAttr(state->Return_type, state->value, Py_None) == -1) + return 0; + state->Delete_type = make_type("Delete", state->stmt_type, Delete_fields, 1, + "Delete(expr* targets)"); + if (!state->Delete_type) return 0; + state->Assign_type = make_type("Assign", state->stmt_type, Assign_fields, 3, + "Assign(expr* targets, expr value, string? type_comment)"); + if (!state->Assign_type) return 0; + if (PyObject_SetAttr(state->Assign_type, state->type_comment, Py_None) == + -1) + return 0; + state->AugAssign_type = make_type("AugAssign", state->stmt_type, + AugAssign_fields, 3, + "AugAssign(expr target, operator op, expr value)"); + if (!state->AugAssign_type) return 0; + state->AnnAssign_type = make_type("AnnAssign", state->stmt_type, + AnnAssign_fields, 4, + "AnnAssign(expr target, expr annotation, expr? value, int simple)"); + if (!state->AnnAssign_type) return 0; + if (PyObject_SetAttr(state->AnnAssign_type, state->value, Py_None) == -1) + return 0; + state->For_type = make_type("For", state->stmt_type, For_fields, 5, + "For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)"); + if (!state->For_type) return 0; + if (PyObject_SetAttr(state->For_type, state->type_comment, Py_None) == -1) + return 0; + state->AsyncFor_type = make_type("AsyncFor", state->stmt_type, + AsyncFor_fields, 5, + "AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)"); + if (!state->AsyncFor_type) return 0; + if (PyObject_SetAttr(state->AsyncFor_type, state->type_comment, Py_None) == + -1) + return 0; + state->While_type = make_type("While", state->stmt_type, While_fields, 3, + "While(expr test, stmt* body, stmt* orelse)"); + if (!state->While_type) return 0; + state->If_type = make_type("If", state->stmt_type, If_fields, 3, + "If(expr test, stmt* body, stmt* orelse)"); + if (!state->If_type) return 0; + state->With_type = make_type("With", state->stmt_type, With_fields, 3, + "With(withitem* items, stmt* body, string? type_comment)"); + if (!state->With_type) return 0; + if (PyObject_SetAttr(state->With_type, state->type_comment, Py_None) == -1) + return 0; + state->AsyncWith_type = make_type("AsyncWith", state->stmt_type, + AsyncWith_fields, 3, + "AsyncWith(withitem* items, stmt* body, string? type_comment)"); + if (!state->AsyncWith_type) return 0; + if (PyObject_SetAttr(state->AsyncWith_type, state->type_comment, Py_None) + == -1) + return 0; + state->Raise_type = make_type("Raise", state->stmt_type, Raise_fields, 2, + "Raise(expr? exc, expr? cause)"); + if (!state->Raise_type) return 0; + if (PyObject_SetAttr(state->Raise_type, state->exc, Py_None) == -1) + return 0; + if (PyObject_SetAttr(state->Raise_type, state->cause, Py_None) == -1) + return 0; + state->Try_type = make_type("Try", state->stmt_type, Try_fields, 4, + "Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)"); + if (!state->Try_type) return 0; + state->Assert_type = make_type("Assert", state->stmt_type, Assert_fields, 2, + "Assert(expr test, expr? msg)"); + if (!state->Assert_type) return 0; + if (PyObject_SetAttr(state->Assert_type, state->msg, Py_None) == -1) + return 0; + state->Import_type = make_type("Import", state->stmt_type, Import_fields, 1, + "Import(alias* names)"); + if (!state->Import_type) return 0; + state->ImportFrom_type = make_type("ImportFrom", state->stmt_type, + ImportFrom_fields, 3, + "ImportFrom(identifier? module, alias* names, int? level)"); + if (!state->ImportFrom_type) return 0; + if (PyObject_SetAttr(state->ImportFrom_type, state->module, Py_None) == -1) + return 0; + if (PyObject_SetAttr(state->ImportFrom_type, state->level, Py_None) == -1) + return 0; + state->Global_type = make_type("Global", state->stmt_type, Global_fields, 1, + "Global(identifier* names)"); + if (!state->Global_type) return 0; + state->Nonlocal_type = make_type("Nonlocal", state->stmt_type, + Nonlocal_fields, 1, + "Nonlocal(identifier* names)"); + if (!state->Nonlocal_type) return 0; + state->Expr_type = make_type("Expr", state->stmt_type, Expr_fields, 1, + "Expr(expr value)"); + if (!state->Expr_type) return 0; + state->Pass_type = make_type("Pass", state->stmt_type, NULL, 0, + "Pass"); + if (!state->Pass_type) return 0; + state->Break_type = make_type("Break", state->stmt_type, NULL, 0, + "Break"); + if (!state->Break_type) return 0; + state->Continue_type = make_type("Continue", state->stmt_type, NULL, 0, + "Continue"); + if (!state->Continue_type) return 0; + state->expr_type = make_type("expr", state->AST_type, NULL, 0, + "expr = BoolOp(boolop op, expr* values)\n" + " | NamedExpr(expr target, expr value)\n" + " | BinOp(expr left, operator op, expr right)\n" + " | UnaryOp(unaryop op, expr operand)\n" + " | Lambda(arguments args, expr body)\n" + " | IfExp(expr test, expr body, expr orelse)\n" + " | Dict(expr* keys, expr* values)\n" + " | Set(expr* elts)\n" + " | ListComp(expr elt, comprehension* generators)\n" + " | SetComp(expr elt, comprehension* generators)\n" + " | DictComp(expr key, expr value, comprehension* generators)\n" + " | GeneratorExp(expr elt, comprehension* generators)\n" + " | Await(expr value)\n" + " | Yield(expr? value)\n" + " | YieldFrom(expr value)\n" + " | Compare(expr left, cmpop* ops, expr* comparators)\n" + " | Call(expr func, expr* args, keyword* keywords)\n" + " | FormattedValue(expr value, int? conversion, expr? format_spec)\n" + " | JoinedStr(expr* values)\n" + " | Constant(constant value, string? kind)\n" + " | Attribute(expr value, identifier attr, expr_context ctx)\n" + " | Subscript(expr value, expr slice, expr_context ctx)\n" + " | Starred(expr value, expr_context ctx)\n" + " | Name(identifier id, expr_context ctx)\n" + " | List(expr* elts, expr_context ctx)\n" + " | Tuple(expr* elts, expr_context ctx)\n" + " | Slice(expr? lower, expr? upper, expr? step)"); + if (!state->expr_type) return 0; + if (!add_attributes(state->expr_type, expr_attributes, 4)) return 0; + if (PyObject_SetAttr(state->expr_type, state->end_lineno, Py_None) == -1) + return 0; + if (PyObject_SetAttr(state->expr_type, state->end_col_offset, Py_None) == + -1) + return 0; + state->BoolOp_type = make_type("BoolOp", state->expr_type, BoolOp_fields, 2, + "BoolOp(boolop op, expr* values)"); + if (!state->BoolOp_type) return 0; + state->NamedExpr_type = make_type("NamedExpr", state->expr_type, + NamedExpr_fields, 2, + "NamedExpr(expr target, expr value)"); + if (!state->NamedExpr_type) return 0; + state->BinOp_type = make_type("BinOp", state->expr_type, BinOp_fields, 3, + "BinOp(expr left, operator op, expr right)"); + if (!state->BinOp_type) return 0; + state->UnaryOp_type = make_type("UnaryOp", state->expr_type, + UnaryOp_fields, 2, + "UnaryOp(unaryop op, expr operand)"); + if (!state->UnaryOp_type) return 0; + state->Lambda_type = make_type("Lambda", state->expr_type, Lambda_fields, 2, + "Lambda(arguments args, expr body)"); + if (!state->Lambda_type) return 0; + state->IfExp_type = make_type("IfExp", state->expr_type, IfExp_fields, 3, + "IfExp(expr test, expr body, expr orelse)"); + if (!state->IfExp_type) return 0; + state->Dict_type = make_type("Dict", state->expr_type, Dict_fields, 2, + "Dict(expr* keys, expr* values)"); + if (!state->Dict_type) return 0; + state->Set_type = make_type("Set", state->expr_type, Set_fields, 1, + "Set(expr* elts)"); + if (!state->Set_type) return 0; + state->ListComp_type = make_type("ListComp", state->expr_type, + ListComp_fields, 2, + "ListComp(expr elt, comprehension* generators)"); + if (!state->ListComp_type) return 0; + state->SetComp_type = make_type("SetComp", state->expr_type, + SetComp_fields, 2, + "SetComp(expr elt, comprehension* generators)"); + if (!state->SetComp_type) return 0; + state->DictComp_type = make_type("DictComp", state->expr_type, + DictComp_fields, 3, + "DictComp(expr key, expr value, comprehension* generators)"); + if (!state->DictComp_type) return 0; + state->GeneratorExp_type = make_type("GeneratorExp", state->expr_type, + GeneratorExp_fields, 2, + "GeneratorExp(expr elt, comprehension* generators)"); + if (!state->GeneratorExp_type) return 0; + state->Await_type = make_type("Await", state->expr_type, Await_fields, 1, + "Await(expr value)"); + if (!state->Await_type) return 0; + state->Yield_type = make_type("Yield", state->expr_type, Yield_fields, 1, + "Yield(expr? value)"); + if (!state->Yield_type) return 0; + if (PyObject_SetAttr(state->Yield_type, state->value, Py_None) == -1) + return 0; + state->YieldFrom_type = make_type("YieldFrom", state->expr_type, + YieldFrom_fields, 1, + "YieldFrom(expr value)"); + if (!state->YieldFrom_type) return 0; + state->Compare_type = make_type("Compare", state->expr_type, + Compare_fields, 3, + "Compare(expr left, cmpop* ops, expr* comparators)"); + if (!state->Compare_type) return 0; + state->Call_type = make_type("Call", state->expr_type, Call_fields, 3, + "Call(expr func, expr* args, keyword* keywords)"); + if (!state->Call_type) return 0; + state->FormattedValue_type = make_type("FormattedValue", state->expr_type, + FormattedValue_fields, 3, + "FormattedValue(expr value, int? conversion, expr? format_spec)"); + if (!state->FormattedValue_type) return 0; + if (PyObject_SetAttr(state->FormattedValue_type, state->conversion, + Py_None) == -1) + return 0; + if (PyObject_SetAttr(state->FormattedValue_type, state->format_spec, + Py_None) == -1) + return 0; + state->JoinedStr_type = make_type("JoinedStr", state->expr_type, + JoinedStr_fields, 1, + "JoinedStr(expr* values)"); + if (!state->JoinedStr_type) return 0; + state->Constant_type = make_type("Constant", state->expr_type, + Constant_fields, 2, + "Constant(constant value, string? kind)"); + if (!state->Constant_type) return 0; + if (PyObject_SetAttr(state->Constant_type, state->kind, Py_None) == -1) + return 0; + state->Attribute_type = make_type("Attribute", state->expr_type, + Attribute_fields, 3, + "Attribute(expr value, identifier attr, expr_context ctx)"); + if (!state->Attribute_type) return 0; + state->Subscript_type = make_type("Subscript", state->expr_type, + Subscript_fields, 3, + "Subscript(expr value, expr slice, expr_context ctx)"); + if (!state->Subscript_type) return 0; + state->Starred_type = make_type("Starred", state->expr_type, + Starred_fields, 2, + "Starred(expr value, expr_context ctx)"); + if (!state->Starred_type) return 0; + state->Name_type = make_type("Name", state->expr_type, Name_fields, 2, + "Name(identifier id, expr_context ctx)"); + if (!state->Name_type) return 0; + state->List_type = make_type("List", state->expr_type, List_fields, 2, + "List(expr* elts, expr_context ctx)"); + if (!state->List_type) return 0; + state->Tuple_type = make_type("Tuple", state->expr_type, Tuple_fields, 2, + "Tuple(expr* elts, expr_context ctx)"); + if (!state->Tuple_type) return 0; + state->Slice_type = make_type("Slice", state->expr_type, Slice_fields, 3, + "Slice(expr? lower, expr? upper, expr? step)"); + if (!state->Slice_type) return 0; + if (PyObject_SetAttr(state->Slice_type, state->lower, Py_None) == -1) + return 0; + if (PyObject_SetAttr(state->Slice_type, state->upper, Py_None) == -1) + return 0; + if (PyObject_SetAttr(state->Slice_type, state->step, Py_None) == -1) + return 0; + state->expr_context_type = make_type("expr_context", state->AST_type, NULL, + 0, + "expr_context = Load | Store | Del"); + if (!state->expr_context_type) return 0; + if (!add_attributes(state->expr_context_type, NULL, 0)) return 0; + state->Load_type = make_type("Load", state->expr_context_type, NULL, 0, + "Load"); + if (!state->Load_type) return 0; + state->Load_singleton = PyType_GenericNew((PyTypeObject *)state->Load_type, + NULL, NULL); + if (!state->Load_singleton) return 0; + state->Store_type = make_type("Store", state->expr_context_type, NULL, 0, + "Store"); + if (!state->Store_type) return 0; + state->Store_singleton = PyType_GenericNew((PyTypeObject + *)state->Store_type, NULL, NULL); + if (!state->Store_singleton) return 0; + state->Del_type = make_type("Del", state->expr_context_type, NULL, 0, + "Del"); + if (!state->Del_type) return 0; + state->Del_singleton = PyType_GenericNew((PyTypeObject *)state->Del_type, + NULL, NULL); + if (!state->Del_singleton) return 0; + state->boolop_type = make_type("boolop", state->AST_type, NULL, 0, + "boolop = And | Or"); + if (!state->boolop_type) return 0; + if (!add_attributes(state->boolop_type, NULL, 0)) return 0; + state->And_type = make_type("And", state->boolop_type, NULL, 0, + "And"); + if (!state->And_type) return 0; + state->And_singleton = PyType_GenericNew((PyTypeObject *)state->And_type, + NULL, NULL); + if (!state->And_singleton) return 0; + state->Or_type = make_type("Or", state->boolop_type, NULL, 0, + "Or"); + if (!state->Or_type) return 0; + state->Or_singleton = PyType_GenericNew((PyTypeObject *)state->Or_type, + NULL, NULL); + if (!state->Or_singleton) return 0; + state->operator_type = make_type("operator", state->AST_type, NULL, 0, + "operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift | RShift | BitOr | BitXor | BitAnd | FloorDiv"); + if (!state->operator_type) return 0; + if (!add_attributes(state->operator_type, NULL, 0)) return 0; + state->Add_type = make_type("Add", state->operator_type, NULL, 0, + "Add"); + if (!state->Add_type) return 0; + state->Add_singleton = PyType_GenericNew((PyTypeObject *)state->Add_type, + NULL, NULL); + if (!state->Add_singleton) return 0; + state->Sub_type = make_type("Sub", state->operator_type, NULL, 0, + "Sub"); + if (!state->Sub_type) return 0; + state->Sub_singleton = PyType_GenericNew((PyTypeObject *)state->Sub_type, + NULL, NULL); + if (!state->Sub_singleton) return 0; + state->Mult_type = make_type("Mult", state->operator_type, NULL, 0, + "Mult"); + if (!state->Mult_type) return 0; + state->Mult_singleton = PyType_GenericNew((PyTypeObject *)state->Mult_type, + NULL, NULL); + if (!state->Mult_singleton) return 0; + state->MatMult_type = make_type("MatMult", state->operator_type, NULL, 0, + "MatMult"); + if (!state->MatMult_type) return 0; + state->MatMult_singleton = PyType_GenericNew((PyTypeObject + *)state->MatMult_type, NULL, + NULL); + if (!state->MatMult_singleton) return 0; + state->Div_type = make_type("Div", state->operator_type, NULL, 0, + "Div"); + if (!state->Div_type) return 0; + state->Div_singleton = PyType_GenericNew((PyTypeObject *)state->Div_type, + NULL, NULL); + if (!state->Div_singleton) return 0; + state->Mod_type = make_type("Mod", state->operator_type, NULL, 0, + "Mod"); + if (!state->Mod_type) return 0; + state->Mod_singleton = PyType_GenericNew((PyTypeObject *)state->Mod_type, + NULL, NULL); + if (!state->Mod_singleton) return 0; + state->Pow_type = make_type("Pow", state->operator_type, NULL, 0, + "Pow"); + if (!state->Pow_type) return 0; + state->Pow_singleton = PyType_GenericNew((PyTypeObject *)state->Pow_type, + NULL, NULL); + if (!state->Pow_singleton) return 0; + state->LShift_type = make_type("LShift", state->operator_type, NULL, 0, + "LShift"); + if (!state->LShift_type) return 0; + state->LShift_singleton = PyType_GenericNew((PyTypeObject + *)state->LShift_type, NULL, + NULL); + if (!state->LShift_singleton) return 0; + state->RShift_type = make_type("RShift", state->operator_type, NULL, 0, + "RShift"); + if (!state->RShift_type) return 0; + state->RShift_singleton = PyType_GenericNew((PyTypeObject + *)state->RShift_type, NULL, + NULL); + if (!state->RShift_singleton) return 0; + state->BitOr_type = make_type("BitOr", state->operator_type, NULL, 0, + "BitOr"); + if (!state->BitOr_type) return 0; + state->BitOr_singleton = PyType_GenericNew((PyTypeObject + *)state->BitOr_type, NULL, NULL); + if (!state->BitOr_singleton) return 0; + state->BitXor_type = make_type("BitXor", state->operator_type, NULL, 0, + "BitXor"); + if (!state->BitXor_type) return 0; + state->BitXor_singleton = PyType_GenericNew((PyTypeObject + *)state->BitXor_type, NULL, + NULL); + if (!state->BitXor_singleton) return 0; + state->BitAnd_type = make_type("BitAnd", state->operator_type, NULL, 0, + "BitAnd"); + if (!state->BitAnd_type) return 0; + state->BitAnd_singleton = PyType_GenericNew((PyTypeObject + *)state->BitAnd_type, NULL, + NULL); + if (!state->BitAnd_singleton) return 0; + state->FloorDiv_type = make_type("FloorDiv", state->operator_type, NULL, 0, + "FloorDiv"); + if (!state->FloorDiv_type) return 0; + state->FloorDiv_singleton = PyType_GenericNew((PyTypeObject + *)state->FloorDiv_type, NULL, + NULL); + if (!state->FloorDiv_singleton) return 0; + state->unaryop_type = make_type("unaryop", state->AST_type, NULL, 0, + "unaryop = Invert | Not | UAdd | USub"); + if (!state->unaryop_type) return 0; + if (!add_attributes(state->unaryop_type, NULL, 0)) return 0; + state->Invert_type = make_type("Invert", state->unaryop_type, NULL, 0, + "Invert"); + if (!state->Invert_type) return 0; + state->Invert_singleton = PyType_GenericNew((PyTypeObject + *)state->Invert_type, NULL, + NULL); + if (!state->Invert_singleton) return 0; + state->Not_type = make_type("Not", state->unaryop_type, NULL, 0, + "Not"); + if (!state->Not_type) return 0; + state->Not_singleton = PyType_GenericNew((PyTypeObject *)state->Not_type, + NULL, NULL); + if (!state->Not_singleton) return 0; + state->UAdd_type = make_type("UAdd", state->unaryop_type, NULL, 0, + "UAdd"); + if (!state->UAdd_type) return 0; + state->UAdd_singleton = PyType_GenericNew((PyTypeObject *)state->UAdd_type, + NULL, NULL); + if (!state->UAdd_singleton) return 0; + state->USub_type = make_type("USub", state->unaryop_type, NULL, 0, + "USub"); + if (!state->USub_type) return 0; + state->USub_singleton = PyType_GenericNew((PyTypeObject *)state->USub_type, + NULL, NULL); + if (!state->USub_singleton) return 0; + state->cmpop_type = make_type("cmpop", state->AST_type, NULL, 0, + "cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn"); + if (!state->cmpop_type) return 0; + if (!add_attributes(state->cmpop_type, NULL, 0)) return 0; + state->Eq_type = make_type("Eq", state->cmpop_type, NULL, 0, + "Eq"); + if (!state->Eq_type) return 0; + state->Eq_singleton = PyType_GenericNew((PyTypeObject *)state->Eq_type, + NULL, NULL); + if (!state->Eq_singleton) return 0; + state->NotEq_type = make_type("NotEq", state->cmpop_type, NULL, 0, + "NotEq"); + if (!state->NotEq_type) return 0; + state->NotEq_singleton = PyType_GenericNew((PyTypeObject + *)state->NotEq_type, NULL, NULL); + if (!state->NotEq_singleton) return 0; + state->Lt_type = make_type("Lt", state->cmpop_type, NULL, 0, + "Lt"); + if (!state->Lt_type) return 0; + state->Lt_singleton = PyType_GenericNew((PyTypeObject *)state->Lt_type, + NULL, NULL); + if (!state->Lt_singleton) return 0; + state->LtE_type = make_type("LtE", state->cmpop_type, NULL, 0, + "LtE"); + if (!state->LtE_type) return 0; + state->LtE_singleton = PyType_GenericNew((PyTypeObject *)state->LtE_type, + NULL, NULL); + if (!state->LtE_singleton) return 0; + state->Gt_type = make_type("Gt", state->cmpop_type, NULL, 0, + "Gt"); + if (!state->Gt_type) return 0; + state->Gt_singleton = PyType_GenericNew((PyTypeObject *)state->Gt_type, + NULL, NULL); + if (!state->Gt_singleton) return 0; + state->GtE_type = make_type("GtE", state->cmpop_type, NULL, 0, + "GtE"); + if (!state->GtE_type) return 0; + state->GtE_singleton = PyType_GenericNew((PyTypeObject *)state->GtE_type, + NULL, NULL); + if (!state->GtE_singleton) return 0; + state->Is_type = make_type("Is", state->cmpop_type, NULL, 0, + "Is"); + if (!state->Is_type) return 0; + state->Is_singleton = PyType_GenericNew((PyTypeObject *)state->Is_type, + NULL, NULL); + if (!state->Is_singleton) return 0; + state->IsNot_type = make_type("IsNot", state->cmpop_type, NULL, 0, + "IsNot"); + if (!state->IsNot_type) return 0; + state->IsNot_singleton = PyType_GenericNew((PyTypeObject + *)state->IsNot_type, NULL, NULL); + if (!state->IsNot_singleton) return 0; + state->In_type = make_type("In", state->cmpop_type, NULL, 0, + "In"); + if (!state->In_type) return 0; + state->In_singleton = PyType_GenericNew((PyTypeObject *)state->In_type, + NULL, NULL); + if (!state->In_singleton) return 0; + state->NotIn_type = make_type("NotIn", state->cmpop_type, NULL, 0, + "NotIn"); + if (!state->NotIn_type) return 0; + state->NotIn_singleton = PyType_GenericNew((PyTypeObject + *)state->NotIn_type, NULL, NULL); + if (!state->NotIn_singleton) return 0; + state->comprehension_type = make_type("comprehension", state->AST_type, + comprehension_fields, 4, + "comprehension(expr target, expr iter, expr* ifs, int is_async)"); + if (!state->comprehension_type) return 0; + if (!add_attributes(state->comprehension_type, NULL, 0)) return 0; + state->excepthandler_type = make_type("excepthandler", state->AST_type, + NULL, 0, + "excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)"); + if (!state->excepthandler_type) return 0; + if (!add_attributes(state->excepthandler_type, excepthandler_attributes, + 4)) return 0; + if (PyObject_SetAttr(state->excepthandler_type, state->end_lineno, Py_None) + == -1) + return 0; + if (PyObject_SetAttr(state->excepthandler_type, state->end_col_offset, + Py_None) == -1) + return 0; + state->ExceptHandler_type = make_type("ExceptHandler", + state->excepthandler_type, + ExceptHandler_fields, 3, + "ExceptHandler(expr? type, identifier? name, stmt* body)"); + if (!state->ExceptHandler_type) return 0; + if (PyObject_SetAttr(state->ExceptHandler_type, state->type, Py_None) == -1) + return 0; + if (PyObject_SetAttr(state->ExceptHandler_type, state->name, Py_None) == -1) + return 0; + state->arguments_type = make_type("arguments", state->AST_type, + arguments_fields, 7, + "arguments(arg* posonlyargs, arg* args, arg? vararg, arg* kwonlyargs, expr* kw_defaults, arg? kwarg, expr* defaults)"); + if (!state->arguments_type) return 0; + if (!add_attributes(state->arguments_type, NULL, 0)) return 0; + if (PyObject_SetAttr(state->arguments_type, state->vararg, Py_None) == -1) + return 0; + if (PyObject_SetAttr(state->arguments_type, state->kwarg, Py_None) == -1) + return 0; + state->arg_type = make_type("arg", state->AST_type, arg_fields, 3, + "arg(identifier arg, expr? annotation, string? type_comment)"); + if (!state->arg_type) return 0; + if (!add_attributes(state->arg_type, arg_attributes, 4)) return 0; + if (PyObject_SetAttr(state->arg_type, state->annotation, Py_None) == -1) + return 0; + if (PyObject_SetAttr(state->arg_type, state->type_comment, Py_None) == -1) + return 0; + if (PyObject_SetAttr(state->arg_type, state->end_lineno, Py_None) == -1) + return 0; + if (PyObject_SetAttr(state->arg_type, state->end_col_offset, Py_None) == -1) + return 0; + state->keyword_type = make_type("keyword", state->AST_type, keyword_fields, + 2, + "keyword(identifier? arg, expr value)"); + if (!state->keyword_type) return 0; + if (!add_attributes(state->keyword_type, keyword_attributes, 4)) return 0; + if (PyObject_SetAttr(state->keyword_type, state->arg, Py_None) == -1) + return 0; + if (PyObject_SetAttr(state->keyword_type, state->end_lineno, Py_None) == -1) + return 0; + if (PyObject_SetAttr(state->keyword_type, state->end_col_offset, Py_None) + == -1) + return 0; + state->alias_type = make_type("alias", state->AST_type, alias_fields, 2, + "alias(identifier name, identifier? asname)"); + if (!state->alias_type) return 0; + if (!add_attributes(state->alias_type, NULL, 0)) return 0; + if (PyObject_SetAttr(state->alias_type, state->asname, Py_None) == -1) + return 0; + state->withitem_type = make_type("withitem", state->AST_type, + withitem_fields, 2, + "withitem(expr context_expr, expr? optional_vars)"); + if (!state->withitem_type) return 0; + if (!add_attributes(state->withitem_type, NULL, 0)) return 0; + if (PyObject_SetAttr(state->withitem_type, state->optional_vars, Py_None) + == -1) + return 0; + state->type_ignore_type = make_type("type_ignore", state->AST_type, NULL, 0, + "type_ignore = TypeIgnore(int lineno, string tag)"); + if (!state->type_ignore_type) return 0; + if (!add_attributes(state->type_ignore_type, NULL, 0)) return 0; + state->TypeIgnore_type = make_type("TypeIgnore", state->type_ignore_type, + TypeIgnore_fields, 2, + "TypeIgnore(int lineno, string tag)"); + if (!state->TypeIgnore_type) return 0; + state->initialized = 1; return 1; } @@ -1226,7 +2028,6 @@ static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena); static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena); static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena); -static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena); static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena); static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena); static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena); @@ -1274,7 +2075,7 @@ Expression(expr_ty body, PyArena *arena) mod_ty p; if (!body) { PyErr_SetString(PyExc_ValueError, - "field body is required for Expression"); + "field 'body' is required for Expression"); return NULL; } p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1291,7 +2092,7 @@ FunctionType(asdl_seq * argtypes, expr_ty returns, PyArena *arena) mod_ty p; if (!returns) { PyErr_SetString(PyExc_ValueError, - "field returns is required for FunctionType"); + "field 'returns' is required for FunctionType"); return NULL; } p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1303,32 +2104,20 @@ FunctionType(asdl_seq * argtypes, expr_ty returns, PyArena *arena) return p; } -mod_ty -Suite(asdl_seq * body, PyArena *arena) -{ - mod_ty p; - p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Suite_kind; - p->v.Suite.body = body; - return p; -} - stmt_ty FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * decorator_list, expr_ty returns, string type_comment, int lineno, - int col_offset, PyArena *arena) + int col_offset, int end_lineno, int end_col_offset, PyArena *arena) { stmt_ty p; if (!name) { PyErr_SetString(PyExc_ValueError, - "field name is required for FunctionDef"); + "field 'name' is required for FunctionDef"); return NULL; } if (!args) { PyErr_SetString(PyExc_ValueError, - "field args is required for FunctionDef"); + "field 'args' is required for FunctionDef"); return NULL; } p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1343,23 +2132,26 @@ FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * p->v.FunctionDef.type_comment = type_comment; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } stmt_ty AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * decorator_list, expr_ty returns, string type_comment, int - lineno, int col_offset, PyArena *arena) + lineno, int col_offset, int end_lineno, int end_col_offset, + PyArena *arena) { stmt_ty p; if (!name) { PyErr_SetString(PyExc_ValueError, - "field name is required for AsyncFunctionDef"); + "field 'name' is required for AsyncFunctionDef"); return NULL; } if (!args) { PyErr_SetString(PyExc_ValueError, - "field args is required for AsyncFunctionDef"); + "field 'args' is required for AsyncFunctionDef"); return NULL; } p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1374,18 +2166,20 @@ AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq p->v.AsyncFunctionDef.type_comment = type_comment; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } stmt_ty ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, asdl_seq * - body, asdl_seq * decorator_list, int lineno, int col_offset, PyArena - *arena) + body, asdl_seq * decorator_list, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena *arena) { stmt_ty p; if (!name) { PyErr_SetString(PyExc_ValueError, - "field name is required for ClassDef"); + "field 'name' is required for ClassDef"); return NULL; } p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1399,11 +2193,14 @@ ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, asdl_seq * p->v.ClassDef.decorator_list = decorator_list; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } stmt_ty -Return(expr_ty value, int lineno, int col_offset, PyArena *arena) +Return(expr_ty value, int lineno, int col_offset, int end_lineno, int + end_col_offset, PyArena *arena) { stmt_ty p; p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1413,11 +2210,14 @@ Return(expr_ty value, int lineno, int col_offset, PyArena *arena) p->v.Return.value = value; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } stmt_ty -Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena) +Delete(asdl_seq * targets, int lineno, int col_offset, int end_lineno, int + end_col_offset, PyArena *arena) { stmt_ty p; p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1427,17 +2227,19 @@ Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena) p->v.Delete.targets = targets; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } stmt_ty Assign(asdl_seq * targets, expr_ty value, string type_comment, int lineno, int - col_offset, PyArena *arena) + col_offset, int end_lineno, int end_col_offset, PyArena *arena) { stmt_ty p; if (!value) { PyErr_SetString(PyExc_ValueError, - "field value is required for Assign"); + "field 'value' is required for Assign"); return NULL; } p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1449,27 +2251,29 @@ Assign(asdl_seq * targets, expr_ty value, string type_comment, int lineno, int p->v.Assign.type_comment = type_comment; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } stmt_ty AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int - col_offset, PyArena *arena) + col_offset, int end_lineno, int end_col_offset, PyArena *arena) { stmt_ty p; if (!target) { PyErr_SetString(PyExc_ValueError, - "field target is required for AugAssign"); + "field 'target' is required for AugAssign"); return NULL; } if (!op) { PyErr_SetString(PyExc_ValueError, - "field op is required for AugAssign"); + "field 'op' is required for AugAssign"); return NULL; } if (!value) { PyErr_SetString(PyExc_ValueError, - "field value is required for AugAssign"); + "field 'value' is required for AugAssign"); return NULL; } p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1481,22 +2285,25 @@ AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int p->v.AugAssign.value = value; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } stmt_ty AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int simple, int - lineno, int col_offset, PyArena *arena) + lineno, int col_offset, int end_lineno, int end_col_offset, PyArena + *arena) { stmt_ty p; if (!target) { PyErr_SetString(PyExc_ValueError, - "field target is required for AnnAssign"); + "field 'target' is required for AnnAssign"); return NULL; } if (!annotation) { PyErr_SetString(PyExc_ValueError, - "field annotation is required for AnnAssign"); + "field 'annotation' is required for AnnAssign"); return NULL; } p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1509,22 +2316,25 @@ AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int simple, int p->v.AnnAssign.simple = simple; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } stmt_ty For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, string - type_comment, int lineno, int col_offset, PyArena *arena) + type_comment, int lineno, int col_offset, int end_lineno, int + end_col_offset, PyArena *arena) { stmt_ty p; if (!target) { PyErr_SetString(PyExc_ValueError, - "field target is required for For"); + "field 'target' is required for For"); return NULL; } if (!iter) { PyErr_SetString(PyExc_ValueError, - "field iter is required for For"); + "field 'iter' is required for For"); return NULL; } p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1538,22 +2348,25 @@ For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, string p->v.For.type_comment = type_comment; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } stmt_ty AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, - string type_comment, int lineno, int col_offset, PyArena *arena) + string type_comment, int lineno, int col_offset, int end_lineno, int + end_col_offset, PyArena *arena) { stmt_ty p; if (!target) { PyErr_SetString(PyExc_ValueError, - "field target is required for AsyncFor"); + "field 'target' is required for AsyncFor"); return NULL; } if (!iter) { PyErr_SetString(PyExc_ValueError, - "field iter is required for AsyncFor"); + "field 'iter' is required for AsyncFor"); return NULL; } p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1567,17 +2380,19 @@ AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, p->v.AsyncFor.type_comment = type_comment; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } stmt_ty While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int - col_offset, PyArena *arena) + col_offset, int end_lineno, int end_col_offset, PyArena *arena) { stmt_ty p; if (!test) { PyErr_SetString(PyExc_ValueError, - "field test is required for While"); + "field 'test' is required for While"); return NULL; } p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1589,17 +2404,19 @@ While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int p->v.While.orelse = orelse; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } stmt_ty If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int - col_offset, PyArena *arena) + col_offset, int end_lineno, int end_col_offset, PyArena *arena) { stmt_ty p; if (!test) { PyErr_SetString(PyExc_ValueError, - "field test is required for If"); + "field 'test' is required for If"); return NULL; } p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1611,12 +2428,14 @@ If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int p->v.If.orelse = orelse; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } stmt_ty With(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, int - col_offset, PyArena *arena) + col_offset, int end_lineno, int end_col_offset, PyArena *arena) { stmt_ty p; p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1628,12 +2447,14 @@ With(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, int p->v.With.type_comment = type_comment; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } stmt_ty AsyncWith(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, - int col_offset, PyArena *arena) + int col_offset, int end_lineno, int end_col_offset, PyArena *arena) { stmt_ty p; p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1645,11 +2466,14 @@ AsyncWith(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, p->v.AsyncWith.type_comment = type_comment; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } stmt_ty -Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, PyArena *arena) +Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int end_lineno, + int end_col_offset, PyArena *arena) { stmt_ty p; p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1660,12 +2484,15 @@ Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, PyArena *arena) p->v.Raise.cause = cause; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } stmt_ty Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq * - finalbody, int lineno, int col_offset, PyArena *arena) + finalbody, int lineno, int col_offset, int end_lineno, int end_col_offset, + PyArena *arena) { stmt_ty p; p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1678,16 +2505,19 @@ Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq * p->v.Try.finalbody = finalbody; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } stmt_ty -Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena) +Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int end_lineno, + int end_col_offset, PyArena *arena) { stmt_ty p; if (!test) { PyErr_SetString(PyExc_ValueError, - "field test is required for Assert"); + "field 'test' is required for Assert"); return NULL; } p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1698,11 +2528,14 @@ Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena) p->v.Assert.msg = msg; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } stmt_ty -Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena) +Import(asdl_seq * names, int lineno, int col_offset, int end_lineno, int + end_col_offset, PyArena *arena) { stmt_ty p; p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1712,12 +2545,14 @@ Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena) p->v.Import.names = names; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } stmt_ty ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int - col_offset, PyArena *arena) + col_offset, int end_lineno, int end_col_offset, PyArena *arena) { stmt_ty p; p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1729,11 +2564,14 @@ ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int p->v.ImportFrom.level = level; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } stmt_ty -Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena) +Global(asdl_seq * names, int lineno, int col_offset, int end_lineno, int + end_col_offset, PyArena *arena) { stmt_ty p; p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1743,11 +2581,14 @@ Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena) p->v.Global.names = names; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } stmt_ty -Nonlocal(asdl_seq * names, int lineno, int col_offset, PyArena *arena) +Nonlocal(asdl_seq * names, int lineno, int col_offset, int end_lineno, int + end_col_offset, PyArena *arena) { stmt_ty p; p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1757,16 +2598,19 @@ Nonlocal(asdl_seq * names, int lineno, int col_offset, PyArena *arena) p->v.Nonlocal.names = names; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } stmt_ty -Expr(expr_ty value, int lineno, int col_offset, PyArena *arena) +Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int + end_col_offset, PyArena *arena) { stmt_ty p; if (!value) { PyErr_SetString(PyExc_ValueError, - "field value is required for Expr"); + "field 'value' is required for Expr"); return NULL; } p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1776,11 +2620,14 @@ Expr(expr_ty value, int lineno, int col_offset, PyArena *arena) p->v.Expr.value = value; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } stmt_ty -Pass(int lineno, int col_offset, PyArena *arena) +Pass(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena + *arena) { stmt_ty p; p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1789,11 +2636,14 @@ Pass(int lineno, int col_offset, PyArena *arena) p->kind = Pass_kind; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } stmt_ty -Break(int lineno, int col_offset, PyArena *arena) +Break(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena + *arena) { stmt_ty p; p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1802,11 +2652,14 @@ Break(int lineno, int col_offset, PyArena *arena) p->kind = Break_kind; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } stmt_ty -Continue(int lineno, int col_offset, PyArena *arena) +Continue(int lineno, int col_offset, int end_lineno, int end_col_offset, + PyArena *arena) { stmt_ty p; p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1815,17 +2668,19 @@ Continue(int lineno, int col_offset, PyArena *arena) p->kind = Continue_kind; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } expr_ty -BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena - *arena) +BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena *arena) { expr_ty p; if (!op) { PyErr_SetString(PyExc_ValueError, - "field op is required for BoolOp"); + "field 'op' is required for BoolOp"); return NULL; } p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1836,27 +2691,57 @@ BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena p->v.BoolOp.values = values; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; + return p; +} + +expr_ty +NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena *arena) +{ + expr_ty p; + if (!target) { + PyErr_SetString(PyExc_ValueError, + "field 'target' is required for NamedExpr"); + return NULL; + } + if (!value) { + PyErr_SetString(PyExc_ValueError, + "field 'value' is required for NamedExpr"); + return NULL; + } + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = NamedExpr_kind; + p->v.NamedExpr.target = target; + p->v.NamedExpr.value = value; + p->lineno = lineno; + p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } expr_ty BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset, - PyArena *arena) + int end_lineno, int end_col_offset, PyArena *arena) { expr_ty p; if (!left) { PyErr_SetString(PyExc_ValueError, - "field left is required for BinOp"); + "field 'left' is required for BinOp"); return NULL; } if (!op) { PyErr_SetString(PyExc_ValueError, - "field op is required for BinOp"); + "field 'op' is required for BinOp"); return NULL; } if (!right) { PyErr_SetString(PyExc_ValueError, - "field right is required for BinOp"); + "field 'right' is required for BinOp"); return NULL; } p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1868,22 +2753,24 @@ BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset, p->v.BinOp.right = right; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } expr_ty -UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena - *arena) +UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena *arena) { expr_ty p; if (!op) { PyErr_SetString(PyExc_ValueError, - "field op is required for UnaryOp"); + "field 'op' is required for UnaryOp"); return NULL; } if (!operand) { PyErr_SetString(PyExc_ValueError, - "field operand is required for UnaryOp"); + "field 'operand' is required for UnaryOp"); return NULL; } p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1894,22 +2781,24 @@ UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena p->v.UnaryOp.operand = operand; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } expr_ty -Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena - *arena) +Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena *arena) { expr_ty p; if (!args) { PyErr_SetString(PyExc_ValueError, - "field args is required for Lambda"); + "field 'args' is required for Lambda"); return NULL; } if (!body) { PyErr_SetString(PyExc_ValueError, - "field body is required for Lambda"); + "field 'body' is required for Lambda"); return NULL; } p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1920,27 +2809,29 @@ Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena p->v.Lambda.body = body; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } expr_ty IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset, - PyArena *arena) + int end_lineno, int end_col_offset, PyArena *arena) { expr_ty p; if (!test) { PyErr_SetString(PyExc_ValueError, - "field test is required for IfExp"); + "field 'test' is required for IfExp"); return NULL; } if (!body) { PyErr_SetString(PyExc_ValueError, - "field body is required for IfExp"); + "field 'body' is required for IfExp"); return NULL; } if (!orelse) { PyErr_SetString(PyExc_ValueError, - "field orelse is required for IfExp"); + "field 'orelse' is required for IfExp"); return NULL; } p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1952,12 +2843,14 @@ IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset, p->v.IfExp.orelse = orelse; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } expr_ty -Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena - *arena) +Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena *arena) { expr_ty p; p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1968,11 +2861,14 @@ Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena p->v.Dict.values = values; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } expr_ty -Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena) +Set(asdl_seq * elts, int lineno, int col_offset, int end_lineno, int + end_col_offset, PyArena *arena) { expr_ty p; p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1982,17 +2878,19 @@ Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena) p->v.Set.elts = elts; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } expr_ty -ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, - PyArena *arena) +ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena *arena) { expr_ty p; if (!elt) { PyErr_SetString(PyExc_ValueError, - "field elt is required for ListComp"); + "field 'elt' is required for ListComp"); return NULL; } p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -2003,17 +2901,19 @@ ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, p->v.ListComp.generators = generators; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } expr_ty -SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena - *arena) +SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena *arena) { expr_ty p; if (!elt) { PyErr_SetString(PyExc_ValueError, - "field elt is required for SetComp"); + "field 'elt' is required for SetComp"); return NULL; } p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -2024,22 +2924,24 @@ SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena p->v.SetComp.generators = generators; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } expr_ty DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int - col_offset, PyArena *arena) + col_offset, int end_lineno, int end_col_offset, PyArena *arena) { expr_ty p; if (!key) { PyErr_SetString(PyExc_ValueError, - "field key is required for DictComp"); + "field 'key' is required for DictComp"); return NULL; } if (!value) { PyErr_SetString(PyExc_ValueError, - "field value is required for DictComp"); + "field 'value' is required for DictComp"); return NULL; } p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -2051,17 +2953,19 @@ DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int p->v.DictComp.generators = generators; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } expr_ty GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, - PyArena *arena) + int end_lineno, int end_col_offset, PyArena *arena) { expr_ty p; if (!elt) { PyErr_SetString(PyExc_ValueError, - "field elt is required for GeneratorExp"); + "field 'elt' is required for GeneratorExp"); return NULL; } p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -2072,16 +2976,19 @@ GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, p->v.GeneratorExp.generators = generators; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } expr_ty -Await(expr_ty value, int lineno, int col_offset, PyArena *arena) +Await(expr_ty value, int lineno, int col_offset, int end_lineno, int + end_col_offset, PyArena *arena) { expr_ty p; if (!value) { PyErr_SetString(PyExc_ValueError, - "field value is required for Await"); + "field 'value' is required for Await"); return NULL; } p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -2091,11 +2998,14 @@ Await(expr_ty value, int lineno, int col_offset, PyArena *arena) p->v.Await.value = value; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } expr_ty -Yield(expr_ty value, int lineno, int col_offset, PyArena *arena) +Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int + end_col_offset, PyArena *arena) { expr_ty p; p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -2105,16 +3015,19 @@ Yield(expr_ty value, int lineno, int col_offset, PyArena *arena) p->v.Yield.value = value; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } expr_ty -YieldFrom(expr_ty value, int lineno, int col_offset, PyArena *arena) +YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int + end_col_offset, PyArena *arena) { expr_ty p; if (!value) { PyErr_SetString(PyExc_ValueError, - "field value is required for YieldFrom"); + "field 'value' is required for YieldFrom"); return NULL; } p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -2124,17 +3037,19 @@ YieldFrom(expr_ty value, int lineno, int col_offset, PyArena *arena) p->v.YieldFrom.value = value; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } expr_ty Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno, - int col_offset, PyArena *arena) + int col_offset, int end_lineno, int end_col_offset, PyArena *arena) { expr_ty p; if (!left) { PyErr_SetString(PyExc_ValueError, - "field left is required for Compare"); + "field 'left' is required for Compare"); return NULL; } p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -2146,17 +3061,19 @@ Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno, p->v.Compare.comparators = comparators; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } expr_ty Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, int lineno, int - col_offset, PyArena *arena) + col_offset, int end_lineno, int end_col_offset, PyArena *arena) { expr_ty p; if (!func) { PyErr_SetString(PyExc_ValueError, - "field func is required for Call"); + "field 'func' is required for Call"); return NULL; } p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -2168,61 +3085,20 @@ Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, int lineno, int p->v.Call.keywords = keywords; p->lineno = lineno; p->col_offset = col_offset; - return p; -} - -expr_ty -Num(object n, int lineno, int col_offset, PyArena *arena) -{ - expr_ty p; - if (!n) { - PyErr_SetString(PyExc_ValueError, - "field n is required for Num"); - return NULL; - } - p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Num_kind; - p->v.Num.n = n; - p->lineno = lineno; - p->col_offset = col_offset; - return p; -} - -expr_ty -Str(string s, string kind, int lineno, int col_offset, PyArena *arena) -{ - expr_ty p; - if (!s) { - PyErr_SetString(PyExc_ValueError, - "field s is required for Str"); - return NULL; - } - if (!kind) { - PyErr_SetString(PyExc_ValueError, - "field kind is required for Str"); - return NULL; - } - p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Str_kind; - p->v.Str.s = s; - p->v.Str.kind = kind; - p->lineno = lineno; - p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } expr_ty FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno, - int col_offset, PyArena *arena) + int col_offset, int end_lineno, int end_col_offset, PyArena + *arena) { expr_ty p; if (!value) { PyErr_SetString(PyExc_ValueError, - "field value is required for FormattedValue"); + "field 'value' is required for FormattedValue"); return NULL; } p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -2234,11 +3110,14 @@ FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno, p->v.FormattedValue.format_spec = format_spec; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } expr_ty -JoinedStr(asdl_seq * values, int lineno, int col_offset, PyArena *arena) +JoinedStr(asdl_seq * values, int lineno, int col_offset, int end_lineno, int + end_col_offset, PyArena *arena) { expr_ty p; p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -2248,73 +3127,19 @@ JoinedStr(asdl_seq * values, int lineno, int col_offset, PyArena *arena) p->v.JoinedStr.values = values; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } expr_ty -Bytes(bytes s, string kind, int lineno, int col_offset, PyArena *arena) -{ - expr_ty p; - if (!s) { - PyErr_SetString(PyExc_ValueError, - "field s is required for Bytes"); - return NULL; - } - if (!kind) { - PyErr_SetString(PyExc_ValueError, - "field kind is required for Bytes"); - return NULL; - } - p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Bytes_kind; - p->v.Bytes.s = s; - p->v.Bytes.kind = kind; - p->lineno = lineno; - p->col_offset = col_offset; - return p; -} - -expr_ty -NameConstant(singleton value, int lineno, int col_offset, PyArena *arena) -{ - expr_ty p; - if (!value) { - PyErr_SetString(PyExc_ValueError, - "field value is required for NameConstant"); - return NULL; - } - p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = NameConstant_kind; - p->v.NameConstant.value = value; - p->lineno = lineno; - p->col_offset = col_offset; - return p; -} - -expr_ty -Ellipsis(int lineno, int col_offset, PyArena *arena) -{ - expr_ty p; - p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Ellipsis_kind; - p->lineno = lineno; - p->col_offset = col_offset; - return p; -} - -expr_ty -Constant(constant value, int lineno, int col_offset, PyArena *arena) +Constant(constant value, string kind, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena *arena) { expr_ty p; if (!value) { PyErr_SetString(PyExc_ValueError, - "field value is required for Constant"); + "field 'value' is required for Constant"); return NULL; } p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -2322,29 +3147,32 @@ Constant(constant value, int lineno, int col_offset, PyArena *arena) return NULL; p->kind = Constant_kind; p->v.Constant.value = value; + p->v.Constant.kind = kind; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } expr_ty Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int - col_offset, PyArena *arena) + col_offset, int end_lineno, int end_col_offset, PyArena *arena) { expr_ty p; if (!value) { PyErr_SetString(PyExc_ValueError, - "field value is required for Attribute"); + "field 'value' is required for Attribute"); return NULL; } if (!attr) { PyErr_SetString(PyExc_ValueError, - "field attr is required for Attribute"); + "field 'attr' is required for Attribute"); return NULL; } if (!ctx) { PyErr_SetString(PyExc_ValueError, - "field ctx is required for Attribute"); + "field 'ctx' is required for Attribute"); return NULL; } p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -2356,27 +3184,29 @@ Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int p->v.Attribute.ctx = ctx; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } expr_ty -Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int - col_offset, PyArena *arena) +Subscript(expr_ty value, expr_ty slice, expr_context_ty ctx, int lineno, int + col_offset, int end_lineno, int end_col_offset, PyArena *arena) { expr_ty p; if (!value) { PyErr_SetString(PyExc_ValueError, - "field value is required for Subscript"); + "field 'value' is required for Subscript"); return NULL; } if (!slice) { PyErr_SetString(PyExc_ValueError, - "field slice is required for Subscript"); + "field 'slice' is required for Subscript"); return NULL; } if (!ctx) { PyErr_SetString(PyExc_ValueError, - "field ctx is required for Subscript"); + "field 'ctx' is required for Subscript"); return NULL; } p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -2388,22 +3218,24 @@ Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int p->v.Subscript.ctx = ctx; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } expr_ty -Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, PyArena - *arena) +Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena *arena) { expr_ty p; if (!value) { PyErr_SetString(PyExc_ValueError, - "field value is required for Starred"); + "field 'value' is required for Starred"); return NULL; } if (!ctx) { PyErr_SetString(PyExc_ValueError, - "field ctx is required for Starred"); + "field 'ctx' is required for Starred"); return NULL; } p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -2414,22 +3246,24 @@ Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, PyArena p->v.Starred.ctx = ctx; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } expr_ty -Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena - *arena) +Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena *arena) { expr_ty p; if (!id) { PyErr_SetString(PyExc_ValueError, - "field id is required for Name"); + "field 'id' is required for Name"); return NULL; } if (!ctx) { PyErr_SetString(PyExc_ValueError, - "field ctx is required for Name"); + "field 'ctx' is required for Name"); return NULL; } p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -2440,17 +3274,19 @@ Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena p->v.Name.ctx = ctx; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } expr_ty -List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena - *arena) +List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena *arena) { expr_ty p; if (!ctx) { PyErr_SetString(PyExc_ValueError, - "field ctx is required for List"); + "field 'ctx' is required for List"); return NULL; } p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -2461,17 +3297,19 @@ List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena p->v.List.ctx = ctx; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } expr_ty -Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena - *arena) +Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena *arena) { expr_ty p; if (!ctx) { PyErr_SetString(PyExc_ValueError, - "field ctx is required for Tuple"); + "field 'ctx' is required for Tuple"); return NULL; } p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -2482,49 +3320,27 @@ Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena p->v.Tuple.ctx = ctx; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } -slice_ty -Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena) +expr_ty +Slice(expr_ty lower, expr_ty upper, expr_ty step, int lineno, int col_offset, + int end_lineno, int end_col_offset, PyArena *arena) { - slice_ty p; - p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); + expr_ty p; + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); if (!p) return NULL; p->kind = Slice_kind; p->v.Slice.lower = lower; p->v.Slice.upper = upper; p->v.Slice.step = step; - return p; -} - -slice_ty -ExtSlice(asdl_seq * dims, PyArena *arena) -{ - slice_ty p; - p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = ExtSlice_kind; - p->v.ExtSlice.dims = dims; - return p; -} - -slice_ty -Index(expr_ty value, PyArena *arena) -{ - slice_ty p; - if (!value) { - PyErr_SetString(PyExc_ValueError, - "field value is required for Index"); - return NULL; - } - p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = Index_kind; - p->v.Index.value = value; + p->lineno = lineno; + p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } @@ -2535,12 +3351,12 @@ comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, int is_async, comprehension_ty p; if (!target) { PyErr_SetString(PyExc_ValueError, - "field target is required for comprehension"); + "field 'target' is required for comprehension"); return NULL; } if (!iter) { PyErr_SetString(PyExc_ValueError, - "field iter is required for comprehension"); + "field 'iter' is required for comprehension"); return NULL; } p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -2555,7 +3371,7 @@ comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, int is_async, excepthandler_ty ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int - col_offset, PyArena *arena) + col_offset, int end_lineno, int end_col_offset, PyArena *arena) { excepthandler_ty p; p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -2567,17 +3383,21 @@ ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int p->v.ExceptHandler.body = body; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } arguments_ty -arguments(asdl_seq * args, arg_ty vararg, asdl_seq * kwonlyargs, asdl_seq * - kw_defaults, arg_ty kwarg, asdl_seq * defaults, PyArena *arena) +arguments(asdl_seq * posonlyargs, asdl_seq * args, arg_ty vararg, asdl_seq * + kwonlyargs, asdl_seq * kw_defaults, arg_ty kwarg, asdl_seq * + defaults, PyArena *arena) { arguments_ty p; p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); if (!p) return NULL; + p->posonlyargs = posonlyargs; p->args = args; p->vararg = vararg; p->kwonlyargs = kwonlyargs; @@ -2589,12 +3409,12 @@ arguments(asdl_seq * args, arg_ty vararg, asdl_seq * kwonlyargs, asdl_seq * arg_ty arg(identifier arg, expr_ty annotation, string type_comment, int lineno, int - col_offset, PyArena *arena) + col_offset, int end_lineno, int end_col_offset, PyArena *arena) { arg_ty p; if (!arg) { PyErr_SetString(PyExc_ValueError, - "field arg is required for arg"); + "field 'arg' is required for arg"); return NULL; } p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -2605,16 +3425,19 @@ arg(identifier arg, expr_ty annotation, string type_comment, int lineno, int p->type_comment = type_comment; p->lineno = lineno; p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } keyword_ty -keyword(identifier arg, expr_ty value, PyArena *arena) +keyword(identifier arg, expr_ty value, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena *arena) { keyword_ty p; if (!value) { PyErr_SetString(PyExc_ValueError, - "field value is required for keyword"); + "field 'value' is required for keyword"); return NULL; } p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -2622,6 +3445,10 @@ keyword(identifier arg, expr_ty value, PyArena *arena) return NULL; p->arg = arg; p->value = value; + p->lineno = lineno; + p->col_offset = col_offset; + p->end_lineno = end_lineno; + p->end_col_offset = end_col_offset; return p; } @@ -2631,7 +3458,7 @@ alias(identifier name, identifier asname, PyArena *arena) alias_ty p; if (!name) { PyErr_SetString(PyExc_ValueError, - "field name is required for alias"); + "field 'name' is required for alias"); return NULL; } p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -2648,7 +3475,7 @@ withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena) withitem_ty p; if (!context_expr) { PyErr_SetString(PyExc_ValueError, - "field context_expr is required for withitem"); + "field 'context_expr' is required for withitem"); return NULL; } p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -2665,7 +3492,7 @@ TypeIgnore(int lineno, string tag, PyArena *arena) type_ignore_ty p; if (!tag) { PyErr_SetString(PyExc_ValueError, - "field tag is required for TypeIgnore"); + "field 'tag' is required for TypeIgnore"); return NULL; } p = (type_ignore_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -2683,63 +3510,62 @@ ast2obj_mod(void* _o) { mod_ty o = (mod_ty)_o; PyObject *result = NULL, *value = NULL; + PyTypeObject *tp; if (!o) { Py_RETURN_NONE; } switch (o->kind) { case Module_kind: - result = PyType_GenericNew(Module_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->Module_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_list(o->v.Module.body, ast2obj_stmt); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.Module.type_ignores, ast2obj_type_ignore); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_type_ignores, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->type_ignores, + value) == -1) goto failed; Py_DECREF(value); break; case Interactive_kind: - result = PyType_GenericNew(Interactive_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->Interactive_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) goto failed; Py_DECREF(value); break; case Expression_kind: - result = PyType_GenericNew(Expression_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->Expression_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_expr(o->v.Expression.body); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) goto failed; Py_DECREF(value); break; case FunctionType_kind: - result = PyType_GenericNew(FunctionType_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->FunctionType_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_list(o->v.FunctionType.argtypes, ast2obj_expr); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_argtypes, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->argtypes, value) == + -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->v.FunctionType.returns); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) - goto failed; - Py_DECREF(value); - break; - case Suite_kind: - result = PyType_GenericNew(Suite_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_list(o->v.Suite.body, ast2obj_stmt); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == + -1) goto failed; Py_DECREF(value); break; @@ -2756,451 +3582,517 @@ ast2obj_stmt(void* _o) { stmt_ty o = (stmt_ty)_o; PyObject *result = NULL, *value = NULL; + PyTypeObject *tp; if (!o) { Py_RETURN_NONE; } switch (o->kind) { case FunctionDef_kind: - result = PyType_GenericNew(FunctionDef_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->FunctionDef_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_identifier(o->v.FunctionDef.name); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_arguments(o->v.FunctionDef.args); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, + value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->v.FunctionDef.returns); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == + -1) goto failed; Py_DECREF(value); value = ast2obj_string(o->v.FunctionDef.type_comment); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->type_comment, + value) == -1) goto failed; Py_DECREF(value); break; case AsyncFunctionDef_kind: - result = PyType_GenericNew(AsyncFunctionDef_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->AsyncFunctionDef_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_identifier(o->v.AsyncFunctionDef.name); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_arguments(o->v.AsyncFunctionDef.args); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list, ast2obj_expr); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, + value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->v.AsyncFunctionDef.returns); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == + -1) goto failed; Py_DECREF(value); value = ast2obj_string(o->v.AsyncFunctionDef.type_comment); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->type_comment, + value) == -1) goto failed; Py_DECREF(value); break; case ClassDef_kind: - result = PyType_GenericNew(ClassDef_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->ClassDef_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_identifier(o->v.ClassDef.name); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_bases, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->bases, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) == + -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, + value) == -1) goto failed; Py_DECREF(value); break; case Return_kind: - result = PyType_GenericNew(Return_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->Return_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_expr(o->v.Return.value); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) goto failed; Py_DECREF(value); break; case Delete_kind: - result = PyType_GenericNew(Delete_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->Delete_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->targets, value) == + -1) goto failed; Py_DECREF(value); break; case Assign_kind: - result = PyType_GenericNew(Assign_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->Assign_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->targets, value) == + -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->v.Assign.value); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_string(o->v.Assign.type_comment); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->type_comment, + value) == -1) goto failed; Py_DECREF(value); break; case AugAssign_kind: - result = PyType_GenericNew(AugAssign_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->AugAssign_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_expr(o->v.AugAssign.target); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->target, value) == + -1) goto failed; Py_DECREF(value); value = ast2obj_operator(o->v.AugAssign.op); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->v.AugAssign.value); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) goto failed; Py_DECREF(value); break; case AnnAssign_kind: - result = PyType_GenericNew(AnnAssign_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->AnnAssign_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_expr(o->v.AnnAssign.target); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->target, value) == + -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->v.AnnAssign.annotation); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) + == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->v.AnnAssign.value); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_int(o->v.AnnAssign.simple); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_simple, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->simple, value) == + -1) goto failed; Py_DECREF(value); break; case For_kind: - result = PyType_GenericNew(For_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->For_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_expr(o->v.For.target); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->target, value) == + -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->v.For.iter); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.For.body, ast2obj_stmt); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == + -1) goto failed; Py_DECREF(value); value = ast2obj_string(o->v.For.type_comment); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->type_comment, + value) == -1) goto failed; Py_DECREF(value); break; case AsyncFor_kind: - result = PyType_GenericNew(AsyncFor_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->AsyncFor_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_expr(o->v.AsyncFor.target); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->target, value) == + -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->v.AsyncFor.iter); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == + -1) goto failed; Py_DECREF(value); value = ast2obj_string(o->v.AsyncFor.type_comment); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->type_comment, + value) == -1) goto failed; Py_DECREF(value); break; case While_kind: - result = PyType_GenericNew(While_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->While_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_expr(o->v.While.test); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.While.body, ast2obj_stmt); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == + -1) goto failed; Py_DECREF(value); break; case If_kind: - result = PyType_GenericNew(If_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->If_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_expr(o->v.If.test); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.If.body, ast2obj_stmt); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == + -1) goto failed; Py_DECREF(value); break; case With_kind: - result = PyType_GenericNew(With_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->With_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_list(o->v.With.items, ast2obj_withitem); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_items, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.With.body, ast2obj_stmt); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_string(o->v.With.type_comment); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->type_comment, + value) == -1) goto failed; Py_DECREF(value); break; case AsyncWith_kind: - result = PyType_GenericNew(AsyncWith_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->AsyncWith_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_items, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_string(o->v.AsyncWith.type_comment); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->type_comment, + value) == -1) goto failed; Py_DECREF(value); break; case Raise_kind: - result = PyType_GenericNew(Raise_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->Raise_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_expr(o->v.Raise.exc); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_exc, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->exc, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->v.Raise.cause); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_cause, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->cause, value) == -1) goto failed; Py_DECREF(value); break; case Try_kind: - result = PyType_GenericNew(Try_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->Try_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_list(o->v.Try.body, ast2obj_stmt); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_handlers, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->handlers, value) == + -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == + -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_finalbody, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->finalbody, value) + == -1) goto failed; Py_DECREF(value); break; case Assert_kind: - result = PyType_GenericNew(Assert_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->Assert_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_expr(o->v.Assert.test); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->v.Assert.msg); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_msg, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->msg, value) == -1) goto failed; Py_DECREF(value); break; case Import_kind: - result = PyType_GenericNew(Import_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->Import_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_list(o->v.Import.names, ast2obj_alias); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) goto failed; Py_DECREF(value); break; case ImportFrom_kind: - result = PyType_GenericNew(ImportFrom_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->ImportFrom_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_identifier(o->v.ImportFrom.module); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_module, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->module, value) == + -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_int(o->v.ImportFrom.level); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_level, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->level, value) == -1) goto failed; Py_DECREF(value); break; case Global_kind: - result = PyType_GenericNew(Global_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->Global_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_list(o->v.Global.names, ast2obj_identifier); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) goto failed; Py_DECREF(value); break; case Nonlocal_kind: - result = PyType_GenericNew(Nonlocal_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->Nonlocal_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) goto failed; Py_DECREF(value); break; case Expr_kind: - result = PyType_GenericNew(Expr_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->Expr_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_expr(o->v.Expr.value); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) goto failed; Py_DECREF(value); break; case Pass_kind: - result = PyType_GenericNew(Pass_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->Pass_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; break; case Break_kind: - result = PyType_GenericNew(Break_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->Break_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; break; case Continue_kind: - result = PyType_GenericNew(Continue_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->Continue_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; break; } value = ast2obj_int(o->lineno); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) + if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) goto failed; Py_DECREF(value); value = ast2obj_int(o->col_offset); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) + if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) + goto failed; + Py_DECREF(value); + value = ast2obj_int(o->end_lineno); + if (!value) goto failed; + if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) + goto failed; + Py_DECREF(value); + value = ast2obj_int(o->end_col_offset); + if (!value) goto failed; + if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) + < 0) goto failed; Py_DECREF(value); return result; @@ -3215,209 +4107,249 @@ ast2obj_expr(void* _o) { expr_ty o = (expr_ty)_o; PyObject *result = NULL, *value = NULL; + PyTypeObject *tp; if (!o) { Py_RETURN_NONE; } switch (o->kind) { case BoolOp_kind: - result = PyType_GenericNew(BoolOp_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->BoolOp_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_boolop(o->v.BoolOp.op); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->values, value) == + -1) + goto failed; + Py_DECREF(value); + break; + case NamedExpr_kind: + tp = (PyTypeObject *)astmodulestate_global->NamedExpr_type; + result = PyType_GenericNew(tp, NULL, NULL); + if (!result) goto failed; + value = ast2obj_expr(o->v.NamedExpr.target); + if (!value) goto failed; + if (PyObject_SetAttr(result, astmodulestate_global->target, value) == + -1) + goto failed; + Py_DECREF(value); + value = ast2obj_expr(o->v.NamedExpr.value); + if (!value) goto failed; + if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) goto failed; Py_DECREF(value); break; case BinOp_kind: - result = PyType_GenericNew(BinOp_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->BinOp_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_expr(o->v.BinOp.left); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_operator(o->v.BinOp.op); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->v.BinOp.right); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_right, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->right, value) == -1) goto failed; Py_DECREF(value); break; case UnaryOp_kind: - result = PyType_GenericNew(UnaryOp_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->UnaryOp_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_unaryop(o->v.UnaryOp.op); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->v.UnaryOp.operand); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_operand, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->operand, value) == + -1) goto failed; Py_DECREF(value); break; case Lambda_kind: - result = PyType_GenericNew(Lambda_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->Lambda_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_arguments(o->v.Lambda.args); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->v.Lambda.body); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) goto failed; Py_DECREF(value); break; case IfExp_kind: - result = PyType_GenericNew(IfExp_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->IfExp_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_expr(o->v.IfExp.test); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->v.IfExp.body); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->v.IfExp.orelse); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == + -1) goto failed; Py_DECREF(value); break; case Dict_kind: - result = PyType_GenericNew(Dict_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->Dict_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_keys, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->keys, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.Dict.values, ast2obj_expr); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->values, value) == + -1) goto failed; Py_DECREF(value); break; case Set_kind: - result = PyType_GenericNew(Set_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->Set_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_list(o->v.Set.elts, ast2obj_expr); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) goto failed; Py_DECREF(value); break; case ListComp_kind: - result = PyType_GenericNew(ListComp_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->ListComp_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_expr(o->v.ListComp.elt); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->generators, value) + == -1) goto failed; Py_DECREF(value); break; case SetComp_kind: - result = PyType_GenericNew(SetComp_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->SetComp_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_expr(o->v.SetComp.elt); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->generators, value) + == -1) goto failed; Py_DECREF(value); break; case DictComp_kind: - result = PyType_GenericNew(DictComp_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->DictComp_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_expr(o->v.DictComp.key); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_key, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->key, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->v.DictComp.value); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->generators, value) + == -1) goto failed; Py_DECREF(value); break; case GeneratorExp_kind: - result = PyType_GenericNew(GeneratorExp_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->GeneratorExp_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_expr(o->v.GeneratorExp.elt); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.GeneratorExp.generators, ast2obj_comprehension); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->generators, value) + == -1) goto failed; Py_DECREF(value); break; case Await_kind: - result = PyType_GenericNew(Await_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->Await_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_expr(o->v.Await.value); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) goto failed; Py_DECREF(value); break; case Yield_kind: - result = PyType_GenericNew(Yield_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->Yield_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_expr(o->v.Yield.value); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) goto failed; Py_DECREF(value); break; case YieldFrom_kind: - result = PyType_GenericNew(YieldFrom_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->YieldFrom_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_expr(o->v.YieldFrom.value); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) goto failed; Py_DECREF(value); break; case Compare_kind: - result = PyType_GenericNew(Compare_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->Compare_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_expr(o->v.Compare.left); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1) goto failed; Py_DECREF(value); { @@ -3428,224 +4360,225 @@ ast2obj_expr(void* _o) PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i))); } if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_ops, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->ops, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_comparators, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->comparators, value) + == -1) goto failed; Py_DECREF(value); break; case Call_kind: - result = PyType_GenericNew(Call_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->Call_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_expr(o->v.Call.func); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_func, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->func, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.Call.args, ast2obj_expr); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) - goto failed; - Py_DECREF(value); - break; - case Num_kind: - result = PyType_GenericNew(Num_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_object(o->v.Num.n); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_n, value) == -1) - goto failed; - Py_DECREF(value); - break; - case Str_kind: - result = PyType_GenericNew(Str_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_string(o->v.Str.s); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_s, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_string(o->v.Str.kind); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_kind, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) == + -1) goto failed; Py_DECREF(value); break; case FormattedValue_kind: - result = PyType_GenericNew(FormattedValue_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->FormattedValue_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_expr(o->v.FormattedValue.value); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_int(o->v.FormattedValue.conversion); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_conversion, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->conversion, value) + == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->v.FormattedValue.format_spec); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_format_spec, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->format_spec, value) + == -1) goto failed; Py_DECREF(value); break; case JoinedStr_kind: - result = PyType_GenericNew(JoinedStr_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->JoinedStr_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) - goto failed; - Py_DECREF(value); - break; - case Bytes_kind: - result = PyType_GenericNew(Bytes_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_bytes(o->v.Bytes.s); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_s, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_string(o->v.Bytes.kind); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_kind, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->values, value) == + -1) goto failed; Py_DECREF(value); break; - case NameConstant_kind: - result = PyType_GenericNew(NameConstant_type, NULL, NULL); + case Constant_kind: + tp = (PyTypeObject *)astmodulestate_global->Constant_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_singleton(o->v.NameConstant.value); + value = ast2obj_constant(o->v.Constant.value); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) goto failed; Py_DECREF(value); - break; - case Ellipsis_kind: - result = PyType_GenericNew(Ellipsis_type, NULL, NULL); - if (!result) goto failed; - break; - case Constant_kind: - result = PyType_GenericNew(Constant_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_constant(o->v.Constant.value); + value = ast2obj_string(o->v.Constant.kind); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->kind, value) == -1) goto failed; Py_DECREF(value); break; case Attribute_kind: - result = PyType_GenericNew(Attribute_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->Attribute_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_expr(o->v.Attribute.value); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_identifier(o->v.Attribute.attr); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_attr, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->attr, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr_context(o->v.Attribute.ctx); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) goto failed; Py_DECREF(value); break; case Subscript_kind: - result = PyType_GenericNew(Subscript_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->Subscript_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_expr(o->v.Subscript.value); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_slice(o->v.Subscript.slice); + value = ast2obj_expr(o->v.Subscript.slice); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_slice, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->slice, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr_context(o->v.Subscript.ctx); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) goto failed; Py_DECREF(value); break; case Starred_kind: - result = PyType_GenericNew(Starred_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->Starred_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_expr(o->v.Starred.value); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr_context(o->v.Starred.ctx); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) goto failed; Py_DECREF(value); break; case Name_kind: - result = PyType_GenericNew(Name_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->Name_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_identifier(o->v.Name.id); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_id, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->id, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr_context(o->v.Name.ctx); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) goto failed; Py_DECREF(value); break; case List_kind: - result = PyType_GenericNew(List_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->List_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_list(o->v.List.elts, ast2obj_expr); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr_context(o->v.List.ctx); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) goto failed; Py_DECREF(value); break; case Tuple_kind: - result = PyType_GenericNew(Tuple_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->Tuple_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr_context(o->v.Tuple.ctx); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) + goto failed; + Py_DECREF(value); + break; + case Slice_kind: + tp = (PyTypeObject *)astmodulestate_global->Slice_type; + result = PyType_GenericNew(tp, NULL, NULL); + if (!result) goto failed; + value = ast2obj_expr(o->v.Slice.lower); + if (!value) goto failed; + if (PyObject_SetAttr(result, astmodulestate_global->lower, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_expr(o->v.Slice.upper); + if (!value) goto failed; + if (PyObject_SetAttr(result, astmodulestate_global->upper, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_expr(o->v.Slice.step); + if (!value) goto failed; + if (PyObject_SetAttr(result, astmodulestate_global->step, value) == -1) goto failed; Py_DECREF(value); break; } value = ast2obj_int(o->lineno); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) + if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) goto failed; Py_DECREF(value); value = ast2obj_int(o->col_offset); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) + if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) + goto failed; + Py_DECREF(value); + value = ast2obj_int(o->end_lineno); + if (!value) goto failed; + if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) + goto failed; + Py_DECREF(value); + value = ast2obj_int(o->end_col_offset); + if (!value) goto failed; + if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) + < 0) goto failed; Py_DECREF(value); return result; @@ -3659,236 +4592,159 @@ PyObject* ast2obj_expr_context(expr_context_ty o) { switch(o) { case Load: - Py_INCREF(Load_singleton); - return Load_singleton; + Py_INCREF(astmodulestate_global->Load_singleton); + return astmodulestate_global->Load_singleton; case Store: - Py_INCREF(Store_singleton); - return Store_singleton; + Py_INCREF(astmodulestate_global->Store_singleton); + return astmodulestate_global->Store_singleton; case Del: - Py_INCREF(Del_singleton); - return Del_singleton; - case AugLoad: - Py_INCREF(AugLoad_singleton); - return AugLoad_singleton; - case AugStore: - Py_INCREF(AugStore_singleton); - return AugStore_singleton; - case Param: - Py_INCREF(Param_singleton); - return Param_singleton; - default: - /* should never happen, but just in case ... */ - PyErr_Format(PyExc_SystemError, "unknown expr_context found"); - return NULL; - } -} -PyObject* -ast2obj_slice(void* _o) -{ - slice_ty o = (slice_ty)_o; - PyObject *result = NULL, *value = NULL; - if (!o) { - Py_RETURN_NONE; - } - - switch (o->kind) { - case Slice_kind: - result = PyType_GenericNew(Slice_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_expr(o->v.Slice.lower); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_lower, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_expr(o->v.Slice.upper); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_upper, value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_expr(o->v.Slice.step); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_step, value) == -1) - goto failed; - Py_DECREF(value); - break; - case ExtSlice_kind: - result = PyType_GenericNew(ExtSlice_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_dims, value) == -1) - goto failed; - Py_DECREF(value); - break; - case Index_kind: - result = PyType_GenericNew(Index_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_expr(o->v.Index.value); - if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) - goto failed; - Py_DECREF(value); - break; + Py_INCREF(astmodulestate_global->Del_singleton); + return astmodulestate_global->Del_singleton; } - return result; -failed: - Py_XDECREF(value); - Py_XDECREF(result); - return NULL; + Py_UNREACHABLE(); } - PyObject* ast2obj_boolop(boolop_ty o) { switch(o) { case And: - Py_INCREF(And_singleton); - return And_singleton; + Py_INCREF(astmodulestate_global->And_singleton); + return astmodulestate_global->And_singleton; case Or: - Py_INCREF(Or_singleton); - return Or_singleton; - default: - /* should never happen, but just in case ... */ - PyErr_Format(PyExc_SystemError, "unknown boolop found"); - return NULL; + Py_INCREF(astmodulestate_global->Or_singleton); + return astmodulestate_global->Or_singleton; } + Py_UNREACHABLE(); } PyObject* ast2obj_operator(operator_ty o) { switch(o) { case Add: - Py_INCREF(Add_singleton); - return Add_singleton; + Py_INCREF(astmodulestate_global->Add_singleton); + return astmodulestate_global->Add_singleton; case Sub: - Py_INCREF(Sub_singleton); - return Sub_singleton; + Py_INCREF(astmodulestate_global->Sub_singleton); + return astmodulestate_global->Sub_singleton; case Mult: - Py_INCREF(Mult_singleton); - return Mult_singleton; + Py_INCREF(astmodulestate_global->Mult_singleton); + return astmodulestate_global->Mult_singleton; case MatMult: - Py_INCREF(MatMult_singleton); - return MatMult_singleton; + Py_INCREF(astmodulestate_global->MatMult_singleton); + return astmodulestate_global->MatMult_singleton; case Div: - Py_INCREF(Div_singleton); - return Div_singleton; + Py_INCREF(astmodulestate_global->Div_singleton); + return astmodulestate_global->Div_singleton; case Mod: - Py_INCREF(Mod_singleton); - return Mod_singleton; + Py_INCREF(astmodulestate_global->Mod_singleton); + return astmodulestate_global->Mod_singleton; case Pow: - Py_INCREF(Pow_singleton); - return Pow_singleton; + Py_INCREF(astmodulestate_global->Pow_singleton); + return astmodulestate_global->Pow_singleton; case LShift: - Py_INCREF(LShift_singleton); - return LShift_singleton; + Py_INCREF(astmodulestate_global->LShift_singleton); + return astmodulestate_global->LShift_singleton; case RShift: - Py_INCREF(RShift_singleton); - return RShift_singleton; + Py_INCREF(astmodulestate_global->RShift_singleton); + return astmodulestate_global->RShift_singleton; case BitOr: - Py_INCREF(BitOr_singleton); - return BitOr_singleton; + Py_INCREF(astmodulestate_global->BitOr_singleton); + return astmodulestate_global->BitOr_singleton; case BitXor: - Py_INCREF(BitXor_singleton); - return BitXor_singleton; + Py_INCREF(astmodulestate_global->BitXor_singleton); + return astmodulestate_global->BitXor_singleton; case BitAnd: - Py_INCREF(BitAnd_singleton); - return BitAnd_singleton; + Py_INCREF(astmodulestate_global->BitAnd_singleton); + return astmodulestate_global->BitAnd_singleton; case FloorDiv: - Py_INCREF(FloorDiv_singleton); - return FloorDiv_singleton; - default: - /* should never happen, but just in case ... */ - PyErr_Format(PyExc_SystemError, "unknown operator found"); - return NULL; + Py_INCREF(astmodulestate_global->FloorDiv_singleton); + return astmodulestate_global->FloorDiv_singleton; } + Py_UNREACHABLE(); } PyObject* ast2obj_unaryop(unaryop_ty o) { switch(o) { case Invert: - Py_INCREF(Invert_singleton); - return Invert_singleton; + Py_INCREF(astmodulestate_global->Invert_singleton); + return astmodulestate_global->Invert_singleton; case Not: - Py_INCREF(Not_singleton); - return Not_singleton; + Py_INCREF(astmodulestate_global->Not_singleton); + return astmodulestate_global->Not_singleton; case UAdd: - Py_INCREF(UAdd_singleton); - return UAdd_singleton; + Py_INCREF(astmodulestate_global->UAdd_singleton); + return astmodulestate_global->UAdd_singleton; case USub: - Py_INCREF(USub_singleton); - return USub_singleton; - default: - /* should never happen, but just in case ... */ - PyErr_Format(PyExc_SystemError, "unknown unaryop found"); - return NULL; + Py_INCREF(astmodulestate_global->USub_singleton); + return astmodulestate_global->USub_singleton; } + Py_UNREACHABLE(); } PyObject* ast2obj_cmpop(cmpop_ty o) { switch(o) { case Eq: - Py_INCREF(Eq_singleton); - return Eq_singleton; + Py_INCREF(astmodulestate_global->Eq_singleton); + return astmodulestate_global->Eq_singleton; case NotEq: - Py_INCREF(NotEq_singleton); - return NotEq_singleton; + Py_INCREF(astmodulestate_global->NotEq_singleton); + return astmodulestate_global->NotEq_singleton; case Lt: - Py_INCREF(Lt_singleton); - return Lt_singleton; + Py_INCREF(astmodulestate_global->Lt_singleton); + return astmodulestate_global->Lt_singleton; case LtE: - Py_INCREF(LtE_singleton); - return LtE_singleton; + Py_INCREF(astmodulestate_global->LtE_singleton); + return astmodulestate_global->LtE_singleton; case Gt: - Py_INCREF(Gt_singleton); - return Gt_singleton; + Py_INCREF(astmodulestate_global->Gt_singleton); + return astmodulestate_global->Gt_singleton; case GtE: - Py_INCREF(GtE_singleton); - return GtE_singleton; + Py_INCREF(astmodulestate_global->GtE_singleton); + return astmodulestate_global->GtE_singleton; case Is: - Py_INCREF(Is_singleton); - return Is_singleton; + Py_INCREF(astmodulestate_global->Is_singleton); + return astmodulestate_global->Is_singleton; case IsNot: - Py_INCREF(IsNot_singleton); - return IsNot_singleton; + Py_INCREF(astmodulestate_global->IsNot_singleton); + return astmodulestate_global->IsNot_singleton; case In: - Py_INCREF(In_singleton); - return In_singleton; + Py_INCREF(astmodulestate_global->In_singleton); + return astmodulestate_global->In_singleton; case NotIn: - Py_INCREF(NotIn_singleton); - return NotIn_singleton; - default: - /* should never happen, but just in case ... */ - PyErr_Format(PyExc_SystemError, "unknown cmpop found"); - return NULL; + Py_INCREF(astmodulestate_global->NotIn_singleton); + return astmodulestate_global->NotIn_singleton; } + Py_UNREACHABLE(); } PyObject* ast2obj_comprehension(void* _o) { comprehension_ty o = (comprehension_ty)_o; PyObject *result = NULL, *value = NULL; + PyTypeObject *tp; if (!o) { Py_RETURN_NONE; } - result = PyType_GenericNew(comprehension_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->comprehension_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) return NULL; value = ast2obj_expr(o->target); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->target, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->iter); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->ifs, ast2obj_expr); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_ifs, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->ifs, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_int(o->is_async); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_is_async, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->is_async, value) == -1) goto failed; Py_DECREF(value); return result; @@ -3903,39 +4759,52 @@ ast2obj_excepthandler(void* _o) { excepthandler_ty o = (excepthandler_ty)_o; PyObject *result = NULL, *value = NULL; + PyTypeObject *tp; if (!o) { Py_RETURN_NONE; } switch (o->kind) { case ExceptHandler_kind: - result = PyType_GenericNew(ExceptHandler_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->ExceptHandler_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_expr(o->v.ExceptHandler.type); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_type, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->type, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_identifier(o->v.ExceptHandler.name); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) goto failed; Py_DECREF(value); break; } value = ast2obj_int(o->lineno); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) + if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) goto failed; Py_DECREF(value); value = ast2obj_int(o->col_offset); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) + if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) + goto failed; + Py_DECREF(value); + value = ast2obj_int(o->end_lineno); + if (!value) goto failed; + if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) + goto failed; + Py_DECREF(value); + value = ast2obj_int(o->end_col_offset); + if (!value) goto failed; + if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) + < 0) goto failed; Py_DECREF(value); return result; @@ -3950,40 +4819,50 @@ ast2obj_arguments(void* _o) { arguments_ty o = (arguments_ty)_o; PyObject *result = NULL, *value = NULL; + PyTypeObject *tp; if (!o) { Py_RETURN_NONE; } - result = PyType_GenericNew(arguments_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->arguments_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) return NULL; + value = ast2obj_list(o->posonlyargs, ast2obj_arg); + if (!value) goto failed; + if (PyObject_SetAttr(result, astmodulestate_global->posonlyargs, value) == + -1) + goto failed; + Py_DECREF(value); value = ast2obj_list(o->args, ast2obj_arg); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_arg(o->vararg); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_vararg, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->vararg, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->kwonlyargs, ast2obj_arg); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_kwonlyargs, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->kwonlyargs, value) == + -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->kw_defaults, ast2obj_expr); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_kw_defaults, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->kw_defaults, value) == + -1) goto failed; Py_DECREF(value); value = ast2obj_arg(o->kwarg); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_kwarg, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->kwarg, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->defaults, ast2obj_expr); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_defaults, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->defaults, value) == -1) goto failed; Py_DECREF(value); return result; @@ -3998,35 +4877,50 @@ ast2obj_arg(void* _o) { arg_ty o = (arg_ty)_o; PyObject *result = NULL, *value = NULL; + PyTypeObject *tp; if (!o) { Py_RETURN_NONE; } - result = PyType_GenericNew(arg_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->arg_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) return NULL; value = ast2obj_identifier(o->arg); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->annotation); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) == + -1) goto failed; Py_DECREF(value); value = ast2obj_string(o->type_comment); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->type_comment, value) == + -1) goto failed; Py_DECREF(value); value = ast2obj_int(o->lineno); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) + if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) goto failed; Py_DECREF(value); value = ast2obj_int(o->col_offset); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) + if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) + goto failed; + Py_DECREF(value); + value = ast2obj_int(o->end_lineno); + if (!value) goto failed; + if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) + goto failed; + Py_DECREF(value); + value = ast2obj_int(o->end_col_offset); + if (!value) goto failed; + if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) + < 0) goto failed; Py_DECREF(value); return result; @@ -4041,20 +4935,43 @@ ast2obj_keyword(void* _o) { keyword_ty o = (keyword_ty)_o; PyObject *result = NULL, *value = NULL; + PyTypeObject *tp; if (!o) { Py_RETURN_NONE; } - result = PyType_GenericNew(keyword_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->keyword_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) return NULL; value = ast2obj_identifier(o->arg); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->value); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_int(o->lineno); + if (!value) goto failed; + if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) + goto failed; + Py_DECREF(value); + value = ast2obj_int(o->col_offset); + if (!value) goto failed; + if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) + goto failed; + Py_DECREF(value); + value = ast2obj_int(o->end_lineno); + if (!value) goto failed; + if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) + goto failed; + Py_DECREF(value); + value = ast2obj_int(o->end_col_offset); + if (!value) goto failed; + if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) + < 0) goto failed; Py_DECREF(value); return result; @@ -4069,20 +4986,22 @@ ast2obj_alias(void* _o) { alias_ty o = (alias_ty)_o; PyObject *result = NULL, *value = NULL; + PyTypeObject *tp; if (!o) { Py_RETURN_NONE; } - result = PyType_GenericNew(alias_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->alias_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) return NULL; value = ast2obj_identifier(o->name); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_identifier(o->asname); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_asname, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->asname, value) == -1) goto failed; Py_DECREF(value); return result; @@ -4097,20 +5016,24 @@ ast2obj_withitem(void* _o) { withitem_ty o = (withitem_ty)_o; PyObject *result = NULL, *value = NULL; + PyTypeObject *tp; if (!o) { Py_RETURN_NONE; } - result = PyType_GenericNew(withitem_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->withitem_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) return NULL; value = ast2obj_expr(o->context_expr); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_context_expr, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->context_expr, value) == + -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->optional_vars); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_optional_vars, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->optional_vars, value) + == -1) goto failed; Py_DECREF(value); return result; @@ -4125,22 +5048,25 @@ ast2obj_type_ignore(void* _o) { type_ignore_ty o = (type_ignore_ty)_o; PyObject *result = NULL, *value = NULL; + PyTypeObject *tp; if (!o) { Py_RETURN_NONE; } switch (o->kind) { case TypeIgnore_kind: - result = PyType_GenericNew(TypeIgnore_type, NULL, NULL); + tp = (PyTypeObject *)astmodulestate_global->TypeIgnore_type; + result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; value = ast2obj_int(o->v.TypeIgnore.lineno); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_lineno, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) == + -1) goto failed; Py_DECREF(value); value = ast2obj_string(o->v.TypeIgnore.tag); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_tag, value) == -1) + if (PyObject_SetAttr(result, astmodulestate_global->tag, value) == -1) goto failed; Py_DECREF(value); break; @@ -4159,12 +5085,14 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) int isinstance; PyObject *tmp = NULL; + PyObject *tp; if (obj == Py_None) { *out = NULL; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type); + tp = astmodulestate_global->Module_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -4172,7 +5100,7 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) asdl_seq* body; asdl_seq* type_ignores; - if (lookup_attr_id(obj, &PyId_body, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -4184,15 +5112,18 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - body = _Ta3_asdl_seq_new(len, arena); + body = _Py_asdl_seq_new(len, arena); if (body == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; - res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_stmt(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration"); @@ -4202,7 +5133,8 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_type_ignores, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->type_ignores, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -4214,15 +5146,18 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Module field \"type_ignores\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Module field \"type_ignores\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - type_ignores = _Ta3_asdl_seq_new(len, arena); + type_ignores = _Py_asdl_seq_new(len, arena); if (type_ignores == NULL) goto failed; for (i = 0; i < len; i++) { type_ignore_ty val; - res = obj2ast_type_ignore(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_type_ignore(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration"); @@ -4236,14 +5171,15 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type); + tp = astmodulestate_global->Interactive_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } if (isinstance) { asdl_seq* body; - if (lookup_attr_id(obj, &PyId_body, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -4255,15 +5191,18 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - body = _Ta3_asdl_seq_new(len, arena); + body = _Py_asdl_seq_new(len, arena); if (body == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; - res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_stmt(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration"); @@ -4277,14 +5216,15 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type); + tp = astmodulestate_global->Expression_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } if (isinstance) { expr_ty body; - if (lookup_attr_id(obj, &PyId_body, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -4301,7 +5241,8 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionType_type); + tp = astmodulestate_global->FunctionType_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -4309,7 +5250,8 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) asdl_seq* argtypes; expr_ty returns; - if (lookup_attr_id(obj, &PyId_argtypes, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->argtypes, &tmp) < + 0) { return 1; } if (tmp == NULL) { @@ -4321,15 +5263,18 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "FunctionType field \"argtypes\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "FunctionType field \"argtypes\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - argtypes = _Ta3_asdl_seq_new(len, arena); + argtypes = _Py_asdl_seq_new(len, arena); if (argtypes == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; - res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_expr(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration"); @@ -4339,7 +5284,8 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_returns, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < + 0) { return 1; } if (tmp == NULL) { @@ -4356,47 +5302,6 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - asdl_seq* body; - - if (lookup_attr_id(obj, &PyId_body, &tmp) < 0) { - return 1; - } - if (tmp == NULL) { - PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite"); - return 1; - } - else { - int res; - Py_ssize_t len; - Py_ssize_t i; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - body = _Ta3_asdl_seq_new(len, arena); - if (body == NULL) goto failed; - for (i = 0; i < len; i++) { - stmt_ty val; - res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); - if (res != 0) goto failed; - if (len != PyList_GET_SIZE(tmp)) { - PyErr_SetString(PyExc_RuntimeError, "Suite field \"body\" changed size during iteration"); - goto failed; - } - asdl_seq_SET(body, i, val); - } - Py_CLEAR(tmp); - } - *out = Suite(body, arena); - if (*out == NULL) goto failed; - return 0; - } PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj); failed: @@ -4410,14 +5315,17 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) int isinstance; PyObject *tmp = NULL; + PyObject *tp; int lineno; int col_offset; + int end_lineno; + int end_col_offset; if (obj == Py_None) { *out = NULL; return 0; } - if (lookup_attr_id(obj, &PyId_lineno, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -4430,7 +5338,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_col_offset, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) + { return 1; } if (tmp == NULL) { @@ -4443,7 +5352,36 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type); + if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) + { + return 1; + } + if (tmp == NULL || tmp == Py_None) { + Py_CLEAR(tmp); + end_lineno = 0; + } + else { + int res; + res = obj2ast_int(tmp, &end_lineno, arena); + if (res != 0) goto failed; + Py_CLEAR(tmp); + } + if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) + < 0) { + return 1; + } + if (tmp == NULL || tmp == Py_None) { + Py_CLEAR(tmp); + end_col_offset = 0; + } + else { + int res; + res = obj2ast_int(tmp, &end_col_offset, arena); + if (res != 0) goto failed; + Py_CLEAR(tmp); + } + tp = astmodulestate_global->FunctionDef_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -4455,7 +5393,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) expr_ty returns; string type_comment; - if (lookup_attr_id(obj, &PyId_name, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -4468,7 +5406,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_args, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -4481,7 +5419,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_body, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -4493,15 +5431,18 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - body = _Ta3_asdl_seq_new(len, arena); + body = _Py_asdl_seq_new(len, arena); if (body == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; - res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_stmt(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration"); @@ -4511,7 +5452,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_decorator_list, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -4523,15 +5465,18 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - decorator_list = _Ta3_asdl_seq_new(len, arena); + decorator_list = _Py_asdl_seq_new(len, arena); if (decorator_list == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; - res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_expr(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration"); @@ -4541,7 +5486,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_returns, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < + 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -4554,7 +5500,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_type_comment, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, + &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -4568,11 +5515,13 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_CLEAR(tmp); } *out = FunctionDef(name, args, body, decorator_list, returns, - type_comment, lineno, col_offset, arena); + type_comment, lineno, col_offset, end_lineno, + end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncFunctionDef_type); + tp = astmodulestate_global->AsyncFunctionDef_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -4584,7 +5533,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) expr_ty returns; string type_comment; - if (lookup_attr_id(obj, &PyId_name, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -4597,7 +5546,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_args, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -4610,7 +5559,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_body, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -4622,15 +5571,18 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - body = _Ta3_asdl_seq_new(len, arena); + body = _Py_asdl_seq_new(len, arena); if (body == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; - res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_stmt(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration"); @@ -4640,7 +5592,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_decorator_list, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -4652,15 +5605,18 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"decorator_list\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - decorator_list = _Ta3_asdl_seq_new(len, arena); + decorator_list = _Py_asdl_seq_new(len, arena); if (decorator_list == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; - res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_expr(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration"); @@ -4670,7 +5626,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_returns, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < + 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -4683,7 +5640,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_type_comment, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, + &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -4697,11 +5655,13 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_CLEAR(tmp); } *out = AsyncFunctionDef(name, args, body, decorator_list, returns, - type_comment, lineno, col_offset, arena); + type_comment, lineno, col_offset, end_lineno, + end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type); + tp = astmodulestate_global->ClassDef_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -4712,7 +5672,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) asdl_seq* body; asdl_seq* decorator_list; - if (lookup_attr_id(obj, &PyId_name, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -4725,7 +5685,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_bases, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->bases, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -4737,15 +5697,18 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - bases = _Ta3_asdl_seq_new(len, arena); + bases = _Py_asdl_seq_new(len, arena); if (bases == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; - res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_expr(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration"); @@ -4755,7 +5718,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_keywords, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) < + 0) { return 1; } if (tmp == NULL) { @@ -4767,15 +5731,18 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - keywords = _Ta3_asdl_seq_new(len, arena); + keywords = _Py_asdl_seq_new(len, arena); if (keywords == NULL) goto failed; for (i = 0; i < len; i++) { keyword_ty val; - res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_keyword(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration"); @@ -4785,7 +5752,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_body, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -4797,15 +5764,18 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - body = _Ta3_asdl_seq_new(len, arena); + body = _Py_asdl_seq_new(len, arena); if (body == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; - res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_stmt(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration"); @@ -4815,7 +5785,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_decorator_list, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -4827,15 +5798,18 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - decorator_list = _Ta3_asdl_seq_new(len, arena); + decorator_list = _Py_asdl_seq_new(len, arena); if (decorator_list == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; - res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_expr(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration"); @@ -4846,18 +5820,19 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_CLEAR(tmp); } *out = ClassDef(name, bases, keywords, body, decorator_list, lineno, - col_offset, arena); + col_offset, end_lineno, end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type); + tp = astmodulestate_global->Return_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } if (isinstance) { expr_ty value; - if (lookup_attr_id(obj, &PyId_value, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -4870,18 +5845,21 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - *out = Return(value, lineno, col_offset, arena); + *out = Return(value, lineno, col_offset, end_lineno, end_col_offset, + arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type); + tp = astmodulestate_global->Delete_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } if (isinstance) { asdl_seq* targets; - if (lookup_attr_id(obj, &PyId_targets, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) < + 0) { return 1; } if (tmp == NULL) { @@ -4893,15 +5871,18 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - targets = _Ta3_asdl_seq_new(len, arena); + targets = _Py_asdl_seq_new(len, arena); if (targets == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; - res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_expr(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration"); @@ -4911,11 +5892,13 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - *out = Delete(targets, lineno, col_offset, arena); + *out = Delete(targets, lineno, col_offset, end_lineno, end_col_offset, + arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type); + tp = astmodulestate_global->Assign_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -4924,7 +5907,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) expr_ty value; string type_comment; - if (lookup_attr_id(obj, &PyId_targets, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) < + 0) { return 1; } if (tmp == NULL) { @@ -4936,15 +5920,18 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - targets = _Ta3_asdl_seq_new(len, arena); + targets = _Py_asdl_seq_new(len, arena); if (targets == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; - res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_expr(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration"); @@ -4954,7 +5941,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_value, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -4967,7 +5954,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_type_comment, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, + &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -4980,11 +5968,13 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - *out = Assign(targets, value, type_comment, lineno, col_offset, arena); + *out = Assign(targets, value, type_comment, lineno, col_offset, + end_lineno, end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type); + tp = astmodulestate_global->AugAssign_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -4993,7 +5983,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) operator_ty op; expr_ty value; - if (lookup_attr_id(obj, &PyId_target, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) + { return 1; } if (tmp == NULL) { @@ -5006,7 +5997,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_op, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5019,7 +6010,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_value, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5032,11 +6023,13 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - *out = AugAssign(target, op, value, lineno, col_offset, arena); + *out = AugAssign(target, op, value, lineno, col_offset, end_lineno, + end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)AnnAssign_type); + tp = astmodulestate_global->AnnAssign_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -5046,7 +6039,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) expr_ty value; int simple; - if (lookup_attr_id(obj, &PyId_target, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) + { return 1; } if (tmp == NULL) { @@ -5059,7 +6053,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_annotation, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -5072,7 +6067,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_value, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -5085,7 +6080,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_simple, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->simple, &tmp) < 0) + { return 1; } if (tmp == NULL) { @@ -5099,11 +6095,12 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_CLEAR(tmp); } *out = AnnAssign(target, annotation, value, simple, lineno, col_offset, - arena); + end_lineno, end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)For_type); + tp = astmodulestate_global->For_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -5114,7 +6111,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) asdl_seq* orelse; string type_comment; - if (lookup_attr_id(obj, &PyId_target, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) + { return 1; } if (tmp == NULL) { @@ -5127,7 +6125,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_iter, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5140,7 +6138,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_body, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5152,15 +6150,18 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - body = _Ta3_asdl_seq_new(len, arena); + body = _Py_asdl_seq_new(len, arena); if (body == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; - res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_stmt(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration"); @@ -5170,7 +6171,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_orelse, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) + { return 1; } if (tmp == NULL) { @@ -5182,15 +6184,18 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - orelse = _Ta3_asdl_seq_new(len, arena); + orelse = _Py_asdl_seq_new(len, arena); if (orelse == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; - res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_stmt(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration"); @@ -5200,7 +6205,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_type_comment, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, + &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -5214,11 +6220,12 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_CLEAR(tmp); } *out = For(target, iter, body, orelse, type_comment, lineno, - col_offset, arena); + col_offset, end_lineno, end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncFor_type); + tp = astmodulestate_global->AsyncFor_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -5229,7 +6236,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) asdl_seq* orelse; string type_comment; - if (lookup_attr_id(obj, &PyId_target, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) + { return 1; } if (tmp == NULL) { @@ -5242,7 +6250,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_iter, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5255,7 +6263,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_body, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5267,15 +6275,18 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "AsyncFor field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "AsyncFor field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - body = _Ta3_asdl_seq_new(len, arena); + body = _Py_asdl_seq_new(len, arena); if (body == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; - res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_stmt(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration"); @@ -5285,7 +6296,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_orelse, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) + { return 1; } if (tmp == NULL) { @@ -5297,15 +6309,18 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "AsyncFor field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "AsyncFor field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - orelse = _Ta3_asdl_seq_new(len, arena); + orelse = _Py_asdl_seq_new(len, arena); if (orelse == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; - res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_stmt(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration"); @@ -5315,7 +6330,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_type_comment, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, + &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -5329,11 +6345,12 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_CLEAR(tmp); } *out = AsyncFor(target, iter, body, orelse, type_comment, lineno, - col_offset, arena); + col_offset, end_lineno, end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)While_type); + tp = astmodulestate_global->While_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -5342,7 +6359,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) asdl_seq* body; asdl_seq* orelse; - if (lookup_attr_id(obj, &PyId_test, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5355,7 +6372,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_body, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5367,15 +6384,18 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - body = _Ta3_asdl_seq_new(len, arena); + body = _Py_asdl_seq_new(len, arena); if (body == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; - res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_stmt(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration"); @@ -5385,7 +6405,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_orelse, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) + { return 1; } if (tmp == NULL) { @@ -5397,15 +6418,18 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - orelse = _Ta3_asdl_seq_new(len, arena); + orelse = _Py_asdl_seq_new(len, arena); if (orelse == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; - res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_stmt(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration"); @@ -5415,11 +6439,13 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - *out = While(test, body, orelse, lineno, col_offset, arena); + *out = While(test, body, orelse, lineno, col_offset, end_lineno, + end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)If_type); + tp = astmodulestate_global->If_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -5428,7 +6454,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) asdl_seq* body; asdl_seq* orelse; - if (lookup_attr_id(obj, &PyId_test, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5441,7 +6467,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_body, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5453,15 +6479,18 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - body = _Ta3_asdl_seq_new(len, arena); + body = _Py_asdl_seq_new(len, arena); if (body == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; - res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_stmt(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration"); @@ -5471,7 +6500,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_orelse, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) + { return 1; } if (tmp == NULL) { @@ -5483,15 +6513,18 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - orelse = _Ta3_asdl_seq_new(len, arena); + orelse = _Py_asdl_seq_new(len, arena); if (orelse == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; - res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_stmt(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration"); @@ -5501,11 +6534,13 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - *out = If(test, body, orelse, lineno, col_offset, arena); + *out = If(test, body, orelse, lineno, col_offset, end_lineno, + end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)With_type); + tp = astmodulestate_global->With_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -5514,7 +6549,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) asdl_seq* body; string type_comment; - if (lookup_attr_id(obj, &PyId_items, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5526,15 +6561,18 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - items = _Ta3_asdl_seq_new(len, arena); + items = _Py_asdl_seq_new(len, arena); if (items == NULL) goto failed; for (i = 0; i < len; i++) { withitem_ty val; - res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_withitem(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration"); @@ -5544,7 +6582,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_body, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5556,15 +6594,18 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - body = _Ta3_asdl_seq_new(len, arena); + body = _Py_asdl_seq_new(len, arena); if (body == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; - res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_stmt(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration"); @@ -5574,7 +6615,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_type_comment, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, + &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -5587,11 +6629,13 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - *out = With(items, body, type_comment, lineno, col_offset, arena); + *out = With(items, body, type_comment, lineno, col_offset, end_lineno, + end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncWith_type); + tp = astmodulestate_global->AsyncWith_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -5600,7 +6644,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) asdl_seq* body; string type_comment; - if (lookup_attr_id(obj, &PyId_items, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5612,15 +6656,18 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "AsyncWith field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "AsyncWith field \"items\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - items = _Ta3_asdl_seq_new(len, arena); + items = _Py_asdl_seq_new(len, arena); if (items == NULL) goto failed; for (i = 0; i < len; i++) { withitem_ty val; - res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_withitem(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration"); @@ -5630,7 +6677,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_body, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5642,15 +6689,18 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "AsyncWith field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "AsyncWith field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - body = _Ta3_asdl_seq_new(len, arena); + body = _Py_asdl_seq_new(len, arena); if (body == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; - res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_stmt(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration"); @@ -5660,7 +6710,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_type_comment, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, + &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -5673,11 +6724,13 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - *out = AsyncWith(items, body, type_comment, lineno, col_offset, arena); + *out = AsyncWith(items, body, type_comment, lineno, col_offset, + end_lineno, end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type); + tp = astmodulestate_global->Raise_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -5685,7 +6738,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) expr_ty exc; expr_ty cause; - if (lookup_attr_id(obj, &PyId_exc, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->exc, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -5698,7 +6751,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_cause, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->cause, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -5711,11 +6764,13 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - *out = Raise(exc, cause, lineno, col_offset, arena); + *out = Raise(exc, cause, lineno, col_offset, end_lineno, + end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)Try_type); + tp = astmodulestate_global->Try_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -5725,7 +6780,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) asdl_seq* orelse; asdl_seq* finalbody; - if (lookup_attr_id(obj, &PyId_body, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5737,15 +6792,18 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - body = _Ta3_asdl_seq_new(len, arena); + body = _Py_asdl_seq_new(len, arena); if (body == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; - res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_stmt(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration"); @@ -5755,7 +6813,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_handlers, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->handlers, &tmp) < + 0) { return 1; } if (tmp == NULL) { @@ -5767,15 +6826,18 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - handlers = _Ta3_asdl_seq_new(len, arena); + handlers = _Py_asdl_seq_new(len, arena); if (handlers == NULL) goto failed; for (i = 0; i < len; i++) { excepthandler_ty val; - res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_excepthandler(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration"); @@ -5785,7 +6847,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_orelse, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) + { return 1; } if (tmp == NULL) { @@ -5797,15 +6860,18 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - orelse = _Ta3_asdl_seq_new(len, arena); + orelse = _Py_asdl_seq_new(len, arena); if (orelse == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; - res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_stmt(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration"); @@ -5815,7 +6881,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_finalbody, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->finalbody, &tmp) < + 0) { return 1; } if (tmp == NULL) { @@ -5827,15 +6894,18 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - finalbody = _Ta3_asdl_seq_new(len, arena); + finalbody = _Py_asdl_seq_new(len, arena); if (finalbody == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; - res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_stmt(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration"); @@ -5846,11 +6916,12 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_CLEAR(tmp); } *out = Try(body, handlers, orelse, finalbody, lineno, col_offset, - arena); + end_lineno, end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type); + tp = astmodulestate_global->Assert_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -5858,7 +6929,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) expr_ty test; expr_ty msg; - if (lookup_attr_id(obj, &PyId_test, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5871,7 +6942,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_msg, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->msg, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -5884,18 +6955,20 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - *out = Assert(test, msg, lineno, col_offset, arena); + *out = Assert(test, msg, lineno, col_offset, end_lineno, + end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type); + tp = astmodulestate_global->Import_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } if (isinstance) { asdl_seq* names; - if (lookup_attr_id(obj, &PyId_names, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5907,15 +6980,18 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - names = _Ta3_asdl_seq_new(len, arena); + names = _Py_asdl_seq_new(len, arena); if (names == NULL) goto failed; for (i = 0; i < len; i++) { alias_ty val; - res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_alias(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration"); @@ -5925,11 +7001,13 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - *out = Import(names, lineno, col_offset, arena); + *out = Import(names, lineno, col_offset, end_lineno, end_col_offset, + arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type); + tp = astmodulestate_global->ImportFrom_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -5938,7 +7016,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) asdl_seq* names; int level; - if (lookup_attr_id(obj, &PyId_module, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->module, &tmp) < 0) + { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -5951,7 +7030,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_names, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5963,15 +7042,18 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - names = _Ta3_asdl_seq_new(len, arena); + names = _Py_asdl_seq_new(len, arena); if (names == NULL) goto failed; for (i = 0; i < len; i++) { alias_ty val; - res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_alias(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration"); @@ -5981,7 +7063,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_level, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->level, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -5994,18 +7076,20 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - *out = ImportFrom(module, names, level, lineno, col_offset, arena); + *out = ImportFrom(module, names, level, lineno, col_offset, end_lineno, + end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type); + tp = astmodulestate_global->Global_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } if (isinstance) { asdl_seq* names; - if (lookup_attr_id(obj, &PyId_names, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6017,15 +7101,18 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - names = _Ta3_asdl_seq_new(len, arena); + names = _Py_asdl_seq_new(len, arena); if (names == NULL) goto failed; for (i = 0; i < len; i++) { identifier val; - res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_identifier(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration"); @@ -6035,18 +7122,20 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - *out = Global(names, lineno, col_offset, arena); + *out = Global(names, lineno, col_offset, end_lineno, end_col_offset, + arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)Nonlocal_type); + tp = astmodulestate_global->Nonlocal_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } if (isinstance) { asdl_seq* names; - if (lookup_attr_id(obj, &PyId_names, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6058,15 +7147,18 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - names = _Ta3_asdl_seq_new(len, arena); + names = _Py_asdl_seq_new(len, arena); if (names == NULL) goto failed; for (i = 0; i < len; i++) { identifier val; - res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_identifier(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration"); @@ -6076,18 +7168,20 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - *out = Nonlocal(names, lineno, col_offset, arena); + *out = Nonlocal(names, lineno, col_offset, end_lineno, end_col_offset, + arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type); + tp = astmodulestate_global->Expr_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } if (isinstance) { expr_ty value; - if (lookup_attr_id(obj, &PyId_value, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6100,37 +7194,41 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - *out = Expr(value, lineno, col_offset, arena); + *out = Expr(value, lineno, col_offset, end_lineno, end_col_offset, + arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type); + tp = astmodulestate_global->Pass_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } if (isinstance) { - *out = Pass(lineno, col_offset, arena); + *out = Pass(lineno, col_offset, end_lineno, end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type); + tp = astmodulestate_global->Break_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } if (isinstance) { - *out = Break(lineno, col_offset, arena); + *out = Break(lineno, col_offset, end_lineno, end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type); + tp = astmodulestate_global->Continue_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } if (isinstance) { - *out = Continue(lineno, col_offset, arena); + *out = Continue(lineno, col_offset, end_lineno, end_col_offset, arena); if (*out == NULL) goto failed; return 0; } @@ -6147,14 +7245,17 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) int isinstance; PyObject *tmp = NULL; + PyObject *tp; int lineno; int col_offset; + int end_lineno; + int end_col_offset; if (obj == Py_None) { *out = NULL; return 0; } - if (lookup_attr_id(obj, &PyId_lineno, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6167,7 +7268,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_col_offset, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) + { return 1; } if (tmp == NULL) { @@ -6180,7 +7282,36 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type); + if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) + { + return 1; + } + if (tmp == NULL || tmp == Py_None) { + Py_CLEAR(tmp); + end_lineno = 0; + } + else { + int res; + res = obj2ast_int(tmp, &end_lineno, arena); + if (res != 0) goto failed; + Py_CLEAR(tmp); + } + if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) + < 0) { + return 1; + } + if (tmp == NULL || tmp == Py_None) { + Py_CLEAR(tmp); + end_col_offset = 0; + } + else { + int res; + res = obj2ast_int(tmp, &end_col_offset, arena); + if (res != 0) goto failed; + Py_CLEAR(tmp); + } + tp = astmodulestate_global->BoolOp_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -6188,7 +7319,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) boolop_ty op; asdl_seq* values; - if (lookup_attr_id(obj, &PyId_op, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6201,7 +7332,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_values, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) + { return 1; } if (tmp == NULL) { @@ -6213,15 +7345,18 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - values = _Ta3_asdl_seq_new(len, arena); + values = _Py_asdl_seq_new(len, arena); if (values == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; - res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_expr(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration"); @@ -6231,11 +7366,54 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - *out = BoolOp(op, values, lineno, col_offset, arena); + *out = BoolOp(op, values, lineno, col_offset, end_lineno, + end_col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + tp = astmodulestate_global->NamedExpr_type; + isinstance = PyObject_IsInstance(obj, tp); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + expr_ty target; + expr_ty value; + + if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) + { + return 1; + } + if (tmp == NULL) { + PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr"); + return 1; + } + else { + int res; + res = obj2ast_expr(tmp, &target, arena); + if (res != 0) goto failed; + Py_CLEAR(tmp); + } + if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { + return 1; + } + if (tmp == NULL) { + PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr"); + return 1; + } + else { + int res; + res = obj2ast_expr(tmp, &value, arena); + if (res != 0) goto failed; + Py_CLEAR(tmp); + } + *out = NamedExpr(target, value, lineno, col_offset, end_lineno, + end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type); + tp = astmodulestate_global->BinOp_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -6244,7 +7422,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) operator_ty op; expr_ty right; - if (lookup_attr_id(obj, &PyId_left, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6257,7 +7435,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_op, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6270,7 +7448,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_right, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->right, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6283,11 +7461,13 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - *out = BinOp(left, op, right, lineno, col_offset, arena); + *out = BinOp(left, op, right, lineno, col_offset, end_lineno, + end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type); + tp = astmodulestate_global->UnaryOp_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -6295,7 +7475,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) unaryop_ty op; expr_ty operand; - if (lookup_attr_id(obj, &PyId_op, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6308,7 +7488,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_operand, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->operand, &tmp) < + 0) { return 1; } if (tmp == NULL) { @@ -6321,11 +7502,13 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - *out = UnaryOp(op, operand, lineno, col_offset, arena); + *out = UnaryOp(op, operand, lineno, col_offset, end_lineno, + end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type); + tp = astmodulestate_global->Lambda_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -6333,7 +7516,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) arguments_ty args; expr_ty body; - if (lookup_attr_id(obj, &PyId_args, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6346,7 +7529,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_body, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6359,11 +7542,13 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - *out = Lambda(args, body, lineno, col_offset, arena); + *out = Lambda(args, body, lineno, col_offset, end_lineno, + end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type); + tp = astmodulestate_global->IfExp_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -6372,7 +7557,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty body; expr_ty orelse; - if (lookup_attr_id(obj, &PyId_test, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6385,7 +7570,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_body, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6398,7 +7583,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_orelse, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) + { return 1; } if (tmp == NULL) { @@ -6411,11 +7597,13 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - *out = IfExp(test, body, orelse, lineno, col_offset, arena); + *out = IfExp(test, body, orelse, lineno, col_offset, end_lineno, + end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type); + tp = astmodulestate_global->Dict_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -6423,7 +7611,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) asdl_seq* keys; asdl_seq* values; - if (lookup_attr_id(obj, &PyId_keys, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->keys, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6435,15 +7623,18 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - keys = _Ta3_asdl_seq_new(len, arena); + keys = _Py_asdl_seq_new(len, arena); if (keys == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; - res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_expr(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration"); @@ -6453,7 +7644,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_values, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) + { return 1; } if (tmp == NULL) { @@ -6465,15 +7657,18 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - values = _Ta3_asdl_seq_new(len, arena); + values = _Py_asdl_seq_new(len, arena); if (values == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; - res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_expr(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration"); @@ -6483,18 +7678,20 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - *out = Dict(keys, values, lineno, col_offset, arena); + *out = Dict(keys, values, lineno, col_offset, end_lineno, + end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)Set_type); + tp = astmodulestate_global->Set_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } if (isinstance) { asdl_seq* elts; - if (lookup_attr_id(obj, &PyId_elts, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6506,15 +7703,18 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - elts = _Ta3_asdl_seq_new(len, arena); + elts = _Py_asdl_seq_new(len, arena); if (elts == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; - res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_expr(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration"); @@ -6524,11 +7724,12 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - *out = Set(elts, lineno, col_offset, arena); + *out = Set(elts, lineno, col_offset, end_lineno, end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type); + tp = astmodulestate_global->ListComp_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -6536,7 +7737,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty elt; asdl_seq* generators; - if (lookup_attr_id(obj, &PyId_elt, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6549,7 +7750,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_generators, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -6561,15 +7763,18 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - generators = _Ta3_asdl_seq_new(len, arena); + generators = _Py_asdl_seq_new(len, arena); if (generators == NULL) goto failed; for (i = 0; i < len; i++) { comprehension_ty val; - res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_comprehension(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration"); @@ -6579,11 +7784,13 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - *out = ListComp(elt, generators, lineno, col_offset, arena); + *out = ListComp(elt, generators, lineno, col_offset, end_lineno, + end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)SetComp_type); + tp = astmodulestate_global->SetComp_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -6591,7 +7798,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty elt; asdl_seq* generators; - if (lookup_attr_id(obj, &PyId_elt, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6604,7 +7811,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_generators, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -6616,15 +7824,18 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - generators = _Ta3_asdl_seq_new(len, arena); + generators = _Py_asdl_seq_new(len, arena); if (generators == NULL) goto failed; for (i = 0; i < len; i++) { comprehension_ty val; - res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_comprehension(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration"); @@ -6634,11 +7845,13 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - *out = SetComp(elt, generators, lineno, col_offset, arena); + *out = SetComp(elt, generators, lineno, col_offset, end_lineno, + end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)DictComp_type); + tp = astmodulestate_global->DictComp_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -6647,7 +7860,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty value; asdl_seq* generators; - if (lookup_attr_id(obj, &PyId_key, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->key, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6660,7 +7873,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_value, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6673,7 +7886,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_generators, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -6685,15 +7899,18 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - generators = _Ta3_asdl_seq_new(len, arena); + generators = _Py_asdl_seq_new(len, arena); if (generators == NULL) goto failed; for (i = 0; i < len; i++) { comprehension_ty val; - res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_comprehension(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration"); @@ -6703,11 +7920,13 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - *out = DictComp(key, value, generators, lineno, col_offset, arena); + *out = DictComp(key, value, generators, lineno, col_offset, end_lineno, + end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type); + tp = astmodulestate_global->GeneratorExp_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -6715,7 +7934,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty elt; asdl_seq* generators; - if (lookup_attr_id(obj, &PyId_elt, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6728,7 +7947,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_generators, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -6740,15 +7960,18 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - generators = _Ta3_asdl_seq_new(len, arena); + generators = _Py_asdl_seq_new(len, arena); if (generators == NULL) goto failed; for (i = 0; i < len; i++) { comprehension_ty val; - res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_comprehension(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration"); @@ -6758,18 +7981,20 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - *out = GeneratorExp(elt, generators, lineno, col_offset, arena); + *out = GeneratorExp(elt, generators, lineno, col_offset, end_lineno, + end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)Await_type); + tp = astmodulestate_global->Await_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } if (isinstance) { expr_ty value; - if (lookup_attr_id(obj, &PyId_value, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6782,18 +8007,20 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - *out = Await(value, lineno, col_offset, arena); + *out = Await(value, lineno, col_offset, end_lineno, end_col_offset, + arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type); + tp = astmodulestate_global->Yield_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } if (isinstance) { expr_ty value; - if (lookup_attr_id(obj, &PyId_value, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -6806,18 +8033,20 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - *out = Yield(value, lineno, col_offset, arena); + *out = Yield(value, lineno, col_offset, end_lineno, end_col_offset, + arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)YieldFrom_type); + tp = astmodulestate_global->YieldFrom_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } if (isinstance) { expr_ty value; - if (lookup_attr_id(obj, &PyId_value, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6830,11 +8059,13 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - *out = YieldFrom(value, lineno, col_offset, arena); + *out = YieldFrom(value, lineno, col_offset, end_lineno, end_col_offset, + arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type); + tp = astmodulestate_global->Compare_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -6843,7 +8074,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) asdl_int_seq* ops; asdl_seq* comparators; - if (lookup_attr_id(obj, &PyId_left, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6856,7 +8087,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_ops, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->ops, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6868,15 +8099,18 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - ops = _Ta3_asdl_int_seq_new(len, arena); + ops = _Py_asdl_int_seq_new(len, arena); if (ops == NULL) goto failed; for (i = 0; i < len; i++) { cmpop_ty val; - res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_cmpop(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration"); @@ -6886,7 +8120,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_comparators, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->comparators, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -6898,15 +8133,18 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - comparators = _Ta3_asdl_seq_new(len, arena); + comparators = _Py_asdl_seq_new(len, arena); if (comparators == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; - res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_expr(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration"); @@ -6916,11 +8154,13 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - *out = Compare(left, ops, comparators, lineno, col_offset, arena); + *out = Compare(left, ops, comparators, lineno, col_offset, end_lineno, + end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type); + tp = astmodulestate_global->Call_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -6929,7 +8169,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) asdl_seq* args; asdl_seq* keywords; - if (lookup_attr_id(obj, &PyId_func, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->func, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6942,7 +8182,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_args, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6954,15 +8194,18 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - args = _Ta3_asdl_seq_new(len, arena); + args = _Py_asdl_seq_new(len, arena); if (args == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; - res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_expr(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration"); @@ -6972,7 +8215,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_keywords, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) < + 0) { return 1; } if (tmp == NULL) { @@ -6984,15 +8228,18 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - keywords = _Ta3_asdl_seq_new(len, arena); + keywords = _Py_asdl_seq_new(len, arena); if (keywords == NULL) goto failed; for (i = 0; i < len; i++) { keyword_ty val; - res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_keyword(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration"); @@ -7002,73 +8249,13 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - *out = Call(func, args, keywords, lineno, col_offset, arena); + *out = Call(func, args, keywords, lineno, col_offset, end_lineno, + end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)Num_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - object n; - - if (lookup_attr_id(obj, &PyId_n, &tmp) < 0) { - return 1; - } - if (tmp == NULL) { - PyErr_SetString(PyExc_TypeError, "required field \"n\" missing from Num"); - return 1; - } - else { - int res; - res = obj2ast_object(tmp, &n, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } - *out = Num(n, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Str_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - string s; - string kind; - - if (lookup_attr_id(obj, &PyId_s, &tmp) < 0) { - return 1; - } - if (tmp == NULL) { - PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Str"); - return 1; - } - else { - int res; - res = obj2ast_string(tmp, &s, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } - if (lookup_attr_id(obj, &PyId_kind, &tmp) < 0) { - return 1; - } - if (tmp == NULL) { - PyErr_SetString(PyExc_TypeError, "required field \"kind\" missing from Str"); - return 1; - } - else { - int res; - res = obj2ast_string(tmp, &kind, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } - *out = Str(s, kind, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)FormattedValue_type); + tp = astmodulestate_global->FormattedValue_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -7077,7 +8264,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) int conversion; expr_ty format_spec; - if (lookup_attr_id(obj, &PyId_value, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7090,7 +8277,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_conversion, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->conversion, &tmp) + < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -7103,7 +8291,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_format_spec, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->format_spec, &tmp) + < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -7117,18 +8306,20 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_CLEAR(tmp); } *out = FormattedValue(value, conversion, format_spec, lineno, - col_offset, arena); + col_offset, end_lineno, end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)JoinedStr_type); + tp = astmodulestate_global->JoinedStr_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } if (isinstance) { asdl_seq* values; - if (lookup_attr_id(obj, &PyId_values, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) + { return 1; } if (tmp == NULL) { @@ -7140,15 +8331,18 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "JoinedStr field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "JoinedStr field \"values\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - values = _Ta3_asdl_seq_new(len, arena); + values = _Py_asdl_seq_new(len, arena); if (values == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; - res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_expr(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration"); @@ -7158,107 +8352,53 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - *out = JoinedStr(values, lineno, col_offset, arena); + *out = JoinedStr(values, lineno, col_offset, end_lineno, + end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)Bytes_type); + tp = astmodulestate_global->Constant_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } if (isinstance) { - bytes s; + constant value; string kind; - if (lookup_attr_id(obj, &PyId_s, &tmp) < 0) { - return 1; - } - if (tmp == NULL) { - PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Bytes"); - return 1; - } - else { - int res; - res = obj2ast_bytes(tmp, &s, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } - if (lookup_attr_id(obj, &PyId_kind, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { return 1; } if (tmp == NULL) { - PyErr_SetString(PyExc_TypeError, "required field \"kind\" missing from Bytes"); + PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant"); return 1; } else { int res; - res = obj2ast_string(tmp, &kind, arena); + res = obj2ast_constant(tmp, &value, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - *out = Bytes(s, kind, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)NameConstant_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - singleton value; - - if (lookup_attr_id(obj, &PyId_value, &tmp) < 0) { - return 1; - } - if (tmp == NULL) { - PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NameConstant"); + if (_PyObject_LookupAttr(obj, astmodulestate_global->kind, &tmp) < 0) { return 1; } - else { - int res; - res = obj2ast_singleton(tmp, &value, arena); - if (res != 0) goto failed; + if (tmp == NULL || tmp == Py_None) { Py_CLEAR(tmp); - } - *out = NameConstant(value, lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Ellipsis_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - - *out = Ellipsis(lineno, col_offset, arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Constant_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - constant value; - - if (lookup_attr_id(obj, &PyId_value, &tmp) < 0) { - return 1; - } - if (tmp == NULL) { - PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant"); - return 1; + kind = NULL; } else { int res; - res = obj2ast_constant(tmp, &value, arena); + res = obj2ast_string(tmp, &kind, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - *out = Constant(value, lineno, col_offset, arena); + *out = Constant(value, kind, lineno, col_offset, end_lineno, + end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type); + tp = astmodulestate_global->Attribute_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -7267,7 +8407,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) identifier attr; expr_context_ty ctx; - if (lookup_attr_id(obj, &PyId_value, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7280,7 +8420,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_attr, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->attr, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7293,7 +8433,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_ctx, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7306,20 +8446,22 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - *out = Attribute(value, attr, ctx, lineno, col_offset, arena); + *out = Attribute(value, attr, ctx, lineno, col_offset, end_lineno, + end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type); + tp = astmodulestate_global->Subscript_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } if (isinstance) { expr_ty value; - slice_ty slice; + expr_ty slice; expr_context_ty ctx; - if (lookup_attr_id(obj, &PyId_value, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7332,7 +8474,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_slice, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->slice, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7341,11 +8483,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_slice(tmp, &slice, arena); + res = obj2ast_expr(tmp, &slice, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_ctx, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7358,11 +8500,13 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - *out = Subscript(value, slice, ctx, lineno, col_offset, arena); + *out = Subscript(value, slice, ctx, lineno, col_offset, end_lineno, + end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)Starred_type); + tp = astmodulestate_global->Starred_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -7370,7 +8514,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty value; expr_context_ty ctx; - if (lookup_attr_id(obj, &PyId_value, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7383,7 +8527,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_ctx, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7396,11 +8540,13 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - *out = Starred(value, ctx, lineno, col_offset, arena); + *out = Starred(value, ctx, lineno, col_offset, end_lineno, + end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type); + tp = astmodulestate_global->Name_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -7408,7 +8554,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) identifier id; expr_context_ty ctx; - if (lookup_attr_id(obj, &PyId_id, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->id, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7421,7 +8567,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_ctx, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7434,11 +8580,13 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - *out = Name(id, ctx, lineno, col_offset, arena); + *out = Name(id, ctx, lineno, col_offset, end_lineno, end_col_offset, + arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)List_type); + tp = astmodulestate_global->List_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -7446,7 +8594,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) asdl_seq* elts; expr_context_ty ctx; - if (lookup_attr_id(obj, &PyId_elts, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7458,15 +8606,18 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - elts = _Ta3_asdl_seq_new(len, arena); + elts = _Py_asdl_seq_new(len, arena); if (elts == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; - res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_expr(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration"); @@ -7476,7 +8627,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_ctx, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7489,11 +8640,13 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - *out = List(elts, ctx, lineno, col_offset, arena); + *out = List(elts, ctx, lineno, col_offset, end_lineno, end_col_offset, + arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type); + tp = astmodulestate_global->Tuple_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -7501,7 +8654,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) asdl_seq* elts; expr_context_ty ctx; - if (lookup_attr_id(obj, &PyId_elts, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7513,15 +8666,18 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - elts = _Ta3_asdl_seq_new(len, arena); + elts = _Py_asdl_seq_new(len, arena); if (elts == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; - res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_expr(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration"); @@ -7531,7 +8687,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_ctx, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7544,87 +8700,13 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - *out = Tuple(elts, ctx, lineno, col_offset, arena); + *out = Tuple(elts, ctx, lineno, col_offset, end_lineno, end_col_offset, + arena); if (*out == NULL) goto failed; return 0; } - - PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj); - failed: - Py_XDECREF(tmp); - return 1; -} - -int -obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) -{ - int isinstance; - - isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - *out = Load; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - *out = Store; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - *out = Del; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - *out = AugLoad; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - *out = AugStore; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - *out = Param; - return 0; - } - - PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj); - return 1; -} - -int -obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) -{ - int isinstance; - - PyObject *tmp = NULL; - - if (obj == Py_None) { - *out = NULL; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type); + tp = astmodulestate_global->Slice_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -7633,7 +8715,7 @@ obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) expr_ty upper; expr_ty step; - if (lookup_attr_id(obj, &PyId_lower, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->lower, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -7646,7 +8728,7 @@ obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_upper, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->upper, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -7659,7 +8741,7 @@ obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_step, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->step, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -7672,79 +8754,49 @@ obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - *out = Slice(lower, upper, step, arena); + *out = Slice(lower, upper, step, lineno, col_offset, end_lineno, + end_col_offset, arena); if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type); + + PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj); + failed: + Py_XDECREF(tmp); + return 1; +} + +int +obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) +{ + int isinstance; + + isinstance = PyObject_IsInstance(obj, astmodulestate_global->Load_type); if (isinstance == -1) { return 1; } if (isinstance) { - asdl_seq* dims; - - if (lookup_attr_id(obj, &PyId_dims, &tmp) < 0) { - return 1; - } - if (tmp == NULL) { - PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice"); - return 1; - } - else { - int res; - Py_ssize_t len; - Py_ssize_t i; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - dims = _Ta3_asdl_seq_new(len, arena); - if (dims == NULL) goto failed; - for (i = 0; i < len; i++) { - slice_ty val; - res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &val, arena); - if (res != 0) goto failed; - if (len != PyList_GET_SIZE(tmp)) { - PyErr_SetString(PyExc_RuntimeError, "ExtSlice field \"dims\" changed size during iteration"); - goto failed; - } - asdl_seq_SET(dims, i, val); - } - Py_CLEAR(tmp); - } - *out = ExtSlice(dims, arena); - if (*out == NULL) goto failed; + *out = Load; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type); + isinstance = PyObject_IsInstance(obj, astmodulestate_global->Store_type); if (isinstance == -1) { return 1; } if (isinstance) { - expr_ty value; - - if (lookup_attr_id(obj, &PyId_value, &tmp) < 0) { - return 1; - } - if (tmp == NULL) { - PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index"); - return 1; - } - else { - int res; - res = obj2ast_expr(tmp, &value, arena); - if (res != 0) goto failed; - Py_CLEAR(tmp); - } - *out = Index(value, arena); - if (*out == NULL) goto failed; + *out = Store; + return 0; + } + isinstance = PyObject_IsInstance(obj, astmodulestate_global->Del_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + *out = Del; return 0; } - PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj); - failed: - Py_XDECREF(tmp); + PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj); return 1; } @@ -7753,7 +8805,7 @@ obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) { int isinstance; - isinstance = PyObject_IsInstance(obj, (PyObject *)And_type); + isinstance = PyObject_IsInstance(obj, astmodulestate_global->And_type); if (isinstance == -1) { return 1; } @@ -7761,7 +8813,7 @@ obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) *out = And; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type); + isinstance = PyObject_IsInstance(obj, astmodulestate_global->Or_type); if (isinstance == -1) { return 1; } @@ -7779,7 +8831,7 @@ obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) { int isinstance; - isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type); + isinstance = PyObject_IsInstance(obj, astmodulestate_global->Add_type); if (isinstance == -1) { return 1; } @@ -7787,7 +8839,7 @@ obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) *out = Add; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type); + isinstance = PyObject_IsInstance(obj, astmodulestate_global->Sub_type); if (isinstance == -1) { return 1; } @@ -7795,7 +8847,7 @@ obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) *out = Sub; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type); + isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mult_type); if (isinstance == -1) { return 1; } @@ -7803,7 +8855,7 @@ obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) *out = Mult; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject *)MatMult_type); + isinstance = PyObject_IsInstance(obj, astmodulestate_global->MatMult_type); if (isinstance == -1) { return 1; } @@ -7811,7 +8863,7 @@ obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) *out = MatMult; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type); + isinstance = PyObject_IsInstance(obj, astmodulestate_global->Div_type); if (isinstance == -1) { return 1; } @@ -7819,7 +8871,7 @@ obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) *out = Div; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type); + isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mod_type); if (isinstance == -1) { return 1; } @@ -7827,7 +8879,7 @@ obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) *out = Mod; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type); + isinstance = PyObject_IsInstance(obj, astmodulestate_global->Pow_type); if (isinstance == -1) { return 1; } @@ -7835,7 +8887,7 @@ obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) *out = Pow; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type); + isinstance = PyObject_IsInstance(obj, astmodulestate_global->LShift_type); if (isinstance == -1) { return 1; } @@ -7843,7 +8895,7 @@ obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) *out = LShift; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type); + isinstance = PyObject_IsInstance(obj, astmodulestate_global->RShift_type); if (isinstance == -1) { return 1; } @@ -7851,7 +8903,7 @@ obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) *out = RShift; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type); + isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitOr_type); if (isinstance == -1) { return 1; } @@ -7859,7 +8911,7 @@ obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) *out = BitOr; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type); + isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitXor_type); if (isinstance == -1) { return 1; } @@ -7867,7 +8919,7 @@ obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) *out = BitXor; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type); + isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitAnd_type); if (isinstance == -1) { return 1; } @@ -7875,7 +8927,7 @@ obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) *out = BitAnd; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type); + isinstance = PyObject_IsInstance(obj, astmodulestate_global->FloorDiv_type); if (isinstance == -1) { return 1; } @@ -7893,7 +8945,7 @@ obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) { int isinstance; - isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type); + isinstance = PyObject_IsInstance(obj, astmodulestate_global->Invert_type); if (isinstance == -1) { return 1; } @@ -7901,7 +8953,7 @@ obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) *out = Invert; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type); + isinstance = PyObject_IsInstance(obj, astmodulestate_global->Not_type); if (isinstance == -1) { return 1; } @@ -7909,7 +8961,7 @@ obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) *out = Not; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type); + isinstance = PyObject_IsInstance(obj, astmodulestate_global->UAdd_type); if (isinstance == -1) { return 1; } @@ -7917,7 +8969,7 @@ obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) *out = UAdd; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type); + isinstance = PyObject_IsInstance(obj, astmodulestate_global->USub_type); if (isinstance == -1) { return 1; } @@ -7935,7 +8987,7 @@ obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) { int isinstance; - isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type); + isinstance = PyObject_IsInstance(obj, astmodulestate_global->Eq_type); if (isinstance == -1) { return 1; } @@ -7943,7 +8995,7 @@ obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) *out = Eq; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type); + isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotEq_type); if (isinstance == -1) { return 1; } @@ -7951,7 +9003,7 @@ obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) *out = NotEq; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type); + isinstance = PyObject_IsInstance(obj, astmodulestate_global->Lt_type); if (isinstance == -1) { return 1; } @@ -7959,7 +9011,7 @@ obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) *out = Lt; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type); + isinstance = PyObject_IsInstance(obj, astmodulestate_global->LtE_type); if (isinstance == -1) { return 1; } @@ -7967,7 +9019,7 @@ obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) *out = LtE; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type); + isinstance = PyObject_IsInstance(obj, astmodulestate_global->Gt_type); if (isinstance == -1) { return 1; } @@ -7975,7 +9027,7 @@ obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) *out = Gt; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type); + isinstance = PyObject_IsInstance(obj, astmodulestate_global->GtE_type); if (isinstance == -1) { return 1; } @@ -7983,7 +9035,7 @@ obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) *out = GtE; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type); + isinstance = PyObject_IsInstance(obj, astmodulestate_global->Is_type); if (isinstance == -1) { return 1; } @@ -7991,7 +9043,7 @@ obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) *out = Is; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type); + isinstance = PyObject_IsInstance(obj, astmodulestate_global->IsNot_type); if (isinstance == -1) { return 1; } @@ -7999,7 +9051,7 @@ obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) *out = IsNot; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject *)In_type); + isinstance = PyObject_IsInstance(obj, astmodulestate_global->In_type); if (isinstance == -1) { return 1; } @@ -8007,7 +9059,7 @@ obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) *out = In; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type); + isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotIn_type); if (isinstance == -1) { return 1; } @@ -8029,7 +9081,7 @@ obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) asdl_seq* ifs; int is_async; - if (lookup_attr_id(obj, &PyId_target, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8042,7 +9094,7 @@ obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_iter, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8055,7 +9107,7 @@ obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_ifs, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->ifs, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8067,15 +9119,18 @@ obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - ifs = _Ta3_asdl_seq_new(len, arena); + ifs = _Py_asdl_seq_new(len, arena); if (ifs == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; - res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_expr(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration"); @@ -8085,7 +9140,7 @@ obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_is_async, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->is_async, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8111,14 +9166,17 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) int isinstance; PyObject *tmp = NULL; + PyObject *tp; int lineno; int col_offset; + int end_lineno; + int end_col_offset; if (obj == Py_None) { *out = NULL; return 0; } - if (lookup_attr_id(obj, &PyId_lineno, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8131,7 +9189,8 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_col_offset, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) + { return 1; } if (tmp == NULL) { @@ -8144,7 +9203,36 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type); + if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) + { + return 1; + } + if (tmp == NULL || tmp == Py_None) { + Py_CLEAR(tmp); + end_lineno = 0; + } + else { + int res; + res = obj2ast_int(tmp, &end_lineno, arena); + if (res != 0) goto failed; + Py_CLEAR(tmp); + } + if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) + < 0) { + return 1; + } + if (tmp == NULL || tmp == Py_None) { + Py_CLEAR(tmp); + end_col_offset = 0; + } + else { + int res; + res = obj2ast_int(tmp, &end_col_offset, arena); + if (res != 0) goto failed; + Py_CLEAR(tmp); + } + tp = astmodulestate_global->ExceptHandler_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -8153,7 +9241,7 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) identifier name; asdl_seq* body; - if (lookup_attr_id(obj, &PyId_type, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->type, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -8166,7 +9254,7 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_name, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -8179,7 +9267,7 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_body, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8191,15 +9279,18 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - body = _Ta3_asdl_seq_new(len, arena); + body = _Py_asdl_seq_new(len, arena); if (body == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; - res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_stmt(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration"); @@ -8209,7 +9300,8 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - *out = ExceptHandler(type, name, body, lineno, col_offset, arena); + *out = ExceptHandler(type, name, body, lineno, col_offset, end_lineno, + end_col_offset, arena); if (*out == NULL) goto failed; return 0; } @@ -8224,6 +9316,7 @@ int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) { PyObject* tmp = NULL; + asdl_seq* posonlyargs; asdl_seq* args; arg_ty vararg; asdl_seq* kwonlyargs; @@ -8231,7 +9324,41 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) arg_ty kwarg; asdl_seq* defaults; - if (lookup_attr_id(obj, &PyId_args, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->posonlyargs, &tmp) < + 0) { + return 1; + } + if (tmp == NULL) { + PyErr_SetString(PyExc_TypeError, "required field \"posonlyargs\" missing from arguments"); + return 1; + } + else { + int res; + Py_ssize_t len; + Py_ssize_t i; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "arguments field \"posonlyargs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + goto failed; + } + len = PyList_GET_SIZE(tmp); + posonlyargs = _Py_asdl_seq_new(len, arena); + if (posonlyargs == NULL) goto failed; + for (i = 0; i < len; i++) { + arg_ty val; + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_arg(tmp2, &val, arena); + Py_DECREF(tmp2); + if (res != 0) goto failed; + if (len != PyList_GET_SIZE(tmp)) { + PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration"); + goto failed; + } + asdl_seq_SET(posonlyargs, i, val); + } + Py_CLEAR(tmp); + } + if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8243,15 +9370,18 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - args = _Ta3_asdl_seq_new(len, arena); + args = _Py_asdl_seq_new(len, arena); if (args == NULL) goto failed; for (i = 0; i < len; i++) { arg_ty val; - res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_arg(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration"); @@ -8261,7 +9391,7 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_vararg, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->vararg, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -8274,7 +9404,8 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_kwonlyargs, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->kwonlyargs, &tmp) < 0) + { return 1; } if (tmp == NULL) { @@ -8286,15 +9417,18 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - kwonlyargs = _Ta3_asdl_seq_new(len, arena); + kwonlyargs = _Py_asdl_seq_new(len, arena); if (kwonlyargs == NULL) goto failed; for (i = 0; i < len; i++) { arg_ty val; - res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_arg(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration"); @@ -8304,7 +9438,8 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_kw_defaults, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->kw_defaults, &tmp) < + 0) { return 1; } if (tmp == NULL) { @@ -8316,15 +9451,18 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - kw_defaults = _Ta3_asdl_seq_new(len, arena); + kw_defaults = _Py_asdl_seq_new(len, arena); if (kw_defaults == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; - res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_expr(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration"); @@ -8334,7 +9472,7 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_kwarg, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->kwarg, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -8347,7 +9485,7 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_defaults, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->defaults, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8359,15 +9497,18 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - defaults = _Ta3_asdl_seq_new(len, arena); + defaults = _Py_asdl_seq_new(len, arena); if (defaults == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; - res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); + PyObject *tmp2 = PyList_GET_ITEM(tmp, i); + Py_INCREF(tmp2); + res = obj2ast_expr(tmp2, &val, arena); + Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration"); @@ -8377,8 +9518,8 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - *out = arguments(args, vararg, kwonlyargs, kw_defaults, kwarg, defaults, - arena); + *out = arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults, kwarg, + defaults, arena); return 0; failed: Py_XDECREF(tmp); @@ -8394,8 +9535,10 @@ obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) string type_comment; int lineno; int col_offset; + int end_lineno; + int end_col_offset; - if (lookup_attr_id(obj, &PyId_arg, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8408,7 +9551,8 @@ obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_annotation, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) < 0) + { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -8421,7 +9565,8 @@ obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_type_comment, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, &tmp) < + 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -8434,7 +9579,7 @@ obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_lineno, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8447,7 +9592,8 @@ obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_col_offset, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) + { return 1; } if (tmp == NULL) { @@ -8460,7 +9606,36 @@ obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - *out = arg(arg, annotation, type_comment, lineno, col_offset, arena); + if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) + { + return 1; + } + if (tmp == NULL || tmp == Py_None) { + Py_CLEAR(tmp); + end_lineno = 0; + } + else { + int res; + res = obj2ast_int(tmp, &end_lineno, arena); + if (res != 0) goto failed; + Py_CLEAR(tmp); + } + if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) + < 0) { + return 1; + } + if (tmp == NULL || tmp == Py_None) { + Py_CLEAR(tmp); + end_col_offset = 0; + } + else { + int res; + res = obj2ast_int(tmp, &end_col_offset, arena); + if (res != 0) goto failed; + Py_CLEAR(tmp); + } + *out = arg(arg, annotation, type_comment, lineno, col_offset, end_lineno, + end_col_offset, arena); return 0; failed: Py_XDECREF(tmp); @@ -8473,8 +9648,12 @@ obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) PyObject* tmp = NULL; identifier arg; expr_ty value; + int lineno; + int col_offset; + int end_lineno; + int end_col_offset; - if (lookup_attr_id(obj, &PyId_arg, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -8487,7 +9666,7 @@ obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_value, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8500,7 +9679,63 @@ obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - *out = keyword(arg, value, arena); + if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { + return 1; + } + if (tmp == NULL) { + PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from keyword"); + return 1; + } + else { + int res; + res = obj2ast_int(tmp, &lineno, arena); + if (res != 0) goto failed; + Py_CLEAR(tmp); + } + if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) + { + return 1; + } + if (tmp == NULL) { + PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from keyword"); + return 1; + } + else { + int res; + res = obj2ast_int(tmp, &col_offset, arena); + if (res != 0) goto failed; + Py_CLEAR(tmp); + } + if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) + { + return 1; + } + if (tmp == NULL || tmp == Py_None) { + Py_CLEAR(tmp); + end_lineno = 0; + } + else { + int res; + res = obj2ast_int(tmp, &end_lineno, arena); + if (res != 0) goto failed; + Py_CLEAR(tmp); + } + if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) + < 0) { + return 1; + } + if (tmp == NULL || tmp == Py_None) { + Py_CLEAR(tmp); + end_col_offset = 0; + } + else { + int res; + res = obj2ast_int(tmp, &end_col_offset, arena); + if (res != 0) goto failed; + Py_CLEAR(tmp); + } + *out = keyword(arg, value, lineno, col_offset, end_lineno, end_col_offset, + arena); return 0; failed: Py_XDECREF(tmp); @@ -8514,7 +9749,7 @@ obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) identifier name; identifier asname; - if (lookup_attr_id(obj, &PyId_name, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8527,7 +9762,7 @@ obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_asname, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->asname, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -8554,7 +9789,8 @@ obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) expr_ty context_expr; expr_ty optional_vars; - if (lookup_attr_id(obj, &PyId_context_expr, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->context_expr, &tmp) < + 0) { return 1; } if (tmp == NULL) { @@ -8567,7 +9803,8 @@ obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_optional_vars, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->optional_vars, &tmp) < + 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -8593,12 +9830,14 @@ obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena) int isinstance; PyObject *tmp = NULL; + PyObject *tp; if (obj == Py_None) { *out = NULL; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)TypeIgnore_type); + tp = astmodulestate_global->TypeIgnore_type; + isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; } @@ -8606,7 +9845,8 @@ obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena) int lineno; string tag; - if (lookup_attr_id(obj, &PyId_lineno, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) + { return 1; } if (tmp == NULL) { @@ -8619,7 +9859,7 @@ obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (lookup_attr_id(obj, &PyId_tag, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, astmodulestate_global->tag, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8644,227 +9884,513 @@ obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena) } -PyObject *ast3_parse(PyObject *self, PyObject *args); -static PyMethodDef ast3_methods[] = { - {"_parse", ast3_parse, METH_VARARGS, "Parse string into typed AST."}, - {NULL, NULL, 0, NULL} -}; -static struct PyModuleDef _astmodule = { - PyModuleDef_HEAD_INIT, "_ast3", NULL, 0, ast3_methods -}; PyMODINIT_FUNC -PyInit__ast3(void) +PyInit__ast(void) { - PyObject *m, *d; + PyObject *m; if (!init_types()) return NULL; - m = PyModule_Create(&_astmodule); + m = PyState_FindModule(&_astmodule); if (!m) return NULL; - d = PyModule_GetDict(m); - if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return NULL; - if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) - return NULL; - if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return NULL; - if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type) < - 0) return NULL; - if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "FunctionType", (PyObject*)FunctionType_type) < - 0) return NULL; - if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return NULL; - if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type) < - 0) return NULL; - if (PyDict_SetItemString(d, "AsyncFunctionDef", - (PyObject*)AsyncFunctionDef_type) < 0) return NULL; - if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "AnnAssign", (PyObject*)AnnAssign_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return NULL; - if (PyDict_SetItemString(d, "AsyncFor", (PyObject*)AsyncFor_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return NULL; - if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return NULL; - if (PyDict_SetItemString(d, "AsyncWith", (PyObject*)AsyncWith_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "Try", (PyObject*)Try_type) < 0) return NULL; - if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return NULL; - if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return NULL; - if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return NULL; - if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return NULL; - if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return NULL; - if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "GeneratorExp", (PyObject*)GeneratorExp_type) < - 0) return NULL; - if (PyDict_SetItemString(d, "Await", (PyObject*)Await_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "YieldFrom", (PyObject*)YieldFrom_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return NULL; - if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return NULL; - if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return NULL; - if (PyDict_SetItemString(d, "FormattedValue", - (PyObject*)FormattedValue_type) < 0) return NULL; - if (PyDict_SetItemString(d, "JoinedStr", (PyObject*)JoinedStr_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "Bytes", (PyObject*)Bytes_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "NameConstant", (PyObject*)NameConstant_type) < - 0) return NULL; - if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "Constant", (PyObject*)Constant_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "Starred", (PyObject*)Starred_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return NULL; - if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return NULL; - if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "expr_context", (PyObject*)expr_context_type) < - 0) return NULL; - if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return NULL; - if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return NULL; - if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return NULL; - if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return NULL; - if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return NULL; - if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return NULL; - if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return NULL; - if (PyDict_SetItemString(d, "MatMult", (PyObject*)MatMult_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return NULL; - if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return NULL; - if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return NULL; - if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return NULL; - if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return NULL; - if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return NULL; - if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return NULL; - if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return NULL; - if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return NULL; - if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return NULL; - if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return NULL; - if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return NULL; - if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return NULL; - if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "comprehension", (PyObject*)comprehension_type) - < 0) return NULL; - if (PyDict_SetItemString(d, "excepthandler", (PyObject*)excepthandler_type) - < 0) return NULL; - if (PyDict_SetItemString(d, "ExceptHandler", (PyObject*)ExceptHandler_type) - < 0) return NULL; - if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return NULL; - if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return - NULL; - if (PyDict_SetItemString(d, "withitem", (PyObject*)withitem_type) < 0) - return NULL; - if (PyDict_SetItemString(d, "type_ignore", (PyObject*)type_ignore_type) < - 0) return NULL; - if (PyDict_SetItemString(d, "TypeIgnore", (PyObject*)TypeIgnore_type) < 0) - return NULL; + if (PyModule_AddObject(m, "AST", astmodulestate_global->AST_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->AST_type); + if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) { + goto error; + } + if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) { + goto error; + } + if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) { + goto error; + } + if (PyModule_AddObject(m, "mod", astmodulestate_global->mod_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->mod_type); + if (PyModule_AddObject(m, "Module", astmodulestate_global->Module_type) < + 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Module_type); + if (PyModule_AddObject(m, "Interactive", + astmodulestate_global->Interactive_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Interactive_type); + if (PyModule_AddObject(m, "Expression", + astmodulestate_global->Expression_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Expression_type); + if (PyModule_AddObject(m, "FunctionType", + astmodulestate_global->FunctionType_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->FunctionType_type); + if (PyModule_AddObject(m, "stmt", astmodulestate_global->stmt_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->stmt_type); + if (PyModule_AddObject(m, "FunctionDef", + astmodulestate_global->FunctionDef_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->FunctionDef_type); + if (PyModule_AddObject(m, "AsyncFunctionDef", + astmodulestate_global->AsyncFunctionDef_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->AsyncFunctionDef_type); + if (PyModule_AddObject(m, "ClassDef", astmodulestate_global->ClassDef_type) + < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->ClassDef_type); + if (PyModule_AddObject(m, "Return", astmodulestate_global->Return_type) < + 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Return_type); + if (PyModule_AddObject(m, "Delete", astmodulestate_global->Delete_type) < + 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Delete_type); + if (PyModule_AddObject(m, "Assign", astmodulestate_global->Assign_type) < + 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Assign_type); + if (PyModule_AddObject(m, "AugAssign", + astmodulestate_global->AugAssign_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->AugAssign_type); + if (PyModule_AddObject(m, "AnnAssign", + astmodulestate_global->AnnAssign_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->AnnAssign_type); + if (PyModule_AddObject(m, "For", astmodulestate_global->For_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->For_type); + if (PyModule_AddObject(m, "AsyncFor", astmodulestate_global->AsyncFor_type) + < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->AsyncFor_type); + if (PyModule_AddObject(m, "While", astmodulestate_global->While_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->While_type); + if (PyModule_AddObject(m, "If", astmodulestate_global->If_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->If_type); + if (PyModule_AddObject(m, "With", astmodulestate_global->With_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->With_type); + if (PyModule_AddObject(m, "AsyncWith", + astmodulestate_global->AsyncWith_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->AsyncWith_type); + if (PyModule_AddObject(m, "Raise", astmodulestate_global->Raise_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Raise_type); + if (PyModule_AddObject(m, "Try", astmodulestate_global->Try_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Try_type); + if (PyModule_AddObject(m, "Assert", astmodulestate_global->Assert_type) < + 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Assert_type); + if (PyModule_AddObject(m, "Import", astmodulestate_global->Import_type) < + 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Import_type); + if (PyModule_AddObject(m, "ImportFrom", + astmodulestate_global->ImportFrom_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->ImportFrom_type); + if (PyModule_AddObject(m, "Global", astmodulestate_global->Global_type) < + 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Global_type); + if (PyModule_AddObject(m, "Nonlocal", astmodulestate_global->Nonlocal_type) + < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Nonlocal_type); + if (PyModule_AddObject(m, "Expr", astmodulestate_global->Expr_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Expr_type); + if (PyModule_AddObject(m, "Pass", astmodulestate_global->Pass_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Pass_type); + if (PyModule_AddObject(m, "Break", astmodulestate_global->Break_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Break_type); + if (PyModule_AddObject(m, "Continue", astmodulestate_global->Continue_type) + < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Continue_type); + if (PyModule_AddObject(m, "expr", astmodulestate_global->expr_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->expr_type); + if (PyModule_AddObject(m, "BoolOp", astmodulestate_global->BoolOp_type) < + 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->BoolOp_type); + if (PyModule_AddObject(m, "NamedExpr", + astmodulestate_global->NamedExpr_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->NamedExpr_type); + if (PyModule_AddObject(m, "BinOp", astmodulestate_global->BinOp_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->BinOp_type); + if (PyModule_AddObject(m, "UnaryOp", astmodulestate_global->UnaryOp_type) < + 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->UnaryOp_type); + if (PyModule_AddObject(m, "Lambda", astmodulestate_global->Lambda_type) < + 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Lambda_type); + if (PyModule_AddObject(m, "IfExp", astmodulestate_global->IfExp_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->IfExp_type); + if (PyModule_AddObject(m, "Dict", astmodulestate_global->Dict_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Dict_type); + if (PyModule_AddObject(m, "Set", astmodulestate_global->Set_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Set_type); + if (PyModule_AddObject(m, "ListComp", astmodulestate_global->ListComp_type) + < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->ListComp_type); + if (PyModule_AddObject(m, "SetComp", astmodulestate_global->SetComp_type) < + 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->SetComp_type); + if (PyModule_AddObject(m, "DictComp", astmodulestate_global->DictComp_type) + < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->DictComp_type); + if (PyModule_AddObject(m, "GeneratorExp", + astmodulestate_global->GeneratorExp_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->GeneratorExp_type); + if (PyModule_AddObject(m, "Await", astmodulestate_global->Await_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Await_type); + if (PyModule_AddObject(m, "Yield", astmodulestate_global->Yield_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Yield_type); + if (PyModule_AddObject(m, "YieldFrom", + astmodulestate_global->YieldFrom_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->YieldFrom_type); + if (PyModule_AddObject(m, "Compare", astmodulestate_global->Compare_type) < + 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Compare_type); + if (PyModule_AddObject(m, "Call", astmodulestate_global->Call_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Call_type); + if (PyModule_AddObject(m, "FormattedValue", + astmodulestate_global->FormattedValue_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->FormattedValue_type); + if (PyModule_AddObject(m, "JoinedStr", + astmodulestate_global->JoinedStr_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->JoinedStr_type); + if (PyModule_AddObject(m, "Constant", astmodulestate_global->Constant_type) + < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Constant_type); + if (PyModule_AddObject(m, "Attribute", + astmodulestate_global->Attribute_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Attribute_type); + if (PyModule_AddObject(m, "Subscript", + astmodulestate_global->Subscript_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Subscript_type); + if (PyModule_AddObject(m, "Starred", astmodulestate_global->Starred_type) < + 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Starred_type); + if (PyModule_AddObject(m, "Name", astmodulestate_global->Name_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Name_type); + if (PyModule_AddObject(m, "List", astmodulestate_global->List_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->List_type); + if (PyModule_AddObject(m, "Tuple", astmodulestate_global->Tuple_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Tuple_type); + if (PyModule_AddObject(m, "Slice", astmodulestate_global->Slice_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Slice_type); + if (PyModule_AddObject(m, "expr_context", + astmodulestate_global->expr_context_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->expr_context_type); + if (PyModule_AddObject(m, "Load", astmodulestate_global->Load_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Load_type); + if (PyModule_AddObject(m, "Store", astmodulestate_global->Store_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Store_type); + if (PyModule_AddObject(m, "Del", astmodulestate_global->Del_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Del_type); + if (PyModule_AddObject(m, "boolop", astmodulestate_global->boolop_type) < + 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->boolop_type); + if (PyModule_AddObject(m, "And", astmodulestate_global->And_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->And_type); + if (PyModule_AddObject(m, "Or", astmodulestate_global->Or_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Or_type); + if (PyModule_AddObject(m, "operator", astmodulestate_global->operator_type) + < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->operator_type); + if (PyModule_AddObject(m, "Add", astmodulestate_global->Add_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Add_type); + if (PyModule_AddObject(m, "Sub", astmodulestate_global->Sub_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Sub_type); + if (PyModule_AddObject(m, "Mult", astmodulestate_global->Mult_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Mult_type); + if (PyModule_AddObject(m, "MatMult", astmodulestate_global->MatMult_type) < + 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->MatMult_type); + if (PyModule_AddObject(m, "Div", astmodulestate_global->Div_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Div_type); + if (PyModule_AddObject(m, "Mod", astmodulestate_global->Mod_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Mod_type); + if (PyModule_AddObject(m, "Pow", astmodulestate_global->Pow_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Pow_type); + if (PyModule_AddObject(m, "LShift", astmodulestate_global->LShift_type) < + 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->LShift_type); + if (PyModule_AddObject(m, "RShift", astmodulestate_global->RShift_type) < + 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->RShift_type); + if (PyModule_AddObject(m, "BitOr", astmodulestate_global->BitOr_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->BitOr_type); + if (PyModule_AddObject(m, "BitXor", astmodulestate_global->BitXor_type) < + 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->BitXor_type); + if (PyModule_AddObject(m, "BitAnd", astmodulestate_global->BitAnd_type) < + 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->BitAnd_type); + if (PyModule_AddObject(m, "FloorDiv", astmodulestate_global->FloorDiv_type) + < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->FloorDiv_type); + if (PyModule_AddObject(m, "unaryop", astmodulestate_global->unaryop_type) < + 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->unaryop_type); + if (PyModule_AddObject(m, "Invert", astmodulestate_global->Invert_type) < + 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Invert_type); + if (PyModule_AddObject(m, "Not", astmodulestate_global->Not_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Not_type); + if (PyModule_AddObject(m, "UAdd", astmodulestate_global->UAdd_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->UAdd_type); + if (PyModule_AddObject(m, "USub", astmodulestate_global->USub_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->USub_type); + if (PyModule_AddObject(m, "cmpop", astmodulestate_global->cmpop_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->cmpop_type); + if (PyModule_AddObject(m, "Eq", astmodulestate_global->Eq_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Eq_type); + if (PyModule_AddObject(m, "NotEq", astmodulestate_global->NotEq_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->NotEq_type); + if (PyModule_AddObject(m, "Lt", astmodulestate_global->Lt_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Lt_type); + if (PyModule_AddObject(m, "LtE", astmodulestate_global->LtE_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->LtE_type); + if (PyModule_AddObject(m, "Gt", astmodulestate_global->Gt_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Gt_type); + if (PyModule_AddObject(m, "GtE", astmodulestate_global->GtE_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->GtE_type); + if (PyModule_AddObject(m, "Is", astmodulestate_global->Is_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->Is_type); + if (PyModule_AddObject(m, "IsNot", astmodulestate_global->IsNot_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->IsNot_type); + if (PyModule_AddObject(m, "In", astmodulestate_global->In_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->In_type); + if (PyModule_AddObject(m, "NotIn", astmodulestate_global->NotIn_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->NotIn_type); + if (PyModule_AddObject(m, "comprehension", + astmodulestate_global->comprehension_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->comprehension_type); + if (PyModule_AddObject(m, "excepthandler", + astmodulestate_global->excepthandler_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->excepthandler_type); + if (PyModule_AddObject(m, "ExceptHandler", + astmodulestate_global->ExceptHandler_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->ExceptHandler_type); + if (PyModule_AddObject(m, "arguments", + astmodulestate_global->arguments_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->arguments_type); + if (PyModule_AddObject(m, "arg", astmodulestate_global->arg_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->arg_type); + if (PyModule_AddObject(m, "keyword", astmodulestate_global->keyword_type) < + 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->keyword_type); + if (PyModule_AddObject(m, "alias", astmodulestate_global->alias_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->alias_type); + if (PyModule_AddObject(m, "withitem", astmodulestate_global->withitem_type) + < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->withitem_type); + if (PyModule_AddObject(m, "type_ignore", + astmodulestate_global->type_ignore_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->type_ignore_type); + if (PyModule_AddObject(m, "TypeIgnore", + astmodulestate_global->TypeIgnore_type) < 0) { + goto error; + } + Py_INCREF(astmodulestate(m)->TypeIgnore_type); return m; +error: + Py_DECREF(m); + return NULL; } -PyObject* Ta3AST_mod2obj(mod_ty t) +PyObject* PyAST_mod2obj(mod_ty t) { if (!init_types()) return NULL; @@ -8872,16 +10398,19 @@ PyObject* Ta3AST_mod2obj(mod_ty t) } /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ -mod_ty Ta3AST_obj2mod(PyObject* ast, PyArena* arena, int mode) +mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) { - mod_ty res; PyObject *req_type[3]; - char *req_name[] = {"Module", "Expression", "Interactive"}; + const char * const req_name[] = {"Module", "Expression", "Interactive"}; int isinstance; - req_type[0] = (PyObject*)Module_type; - req_type[1] = (PyObject*)Expression_type; - req_type[2] = (PyObject*)Interactive_type; + if (PySys_Audit("compile", "OO", ast, Py_None) < 0) { + return NULL; + } + + req_type[0] = astmodulestate_global->Module_type; + req_type[1] = astmodulestate_global->Expression_type; + req_type[2] = astmodulestate_global->Interactive_type; assert(0 <= mode && mode <= 2); @@ -8893,20 +10422,22 @@ mod_ty Ta3AST_obj2mod(PyObject* ast, PyArena* arena, int mode) return NULL; if (!isinstance) { PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", - req_name[mode], Py_TYPE(ast)->tp_name); + req_name[mode], _PyType_Name(Py_TYPE(ast))); return NULL; } + + mod_ty res = NULL; if (obj2ast_mod(ast, &res, arena) != 0) return NULL; else return res; } -int Ta3AST_Check(PyObject* obj) +int PyAST_Check(PyObject* obj) { if (!init_types()) return -1; - return PyObject_IsInstance(obj, (PyObject*)&AST_type); + return PyObject_IsInstance(obj, astmodulestate_global->AST_type); } diff --git a/ast3/Python/asdl.c b/ast3/Python/asdl.c index 0077484a..c2110781 100644 --- a/ast3/Python/asdl.c +++ b/ast3/Python/asdl.c @@ -1,8 +1,8 @@ #include "Python.h" -#include "../Include/asdl.h" +#include "asdl.h" asdl_seq * -_Ta3_asdl_seq_new(Py_ssize_t size, PyArena *arena) +_Py_asdl_seq_new(Py_ssize_t size, PyArena *arena) { asdl_seq *seq = NULL; size_t n; @@ -33,7 +33,7 @@ _Ta3_asdl_seq_new(Py_ssize_t size, PyArena *arena) } asdl_int_seq * -_Ta3_asdl_int_seq_new(Py_ssize_t size, PyArena *arena) +_Py_asdl_int_seq_new(Py_ssize_t size, PyArena *arena) { asdl_int_seq *seq = NULL; size_t n; diff --git a/ast3/Python/ast.c b/ast3/Python/ast.c deleted file mode 100644 index cfca73f1..00000000 --- a/ast3/Python/ast.c +++ /dev/null @@ -1,5609 +0,0 @@ -/* - * This file includes functions to transform a concrete syntax tree (CST) to - * an abstract syntax tree (AST). The main function is Ta3AST_FromNode(). - * - */ -#include "Python.h" -#include "../Include/Python-ast.h" -#include "../Include/node.h" -#include "../Include/ast.h" -#include "../Include/token.h" -#include "pythonrun.h" - -#include - -// VS 2010 doesn't have ... -typedef int bool; -#define false 0 -#define true 1 - -#if PY_MINOR_VERSION < 6 -static PyObject * -_PyObject_FastCall(PyObject *func, PyObject *const *args, int nargs) -{ - PyObject *t, *res; - int i; - - t = PyTuple_New(nargs); - if (t == NULL) { - return NULL; - } - for (i = 0; i < nargs; i++) { - Py_INCREF(args[i]); - if (PyTuple_SetItem(t, i, args[i]) < 0) { - Py_DECREF(t); - return NULL; - } - } - res = PyObject_CallObject(func, t); - Py_DECREF(t); - return res; -} -#endif - -#if PY_MINOR_VERSION < 6 -#define _PyUnicode_EqualToASCIIString(a, b) (PyUnicode_CompareWithASCIIString((a), (b)) == 0) - -static PyObject * -_PyBytes_DecodeEscape(const char *s, - Py_ssize_t len, - const char *errors, - Py_ssize_t unicode, - const char *recode_encoding, - const char **first_invalid_escape) -{ - *first_invalid_escape = NULL; - return PyBytes_DecodeEscape(s, len, errors, unicode, recode_encoding); -} - -PyObject * -_PyUnicode_DecodeUnicodeEscape(const char *s, - Py_ssize_t size, - const char *errors, - const char **first_invalid_escape) -{ - *first_invalid_escape = NULL; - return PyUnicode_DecodeUnicodeEscape(s, size, errors); -} - -#endif - -static int validate_stmts(asdl_seq *); -static int validate_exprs(asdl_seq *, expr_context_ty, int); -static int validate_nonempty_seq(asdl_seq *, const char *, const char *); -static int validate_stmt(stmt_ty); -static int validate_expr(expr_ty, expr_context_ty); - -void -_Ta3Parser_UpdateFlags(PyCompilerFlags *flags, int *iflags, int feature_version); -node * -Ta3Parser_SimpleParseStringFlagsFilename(const char *str, const char *filename, - int start, int flags); - -static int -validate_comprehension(asdl_seq *gens) -{ - int i; - if (!asdl_seq_LEN(gens)) { - PyErr_SetString(PyExc_ValueError, "comprehension with no generators"); - return 0; - } - for (i = 0; i < asdl_seq_LEN(gens); i++) { - comprehension_ty comp = asdl_seq_GET(gens, i); - if (!validate_expr(comp->target, Store) || - !validate_expr(comp->iter, Load) || - !validate_exprs(comp->ifs, Load, 0)) - return 0; - } - return 1; -} - -static int -validate_slice(slice_ty slice) -{ - switch (slice->kind) { - case Slice_kind: - return (!slice->v.Slice.lower || validate_expr(slice->v.Slice.lower, Load)) && - (!slice->v.Slice.upper || validate_expr(slice->v.Slice.upper, Load)) && - (!slice->v.Slice.step || validate_expr(slice->v.Slice.step, Load)); - case ExtSlice_kind: { - int i; - if (!validate_nonempty_seq(slice->v.ExtSlice.dims, "dims", "ExtSlice")) - return 0; - for (i = 0; i < asdl_seq_LEN(slice->v.ExtSlice.dims); i++) - if (!validate_slice(asdl_seq_GET(slice->v.ExtSlice.dims, i))) - return 0; - return 1; - } - case Index_kind: - return validate_expr(slice->v.Index.value, Load); - default: - PyErr_SetString(PyExc_SystemError, "unknown slice node"); - return 0; - } -} - -static int -validate_keywords(asdl_seq *keywords) -{ - int i; - for (i = 0; i < asdl_seq_LEN(keywords); i++) - if (!validate_expr(((keyword_ty)asdl_seq_GET(keywords, i))->value, Load)) - return 0; - return 1; -} - -static int -validate_args(asdl_seq *args) -{ - int i; - for (i = 0; i < asdl_seq_LEN(args); i++) { - arg_ty arg = asdl_seq_GET(args, i); - if (arg->annotation && !validate_expr(arg->annotation, Load)) - return 0; - } - return 1; -} - -static const char * -expr_context_name(expr_context_ty ctx) -{ - switch (ctx) { - case Load: - return "Load"; - case Store: - return "Store"; - case Del: - return "Del"; - case AugLoad: - return "AugLoad"; - case AugStore: - return "AugStore"; - case Param: - return "Param"; - default: - abort(); - } -} - -static int -validate_arguments(arguments_ty args) -{ - if (!validate_args(args->args)) - return 0; - if (args->vararg && args->vararg->annotation - && !validate_expr(args->vararg->annotation, Load)) { - return 0; - } - if (!validate_args(args->kwonlyargs)) - return 0; - if (args->kwarg && args->kwarg->annotation - && !validate_expr(args->kwarg->annotation, Load)) { - return 0; - } - if (asdl_seq_LEN(args->defaults) > asdl_seq_LEN(args->args)) { - PyErr_SetString(PyExc_ValueError, "more positional defaults than args on arguments"); - return 0; - } - if (asdl_seq_LEN(args->kw_defaults) != asdl_seq_LEN(args->kwonlyargs)) { - PyErr_SetString(PyExc_ValueError, "length of kwonlyargs is not the same as " - "kw_defaults on arguments"); - return 0; - } - return validate_exprs(args->defaults, Load, 0) && validate_exprs(args->kw_defaults, Load, 1); -} - -static int -validate_constant(PyObject *value) -{ - if (value == Py_None || value == Py_Ellipsis) - return 1; - - if (PyLong_CheckExact(value) - || PyFloat_CheckExact(value) - || PyComplex_CheckExact(value) - || PyBool_Check(value) - || PyUnicode_CheckExact(value) - || PyBytes_CheckExact(value)) - return 1; - - if (PyTuple_CheckExact(value) || PyFrozenSet_CheckExact(value)) { - PyObject *it; - - it = PyObject_GetIter(value); - if (it == NULL) - return 0; - - while (1) { - PyObject *item = PyIter_Next(it); - if (item == NULL) { - if (PyErr_Occurred()) { - Py_DECREF(it); - return 0; - } - break; - } - - if (!validate_constant(item)) { - Py_DECREF(it); - Py_DECREF(item); - return 0; - } - Py_DECREF(item); - } - - Py_DECREF(it); - return 1; - } - - return 0; -} - -static int -validate_expr(expr_ty exp, expr_context_ty ctx) -{ - int check_ctx = 1; - expr_context_ty actual_ctx; - - /* First check expression context. */ - switch (exp->kind) { - case Attribute_kind: - actual_ctx = exp->v.Attribute.ctx; - break; - case Subscript_kind: - actual_ctx = exp->v.Subscript.ctx; - break; - case Starred_kind: - actual_ctx = exp->v.Starred.ctx; - break; - case Name_kind: - actual_ctx = exp->v.Name.ctx; - break; - case List_kind: - actual_ctx = exp->v.List.ctx; - break; - case Tuple_kind: - actual_ctx = exp->v.Tuple.ctx; - break; - default: - if (ctx != Load) { - PyErr_Format(PyExc_ValueError, "expression which can't be " - "assigned to in %s context", expr_context_name(ctx)); - return 0; - } - check_ctx = 0; - /* set actual_ctx to prevent gcc warning */ - actual_ctx = 0; - } - if (check_ctx && actual_ctx != ctx) { - PyErr_Format(PyExc_ValueError, "expression must have %s context but has %s instead", - expr_context_name(ctx), expr_context_name(actual_ctx)); - return 0; - } - - /* Now validate expression. */ - switch (exp->kind) { - case BoolOp_kind: - if (asdl_seq_LEN(exp->v.BoolOp.values) < 2) { - PyErr_SetString(PyExc_ValueError, "BoolOp with less than 2 values"); - return 0; - } - return validate_exprs(exp->v.BoolOp.values, Load, 0); - case BinOp_kind: - return validate_expr(exp->v.BinOp.left, Load) && - validate_expr(exp->v.BinOp.right, Load); - case UnaryOp_kind: - return validate_expr(exp->v.UnaryOp.operand, Load); - case Lambda_kind: - return validate_arguments(exp->v.Lambda.args) && - validate_expr(exp->v.Lambda.body, Load); - case IfExp_kind: - return validate_expr(exp->v.IfExp.test, Load) && - validate_expr(exp->v.IfExp.body, Load) && - validate_expr(exp->v.IfExp.orelse, Load); - case Dict_kind: - if (asdl_seq_LEN(exp->v.Dict.keys) != asdl_seq_LEN(exp->v.Dict.values)) { - PyErr_SetString(PyExc_ValueError, - "Dict doesn't have the same number of keys as values"); - return 0; - } - /* null_ok=1 for keys expressions to allow dict unpacking to work in - dict literals, i.e. ``{**{a:b}}`` */ - return validate_exprs(exp->v.Dict.keys, Load, /*null_ok=*/ 1) && - validate_exprs(exp->v.Dict.values, Load, /*null_ok=*/ 0); - case Set_kind: - return validate_exprs(exp->v.Set.elts, Load, 0); -#define COMP(NAME) \ - case NAME ## _kind: \ - return validate_comprehension(exp->v.NAME.generators) && \ - validate_expr(exp->v.NAME.elt, Load); - COMP(ListComp) - COMP(SetComp) - COMP(GeneratorExp) -#undef COMP - case DictComp_kind: - return validate_comprehension(exp->v.DictComp.generators) && - validate_expr(exp->v.DictComp.key, Load) && - validate_expr(exp->v.DictComp.value, Load); - case Yield_kind: - return !exp->v.Yield.value || validate_expr(exp->v.Yield.value, Load); - case YieldFrom_kind: - return validate_expr(exp->v.YieldFrom.value, Load); - case Await_kind: - return validate_expr(exp->v.Await.value, Load); - case Compare_kind: - if (!asdl_seq_LEN(exp->v.Compare.comparators)) { - PyErr_SetString(PyExc_ValueError, "Compare with no comparators"); - return 0; - } - if (asdl_seq_LEN(exp->v.Compare.comparators) != - asdl_seq_LEN(exp->v.Compare.ops)) { - PyErr_SetString(PyExc_ValueError, "Compare has a different number " - "of comparators and operands"); - return 0; - } - return validate_exprs(exp->v.Compare.comparators, Load, 0) && - validate_expr(exp->v.Compare.left, Load); - case Call_kind: - return validate_expr(exp->v.Call.func, Load) && - validate_exprs(exp->v.Call.args, Load, 0) && - validate_keywords(exp->v.Call.keywords); - case Constant_kind: - if (!validate_constant(exp->v.Constant.value)) { - PyErr_Format(PyExc_TypeError, - "got an invalid type in Constant: %s", - Py_TYPE(exp->v.Constant.value)->tp_name); - return 0; - } - return 1; - case Num_kind: { - PyObject *n = exp->v.Num.n; - if (!PyLong_CheckExact(n) && !PyFloat_CheckExact(n) && - !PyComplex_CheckExact(n)) { - PyErr_SetString(PyExc_TypeError, "non-numeric type in Num"); - return 0; - } - return 1; - } - case Str_kind: { - PyObject *s = exp->v.Str.s; - if (!PyUnicode_CheckExact(s)) { - PyErr_SetString(PyExc_TypeError, "non-string type in Str"); - return 0; - } - return 1; - } - case JoinedStr_kind: - return validate_exprs(exp->v.JoinedStr.values, Load, 0); - case FormattedValue_kind: - if (validate_expr(exp->v.FormattedValue.value, Load) == 0) - return 0; - if (exp->v.FormattedValue.format_spec) - return validate_expr(exp->v.FormattedValue.format_spec, Load); - return 1; - case Bytes_kind: { - PyObject *b = exp->v.Bytes.s; - if (!PyBytes_CheckExact(b)) { - PyErr_SetString(PyExc_TypeError, "non-bytes type in Bytes"); - return 0; - } - return 1; - } - case Attribute_kind: - return validate_expr(exp->v.Attribute.value, Load); - case Subscript_kind: - return validate_slice(exp->v.Subscript.slice) && - validate_expr(exp->v.Subscript.value, Load); - case Starred_kind: - return validate_expr(exp->v.Starred.value, ctx); - case List_kind: - return validate_exprs(exp->v.List.elts, ctx, 0); - case Tuple_kind: - return validate_exprs(exp->v.Tuple.elts, ctx, 0); - /* These last cases don't have any checking. */ - case Name_kind: - case NameConstant_kind: - case Ellipsis_kind: - return 1; - default: - PyErr_SetString(PyExc_SystemError, "unexpected expression"); - return 0; - } -} - -static int -validate_nonempty_seq(asdl_seq *seq, const char *what, const char *owner) -{ - if (asdl_seq_LEN(seq)) - return 1; - PyErr_Format(PyExc_ValueError, "empty %s on %s", what, owner); - return 0; -} - -static int -validate_assignlist(asdl_seq *targets, expr_context_ty ctx) -{ - return validate_nonempty_seq(targets, "targets", ctx == Del ? "Delete" : "Assign") && - validate_exprs(targets, ctx, 0); -} - -static int -validate_body(asdl_seq *body, const char *owner) -{ - return validate_nonempty_seq(body, "body", owner) && validate_stmts(body); -} - -static int -validate_stmt(stmt_ty stmt) -{ - int i; - switch (stmt->kind) { - case FunctionDef_kind: - return validate_body(stmt->v.FunctionDef.body, "FunctionDef") && - validate_arguments(stmt->v.FunctionDef.args) && - validate_exprs(stmt->v.FunctionDef.decorator_list, Load, 0) && - (!stmt->v.FunctionDef.returns || - validate_expr(stmt->v.FunctionDef.returns, Load)); - case ClassDef_kind: - return validate_body(stmt->v.ClassDef.body, "ClassDef") && - validate_exprs(stmt->v.ClassDef.bases, Load, 0) && - validate_keywords(stmt->v.ClassDef.keywords) && - validate_exprs(stmt->v.ClassDef.decorator_list, Load, 0); - case Return_kind: - return !stmt->v.Return.value || validate_expr(stmt->v.Return.value, Load); - case Delete_kind: - return validate_assignlist(stmt->v.Delete.targets, Del); - case Assign_kind: - return validate_assignlist(stmt->v.Assign.targets, Store) && - validate_expr(stmt->v.Assign.value, Load); - case AugAssign_kind: - return validate_expr(stmt->v.AugAssign.target, Store) && - validate_expr(stmt->v.AugAssign.value, Load); - case AnnAssign_kind: - if (stmt->v.AnnAssign.target->kind != Name_kind && - stmt->v.AnnAssign.simple) { - PyErr_SetString(PyExc_TypeError, - "AnnAssign with simple non-Name target"); - return 0; - } - return validate_expr(stmt->v.AnnAssign.target, Store) && - (!stmt->v.AnnAssign.value || - validate_expr(stmt->v.AnnAssign.value, Load)) && - validate_expr(stmt->v.AnnAssign.annotation, Load); - case For_kind: - return validate_expr(stmt->v.For.target, Store) && - validate_expr(stmt->v.For.iter, Load) && - validate_body(stmt->v.For.body, "For") && - validate_stmts(stmt->v.For.orelse); - case AsyncFor_kind: - return validate_expr(stmt->v.AsyncFor.target, Store) && - validate_expr(stmt->v.AsyncFor.iter, Load) && - validate_body(stmt->v.AsyncFor.body, "AsyncFor") && - validate_stmts(stmt->v.AsyncFor.orelse); - case While_kind: - return validate_expr(stmt->v.While.test, Load) && - validate_body(stmt->v.While.body, "While") && - validate_stmts(stmt->v.While.orelse); - case If_kind: - return validate_expr(stmt->v.If.test, Load) && - validate_body(stmt->v.If.body, "If") && - validate_stmts(stmt->v.If.orelse); - case With_kind: - if (!validate_nonempty_seq(stmt->v.With.items, "items", "With")) - return 0; - for (i = 0; i < asdl_seq_LEN(stmt->v.With.items); i++) { - withitem_ty item = asdl_seq_GET(stmt->v.With.items, i); - if (!validate_expr(item->context_expr, Load) || - (item->optional_vars && !validate_expr(item->optional_vars, Store))) - return 0; - } - return validate_body(stmt->v.With.body, "With"); - case AsyncWith_kind: - if (!validate_nonempty_seq(stmt->v.AsyncWith.items, "items", "AsyncWith")) - return 0; - for (i = 0; i < asdl_seq_LEN(stmt->v.AsyncWith.items); i++) { - withitem_ty item = asdl_seq_GET(stmt->v.AsyncWith.items, i); - if (!validate_expr(item->context_expr, Load) || - (item->optional_vars && !validate_expr(item->optional_vars, Store))) - return 0; - } - return validate_body(stmt->v.AsyncWith.body, "AsyncWith"); - case Raise_kind: - if (stmt->v.Raise.exc) { - return validate_expr(stmt->v.Raise.exc, Load) && - (!stmt->v.Raise.cause || validate_expr(stmt->v.Raise.cause, Load)); - } - if (stmt->v.Raise.cause) { - PyErr_SetString(PyExc_ValueError, "Raise with cause but no exception"); - return 0; - } - return 1; - case Try_kind: - if (!validate_body(stmt->v.Try.body, "Try")) - return 0; - if (!asdl_seq_LEN(stmt->v.Try.handlers) && - !asdl_seq_LEN(stmt->v.Try.finalbody)) { - PyErr_SetString(PyExc_ValueError, "Try has neither except handlers nor finalbody"); - return 0; - } - if (!asdl_seq_LEN(stmt->v.Try.handlers) && - asdl_seq_LEN(stmt->v.Try.orelse)) { - PyErr_SetString(PyExc_ValueError, "Try has orelse but no except handlers"); - return 0; - } - for (i = 0; i < asdl_seq_LEN(stmt->v.Try.handlers); i++) { - excepthandler_ty handler = asdl_seq_GET(stmt->v.Try.handlers, i); - if ((handler->v.ExceptHandler.type && - !validate_expr(handler->v.ExceptHandler.type, Load)) || - !validate_body(handler->v.ExceptHandler.body, "ExceptHandler")) - return 0; - } - return (!asdl_seq_LEN(stmt->v.Try.finalbody) || - validate_stmts(stmt->v.Try.finalbody)) && - (!asdl_seq_LEN(stmt->v.Try.orelse) || - validate_stmts(stmt->v.Try.orelse)); - case Assert_kind: - return validate_expr(stmt->v.Assert.test, Load) && - (!stmt->v.Assert.msg || validate_expr(stmt->v.Assert.msg, Load)); - case Import_kind: - return validate_nonempty_seq(stmt->v.Import.names, "names", "Import"); - case ImportFrom_kind: - if (stmt->v.ImportFrom.level < 0) { - PyErr_SetString(PyExc_ValueError, "Negative ImportFrom level"); - return 0; - } - return validate_nonempty_seq(stmt->v.ImportFrom.names, "names", "ImportFrom"); - case Global_kind: - return validate_nonempty_seq(stmt->v.Global.names, "names", "Global"); - case Nonlocal_kind: - return validate_nonempty_seq(stmt->v.Nonlocal.names, "names", "Nonlocal"); - case Expr_kind: - return validate_expr(stmt->v.Expr.value, Load); - case AsyncFunctionDef_kind: - return validate_body(stmt->v.AsyncFunctionDef.body, "AsyncFunctionDef") && - validate_arguments(stmt->v.AsyncFunctionDef.args) && - validate_exprs(stmt->v.AsyncFunctionDef.decorator_list, Load, 0) && - (!stmt->v.AsyncFunctionDef.returns || - validate_expr(stmt->v.AsyncFunctionDef.returns, Load)); - case Pass_kind: - case Break_kind: - case Continue_kind: - return 1; - default: - PyErr_SetString(PyExc_SystemError, "unexpected statement"); - return 0; - } -} - -static int -validate_stmts(asdl_seq *seq) -{ - int i; - for (i = 0; i < asdl_seq_LEN(seq); i++) { - stmt_ty stmt = asdl_seq_GET(seq, i); - if (stmt) { - if (!validate_stmt(stmt)) - return 0; - } - else { - PyErr_SetString(PyExc_ValueError, - "None disallowed in statement list"); - return 0; - } - } - return 1; -} - -static int -validate_exprs(asdl_seq *exprs, expr_context_ty ctx, int null_ok) -{ - int i; - for (i = 0; i < asdl_seq_LEN(exprs); i++) { - expr_ty expr = asdl_seq_GET(exprs, i); - if (expr) { - if (!validate_expr(expr, ctx)) - return 0; - } - else if (!null_ok) { - PyErr_SetString(PyExc_ValueError, - "None disallowed in expression list"); - return 0; - } - - } - return 1; -} - -int -Ta3AST_Validate(mod_ty mod) -{ - int res = 0; - - switch (mod->kind) { - case Module_kind: - res = validate_stmts(mod->v.Module.body); - break; - case Interactive_kind: - res = validate_stmts(mod->v.Interactive.body); - break; - case Expression_kind: - res = validate_expr(mod->v.Expression.body, Load); - break; - case Suite_kind: - PyErr_SetString(PyExc_ValueError, "Suite is not valid in the CPython compiler"); - break; - default: - PyErr_SetString(PyExc_SystemError, "impossible module node"); - res = 0; - break; - } - return res; -} - -/* This is done here, so defines like "test" don't interfere with AST use above. */ -#include "../Include/grammar.h" -#include "../Include/parsetok.h" -#include "../Include/graminit.h" - -/* Data structure used internally */ -struct compiling { - PyArena *c_arena; /* Arena for allocating memory. */ - PyObject *c_filename; /* filename */ - PyObject *c_normalize; /* Normalization function from unicodedata. */ - int c_feature_version; /* Latest minior version of Python for allowed features */ -}; - -static asdl_seq *seq_for_testlist(struct compiling *, const node *); -static expr_ty ast_for_expr(struct compiling *, const node *); -static stmt_ty ast_for_stmt(struct compiling *, const node *); -static asdl_seq *ast_for_suite(struct compiling *c, const node *n); -static asdl_seq *ast_for_exprlist(struct compiling *, const node *, - expr_context_ty); -static expr_ty ast_for_testlist(struct compiling *, const node *); -static stmt_ty ast_for_classdef(struct compiling *, const node *, asdl_seq *); - -static stmt_ty ast_for_with_stmt(struct compiling *, const node *, bool); -static stmt_ty ast_for_for_stmt(struct compiling *, const node *, bool); - -/* Note different signature for ast_for_call */ -static expr_ty ast_for_call(struct compiling *, const node *, expr_ty, bool); - -static PyObject *parsenumber(struct compiling *, const char *); -static expr_ty parsestrplus(struct compiling *, const node *n); - -#define COMP_GENEXP 0 -#define COMP_LISTCOMP 1 -#define COMP_SETCOMP 2 - -static int -init_normalization(struct compiling *c) -{ - PyObject *m = PyImport_ImportModuleNoBlock("unicodedata"); - if (!m) - return 0; - c->c_normalize = PyObject_GetAttrString(m, "normalize"); - Py_DECREF(m); - if (!c->c_normalize) - return 0; - return 1; -} - -static identifier -new_identifier(const char *n, struct compiling *c) -{ - PyObject *id = PyUnicode_DecodeUTF8(n, strlen(n), NULL); - if (!id) - return NULL; - /* PyUnicode_DecodeUTF8 should always return a ready string. */ - assert(PyUnicode_IS_READY(id)); - /* Check whether there are non-ASCII characters in the - identifier; if so, normalize to NFKC. */ - if (!PyUnicode_IS_ASCII(id)) { - PyObject *id2; - PyObject *form; - PyObject *args[2]; - _Py_IDENTIFIER(NFKC); - if (!c->c_normalize && !init_normalization(c)) { - Py_DECREF(id); - return NULL; - } - form = _PyUnicode_FromId(&PyId_NFKC); - if (form == NULL) { - Py_DECREF(id); - return NULL; - } - args[0] = form; - args[1] = id; - id2 = _PyObject_FastCall(c->c_normalize, args, 2); - Py_DECREF(id); - if (!id2) - return NULL; - if (!PyUnicode_Check(id2)) { - PyErr_Format(PyExc_TypeError, - "unicodedata.normalize() must return a string, not " - "%.200s", - Py_TYPE(id2)->tp_name); - Py_DECREF(id2); - return NULL; - } - id = id2; - } - PyUnicode_InternInPlace(&id); - if (PyArena_AddPyObject(c->c_arena, id) < 0) { - Py_DECREF(id); - return NULL; - } - return id; -} - -#define NEW_IDENTIFIER(n) new_identifier(STR(n), c) - -static string -new_type_comment(const char *s, struct compiling *c) -{ - PyObject *res = PyUnicode_DecodeUTF8(s, strlen(s), NULL); - if (!res) - return NULL; - if (PyArena_AddPyObject(c->c_arena, res) < 0) { - Py_DECREF(res); - return NULL; - } - return res; -} -#define NEW_TYPE_COMMENT(n) new_type_comment(STR(n), c) - -static int -ast_error(struct compiling *c, const node *n, const char *errmsg) -{ - PyObject *value, *errstr, *loc, *tmp; - - loc = PyErr_ProgramTextObject(c->c_filename, LINENO(n)); - if (!loc) { - Py_INCREF(Py_None); - loc = Py_None; - } - tmp = Py_BuildValue("(OiiN)", c->c_filename, LINENO(n), n->n_col_offset, loc); - if (!tmp) - return 0; - errstr = PyUnicode_FromString(errmsg); - if (!errstr) { - Py_DECREF(tmp); - return 0; - } - value = PyTuple_Pack(2, errstr, tmp); - Py_DECREF(errstr); - Py_DECREF(tmp); - if (value) { - PyErr_SetObject(PyExc_SyntaxError, value); - Py_DECREF(value); - } - return 0; -} - -/* num_stmts() returns number of contained statements. - - Use this routine to determine how big a sequence is needed for - the statements in a parse tree. Its raison d'etre is this bit of - grammar: - - stmt: simple_stmt | compound_stmt - simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE - - A simple_stmt can contain multiple small_stmt elements joined - by semicolons. If the arg is a simple_stmt, the number of - small_stmt elements is returned. -*/ - -static int -num_stmts(const node *n) -{ - int i, l; - node *ch; - - switch (TYPE(n)) { - case single_input: - if (TYPE(CHILD(n, 0)) == NEWLINE) - return 0; - else - return num_stmts(CHILD(n, 0)); - case file_input: - l = 0; - for (i = 0; i < NCH(n); i++) { - ch = CHILD(n, i); - if (TYPE(ch) == stmt) - l += num_stmts(ch); - } - return l; - case stmt: - return num_stmts(CHILD(n, 0)); - case compound_stmt: - return 1; - case simple_stmt: - return NCH(n) / 2; /* Divide by 2 to remove count of semi-colons */ - case suite: - /* suite: simple_stmt | NEWLINE [TYPE_COMMENT NEWLINE] INDENT stmt+ DEDENT */ - if (NCH(n) == 1) - return num_stmts(CHILD(n, 0)); - else { - i = 2; - l = 0; - if (TYPE(CHILD(n, 1)) == TYPE_COMMENT) - i += 2; - for (; i < (NCH(n) - 1); i++) - l += num_stmts(CHILD(n, i)); - return l; - } - default: { - char buf[128]; - - sprintf(buf, "Non-statement found: %d %d", - TYPE(n), NCH(n)); - Py_FatalError(buf); - } - } - abort(); -} - -/* Transform the CST rooted at node * to the appropriate AST -*/ - -mod_ty -Ta3AST_FromNodeObject(const node *n, PyCompilerFlags *flags, - PyObject *filename, int feature_version, - PyArena *arena) -{ - int i, j, k, num; - asdl_seq *stmts = NULL; - asdl_seq *type_ignores = NULL; - stmt_ty s; - node *ch; - struct compiling c; - mod_ty res = NULL; - asdl_seq *argtypes = NULL; - expr_ty ret, arg; - - c.c_arena = arena; - /* borrowed reference */ - c.c_filename = filename; - c.c_normalize = NULL; - c.c_feature_version = feature_version; - - if (TYPE(n) == encoding_decl) - n = CHILD(n, 0); - - k = 0; - switch (TYPE(n)) { - case file_input: - stmts = _Ta3_asdl_seq_new(num_stmts(n), arena); - if (!stmts) - goto out; - for (i = 0; i < NCH(n) - 1; i++) { - ch = CHILD(n, i); - if (TYPE(ch) == NEWLINE) - continue; - REQ(ch, stmt); - num = num_stmts(ch); - if (num == 1) { - s = ast_for_stmt(&c, ch); - if (!s) - goto out; - asdl_seq_SET(stmts, k++, s); - } - else { - ch = CHILD(ch, 0); - REQ(ch, simple_stmt); - for (j = 0; j < num; j++) { - s = ast_for_stmt(&c, CHILD(ch, j * 2)); - if (!s) - goto out; - asdl_seq_SET(stmts, k++, s); - } - } - } - - /* Type ignores are stored under the ENDMARKER in file_input. */ - ch = CHILD(n, NCH(n) - 1); - REQ(ch, ENDMARKER); - num = NCH(ch); - type_ignores = _Ta3_asdl_seq_new(num, arena); - if (!type_ignores) - goto out; - - for (i = 0; i < num; i++) { - string type_comment = new_type_comment(STR(CHILD(ch, i)), &c); - if (!type_comment) - goto out; - type_ignore_ty ti = TypeIgnore(LINENO(CHILD(ch, i)), type_comment, arena); - if (!ti) - goto out; - asdl_seq_SET(type_ignores, i, ti); - } - - res = Module(stmts, type_ignores, arena); - break; - case eval_input: { - expr_ty testlist_ast; - - /* XXX Why not comp_for here? */ - testlist_ast = ast_for_testlist(&c, CHILD(n, 0)); - if (!testlist_ast) - goto out; - res = Expression(testlist_ast, arena); - break; - } - case single_input: - if (TYPE(CHILD(n, 0)) == NEWLINE) { - stmts = _Ta3_asdl_seq_new(1, arena); - if (!stmts) - goto out; - asdl_seq_SET(stmts, 0, Pass(n->n_lineno, n->n_col_offset, - arena)); - if (!asdl_seq_GET(stmts, 0)) - goto out; - res = Interactive(stmts, arena); - } - else { - n = CHILD(n, 0); - num = num_stmts(n); - stmts = _Ta3_asdl_seq_new(num, arena); - if (!stmts) - goto out; - if (num == 1) { - s = ast_for_stmt(&c, n); - if (!s) - goto out; - asdl_seq_SET(stmts, 0, s); - } - else { - /* Only a simple_stmt can contain multiple statements. */ - REQ(n, simple_stmt); - for (i = 0; i < NCH(n); i += 2) { - if (TYPE(CHILD(n, i)) == NEWLINE) - break; - s = ast_for_stmt(&c, CHILD(n, i)); - if (!s) - goto out; - asdl_seq_SET(stmts, i / 2, s); - } - } - - res = Interactive(stmts, arena); - } - break; - case func_type_input: - n = CHILD(n, 0); - REQ(n, func_type); - - if (TYPE(CHILD(n, 1)) == typelist) { - ch = CHILD(n, 1); - /* this is overly permissive -- we don't pay any attention to - * stars on the args -- just parse them into an ordered list */ - num = 0; - for (i = 0; i < NCH(ch); i++) { - if (TYPE(CHILD(ch, i)) == test) - num++; - } - - argtypes = _Ta3_asdl_seq_new(num, arena); - - j = 0; - for (i = 0; i < NCH(ch); i++) { - if (TYPE(CHILD(ch, i)) == test) { - arg = ast_for_expr(&c, CHILD(ch, i)); - if (!arg) - goto out; - asdl_seq_SET(argtypes, j++, arg); - } - } - } - else - argtypes = _Ta3_asdl_seq_new(0, arena); - - ret = ast_for_expr(&c, CHILD(n, NCH(n) - 1)); - if (!ret) - goto out; - res = FunctionType(argtypes, ret, arena); - break; - default: - PyErr_Format(PyExc_SystemError, - "invalid node %d for Ta3AST_FromNode", TYPE(n)); - goto out; - } - out: - if (c.c_normalize) { - Py_DECREF(c.c_normalize); - } - return res; -} - -mod_ty -Ta3AST_FromNode(const node *n, PyCompilerFlags *flags, const char *filename_str, - int feature_version, PyArena *arena) -{ - mod_ty mod; - PyObject *filename; - filename = PyUnicode_DecodeFSDefault(filename_str); - if (filename == NULL) - return NULL; - mod = Ta3AST_FromNodeObject(n, flags, filename, feature_version, arena); - Py_DECREF(filename); - return mod; - -} - -/* Return the AST repr. of the operator represented as syntax (|, ^, etc.) -*/ - -static operator_ty -get_operator(struct compiling *c, const node *n) -{ - switch (TYPE(n)) { - case VBAR: - return BitOr; - case CIRCUMFLEX: - return BitXor; - case AMPER: - return BitAnd; - case LEFTSHIFT: - return LShift; - case RIGHTSHIFT: - return RShift; - case PLUS: - return Add; - case MINUS: - return Sub; - case STAR: - return Mult; - case AT: - if (c->c_feature_version < 5) { - ast_error(c, n, - "The '@' operator is only supported in Python 3.5 and greater"); - return (operator_ty)0; - } - return MatMult; - case SLASH: - return Div; - case DOUBLESLASH: - return FloorDiv; - case PERCENT: - return Mod; - default: - return (operator_ty)0; - } -} - -static const char * const FORBIDDEN[] = { - "None", - "True", - "False", - NULL, -}; - -static int -forbidden_name(struct compiling *c, identifier name, const node *n, - int full_checks) -{ - assert(PyUnicode_Check(name)); - if (_PyUnicode_EqualToASCIIString(name, "__debug__")) { - ast_error(c, n, "assignment to keyword"); - return 1; - } - if (full_checks) { - const char * const *p; - for (p = FORBIDDEN; *p; p++) { - if (_PyUnicode_EqualToASCIIString(name, *p)) { - ast_error(c, n, "assignment to keyword"); - return 1; - } - } - } - return 0; -} - -/* Set the context ctx for expr_ty e, recursively traversing e. - - Only sets context for expr kinds that "can appear in assignment context" - (according to ../Parser/Python.asdl). For other expr kinds, it sets - an appropriate syntax error and returns false. -*/ - -static int -set_context(struct compiling *c, expr_ty e, expr_context_ty ctx, const node *n) -{ - asdl_seq *s = NULL; - /* If a particular expression type can't be used for assign / delete, - set expr_name to its name and an error message will be generated. - */ - const char* expr_name = NULL; - - /* The ast defines augmented store and load contexts, but the - implementation here doesn't actually use them. The code may be - a little more complex than necessary as a result. It also means - that expressions in an augmented assignment have a Store context. - Consider restructuring so that augmented assignment uses - set_context(), too. - */ - assert(ctx != AugStore && ctx != AugLoad); - - switch (e->kind) { - case Attribute_kind: - e->v.Attribute.ctx = ctx; - if (ctx == Store && forbidden_name(c, e->v.Attribute.attr, n, 1)) - return 0; - break; - case Subscript_kind: - e->v.Subscript.ctx = ctx; - break; - case Starred_kind: - e->v.Starred.ctx = ctx; - if (!set_context(c, e->v.Starred.value, ctx, n)) - return 0; - break; - case Name_kind: - if (ctx == Store) { - if (forbidden_name(c, e->v.Name.id, n, 0)) - return 0; /* forbidden_name() calls ast_error() */ - } - e->v.Name.ctx = ctx; - break; - case List_kind: - e->v.List.ctx = ctx; - s = e->v.List.elts; - break; - case Tuple_kind: - e->v.Tuple.ctx = ctx; - s = e->v.Tuple.elts; - break; - case Lambda_kind: - expr_name = "lambda"; - break; - case Call_kind: - expr_name = "function call"; - break; - case BoolOp_kind: - case BinOp_kind: - case UnaryOp_kind: - expr_name = "operator"; - break; - case GeneratorExp_kind: - expr_name = "generator expression"; - break; - case Yield_kind: - case YieldFrom_kind: - expr_name = "yield expression"; - break; - case Await_kind: - expr_name = "await expression"; - break; - case ListComp_kind: - expr_name = "list comprehension"; - break; - case SetComp_kind: - expr_name = "set comprehension"; - break; - case DictComp_kind: - expr_name = "dict comprehension"; - break; - case Dict_kind: - case Set_kind: - case Num_kind: - case Str_kind: - case Bytes_kind: - case JoinedStr_kind: - case FormattedValue_kind: - expr_name = "literal"; - break; - case NameConstant_kind: - expr_name = "keyword"; - break; - case Ellipsis_kind: - expr_name = "Ellipsis"; - break; - case Compare_kind: - expr_name = "comparison"; - break; - case IfExp_kind: - expr_name = "conditional expression"; - break; - default: - PyErr_Format(PyExc_SystemError, - "unexpected expression in assignment %d (line %d)", - e->kind, e->lineno); - return 0; - } - /* Check for error string set by switch */ - if (expr_name) { - char buf[300]; - PyOS_snprintf(buf, sizeof(buf), - "can't %s %s", - ctx == Store ? "assign to" : "delete", - expr_name); - return ast_error(c, n, buf); - } - - /* If the LHS is a list or tuple, we need to set the assignment - context for all the contained elements. - */ - if (s) { - int i; - - for (i = 0; i < asdl_seq_LEN(s); i++) { - if (!set_context(c, (expr_ty)asdl_seq_GET(s, i), ctx, n)) - return 0; - } - } - return 1; -} - -static operator_ty -ast_for_augassign(struct compiling *c, const node *n) -{ - REQ(n, augassign); - n = CHILD(n, 0); - switch (STR(n)[0]) { - case '+': - return Add; - case '-': - return Sub; - case '/': - if (STR(n)[1] == '/') - return FloorDiv; - else - return Div; - case '%': - return Mod; - case '<': - return LShift; - case '>': - return RShift; - case '&': - return BitAnd; - case '^': - return BitXor; - case '|': - return BitOr; - case '*': - if (STR(n)[1] == '*') - return Pow; - else - return Mult; - case '@': - if (c->c_feature_version < 5) { - ast_error(c, n, - "The '@' operator is only supported in Python 3.5 and greater"); - return (operator_ty)0; - } - return MatMult; - default: - PyErr_Format(PyExc_SystemError, "invalid augassign: %s", STR(n)); - return (operator_ty)0; - } -} - -static cmpop_ty -ast_for_comp_op(struct compiling *c, const node *n) -{ - /* comp_op: '<'|'>'|'=='|'>='|'<='|'!='|'in'|'not' 'in'|'is' - |'is' 'not' - */ - REQ(n, comp_op); - if (NCH(n) == 1) { - n = CHILD(n, 0); - switch (TYPE(n)) { - case LESS: - return Lt; - case GREATER: - return Gt; - case EQEQUAL: /* == */ - return Eq; - case LESSEQUAL: - return LtE; - case GREATEREQUAL: - return GtE; - case NOTEQUAL: - return NotEq; - case NAME: - if (strcmp(STR(n), "in") == 0) - return In; - if (strcmp(STR(n), "is") == 0) - return Is; - /* fall through */ - default: - PyErr_Format(PyExc_SystemError, "invalid comp_op: %s", - STR(n)); - return (cmpop_ty)0; - } - } - else if (NCH(n) == 2) { - /* handle "not in" and "is not" */ - switch (TYPE(CHILD(n, 0))) { - case NAME: - if (strcmp(STR(CHILD(n, 1)), "in") == 0) - return NotIn; - if (strcmp(STR(CHILD(n, 0)), "is") == 0) - return IsNot; - /* fall through */ - default: - PyErr_Format(PyExc_SystemError, "invalid comp_op: %s %s", - STR(CHILD(n, 0)), STR(CHILD(n, 1))); - return (cmpop_ty)0; - } - } - PyErr_Format(PyExc_SystemError, "invalid comp_op: has %d children", - NCH(n)); - return (cmpop_ty)0; -} - -static asdl_seq * -seq_for_testlist(struct compiling *c, const node *n) -{ - /* testlist: test (',' test)* [','] - testlist_star_expr: test|star_expr (',' test|star_expr)* [','] - */ - asdl_seq *seq; - expr_ty expression; - int i; - assert(TYPE(n) == testlist || TYPE(n) == testlist_star_expr || TYPE(n) == testlist_comp); - - seq = _Ta3_asdl_seq_new((NCH(n) + 1) / 2, c->c_arena); - if (!seq) - return NULL; - - for (i = 0; i < NCH(n); i += 2) { - const node *ch = CHILD(n, i); - assert(TYPE(ch) == test || TYPE(ch) == test_nocond || TYPE(ch) == star_expr); - - expression = ast_for_expr(c, ch); - if (!expression) - return NULL; - - assert(i / 2 < seq->size); - asdl_seq_SET(seq, i / 2, expression); - } - return seq; -} - -static arg_ty -ast_for_arg(struct compiling *c, const node *n) -{ - identifier name; - expr_ty annotation = NULL; - node *ch; - arg_ty ret; - - assert(TYPE(n) == tfpdef || TYPE(n) == vfpdef); - ch = CHILD(n, 0); - name = NEW_IDENTIFIER(ch); - if (!name) - return NULL; - if (forbidden_name(c, name, ch, 0)) - return NULL; - - if (NCH(n) == 3 && TYPE(CHILD(n, 1)) == COLON) { - annotation = ast_for_expr(c, CHILD(n, 2)); - if (!annotation) - return NULL; - } - - ret = arg(name, annotation, NULL, LINENO(n), n->n_col_offset, c->c_arena); - if (!ret) - return NULL; - return ret; -} - -/* returns -1 if failed to handle keyword only arguments - returns new position to keep processing if successful - (',' tfpdef ['=' test])* - ^^^ - start pointing here - */ -static int -handle_keywordonly_args(struct compiling *c, const node *n, int start, - asdl_seq *kwonlyargs, asdl_seq *kwdefaults) -{ - PyObject *argname; - node *ch; - expr_ty expression, annotation; - arg_ty arg = NULL; - int i = start; - int j = 0; /* index for kwdefaults and kwonlyargs */ - - if (kwonlyargs == NULL) { - ast_error(c, CHILD(n, start), "named arguments must follow bare *"); - return -1; - } - assert(kwdefaults != NULL); - while (i < NCH(n)) { - ch = CHILD(n, i); - switch (TYPE(ch)) { - case vfpdef: - case tfpdef: - if (i + 1 < NCH(n) && TYPE(CHILD(n, i + 1)) == EQUAL) { - expression = ast_for_expr(c, CHILD(n, i + 2)); - if (!expression) - goto error; - asdl_seq_SET(kwdefaults, j, expression); - i += 2; /* '=' and test */ - } - else { /* setting NULL if no default value exists */ - asdl_seq_SET(kwdefaults, j, NULL); - } - if (NCH(ch) == 3) { - /* ch is NAME ':' test */ - annotation = ast_for_expr(c, CHILD(ch, 2)); - if (!annotation) - goto error; - } - else { - annotation = NULL; - } - ch = CHILD(ch, 0); - argname = NEW_IDENTIFIER(ch); - if (!argname) - goto error; - if (forbidden_name(c, argname, ch, 0)) - goto error; - arg = arg(argname, annotation, NULL, LINENO(ch), ch->n_col_offset, - c->c_arena); - if (!arg) - goto error; - asdl_seq_SET(kwonlyargs, j++, arg); - i += 1; /* the name */ - if (i < NCH(n) && TYPE(CHILD(n, i)) == COMMA) - i += 1; /* the comma, if present */ - break; - case TYPE_COMMENT: - /* arg will be equal to the last argument processed */ - arg->type_comment = NEW_TYPE_COMMENT(ch); - if (!arg->type_comment) - goto error; - i += 1; - break; - case DOUBLESTAR: - return i; - default: - ast_error(c, ch, "unexpected node"); - goto error; - } - } - return i; - error: - return -1; -} - -/* Create AST for argument list. */ - -static arguments_ty -ast_for_arguments(struct compiling *c, const node *n) -{ - /* This function handles both typedargslist (function definition) - and varargslist (lambda definition). - - parameters: '(' [typedargslist] ')' - typedargslist: (tfpdef ['=' test] (',' tfpdef ['=' test])* [',' [ - '*' [tfpdef] (',' tfpdef ['=' test])* [',' ['**' tfpdef [',']]] - | '**' tfpdef [',']]] - | '*' [tfpdef] (',' tfpdef ['=' test])* [',' ['**' tfpdef [',']]] - | '**' tfpdef [',']) - tfpdef: NAME [':' test] - varargslist: (vfpdef ['=' test] (',' vfpdef ['=' test])* [',' [ - '*' [vfpdef] (',' vfpdef ['=' test])* [',' ['**' vfpdef [',']]] - | '**' vfpdef [',']]] - | '*' [vfpdef] (',' vfpdef ['=' test])* [',' ['**' vfpdef [',']]] - | '**' vfpdef [','] - ) - vfpdef: NAME - - */ - int i, j, k, nposargs = 0, nkwonlyargs = 0; - int nposdefaults = 0, found_default = 0; - asdl_seq *posargs, *posdefaults, *kwonlyargs, *kwdefaults; - arg_ty vararg = NULL, kwarg = NULL; - arg_ty arg = NULL; - node *ch; - - if (TYPE(n) == parameters) { - if (NCH(n) == 2) /* () as argument list */ - return arguments(NULL, NULL, NULL, NULL, NULL, NULL, c->c_arena); - n = CHILD(n, 1); - } - assert(TYPE(n) == typedargslist || TYPE(n) == varargslist); - - /* First count the number of positional args & defaults. The - variable i is the loop index for this for loop and the next. - The next loop picks up where the first leaves off. - */ - for (i = 0; i < NCH(n); i++) { - ch = CHILD(n, i); - if (TYPE(ch) == STAR) { - /* skip star */ - i++; - if (i < NCH(n) && /* skip argument following star */ - (TYPE(CHILD(n, i)) == tfpdef || - TYPE(CHILD(n, i)) == vfpdef)) { - i++; - } - break; - } - if (TYPE(ch) == DOUBLESTAR) break; - if (TYPE(ch) == vfpdef || TYPE(ch) == tfpdef) nposargs++; - if (TYPE(ch) == EQUAL) nposdefaults++; - } - /* count the number of keyword only args & - defaults for keyword only args */ - for ( ; i < NCH(n); ++i) { - ch = CHILD(n, i); - if (TYPE(ch) == DOUBLESTAR) break; - if (TYPE(ch) == tfpdef || TYPE(ch) == vfpdef) nkwonlyargs++; - } - posargs = (nposargs ? _Ta3_asdl_seq_new(nposargs, c->c_arena) : NULL); - if (!posargs && nposargs) - return NULL; - kwonlyargs = (nkwonlyargs ? - _Ta3_asdl_seq_new(nkwonlyargs, c->c_arena) : NULL); - if (!kwonlyargs && nkwonlyargs) - return NULL; - posdefaults = (nposdefaults ? - _Ta3_asdl_seq_new(nposdefaults, c->c_arena) : NULL); - if (!posdefaults && nposdefaults) - return NULL; - /* The length of kwonlyargs and kwdefaults are same - since we set NULL as default for keyword only argument w/o default - - we have sequence data structure, but no dictionary */ - kwdefaults = (nkwonlyargs ? - _Ta3_asdl_seq_new(nkwonlyargs, c->c_arena) : NULL); - if (!kwdefaults && nkwonlyargs) - return NULL; - - /* tfpdef: NAME [':' test] - vfpdef: NAME - */ - i = 0; - j = 0; /* index for defaults */ - k = 0; /* index for args */ - while (i < NCH(n)) { - ch = CHILD(n, i); - switch (TYPE(ch)) { - case tfpdef: - case vfpdef: - /* XXX Need to worry about checking if TYPE(CHILD(n, i+1)) is - anything other than EQUAL or a comma? */ - /* XXX Should NCH(n) check be made a separate check? */ - if (i + 1 < NCH(n) && TYPE(CHILD(n, i + 1)) == EQUAL) { - expr_ty expression = ast_for_expr(c, CHILD(n, i + 2)); - if (!expression) - return NULL; - assert(posdefaults != NULL); - asdl_seq_SET(posdefaults, j++, expression); - i += 2; - found_default = 1; - } - else if (found_default) { - ast_error(c, n, - "non-default argument follows default argument"); - return NULL; - } - arg = ast_for_arg(c, ch); - if (!arg) - return NULL; - asdl_seq_SET(posargs, k++, arg); - i += 1; /* the name */ - if (i < NCH(n) && TYPE(CHILD(n, i)) == COMMA) - i += 1; /* the comma, if present */ - break; - case STAR: - if (i+1 >= NCH(n) || - (i+2 == NCH(n) && (TYPE(CHILD(n, i+1)) == COMMA - || TYPE(CHILD(n, i+1)) == TYPE_COMMENT))) { - ast_error(c, CHILD(n, i), - "named arguments must follow bare *"); - return NULL; - } - ch = CHILD(n, i+1); /* tfpdef or COMMA */ - if (TYPE(ch) == COMMA) { - int res = 0; - i += 2; /* now follows keyword only arguments */ - - if (i < NCH(n) && TYPE(CHILD(n, i)) == TYPE_COMMENT) { - ast_error(c, CHILD(n, i), - "bare * has associated type comment"); - return NULL; - } - - res = handle_keywordonly_args(c, n, i, - kwonlyargs, kwdefaults); - if (res == -1) return NULL; - i = res; /* res has new position to process */ - } - else { - vararg = ast_for_arg(c, ch); - if (!vararg) - return NULL; - - i += 2; /* the star and the name */ - if (i < NCH(n) && TYPE(CHILD(n, i)) == COMMA) - i += 1; /* the comma, if present */ - - if (i < NCH(n) && TYPE(CHILD(n, i)) == TYPE_COMMENT) { - vararg->type_comment = NEW_TYPE_COMMENT(CHILD(n, i)); - if (!vararg->type_comment) - return NULL; - i += 1; - } - - if (i < NCH(n) && (TYPE(CHILD(n, i)) == tfpdef - || TYPE(CHILD(n, i)) == vfpdef)) { - int res = 0; - res = handle_keywordonly_args(c, n, i, - kwonlyargs, kwdefaults); - if (res == -1) return NULL; - i = res; /* res has new position to process */ - } - } - break; - case DOUBLESTAR: - ch = CHILD(n, i+1); /* tfpdef */ - assert(TYPE(ch) == tfpdef || TYPE(ch) == vfpdef); - kwarg = ast_for_arg(c, ch); - if (!kwarg) - return NULL; - i += 2; /* the double star and the name */ - if (i < NCH(n) && TYPE(CHILD(n, i)) == COMMA) - i += 1; /* the comma, if present */ - break; - case TYPE_COMMENT: - assert(i); - - if (kwarg) - arg = kwarg; - - /* arg will be equal to the last argument processed */ - arg->type_comment = NEW_TYPE_COMMENT(ch); - if (!arg->type_comment) - return NULL; - i += 1; - break; - default: - PyErr_Format(PyExc_SystemError, - "unexpected node in varargslist: %d @ %d", - TYPE(ch), i); - return NULL; - } - } - return arguments(posargs, vararg, kwonlyargs, kwdefaults, kwarg, posdefaults, c->c_arena); -} - -static expr_ty -ast_for_dotted_name(struct compiling *c, const node *n) -{ - expr_ty e; - identifier id; - int lineno, col_offset; - int i; - - REQ(n, dotted_name); - - lineno = LINENO(n); - col_offset = n->n_col_offset; - - id = NEW_IDENTIFIER(CHILD(n, 0)); - if (!id) - return NULL; - e = Name(id, Load, lineno, col_offset, c->c_arena); - if (!e) - return NULL; - - for (i = 2; i < NCH(n); i+=2) { - id = NEW_IDENTIFIER(CHILD(n, i)); - if (!id) - return NULL; - e = Attribute(e, id, Load, lineno, col_offset, c->c_arena); - if (!e) - return NULL; - } - - return e; -} - -static expr_ty -ast_for_decorator(struct compiling *c, const node *n) -{ - /* decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE */ - expr_ty d = NULL; - expr_ty name_expr; - - REQ(n, decorator); - REQ(CHILD(n, 0), AT); - REQ(RCHILD(n, -1), NEWLINE); - - name_expr = ast_for_dotted_name(c, CHILD(n, 1)); - if (!name_expr) - return NULL; - - if (NCH(n) == 3) { /* No arguments */ - d = name_expr; - name_expr = NULL; - } - else if (NCH(n) == 5) { /* Call with no arguments */ - d = Call(name_expr, NULL, NULL, LINENO(n), - n->n_col_offset, c->c_arena); - if (!d) - return NULL; - name_expr = NULL; - } - else { - d = ast_for_call(c, CHILD(n, 3), name_expr, true); - if (!d) - return NULL; - name_expr = NULL; - } - - return d; -} - -static asdl_seq* -ast_for_decorators(struct compiling *c, const node *n) -{ - asdl_seq* decorator_seq; - expr_ty d; - int i; - - REQ(n, decorators); - decorator_seq = _Ta3_asdl_seq_new(NCH(n), c->c_arena); - if (!decorator_seq) - return NULL; - - for (i = 0; i < NCH(n); i++) { - d = ast_for_decorator(c, CHILD(n, i)); - if (!d) - return NULL; - asdl_seq_SET(decorator_seq, i, d); - } - return decorator_seq; -} - -static stmt_ty -ast_for_funcdef_impl(struct compiling *c, const node *n0, - asdl_seq *decorator_seq, bool is_async) -{ - /* funcdef: 'def' NAME parameters ['->' test] ':' [TYPE_COMMENT] suite */ - const node * const n = is_async ? CHILD(n0, 1) : n0; - identifier name; - arguments_ty args; - asdl_seq *body; - expr_ty returns = NULL; - int name_i = 1; - node *tc; - string type_comment = NULL; - - if (is_async && c->c_feature_version < 5) { - ast_error(c, n, - "Async functions are only supported in Python 3.5 and greater"); - return NULL; - } - - REQ(n, funcdef); - - name = NEW_IDENTIFIER(CHILD(n, name_i)); - if (!name) - return NULL; - if (forbidden_name(c, name, CHILD(n, name_i), 0)) - return NULL; - args = ast_for_arguments(c, CHILD(n, name_i + 1)); - if (!args) - return NULL; - if (TYPE(CHILD(n, name_i+2)) == RARROW) { - returns = ast_for_expr(c, CHILD(n, name_i + 3)); - if (!returns) - return NULL; - name_i += 2; - } - if (TYPE(CHILD(n, name_i + 3)) == TYPE_COMMENT) { - type_comment = NEW_TYPE_COMMENT(CHILD(n, name_i + 3)); - if (!type_comment) - return NULL; - name_i += 1; - } - body = ast_for_suite(c, CHILD(n, name_i + 3)); - if (!body) - return NULL; - - if (NCH(CHILD(n, name_i + 3)) > 1) { - /* Check if the suite has a type comment in it. */ - tc = CHILD(CHILD(n, name_i + 3), 1); - - if (TYPE(tc) == TYPE_COMMENT) { - if (type_comment != NULL) { - ast_error(c, n, "Cannot have two type comments on def"); - return NULL; - } - type_comment = NEW_TYPE_COMMENT(tc); - if (!type_comment) - return NULL; - } - } - - if (is_async) - return AsyncFunctionDef(name, args, body, decorator_seq, returns, - type_comment, LINENO(n0), n0->n_col_offset, c->c_arena); - else - return FunctionDef(name, args, body, decorator_seq, returns, - type_comment, LINENO(n), n->n_col_offset, c->c_arena); -} - -static stmt_ty -ast_for_async_funcdef(struct compiling *c, const node *n, asdl_seq *decorator_seq) -{ - /* async_funcdef: 'async' funcdef */ - REQ(n, async_funcdef); - REQ(CHILD(n, 0), ASYNC); - REQ(CHILD(n, 1), funcdef); - - return ast_for_funcdef_impl(c, n, decorator_seq, - true /* is_async */); -} - -static stmt_ty -ast_for_funcdef(struct compiling *c, const node *n, asdl_seq *decorator_seq) -{ - /* funcdef: 'def' NAME parameters ['->' test] ':' suite */ - return ast_for_funcdef_impl(c, n, decorator_seq, - false /* is_async */); -} - - -static stmt_ty -ast_for_async_stmt(struct compiling *c, const node *n) -{ - /* async_stmt: 'async' (funcdef | with_stmt | for_stmt) */ - REQ(n, async_stmt); - REQ(CHILD(n, 0), ASYNC); - - switch (TYPE(CHILD(n, 1))) { - case funcdef: - return ast_for_funcdef_impl(c, n, NULL, - true /* is_async */); - case with_stmt: - return ast_for_with_stmt(c, n, - true /* is_async */); - - case for_stmt: - return ast_for_for_stmt(c, n, - true /* is_async */); - - default: - PyErr_Format(PyExc_SystemError, - "invalid async stament: %s", - STR(CHILD(n, 1))); - return NULL; - } -} - -static stmt_ty -ast_for_decorated(struct compiling *c, const node *n) -{ - /* decorated: decorators (classdef | funcdef | async_funcdef) */ - stmt_ty thing = NULL; - asdl_seq *decorator_seq = NULL; - - REQ(n, decorated); - - decorator_seq = ast_for_decorators(c, CHILD(n, 0)); - if (!decorator_seq) - return NULL; - - assert(TYPE(CHILD(n, 1)) == funcdef || - TYPE(CHILD(n, 1)) == async_funcdef || - TYPE(CHILD(n, 1)) == classdef); - - if (TYPE(CHILD(n, 1)) == funcdef) { - thing = ast_for_funcdef(c, CHILD(n, 1), decorator_seq); - } else if (TYPE(CHILD(n, 1)) == classdef) { - thing = ast_for_classdef(c, CHILD(n, 1), decorator_seq); - } else if (TYPE(CHILD(n, 1)) == async_funcdef) { - thing = ast_for_async_funcdef(c, CHILD(n, 1), decorator_seq); - } - /* we count the decorators in when talking about the class' or - * function's line number */ - if (thing) { - thing->lineno = LINENO(n); - thing->col_offset = n->n_col_offset; - } - return thing; -} - -static expr_ty -ast_for_lambdef(struct compiling *c, const node *n) -{ - /* lambdef: 'lambda' [varargslist] ':' test - lambdef_nocond: 'lambda' [varargslist] ':' test_nocond */ - arguments_ty args; - expr_ty expression; - - if (NCH(n) == 3) { - args = arguments(NULL, NULL, NULL, NULL, NULL, NULL, c->c_arena); - if (!args) - return NULL; - expression = ast_for_expr(c, CHILD(n, 2)); - if (!expression) - return NULL; - } - else { - args = ast_for_arguments(c, CHILD(n, 1)); - if (!args) - return NULL; - expression = ast_for_expr(c, CHILD(n, 3)); - if (!expression) - return NULL; - } - - return Lambda(args, expression, LINENO(n), n->n_col_offset, c->c_arena); -} - -static expr_ty -ast_for_ifexpr(struct compiling *c, const node *n) -{ - /* test: or_test 'if' or_test 'else' test */ - expr_ty expression, body, orelse; - - assert(NCH(n) == 5); - body = ast_for_expr(c, CHILD(n, 0)); - if (!body) - return NULL; - expression = ast_for_expr(c, CHILD(n, 2)); - if (!expression) - return NULL; - orelse = ast_for_expr(c, CHILD(n, 4)); - if (!orelse) - return NULL; - return IfExp(expression, body, orelse, LINENO(n), n->n_col_offset, - c->c_arena); -} - -/* - Count the number of 'for' loops in a comprehension. - - Helper for ast_for_comprehension(). -*/ - -static int -count_comp_fors(struct compiling *c, const node *n) -{ - int n_fors = 0; - - count_comp_for: - n_fors++; - REQ(n, comp_for); - if (NCH(n) == 2) { - REQ(CHILD(n, 0), ASYNC); - n = CHILD(n, 1); - } - else if (NCH(n) == 1) { - n = CHILD(n, 0); - } - else { - goto error; - } - if (NCH(n) == (5)) { - n = CHILD(n, 4); - } - else { - return n_fors; - } - count_comp_iter: - REQ(n, comp_iter); - n = CHILD(n, 0); - if (TYPE(n) == comp_for) - goto count_comp_for; - else if (TYPE(n) == comp_if) { - if (NCH(n) == 3) { - n = CHILD(n, 2); - goto count_comp_iter; - } - else - return n_fors; - } - - error: - /* Should never be reached */ - PyErr_SetString(PyExc_SystemError, - "logic error in count_comp_fors"); - return -1; -} - -/* Count the number of 'if' statements in a comprehension. - - Helper for ast_for_comprehension(). -*/ - -static int -count_comp_ifs(struct compiling *c, const node *n) -{ - int n_ifs = 0; - - while (1) { - REQ(n, comp_iter); - if (TYPE(CHILD(n, 0)) == comp_for) - return n_ifs; - n = CHILD(n, 0); - REQ(n, comp_if); - n_ifs++; - if (NCH(n) == 2) - return n_ifs; - n = CHILD(n, 2); - } -} - -static asdl_seq * -ast_for_comprehension(struct compiling *c, const node *n) -{ - int i, n_fors; - asdl_seq *comps; - - n_fors = count_comp_fors(c, n); - if (n_fors == -1) - return NULL; - - comps = _Ta3_asdl_seq_new(n_fors, c->c_arena); - if (!comps) - return NULL; - - for (i = 0; i < n_fors; i++) { - comprehension_ty comp; - asdl_seq *t; - expr_ty expression, first; - node *for_ch; - node *sync_n; - int is_async = 0; - - REQ(n, comp_for); - - if (NCH(n) == 2) { - is_async = 1; - REQ(CHILD(n, 0), ASYNC); - sync_n = CHILD(n, 1); - } - else { - sync_n = CHILD(n, 0); - } - REQ(sync_n, sync_comp_for); - - /* Async comprehensions only allowed in Python 3.6 and greater */ - if (is_async && c->c_feature_version < 6) { - ast_error(c, n, - "Async comprehensions are only supported in Python 3.6 and greater"); - return NULL; - } - - for_ch = CHILD(sync_n, 1); - t = ast_for_exprlist(c, for_ch, Store); - if (!t) - return NULL; - expression = ast_for_expr(c, CHILD(sync_n, 3)); - if (!expression) - return NULL; - - /* Check the # of children rather than the length of t, since - (x for x, in ...) has 1 element in t, but still requires a Tuple. */ - first = (expr_ty)asdl_seq_GET(t, 0); - if (NCH(for_ch) == 1) - comp = comprehension(first, expression, NULL, - is_async, c->c_arena); - else - comp = comprehension(Tuple(t, Store, first->lineno, - first->col_offset, c->c_arena), - expression, NULL, is_async, c->c_arena); - if (!comp) - return NULL; - - if (NCH(sync_n) == 5) { - int j, n_ifs; - asdl_seq *ifs; - - n = CHILD(sync_n, 4); - n_ifs = count_comp_ifs(c, n); - if (n_ifs == -1) - return NULL; - - ifs = _Ta3_asdl_seq_new(n_ifs, c->c_arena); - if (!ifs) - return NULL; - - for (j = 0; j < n_ifs; j++) { - REQ(n, comp_iter); - n = CHILD(n, 0); - REQ(n, comp_if); - - expression = ast_for_expr(c, CHILD(n, 1)); - if (!expression) - return NULL; - asdl_seq_SET(ifs, j, expression); - if (NCH(n) == 3) - n = CHILD(n, 2); - } - /* on exit, must guarantee that n is a comp_for */ - if (TYPE(n) == comp_iter) - n = CHILD(n, 0); - comp->ifs = ifs; - } - asdl_seq_SET(comps, i, comp); - } - return comps; -} - -static expr_ty -ast_for_itercomp(struct compiling *c, const node *n, int type) -{ - /* testlist_comp: (test|star_expr) - * ( comp_for | (',' (test|star_expr))* [','] ) */ - expr_ty elt; - asdl_seq *comps; - node *ch; - - assert(NCH(n) > 1); - - ch = CHILD(n, 0); - elt = ast_for_expr(c, ch); - if (!elt) - return NULL; - if (elt->kind == Starred_kind) { - ast_error(c, ch, "iterable unpacking cannot be used in comprehension"); - return NULL; - } - - comps = ast_for_comprehension(c, CHILD(n, 1)); - if (!comps) - return NULL; - - if (type == COMP_GENEXP) - return GeneratorExp(elt, comps, LINENO(n), n->n_col_offset, c->c_arena); - else if (type == COMP_LISTCOMP) - return ListComp(elt, comps, LINENO(n), n->n_col_offset, c->c_arena); - else if (type == COMP_SETCOMP) - return SetComp(elt, comps, LINENO(n), n->n_col_offset, c->c_arena); - else - /* Should never happen */ - return NULL; -} - -/* Fills in the key, value pair corresponding to the dict element. In case - * of an unpacking, key is NULL. *i is advanced by the number of ast - * elements. Iff successful, nonzero is returned. - */ -static int -ast_for_dictelement(struct compiling *c, const node *n, int *i, - expr_ty *key, expr_ty *value) -{ - expr_ty expression; - if (TYPE(CHILD(n, *i)) == DOUBLESTAR) { - assert(NCH(n) - *i >= 2); - - expression = ast_for_expr(c, CHILD(n, *i + 1)); - if (!expression) - return 0; - *key = NULL; - *value = expression; - - *i += 2; - } - else { - assert(NCH(n) - *i >= 3); - - expression = ast_for_expr(c, CHILD(n, *i)); - if (!expression) - return 0; - *key = expression; - - REQ(CHILD(n, *i + 1), COLON); - - expression = ast_for_expr(c, CHILD(n, *i + 2)); - if (!expression) - return 0; - *value = expression; - - *i += 3; - } - return 1; -} - -static expr_ty -ast_for_dictcomp(struct compiling *c, const node *n) -{ - expr_ty key, value; - asdl_seq *comps; - int i = 0; - - if (!ast_for_dictelement(c, n, &i, &key, &value)) - return NULL; - assert(key); - assert(NCH(n) - i >= 1); - - comps = ast_for_comprehension(c, CHILD(n, i)); - if (!comps) - return NULL; - - return DictComp(key, value, comps, LINENO(n), n->n_col_offset, c->c_arena); -} - -static expr_ty -ast_for_dictdisplay(struct compiling *c, const node *n) -{ - int i; - int j; - int size; - asdl_seq *keys, *values; - - size = (NCH(n) + 1) / 3; /* +1 in case no trailing comma */ - keys = _Ta3_asdl_seq_new(size, c->c_arena); - if (!keys) - return NULL; - - values = _Ta3_asdl_seq_new(size, c->c_arena); - if (!values) - return NULL; - - j = 0; - for (i = 0; i < NCH(n); i++) { - expr_ty key, value; - - if (!ast_for_dictelement(c, n, &i, &key, &value)) - return NULL; - asdl_seq_SET(keys, j, key); - asdl_seq_SET(values, j, value); - - j++; - } - keys->size = j; - values->size = j; - return Dict(keys, values, LINENO(n), n->n_col_offset, c->c_arena); -} - -static expr_ty -ast_for_genexp(struct compiling *c, const node *n) -{ - assert(TYPE(n) == (testlist_comp) || TYPE(n) == (argument)); - return ast_for_itercomp(c, n, COMP_GENEXP); -} - -static expr_ty -ast_for_listcomp(struct compiling *c, const node *n) -{ - assert(TYPE(n) == (testlist_comp)); - return ast_for_itercomp(c, n, COMP_LISTCOMP); -} - -static expr_ty -ast_for_setcomp(struct compiling *c, const node *n) -{ - assert(TYPE(n) == (dictorsetmaker)); - return ast_for_itercomp(c, n, COMP_SETCOMP); -} - -static expr_ty -ast_for_setdisplay(struct compiling *c, const node *n) -{ - int i; - int size; - asdl_seq *elts; - - assert(TYPE(n) == (dictorsetmaker)); - size = (NCH(n) + 1) / 2; /* +1 in case no trailing comma */ - elts = _Ta3_asdl_seq_new(size, c->c_arena); - if (!elts) - return NULL; - for (i = 0; i < NCH(n); i += 2) { - expr_ty expression; - expression = ast_for_expr(c, CHILD(n, i)); - if (!expression) - return NULL; - asdl_seq_SET(elts, i / 2, expression); - } - return Set(elts, LINENO(n), n->n_col_offset, c->c_arena); -} - -static expr_ty -ast_for_atom(struct compiling *c, const node *n) -{ - /* atom: '(' [yield_expr|testlist_comp] ')' | '[' [testlist_comp] ']' - | '{' [dictmaker|testlist_comp] '}' | NAME | NUMBER | STRING+ - | '...' | 'None' | 'True' | 'False' - */ - node *ch = CHILD(n, 0); - - switch (TYPE(ch)) { - case NAME: { - PyObject *name; - const char *s = STR(ch); - size_t len = strlen(s); - if (len >= 4 && len <= 5) { - if (!strcmp(s, "None")) - return NameConstant(Py_None, LINENO(n), n->n_col_offset, c->c_arena); - if (!strcmp(s, "True")) - return NameConstant(Py_True, LINENO(n), n->n_col_offset, c->c_arena); - if (!strcmp(s, "False")) - return NameConstant(Py_False, LINENO(n), n->n_col_offset, c->c_arena); - } - name = new_identifier(s, c); - if (!name) - return NULL; - /* All names start in Load context, but may later be changed. */ - return Name(name, Load, LINENO(n), n->n_col_offset, c->c_arena); - } - case STRING: { - expr_ty str = parsestrplus(c, n); - if (!str) { - const char *errtype = NULL; - if (PyErr_ExceptionMatches(PyExc_UnicodeError)) - errtype = "unicode error"; - else if (PyErr_ExceptionMatches(PyExc_ValueError)) - errtype = "value error"; - if (errtype) { - char buf[128]; - const char *s = NULL; - PyObject *type, *value, *tback, *errstr; - PyErr_Fetch(&type, &value, &tback); - errstr = PyObject_Str(value); - if (errstr) - s = PyUnicode_AsUTF8(errstr); - if (s) { - PyOS_snprintf(buf, sizeof(buf), "(%s) %s", errtype, s); - } else { - PyErr_Clear(); - PyOS_snprintf(buf, sizeof(buf), "(%s) unknown error", errtype); - } - Py_XDECREF(errstr); - ast_error(c, n, buf); - Py_DECREF(type); - Py_XDECREF(value); - Py_XDECREF(tback); - } - return NULL; - } - return str; - } - case NUMBER: { - PyObject *pynum; - const char *s = STR(ch); - /* Underscores in numeric literals are only allowed in Python 3.6 or greater */ - /* Check for underscores here rather than in parse_number so we can report a line number on error */ - if (c->c_feature_version < 6 && strchr(s, '_') != NULL) { - ast_error(c, ch, - "Underscores in numeric literals are only supported in Python 3.6 and greater"); - return NULL; - } - pynum = parsenumber(c, STR(ch)); - if (!pynum) - return NULL; - - if (PyArena_AddPyObject(c->c_arena, pynum) < 0) { - Py_DECREF(pynum); - return NULL; - } - return Num(pynum, LINENO(n), n->n_col_offset, c->c_arena); - } - case ELLIPSIS: /* Ellipsis */ - return Ellipsis(LINENO(n), n->n_col_offset, c->c_arena); - case LPAR: /* some parenthesized expressions */ - ch = CHILD(n, 1); - - if (TYPE(ch) == RPAR) - return Tuple(NULL, Load, LINENO(n), n->n_col_offset, c->c_arena); - - if (TYPE(ch) == yield_expr) - return ast_for_expr(c, ch); - - /* testlist_comp: test ( comp_for | (',' test)* [','] ) */ - if ((NCH(ch) > 1) && (TYPE(CHILD(ch, 1)) == comp_for)) - return ast_for_genexp(c, ch); - - return ast_for_testlist(c, ch); - case LSQB: /* list (or list comprehension) */ - ch = CHILD(n, 1); - - if (TYPE(ch) == RSQB) - return List(NULL, Load, LINENO(n), n->n_col_offset, c->c_arena); - - REQ(ch, testlist_comp); - if (NCH(ch) == 1 || TYPE(CHILD(ch, 1)) == COMMA) { - asdl_seq *elts = seq_for_testlist(c, ch); - if (!elts) - return NULL; - - return List(elts, Load, LINENO(n), n->n_col_offset, c->c_arena); - } - else - return ast_for_listcomp(c, ch); - case LBRACE: { - /* dictorsetmaker: ( ((test ':' test | '**' test) - * (comp_for | (',' (test ':' test | '**' test))* [','])) | - * ((test | '*' test) - * (comp_for | (',' (test | '*' test))* [','])) ) */ - expr_ty res; - ch = CHILD(n, 1); - if (TYPE(ch) == RBRACE) { - /* It's an empty dict. */ - return Dict(NULL, NULL, LINENO(n), n->n_col_offset, c->c_arena); - } - else { - int is_dict = (TYPE(CHILD(ch, 0)) == DOUBLESTAR); - if (NCH(ch) == 1 || - (NCH(ch) > 1 && - TYPE(CHILD(ch, 1)) == COMMA)) { - /* It's a set display. */ - res = ast_for_setdisplay(c, ch); - } - else if (NCH(ch) > 1 && - TYPE(CHILD(ch, 1)) == comp_for) { - /* It's a set comprehension. */ - res = ast_for_setcomp(c, ch); - } - else if (NCH(ch) > 3 - is_dict && - TYPE(CHILD(ch, 3 - is_dict)) == comp_for) { - /* It's a dictionary comprehension. */ - if (is_dict) { - ast_error(c, n, "dict unpacking cannot be used in " - "dict comprehension"); - return NULL; - } - res = ast_for_dictcomp(c, ch); - } - else { - /* It's a dictionary display. */ - res = ast_for_dictdisplay(c, ch); - } - if (res) { - res->lineno = LINENO(n); - res->col_offset = n->n_col_offset; - } - return res; - } - } - default: - PyErr_Format(PyExc_SystemError, "unhandled atom %d", TYPE(ch)); - return NULL; - } -} - -static slice_ty -ast_for_slice(struct compiling *c, const node *n) -{ - node *ch; - expr_ty lower = NULL, upper = NULL, step = NULL; - - REQ(n, subscript); - - /* - subscript: test | [test] ':' [test] [sliceop] - sliceop: ':' [test] - */ - ch = CHILD(n, 0); - if (NCH(n) == 1 && TYPE(ch) == test) { - /* 'step' variable hold no significance in terms of being used over - other vars */ - step = ast_for_expr(c, ch); - if (!step) - return NULL; - - return Index(step, c->c_arena); - } - - if (TYPE(ch) == test) { - lower = ast_for_expr(c, ch); - if (!lower) - return NULL; - } - - /* If there's an upper bound it's in the second or third position. */ - if (TYPE(ch) == COLON) { - if (NCH(n) > 1) { - node *n2 = CHILD(n, 1); - - if (TYPE(n2) == test) { - upper = ast_for_expr(c, n2); - if (!upper) - return NULL; - } - } - } else if (NCH(n) > 2) { - node *n2 = CHILD(n, 2); - - if (TYPE(n2) == test) { - upper = ast_for_expr(c, n2); - if (!upper) - return NULL; - } - } - - ch = CHILD(n, NCH(n) - 1); - if (TYPE(ch) == sliceop) { - if (NCH(ch) != 1) { - ch = CHILD(ch, 1); - if (TYPE(ch) == test) { - step = ast_for_expr(c, ch); - if (!step) - return NULL; - } - } - } - - return Slice(lower, upper, step, c->c_arena); -} - -static expr_ty -ast_for_binop(struct compiling *c, const node *n) -{ - /* Must account for a sequence of expressions. - How should A op B op C by represented? - BinOp(BinOp(A, op, B), op, C). - */ - - int i, nops; - expr_ty expr1, expr2, result; - operator_ty newoperator; - - expr1 = ast_for_expr(c, CHILD(n, 0)); - if (!expr1) - return NULL; - - expr2 = ast_for_expr(c, CHILD(n, 2)); - if (!expr2) - return NULL; - - newoperator = get_operator(c, CHILD(n, 1)); - if (!newoperator) - return NULL; - - result = BinOp(expr1, newoperator, expr2, LINENO(n), n->n_col_offset, - c->c_arena); - if (!result) - return NULL; - - nops = (NCH(n) - 1) / 2; - for (i = 1; i < nops; i++) { - expr_ty tmp_result, tmp; - const node* next_oper = CHILD(n, i * 2 + 1); - - newoperator = get_operator(c, next_oper); - if (!newoperator) - return NULL; - - tmp = ast_for_expr(c, CHILD(n, i * 2 + 2)); - if (!tmp) - return NULL; - - tmp_result = BinOp(result, newoperator, tmp, - LINENO(next_oper), next_oper->n_col_offset, - c->c_arena); - if (!tmp_result) - return NULL; - result = tmp_result; - } - return result; -} - -static expr_ty -ast_for_trailer(struct compiling *c, const node *n, expr_ty left_expr) -{ - /* trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME - subscriptlist: subscript (',' subscript)* [','] - subscript: '.' '.' '.' | test | [test] ':' [test] [sliceop] - */ - REQ(n, trailer); - if (TYPE(CHILD(n, 0)) == LPAR) { - if (NCH(n) == 2) - return Call(left_expr, NULL, NULL, LINENO(n), - n->n_col_offset, c->c_arena); - else - return ast_for_call(c, CHILD(n, 1), left_expr, true); - } - else if (TYPE(CHILD(n, 0)) == DOT) { - PyObject *attr_id = NEW_IDENTIFIER(CHILD(n, 1)); - if (!attr_id) - return NULL; - return Attribute(left_expr, attr_id, Load, - LINENO(n), n->n_col_offset, c->c_arena); - } - else { - REQ(CHILD(n, 0), LSQB); - REQ(CHILD(n, 2), RSQB); - n = CHILD(n, 1); - if (NCH(n) == 1) { - slice_ty slc = ast_for_slice(c, CHILD(n, 0)); - if (!slc) - return NULL; - return Subscript(left_expr, slc, Load, LINENO(n), n->n_col_offset, - c->c_arena); - } - else { - /* The grammar is ambiguous here. The ambiguity is resolved - by treating the sequence as a tuple literal if there are - no slice features. - */ - int j; - slice_ty slc; - expr_ty e; - int simple = 1; - asdl_seq *slices, *elts; - slices = _Ta3_asdl_seq_new((NCH(n) + 1) / 2, c->c_arena); - if (!slices) - return NULL; - for (j = 0; j < NCH(n); j += 2) { - slc = ast_for_slice(c, CHILD(n, j)); - if (!slc) - return NULL; - if (slc->kind != Index_kind) - simple = 0; - asdl_seq_SET(slices, j / 2, slc); - } - if (!simple) { - return Subscript(left_expr, ExtSlice(slices, c->c_arena), - Load, LINENO(n), n->n_col_offset, c->c_arena); - } - /* extract Index values and put them in a Tuple */ - elts = _Ta3_asdl_seq_new(asdl_seq_LEN(slices), c->c_arena); - if (!elts) - return NULL; - for (j = 0; j < asdl_seq_LEN(slices); ++j) { - slc = (slice_ty)asdl_seq_GET(slices, j); - assert(slc->kind == Index_kind && slc->v.Index.value); - asdl_seq_SET(elts, j, slc->v.Index.value); - } - e = Tuple(elts, Load, LINENO(n), n->n_col_offset, c->c_arena); - if (!e) - return NULL; - return Subscript(left_expr, Index(e, c->c_arena), - Load, LINENO(n), n->n_col_offset, c->c_arena); - } - } -} - -static expr_ty -ast_for_factor(struct compiling *c, const node *n) -{ - expr_ty expression; - - expression = ast_for_expr(c, CHILD(n, 1)); - if (!expression) - return NULL; - - switch (TYPE(CHILD(n, 0))) { - case PLUS: - return UnaryOp(UAdd, expression, LINENO(n), n->n_col_offset, - c->c_arena); - case MINUS: - return UnaryOp(USub, expression, LINENO(n), n->n_col_offset, - c->c_arena); - case TILDE: - return UnaryOp(Invert, expression, LINENO(n), - n->n_col_offset, c->c_arena); - } - PyErr_Format(PyExc_SystemError, "unhandled factor: %d", - TYPE(CHILD(n, 0))); - return NULL; -} - -static expr_ty -ast_for_atom_expr(struct compiling *c, const node *n) -{ - int i, nch, start = 0; - expr_ty e, tmp; - - REQ(n, atom_expr); - nch = NCH(n); - - if (TYPE(CHILD(n, 0)) == AWAIT) { - if (c->c_feature_version < 5) { - ast_error(c, n, - "Await expressions are only supported in Python 3.5 and greater"); - return NULL; - } - start = 1; - assert(nch > 1); - } - - e = ast_for_atom(c, CHILD(n, start)); - if (!e) - return NULL; - if (nch == 1) - return e; - if (start && nch == 2) { - return Await(e, LINENO(n), n->n_col_offset, c->c_arena); - } - - for (i = start + 1; i < nch; i++) { - node *ch = CHILD(n, i); - if (TYPE(ch) != trailer) - break; - tmp = ast_for_trailer(c, ch, e); - if (!tmp) - return NULL; - tmp->lineno = e->lineno; - tmp->col_offset = e->col_offset; - e = tmp; - } - - if (start) { - /* there was an 'await' */ - return Await(e, LINENO(n), n->n_col_offset, c->c_arena); - } - else { - return e; - } -} - -static expr_ty -ast_for_power(struct compiling *c, const node *n) -{ - /* power: atom trailer* ('**' factor)* - */ - expr_ty e; - REQ(n, power); - e = ast_for_atom_expr(c, CHILD(n, 0)); - if (!e) - return NULL; - if (NCH(n) == 1) - return e; - if (TYPE(CHILD(n, NCH(n) - 1)) == factor) { - expr_ty f = ast_for_expr(c, CHILD(n, NCH(n) - 1)); - if (!f) - return NULL; - e = BinOp(e, Pow, f, LINENO(n), n->n_col_offset, c->c_arena); - } - return e; -} - -static expr_ty -ast_for_starred(struct compiling *c, const node *n) -{ - expr_ty tmp; - REQ(n, star_expr); - - tmp = ast_for_expr(c, CHILD(n, 1)); - if (!tmp) - return NULL; - - /* The Load context is changed later. */ - return Starred(tmp, Load, LINENO(n), n->n_col_offset, c->c_arena); -} - - -/* Do not name a variable 'expr'! Will cause a compile error. -*/ - -static expr_ty -ast_for_expr(struct compiling *c, const node *n) -{ - /* handle the full range of simple expressions - test: or_test ['if' or_test 'else' test] | lambdef - test_nocond: or_test | lambdef_nocond - or_test: and_test ('or' and_test)* - and_test: not_test ('and' not_test)* - not_test: 'not' not_test | comparison - comparison: expr (comp_op expr)* - expr: xor_expr ('|' xor_expr)* - xor_expr: and_expr ('^' and_expr)* - and_expr: shift_expr ('&' shift_expr)* - shift_expr: arith_expr (('<<'|'>>') arith_expr)* - arith_expr: term (('+'|'-') term)* - term: factor (('*'|'@'|'/'|'%'|'//') factor)* - factor: ('+'|'-'|'~') factor | power - power: atom_expr ['**' factor] - atom_expr: ['await'] atom trailer* - yield_expr: 'yield' [yield_arg] - */ - - asdl_seq *seq; - int i; - - loop: - switch (TYPE(n)) { - case test: - case test_nocond: - if (TYPE(CHILD(n, 0)) == lambdef || - TYPE(CHILD(n, 0)) == lambdef_nocond) - return ast_for_lambdef(c, CHILD(n, 0)); - else if (NCH(n) > 1) - return ast_for_ifexpr(c, n); - /* Fallthrough */ - case or_test: - case and_test: - if (NCH(n) == 1) { - n = CHILD(n, 0); - goto loop; - } - seq = _Ta3_asdl_seq_new((NCH(n) + 1) / 2, c->c_arena); - if (!seq) - return NULL; - for (i = 0; i < NCH(n); i += 2) { - expr_ty e = ast_for_expr(c, CHILD(n, i)); - if (!e) - return NULL; - asdl_seq_SET(seq, i / 2, e); - } - if (!strcmp(STR(CHILD(n, 1)), "and")) - return BoolOp(And, seq, LINENO(n), n->n_col_offset, - c->c_arena); - assert(!strcmp(STR(CHILD(n, 1)), "or")); - return BoolOp(Or, seq, LINENO(n), n->n_col_offset, c->c_arena); - case not_test: - if (NCH(n) == 1) { - n = CHILD(n, 0); - goto loop; - } - else { - expr_ty expression = ast_for_expr(c, CHILD(n, 1)); - if (!expression) - return NULL; - - return UnaryOp(Not, expression, LINENO(n), n->n_col_offset, - c->c_arena); - } - case comparison: - if (NCH(n) == 1) { - n = CHILD(n, 0); - goto loop; - } - else { - expr_ty expression; - asdl_int_seq *ops; - asdl_seq *cmps; - ops = _Ta3_asdl_int_seq_new(NCH(n) / 2, c->c_arena); - if (!ops) - return NULL; - cmps = _Ta3_asdl_seq_new(NCH(n) / 2, c->c_arena); - if (!cmps) { - return NULL; - } - for (i = 1; i < NCH(n); i += 2) { - cmpop_ty newoperator; - - newoperator = ast_for_comp_op(c, CHILD(n, i)); - if (!newoperator) { - return NULL; - } - - expression = ast_for_expr(c, CHILD(n, i + 1)); - if (!expression) { - return NULL; - } - - asdl_seq_SET(ops, i / 2, newoperator); - asdl_seq_SET(cmps, i / 2, expression); - } - expression = ast_for_expr(c, CHILD(n, 0)); - if (!expression) { - return NULL; - } - - return Compare(expression, ops, cmps, LINENO(n), - n->n_col_offset, c->c_arena); - } - break; - - case star_expr: - return ast_for_starred(c, n); - /* The next five cases all handle BinOps. The main body of code - is the same in each case, but the switch turned inside out to - reuse the code for each type of operator. - */ - case expr: - case xor_expr: - case and_expr: - case shift_expr: - case arith_expr: - case term: - if (NCH(n) == 1) { - n = CHILD(n, 0); - goto loop; - } - return ast_for_binop(c, n); - case yield_expr: { - node *an = NULL; - node *en = NULL; - int is_from = 0; - expr_ty exp = NULL; - if (NCH(n) > 1) - an = CHILD(n, 1); /* yield_arg */ - if (an) { - en = CHILD(an, NCH(an) - 1); - if (NCH(an) == 2) { - is_from = 1; - exp = ast_for_expr(c, en); - } - else - exp = ast_for_testlist(c, en); - if (!exp) - return NULL; - } - if (is_from) - return YieldFrom(exp, LINENO(n), n->n_col_offset, c->c_arena); - return Yield(exp, LINENO(n), n->n_col_offset, c->c_arena); - } - case factor: - if (NCH(n) == 1) { - n = CHILD(n, 0); - goto loop; - } - return ast_for_factor(c, n); - case power: - return ast_for_power(c, n); - default: - PyErr_Format(PyExc_SystemError, "unhandled expr: %d", TYPE(n)); - return NULL; - } - /* should never get here unless if error is set */ - return NULL; -} - -static expr_ty -ast_for_call(struct compiling *c, const node *n, expr_ty func, bool allowgen) -{ - /* - arglist: argument (',' argument)* [','] - argument: ( test [comp_for] | '*' test | test '=' test | '**' test ) - */ - - int i, nargs, nkeywords; - int ndoublestars; - asdl_seq *args; - asdl_seq *keywords; - - REQ(n, arglist); - - nargs = 0; - nkeywords = 0; - for (i = 0; i < NCH(n); i++) { - node *ch = CHILD(n, i); - if (TYPE(ch) == argument) { - if (NCH(ch) == 1) - nargs++; - else if (TYPE(CHILD(ch, 1)) == comp_for) { - nargs++; - if (!allowgen) { - ast_error(c, ch, "invalid syntax"); - return NULL; - } - if (NCH(n) > 1) { - ast_error(c, ch, "Generator expression must be parenthesized"); - return NULL; - } - } - else if (TYPE(CHILD(ch, 0)) == STAR) - nargs++; - else - /* TYPE(CHILD(ch, 0)) == DOUBLESTAR or keyword argument */ - nkeywords++; - } - } - - args = _Ta3_asdl_seq_new(nargs, c->c_arena); - if (!args) - return NULL; - keywords = _Ta3_asdl_seq_new(nkeywords, c->c_arena); - if (!keywords) - return NULL; - - nargs = 0; /* positional arguments + iterable argument unpackings */ - nkeywords = 0; /* keyword arguments + keyword argument unpackings */ - ndoublestars = 0; /* just keyword argument unpackings */ - for (i = 0; i < NCH(n); i++) { - node *ch = CHILD(n, i); - if (TYPE(ch) == argument) { - expr_ty e; - node *chch = CHILD(ch, 0); - if (NCH(ch) == 1) { - /* a positional argument */ - if (nkeywords) { - if (ndoublestars) { - ast_error(c, chch, - "positional argument follows " - "keyword argument unpacking"); - } - else { - ast_error(c, chch, - "positional argument follows " - "keyword argument"); - } - return NULL; - } - e = ast_for_expr(c, chch); - if (!e) - return NULL; - asdl_seq_SET(args, nargs++, e); - } - else if (TYPE(chch) == STAR) { - /* an iterable argument unpacking */ - expr_ty starred; - if (ndoublestars) { - ast_error(c, chch, - "iterable argument unpacking follows " - "keyword argument unpacking"); - return NULL; - } - e = ast_for_expr(c, CHILD(ch, 1)); - if (!e) - return NULL; - starred = Starred(e, Load, LINENO(chch), - chch->n_col_offset, - c->c_arena); - if (!starred) - return NULL; - asdl_seq_SET(args, nargs++, starred); - - } - else if (TYPE(chch) == DOUBLESTAR) { - /* a keyword argument unpacking */ - keyword_ty kw; - i++; - e = ast_for_expr(c, CHILD(ch, 1)); - if (!e) - return NULL; - kw = keyword(NULL, e, c->c_arena); - asdl_seq_SET(keywords, nkeywords++, kw); - ndoublestars++; - } - else if (TYPE(CHILD(ch, 1)) == comp_for) { - /* the lone generator expression */ - e = ast_for_genexp(c, ch); - if (!e) - return NULL; - asdl_seq_SET(args, nargs++, e); - } - else { - /* a keyword argument */ - keyword_ty kw; - identifier key, tmp; - int k; - - /* chch is test, but must be an identifier? */ - e = ast_for_expr(c, chch); - if (!e) - return NULL; - /* f(lambda x: x[0] = 3) ends up getting parsed with - * LHS test = lambda x: x[0], and RHS test = 3. - * SF bug 132313 points out that complaining about a keyword - * then is very confusing. - */ - if (e->kind == Lambda_kind) { - ast_error(c, chch, - "lambda cannot contain assignment"); - return NULL; - } - else if (e->kind != Name_kind) { - ast_error(c, chch, - "keyword can't be an expression"); - return NULL; - } - else if (forbidden_name(c, e->v.Name.id, ch, 1)) { - return NULL; - } - key = e->v.Name.id; - for (k = 0; k < nkeywords; k++) { - tmp = ((keyword_ty)asdl_seq_GET(keywords, k))->arg; - if (tmp && !PyUnicode_Compare(tmp, key)) { - ast_error(c, chch, - "keyword argument repeated"); - return NULL; - } - } - e = ast_for_expr(c, CHILD(ch, 2)); - if (!e) - return NULL; - kw = keyword(key, e, c->c_arena); - if (!kw) - return NULL; - asdl_seq_SET(keywords, nkeywords++, kw); - } - } - } - - return Call(func, args, keywords, func->lineno, func->col_offset, c->c_arena); -} - -static expr_ty -ast_for_testlist(struct compiling *c, const node* n) -{ - /* testlist_comp: test (comp_for | (',' test)* [',']) */ - /* testlist: test (',' test)* [','] */ - assert(NCH(n) > 0); - if (TYPE(n) == testlist_comp) { - if (NCH(n) > 1) - assert(TYPE(CHILD(n, 1)) != comp_for); - } - else { - assert(TYPE(n) == testlist || - TYPE(n) == testlist_star_expr); - } - if (NCH(n) == 1) - return ast_for_expr(c, CHILD(n, 0)); - else { - asdl_seq *tmp = seq_for_testlist(c, n); - if (!tmp) - return NULL; - return Tuple(tmp, Load, LINENO(n), n->n_col_offset, c->c_arena); - } -} - -static stmt_ty -ast_for_expr_stmt(struct compiling *c, const node *n) -{ - int num; - - REQ(n, expr_stmt); - /* expr_stmt: testlist_star_expr (annassign | augassign (yield_expr|testlist) | - ('=' (yield_expr|testlist_star_expr))* [TYPE_COMMENT]) - annassign: ':' test ['=' test] - testlist_star_expr: (test|star_expr) (',' test|star_expr)* [','] - augassign: '+=' | '-=' | '*=' | '@=' | '/=' | '%=' | '&=' | '|=' | '^=' - | '<<=' | '>>=' | '**=' | '//=' - test: ... here starts the operator precedence dance - */ - num = NCH(n); - - if (num == 1 || (num == 2 && TYPE(CHILD(n, 1)) == TYPE_COMMENT)) { - expr_ty e = ast_for_testlist(c, CHILD(n, 0)); - if (!e) - return NULL; - - return Expr(e, LINENO(n), n->n_col_offset, c->c_arena); - } - else if (TYPE(CHILD(n, 1)) == augassign) { - expr_ty expr1, expr2; - operator_ty newoperator; - node *ch = CHILD(n, 0); - - expr1 = ast_for_testlist(c, ch); - if (!expr1) - return NULL; - if(!set_context(c, expr1, Store, ch)) - return NULL; - /* set_context checks that most expressions are not the left side. - Augmented assignments can only have a name, a subscript, or an - attribute on the left, though, so we have to explicitly check for - those. */ - switch (expr1->kind) { - case Name_kind: - case Attribute_kind: - case Subscript_kind: - break; - default: - ast_error(c, ch, "illegal expression for augmented assignment"); - return NULL; - } - - ch = CHILD(n, 2); - if (TYPE(ch) == testlist) - expr2 = ast_for_testlist(c, ch); - else - expr2 = ast_for_expr(c, ch); - if (!expr2) - return NULL; - - newoperator = ast_for_augassign(c, CHILD(n, 1)); - if (!newoperator) - return NULL; - - return AugAssign(expr1, newoperator, expr2, LINENO(n), n->n_col_offset, c->c_arena); - } - else if (TYPE(CHILD(n, 1)) == annassign) { - expr_ty expr1, expr2, expr3; - node *ch = CHILD(n, 0); - node *deep, *ann = CHILD(n, 1); - int simple = 1; - - /* AnnAssigns are only allowed in Python 3.6 or greater */ - if (c->c_feature_version < 6) { - ast_error(c, ch, - "Variable annotation syntax is only supported in Python 3.6 and greater"); - return NULL; - } - - /* we keep track of parens to qualify (x) as expression not name */ - deep = ch; - while (NCH(deep) == 1) { - deep = CHILD(deep, 0); - } - if (NCH(deep) > 0 && TYPE(CHILD(deep, 0)) == LPAR) { - simple = 0; - } - expr1 = ast_for_testlist(c, ch); - if (!expr1) { - return NULL; - } - switch (expr1->kind) { - case Name_kind: - if (forbidden_name(c, expr1->v.Name.id, n, 0)) { - return NULL; - } - expr1->v.Name.ctx = Store; - break; - case Attribute_kind: - if (forbidden_name(c, expr1->v.Attribute.attr, n, 1)) { - return NULL; - } - expr1->v.Attribute.ctx = Store; - break; - case Subscript_kind: - expr1->v.Subscript.ctx = Store; - break; - case List_kind: - ast_error(c, ch, - "only single target (not list) can be annotated"); - return NULL; - case Tuple_kind: - ast_error(c, ch, - "only single target (not tuple) can be annotated"); - return NULL; - default: - ast_error(c, ch, - "illegal target for annotation"); - return NULL; - } - - if (expr1->kind != Name_kind) { - simple = 0; - } - ch = CHILD(ann, 1); - expr2 = ast_for_expr(c, ch); - if (!expr2) { - return NULL; - } - if (NCH(ann) == 2) { - return AnnAssign(expr1, expr2, NULL, simple, - LINENO(n), n->n_col_offset, c->c_arena); - } - else { - ch = CHILD(ann, 3); - expr3 = ast_for_expr(c, ch); - if (!expr3) { - return NULL; - } - return AnnAssign(expr1, expr2, expr3, simple, - LINENO(n), n->n_col_offset, c->c_arena); - } - } - else { - int i, nch_minus_type, has_type_comment; - asdl_seq *targets; - node *value; - expr_ty expression; - string type_comment; - - /* a normal assignment */ - REQ(CHILD(n, 1), EQUAL); - - has_type_comment = TYPE(CHILD(n, num - 1)) == TYPE_COMMENT; - nch_minus_type = num - has_type_comment; - - targets = _Ta3_asdl_seq_new(nch_minus_type / 2, c->c_arena); - if (!targets) - return NULL; - for (i = 0; i < nch_minus_type - 2; i += 2) { - expr_ty e; - node *ch = CHILD(n, i); - if (TYPE(ch) == yield_expr) { - ast_error(c, ch, "assignment to yield expression not possible"); - return NULL; - } - e = ast_for_testlist(c, ch); - if (!e) - return NULL; - - /* set context to assign */ - if (!set_context(c, e, Store, CHILD(n, i))) - return NULL; - - asdl_seq_SET(targets, i / 2, e); - } - value = CHILD(n, nch_minus_type - 1); - if (TYPE(value) == testlist_star_expr) - expression = ast_for_testlist(c, value); - else - expression = ast_for_expr(c, value); - if (!expression) - return NULL; - if (has_type_comment) { - type_comment = NEW_TYPE_COMMENT(CHILD(n, nch_minus_type)); - if (!type_comment) - return NULL; - } - else - type_comment = NULL; - return Assign(targets, expression, type_comment, LINENO(n), n->n_col_offset, c->c_arena); - } -} - - -static asdl_seq * -ast_for_exprlist(struct compiling *c, const node *n, expr_context_ty context) -{ - asdl_seq *seq; - int i; - expr_ty e; - - REQ(n, exprlist); - - seq = _Ta3_asdl_seq_new((NCH(n) + 1) / 2, c->c_arena); - if (!seq) - return NULL; - for (i = 0; i < NCH(n); i += 2) { - e = ast_for_expr(c, CHILD(n, i)); - if (!e) - return NULL; - asdl_seq_SET(seq, i / 2, e); - if (context && !set_context(c, e, context, CHILD(n, i))) - return NULL; - } - return seq; -} - -static stmt_ty -ast_for_del_stmt(struct compiling *c, const node *n) -{ - asdl_seq *expr_list; - - /* del_stmt: 'del' exprlist */ - REQ(n, del_stmt); - - expr_list = ast_for_exprlist(c, CHILD(n, 1), Del); - if (!expr_list) - return NULL; - return Delete(expr_list, LINENO(n), n->n_col_offset, c->c_arena); -} - -static stmt_ty -ast_for_flow_stmt(struct compiling *c, const node *n) -{ - /* - flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt - | yield_stmt - break_stmt: 'break' - continue_stmt: 'continue' - return_stmt: 'return' [testlist] - yield_stmt: yield_expr - yield_expr: 'yield' testlist | 'yield' 'from' test - raise_stmt: 'raise' [test [',' test [',' test]]] - */ - node *ch; - - REQ(n, flow_stmt); - ch = CHILD(n, 0); - switch (TYPE(ch)) { - case break_stmt: - return Break(LINENO(n), n->n_col_offset, c->c_arena); - case continue_stmt: - return Continue(LINENO(n), n->n_col_offset, c->c_arena); - case yield_stmt: { /* will reduce to yield_expr */ - expr_ty exp = ast_for_expr(c, CHILD(ch, 0)); - if (!exp) - return NULL; - return Expr(exp, LINENO(n), n->n_col_offset, c->c_arena); - } - case return_stmt: - if (NCH(ch) == 1) - return Return(NULL, LINENO(n), n->n_col_offset, c->c_arena); - else { - expr_ty expression = ast_for_testlist(c, CHILD(ch, 1)); - if (!expression) - return NULL; - return Return(expression, LINENO(n), n->n_col_offset, c->c_arena); - } - case raise_stmt: - if (NCH(ch) == 1) - return Raise(NULL, NULL, LINENO(n), n->n_col_offset, c->c_arena); - else if (NCH(ch) >= 2) { - expr_ty cause = NULL; - expr_ty expression = ast_for_expr(c, CHILD(ch, 1)); - if (!expression) - return NULL; - if (NCH(ch) == 4) { - cause = ast_for_expr(c, CHILD(ch, 3)); - if (!cause) - return NULL; - } - return Raise(expression, cause, LINENO(n), n->n_col_offset, c->c_arena); - } - /* fall through */ - default: - PyErr_Format(PyExc_SystemError, - "unexpected flow_stmt: %d", TYPE(ch)); - return NULL; - } -} - -static alias_ty -alias_for_import_name(struct compiling *c, const node *n, int store) -{ - /* - import_as_name: NAME ['as' NAME] - dotted_as_name: dotted_name ['as' NAME] - dotted_name: NAME ('.' NAME)* - */ - identifier str, name; - - loop: - switch (TYPE(n)) { - case import_as_name: { - node *name_node = CHILD(n, 0); - str = NULL; - name = NEW_IDENTIFIER(name_node); - if (!name) - return NULL; - if (NCH(n) == 3) { - node *str_node = CHILD(n, 2); - str = NEW_IDENTIFIER(str_node); - if (!str) - return NULL; - if (store && forbidden_name(c, str, str_node, 0)) - return NULL; - } - else { - if (forbidden_name(c, name, name_node, 0)) - return NULL; - } - return alias(name, str, c->c_arena); - } - case dotted_as_name: - if (NCH(n) == 1) { - n = CHILD(n, 0); - goto loop; - } - else { - node *asname_node = CHILD(n, 2); - alias_ty a = alias_for_import_name(c, CHILD(n, 0), 0); - if (!a) - return NULL; - assert(!a->asname); - a->asname = NEW_IDENTIFIER(asname_node); - if (!a->asname) - return NULL; - if (forbidden_name(c, a->asname, asname_node, 0)) - return NULL; - return a; - } - break; - case dotted_name: - if (NCH(n) == 1) { - node *name_node = CHILD(n, 0); - name = NEW_IDENTIFIER(name_node); - if (!name) - return NULL; - if (store && forbidden_name(c, name, name_node, 0)) - return NULL; - return alias(name, NULL, c->c_arena); - } - else { - /* Create a string of the form "a.b.c" */ - int i; - size_t len; - char *s; - PyObject *uni; - - len = 0; - for (i = 0; i < NCH(n); i += 2) - /* length of string plus one for the dot */ - len += strlen(STR(CHILD(n, i))) + 1; - len--; /* the last name doesn't have a dot */ - str = PyBytes_FromStringAndSize(NULL, len); - if (!str) - return NULL; - s = PyBytes_AS_STRING(str); - if (!s) - return NULL; - for (i = 0; i < NCH(n); i += 2) { - char *sch = STR(CHILD(n, i)); - strcpy(s, STR(CHILD(n, i))); - s += strlen(sch); - *s++ = '.'; - } - --s; - *s = '\0'; - uni = PyUnicode_DecodeUTF8(PyBytes_AS_STRING(str), - PyBytes_GET_SIZE(str), - NULL); - Py_DECREF(str); - if (!uni) - return NULL; - str = uni; - PyUnicode_InternInPlace(&str); - if (PyArena_AddPyObject(c->c_arena, str) < 0) { - Py_DECREF(str); - return NULL; - } - return alias(str, NULL, c->c_arena); - } - break; - case STAR: - str = PyUnicode_InternFromString("*"); - if (!str) - return NULL; - if (PyArena_AddPyObject(c->c_arena, str) < 0) { - Py_DECREF(str); - return NULL; - } - return alias(str, NULL, c->c_arena); - default: - PyErr_Format(PyExc_SystemError, - "unexpected import name: %d", TYPE(n)); - return NULL; - } - - PyErr_SetString(PyExc_SystemError, "unhandled import name condition"); - return NULL; -} - -static stmt_ty -ast_for_import_stmt(struct compiling *c, const node *n) -{ - /* - import_stmt: import_name | import_from - import_name: 'import' dotted_as_names - import_from: 'from' (('.' | '...')* dotted_name | ('.' | '...')+) - 'import' ('*' | '(' import_as_names ')' | import_as_names) - */ - int lineno; - int col_offset; - int i; - asdl_seq *aliases; - - REQ(n, import_stmt); - lineno = LINENO(n); - col_offset = n->n_col_offset; - n = CHILD(n, 0); - if (TYPE(n) == import_name) { - n = CHILD(n, 1); - REQ(n, dotted_as_names); - aliases = _Ta3_asdl_seq_new((NCH(n) + 1) / 2, c->c_arena); - if (!aliases) - return NULL; - for (i = 0; i < NCH(n); i += 2) { - alias_ty import_alias = alias_for_import_name(c, CHILD(n, i), 1); - if (!import_alias) - return NULL; - asdl_seq_SET(aliases, i / 2, import_alias); - } - return Import(aliases, lineno, col_offset, c->c_arena); - } - else if (TYPE(n) == import_from) { - int n_children; - int idx, ndots = 0; - alias_ty mod = NULL; - identifier modname = NULL; - - /* Count the number of dots (for relative imports) and check for the - optional module name */ - for (idx = 1; idx < NCH(n); idx++) { - if (TYPE(CHILD(n, idx)) == dotted_name) { - mod = alias_for_import_name(c, CHILD(n, idx), 0); - if (!mod) - return NULL; - idx++; - break; - } else if (TYPE(CHILD(n, idx)) == ELLIPSIS) { - /* three consecutive dots are tokenized as one ELLIPSIS */ - ndots += 3; - continue; - } else if (TYPE(CHILD(n, idx)) != DOT) { - break; - } - ndots++; - } - idx++; /* skip over the 'import' keyword */ - switch (TYPE(CHILD(n, idx))) { - case STAR: - /* from ... import * */ - n = CHILD(n, idx); - n_children = 1; - break; - case LPAR: - /* from ... import (x, y, z) */ - n = CHILD(n, idx + 1); - n_children = NCH(n); - break; - case import_as_names: - /* from ... import x, y, z */ - n = CHILD(n, idx); - n_children = NCH(n); - if (n_children % 2 == 0) { - ast_error(c, n, "trailing comma not allowed without" - " surrounding parentheses"); - return NULL; - } - break; - default: - ast_error(c, n, "Unexpected node-type in from-import"); - return NULL; - } - - aliases = _Ta3_asdl_seq_new((n_children + 1) / 2, c->c_arena); - if (!aliases) - return NULL; - - /* handle "from ... import *" special b/c there's no children */ - if (TYPE(n) == STAR) { - alias_ty import_alias = alias_for_import_name(c, n, 1); - if (!import_alias) - return NULL; - asdl_seq_SET(aliases, 0, import_alias); - } - else { - for (i = 0; i < NCH(n); i += 2) { - alias_ty import_alias = alias_for_import_name(c, CHILD(n, i), 1); - if (!import_alias) - return NULL; - asdl_seq_SET(aliases, i / 2, import_alias); - } - } - if (mod != NULL) - modname = mod->name; - return ImportFrom(modname, aliases, ndots, lineno, col_offset, - c->c_arena); - } - PyErr_Format(PyExc_SystemError, - "unknown import statement: starts with command '%s'", - STR(CHILD(n, 0))); - return NULL; -} - -static stmt_ty -ast_for_global_stmt(struct compiling *c, const node *n) -{ - /* global_stmt: 'global' NAME (',' NAME)* */ - identifier name; - asdl_seq *s; - int i; - - REQ(n, global_stmt); - s = _Ta3_asdl_seq_new(NCH(n) / 2, c->c_arena); - if (!s) - return NULL; - for (i = 1; i < NCH(n); i += 2) { - name = NEW_IDENTIFIER(CHILD(n, i)); - if (!name) - return NULL; - asdl_seq_SET(s, i / 2, name); - } - return Global(s, LINENO(n), n->n_col_offset, c->c_arena); -} - -static stmt_ty -ast_for_nonlocal_stmt(struct compiling *c, const node *n) -{ - /* nonlocal_stmt: 'nonlocal' NAME (',' NAME)* */ - identifier name; - asdl_seq *s; - int i; - - REQ(n, nonlocal_stmt); - s = _Ta3_asdl_seq_new(NCH(n) / 2, c->c_arena); - if (!s) - return NULL; - for (i = 1; i < NCH(n); i += 2) { - name = NEW_IDENTIFIER(CHILD(n, i)); - if (!name) - return NULL; - asdl_seq_SET(s, i / 2, name); - } - return Nonlocal(s, LINENO(n), n->n_col_offset, c->c_arena); -} - -static stmt_ty -ast_for_assert_stmt(struct compiling *c, const node *n) -{ - /* assert_stmt: 'assert' test [',' test] */ - REQ(n, assert_stmt); - if (NCH(n) == 2) { - expr_ty expression = ast_for_expr(c, CHILD(n, 1)); - if (!expression) - return NULL; - return Assert(expression, NULL, LINENO(n), n->n_col_offset, c->c_arena); - } - else if (NCH(n) == 4) { - expr_ty expr1, expr2; - - expr1 = ast_for_expr(c, CHILD(n, 1)); - if (!expr1) - return NULL; - expr2 = ast_for_expr(c, CHILD(n, 3)); - if (!expr2) - return NULL; - - return Assert(expr1, expr2, LINENO(n), n->n_col_offset, c->c_arena); - } - PyErr_Format(PyExc_SystemError, - "improper number of parts to 'assert' statement: %d", - NCH(n)); - return NULL; -} - -static asdl_seq * -ast_for_suite(struct compiling *c, const node *n) -{ - /* suite: simple_stmt | NEWLINE [TYPE_COMMENT NEWLINE] INDENT stmt+ DEDENT */ - asdl_seq *seq; - stmt_ty s; - int i, total, num, end, pos = 0; - node *ch; - - REQ(n, suite); - - total = num_stmts(n); - seq = _Ta3_asdl_seq_new(total, c->c_arena); - if (!seq) - return NULL; - if (TYPE(CHILD(n, 0)) == simple_stmt) { - n = CHILD(n, 0); - /* simple_stmt always ends with a NEWLINE, - and may have a trailing SEMI - */ - end = NCH(n) - 1; - if (TYPE(CHILD(n, end - 1)) == SEMI) - end--; - /* loop by 2 to skip semi-colons */ - for (i = 0; i < end; i += 2) { - ch = CHILD(n, i); - s = ast_for_stmt(c, ch); - if (!s) - return NULL; - asdl_seq_SET(seq, pos++, s); - } - } - else { - i = 2; - if (TYPE(CHILD(n, 1)) == TYPE_COMMENT) - i += 2; - - for (; i < (NCH(n) - 1); i++) { - ch = CHILD(n, i); - REQ(ch, stmt); - num = num_stmts(ch); - if (num == 1) { - /* small_stmt or compound_stmt with only one child */ - s = ast_for_stmt(c, ch); - if (!s) - return NULL; - asdl_seq_SET(seq, pos++, s); - } - else { - int j; - ch = CHILD(ch, 0); - REQ(ch, simple_stmt); - for (j = 0; j < NCH(ch); j += 2) { - /* statement terminates with a semi-colon ';' */ - if (NCH(CHILD(ch, j)) == 0) { - assert((j + 1) == NCH(ch)); - break; - } - s = ast_for_stmt(c, CHILD(ch, j)); - if (!s) - return NULL; - asdl_seq_SET(seq, pos++, s); - } - } - } - } - assert(pos == seq->size); - return seq; -} - -static stmt_ty -ast_for_if_stmt(struct compiling *c, const node *n) -{ - /* if_stmt: 'if' test ':' suite ('elif' test ':' suite)* - ['else' ':' suite] - */ - char *s; - - REQ(n, if_stmt); - - if (NCH(n) == 4) { - expr_ty expression; - asdl_seq *suite_seq; - - expression = ast_for_expr(c, CHILD(n, 1)); - if (!expression) - return NULL; - suite_seq = ast_for_suite(c, CHILD(n, 3)); - if (!suite_seq) - return NULL; - - return If(expression, suite_seq, NULL, LINENO(n), n->n_col_offset, - c->c_arena); - } - - s = STR(CHILD(n, 4)); - /* s[2], the third character in the string, will be - 's' for el_s_e, or - 'i' for el_i_f - */ - if (s[2] == 's') { - expr_ty expression; - asdl_seq *seq1, *seq2; - - expression = ast_for_expr(c, CHILD(n, 1)); - if (!expression) - return NULL; - seq1 = ast_for_suite(c, CHILD(n, 3)); - if (!seq1) - return NULL; - seq2 = ast_for_suite(c, CHILD(n, 6)); - if (!seq2) - return NULL; - - return If(expression, seq1, seq2, LINENO(n), n->n_col_offset, - c->c_arena); - } - else if (s[2] == 'i') { - int i, n_elif, has_else = 0; - expr_ty expression; - asdl_seq *suite_seq; - asdl_seq *orelse = NULL; - n_elif = NCH(n) - 4; - /* must reference the child n_elif+1 since 'else' token is third, - not fourth, child from the end. */ - if (TYPE(CHILD(n, (n_elif + 1))) == NAME - && STR(CHILD(n, (n_elif + 1)))[2] == 's') { - has_else = 1; - n_elif -= 3; - } - n_elif /= 4; - - if (has_else) { - asdl_seq *suite_seq2; - - orelse = _Ta3_asdl_seq_new(1, c->c_arena); - if (!orelse) - return NULL; - expression = ast_for_expr(c, CHILD(n, NCH(n) - 6)); - if (!expression) - return NULL; - suite_seq = ast_for_suite(c, CHILD(n, NCH(n) - 4)); - if (!suite_seq) - return NULL; - suite_seq2 = ast_for_suite(c, CHILD(n, NCH(n) - 1)); - if (!suite_seq2) - return NULL; - - asdl_seq_SET(orelse, 0, - If(expression, suite_seq, suite_seq2, - LINENO(CHILD(n, NCH(n) - 6)), - CHILD(n, NCH(n) - 6)->n_col_offset, - c->c_arena)); - /* the just-created orelse handled the last elif */ - n_elif--; - } - - for (i = 0; i < n_elif; i++) { - int off = 5 + (n_elif - i - 1) * 4; - asdl_seq *newobj = _Ta3_asdl_seq_new(1, c->c_arena); - if (!newobj) - return NULL; - expression = ast_for_expr(c, CHILD(n, off)); - if (!expression) - return NULL; - suite_seq = ast_for_suite(c, CHILD(n, off + 2)); - if (!suite_seq) - return NULL; - - asdl_seq_SET(newobj, 0, - If(expression, suite_seq, orelse, - LINENO(CHILD(n, off)), - CHILD(n, off)->n_col_offset, c->c_arena)); - orelse = newobj; - } - expression = ast_for_expr(c, CHILD(n, 1)); - if (!expression) - return NULL; - suite_seq = ast_for_suite(c, CHILD(n, 3)); - if (!suite_seq) - return NULL; - return If(expression, suite_seq, orelse, - LINENO(n), n->n_col_offset, c->c_arena); - } - - PyErr_Format(PyExc_SystemError, - "unexpected token in 'if' statement: %s", s); - return NULL; -} - -static stmt_ty -ast_for_while_stmt(struct compiling *c, const node *n) -{ - /* while_stmt: 'while' test ':' suite ['else' ':' suite] */ - REQ(n, while_stmt); - - if (NCH(n) == 4) { - expr_ty expression; - asdl_seq *suite_seq; - - expression = ast_for_expr(c, CHILD(n, 1)); - if (!expression) - return NULL; - suite_seq = ast_for_suite(c, CHILD(n, 3)); - if (!suite_seq) - return NULL; - return While(expression, suite_seq, NULL, LINENO(n), n->n_col_offset, c->c_arena); - } - else if (NCH(n) == 7) { - expr_ty expression; - asdl_seq *seq1, *seq2; - - expression = ast_for_expr(c, CHILD(n, 1)); - if (!expression) - return NULL; - seq1 = ast_for_suite(c, CHILD(n, 3)); - if (!seq1) - return NULL; - seq2 = ast_for_suite(c, CHILD(n, 6)); - if (!seq2) - return NULL; - - return While(expression, seq1, seq2, LINENO(n), n->n_col_offset, c->c_arena); - } - - PyErr_Format(PyExc_SystemError, - "wrong number of tokens for 'while' statement: %d", - NCH(n)); - return NULL; -} - -static stmt_ty -ast_for_for_stmt(struct compiling *c, const node *n0, bool is_async) -{ - const node * const n = is_async ? CHILD(n0, 1) : n0; - asdl_seq *_target, *seq = NULL, *suite_seq; - expr_ty expression; - expr_ty target, first; - const node *node_target; - int has_type_comment; - string type_comment; - - if (is_async && c->c_feature_version < 5) { - ast_error(c, n, - "Async for loops are only supported in Python 3.5 and greater"); - return NULL; - } - - /* for_stmt: 'for' exprlist 'in' testlist ':' [TYPE_COMMENT] suite ['else' ':' suite] */ - REQ(n, for_stmt); - - has_type_comment = TYPE(CHILD(n, 5)) == TYPE_COMMENT; - - if (NCH(n) == 9 + has_type_comment) { - seq = ast_for_suite(c, CHILD(n, 8 + has_type_comment)); - if (!seq) - return NULL; - } - - node_target = CHILD(n, 1); - _target = ast_for_exprlist(c, node_target, Store); - if (!_target) - return NULL; - /* Check the # of children rather than the length of _target, since - for x, in ... has 1 element in _target, but still requires a Tuple. */ - first = (expr_ty)asdl_seq_GET(_target, 0); - if (NCH(node_target) == 1) - target = first; - else - target = Tuple(_target, Store, first->lineno, first->col_offset, c->c_arena); - - expression = ast_for_testlist(c, CHILD(n, 3)); - if (!expression) - return NULL; - suite_seq = ast_for_suite(c, CHILD(n, 5 + has_type_comment)); - if (!suite_seq) - return NULL; - - if (has_type_comment) { - type_comment = NEW_TYPE_COMMENT(CHILD(n, 5)); - if (!type_comment) - return NULL; - } - else - type_comment = NULL; - - if (is_async) - return AsyncFor(target, expression, suite_seq, seq, type_comment, - LINENO(n0), n0->n_col_offset, - c->c_arena); - else - return For(target, expression, suite_seq, seq, type_comment, - LINENO(n), n->n_col_offset, - c->c_arena); -} - -static excepthandler_ty -ast_for_except_clause(struct compiling *c, const node *exc, node *body) -{ - /* except_clause: 'except' [test ['as' test]] */ - REQ(exc, except_clause); - REQ(body, suite); - - if (NCH(exc) == 1) { - asdl_seq *suite_seq = ast_for_suite(c, body); - if (!suite_seq) - return NULL; - - return ExceptHandler(NULL, NULL, suite_seq, LINENO(exc), - exc->n_col_offset, c->c_arena); - } - else if (NCH(exc) == 2) { - expr_ty expression; - asdl_seq *suite_seq; - - expression = ast_for_expr(c, CHILD(exc, 1)); - if (!expression) - return NULL; - suite_seq = ast_for_suite(c, body); - if (!suite_seq) - return NULL; - - return ExceptHandler(expression, NULL, suite_seq, LINENO(exc), - exc->n_col_offset, c->c_arena); - } - else if (NCH(exc) == 4) { - asdl_seq *suite_seq; - expr_ty expression; - identifier e = NEW_IDENTIFIER(CHILD(exc, 3)); - if (!e) - return NULL; - if (forbidden_name(c, e, CHILD(exc, 3), 0)) - return NULL; - expression = ast_for_expr(c, CHILD(exc, 1)); - if (!expression) - return NULL; - suite_seq = ast_for_suite(c, body); - if (!suite_seq) - return NULL; - - return ExceptHandler(expression, e, suite_seq, LINENO(exc), - exc->n_col_offset, c->c_arena); - } - - PyErr_Format(PyExc_SystemError, - "wrong number of children for 'except' clause: %d", - NCH(exc)); - return NULL; -} - -static stmt_ty -ast_for_try_stmt(struct compiling *c, const node *n) -{ - const int nch = NCH(n); - int n_except = (nch - 3)/3; - asdl_seq *body, *handlers = NULL, *orelse = NULL, *finally = NULL; - - REQ(n, try_stmt); - - body = ast_for_suite(c, CHILD(n, 2)); - if (body == NULL) - return NULL; - - if (TYPE(CHILD(n, nch - 3)) == NAME) { - if (strcmp(STR(CHILD(n, nch - 3)), "finally") == 0) { - if (nch >= 9 && TYPE(CHILD(n, nch - 6)) == NAME) { - /* we can assume it's an "else", - because nch >= 9 for try-else-finally and - it would otherwise have a type of except_clause */ - orelse = ast_for_suite(c, CHILD(n, nch - 4)); - if (orelse == NULL) - return NULL; - n_except--; - } - - finally = ast_for_suite(c, CHILD(n, nch - 1)); - if (finally == NULL) - return NULL; - n_except--; - } - else { - /* we can assume it's an "else", - otherwise it would have a type of except_clause */ - orelse = ast_for_suite(c, CHILD(n, nch - 1)); - if (orelse == NULL) - return NULL; - n_except--; - } - } - else if (TYPE(CHILD(n, nch - 3)) != except_clause) { - ast_error(c, n, "malformed 'try' statement"); - return NULL; - } - - if (n_except > 0) { - int i; - /* process except statements to create a try ... except */ - handlers = _Ta3_asdl_seq_new(n_except, c->c_arena); - if (handlers == NULL) - return NULL; - - for (i = 0; i < n_except; i++) { - excepthandler_ty e = ast_for_except_clause(c, CHILD(n, 3 + i * 3), - CHILD(n, 5 + i * 3)); - if (!e) - return NULL; - asdl_seq_SET(handlers, i, e); - } - } - - assert(finally != NULL || asdl_seq_LEN(handlers)); - return Try(body, handlers, orelse, finally, LINENO(n), n->n_col_offset, c->c_arena); -} - -/* with_item: test ['as' expr] */ -static withitem_ty -ast_for_with_item(struct compiling *c, const node *n) -{ - expr_ty context_expr, optional_vars = NULL; - - REQ(n, with_item); - context_expr = ast_for_expr(c, CHILD(n, 0)); - if (!context_expr) - return NULL; - if (NCH(n) == 3) { - optional_vars = ast_for_expr(c, CHILD(n, 2)); - - if (!optional_vars) { - return NULL; - } - if (!set_context(c, optional_vars, Store, n)) { - return NULL; - } - } - - return withitem(context_expr, optional_vars, c->c_arena); -} - -/* with_stmt: 'with' with_item (',' with_item)* ':' [TYPE_COMMENT] suite */ -static stmt_ty -ast_for_with_stmt(struct compiling *c, const node *n0, bool is_async) -{ - const node * const n = is_async ? CHILD(n0, 1) : n0; - int i, n_items, nch_minus_type, has_type_comment; - asdl_seq *items, *body; - string type_comment; - - if (is_async && c->c_feature_version < 5) { - ast_error(c, n, - "Async with statements are only supported in Python 3.5 and greater"); - return NULL; - } - - REQ(n, with_stmt); - - has_type_comment = TYPE(CHILD(n, NCH(n) - 2)) == TYPE_COMMENT; - nch_minus_type = NCH(n) - has_type_comment; - - n_items = (nch_minus_type - 2) / 2; - items = _Ta3_asdl_seq_new(n_items, c->c_arena); - if (!items) - return NULL; - for (i = 1; i < nch_minus_type - 2; i += 2) { - withitem_ty item = ast_for_with_item(c, CHILD(n, i)); - if (!item) - return NULL; - asdl_seq_SET(items, (i - 1) / 2, item); - } - - body = ast_for_suite(c, CHILD(n, NCH(n) - 1)); - if (!body) - return NULL; - - if (has_type_comment) { - type_comment = NEW_TYPE_COMMENT(CHILD(n, NCH(n) - 2)); - if (!type_comment) - return NULL; - } - else - type_comment = NULL; - - if (is_async) - return AsyncWith(items, body, type_comment, LINENO(n0), n0->n_col_offset, c->c_arena); - else - return With(items, body, type_comment, LINENO(n), n->n_col_offset, c->c_arena); -} - -static stmt_ty -ast_for_classdef(struct compiling *c, const node *n, asdl_seq *decorator_seq) -{ - /* classdef: 'class' NAME ['(' arglist ')'] ':' suite */ - PyObject *classname; - asdl_seq *s; - expr_ty call; - - REQ(n, classdef); - - if (NCH(n) == 4) { /* class NAME ':' suite */ - s = ast_for_suite(c, CHILD(n, 3)); - if (!s) - return NULL; - classname = NEW_IDENTIFIER(CHILD(n, 1)); - if (!classname) - return NULL; - if (forbidden_name(c, classname, CHILD(n, 3), 0)) - return NULL; - return ClassDef(classname, NULL, NULL, s, decorator_seq, - LINENO(n), n->n_col_offset, c->c_arena); - } - - if (TYPE(CHILD(n, 3)) == RPAR) { /* class NAME '(' ')' ':' suite */ - s = ast_for_suite(c, CHILD(n, 5)); - if (!s) - return NULL; - classname = NEW_IDENTIFIER(CHILD(n, 1)); - if (!classname) - return NULL; - if (forbidden_name(c, classname, CHILD(n, 3), 0)) - return NULL; - return ClassDef(classname, NULL, NULL, s, decorator_seq, - LINENO(n), n->n_col_offset, c->c_arena); - } - - /* class NAME '(' arglist ')' ':' suite */ - /* build up a fake Call node so we can extract its pieces */ - { - PyObject *dummy_name; - expr_ty dummy; - dummy_name = NEW_IDENTIFIER(CHILD(n, 1)); - if (!dummy_name) - return NULL; - dummy = Name(dummy_name, Load, LINENO(n), n->n_col_offset, c->c_arena); - call = ast_for_call(c, CHILD(n, 3), dummy, false); - if (!call) - return NULL; - } - s = ast_for_suite(c, CHILD(n, 6)); - if (!s) - return NULL; - classname = NEW_IDENTIFIER(CHILD(n, 1)); - if (!classname) - return NULL; - if (forbidden_name(c, classname, CHILD(n, 1), 0)) - return NULL; - - return ClassDef(classname, call->v.Call.args, call->v.Call.keywords, s, - decorator_seq, LINENO(n), n->n_col_offset, c->c_arena); -} - -static stmt_ty -ast_for_stmt(struct compiling *c, const node *n) -{ - if (TYPE(n) == stmt) { - assert(NCH(n) == 1); - n = CHILD(n, 0); - } - if (TYPE(n) == simple_stmt) { - assert(num_stmts(n) == 1); - n = CHILD(n, 0); - } - if (TYPE(n) == small_stmt) { - n = CHILD(n, 0); - /* small_stmt: expr_stmt | del_stmt | pass_stmt | flow_stmt - | import_stmt | global_stmt | nonlocal_stmt | assert_stmt - */ - switch (TYPE(n)) { - case expr_stmt: - return ast_for_expr_stmt(c, n); - case del_stmt: - return ast_for_del_stmt(c, n); - case pass_stmt: - return Pass(LINENO(n), n->n_col_offset, c->c_arena); - case flow_stmt: - return ast_for_flow_stmt(c, n); - case import_stmt: - return ast_for_import_stmt(c, n); - case global_stmt: - return ast_for_global_stmt(c, n); - case nonlocal_stmt: - return ast_for_nonlocal_stmt(c, n); - case assert_stmt: - return ast_for_assert_stmt(c, n); - default: - PyErr_Format(PyExc_SystemError, - "unhandled small_stmt: TYPE=%d NCH=%d\n", - TYPE(n), NCH(n)); - return NULL; - } - } - else { - /* compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt - | funcdef | classdef | decorated | async_stmt - */ - node *ch = CHILD(n, 0); - REQ(n, compound_stmt); - switch (TYPE(ch)) { - case if_stmt: - return ast_for_if_stmt(c, ch); - case while_stmt: - return ast_for_while_stmt(c, ch); - case for_stmt: - return ast_for_for_stmt(c, ch, 0); - case try_stmt: - return ast_for_try_stmt(c, ch); - case with_stmt: - return ast_for_with_stmt(c, ch, 0); - case funcdef: - return ast_for_funcdef(c, ch, NULL); - case classdef: - return ast_for_classdef(c, ch, NULL); - case decorated: - return ast_for_decorated(c, ch); - case async_stmt: - return ast_for_async_stmt(c, ch); - default: - PyErr_Format(PyExc_SystemError, - "unhandled small_stmt: TYPE=%d NCH=%d\n", - TYPE(n), NCH(n)); - return NULL; - } - } -} - -static PyObject * -parsenumber_raw(struct compiling *c, const char *s) -{ - const char *end; - long x; - double dx; - Py_complex compl; - int imflag; - - assert(s != NULL); - errno = 0; - end = s + strlen(s) - 1; - imflag = *end == 'j' || *end == 'J'; - if (s[0] == '0') { - x = (long) PyOS_strtoul(s, (char **)&end, 0); - if (x < 0 && errno == 0) { - return PyLong_FromString(s, (char **)0, 0); - } - } - else - x = PyOS_strtol(s, (char **)&end, 0); - if (*end == '\0') { - if (errno != 0) - return PyLong_FromString(s, (char **)0, 0); - return PyLong_FromLong(x); - } - /* XXX Huge floats may silently fail */ - if (imflag) { - compl.real = 0.; - compl.imag = PyOS_string_to_double(s, (char **)&end, NULL); - if (compl.imag == -1.0 && PyErr_Occurred()) - return NULL; - return PyComplex_FromCComplex(compl); - } - else - { - dx = PyOS_string_to_double(s, NULL, NULL); - if (dx == -1.0 && PyErr_Occurred()) - return NULL; - return PyFloat_FromDouble(dx); - } -} - -static PyObject * -parsenumber(struct compiling *c, const char *s) -{ - char *dup, *end; - PyObject *res = NULL; - - assert(s != NULL); - - if (strchr(s, '_') == NULL) { - return parsenumber_raw(c, s); - } - /* Create a duplicate without underscores. */ - dup = PyMem_Malloc(strlen(s) + 1); - if (dup == NULL) { - return PyErr_NoMemory(); - } - end = dup; - for (; *s; s++) { - if (*s != '_') { - *end++ = *s; - } - } - *end = '\0'; - res = parsenumber_raw(c, dup); - PyMem_Free(dup); - return res; -} - -static PyObject * -decode_utf8(struct compiling *c, const char **sPtr, const char *end) -{ - const char *s, *t; - t = s = *sPtr; - /* while (s < end && *s != '\\') s++; */ /* inefficient for u".." */ - while (s < end && (*s & 0x80)) s++; - *sPtr = s; - return PyUnicode_DecodeUTF8(t, s - t, NULL); -} - -static int -warn_invalid_escape_sequence(struct compiling *c, const node *n, - unsigned char first_invalid_escape_char) -{ - PyObject *msg = PyUnicode_FromFormat("invalid escape sequence \\%c", - first_invalid_escape_char); - if (msg == NULL) { - return -1; - } - if (PyErr_WarnExplicitObject(PyExc_DeprecationWarning, msg, - c->c_filename, LINENO(n), - NULL, NULL) < 0) - { - if (PyErr_ExceptionMatches(PyExc_DeprecationWarning)) { - const char *s; - - /* Replace the DeprecationWarning exception with a SyntaxError - to get a more accurate error report */ - PyErr_Clear(); - - s = PyUnicode_AsUTF8(msg); - if (s != NULL) { - ast_error(c, n, s); - } - } - Py_DECREF(msg); - return -1; - } - Py_DECREF(msg); - return 0; -} - -static PyObject * -decode_unicode_with_escapes(struct compiling *c, const node *n, const char *s, - size_t len) -{ - PyObject *v, *u; - char *buf; - char *p; - const char *end; - const char *first_invalid_escape; - - /* check for integer overflow */ - if (len > SIZE_MAX / 6) - return NULL; - /* "ä" (2 bytes) may become "\U000000E4" (10 bytes), or 1:5 - "\ä" (3 bytes) may become "\u005c\U000000E4" (16 bytes), or ~1:6 */ - u = PyBytes_FromStringAndSize((char *)NULL, len * 6); - if (u == NULL) - return NULL; - p = buf = PyBytes_AsString(u); - end = s + len; - while (s < end) { - if (*s == '\\') { - *p++ = *s++; - if (s >= end || *s & 0x80) { - strcpy(p, "u005c"); - p += 5; - if (s >= end) - break; - } - } - if (*s & 0x80) { /* XXX inefficient */ - PyObject *w; - int kind; - void *data; - Py_ssize_t len, i; - w = decode_utf8(c, &s, end); - if (w == NULL) { - Py_DECREF(u); - return NULL; - } - kind = PyUnicode_KIND(w); - data = PyUnicode_DATA(w); - len = PyUnicode_GET_LENGTH(w); - for (i = 0; i < len; i++) { - Py_UCS4 chr = PyUnicode_READ(kind, data, i); - sprintf(p, "\\U%08x", chr); - p += 10; - } - /* Should be impossible to overflow */ - assert(p - buf <= PyBytes_GET_SIZE(u)); - Py_DECREF(w); - } else { - *p++ = *s++; - } - } - len = p - buf; - s = buf; - - v = _PyUnicode_DecodeUnicodeEscape(s, len, NULL, &first_invalid_escape); - - if (v != NULL && first_invalid_escape != NULL) { - if (warn_invalid_escape_sequence(c, n, *first_invalid_escape) < 0) { - /* We have not decref u before because first_invalid_escape points - inside u. */ - Py_XDECREF(u); - Py_DECREF(v); - return NULL; - } - } - Py_XDECREF(u); - return v; -} - -static PyObject * -decode_bytes_with_escapes(struct compiling *c, const node *n, const char *s, - size_t len) -{ - const char *first_invalid_escape; - - #if PY_MINOR_VERSION < 9 - PyObject *result = _PyBytes_DecodeEscape(s, len, NULL, 0, NULL, - &first_invalid_escape); - #else - PyObject *result = _PyBytes_DecodeEscape(s, len, NULL, - &first_invalid_escape); - #endif - if (result == NULL) - return NULL; - - if (first_invalid_escape != NULL) { - if (warn_invalid_escape_sequence(c, n, *first_invalid_escape) < 0) { - Py_DECREF(result); - return NULL; - } - } - return result; -} - -/* Shift locations for the given node and all its children by adding `lineno` - and `col_offset` to existing locations. */ -static void fstring_shift_node_locations(node *n, int lineno, int col_offset) -{ - int i; - n->n_col_offset = n->n_col_offset + col_offset; - for (i = 0; i < NCH(n); ++i) { - if (n->n_lineno && n->n_lineno < CHILD(n, i)->n_lineno) { - /* Shifting column offsets unnecessary if there's been newlines. */ - col_offset = 0; - } - fstring_shift_node_locations(CHILD(n, i), lineno, col_offset); - } - n->n_lineno = n->n_lineno + lineno; -} - -/* Fix locations for the given node and its children. - - `parent` is the enclosing node. - `n` is the node which locations are going to be fixed relative to parent. - `expr_str` is the child node's string representation, including braces. -*/ -static void -fstring_fix_node_location(const node *parent, node *n, char *expr_str) -{ - char *substr = NULL; - char *start; - int lines = LINENO(parent) - 1; - int cols = parent->n_col_offset; - /* Find the full fstring to fix location information in `n`. */ - while (parent && parent->n_type != STRING) - parent = parent->n_child; - if (parent && parent->n_str) { - substr = strstr(parent->n_str, expr_str); - if (substr) { - start = substr; - while (start > parent->n_str) { - if (start[0] == '\n') - break; - start--; - } - cols += substr - start; - /* Fix lineno in mulitline strings. */ - while ((substr = strchr(substr + 1, '\n'))) - lines--; - } - } - fstring_shift_node_locations(n, lines, cols); -} - -/* Compile this expression in to an expr_ty. Add parens around the - expression, in order to allow leading spaces in the expression. */ -static expr_ty -fstring_compile_expr(const char *expr_start, const char *expr_end, - struct compiling *c, const node *n) - -{ - PyCompilerFlags cf; - node *mod_n; - mod_ty mod; - char *str; - Py_ssize_t len; - const char *s; - int iflags = 0; - - assert(expr_end >= expr_start); - assert(*(expr_start-1) == '{'); - assert(*expr_end == '}' || *expr_end == '!' || *expr_end == ':'); - - /* If the substring is all whitespace, it's an error. We need to catch this - here, and not when we call PyParser_SimpleParseStringFlagsFilename, - because turning the expression '' in to '()' would go from being invalid - to valid. */ - for (s = expr_start; s != expr_end; s++) { - char c = *s; - /* The Python parser ignores only the following whitespace - characters (\r already is converted to \n). */ - if (!(c == ' ' || c == '\t' || c == '\n' || c == '\f')) { - break; - } - } - if (s == expr_end) { - ast_error(c, n, "f-string: empty expression not allowed"); - return NULL; - } - - len = expr_end - expr_start; - /* Allocate 3 extra bytes: open paren, close paren, null byte. */ - str = PyMem_RawMalloc(len + 3); - if (str == NULL) { - PyErr_NoMemory(); - return NULL; - } - - str[0] = '('; - memcpy(str+1, expr_start, len); - str[len+1] = ')'; - str[len+2] = 0; - - cf.cf_flags = PyCF_ONLY_AST; - _Ta3Parser_UpdateFlags(&cf, &iflags, c->c_feature_version); - mod_n = Ta3Parser_SimpleParseStringFlagsFilename(str, "", - Py_eval_input, iflags); - if (!mod_n) { - PyMem_RawFree(str); - return NULL; - } - /* Reuse str to find the correct column offset. */ - str[0] = '{'; - str[len+1] = '}'; - fstring_fix_node_location(n, mod_n, str); - mod = Ta3AST_FromNode(mod_n, &cf, "", c->c_feature_version, c->c_arena); - PyMem_RawFree(str); - Ta3Node_Free(mod_n); - if (!mod) - return NULL; - return mod->v.Expression.body; -} - -/* Return -1 on error. - - Return 0 if we reached the end of the literal. - - Return 1 if we haven't reached the end of the literal, but we want - the caller to process the literal up to this point. Used for - doubled braces. -*/ -static int -fstring_find_literal(const char **str, const char *end, int raw, - PyObject **literal, int recurse_lvl, - struct compiling *c, const node *n) -{ - /* Get any literal string. It ends when we hit an un-doubled left - brace (which isn't part of a unicode name escape such as - "\N{EULER CONSTANT}"), or the end of the string. */ - - const char *s = *str; - const char *literal_start = s; - int result = 0; - - assert(*literal == NULL); - while (s < end) { - char ch = *s++; - if (!raw && ch == '\\' && s < end) { - ch = *s++; - if (ch == 'N') { - if (s < end && *s++ == '{') { - while (s < end && *s++ != '}') { - } - continue; - } - break; - } - if (ch == '{' && warn_invalid_escape_sequence(c, n, ch) < 0) { - return -1; - } - } - if (ch == '{' || ch == '}') { - /* Check for doubled braces, but only at the top level. If - we checked at every level, then f'{0:{3}}' would fail - with the two closing braces. */ - if (recurse_lvl == 0) { - if (s < end && *s == ch) { - /* We're going to tell the caller that the literal ends - here, but that they should continue scanning. But also - skip over the second brace when we resume scanning. */ - *str = s + 1; - result = 1; - goto done; - } - - /* Where a single '{' is the start of a new expression, a - single '}' is not allowed. */ - if (ch == '}') { - *str = s - 1; - ast_error(c, n, "f-string: single '}' is not allowed"); - return -1; - } - } - /* We're either at a '{', which means we're starting another - expression; or a '}', which means we're at the end of this - f-string (for a nested format_spec). */ - s--; - break; - } - } - *str = s; - assert(s <= end); - assert(s == end || *s == '{' || *s == '}'); -done: - if (literal_start != s) { - if (raw) - *literal = PyUnicode_DecodeUTF8Stateful(literal_start, - s - literal_start, - NULL, NULL); - else - *literal = decode_unicode_with_escapes(c, n, literal_start, - s - literal_start); - if (!*literal) - return -1; - } - return result; -} - -/* Forward declaration because parsing is recursive. */ -static expr_ty -fstring_parse(const char **str, const char *end, int raw, int recurse_lvl, - struct compiling *c, const node *n); - -/* Parse the f-string at *str, ending at end. We know *str starts an - expression (so it must be a '{'). Returns the FormattedValue node, - which includes the expression, conversion character, and - format_spec expression. - - Note that I don't do a perfect job here: I don't make sure that a - closing brace doesn't match an opening paren, for example. It - doesn't need to error on all invalid expressions, just correctly - find the end of all valid ones. Any errors inside the expression - will be caught when we parse it later. */ -static int -fstring_find_expr(const char **str, const char *end, int raw, int recurse_lvl, - expr_ty *expression, struct compiling *c, const node *n) -{ - /* Return -1 on error, else 0. */ - - const char *expr_start; - const char *expr_end; - expr_ty simple_expression; - expr_ty format_spec = NULL; /* Optional format specifier. */ - int conversion = -1; /* The conversion char. -1 if not specified. */ - - /* 0 if we're not in a string, else the quote char we're trying to - match (single or double quote). */ - char quote_char = 0; - - /* If we're inside a string, 1=normal, 3=triple-quoted. */ - int string_type = 0; - - /* Keep track of nesting level for braces/parens/brackets in - expressions. */ - Py_ssize_t nested_depth = 0; - - /* Can only nest one level deep. */ - if (recurse_lvl >= 2) { - ast_error(c, n, "f-string: expressions nested too deeply"); - return -1; - } - - /* The first char must be a left brace, or we wouldn't have gotten - here. Skip over it. */ - assert(**str == '{'); - *str += 1; - - expr_start = *str; - for (; *str < end; (*str)++) { - char ch; - - /* Loop invariants. */ - assert(nested_depth >= 0); - assert(*str >= expr_start && *str < end); - if (quote_char) - assert(string_type == 1 || string_type == 3); - else - assert(string_type == 0); - - ch = **str; - /* Nowhere inside an expression is a backslash allowed. */ - if (ch == '\\') { - /* Error: can't include a backslash character, inside - parens or strings or not. */ - ast_error(c, n, "f-string expression part " - "cannot include a backslash"); - return -1; - } - if (quote_char) { - /* We're inside a string. See if we're at the end. */ - /* This code needs to implement the same non-error logic - as tok_get from tokenizer.c, at the letter_quote - label. To actually share that code would be a - nightmare. But, it's unlikely to change and is small, - so duplicate it here. Note we don't need to catch all - of the errors, since they'll be caught when parsing the - expression. We just need to match the non-error - cases. Thus we can ignore \n in single-quoted strings, - for example. Or non-terminated strings. */ - if (ch == quote_char) { - /* Does this match the string_type (single or triple - quoted)? */ - if (string_type == 3) { - if (*str+2 < end && *(*str+1) == ch && *(*str+2) == ch) { - /* We're at the end of a triple quoted string. */ - *str += 2; - string_type = 0; - quote_char = 0; - continue; - } - } else { - /* We're at the end of a normal string. */ - quote_char = 0; - string_type = 0; - continue; - } - } - } else if (ch == '\'' || ch == '"') { - /* Is this a triple quoted string? */ - if (*str+2 < end && *(*str+1) == ch && *(*str+2) == ch) { - string_type = 3; - *str += 2; - } else { - /* Start of a normal string. */ - string_type = 1; - } - /* Start looking for the end of the string. */ - quote_char = ch; - } else if (ch == '[' || ch == '{' || ch == '(') { - nested_depth++; - } else if (nested_depth != 0 && - (ch == ']' || ch == '}' || ch == ')')) { - nested_depth--; - } else if (ch == '#') { - /* Error: can't include a comment character, inside parens - or not. */ - ast_error(c, n, "f-string expression part cannot include '#'"); - return -1; - } else if (nested_depth == 0 && - (ch == '!' || ch == ':' || ch == '}')) { - /* First, test for the special case of "!=". Since '=' is - not an allowed conversion character, nothing is lost in - this test. */ - if (ch == '!' && *str+1 < end && *(*str+1) == '=') { - /* This isn't a conversion character, just continue. */ - continue; - } - /* Normal way out of this loop. */ - break; - } else { - /* Just consume this char and loop around. */ - } - } - expr_end = *str; - /* If we leave this loop in a string or with mismatched parens, we - don't care. We'll get a syntax error when compiling the - expression. But, we can produce a better error message, so - let's just do that.*/ - if (quote_char) { - ast_error(c, n, "f-string: unterminated string"); - return -1; - } - if (nested_depth) { - ast_error(c, n, "f-string: mismatched '(', '{', or '['"); - return -1; - } - - if (*str >= end) - goto unexpected_end_of_string; - - /* Compile the expression as soon as possible, so we show errors - related to the expression before errors related to the - conversion or format_spec. */ - simple_expression = fstring_compile_expr(expr_start, expr_end, c, n); - if (!simple_expression) - return -1; - - /* Check for a conversion char, if present. */ - if (**str == '!') { - *str += 1; - if (*str >= end) - goto unexpected_end_of_string; - - conversion = **str; - *str += 1; - - /* Validate the conversion. */ - if (!(conversion == 's' || conversion == 'r' - || conversion == 'a')) { - ast_error(c, n, "f-string: invalid conversion character: " - "expected 's', 'r', or 'a'"); - return -1; - } - } - - /* Check for the format spec, if present. */ - if (*str >= end) - goto unexpected_end_of_string; - if (**str == ':') { - *str += 1; - if (*str >= end) - goto unexpected_end_of_string; - - /* Parse the format spec. */ - format_spec = fstring_parse(str, end, raw, recurse_lvl+1, c, n); - if (!format_spec) - return -1; - } - - if (*str >= end || **str != '}') - goto unexpected_end_of_string; - - /* We're at a right brace. Consume it. */ - assert(*str < end); - assert(**str == '}'); - *str += 1; - - /* And now create the FormattedValue node that represents this - entire expression with the conversion and format spec. */ - *expression = FormattedValue(simple_expression, conversion, - format_spec, LINENO(n), n->n_col_offset, - c->c_arena); - if (!*expression) - return -1; - - return 0; - -unexpected_end_of_string: - ast_error(c, n, "f-string: expecting '}'"); - return -1; -} - -/* Return -1 on error. - - Return 0 if we have a literal (possible zero length) and an - expression (zero length if at the end of the string. - - Return 1 if we have a literal, but no expression, and we want the - caller to call us again. This is used to deal with doubled - braces. - - When called multiple times on the string 'a{{b{0}c', this function - will return: - - 1. the literal 'a{' with no expression, and a return value - of 1. Despite the fact that there's no expression, the return - value of 1 means we're not finished yet. - - 2. the literal 'b' and the expression '0', with a return value of - 0. The fact that there's an expression means we're not finished. - - 3. literal 'c' with no expression and a return value of 0. The - combination of the return value of 0 with no expression means - we're finished. -*/ -static int -fstring_find_literal_and_expr(const char **str, const char *end, int raw, - int recurse_lvl, PyObject **literal, - expr_ty *expression, - struct compiling *c, const node *n) -{ - int result; - - assert(*literal == NULL && *expression == NULL); - - /* Get any literal string. */ - result = fstring_find_literal(str, end, raw, literal, recurse_lvl, c, n); - if (result < 0) - goto error; - - assert(result == 0 || result == 1); - - if (result == 1) - /* We have a literal, but don't look at the expression. */ - return 1; - - if (*str >= end || **str == '}') - /* We're at the end of the string or the end of a nested - f-string: no expression. The top-level error case where we - expect to be at the end of the string but we're at a '}' is - handled later. */ - return 0; - - /* We must now be the start of an expression, on a '{'. */ - assert(**str == '{'); - - if (fstring_find_expr(str, end, raw, recurse_lvl, expression, c, n) < 0) - goto error; - - return 0; - -error: - Py_CLEAR(*literal); - return -1; -} - -#define EXPRLIST_N_CACHED 64 - -typedef struct { - /* Incrementally build an array of expr_ty, so be used in an - asdl_seq. Cache some small but reasonably sized number of - expr_ty's, and then after that start dynamically allocating, - doubling the number allocated each time. Note that the f-string - f'{0}a{1}' contains 3 expr_ty's: 2 FormattedValue's, and one - Str for the literal 'a'. So you add expr_ty's about twice as - fast as you add exressions in an f-string. */ - - Py_ssize_t allocated; /* Number we've allocated. */ - Py_ssize_t size; /* Number we've used. */ - expr_ty *p; /* Pointer to the memory we're actually - using. Will point to 'data' until we - start dynamically allocating. */ - expr_ty data[EXPRLIST_N_CACHED]; -} ExprList; - -#ifdef NDEBUG -#define ExprList_check_invariants(l) -#else -static void -ExprList_check_invariants(ExprList *l) -{ - /* Check our invariants. Make sure this object is "live", and - hasn't been deallocated. */ - assert(l->size >= 0); - assert(l->p != NULL); - if (l->size <= EXPRLIST_N_CACHED) - assert(l->data == l->p); -} -#endif - -static void -ExprList_Init(ExprList *l) -{ - l->allocated = EXPRLIST_N_CACHED; - l->size = 0; - - /* Until we start allocating dynamically, p points to data. */ - l->p = l->data; - - ExprList_check_invariants(l); -} - -static int -ExprList_Append(ExprList *l, expr_ty exp) -{ - ExprList_check_invariants(l); - if (l->size >= l->allocated) { - /* We need to alloc (or realloc) the memory. */ - Py_ssize_t new_size = l->allocated * 2; - - /* See if we've ever allocated anything dynamically. */ - if (l->p == l->data) { - Py_ssize_t i; - /* We're still using the cached data. Switch to - alloc-ing. */ - l->p = PyMem_RawMalloc(sizeof(expr_ty) * new_size); - if (!l->p) - return -1; - /* Copy the cached data into the new buffer. */ - for (i = 0; i < l->size; i++) - l->p[i] = l->data[i]; - } else { - /* Just realloc. */ - expr_ty *tmp = PyMem_RawRealloc(l->p, sizeof(expr_ty) * new_size); - if (!tmp) { - PyMem_RawFree(l->p); - l->p = NULL; - return -1; - } - l->p = tmp; - } - - l->allocated = new_size; - assert(l->allocated == 2 * l->size); - } - - l->p[l->size++] = exp; - - ExprList_check_invariants(l); - return 0; -} - -static void -ExprList_Dealloc(ExprList *l) -{ - ExprList_check_invariants(l); - - /* If there's been an error, or we've never dynamically allocated, - do nothing. */ - if (!l->p || l->p == l->data) { - /* Do nothing. */ - } else { - /* We have dynamically allocated. Free the memory. */ - PyMem_RawFree(l->p); - } - l->p = NULL; - l->size = -1; -} - -static asdl_seq * -ExprList_Finish(ExprList *l, PyArena *arena) -{ - asdl_seq *seq; - - ExprList_check_invariants(l); - - /* Allocate the asdl_seq and copy the expressions in to it. */ - seq = _Ta3_asdl_seq_new(l->size, arena); - if (seq) { - Py_ssize_t i; - for (i = 0; i < l->size; i++) - asdl_seq_SET(seq, i, l->p[i]); - } - ExprList_Dealloc(l); - return seq; -} - -/* The FstringParser is designed to add a mix of strings and - f-strings, and concat them together as needed. Ultimately, it - generates an expr_ty. */ -typedef struct { - PyObject *last_str; - ExprList expr_list; - int fmode; -} FstringParser; - -#ifdef NDEBUG -#define FstringParser_check_invariants(state) -#else -static void -FstringParser_check_invariants(FstringParser *state) -{ - if (state->last_str) - assert(PyUnicode_CheckExact(state->last_str)); - ExprList_check_invariants(&state->expr_list); -} -#endif - -static void -FstringParser_Init(FstringParser *state) -{ - state->last_str = NULL; - state->fmode = 0; - ExprList_Init(&state->expr_list); - FstringParser_check_invariants(state); -} - -static void -FstringParser_Dealloc(FstringParser *state) -{ - FstringParser_check_invariants(state); - - Py_XDECREF(state->last_str); - ExprList_Dealloc(&state->expr_list); -} - -static PyObject * -make_str_kind(const char *raw) { - /* currently Python allows up to 2 string modifiers */ - char *ch, s_kind[3] = {0, 0, 0}; - ch = s_kind; - while (*raw && *raw != '\'' && *raw != '"') { - *ch++ = *raw++; - } - return PyUnicode_FromString(s_kind); -} - - -/* Make a Str node, but decref the PyUnicode object being added. */ -static expr_ty -make_str_node_and_del(PyObject **str, struct compiling *c, const node* n) -{ - PyObject *s = *str; - PyObject *kind = make_str_kind(STR(CHILD(n, 0))); - if (!kind) { - return NULL; - } - *str = NULL; - assert(PyUnicode_CheckExact(s)); - if (PyArena_AddPyObject(c->c_arena, s) < 0) { - Py_DECREF(s); - return NULL; - } - return Str(s, kind, LINENO(n), n->n_col_offset, c->c_arena); -} - -/* Add a non-f-string (that is, a regular literal string). str is - decref'd. */ -static int -FstringParser_ConcatAndDel(FstringParser *state, PyObject *str) -{ - FstringParser_check_invariants(state); - - assert(PyUnicode_CheckExact(str)); - - if (PyUnicode_GET_LENGTH(str) == 0) { - Py_DECREF(str); - return 0; - } - - if (!state->last_str) { - /* We didn't have a string before, so just remember this one. */ - state->last_str = str; - } else { - /* Concatenate this with the previous string. */ - PyUnicode_AppendAndDel(&state->last_str, str); - if (!state->last_str) - return -1; - } - FstringParser_check_invariants(state); - return 0; -} - -/* Parse an f-string. The f-string is in *str to end, with no - 'f' or quotes. */ -static int -FstringParser_ConcatFstring(FstringParser *state, const char **str, - const char *end, int raw, int recurse_lvl, - struct compiling *c, const node *n) -{ - FstringParser_check_invariants(state); - state->fmode = 1; - - /* Parse the f-string. */ - while (1) { - PyObject *literal = NULL; - expr_ty expression = NULL; - - /* If there's a zero length literal in front of the - expression, literal will be NULL. If we're at the end of - the f-string, expression will be NULL (unless result == 1, - see below). */ - int result = fstring_find_literal_and_expr(str, end, raw, recurse_lvl, - &literal, &expression, - c, n); - if (result < 0) - return -1; - - /* Add the literal, if any. */ - if (!literal) { - /* Do nothing. Just leave last_str alone (and possibly - NULL). */ - } else if (!state->last_str) { - /* Note that the literal can be zero length, if the - input string is "\\\n" or "\\\r", among others. */ - state->last_str = literal; - literal = NULL; - } else { - /* We have a literal, concatenate it. */ - assert(PyUnicode_GET_LENGTH(literal) != 0); - if (FstringParser_ConcatAndDel(state, literal) < 0) - return -1; - literal = NULL; - } - - /* We've dealt with the literal now. It can't be leaked on further - errors. */ - assert(literal == NULL); - - /* See if we should just loop around to get the next literal - and expression, while ignoring the expression this - time. This is used for un-doubling braces, as an - optimization. */ - if (result == 1) - continue; - - if (!expression) - /* We're done with this f-string. */ - break; - - /* We know we have an expression. Convert any existing string - to a Str node. */ - if (!state->last_str) { - /* Do nothing. No previous literal. */ - } else { - /* Convert the existing last_str literal to a Str node. */ - expr_ty str = make_str_node_and_del(&state->last_str, c, n); - if (!str || ExprList_Append(&state->expr_list, str) < 0) - return -1; - } - - if (ExprList_Append(&state->expr_list, expression) < 0) - return -1; - } - - /* If recurse_lvl is zero, then we must be at the end of the - string. Otherwise, we must be at a right brace. */ - - if (recurse_lvl == 0 && *str < end-1) { - ast_error(c, n, "f-string: unexpected end of string"); - return -1; - } - if (recurse_lvl != 0 && **str != '}') { - ast_error(c, n, "f-string: expecting '}'"); - return -1; - } - - FstringParser_check_invariants(state); - return 0; -} - -/* Convert the partial state reflected in last_str and expr_list to an - expr_ty. The expr_ty can be a Str, or a JoinedStr. */ -static expr_ty -FstringParser_Finish(FstringParser *state, struct compiling *c, - const node *n) -{ - asdl_seq *seq; - - FstringParser_check_invariants(state); - - /* If we're just a constant string with no expressions, return - that. */ - if (!state->fmode) { - assert(!state->expr_list.size); - if (!state->last_str) { - /* Create a zero length string. */ - state->last_str = PyUnicode_FromStringAndSize(NULL, 0); - if (!state->last_str) - goto error; - } - return make_str_node_and_del(&state->last_str, c, n); - } - - /* Create a Str node out of last_str, if needed. It will be the - last node in our expression list. */ - if (state->last_str) { - expr_ty str = make_str_node_and_del(&state->last_str, c, n); - if (!str || ExprList_Append(&state->expr_list, str) < 0) - goto error; - } - /* This has already been freed. */ - assert(state->last_str == NULL); - - seq = ExprList_Finish(&state->expr_list, c->c_arena); - if (!seq) - goto error; - - return JoinedStr(seq, LINENO(n), n->n_col_offset, c->c_arena); - -error: - FstringParser_Dealloc(state); - return NULL; -} - -/* Given an f-string (with no 'f' or quotes) that's in *str and ends - at end, parse it into an expr_ty. Return NULL on error. Adjust - str to point past the parsed portion. */ -static expr_ty -fstring_parse(const char **str, const char *end, int raw, int recurse_lvl, - struct compiling *c, const node *n) -{ - FstringParser state; - - FstringParser_Init(&state); - if (FstringParser_ConcatFstring(&state, str, end, raw, recurse_lvl, - c, n) < 0) { - FstringParser_Dealloc(&state); - return NULL; - } - - return FstringParser_Finish(&state, c, n); -} - -/* n is a Python string literal, including the bracketing quote - characters, and r, b, u, &/or f prefixes (if any), and embedded - escape sequences (if any). parsestr parses it, and sets *result to - decoded Python string object. If the string is an f-string, set - *fstr and *fstrlen to the unparsed string object. Return 0 if no - errors occurred. -*/ -static int -parsestr(struct compiling *c, const node *n, int *bytesmode, int *rawmode, - PyObject **result, const char **fstr, Py_ssize_t *fstrlen) -{ - size_t len; - const char *s = STR(n); - int quote = Py_CHARMASK(*s); - int fmode = 0; - *bytesmode = 0; - *rawmode = 0; - *result = NULL; - *fstr = NULL; - if (Py_ISALPHA(quote)) { - while (!*bytesmode || !*rawmode) { - if (quote == 'b' || quote == 'B') { - quote = *++s; - *bytesmode = 1; - } - else if (quote == 'u' || quote == 'U') { - quote = *++s; - } - else if (quote == 'r' || quote == 'R') { - quote = *++s; - *rawmode = 1; - } - else if (quote == 'f' || quote == 'F') { - quote = *++s; - fmode = 1; - } - else { - break; - } - } - } - /* fstrings are only allowed in Python 3.6 and greater */ - if (fmode && c->c_feature_version < 6) { - ast_error(c, n, "Format strings are only supported in Python 3.6 and greater"); - return -1; - } - if (fmode && *bytesmode) { - PyErr_BadInternalCall(); - return -1; - } - if (quote != '\'' && quote != '\"') { - PyErr_BadInternalCall(); - return -1; - } - /* Skip the leading quote char. */ - s++; - len = strlen(s); - if (len > INT_MAX) { - PyErr_SetString(PyExc_OverflowError, - "string to parse is too long"); - return -1; - } - if (s[--len] != quote) { - /* Last quote char must match the first. */ - PyErr_BadInternalCall(); - return -1; - } - if (len >= 4 && s[0] == quote && s[1] == quote) { - /* A triple quoted string. We've already skipped one quote at - the start and one at the end of the string. Now skip the - two at the start. */ - s += 2; - len -= 2; - /* And check that the last two match. */ - if (s[--len] != quote || s[--len] != quote) { - PyErr_BadInternalCall(); - return -1; - } - } - - if (fmode) { - /* Just return the bytes. The caller will parse the resulting - string. */ - *fstr = s; - *fstrlen = len; - return 0; - } - - /* Not an f-string. */ - /* Avoid invoking escape decoding routines if possible. */ - *rawmode = *rawmode || strchr(s, '\\') == NULL; - if (*bytesmode) { - /* Disallow non-ASCII characters. */ - const char *ch; - for (ch = s; *ch; ch++) { - if (Py_CHARMASK(*ch) >= 0x80) { - ast_error(c, n, "bytes can only contain ASCII " - "literal characters."); - return -1; - } - } - if (*rawmode) - *result = PyBytes_FromStringAndSize(s, len); - else - *result = decode_bytes_with_escapes(c, n, s, len); - } else { - if (*rawmode) - *result = PyUnicode_DecodeUTF8Stateful(s, len, NULL, NULL); - else - *result = decode_unicode_with_escapes(c, n, s, len); - } - return *result == NULL ? -1 : 0; -} - -/* Accepts a STRING+ atom, and produces an expr_ty node. Run through - each STRING atom, and process it as needed. For bytes, just - concatenate them together, and the result will be a Bytes node. For - normal strings and f-strings, concatenate them together. The result - will be a Str node if there were no f-strings; a FormattedValue - node if there's just an f-string (with no leading or trailing - literals), or a JoinedStr node if there are multiple f-strings or - any literals involved. */ -static expr_ty -parsestrplus(struct compiling *c, const node *n) -{ - int bytesmode = 0; - PyObject *bytes_str = NULL; - int i; - - FstringParser state; - FstringParser_Init(&state); - - for (i = 0; i < NCH(n); i++) { - int this_bytesmode; - int this_rawmode; - PyObject *s; - const char *fstr; - Py_ssize_t fstrlen = -1; /* Silence a compiler warning. */ - - REQ(CHILD(n, i), STRING); - if (parsestr(c, CHILD(n, i), &this_bytesmode, &this_rawmode, &s, - &fstr, &fstrlen) != 0) - goto error; - - /* Check that we're not mixing bytes with unicode. */ - if (i != 0 && bytesmode != this_bytesmode) { - ast_error(c, n, "cannot mix bytes and nonbytes literals"); - /* s is NULL if the current string part is an f-string. */ - Py_XDECREF(s); - goto error; - } - bytesmode = this_bytesmode; - - if (fstr != NULL) { - int result; - assert(s == NULL && !bytesmode); - /* This is an f-string. Parse and concatenate it. */ - result = FstringParser_ConcatFstring(&state, &fstr, fstr+fstrlen, - this_rawmode, 0, c, n); - if (result < 0) - goto error; - } else { - /* A string or byte string. */ - assert(s != NULL && fstr == NULL); - - assert(bytesmode ? PyBytes_CheckExact(s) : - PyUnicode_CheckExact(s)); - - if (bytesmode) { - /* For bytes, concat as we go. */ - if (i == 0) { - /* First time, just remember this value. */ - bytes_str = s; - } else { - PyBytes_ConcatAndDel(&bytes_str, s); - if (!bytes_str) - goto error; - } - } else { - /* This is a regular string. Concatenate it. */ - if (FstringParser_ConcatAndDel(&state, s) < 0) - goto error; - } - } - } - if (bytesmode) { - PyObject *kind = make_str_kind(STR(CHILD(n, 0))); - - /* Just return the bytes object and we're done. */ - if (PyArena_AddPyObject(c->c_arena, bytes_str) < 0) { - Py_DECREF(kind); - goto error; - } - return Bytes(bytes_str, kind, LINENO(n), n->n_col_offset, c->c_arena); - } - - /* We're not a bytes string, bytes_str should never have been set. */ - assert(bytes_str == NULL); - - return FstringParser_Finish(&state, c, n); - -error: - Py_XDECREF(bytes_str); - FstringParser_Dealloc(&state); - return NULL; -} diff --git a/ast3/Python/graminit.c b/ast3/Python/graminit.c deleted file mode 100644 index e6778122..00000000 --- a/ast3/Python/graminit.c +++ /dev/null @@ -1,2451 +0,0 @@ -/* Generated by Parser/pgen */ - -#include "../Include/pgenheaders.h" -#include "../Include/grammar.h" -extern grammar _Ta3Parser_Grammar; -static arc arcs_0_0[3] = { - {2, 1}, - {3, 1}, - {4, 2}, -}; -static arc arcs_0_1[1] = { - {0, 1}, -}; -static arc arcs_0_2[1] = { - {2, 1}, -}; -static state states_0[3] = { - {3, arcs_0_0}, - {1, arcs_0_1}, - {1, arcs_0_2}, -}; -static arc arcs_1_0[3] = { - {2, 0}, - {6, 0}, - {7, 1}, -}; -static arc arcs_1_1[1] = { - {0, 1}, -}; -static state states_1[2] = { - {3, arcs_1_0}, - {1, arcs_1_1}, -}; -static arc arcs_2_0[1] = { - {9, 1}, -}; -static arc arcs_2_1[2] = { - {2, 1}, - {7, 2}, -}; -static arc arcs_2_2[1] = { - {0, 2}, -}; -static state states_2[3] = { - {1, arcs_2_0}, - {2, arcs_2_1}, - {1, arcs_2_2}, -}; -static arc arcs_3_0[1] = { - {11, 1}, -}; -static arc arcs_3_1[1] = { - {12, 2}, -}; -static arc arcs_3_2[2] = { - {13, 3}, - {2, 4}, -}; -static arc arcs_3_3[2] = { - {14, 5}, - {15, 6}, -}; -static arc arcs_3_4[1] = { - {0, 4}, -}; -static arc arcs_3_5[1] = { - {15, 6}, -}; -static arc arcs_3_6[1] = { - {2, 4}, -}; -static state states_3[7] = { - {1, arcs_3_0}, - {1, arcs_3_1}, - {2, arcs_3_2}, - {2, arcs_3_3}, - {1, arcs_3_4}, - {1, arcs_3_5}, - {1, arcs_3_6}, -}; -static arc arcs_4_0[1] = { - {10, 1}, -}; -static arc arcs_4_1[2] = { - {10, 1}, - {0, 1}, -}; -static state states_4[2] = { - {1, arcs_4_0}, - {2, arcs_4_1}, -}; -static arc arcs_5_0[1] = { - {16, 1}, -}; -static arc arcs_5_1[3] = { - {18, 2}, - {19, 2}, - {20, 2}, -}; -static arc arcs_5_2[1] = { - {0, 2}, -}; -static state states_5[3] = { - {1, arcs_5_0}, - {3, arcs_5_1}, - {1, arcs_5_2}, -}; -static arc arcs_6_0[1] = { - {21, 1}, -}; -static arc arcs_6_1[1] = { - {19, 2}, -}; -static arc arcs_6_2[1] = { - {0, 2}, -}; -static state states_6[3] = { - {1, arcs_6_0}, - {1, arcs_6_1}, - {1, arcs_6_2}, -}; -static arc arcs_7_0[1] = { - {22, 1}, -}; -static arc arcs_7_1[1] = { - {23, 2}, -}; -static arc arcs_7_2[1] = { - {24, 3}, -}; -static arc arcs_7_3[2] = { - {25, 4}, - {27, 5}, -}; -static arc arcs_7_4[1] = { - {26, 6}, -}; -static arc arcs_7_5[2] = { - {28, 7}, - {29, 8}, -}; -static arc arcs_7_6[1] = { - {27, 5}, -}; -static arc arcs_7_7[1] = { - {29, 8}, -}; -static arc arcs_7_8[1] = { - {0, 8}, -}; -static state states_7[9] = { - {1, arcs_7_0}, - {1, arcs_7_1}, - {1, arcs_7_2}, - {2, arcs_7_3}, - {1, arcs_7_4}, - {2, arcs_7_5}, - {1, arcs_7_6}, - {1, arcs_7_7}, - {1, arcs_7_8}, -}; -static arc arcs_8_0[1] = { - {13, 1}, -}; -static arc arcs_8_1[2] = { - {30, 2}, - {15, 3}, -}; -static arc arcs_8_2[1] = { - {15, 3}, -}; -static arc arcs_8_3[1] = { - {0, 3}, -}; -static state states_8[4] = { - {1, arcs_8_0}, - {2, arcs_8_1}, - {1, arcs_8_2}, - {1, arcs_8_3}, -}; -static arc arcs_9_0[3] = { - {31, 1}, - {34, 2}, - {35, 3}, -}; -static arc arcs_9_1[4] = { - {32, 4}, - {33, 5}, - {28, 6}, - {0, 1}, -}; -static arc arcs_9_2[4] = { - {31, 7}, - {33, 8}, - {28, 6}, - {0, 2}, -}; -static arc arcs_9_3[1] = { - {31, 9}, -}; -static arc arcs_9_4[1] = { - {26, 10}, -}; -static arc arcs_9_5[5] = { - {28, 11}, - {31, 12}, - {34, 13}, - {35, 3}, - {0, 5}, -}; -static arc arcs_9_6[1] = { - {0, 6}, -}; -static arc arcs_9_7[3] = { - {33, 8}, - {28, 6}, - {0, 7}, -}; -static arc arcs_9_8[4] = { - {28, 14}, - {31, 15}, - {35, 3}, - {0, 8}, -}; -static arc arcs_9_9[3] = { - {33, 16}, - {28, 6}, - {0, 9}, -}; -static arc arcs_9_10[3] = { - {33, 5}, - {28, 6}, - {0, 10}, -}; -static arc arcs_9_11[4] = { - {31, 12}, - {34, 13}, - {35, 3}, - {0, 11}, -}; -static arc arcs_9_12[4] = { - {33, 5}, - {32, 4}, - {28, 6}, - {0, 12}, -}; -static arc arcs_9_13[4] = { - {31, 17}, - {33, 18}, - {28, 6}, - {0, 13}, -}; -static arc arcs_9_14[3] = { - {31, 15}, - {35, 3}, - {0, 14}, -}; -static arc arcs_9_15[4] = { - {33, 8}, - {32, 19}, - {28, 6}, - {0, 15}, -}; -static arc arcs_9_16[2] = { - {28, 6}, - {0, 16}, -}; -static arc arcs_9_17[3] = { - {33, 18}, - {28, 6}, - {0, 17}, -}; -static arc arcs_9_18[4] = { - {28, 20}, - {31, 21}, - {35, 3}, - {0, 18}, -}; -static arc arcs_9_19[1] = { - {26, 7}, -}; -static arc arcs_9_20[3] = { - {31, 21}, - {35, 3}, - {0, 20}, -}; -static arc arcs_9_21[4] = { - {33, 18}, - {32, 22}, - {28, 6}, - {0, 21}, -}; -static arc arcs_9_22[1] = { - {26, 17}, -}; -static state states_9[23] = { - {3, arcs_9_0}, - {4, arcs_9_1}, - {4, arcs_9_2}, - {1, arcs_9_3}, - {1, arcs_9_4}, - {5, arcs_9_5}, - {1, arcs_9_6}, - {3, arcs_9_7}, - {4, arcs_9_8}, - {3, arcs_9_9}, - {3, arcs_9_10}, - {4, arcs_9_11}, - {4, arcs_9_12}, - {4, arcs_9_13}, - {3, arcs_9_14}, - {4, arcs_9_15}, - {2, arcs_9_16}, - {3, arcs_9_17}, - {4, arcs_9_18}, - {1, arcs_9_19}, - {3, arcs_9_20}, - {4, arcs_9_21}, - {1, arcs_9_22}, -}; -static arc arcs_10_0[1] = { - {23, 1}, -}; -static arc arcs_10_1[2] = { - {27, 2}, - {0, 1}, -}; -static arc arcs_10_2[1] = { - {26, 3}, -}; -static arc arcs_10_3[1] = { - {0, 3}, -}; -static state states_10[4] = { - {1, arcs_10_0}, - {2, arcs_10_1}, - {1, arcs_10_2}, - {1, arcs_10_3}, -}; -static arc arcs_11_0[3] = { - {37, 1}, - {34, 2}, - {35, 3}, -}; -static arc arcs_11_1[3] = { - {32, 4}, - {33, 5}, - {0, 1}, -}; -static arc arcs_11_2[3] = { - {37, 6}, - {33, 7}, - {0, 2}, -}; -static arc arcs_11_3[1] = { - {37, 8}, -}; -static arc arcs_11_4[1] = { - {26, 9}, -}; -static arc arcs_11_5[4] = { - {37, 10}, - {34, 11}, - {35, 3}, - {0, 5}, -}; -static arc arcs_11_6[2] = { - {33, 7}, - {0, 6}, -}; -static arc arcs_11_7[3] = { - {37, 12}, - {35, 3}, - {0, 7}, -}; -static arc arcs_11_8[2] = { - {33, 13}, - {0, 8}, -}; -static arc arcs_11_9[2] = { - {33, 5}, - {0, 9}, -}; -static arc arcs_11_10[3] = { - {33, 5}, - {32, 4}, - {0, 10}, -}; -static arc arcs_11_11[3] = { - {37, 14}, - {33, 15}, - {0, 11}, -}; -static arc arcs_11_12[3] = { - {33, 7}, - {32, 16}, - {0, 12}, -}; -static arc arcs_11_13[1] = { - {0, 13}, -}; -static arc arcs_11_14[2] = { - {33, 15}, - {0, 14}, -}; -static arc arcs_11_15[3] = { - {37, 17}, - {35, 3}, - {0, 15}, -}; -static arc arcs_11_16[1] = { - {26, 6}, -}; -static arc arcs_11_17[3] = { - {33, 15}, - {32, 18}, - {0, 17}, -}; -static arc arcs_11_18[1] = { - {26, 14}, -}; -static state states_11[19] = { - {3, arcs_11_0}, - {3, arcs_11_1}, - {3, arcs_11_2}, - {1, arcs_11_3}, - {1, arcs_11_4}, - {4, arcs_11_5}, - {2, arcs_11_6}, - {3, arcs_11_7}, - {2, arcs_11_8}, - {2, arcs_11_9}, - {3, arcs_11_10}, - {3, arcs_11_11}, - {3, arcs_11_12}, - {1, arcs_11_13}, - {2, arcs_11_14}, - {3, arcs_11_15}, - {1, arcs_11_16}, - {3, arcs_11_17}, - {1, arcs_11_18}, -}; -static arc arcs_12_0[1] = { - {23, 1}, -}; -static arc arcs_12_1[1] = { - {0, 1}, -}; -static state states_12[2] = { - {1, arcs_12_0}, - {1, arcs_12_1}, -}; -static arc arcs_13_0[2] = { - {3, 1}, - {4, 1}, -}; -static arc arcs_13_1[1] = { - {0, 1}, -}; -static state states_13[2] = { - {2, arcs_13_0}, - {1, arcs_13_1}, -}; -static arc arcs_14_0[1] = { - {38, 1}, -}; -static arc arcs_14_1[2] = { - {39, 2}, - {2, 3}, -}; -static arc arcs_14_2[2] = { - {38, 1}, - {2, 3}, -}; -static arc arcs_14_3[1] = { - {0, 3}, -}; -static state states_14[4] = { - {1, arcs_14_0}, - {2, arcs_14_1}, - {2, arcs_14_2}, - {1, arcs_14_3}, -}; -static arc arcs_15_0[8] = { - {40, 1}, - {41, 1}, - {42, 1}, - {43, 1}, - {44, 1}, - {45, 1}, - {46, 1}, - {47, 1}, -}; -static arc arcs_15_1[1] = { - {0, 1}, -}; -static state states_15[2] = { - {8, arcs_15_0}, - {1, arcs_15_1}, -}; -static arc arcs_16_0[1] = { - {48, 1}, -}; -static arc arcs_16_1[5] = { - {49, 2}, - {50, 3}, - {32, 4}, - {28, 2}, - {0, 1}, -}; -static arc arcs_16_2[1] = { - {0, 2}, -}; -static arc arcs_16_3[2] = { - {51, 2}, - {9, 2}, -}; -static arc arcs_16_4[2] = { - {51, 5}, - {48, 5}, -}; -static arc arcs_16_5[3] = { - {32, 4}, - {28, 2}, - {0, 5}, -}; -static state states_16[6] = { - {1, arcs_16_0}, - {5, arcs_16_1}, - {1, arcs_16_2}, - {2, arcs_16_3}, - {2, arcs_16_4}, - {3, arcs_16_5}, -}; -static arc arcs_17_0[1] = { - {27, 1}, -}; -static arc arcs_17_1[1] = { - {26, 2}, -}; -static arc arcs_17_2[2] = { - {32, 3}, - {0, 2}, -}; -static arc arcs_17_3[1] = { - {26, 4}, -}; -static arc arcs_17_4[1] = { - {0, 4}, -}; -static state states_17[5] = { - {1, arcs_17_0}, - {1, arcs_17_1}, - {2, arcs_17_2}, - {1, arcs_17_3}, - {1, arcs_17_4}, -}; -static arc arcs_18_0[2] = { - {26, 1}, - {52, 1}, -}; -static arc arcs_18_1[2] = { - {33, 2}, - {0, 1}, -}; -static arc arcs_18_2[3] = { - {26, 1}, - {52, 1}, - {0, 2}, -}; -static state states_18[3] = { - {2, arcs_18_0}, - {2, arcs_18_1}, - {3, arcs_18_2}, -}; -static arc arcs_19_0[13] = { - {53, 1}, - {54, 1}, - {55, 1}, - {56, 1}, - {57, 1}, - {58, 1}, - {59, 1}, - {60, 1}, - {61, 1}, - {62, 1}, - {63, 1}, - {64, 1}, - {65, 1}, -}; -static arc arcs_19_1[1] = { - {0, 1}, -}; -static state states_19[2] = { - {13, arcs_19_0}, - {1, arcs_19_1}, -}; -static arc arcs_20_0[1] = { - {66, 1}, -}; -static arc arcs_20_1[1] = { - {67, 2}, -}; -static arc arcs_20_2[1] = { - {0, 2}, -}; -static state states_20[3] = { - {1, arcs_20_0}, - {1, arcs_20_1}, - {1, arcs_20_2}, -}; -static arc arcs_21_0[1] = { - {68, 1}, -}; -static arc arcs_21_1[1] = { - {0, 1}, -}; -static state states_21[2] = { - {1, arcs_21_0}, - {1, arcs_21_1}, -}; -static arc arcs_22_0[5] = { - {69, 1}, - {70, 1}, - {71, 1}, - {72, 1}, - {73, 1}, -}; -static arc arcs_22_1[1] = { - {0, 1}, -}; -static state states_22[2] = { - {5, arcs_22_0}, - {1, arcs_22_1}, -}; -static arc arcs_23_0[1] = { - {74, 1}, -}; -static arc arcs_23_1[1] = { - {0, 1}, -}; -static state states_23[2] = { - {1, arcs_23_0}, - {1, arcs_23_1}, -}; -static arc arcs_24_0[1] = { - {75, 1}, -}; -static arc arcs_24_1[1] = { - {0, 1}, -}; -static state states_24[2] = { - {1, arcs_24_0}, - {1, arcs_24_1}, -}; -static arc arcs_25_0[1] = { - {76, 1}, -}; -static arc arcs_25_1[2] = { - {9, 2}, - {0, 1}, -}; -static arc arcs_25_2[1] = { - {0, 2}, -}; -static state states_25[3] = { - {1, arcs_25_0}, - {2, arcs_25_1}, - {1, arcs_25_2}, -}; -static arc arcs_26_0[1] = { - {51, 1}, -}; -static arc arcs_26_1[1] = { - {0, 1}, -}; -static state states_26[2] = { - {1, arcs_26_0}, - {1, arcs_26_1}, -}; -static arc arcs_27_0[1] = { - {77, 1}, -}; -static arc arcs_27_1[2] = { - {26, 2}, - {0, 1}, -}; -static arc arcs_27_2[2] = { - {78, 3}, - {0, 2}, -}; -static arc arcs_27_3[1] = { - {26, 4}, -}; -static arc arcs_27_4[1] = { - {0, 4}, -}; -static state states_27[5] = { - {1, arcs_27_0}, - {2, arcs_27_1}, - {2, arcs_27_2}, - {1, arcs_27_3}, - {1, arcs_27_4}, -}; -static arc arcs_28_0[2] = { - {79, 1}, - {80, 1}, -}; -static arc arcs_28_1[1] = { - {0, 1}, -}; -static state states_28[2] = { - {2, arcs_28_0}, - {1, arcs_28_1}, -}; -static arc arcs_29_0[1] = { - {81, 1}, -}; -static arc arcs_29_1[1] = { - {82, 2}, -}; -static arc arcs_29_2[1] = { - {0, 2}, -}; -static state states_29[3] = { - {1, arcs_29_0}, - {1, arcs_29_1}, - {1, arcs_29_2}, -}; -static arc arcs_30_0[1] = { - {78, 1}, -}; -static arc arcs_30_1[3] = { - {83, 2}, - {84, 2}, - {12, 3}, -}; -static arc arcs_30_2[4] = { - {83, 2}, - {84, 2}, - {12, 3}, - {81, 4}, -}; -static arc arcs_30_3[1] = { - {81, 4}, -}; -static arc arcs_30_4[3] = { - {34, 5}, - {13, 6}, - {85, 5}, -}; -static arc arcs_30_5[1] = { - {0, 5}, -}; -static arc arcs_30_6[1] = { - {85, 7}, -}; -static arc arcs_30_7[1] = { - {15, 5}, -}; -static state states_30[8] = { - {1, arcs_30_0}, - {3, arcs_30_1}, - {4, arcs_30_2}, - {1, arcs_30_3}, - {3, arcs_30_4}, - {1, arcs_30_5}, - {1, arcs_30_6}, - {1, arcs_30_7}, -}; -static arc arcs_31_0[1] = { - {23, 1}, -}; -static arc arcs_31_1[2] = { - {87, 2}, - {0, 1}, -}; -static arc arcs_31_2[1] = { - {23, 3}, -}; -static arc arcs_31_3[1] = { - {0, 3}, -}; -static state states_31[4] = { - {1, arcs_31_0}, - {2, arcs_31_1}, - {1, arcs_31_2}, - {1, arcs_31_3}, -}; -static arc arcs_32_0[1] = { - {12, 1}, -}; -static arc arcs_32_1[2] = { - {87, 2}, - {0, 1}, -}; -static arc arcs_32_2[1] = { - {23, 3}, -}; -static arc arcs_32_3[1] = { - {0, 3}, -}; -static state states_32[4] = { - {1, arcs_32_0}, - {2, arcs_32_1}, - {1, arcs_32_2}, - {1, arcs_32_3}, -}; -static arc arcs_33_0[1] = { - {86, 1}, -}; -static arc arcs_33_1[2] = { - {33, 2}, - {0, 1}, -}; -static arc arcs_33_2[2] = { - {86, 1}, - {0, 2}, -}; -static state states_33[3] = { - {1, arcs_33_0}, - {2, arcs_33_1}, - {2, arcs_33_2}, -}; -static arc arcs_34_0[1] = { - {88, 1}, -}; -static arc arcs_34_1[2] = { - {33, 0}, - {0, 1}, -}; -static state states_34[2] = { - {1, arcs_34_0}, - {2, arcs_34_1}, -}; -static arc arcs_35_0[1] = { - {23, 1}, -}; -static arc arcs_35_1[2] = { - {83, 0}, - {0, 1}, -}; -static state states_35[2] = { - {1, arcs_35_0}, - {2, arcs_35_1}, -}; -static arc arcs_36_0[1] = { - {89, 1}, -}; -static arc arcs_36_1[1] = { - {23, 2}, -}; -static arc arcs_36_2[2] = { - {33, 1}, - {0, 2}, -}; -static state states_36[3] = { - {1, arcs_36_0}, - {1, arcs_36_1}, - {2, arcs_36_2}, -}; -static arc arcs_37_0[1] = { - {90, 1}, -}; -static arc arcs_37_1[1] = { - {23, 2}, -}; -static arc arcs_37_2[2] = { - {33, 1}, - {0, 2}, -}; -static state states_37[3] = { - {1, arcs_37_0}, - {1, arcs_37_1}, - {2, arcs_37_2}, -}; -static arc arcs_38_0[1] = { - {91, 1}, -}; -static arc arcs_38_1[1] = { - {26, 2}, -}; -static arc arcs_38_2[2] = { - {33, 3}, - {0, 2}, -}; -static arc arcs_38_3[1] = { - {26, 4}, -}; -static arc arcs_38_4[1] = { - {0, 4}, -}; -static state states_38[5] = { - {1, arcs_38_0}, - {1, arcs_38_1}, - {2, arcs_38_2}, - {1, arcs_38_3}, - {1, arcs_38_4}, -}; -static arc arcs_39_0[9] = { - {92, 1}, - {93, 1}, - {94, 1}, - {95, 1}, - {96, 1}, - {19, 1}, - {18, 1}, - {17, 1}, - {97, 1}, -}; -static arc arcs_39_1[1] = { - {0, 1}, -}; -static state states_39[2] = { - {9, arcs_39_0}, - {1, arcs_39_1}, -}; -static arc arcs_40_0[1] = { - {21, 1}, -}; -static arc arcs_40_1[3] = { - {19, 2}, - {96, 2}, - {94, 2}, -}; -static arc arcs_40_2[1] = { - {0, 2}, -}; -static state states_40[3] = { - {1, arcs_40_0}, - {3, arcs_40_1}, - {1, arcs_40_2}, -}; -static arc arcs_41_0[1] = { - {98, 1}, -}; -static arc arcs_41_1[1] = { - {26, 2}, -}; -static arc arcs_41_2[1] = { - {27, 3}, -}; -static arc arcs_41_3[1] = { - {29, 4}, -}; -static arc arcs_41_4[3] = { - {99, 1}, - {100, 5}, - {0, 4}, -}; -static arc arcs_41_5[1] = { - {27, 6}, -}; -static arc arcs_41_6[1] = { - {29, 7}, -}; -static arc arcs_41_7[1] = { - {0, 7}, -}; -static state states_41[8] = { - {1, arcs_41_0}, - {1, arcs_41_1}, - {1, arcs_41_2}, - {1, arcs_41_3}, - {3, arcs_41_4}, - {1, arcs_41_5}, - {1, arcs_41_6}, - {1, arcs_41_7}, -}; -static arc arcs_42_0[1] = { - {101, 1}, -}; -static arc arcs_42_1[1] = { - {26, 2}, -}; -static arc arcs_42_2[1] = { - {27, 3}, -}; -static arc arcs_42_3[1] = { - {29, 4}, -}; -static arc arcs_42_4[2] = { - {100, 5}, - {0, 4}, -}; -static arc arcs_42_5[1] = { - {27, 6}, -}; -static arc arcs_42_6[1] = { - {29, 7}, -}; -static arc arcs_42_7[1] = { - {0, 7}, -}; -static state states_42[8] = { - {1, arcs_42_0}, - {1, arcs_42_1}, - {1, arcs_42_2}, - {1, arcs_42_3}, - {2, arcs_42_4}, - {1, arcs_42_5}, - {1, arcs_42_6}, - {1, arcs_42_7}, -}; -static arc arcs_43_0[1] = { - {102, 1}, -}; -static arc arcs_43_1[1] = { - {67, 2}, -}; -static arc arcs_43_2[1] = { - {103, 3}, -}; -static arc arcs_43_3[1] = { - {9, 4}, -}; -static arc arcs_43_4[1] = { - {27, 5}, -}; -static arc arcs_43_5[2] = { - {28, 6}, - {29, 7}, -}; -static arc arcs_43_6[1] = { - {29, 7}, -}; -static arc arcs_43_7[2] = { - {100, 8}, - {0, 7}, -}; -static arc arcs_43_8[1] = { - {27, 9}, -}; -static arc arcs_43_9[1] = { - {29, 10}, -}; -static arc arcs_43_10[1] = { - {0, 10}, -}; -static state states_43[11] = { - {1, arcs_43_0}, - {1, arcs_43_1}, - {1, arcs_43_2}, - {1, arcs_43_3}, - {1, arcs_43_4}, - {2, arcs_43_5}, - {1, arcs_43_6}, - {2, arcs_43_7}, - {1, arcs_43_8}, - {1, arcs_43_9}, - {1, arcs_43_10}, -}; -static arc arcs_44_0[1] = { - {104, 1}, -}; -static arc arcs_44_1[1] = { - {27, 2}, -}; -static arc arcs_44_2[1] = { - {29, 3}, -}; -static arc arcs_44_3[2] = { - {105, 4}, - {106, 5}, -}; -static arc arcs_44_4[1] = { - {27, 6}, -}; -static arc arcs_44_5[1] = { - {27, 7}, -}; -static arc arcs_44_6[1] = { - {29, 8}, -}; -static arc arcs_44_7[1] = { - {29, 9}, -}; -static arc arcs_44_8[4] = { - {105, 4}, - {100, 10}, - {106, 5}, - {0, 8}, -}; -static arc arcs_44_9[1] = { - {0, 9}, -}; -static arc arcs_44_10[1] = { - {27, 11}, -}; -static arc arcs_44_11[1] = { - {29, 12}, -}; -static arc arcs_44_12[2] = { - {106, 5}, - {0, 12}, -}; -static state states_44[13] = { - {1, arcs_44_0}, - {1, arcs_44_1}, - {1, arcs_44_2}, - {2, arcs_44_3}, - {1, arcs_44_4}, - {1, arcs_44_5}, - {1, arcs_44_6}, - {1, arcs_44_7}, - {4, arcs_44_8}, - {1, arcs_44_9}, - {1, arcs_44_10}, - {1, arcs_44_11}, - {2, arcs_44_12}, -}; -static arc arcs_45_0[1] = { - {107, 1}, -}; -static arc arcs_45_1[1] = { - {108, 2}, -}; -static arc arcs_45_2[2] = { - {33, 1}, - {27, 3}, -}; -static arc arcs_45_3[2] = { - {28, 4}, - {29, 5}, -}; -static arc arcs_45_4[1] = { - {29, 5}, -}; -static arc arcs_45_5[1] = { - {0, 5}, -}; -static state states_45[6] = { - {1, arcs_45_0}, - {1, arcs_45_1}, - {2, arcs_45_2}, - {2, arcs_45_3}, - {1, arcs_45_4}, - {1, arcs_45_5}, -}; -static arc arcs_46_0[1] = { - {26, 1}, -}; -static arc arcs_46_1[2] = { - {87, 2}, - {0, 1}, -}; -static arc arcs_46_2[1] = { - {109, 3}, -}; -static arc arcs_46_3[1] = { - {0, 3}, -}; -static state states_46[4] = { - {1, arcs_46_0}, - {2, arcs_46_1}, - {1, arcs_46_2}, - {1, arcs_46_3}, -}; -static arc arcs_47_0[1] = { - {110, 1}, -}; -static arc arcs_47_1[2] = { - {26, 2}, - {0, 1}, -}; -static arc arcs_47_2[2] = { - {87, 3}, - {0, 2}, -}; -static arc arcs_47_3[1] = { - {23, 4}, -}; -static arc arcs_47_4[1] = { - {0, 4}, -}; -static state states_47[5] = { - {1, arcs_47_0}, - {2, arcs_47_1}, - {2, arcs_47_2}, - {1, arcs_47_3}, - {1, arcs_47_4}, -}; -static arc arcs_48_0[2] = { - {3, 1}, - {2, 2}, -}; -static arc arcs_48_1[1] = { - {0, 1}, -}; -static arc arcs_48_2[2] = { - {28, 3}, - {111, 4}, -}; -static arc arcs_48_3[1] = { - {2, 5}, -}; -static arc arcs_48_4[1] = { - {6, 6}, -}; -static arc arcs_48_5[1] = { - {111, 4}, -}; -static arc arcs_48_6[2] = { - {6, 6}, - {112, 1}, -}; -static state states_48[7] = { - {2, arcs_48_0}, - {1, arcs_48_1}, - {2, arcs_48_2}, - {1, arcs_48_3}, - {1, arcs_48_4}, - {1, arcs_48_5}, - {2, arcs_48_6}, -}; -static arc arcs_49_0[2] = { - {113, 1}, - {114, 2}, -}; -static arc arcs_49_1[2] = { - {98, 3}, - {0, 1}, -}; -static arc arcs_49_2[1] = { - {0, 2}, -}; -static arc arcs_49_3[1] = { - {113, 4}, -}; -static arc arcs_49_4[1] = { - {100, 5}, -}; -static arc arcs_49_5[1] = { - {26, 2}, -}; -static state states_49[6] = { - {2, arcs_49_0}, - {2, arcs_49_1}, - {1, arcs_49_2}, - {1, arcs_49_3}, - {1, arcs_49_4}, - {1, arcs_49_5}, -}; -static arc arcs_50_0[2] = { - {113, 1}, - {116, 1}, -}; -static arc arcs_50_1[1] = { - {0, 1}, -}; -static state states_50[2] = { - {2, arcs_50_0}, - {1, arcs_50_1}, -}; -static arc arcs_51_0[1] = { - {117, 1}, -}; -static arc arcs_51_1[2] = { - {36, 2}, - {27, 3}, -}; -static arc arcs_51_2[1] = { - {27, 3}, -}; -static arc arcs_51_3[1] = { - {26, 4}, -}; -static arc arcs_51_4[1] = { - {0, 4}, -}; -static state states_51[5] = { - {1, arcs_51_0}, - {2, arcs_51_1}, - {1, arcs_51_2}, - {1, arcs_51_3}, - {1, arcs_51_4}, -}; -static arc arcs_52_0[1] = { - {117, 1}, -}; -static arc arcs_52_1[2] = { - {36, 2}, - {27, 3}, -}; -static arc arcs_52_2[1] = { - {27, 3}, -}; -static arc arcs_52_3[1] = { - {115, 4}, -}; -static arc arcs_52_4[1] = { - {0, 4}, -}; -static state states_52[5] = { - {1, arcs_52_0}, - {2, arcs_52_1}, - {1, arcs_52_2}, - {1, arcs_52_3}, - {1, arcs_52_4}, -}; -static arc arcs_53_0[1] = { - {118, 1}, -}; -static arc arcs_53_1[2] = { - {119, 0}, - {0, 1}, -}; -static state states_53[2] = { - {1, arcs_53_0}, - {2, arcs_53_1}, -}; -static arc arcs_54_0[1] = { - {120, 1}, -}; -static arc arcs_54_1[2] = { - {121, 0}, - {0, 1}, -}; -static state states_54[2] = { - {1, arcs_54_0}, - {2, arcs_54_1}, -}; -static arc arcs_55_0[2] = { - {122, 1}, - {123, 2}, -}; -static arc arcs_55_1[1] = { - {120, 2}, -}; -static arc arcs_55_2[1] = { - {0, 2}, -}; -static state states_55[3] = { - {2, arcs_55_0}, - {1, arcs_55_1}, - {1, arcs_55_2}, -}; -static arc arcs_56_0[1] = { - {109, 1}, -}; -static arc arcs_56_1[2] = { - {124, 0}, - {0, 1}, -}; -static state states_56[2] = { - {1, arcs_56_0}, - {2, arcs_56_1}, -}; -static arc arcs_57_0[10] = { - {125, 1}, - {126, 1}, - {127, 1}, - {128, 1}, - {129, 1}, - {130, 1}, - {131, 1}, - {103, 1}, - {122, 2}, - {132, 3}, -}; -static arc arcs_57_1[1] = { - {0, 1}, -}; -static arc arcs_57_2[1] = { - {103, 1}, -}; -static arc arcs_57_3[2] = { - {122, 1}, - {0, 3}, -}; -static state states_57[4] = { - {10, arcs_57_0}, - {1, arcs_57_1}, - {1, arcs_57_2}, - {2, arcs_57_3}, -}; -static arc arcs_58_0[1] = { - {34, 1}, -}; -static arc arcs_58_1[1] = { - {109, 2}, -}; -static arc arcs_58_2[1] = { - {0, 2}, -}; -static state states_58[3] = { - {1, arcs_58_0}, - {1, arcs_58_1}, - {1, arcs_58_2}, -}; -static arc arcs_59_0[1] = { - {133, 1}, -}; -static arc arcs_59_1[2] = { - {134, 0}, - {0, 1}, -}; -static state states_59[2] = { - {1, arcs_59_0}, - {2, arcs_59_1}, -}; -static arc arcs_60_0[1] = { - {135, 1}, -}; -static arc arcs_60_1[2] = { - {136, 0}, - {0, 1}, -}; -static state states_60[2] = { - {1, arcs_60_0}, - {2, arcs_60_1}, -}; -static arc arcs_61_0[1] = { - {137, 1}, -}; -static arc arcs_61_1[2] = { - {138, 0}, - {0, 1}, -}; -static state states_61[2] = { - {1, arcs_61_0}, - {2, arcs_61_1}, -}; -static arc arcs_62_0[1] = { - {139, 1}, -}; -static arc arcs_62_1[3] = { - {140, 0}, - {141, 0}, - {0, 1}, -}; -static state states_62[2] = { - {1, arcs_62_0}, - {3, arcs_62_1}, -}; -static arc arcs_63_0[1] = { - {142, 1}, -}; -static arc arcs_63_1[3] = { - {143, 0}, - {144, 0}, - {0, 1}, -}; -static state states_63[2] = { - {1, arcs_63_0}, - {3, arcs_63_1}, -}; -static arc arcs_64_0[1] = { - {145, 1}, -}; -static arc arcs_64_1[6] = { - {34, 0}, - {11, 0}, - {146, 0}, - {147, 0}, - {148, 0}, - {0, 1}, -}; -static state states_64[2] = { - {1, arcs_64_0}, - {6, arcs_64_1}, -}; -static arc arcs_65_0[4] = { - {143, 1}, - {144, 1}, - {149, 1}, - {150, 2}, -}; -static arc arcs_65_1[1] = { - {145, 2}, -}; -static arc arcs_65_2[1] = { - {0, 2}, -}; -static state states_65[3] = { - {4, arcs_65_0}, - {1, arcs_65_1}, - {1, arcs_65_2}, -}; -static arc arcs_66_0[1] = { - {151, 1}, -}; -static arc arcs_66_1[2] = { - {35, 2}, - {0, 1}, -}; -static arc arcs_66_2[1] = { - {145, 3}, -}; -static arc arcs_66_3[1] = { - {0, 3}, -}; -static state states_66[4] = { - {1, arcs_66_0}, - {2, arcs_66_1}, - {1, arcs_66_2}, - {1, arcs_66_3}, -}; -static arc arcs_67_0[2] = { - {152, 1}, - {153, 2}, -}; -static arc arcs_67_1[1] = { - {153, 2}, -}; -static arc arcs_67_2[2] = { - {154, 2}, - {0, 2}, -}; -static state states_67[3] = { - {2, arcs_67_0}, - {1, arcs_67_1}, - {2, arcs_67_2}, -}; -static arc arcs_68_0[10] = { - {13, 1}, - {156, 2}, - {158, 3}, - {23, 4}, - {161, 4}, - {162, 5}, - {84, 4}, - {163, 4}, - {164, 4}, - {165, 4}, -}; -static arc arcs_68_1[3] = { - {51, 6}, - {155, 6}, - {15, 4}, -}; -static arc arcs_68_2[2] = { - {155, 7}, - {157, 4}, -}; -static arc arcs_68_3[2] = { - {159, 8}, - {160, 4}, -}; -static arc arcs_68_4[1] = { - {0, 4}, -}; -static arc arcs_68_5[2] = { - {162, 5}, - {0, 5}, -}; -static arc arcs_68_6[1] = { - {15, 4}, -}; -static arc arcs_68_7[1] = { - {157, 4}, -}; -static arc arcs_68_8[1] = { - {160, 4}, -}; -static state states_68[9] = { - {10, arcs_68_0}, - {3, arcs_68_1}, - {2, arcs_68_2}, - {2, arcs_68_3}, - {1, arcs_68_4}, - {2, arcs_68_5}, - {1, arcs_68_6}, - {1, arcs_68_7}, - {1, arcs_68_8}, -}; -static arc arcs_69_0[2] = { - {26, 1}, - {52, 1}, -}; -static arc arcs_69_1[3] = { - {166, 2}, - {33, 3}, - {0, 1}, -}; -static arc arcs_69_2[1] = { - {0, 2}, -}; -static arc arcs_69_3[3] = { - {26, 4}, - {52, 4}, - {0, 3}, -}; -static arc arcs_69_4[2] = { - {33, 3}, - {0, 4}, -}; -static state states_69[5] = { - {2, arcs_69_0}, - {3, arcs_69_1}, - {1, arcs_69_2}, - {3, arcs_69_3}, - {2, arcs_69_4}, -}; -static arc arcs_70_0[3] = { - {13, 1}, - {156, 2}, - {83, 3}, -}; -static arc arcs_70_1[2] = { - {14, 4}, - {15, 5}, -}; -static arc arcs_70_2[1] = { - {167, 6}, -}; -static arc arcs_70_3[1] = { - {23, 5}, -}; -static arc arcs_70_4[1] = { - {15, 5}, -}; -static arc arcs_70_5[1] = { - {0, 5}, -}; -static arc arcs_70_6[1] = { - {157, 5}, -}; -static state states_70[7] = { - {3, arcs_70_0}, - {2, arcs_70_1}, - {1, arcs_70_2}, - {1, arcs_70_3}, - {1, arcs_70_4}, - {1, arcs_70_5}, - {1, arcs_70_6}, -}; -static arc arcs_71_0[1] = { - {168, 1}, -}; -static arc arcs_71_1[2] = { - {33, 2}, - {0, 1}, -}; -static arc arcs_71_2[2] = { - {168, 1}, - {0, 2}, -}; -static state states_71[3] = { - {1, arcs_71_0}, - {2, arcs_71_1}, - {2, arcs_71_2}, -}; -static arc arcs_72_0[2] = { - {26, 1}, - {27, 2}, -}; -static arc arcs_72_1[2] = { - {27, 2}, - {0, 1}, -}; -static arc arcs_72_2[3] = { - {26, 3}, - {169, 4}, - {0, 2}, -}; -static arc arcs_72_3[2] = { - {169, 4}, - {0, 3}, -}; -static arc arcs_72_4[1] = { - {0, 4}, -}; -static state states_72[5] = { - {2, arcs_72_0}, - {2, arcs_72_1}, - {3, arcs_72_2}, - {2, arcs_72_3}, - {1, arcs_72_4}, -}; -static arc arcs_73_0[1] = { - {27, 1}, -}; -static arc arcs_73_1[2] = { - {26, 2}, - {0, 1}, -}; -static arc arcs_73_2[1] = { - {0, 2}, -}; -static state states_73[3] = { - {1, arcs_73_0}, - {2, arcs_73_1}, - {1, arcs_73_2}, -}; -static arc arcs_74_0[2] = { - {109, 1}, - {52, 1}, -}; -static arc arcs_74_1[2] = { - {33, 2}, - {0, 1}, -}; -static arc arcs_74_2[3] = { - {109, 1}, - {52, 1}, - {0, 2}, -}; -static state states_74[3] = { - {2, arcs_74_0}, - {2, arcs_74_1}, - {3, arcs_74_2}, -}; -static arc arcs_75_0[1] = { - {26, 1}, -}; -static arc arcs_75_1[2] = { - {33, 2}, - {0, 1}, -}; -static arc arcs_75_2[2] = { - {26, 1}, - {0, 2}, -}; -static state states_75[3] = { - {1, arcs_75_0}, - {2, arcs_75_1}, - {2, arcs_75_2}, -}; -static arc arcs_76_0[3] = { - {26, 1}, - {35, 2}, - {52, 3}, -}; -static arc arcs_76_1[4] = { - {27, 4}, - {166, 5}, - {33, 6}, - {0, 1}, -}; -static arc arcs_76_2[1] = { - {109, 7}, -}; -static arc arcs_76_3[3] = { - {166, 5}, - {33, 6}, - {0, 3}, -}; -static arc arcs_76_4[1] = { - {26, 7}, -}; -static arc arcs_76_5[1] = { - {0, 5}, -}; -static arc arcs_76_6[3] = { - {26, 8}, - {52, 8}, - {0, 6}, -}; -static arc arcs_76_7[3] = { - {166, 5}, - {33, 9}, - {0, 7}, -}; -static arc arcs_76_8[2] = { - {33, 6}, - {0, 8}, -}; -static arc arcs_76_9[3] = { - {26, 10}, - {35, 11}, - {0, 9}, -}; -static arc arcs_76_10[1] = { - {27, 12}, -}; -static arc arcs_76_11[1] = { - {109, 13}, -}; -static arc arcs_76_12[1] = { - {26, 13}, -}; -static arc arcs_76_13[2] = { - {33, 9}, - {0, 13}, -}; -static state states_76[14] = { - {3, arcs_76_0}, - {4, arcs_76_1}, - {1, arcs_76_2}, - {3, arcs_76_3}, - {1, arcs_76_4}, - {1, arcs_76_5}, - {3, arcs_76_6}, - {3, arcs_76_7}, - {2, arcs_76_8}, - {3, arcs_76_9}, - {1, arcs_76_10}, - {1, arcs_76_11}, - {1, arcs_76_12}, - {2, arcs_76_13}, -}; -static arc arcs_77_0[1] = { - {170, 1}, -}; -static arc arcs_77_1[1] = { - {23, 2}, -}; -static arc arcs_77_2[2] = { - {13, 3}, - {27, 4}, -}; -static arc arcs_77_3[2] = { - {14, 5}, - {15, 6}, -}; -static arc arcs_77_4[1] = { - {29, 7}, -}; -static arc arcs_77_5[1] = { - {15, 6}, -}; -static arc arcs_77_6[1] = { - {27, 4}, -}; -static arc arcs_77_7[1] = { - {0, 7}, -}; -static state states_77[8] = { - {1, arcs_77_0}, - {1, arcs_77_1}, - {2, arcs_77_2}, - {2, arcs_77_3}, - {1, arcs_77_4}, - {1, arcs_77_5}, - {1, arcs_77_6}, - {1, arcs_77_7}, -}; -static arc arcs_78_0[1] = { - {171, 1}, -}; -static arc arcs_78_1[2] = { - {33, 2}, - {0, 1}, -}; -static arc arcs_78_2[2] = { - {171, 1}, - {0, 2}, -}; -static state states_78[3] = { - {1, arcs_78_0}, - {2, arcs_78_1}, - {2, arcs_78_2}, -}; -static arc arcs_79_0[3] = { - {26, 1}, - {35, 2}, - {34, 2}, -}; -static arc arcs_79_1[3] = { - {166, 3}, - {32, 2}, - {0, 1}, -}; -static arc arcs_79_2[1] = { - {26, 3}, -}; -static arc arcs_79_3[1] = { - {0, 3}, -}; -static state states_79[4] = { - {3, arcs_79_0}, - {3, arcs_79_1}, - {1, arcs_79_2}, - {1, arcs_79_3}, -}; -static arc arcs_80_0[2] = { - {166, 1}, - {173, 1}, -}; -static arc arcs_80_1[1] = { - {0, 1}, -}; -static state states_80[2] = { - {2, arcs_80_0}, - {1, arcs_80_1}, -}; -static arc arcs_81_0[1] = { - {102, 1}, -}; -static arc arcs_81_1[1] = { - {67, 2}, -}; -static arc arcs_81_2[1] = { - {103, 3}, -}; -static arc arcs_81_3[1] = { - {113, 4}, -}; -static arc arcs_81_4[2] = { - {172, 5}, - {0, 4}, -}; -static arc arcs_81_5[1] = { - {0, 5}, -}; -static state states_81[6] = { - {1, arcs_81_0}, - {1, arcs_81_1}, - {1, arcs_81_2}, - {1, arcs_81_3}, - {2, arcs_81_4}, - {1, arcs_81_5}, -}; -static arc arcs_82_0[2] = { - {21, 1}, - {174, 2}, -}; -static arc arcs_82_1[1] = { - {174, 2}, -}; -static arc arcs_82_2[1] = { - {0, 2}, -}; -static state states_82[3] = { - {2, arcs_82_0}, - {1, arcs_82_1}, - {1, arcs_82_2}, -}; -static arc arcs_83_0[1] = { - {98, 1}, -}; -static arc arcs_83_1[1] = { - {115, 2}, -}; -static arc arcs_83_2[2] = { - {172, 3}, - {0, 2}, -}; -static arc arcs_83_3[1] = { - {0, 3}, -}; -static state states_83[4] = { - {1, arcs_83_0}, - {1, arcs_83_1}, - {2, arcs_83_2}, - {1, arcs_83_3}, -}; -static arc arcs_84_0[1] = { - {23, 1}, -}; -static arc arcs_84_1[1] = { - {0, 1}, -}; -static state states_84[2] = { - {1, arcs_84_0}, - {1, arcs_84_1}, -}; -static arc arcs_85_0[1] = { - {176, 1}, -}; -static arc arcs_85_1[2] = { - {177, 2}, - {0, 1}, -}; -static arc arcs_85_2[1] = { - {0, 2}, -}; -static state states_85[3] = { - {1, arcs_85_0}, - {2, arcs_85_1}, - {1, arcs_85_2}, -}; -static arc arcs_86_0[2] = { - {78, 1}, - {9, 2}, -}; -static arc arcs_86_1[1] = { - {26, 2}, -}; -static arc arcs_86_2[1] = { - {0, 2}, -}; -static state states_86[3] = { - {2, arcs_86_0}, - {1, arcs_86_1}, - {1, arcs_86_2}, -}; -static arc arcs_87_0[1] = { - {179, 1}, -}; -static arc arcs_87_1[2] = { - {2, 1}, - {7, 2}, -}; -static arc arcs_87_2[1] = { - {0, 2}, -}; -static state states_87[3] = { - {1, arcs_87_0}, - {2, arcs_87_1}, - {1, arcs_87_2}, -}; -static arc arcs_88_0[1] = { - {13, 1}, -}; -static arc arcs_88_1[2] = { - {180, 2}, - {15, 3}, -}; -static arc arcs_88_2[1] = { - {15, 3}, -}; -static arc arcs_88_3[1] = { - {25, 4}, -}; -static arc arcs_88_4[1] = { - {26, 5}, -}; -static arc arcs_88_5[1] = { - {0, 5}, -}; -static state states_88[6] = { - {1, arcs_88_0}, - {2, arcs_88_1}, - {1, arcs_88_2}, - {1, arcs_88_3}, - {1, arcs_88_4}, - {1, arcs_88_5}, -}; -static arc arcs_89_0[3] = { - {26, 1}, - {34, 2}, - {35, 3}, -}; -static arc arcs_89_1[2] = { - {33, 4}, - {0, 1}, -}; -static arc arcs_89_2[3] = { - {26, 5}, - {33, 6}, - {0, 2}, -}; -static arc arcs_89_3[1] = { - {26, 7}, -}; -static arc arcs_89_4[4] = { - {26, 1}, - {34, 8}, - {35, 3}, - {0, 4}, -}; -static arc arcs_89_5[2] = { - {33, 6}, - {0, 5}, -}; -static arc arcs_89_6[2] = { - {26, 5}, - {35, 3}, -}; -static arc arcs_89_7[1] = { - {0, 7}, -}; -static arc arcs_89_8[3] = { - {26, 9}, - {33, 10}, - {0, 8}, -}; -static arc arcs_89_9[2] = { - {33, 10}, - {0, 9}, -}; -static arc arcs_89_10[2] = { - {26, 9}, - {35, 3}, -}; -static state states_89[11] = { - {3, arcs_89_0}, - {2, arcs_89_1}, - {3, arcs_89_2}, - {1, arcs_89_3}, - {4, arcs_89_4}, - {2, arcs_89_5}, - {2, arcs_89_6}, - {1, arcs_89_7}, - {3, arcs_89_8}, - {2, arcs_89_9}, - {2, arcs_89_10}, -}; -static dfa dfas[90] = { - {256, "single_input", 0, 3, states_0, - "\004\050\340\000\004\000\000\000\024\174\022\016\144\011\040\004\000\200\041\121\076\004\001"}, - {257, "file_input", 0, 2, states_1, - "\204\050\340\000\004\000\000\000\024\174\022\016\144\011\040\004\000\200\041\121\076\004\001"}, - {258, "eval_input", 0, 3, states_2, - "\000\040\200\000\000\000\000\000\000\000\020\000\000\000\040\004\000\200\041\121\076\000\000"}, - {259, "decorator", 0, 7, states_3, - "\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {260, "decorators", 0, 2, states_4, - "\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {261, "decorated", 0, 3, states_5, - "\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {262, "async_funcdef", 0, 3, states_6, - "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {263, "funcdef", 0, 9, states_7, - "\000\000\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {264, "parameters", 0, 4, states_8, - "\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {265, "typedargslist", 0, 23, states_9, - "\000\000\200\000\014\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {266, "tfpdef", 0, 4, states_10, - "\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {267, "varargslist", 0, 19, states_11, - "\000\000\200\000\014\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {268, "vfpdef", 0, 2, states_12, - "\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {269, "stmt", 0, 2, states_13, - "\000\050\340\000\004\000\000\000\024\174\022\016\144\011\040\004\000\200\041\121\076\004\001"}, - {270, "simple_stmt", 0, 4, states_14, - "\000\040\200\000\004\000\000\000\024\174\022\016\000\000\040\004\000\200\041\121\076\000\001"}, - {271, "small_stmt", 0, 2, states_15, - "\000\040\200\000\004\000\000\000\024\174\022\016\000\000\040\004\000\200\041\121\076\000\001"}, - {272, "expr_stmt", 0, 6, states_16, - "\000\040\200\000\004\000\000\000\000\000\020\000\000\000\040\004\000\200\041\121\076\000\000"}, - {273, "annassign", 0, 5, states_17, - "\000\000\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {274, "testlist_star_expr", 0, 3, states_18, - "\000\040\200\000\004\000\000\000\000\000\020\000\000\000\040\004\000\200\041\121\076\000\000"}, - {275, "augassign", 0, 2, states_19, - "\000\000\000\000\000\000\340\377\003\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {276, "del_stmt", 0, 3, states_20, - "\000\000\000\000\000\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {277, "pass_stmt", 0, 2, states_21, - "\000\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {278, "flow_stmt", 0, 2, states_22, - "\000\000\000\000\000\000\000\000\000\074\000\000\000\000\000\000\000\000\000\000\000\000\001"}, - {279, "break_stmt", 0, 2, states_23, - "\000\000\000\000\000\000\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {280, "continue_stmt", 0, 2, states_24, - "\000\000\000\000\000\000\000\000\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {281, "return_stmt", 0, 3, states_25, - "\000\000\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {282, "yield_stmt", 0, 2, states_26, - "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\001"}, - {283, "raise_stmt", 0, 5, states_27, - "\000\000\000\000\000\000\000\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {284, "import_stmt", 0, 2, states_28, - "\000\000\000\000\000\000\000\000\000\100\002\000\000\000\000\000\000\000\000\000\000\000\000"}, - {285, "import_name", 0, 3, states_29, - "\000\000\000\000\000\000\000\000\000\000\002\000\000\000\000\000\000\000\000\000\000\000\000"}, - {286, "import_from", 0, 8, states_30, - "\000\000\000\000\000\000\000\000\000\100\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {287, "import_as_name", 0, 4, states_31, - "\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {288, "dotted_as_name", 0, 4, states_32, - "\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {289, "import_as_names", 0, 3, states_33, - "\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {290, "dotted_as_names", 0, 2, states_34, - "\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {291, "dotted_name", 0, 2, states_35, - "\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {292, "global_stmt", 0, 3, states_36, - "\000\000\000\000\000\000\000\000\000\000\000\002\000\000\000\000\000\000\000\000\000\000\000"}, - {293, "nonlocal_stmt", 0, 3, states_37, - "\000\000\000\000\000\000\000\000\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000"}, - {294, "assert_stmt", 0, 5, states_38, - "\000\000\000\000\000\000\000\000\000\000\000\010\000\000\000\000\000\000\000\000\000\000\000"}, - {295, "compound_stmt", 0, 2, states_39, - "\000\010\140\000\000\000\000\000\000\000\000\000\144\011\000\000\000\000\000\000\000\004\000"}, - {296, "async_stmt", 0, 3, states_40, - "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {297, "if_stmt", 0, 8, states_41, - "\000\000\000\000\000\000\000\000\000\000\000\000\004\000\000\000\000\000\000\000\000\000\000"}, - {298, "while_stmt", 0, 8, states_42, - "\000\000\000\000\000\000\000\000\000\000\000\000\040\000\000\000\000\000\000\000\000\000\000"}, - {299, "for_stmt", 0, 11, states_43, - "\000\000\000\000\000\000\000\000\000\000\000\000\100\000\000\000\000\000\000\000\000\000\000"}, - {300, "try_stmt", 0, 13, states_44, - "\000\000\000\000\000\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000"}, - {301, "with_stmt", 0, 6, states_45, - "\000\000\000\000\000\000\000\000\000\000\000\000\000\010\000\000\000\000\000\000\000\000\000"}, - {302, "with_item", 0, 4, states_46, - "\000\040\200\000\000\000\000\000\000\000\020\000\000\000\040\004\000\200\041\121\076\000\000"}, - {303, "except_clause", 0, 5, states_47, - "\000\000\000\000\000\000\000\000\000\000\000\000\000\100\000\000\000\000\000\000\000\000\000"}, - {304, "suite", 0, 7, states_48, - "\004\040\200\000\004\000\000\000\024\174\022\016\000\000\040\004\000\200\041\121\076\000\001"}, - {305, "test", 0, 6, states_49, - "\000\040\200\000\000\000\000\000\000\000\020\000\000\000\040\004\000\200\041\121\076\000\000"}, - {306, "test_nocond", 0, 2, states_50, - "\000\040\200\000\000\000\000\000\000\000\020\000\000\000\040\004\000\200\041\121\076\000\000"}, - {307, "lambdef", 0, 5, states_51, - "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\040\000\000\000\000\000\000\000\000"}, - {308, "lambdef_nocond", 0, 5, states_52, - "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\040\000\000\000\000\000\000\000\000"}, - {309, "or_test", 0, 2, states_53, - "\000\040\200\000\000\000\000\000\000\000\020\000\000\000\000\004\000\200\041\121\076\000\000"}, - {310, "and_test", 0, 2, states_54, - "\000\040\200\000\000\000\000\000\000\000\020\000\000\000\000\004\000\200\041\121\076\000\000"}, - {311, "not_test", 0, 3, states_55, - "\000\040\200\000\000\000\000\000\000\000\020\000\000\000\000\004\000\200\041\121\076\000\000"}, - {312, "comparison", 0, 2, states_56, - "\000\040\200\000\000\000\000\000\000\000\020\000\000\000\000\000\000\200\041\121\076\000\000"}, - {313, "comp_op", 0, 4, states_57, - "\000\000\000\000\000\000\000\000\000\000\000\000\200\000\000\344\037\000\000\000\000\000\000"}, - {314, "star_expr", 0, 3, states_58, - "\000\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {315, "expr", 0, 2, states_59, - "\000\040\200\000\000\000\000\000\000\000\020\000\000\000\000\000\000\200\041\121\076\000\000"}, - {316, "xor_expr", 0, 2, states_60, - "\000\040\200\000\000\000\000\000\000\000\020\000\000\000\000\000\000\200\041\121\076\000\000"}, - {317, "and_expr", 0, 2, states_61, - "\000\040\200\000\000\000\000\000\000\000\020\000\000\000\000\000\000\200\041\121\076\000\000"}, - {318, "shift_expr", 0, 2, states_62, - "\000\040\200\000\000\000\000\000\000\000\020\000\000\000\000\000\000\200\041\121\076\000\000"}, - {319, "arith_expr", 0, 2, states_63, - "\000\040\200\000\000\000\000\000\000\000\020\000\000\000\000\000\000\200\041\121\076\000\000"}, - {320, "term", 0, 2, states_64, - "\000\040\200\000\000\000\000\000\000\000\020\000\000\000\000\000\000\200\041\121\076\000\000"}, - {321, "factor", 0, 3, states_65, - "\000\040\200\000\000\000\000\000\000\000\020\000\000\000\000\000\000\200\041\121\076\000\000"}, - {322, "power", 0, 4, states_66, - "\000\040\200\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000\000\121\076\000\000"}, - {323, "atom_expr", 0, 3, states_67, - "\000\040\200\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000\000\121\076\000\000"}, - {324, "atom", 0, 9, states_68, - "\000\040\200\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000\000\120\076\000\000"}, - {325, "testlist_comp", 0, 5, states_69, - "\000\040\200\000\004\000\000\000\000\000\020\000\000\000\040\004\000\200\041\121\076\000\000"}, - {326, "trailer", 0, 7, states_70, - "\000\040\000\000\000\000\000\000\000\000\010\000\000\000\000\000\000\000\000\020\000\000\000"}, - {327, "subscriptlist", 0, 3, states_71, - "\000\040\200\010\000\000\000\000\000\000\020\000\000\000\040\004\000\200\041\121\076\000\000"}, - {328, "subscript", 0, 5, states_72, - "\000\040\200\010\000\000\000\000\000\000\020\000\000\000\040\004\000\200\041\121\076\000\000"}, - {329, "sliceop", 0, 3, states_73, - "\000\000\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {330, "exprlist", 0, 3, states_74, - "\000\040\200\000\004\000\000\000\000\000\020\000\000\000\000\000\000\200\041\121\076\000\000"}, - {331, "testlist", 0, 3, states_75, - "\000\040\200\000\000\000\000\000\000\000\020\000\000\000\040\004\000\200\041\121\076\000\000"}, - {332, "dictorsetmaker", 0, 14, states_76, - "\000\040\200\000\014\000\000\000\000\000\020\000\000\000\040\004\000\200\041\121\076\000\000"}, - {333, "classdef", 0, 8, states_77, - "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\004\000"}, - {334, "arglist", 0, 3, states_78, - "\000\040\200\000\014\000\000\000\000\000\020\000\000\000\040\004\000\200\041\121\076\000\000"}, - {335, "argument", 0, 4, states_79, - "\000\040\200\000\014\000\000\000\000\000\020\000\000\000\040\004\000\200\041\121\076\000\000"}, - {336, "comp_iter", 0, 2, states_80, - "\000\000\040\000\000\000\000\000\000\000\000\000\104\000\000\000\000\000\000\000\000\000\000"}, - {337, "sync_comp_for", 0, 6, states_81, - "\000\000\000\000\000\000\000\000\000\000\000\000\100\000\000\000\000\000\000\000\000\000\000"}, - {338, "comp_for", 0, 3, states_82, - "\000\000\040\000\000\000\000\000\000\000\000\000\100\000\000\000\000\000\000\000\000\000\000"}, - {339, "comp_if", 0, 4, states_83, - "\000\000\000\000\000\000\000\000\000\000\000\000\004\000\000\000\000\000\000\000\000\000\000"}, - {340, "encoding_decl", 0, 2, states_84, - "\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {341, "yield_expr", 0, 3, states_85, - "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\001"}, - {342, "yield_arg", 0, 3, states_86, - "\000\040\200\000\000\000\000\000\000\100\020\000\000\000\040\004\000\200\041\121\076\000\000"}, - {343, "func_type_input", 0, 3, states_87, - "\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {344, "func_type", 0, 6, states_88, - "\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {345, "typelist", 0, 11, states_89, - "\000\040\200\000\014\000\000\000\000\000\020\000\000\000\040\004\000\200\041\121\076\000\000"}, -}; -static label labels[181] = { - {0, "EMPTY"}, - {256, 0}, - {4, 0}, - {270, 0}, - {295, 0}, - {257, 0}, - {269, 0}, - {0, 0}, - {258, 0}, - {331, 0}, - {259, 0}, - {49, 0}, - {291, 0}, - {7, 0}, - {334, 0}, - {8, 0}, - {260, 0}, - {261, 0}, - {333, 0}, - {263, 0}, - {262, 0}, - {55, 0}, - {1, "def"}, - {1, 0}, - {264, 0}, - {51, 0}, - {305, 0}, - {11, 0}, - {57, 0}, - {304, 0}, - {265, 0}, - {266, 0}, - {22, 0}, - {12, 0}, - {16, 0}, - {35, 0}, - {267, 0}, - {268, 0}, - {271, 0}, - {13, 0}, - {272, 0}, - {276, 0}, - {277, 0}, - {278, 0}, - {284, 0}, - {292, 0}, - {293, 0}, - {294, 0}, - {274, 0}, - {273, 0}, - {275, 0}, - {341, 0}, - {314, 0}, - {36, 0}, - {37, 0}, - {38, 0}, - {50, 0}, - {39, 0}, - {40, 0}, - {41, 0}, - {42, 0}, - {43, 0}, - {44, 0}, - {45, 0}, - {46, 0}, - {48, 0}, - {1, "del"}, - {330, 0}, - {1, "pass"}, - {279, 0}, - {280, 0}, - {281, 0}, - {283, 0}, - {282, 0}, - {1, "break"}, - {1, "continue"}, - {1, "return"}, - {1, "raise"}, - {1, "from"}, - {285, 0}, - {286, 0}, - {1, "import"}, - {290, 0}, - {23, 0}, - {52, 0}, - {289, 0}, - {287, 0}, - {1, "as"}, - {288, 0}, - {1, "global"}, - {1, "nonlocal"}, - {1, "assert"}, - {297, 0}, - {298, 0}, - {299, 0}, - {300, 0}, - {301, 0}, - {296, 0}, - {1, "if"}, - {1, "elif"}, - {1, "else"}, - {1, "while"}, - {1, "for"}, - {1, "in"}, - {1, "try"}, - {303, 0}, - {1, "finally"}, - {1, "with"}, - {302, 0}, - {315, 0}, - {1, "except"}, - {5, 0}, - {6, 0}, - {309, 0}, - {307, 0}, - {306, 0}, - {308, 0}, - {1, "lambda"}, - {310, 0}, - {1, "or"}, - {311, 0}, - {1, "and"}, - {1, "not"}, - {312, 0}, - {313, 0}, - {20, 0}, - {21, 0}, - {27, 0}, - {30, 0}, - {29, 0}, - {28, 0}, - {28, 0}, - {1, "is"}, - {316, 0}, - {18, 0}, - {317, 0}, - {32, 0}, - {318, 0}, - {19, 0}, - {319, 0}, - {33, 0}, - {34, 0}, - {320, 0}, - {14, 0}, - {15, 0}, - {321, 0}, - {17, 0}, - {24, 0}, - {47, 0}, - {31, 0}, - {322, 0}, - {323, 0}, - {54, 0}, - {324, 0}, - {326, 0}, - {325, 0}, - {9, 0}, - {10, 0}, - {25, 0}, - {332, 0}, - {26, 0}, - {2, 0}, - {3, 0}, - {1, "None"}, - {1, "True"}, - {1, "False"}, - {338, 0}, - {327, 0}, - {328, 0}, - {329, 0}, - {1, "class"}, - {335, 0}, - {336, 0}, - {339, 0}, - {337, 0}, - {340, 0}, - {1, "yield"}, - {342, 0}, - {343, 0}, - {344, 0}, - {345, 0}, -}; -grammar _Ta3Parser_Grammar = { - 90, - dfas, - {181, labels}, - 256 -}; diff --git a/ast3/Tools/peg_generator/.clang-format b/ast3/Tools/peg_generator/.clang-format new file mode 100644 index 00000000..b2bb93db --- /dev/null +++ b/ast3/Tools/peg_generator/.clang-format @@ -0,0 +1,17 @@ +# A clang-format style that approximates Python's PEP 7 +BasedOnStyle: Google +AlwaysBreakAfterReturnType: All +AllowShortIfStatementsOnASingleLine: false +AlignAfterOpenBracket: Align +BreakBeforeBraces: Stroustrup +ColumnLimit: 95 +DerivePointerAlignment: false +IndentWidth: 4 +Language: Cpp +PointerAlignment: Right +ReflowComments: true +SpaceBeforeParens: ControlStatements +SpacesInParentheses: false +TabWidth: 4 +UseTab: Never +SortIncludes: false diff --git a/ast3/Tools/peg_generator/.gitignore b/ast3/Tools/peg_generator/.gitignore new file mode 100644 index 00000000..91c41f89 --- /dev/null +++ b/ast3/Tools/peg_generator/.gitignore @@ -0,0 +1,3 @@ +peg_extension/parse.c +data/xxl.py +@data diff --git a/ast3/Tools/peg_generator/Makefile b/ast3/Tools/peg_generator/Makefile new file mode 100644 index 00000000..c1219b92 --- /dev/null +++ b/ast3/Tools/peg_generator/Makefile @@ -0,0 +1,119 @@ +UNAME_S := $(shell uname -s) +ifeq ($(UNAME_S),Linux) + PYTHON ?= ../../python +endif +ifeq ($(UNAME_S),Darwin) + PYTHON ?= ../../python.exe +endif + +CPYTHON ?= ../../Lib +MYPY ?= mypy + +GRAMMAR = ../../Grammar/python.gram +TOKENS = ../../Grammar/Tokens +TESTFILE = data/cprog.py +TIMEFILE = data/xxl.py +TESTDIR = . +TESTFLAGS = --short + +data/xxl.py: + $(PYTHON) -m zipfile -e data/xxl.zip data + +build: peg_extension/parse.c + +peg_extension/parse.c: $(GRAMMAR) $(TOKENS) pegen/*.py peg_extension/peg_extension.c ../../Parser/pegen/pegen.c ../../Parser/pegen/parse_string.c ../../Parser/pegen/*.h pegen/grammar_parser.py + $(PYTHON) -m pegen -q c $(GRAMMAR) $(TOKENS) -o peg_extension/parse.c --compile-extension + +clean: + -rm -f peg_extension/*.o peg_extension/*.so peg_extension/parse.c + -rm -f data/xxl.py + +dump: peg_extension/parse.c + cat -n $(TESTFILE) + $(PYTHON) -c "from peg_extension import parse; import ast; t = parse.parse_file('$(TESTFILE)', mode=1); print(ast.dump(t))" + +regen-metaparser: pegen/metagrammar.gram pegen/*.py + $(PYTHON) -m pegen -q python pegen/metagrammar.gram -o pegen/grammar_parser.py + +# Note: These targets really depend on the generated shared object in peg_extension/parse.*.so but +# this has different names in different systems so we are abusing the implicit dependency on +# parse.c by the use of --compile-extension. + +.PHONY: test + +test: run + +run: peg_extension/parse.c + $(PYTHON) -c "from peg_extension import parse; t = parse.parse_file('$(TESTFILE)'); exec(t)" + +compile: peg_extension/parse.c + $(PYTHON) -c "from peg_extension import parse; t = parse.parse_file('$(TESTFILE)', mode=2)" + +parse: peg_extension/parse.c + $(PYTHON) -c "from peg_extension import parse; t = parse.parse_file('$(TESTFILE)', mode=1)" + +check: peg_extension/parse.c + $(PYTHON) -c "from peg_extension import parse; t = parse.parse_file('$(TESTFILE)', mode=0)" + +stats: peg_extension/parse.c data/xxl.py + $(PYTHON) -c "from peg_extension import parse; t = parse.parse_file('$(TIMEFILE)', mode=0); parse.dump_memo_stats()" >@data + $(PYTHON) scripts/joinstats.py @data + +time: time_compile + +time_compile: peg_extension/parse.c data/xxl.py + $(PYTHON) scripts/benchmark.py --parser=pegen --target=xxl compile + +time_parse: peg_extension/parse.c data/xxl.py + $(PYTHON) scripts/benchmark.py --parser=pegen --target=xxl parse + +time_check: peg_extension/parse.c data/xxl.py + $(PYTHON) scripts/benchmark.py --parser=pegen --target=xxl check + +time_stdlib: time_stdlib_compile + +time_stdlib_compile: data/xxl.py + $(PYTHON) scripts/benchmark.py --parser=cpython --target=xxl compile + +time_stdlib_parse: data/xxl.py + $(PYTHON) scripts/benchmark.py --parser=cpython --target=xxl parse + +test_local: + $(PYTHON) scripts/test_parse_directory.py \ + --grammar-file $(GRAMMAR) \ + --tokens-file $(TOKENS) \ + -d $(TESTDIR) \ + $(TESTFLAGS) \ + --exclude "*/failset/*" \ + --exclude "*/failset/**" \ + --exclude "*/failset/**/*" + +test_global: $(CPYTHON) + $(PYTHON) scripts/test_parse_directory.py \ + --grammar-file $(GRAMMAR) \ + --tokens-file $(TOKENS) \ + -d $(CPYTHON) \ + $(TESTFLAGS) \ + --exclude "*/test2to3/*" \ + --exclude "*/test2to3/**/*" \ + --exclude "*/bad*" \ + --exclude "*/lib2to3/tests/data/*" + +mypy: regen-metaparser + $(MYPY) # For list of files, see mypy.ini + +format-python: + black pegen scripts + +bench: + $(PYTHON) scripts/benchmark.py --parser=pegen --target=stdlib check + +format: format-python + +find_max_nesting: + $(PYTHON) scripts/find_max_nesting.py + +tags: TAGS + +TAGS: pegen/*.py test/test_pegen.py + etags pegen/*.py test/test_pegen.py diff --git a/ast3/Tools/peg_generator/data/cprog.py b/ast3/Tools/peg_generator/data/cprog.py new file mode 100644 index 00000000..79a42983 --- /dev/null +++ b/ast3/Tools/peg_generator/data/cprog.py @@ -0,0 +1,11 @@ +if 1: + print("Hello " + "world") + if 0: + print("then") + print("clause") + elif 1: + pass + elif 1: + pass + else: + print("else-clause") diff --git a/ast3/Tools/peg_generator/data/top-pypi-packages-365-days.json b/ast3/Tools/peg_generator/data/top-pypi-packages-365-days.json new file mode 100644 index 00000000..63ff0843 --- /dev/null +++ b/ast3/Tools/peg_generator/data/top-pypi-packages-365-days.json @@ -0,0 +1,16011 @@ +{ + "last_update": "2020-01-17 15:34:44", + "query": { + "bytes_billed": 646188105728, + "bytes_processed": 646187256701, + "cached": false, + "estimated_cost": "2.94" + }, + "rows": [ + { + "download_count": 910195765, + "project": "urllib3" + }, + { + "download_count": 749120890, + "project": "six" + }, + { + "download_count": 670113460, + "project": "botocore" + }, + { + "download_count": 629757389, + "project": "python-dateutil" + }, + { + "download_count": 629606070, + "project": "pip" + }, + { + "download_count": 626954494, + "project": "requests" + }, + { + "download_count": 595019137, + "project": "s3transfer" + }, + { + "download_count": 570148733, + "project": "certifi" + }, + { + "download_count": 542241710, + "project": "idna" + }, + { + "download_count": 534393540, + "project": "pyyaml" + }, + { + "download_count": 531342983, + "project": "pyasn1" + }, + { + "download_count": 518080177, + "project": "docutils" + }, + { + "download_count": 516892347, + "project": "chardet" + }, + { + "download_count": 502956749, + "project": "rsa" + }, + { + "download_count": 480905080, + "project": "jmespath" + }, + { + "download_count": 410856025, + "project": "setuptools" + }, + { + "download_count": 410196551, + "project": "pytz" + }, + { + "download_count": 397671253, + "project": "awscli" + }, + { + "download_count": 392932234, + "project": "futures" + }, + { + "download_count": 375594752, + "project": "colorama" + }, + { + "download_count": 346035749, + "project": "simplejson" + }, + { + "download_count": 337185380, + "project": "boto3" + }, + { + "download_count": 305750769, + "project": "numpy" + }, + { + "download_count": 304101394, + "project": "wheel" + }, + { + "download_count": 264199809, + "project": "protobuf" + }, + { + "download_count": 244941990, + "project": "markupsafe" + }, + { + "download_count": 242351858, + "project": "cffi" + }, + { + "download_count": 214070466, + "project": "jinja2" + }, + { + "download_count": 212238740, + "project": "pyasn1-modules" + }, + { + "download_count": 210982876, + "project": "cryptography" + }, + { + "download_count": 190156825, + "project": "attrs" + }, + { + "download_count": 182755695, + "project": "cachetools" + }, + { + "download_count": 178075863, + "project": "google-api-core" + }, + { + "download_count": 177966855, + "project": "enum34" + }, + { + "download_count": 173568874, + "project": "click" + }, + { + "download_count": 168990924, + "project": "future" + }, + { + "download_count": 168313449, + "project": "google-auth" + }, + { + "download_count": 165064404, + "project": "pandas" + }, + { + "download_count": 161184509, + "project": "grpcio" + }, + { + "download_count": 153694077, + "project": "google-cloud-core" + }, + { + "download_count": 152780068, + "project": "pycparser" + }, + { + "download_count": 150391523, + "project": "googleapis-common-protos" + }, + { + "download_count": 145133278, + "project": "pyparsing" + }, + { + "download_count": 143193200, + "project": "werkzeug" + }, + { + "download_count": 136092386, + "project": "pytest" + }, + { + "download_count": 135106914, + "project": "decorator" + }, + { + "download_count": 128924918, + "project": "asn1crypto" + }, + { + "download_count": 126657878, + "project": "more-itertools" + }, + { + "download_count": 126309809, + "project": "awscli-cwlogs" + }, + { + "download_count": 120300118, + "project": "pluggy" + }, + { + "download_count": 117455899, + "project": "flask" + }, + { + "download_count": 116968652, + "project": "scipy" + }, + { + "download_count": 113639938, + "project": "itsdangerous" + }, + { + "download_count": 111213522, + "project": "oauthlib" + }, + { + "download_count": 106969182, + "project": "py" + }, + { + "download_count": 106245186, + "project": "coverage" + }, + { + "download_count": 104256236, + "project": "virtualenv" + }, + { + "download_count": 102765613, + "project": "requests-oauthlib" + }, + { + "download_count": 102590841, + "project": "psutil" + }, + { + "download_count": 102589154, + "project": "ipaddress" + }, + { + "download_count": 102291693, + "project": "jsonschema" + }, + { + "download_count": 100560003, + "project": "scikit-learn" + }, + { + "download_count": 99249602, + "project": "importlib-metadata" + }, + { + "download_count": 95618798, + "project": "pygments" + }, + { + "download_count": 94913658, + "project": "wcwidth" + }, + { + "download_count": 93958133, + "project": "zipp" + }, + { + "download_count": 93185870, + "project": "pyopenssl" + }, + { + "download_count": 92353815, + "project": "pyjwt" + }, + { + "download_count": 92018680, + "project": "mock" + }, + { + "download_count": 90635179, + "project": "wrapt" + }, + { + "download_count": 90150749, + "project": "google-cloud-storage" + }, + { + "download_count": 86097386, + "project": "pillow" + }, + { + "download_count": 85698334, + "project": "websocket-client" + }, + { + "download_count": 84842257, + "project": "packaging" + }, + { + "download_count": 84475934, + "project": "pbr" + }, + { + "download_count": 82019683, + "project": "ipython" + }, + { + "download_count": 81402313, + "project": "prompt-toolkit" + }, + { + "download_count": 80731622, + "project": "matplotlib" + }, + { + "download_count": 80443033, + "project": "httplib2" + }, + { + "download_count": 78391981, + "project": "boto" + }, + { + "download_count": 77428445, + "project": "lxml" + }, + { + "download_count": 76599773, + "project": "docker" + }, + { + "download_count": 75883487, + "project": "atomicwrites" + }, + { + "download_count": 73114976, + "project": "google-resumable-media" + }, + { + "download_count": 72286328, + "project": "sqlalchemy" + }, + { + "download_count": 71355694, + "project": "argparse" + }, + { + "download_count": 70247997, + "project": "kiwisolver" + }, + { + "download_count": 70157529, + "project": "mccabe" + }, + { + "download_count": 69616809, + "project": "configparser" + }, + { + "download_count": 68080016, + "project": "multidict" + }, + { + "download_count": 65738785, + "project": "tqdm" + }, + { + "download_count": 65716434, + "project": "tornado" + }, + { + "download_count": 65152549, + "project": "funcsigs" + }, + { + "download_count": 64373372, + "project": "beautifulsoup4" + }, + { + "download_count": 64241326, + "project": "paramiko" + }, + { + "download_count": 63570436, + "project": "psycopg2" + }, + { + "download_count": 63544025, + "project": "pyrsistent" + }, + { + "download_count": 63424037, + "project": "typing" + }, + { + "download_count": 62605787, + "project": "markdown" + }, + { + "download_count": 62535342, + "project": "google-api-python-client" + }, + { + "download_count": 61655343, + "project": "redis" + }, + { + "download_count": 61634970, + "project": "bcrypt" + }, + { + "download_count": 60696872, + "project": "pexpect" + }, + { + "download_count": 60144339, + "project": "pycodestyle" + }, + { + "download_count": 60125614, + "project": "absl-py" + }, + { + "download_count": 59496247, + "project": "ptyprocess" + }, + { + "download_count": 59137610, + "project": "aiohttp" + }, + { + "download_count": 59052497, + "project": "entrypoints" + }, + { + "download_count": 58282657, + "project": "oauth2client" + }, + { + "download_count": 57910701, + "project": "docopt" + }, + { + "download_count": 57238190, + "project": "pynacl" + }, + { + "download_count": 55087716, + "project": "traitlets" + }, + { + "download_count": 55005408, + "project": "tabulate" + }, + { + "download_count": 54655331, + "project": "backports-functools-lru-cache" + }, + { + "download_count": 54439203, + "project": "lazy-object-proxy" + }, + { + "download_count": 54278961, + "project": "dill" + }, + { + "download_count": 53875643, + "project": "ipython-genutils" + }, + { + "download_count": 53414364, + "project": "pathlib2" + }, + { + "download_count": 53208142, + "project": "isodate" + }, + { + "download_count": 52918821, + "project": "azure-common" + }, + { + "download_count": 52876560, + "project": "gunicorn" + }, + { + "download_count": 52367394, + "project": "uritemplate" + }, + { + "download_count": 52356165, + "project": "cycler" + }, + { + "download_count": 52009177, + "project": "defusedxml" + }, + { + "download_count": 51204829, + "project": "psycopg2-binary" + }, + { + "download_count": 51194283, + "project": "h5py" + }, + { + "download_count": 51011471, + "project": "termcolor" + }, + { + "download_count": 50365341, + "project": "pickleshare" + }, + { + "download_count": 50282815, + "project": "soupsieve" + }, + { + "download_count": 50184503, + "project": "pyflakes" + }, + { + "download_count": 49235593, + "project": "requests-toolbelt" + }, + { + "download_count": 48265870, + "project": "google-cloud-bigquery" + }, + { + "download_count": 47092132, + "project": "tensorboard" + }, + { + "download_count": 46785233, + "project": "typed-ast" + }, + { + "download_count": 46639206, + "project": "networkx" + }, + { + "download_count": 45991420, + "project": "webencodings" + }, + { + "download_count": 45685686, + "project": "async-timeout" + }, + { + "download_count": 45449338, + "project": "tensorflow" + }, + { + "download_count": 45435235, + "project": "gitpython" + }, + { + "download_count": 45275021, + "project": "pymongo" + }, + { + "download_count": 45205520, + "project": "azure-storage-blob" + }, + { + "download_count": 45085736, + "project": "flake8" + }, + { + "download_count": 44565799, + "project": "isort" + }, + { + "download_count": 44491717, + "project": "contextlib2" + }, + { + "download_count": 44308938, + "project": "scandir" + }, + { + "download_count": 44265261, + "project": "functools32" + }, + { + "download_count": 44039749, + "project": "gevent" + }, + { + "download_count": 42987880, + "project": "pytest-cov" + }, + { + "download_count": 42298933, + "project": "docker-pycreds" + }, + { + "download_count": 42280978, + "project": "joblib" + }, + { + "download_count": 42125807, + "project": "yarl" + }, + { + "download_count": 42105718, + "project": "grpc-google-iam-v1" + }, + { + "download_count": 42070985, + "project": "greenlet" + }, + { + "download_count": 41679952, + "project": "zope-interface" + }, + { + "download_count": 41396597, + "project": "pyzmq" + }, + { + "download_count": 41281740, + "project": "pymysql" + }, + { + "download_count": 41194733, + "project": "django" + }, + { + "download_count": 41174124, + "project": "datadog" + }, + { + "download_count": 41132868, + "project": "bleach" + }, + { + "download_count": 40599053, + "project": "astroid" + }, + { + "download_count": 40529351, + "project": "gitdb2" + }, + { + "download_count": 40342805, + "project": "pylint" + }, + { + "download_count": 40116789, + "project": "babel" + }, + { + "download_count": 39847400, + "project": "azure-storage-common" + }, + { + "download_count": 39689270, + "project": "keras-applications" + }, + { + "download_count": 39395842, + "project": "keras-preprocessing" + }, + { + "download_count": 39184540, + "project": "smmap2" + }, + { + "download_count": 38876199, + "project": "opencv-python" + }, + { + "download_count": 38852272, + "project": "subprocess32" + }, + { + "download_count": 38836392, + "project": "msrest" + }, + { + "download_count": 38732044, + "project": "google-auth-httplib2" + }, + { + "download_count": 38166504, + "project": "parso" + }, + { + "download_count": 37940669, + "project": "jedi" + }, + { + "download_count": 37805943, + "project": "pycryptodome" + }, + { + "download_count": 37739739, + "project": "astor" + }, + { + "download_count": 37110085, + "project": "gast" + }, + { + "download_count": 36881409, + "project": "retrying" + }, + { + "download_count": 35451582, + "project": "elasticsearch" + }, + { + "download_count": 35263938, + "project": "jsonpickle" + }, + { + "download_count": 34975483, + "project": "sqlparse" + }, + { + "download_count": 34879648, + "project": "pyarrow" + }, + { + "download_count": 34858569, + "project": "ordereddict" + }, + { + "download_count": 33824794, + "project": "scikit-image" + }, + { + "download_count": 33775490, + "project": "pycrypto" + }, + { + "download_count": 32742937, + "project": "appdirs" + }, + { + "download_count": 32689782, + "project": "toml" + }, + { + "download_count": 32684718, + "project": "adal" + }, + { + "download_count": 32591485, + "project": "azure-nspkg" + }, + { + "download_count": 32103427, + "project": "xlrd" + }, + { + "download_count": 32000159, + "project": "jupyter-core" + }, + { + "download_count": 31774601, + "project": "xmltodict" + }, + { + "download_count": 31736336, + "project": "toolz" + }, + { + "download_count": 31576642, + "project": "cached-property" + }, + { + "download_count": 31550164, + "project": "prometheus-client" + }, + { + "download_count": 31302562, + "project": "tensorflow-estimator" + }, + { + "download_count": 31010564, + "project": "py4j" + }, + { + "download_count": 30527374, + "project": "websockets" + }, + { + "download_count": 30383292, + "project": "dnspython" + }, + { + "download_count": 30245623, + "project": "nbformat" + }, + { + "download_count": 30162734, + "project": "monotonic" + }, + { + "download_count": 29978338, + "project": "nose" + }, + { + "download_count": 29531870, + "project": "typing-extensions" + }, + { + "download_count": 29443454, + "project": "sklearn" + }, + { + "download_count": 29064516, + "project": "cloudpickle" + }, + { + "download_count": 28794637, + "project": "pywavelets" + }, + { + "download_count": 28710649, + "project": "pycryptodomex" + }, + { + "download_count": 28533182, + "project": "ansible" + }, + { + "download_count": 28501824, + "project": "singledispatch" + }, + { + "download_count": 28281846, + "project": "ply" + }, + { + "download_count": 27973857, + "project": "cython" + }, + { + "download_count": 27913607, + "project": "mako" + }, + { + "download_count": 27864029, + "project": "selenium" + }, + { + "download_count": 27848508, + "project": "html5lib" + }, + { + "download_count": 27745677, + "project": "simplegeneric" + }, + { + "download_count": 27671952, + "project": "apache-beam" + }, + { + "download_count": 27579084, + "project": "backcall" + }, + { + "download_count": 26844011, + "project": "msgpack" + }, + { + "download_count": 26331607, + "project": "dask" + }, + { + "download_count": 26266166, + "project": "regex" + }, + { + "download_count": 26239282, + "project": "ipykernel" + }, + { + "download_count": 25952891, + "project": "ujson" + }, + { + "download_count": 25898723, + "project": "mistune" + }, + { + "download_count": 25796973, + "project": "backports-ssl-match-hostname" + }, + { + "download_count": 25756543, + "project": "amqp" + }, + { + "download_count": 25750485, + "project": "jupyter-client" + }, + { + "download_count": 25701706, + "project": "docker-compose" + }, + { + "download_count": 25315661, + "project": "kombu" + }, + { + "download_count": 25281035, + "project": "ruamel-yaml" + }, + { + "download_count": 25271754, + "project": "nltk" + }, + { + "download_count": 25075126, + "project": "alembic" + }, + { + "download_count": 24664889, + "project": "google-auth-oauthlib" + }, + { + "download_count": 24499399, + "project": "raven" + }, + { + "download_count": 24483899, + "project": "python-editor" + }, + { + "download_count": 24388318, + "project": "sortedcontainers" + }, + { + "download_count": 24375921, + "project": "nbconvert" + }, + { + "download_count": 24045975, + "project": "thrift" + }, + { + "download_count": 23835990, + "project": "notebook" + }, + { + "download_count": 23817589, + "project": "hdfs" + }, + { + "download_count": 23689627, + "project": "slackclient" + }, + { + "download_count": 23619686, + "project": "testpath" + }, + { + "download_count": 23536824, + "project": "s3fs" + }, + { + "download_count": 23476069, + "project": "keras" + }, + { + "download_count": 23364791, + "project": "celery" + }, + { + "download_count": 23339282, + "project": "discord-py" + }, + { + "download_count": 23232254, + "project": "billiard" + }, + { + "download_count": 23210897, + "project": "filelock" + }, + { + "download_count": 23187414, + "project": "snowballstemmer" + }, + { + "download_count": 23088875, + "project": "unidecode" + }, + { + "download_count": 23011985, + "project": "netaddr" + }, + { + "download_count": 22993463, + "project": "pandocfilters" + }, + { + "download_count": 22747435, + "project": "send2trash" + }, + { + "download_count": 22715519, + "project": "terminado" + }, + { + "download_count": 22431738, + "project": "backports-shutil-get-terminal-size" + }, + { + "download_count": 22409669, + "project": "backports-weakref" + }, + { + "download_count": 22231171, + "project": "msrestazure" + }, + { + "download_count": 21906531, + "project": "sentry-sdk" + }, + { + "download_count": 21817254, + "project": "ipywidgets" + }, + { + "download_count": 21711592, + "project": "tzlocal" + }, + { + "download_count": 21626474, + "project": "widgetsnbextension" + }, + { + "download_count": 21533795, + "project": "ijson" + }, + { + "download_count": 21335834, + "project": "mysqlclient" + }, + { + "download_count": 20939369, + "project": "tox" + }, + { + "download_count": 20733637, + "project": "lockfile" + }, + { + "download_count": 20642115, + "project": "xgboost" + }, + { + "download_count": 20630795, + "project": "arrow" + }, + { + "download_count": 20559416, + "project": "vine" + }, + { + "download_count": 20399386, + "project": "google-cloud-pubsub" + }, + { + "download_count": 20372136, + "project": "sphinx" + }, + { + "download_count": 20261684, + "project": "djangorestframework" + }, + { + "download_count": 20222772, + "project": "openpyxl" + }, + { + "download_count": 20101811, + "project": "ecdsa" + }, + { + "download_count": 20081473, + "project": "xlsxwriter" + }, + { + "download_count": 20021156, + "project": "snowflake-connector-python" + }, + { + "download_count": 19972964, + "project": "pyhamcrest" + }, + { + "download_count": 19806017, + "project": "google-cloud-firestore" + }, + { + "download_count": 19717486, + "project": "google-cloud-datastore" + }, + { + "download_count": 19580510, + "project": "google-pasta" + }, + { + "download_count": 19191080, + "project": "qtconsole" + }, + { + "download_count": 19179159, + "project": "bs4" + }, + { + "download_count": 19098496, + "project": "text-unidecode" + }, + { + "download_count": 19089305, + "project": "prettytable" + }, + { + "download_count": 19018504, + "project": "jdcal" + }, + { + "download_count": 19002384, + "project": "google-cloud-logging" + }, + { + "download_count": 18962785, + "project": "backports-abc" + }, + { + "download_count": 18918332, + "project": "jupyter-console" + }, + { + "download_count": 18706905, + "project": "smart-open" + }, + { + "download_count": 18670352, + "project": "alabaster" + }, + { + "download_count": 18664013, + "project": "pyspark" + }, + { + "download_count": 18533388, + "project": "jupyter" + }, + { + "download_count": 18480060, + "project": "statsmodels" + }, + { + "download_count": 18431746, + "project": "unicodecsv" + }, + { + "download_count": 18351262, + "project": "dockerpty" + }, + { + "download_count": 18303864, + "project": "shapely" + }, + { + "download_count": 18289269, + "project": "twisted" + }, + { + "download_count": 18288202, + "project": "hiredis" + }, + { + "download_count": 18166239, + "project": "virtualenv-clone" + }, + { + "download_count": 18139397, + "project": "imagesize" + }, + { + "download_count": 18056871, + "project": "idna-ssl" + }, + { + "download_count": 18052633, + "project": "fasteners" + }, + { + "download_count": 18027552, + "project": "marshmallow" + }, + { + "download_count": 18017517, + "project": "plotly" + }, + { + "download_count": 17675962, + "project": "pytest-forked" + }, + { + "download_count": 17577035, + "project": "texttable" + }, + { + "download_count": 17473671, + "project": "et-xmlfile" + }, + { + "download_count": 17113449, + "project": "kubernetes" + }, + { + "download_count": 17078526, + "project": "incremental" + }, + { + "download_count": 16916001, + "project": "iso8601" + }, + { + "download_count": 16883776, + "project": "applicationinsights" + }, + { + "download_count": 16840538, + "project": "google-cloud-bigtable" + }, + { + "download_count": 16823748, + "project": "pathlib" + }, + { + "download_count": 16759673, + "project": "constantly" + }, + { + "download_count": 16691118, + "project": "automat" + }, + { + "download_count": 16638971, + "project": "hyperlink" + }, + { + "download_count": 16463703, + "project": "azure-mgmt-resource" + }, + { + "download_count": 16410162, + "project": "croniter" + }, + { + "download_count": 16390810, + "project": "python-jose" + }, + { + "download_count": 16303498, + "project": "pipenv" + }, + { + "download_count": 15658966, + "project": "pathspec" + }, + { + "download_count": 15520321, + "project": "nvidia-ml-py3" + }, + { + "download_count": 15364508, + "project": "execnet" + }, + { + "download_count": 15314360, + "project": "aniso8601" + }, + { + "download_count": 15247809, + "project": "python-magic" + }, + { + "download_count": 15213240, + "project": "flask-cors" + }, + { + "download_count": 15203298, + "project": "inflection" + }, + { + "download_count": 15113541, + "project": "gym" + }, + { + "download_count": 14999608, + "project": "mypy" + }, + { + "download_count": 14927461, + "project": "azure-mgmt-storage" + }, + { + "download_count": 14835131, + "project": "flask-sqlalchemy" + }, + { + "download_count": 14822442, + "project": "service-identity" + }, + { + "download_count": 14807088, + "project": "mozrunner" + }, + { + "download_count": 14682178, + "project": "argcomplete" + }, + { + "download_count": 14637155, + "project": "faker" + }, + { + "download_count": 14609350, + "project": "uvloop" + }, + { + "download_count": 14582824, + "project": "apipkg" + }, + { + "download_count": 14479520, + "project": "stevedore" + }, + { + "download_count": 14469933, + "project": "azure-storage-nspkg" + }, + { + "download_count": 14356576, + "project": "ndg-httpsclient" + }, + { + "download_count": 14226382, + "project": "pyserial" + }, + { + "download_count": 14190037, + "project": "seaborn" + }, + { + "download_count": 14151070, + "project": "distro" + }, + { + "download_count": 14141290, + "project": "pytest-timeout" + }, + { + "download_count": 14122087, + "project": "bz2file" + }, + { + "download_count": 14098838, + "project": "patsy" + }, + { + "download_count": 14036101, + "project": "cssselect" + }, + { + "download_count": 13956987, + "project": "tenacity" + }, + { + "download_count": 13927328, + "project": "tensorflow-metadata" + }, + { + "download_count": 13870715, + "project": "graphviz" + }, + { + "download_count": 13850391, + "project": "pydot" + }, + { + "download_count": 13813387, + "project": "azure-mgmt-nspkg" + }, + { + "download_count": 13809809, + "project": "avro" + }, + { + "download_count": 13771055, + "project": "imageio" + }, + { + "download_count": 13764392, + "project": "fastavro" + }, + { + "download_count": 13686467, + "project": "gensim" + }, + { + "download_count": 13643493, + "project": "trueskill" + }, + { + "download_count": 13548711, + "project": "statsd" + }, + { + "download_count": 13505330, + "project": "pytest-xdist" + }, + { + "download_count": 13453212, + "project": "azure-mgmt-containerregistry" + }, + { + "download_count": 13380441, + "project": "mypy-extensions" + }, + { + "download_count": 13340370, + "project": "azure-mgmt-keyvault" + }, + { + "download_count": 13259227, + "project": "ua-parser" + }, + { + "download_count": 13241753, + "project": "configobj" + }, + { + "download_count": 13193523, + "project": "mozlog" + }, + { + "download_count": 13161090, + "project": "fuzzywuzzy" + }, + { + "download_count": 13153967, + "project": "google-gax" + }, + { + "download_count": 12999681, + "project": "responses" + }, + { + "download_count": 12946906, + "project": "aliyun-python-sdk-core" + }, + { + "download_count": 12863346, + "project": "azure-datalake-store" + }, + { + "download_count": 12839810, + "project": "pytest-mock" + }, + { + "download_count": 12835022, + "project": "aliyun-python-sdk-ecs" + }, + { + "download_count": 12816025, + "project": "elasticsearch-dsl" + }, + { + "download_count": 12792645, + "project": "azure-mgmt-authorization" + }, + { + "download_count": 12780433, + "project": "google-apitools" + }, + { + "download_count": 12772525, + "project": "python-daemon" + }, + { + "download_count": 12766382, + "project": "azure-graphrbac" + }, + { + "download_count": 12561149, + "project": "netifaces" + }, + { + "download_count": 12538305, + "project": "s3cmd" + }, + { + "download_count": 12534903, + "project": "python-json-logger" + }, + { + "download_count": 12484719, + "project": "aliyunsdkcore" + }, + { + "download_count": 12406280, + "project": "manhole" + }, + { + "download_count": 12261609, + "project": "hvac" + }, + { + "download_count": 12253367, + "project": "humanfriendly" + }, + { + "download_count": 12246930, + "project": "ipdb" + }, + { + "download_count": 12209179, + "project": "deepdiff" + }, + { + "download_count": 12207990, + "project": "freezegun" + }, + { + "download_count": 12098216, + "project": "maxminddb" + }, + { + "download_count": 12042231, + "project": "uwsgi" + }, + { + "download_count": 11947362, + "project": "pykube" + }, + { + "download_count": 11860617, + "project": "appnope" + }, + { + "download_count": 11805813, + "project": "databricks-cli" + }, + { + "download_count": 11788737, + "project": "python-levenshtein" + }, + { + "download_count": 11778504, + "project": "tensorflow-transform" + }, + { + "download_count": 11612558, + "project": "tldextract" + }, + { + "download_count": 11569388, + "project": "pyodbc" + }, + { + "download_count": 11561349, + "project": "autopep8" + }, + { + "download_count": 11432600, + "project": "pendulum" + }, + { + "download_count": 11383453, + "project": "newrelic" + }, + { + "download_count": 11361327, + "project": "python-dotenv" + }, + { + "download_count": 11334209, + "project": "pytzdata" + }, + { + "download_count": 11270038, + "project": "wtforms" + }, + { + "download_count": 11224152, + "project": "pytest-runner" + }, + { + "download_count": 11104163, + "project": "libtmux" + }, + { + "download_count": 11089587, + "project": "zope-deprecation" + }, + { + "download_count": 11017907, + "project": "jsonpointer" + }, + { + "download_count": 10994575, + "project": "webob" + }, + { + "download_count": 10990219, + "project": "retry" + }, + { + "download_count": 10987260, + "project": "blinker" + }, + { + "download_count": 10973921, + "project": "semantic-version" + }, + { + "download_count": 10843556, + "project": "requests-file" + }, + { + "download_count": 10781388, + "project": "graphql-core" + }, + { + "download_count": 10728518, + "project": "blessings" + }, + { + "download_count": 10716974, + "project": "backoff" + }, + { + "download_count": 10695298, + "project": "black" + }, + { + "download_count": 10686016, + "project": "geopy" + }, + { + "download_count": 10629161, + "project": "google-cloud" + }, + { + "download_count": 10551343, + "project": "bottle" + }, + { + "download_count": 10527245, + "project": "pep8" + }, + { + "download_count": 10511519, + "project": "geoip2" + }, + { + "download_count": 10451332, + "project": "grpcio-tools" + }, + { + "download_count": 10410102, + "project": "traceback2" + }, + { + "download_count": 10386312, + "project": "linecache2" + }, + { + "download_count": 10351287, + "project": "django-extensions" + }, + { + "download_count": 10318239, + "project": "sphinxcontrib-websupport" + }, + { + "download_count": 10239847, + "project": "unittest2" + }, + { + "download_count": 10187032, + "project": "fsspec" + }, + { + "download_count": 10146539, + "project": "django-cors-headers" + }, + { + "download_count": 10119472, + "project": "pkginfo" + }, + { + "download_count": 10077843, + "project": "django-filter" + }, + { + "download_count": 10057055, + "project": "secretstorage" + }, + { + "download_count": 10050204, + "project": "user-agents" + }, + { + "download_count": 10001744, + "project": "configargparse" + }, + { + "download_count": 9957349, + "project": "scp" + }, + { + "download_count": 9942530, + "project": "azure-devops" + }, + { + "download_count": 9938936, + "project": "azure-mgmt-compute" + }, + { + "download_count": 9934159, + "project": "azure-mgmt-network" + }, + { + "download_count": 9904711, + "project": "msgpack-python" + }, + { + "download_count": 9827614, + "project": "azure-mgmt-datalake-nspkg" + }, + { + "download_count": 9735081, + "project": "azure-mgmt-datalake-store" + }, + { + "download_count": 9706197, + "project": "google-cloud-monitoring" + }, + { + "download_count": 9674967, + "project": "mpi4py" + }, + { + "download_count": 9609045, + "project": "mozdevice" + }, + { + "download_count": 9561083, + "project": "azure-keyvault" + }, + { + "download_count": 9523786, + "project": "pysocks" + }, + { + "download_count": 9521848, + "project": "azure-cli" + }, + { + "download_count": 9493349, + "project": "jsondiff" + }, + { + "download_count": 9467938, + "project": "cherrypy" + }, + { + "download_count": 9467625, + "project": "pika" + }, + { + "download_count": 9410911, + "project": "parsedatetime" + }, + { + "download_count": 9399772, + "project": "azure-mgmt-batch" + }, + { + "download_count": 9376391, + "project": "lightgbm" + }, + { + "download_count": 9375734, + "project": "querystring-parser" + }, + { + "download_count": 9342152, + "project": "pyrfc3339" + }, + { + "download_count": 9319192, + "project": "argh" + }, + { + "download_count": 9315946, + "project": "pyproj" + }, + { + "download_count": 9307163, + "project": "mozprofile" + }, + { + "download_count": 9301729, + "project": "pycurl" + }, + { + "download_count": 9288555, + "project": "dictdiffer" + }, + { + "download_count": 9274785, + "project": "flask-wtf" + }, + { + "download_count": 9274704, + "project": "mysql-connector-python" + }, + { + "download_count": 9272854, + "project": "cheroot" + }, + { + "download_count": 9261620, + "project": "codecov" + }, + { + "download_count": 9224842, + "project": "mozinfo" + }, + { + "download_count": 9222371, + "project": "jsonpatch" + }, + { + "download_count": 9217176, + "project": "glob2" + }, + { + "download_count": 9059754, + "project": "azure-batch" + }, + { + "download_count": 9057979, + "project": "crcmod" + }, + { + "download_count": 9033939, + "project": "jaraco-functools" + }, + { + "download_count": 8995380, + "project": "tempora" + }, + { + "download_count": 8959399, + "project": "azure-mgmt-dns" + }, + { + "download_count": 8945640, + "project": "pyhive" + }, + { + "download_count": 8906609, + "project": "azure-mgmt-rdbms" + }, + { + "download_count": 8891960, + "project": "azure-mgmt-sql" + }, + { + "download_count": 8888437, + "project": "mozprocess" + }, + { + "download_count": 8874708, + "project": "portend" + }, + { + "download_count": 8853246, + "project": "geographiclib" + }, + { + "download_count": 8803957, + "project": "azure-mgmt-web" + }, + { + "download_count": 8753999, + "project": "deprecated" + }, + { + "download_count": 8739361, + "project": "munch" + }, + { + "download_count": 8687617, + "project": "jpype1" + }, + { + "download_count": 8659485, + "project": "pysftp" + }, + { + "download_count": 8648248, + "project": "watchdog" + }, + { + "download_count": 8644057, + "project": "ruamel-yaml-clib" + }, + { + "download_count": 8628293, + "project": "mlflow" + }, + { + "download_count": 8605163, + "project": "kafka-python" + }, + { + "download_count": 8593398, + "project": "google" + }, + { + "download_count": 8591157, + "project": "gapic-google-cloud-logging-v2" + }, + { + "download_count": 8565550, + "project": "mujoco-py" + }, + { + "download_count": 8557624, + "project": "zeep" + }, + { + "download_count": 8557527, + "project": "proto-google-cloud-logging-v2" + }, + { + "download_count": 8555221, + "project": "azure-storage" + }, + { + "download_count": 8548889, + "project": "pathtools" + }, + { + "download_count": 8547554, + "project": "django-storages" + }, + { + "download_count": 8493425, + "project": "spacy" + }, + { + "download_count": 8479997, + "project": "pytest-instafail" + }, + { + "download_count": 8476835, + "project": "thinc" + }, + { + "download_count": 8468171, + "project": "factory-boy" + }, + { + "download_count": 8466351, + "project": "preshed" + }, + { + "download_count": 8433752, + "project": "google-cloud-spanner" + }, + { + "download_count": 8433718, + "project": "simpleflock" + }, + { + "download_count": 8402292, + "project": "cymem" + }, + { + "download_count": 8374248, + "project": "azure-storage-queue" + }, + { + "download_count": 8367380, + "project": "azure-mgmt-monitor" + }, + { + "download_count": 8361234, + "project": "murmurhash" + }, + { + "download_count": 8360473, + "project": "jeepney" + }, + { + "download_count": 8358801, + "project": "azure-mgmt-containerservice" + }, + { + "download_count": 8334989, + "project": "zc-lockfile" + }, + { + "download_count": 8334854, + "project": "numpy-stl" + }, + { + "download_count": 8334779, + "project": "requests-mock" + }, + { + "download_count": 8331547, + "project": "tensorflow-serving-api" + }, + { + "download_count": 8316359, + "project": "passlib" + }, + { + "download_count": 8257864, + "project": "aws-xray-sdk" + }, + { + "download_count": 8253117, + "project": "waitress" + }, + { + "download_count": 8213115, + "project": "azure-mgmt-containerinstance" + }, + { + "download_count": 8194190, + "project": "oauth" + }, + { + "download_count": 8192420, + "project": "azure-mgmt-redis" + }, + { + "download_count": 8182626, + "project": "azure-mgmt-cognitiveservices" + }, + { + "download_count": 8169888, + "project": "fabric" + }, + { + "download_count": 8160603, + "project": "sphinx-rtd-theme" + }, + { + "download_count": 8151766, + "project": "azure-mgmt-trafficmanager" + }, + { + "download_count": 8146427, + "project": "pystache" + }, + { + "download_count": 8142774, + "project": "python-slugify" + }, + { + "download_count": 8104254, + "project": "azure-mgmt-devtestlabs" + }, + { + "download_count": 8101969, + "project": "sh" + }, + { + "download_count": 8100079, + "project": "azure-mgmt-cdn" + }, + { + "download_count": 8084499, + "project": "azure-mgmt-datalake-analytics" + }, + { + "download_count": 8068973, + "project": "pyaml" + }, + { + "download_count": 8068659, + "project": "azure-mgmt-iothub" + }, + { + "download_count": 8045085, + "project": "azure-mgmt-cosmosdb" + }, + { + "download_count": 8043637, + "project": "jira" + }, + { + "download_count": 8016426, + "project": "mozterm" + }, + { + "download_count": 8000597, + "project": "flask-login" + }, + { + "download_count": 7983143, + "project": "pycairo" + }, + { + "download_count": 7981647, + "project": "invoke" + }, + { + "download_count": 7969857, + "project": "pyxdg" + }, + { + "download_count": 7896477, + "project": "flask-restful" + }, + { + "download_count": 7892342, + "project": "pymssql" + }, + { + "download_count": 7872871, + "project": "plac" + }, + { + "download_count": 7871712, + "project": "colorlog" + }, + { + "download_count": 7841110, + "project": "stripe" + }, + { + "download_count": 7795667, + "project": "pygobject" + }, + { + "download_count": 7793570, + "project": "vsts" + }, + { + "download_count": 7786931, + "project": "azure-mgmt-applicationinsights" + }, + { + "download_count": 7755436, + "project": "azure-cosmosdb-table" + }, + { + "download_count": 7751414, + "project": "zope-event" + }, + { + "download_count": 7745717, + "project": "gspread" + }, + { + "download_count": 7724172, + "project": "phonenumbers" + }, + { + "download_count": 7698105, + "project": "torch" + }, + { + "download_count": 7677484, + "project": "django-debug-toolbar" + }, + { + "download_count": 7669014, + "project": "azure-mgmt-eventhub" + }, + { + "download_count": 7653695, + "project": "sendgrid" + }, + { + "download_count": 7621120, + "project": "azure-core" + }, + { + "download_count": 7618409, + "project": "requests-aws4auth" + }, + { + "download_count": 7606270, + "project": "zope-component" + }, + { + "download_count": 7602809, + "project": "azure-mgmt-marketplaceordering" + }, + { + "download_count": 7589910, + "project": "holidays" + }, + { + "download_count": 7568947, + "project": "azure-cosmosdb-nspkg" + }, + { + "download_count": 7560913, + "project": "azure-mgmt-servicebus" + }, + { + "download_count": 7555791, + "project": "azure-mgmt-loganalytics" + }, + { + "download_count": 7533328, + "project": "azure-mgmt-recoveryservices" + }, + { + "download_count": 7532133, + "project": "azure-mgmt-recoveryservicesbackup" + }, + { + "download_count": 7519987, + "project": "azure-mgmt-eventgrid" + }, + { + "download_count": 7511851, + "project": "simple-salesforce" + }, + { + "download_count": 7493612, + "project": "azure-mgmt-reservations" + }, + { + "download_count": 7490404, + "project": "mysql-python" + }, + { + "download_count": 7471849, + "project": "azure-mgmt-advisor" + }, + { + "download_count": 7470909, + "project": "azure-mgmt-media" + }, + { + "download_count": 7461600, + "project": "backports-tempfile" + }, + { + "download_count": 7452831, + "project": "azure-mgmt-msi" + }, + { + "download_count": 7444403, + "project": "azure-mgmt-batchai" + }, + { + "download_count": 7443190, + "project": "azure-mgmt-iothubprovisioningservices" + }, + { + "download_count": 7427082, + "project": "azure-mgmt-search" + }, + { + "download_count": 7426073, + "project": "azure-mgmt-consumption" + }, + { + "download_count": 7421118, + "project": "azure-mgmt-servicefabric" + }, + { + "download_count": 7420661, + "project": "azure-mgmt-billing" + }, + { + "download_count": 7410977, + "project": "semver" + }, + { + "download_count": 7399599, + "project": "w3lib" + }, + { + "download_count": 7377445, + "project": "supervisor" + }, + { + "download_count": 7371140, + "project": "moto" + }, + { + "download_count": 7360517, + "project": "josepy" + }, + { + "download_count": 7359916, + "project": "azure-mgmt-relay" + }, + { + "download_count": 7325634, + "project": "pandas-gbq" + }, + { + "download_count": 7317868, + "project": "acme" + }, + { + "download_count": 7308144, + "project": "azure-servicebus" + }, + { + "download_count": 7271321, + "project": "xlwt" + }, + { + "download_count": 7270699, + "project": "structlog" + }, + { + "download_count": 7268987, + "project": "sphinxcontrib-serializinghtml" + }, + { + "download_count": 7268175, + "project": "sphinxcontrib-htmlhelp" + }, + { + "download_count": 7251725, + "project": "keyring" + }, + { + "download_count": 7251674, + "project": "sphinxcontrib-qthelp" + }, + { + "download_count": 7251256, + "project": "sphinxcontrib-devhelp" + }, + { + "download_count": 7251076, + "project": "sphinxcontrib-applehelp" + }, + { + "download_count": 7250627, + "project": "sphinxcontrib-jsmath" + }, + { + "download_count": 7239285, + "project": "pytest-django" + }, + { + "download_count": 7236146, + "project": "voluptuous" + }, + { + "download_count": 7235602, + "project": "llvmlite" + }, + { + "download_count": 7112734, + "project": "theano" + }, + { + "download_count": 7042677, + "project": "numba" + }, + { + "download_count": 7038235, + "project": "shellingham" + }, + { + "download_count": 7023740, + "project": "pydocumentdb" + }, + { + "download_count": 7014759, + "project": "parse" + }, + { + "download_count": 7011858, + "project": "coloredlogs" + }, + { + "download_count": 6991011, + "project": "certbot" + }, + { + "download_count": 6989202, + "project": "google-cloud-vision" + }, + { + "download_count": 6983443, + "project": "influxdb" + }, + { + "download_count": 6981795, + "project": "azure-mgmt-managementgroups" + }, + { + "download_count": 6962527, + "project": "azure-mgmt-datamigration" + }, + { + "download_count": 6935874, + "project": "cheetah" + }, + { + "download_count": 6931267, + "project": "azure-mgmt-policyinsights" + }, + { + "download_count": 6910342, + "project": "python-augeas" + }, + { + "download_count": 6902895, + "project": "tblib" + }, + { + "download_count": 6885492, + "project": "azure-mgmt-iotcentral" + }, + { + "download_count": 6882533, + "project": "azure-mgmt-signalr" + }, + { + "download_count": 6879787, + "project": "instana" + }, + { + "download_count": 6848658, + "project": "uptime" + }, + { + "download_count": 6823328, + "project": "azure-mgmt-maps" + }, + { + "download_count": 6811121, + "project": "coreapi" + }, + { + "download_count": 6805884, + "project": "setproctitle" + }, + { + "download_count": 6803339, + "project": "pymemcache" + }, + { + "download_count": 6790921, + "project": "opt-einsum" + }, + { + "download_count": 6746204, + "project": "coreschema" + }, + { + "download_count": 6733204, + "project": "dicttoxml" + }, + { + "download_count": 6709540, + "project": "python-mimeparse" + }, + { + "download_count": 6686487, + "project": "letsencrypt" + }, + { + "download_count": 6671209, + "project": "pypdf2" + }, + { + "download_count": 6659143, + "project": "certbot-apache" + }, + { + "download_count": 6650051, + "project": "feedparser" + }, + { + "download_count": 6629341, + "project": "itypes" + }, + { + "download_count": 6607528, + "project": "datetime" + }, + { + "download_count": 6595896, + "project": "pyglet" + }, + { + "download_count": 6565703, + "project": "pywin32" + }, + { + "download_count": 6555587, + "project": "cachecontrol" + }, + { + "download_count": 6537738, + "project": "whichcraft" + }, + { + "download_count": 6493687, + "project": "repoze-lru" + }, + { + "download_count": 6483589, + "project": "opentracing" + }, + { + "download_count": 6471332, + "project": "yapf" + }, + { + "download_count": 6470521, + "project": "reportlab" + }, + { + "download_count": 6454108, + "project": "pyperclip" + }, + { + "download_count": 6427226, + "project": "sasl" + }, + { + "download_count": 6416154, + "project": "pydocstyle" + }, + { + "download_count": 6412179, + "project": "ldap3" + }, + { + "download_count": 6364528, + "project": "python-http-client" + }, + { + "download_count": 6363103, + "project": "pycountry" + }, + { + "download_count": 6348755, + "project": "azure-servicemanagement-legacy" + }, + { + "download_count": 6348419, + "project": "certbot-nginx" + }, + { + "download_count": 6347386, + "project": "python-gnupg" + }, + { + "download_count": 6338642, + "project": "suds-jurko" + }, + { + "download_count": 6325028, + "project": "promise" + }, + { + "download_count": 6321828, + "project": "twine" + }, + { + "download_count": 6310843, + "project": "django-redis" + }, + { + "download_count": 6310630, + "project": "redis-py-cluster" + }, + { + "download_count": 6301931, + "project": "mysql-connector" + }, + { + "download_count": 6295377, + "project": "python-jenkins" + }, + { + "download_count": 6275920, + "project": "azure-servicefabric" + }, + { + "download_count": 6251258, + "project": "expiringdict" + }, + { + "download_count": 6237744, + "project": "pyvcf" + }, + { + "download_count": 6217846, + "project": "watchtower" + }, + { + "download_count": 6191358, + "project": "poyo" + }, + { + "download_count": 6177944, + "project": "html2text" + }, + { + "download_count": 6167605, + "project": "binaryornot" + }, + { + "download_count": 6156388, + "project": "azure-mgmt" + }, + { + "download_count": 6141630, + "project": "bokeh" + }, + { + "download_count": 6124335, + "project": "python3-openid" + }, + { + "download_count": 6124110, + "project": "azure-storage-file" + }, + { + "download_count": 6123086, + "project": "oscrypto" + }, + { + "download_count": 6089609, + "project": "kazoo" + }, + { + "download_count": 6087309, + "project": "cookiecutter" + }, + { + "download_count": 6069231, + "project": "jinja2-time" + }, + { + "download_count": 6060397, + "project": "azure" + }, + { + "download_count": 6048114, + "project": "google-cloud-translate" + }, + { + "download_count": 6041366, + "project": "humanize" + }, + { + "download_count": 6039221, + "project": "numexpr" + }, + { + "download_count": 6020894, + "project": "twilio" + }, + { + "download_count": 6012401, + "project": "cerberus" + }, + { + "download_count": 6012147, + "project": "azure-mgmt-logic" + }, + { + "download_count": 6006198, + "project": "google-cloud-language" + }, + { + "download_count": 6003966, + "project": "nodeenv" + }, + { + "download_count": 5973514, + "project": "azure-mgmt-scheduler" + }, + { + "download_count": 5943411, + "project": "backports-csv" + }, + { + "download_count": 5918171, + "project": "multi-key-dict" + }, + { + "download_count": 5880962, + "project": "python-memcached" + }, + { + "download_count": 5873333, + "project": "srsly" + }, + { + "download_count": 5867465, + "project": "cx-oracle" + }, + { + "download_count": 5859924, + "project": "blis" + }, + { + "download_count": 5855262, + "project": "azure-mgmt-datafactory" + }, + { + "download_count": 5829317, + "project": "identify" + }, + { + "download_count": 5817248, + "project": "pydata-google-auth" + }, + { + "download_count": 5816751, + "project": "parsel" + }, + { + "download_count": 5808925, + "project": "setuptools-scm" + }, + { + "download_count": 5798570, + "project": "confluent-kafka" + }, + { + "download_count": 5780362, + "project": "lunardate" + }, + { + "download_count": 5770962, + "project": "eventlet" + }, + { + "download_count": 5764369, + "project": "webtest" + }, + { + "download_count": 5762114, + "project": "sqlalchemy-utils" + }, + { + "download_count": 5748385, + "project": "pre-commit" + }, + { + "download_count": 5744591, + "project": "flask-restplus" + }, + { + "download_count": 5741800, + "project": "google-cloud-error-reporting" + }, + { + "download_count": 5727692, + "project": "gapic-google-cloud-datastore-v1" + }, + { + "download_count": 5726258, + "project": "google-cloud-speech" + }, + { + "download_count": 5696390, + "project": "tensorflow-gpu" + }, + { + "download_count": 5671626, + "project": "youtube-dl" + }, + { + "download_count": 5669862, + "project": "zope-proxy" + }, + { + "download_count": 5668657, + "project": "zope-hookable" + }, + { + "download_count": 5666674, + "project": "aspy-yaml" + }, + { + "download_count": 5665846, + "project": "pystan" + }, + { + "download_count": 5658876, + "project": "meld3" + }, + { + "download_count": 5657136, + "project": "zope-deferredimport" + }, + { + "download_count": 5646525, + "project": "altgraph" + }, + { + "download_count": 5638012, + "project": "yamllint" + }, + { + "download_count": 5627465, + "project": "pydispatcher" + }, + { + "download_count": 5598597, + "project": "pytest-html" + }, + { + "download_count": 5589472, + "project": "queuelib" + }, + { + "download_count": 5580580, + "project": "mpmath" + }, + { + "download_count": 5556096, + "project": "wasabi" + }, + { + "download_count": 5538810, + "project": "dateparser" + }, + { + "download_count": 5522745, + "project": "azure-mgmt-subscription" + }, + { + "download_count": 5500243, + "project": "flask-migrate" + }, + { + "download_count": 5494861, + "project": "cfgv" + }, + { + "download_count": 5490908, + "project": "azure-mgmt-notificationhubs" + }, + { + "download_count": 5479229, + "project": "azure-mgmt-managementpartner" + }, + { + "download_count": 5477766, + "project": "azure-mgmt-powerbiembedded" + }, + { + "download_count": 5471458, + "project": "azure-eventgrid" + }, + { + "download_count": 5469115, + "project": "azure-mgmt-commerce" + }, + { + "download_count": 5465959, + "project": "azure-mgmt-machinelearningcompute" + }, + { + "download_count": 5462201, + "project": "readme-renderer" + }, + { + "download_count": 5461957, + "project": "azure-mgmt-hanaonazure" + }, + { + "download_count": 5447652, + "project": "rfc3986" + }, + { + "download_count": 5440586, + "project": "scrapy" + }, + { + "download_count": 5434695, + "project": "aenum" + }, + { + "download_count": 5420091, + "project": "anyjson" + }, + { + "download_count": 5407106, + "project": "proto-google-cloud-datastore-v1" + }, + { + "download_count": 5387258, + "project": "sympy" + }, + { + "download_count": 5374203, + "project": "pygithub" + }, + { + "download_count": 5373585, + "project": "pytest-metadata" + }, + { + "download_count": 5340852, + "project": "paho-mqtt" + }, + { + "download_count": 5335035, + "project": "multiprocess" + }, + { + "download_count": 5333251, + "project": "googledatastore" + }, + { + "download_count": 5328607, + "project": "phoenixdb" + }, + { + "download_count": 5322559, + "project": "nose-exclude" + }, + { + "download_count": 5309246, + "project": "importlib-resources" + }, + { + "download_count": 5299450, + "project": "cookies" + }, + { + "download_count": 5277019, + "project": "tensorflow-tensorboard" + }, + { + "download_count": 5255084, + "project": "thrift-sasl" + }, + { + "download_count": 5249244, + "project": "jsonpath-rw" + }, + { + "download_count": 5245636, + "project": "oslo-i18n" + }, + { + "download_count": 5245466, + "project": "s2sphere" + }, + { + "download_count": 5245010, + "project": "whitenoise" + }, + { + "download_count": 5236181, + "project": "google-cloud-dns" + }, + { + "download_count": 5223390, + "project": "aws-sam-translator" + }, + { + "download_count": 5213027, + "project": "slacker" + }, + { + "download_count": 5165706, + "project": "hypothesis" + }, + { + "download_count": 5155283, + "project": "google-cloud-resource-manager" + }, + { + "download_count": 5152438, + "project": "debtcollector" + }, + { + "download_count": 5141790, + "project": "ruamel-ordereddict" + }, + { + "download_count": 5136659, + "project": "azure-loganalytics" + }, + { + "download_count": 5089358, + "project": "rx" + }, + { + "download_count": 5083806, + "project": "discord" + }, + { + "download_count": 5082337, + "project": "click-plugins" + }, + { + "download_count": 5069136, + "project": "google-cloud-videointelligence" + }, + { + "download_count": 5067821, + "project": "google-cloud-runtimeconfig" + }, + { + "download_count": 5043933, + "project": "inflect" + }, + { + "download_count": 5006490, + "project": "pulp" + }, + { + "download_count": 5001567, + "project": "oslo-utils" + }, + { + "download_count": 4965630, + "project": "azure-mgmt-devspaces" + }, + { + "download_count": 4949806, + "project": "stringcase" + }, + { + "download_count": 4926195, + "project": "django-appconf" + }, + { + "download_count": 4913373, + "project": "pynamodb" + }, + { + "download_count": 4913090, + "project": "dogpile-cache" + }, + { + "download_count": 4899768, + "project": "python-consul" + }, + { + "download_count": 4896198, + "project": "milksnake" + }, + { + "download_count": 4875874, + "project": "pypng" + }, + { + "download_count": 4868256, + "project": "oslo-config" + }, + { + "download_count": 4857940, + "project": "haversine" + }, + { + "download_count": 4854545, + "project": "azure-applicationinsights" + }, + { + "download_count": 4830085, + "project": "flower" + }, + { + "download_count": 4787508, + "project": "bandit" + }, + { + "download_count": 4766743, + "project": "strict-rfc3339" + }, + { + "download_count": 4744246, + "project": "findspark" + }, + { + "download_count": 4742234, + "project": "flask-admin" + }, + { + "download_count": 4742026, + "project": "qds-sdk" + }, + { + "download_count": 4735803, + "project": "pip-tools" + }, + { + "download_count": 4701984, + "project": "cliff" + }, + { + "download_count": 4701803, + "project": "ddtrace" + }, + { + "download_count": 4693878, + "project": "progressbar2" + }, + { + "download_count": 4652633, + "project": "python-utils" + }, + { + "download_count": 4645712, + "project": "cairocffi" + }, + { + "download_count": 4645547, + "project": "google-cloud-trace" + }, + { + "download_count": 4636704, + "project": "docker-py" + }, + { + "download_count": 4632853, + "project": "tinycss2" + }, + { + "download_count": 4627762, + "project": "apscheduler" + }, + { + "download_count": 4606642, + "project": "python-pam" + }, + { + "download_count": 4606137, + "project": "grpcio-gcp" + }, + { + "download_count": 4605186, + "project": "parse-type" + }, + { + "download_count": 4601072, + "project": "parameterized" + }, + { + "download_count": 4600206, + "project": "avro-python3" + }, + { + "download_count": 4589906, + "project": "pypiwin32" + }, + { + "download_count": 4587705, + "project": "olefile" + }, + { + "download_count": 4586230, + "project": "testtools" + }, + { + "download_count": 4583482, + "project": "dj-database-url" + }, + { + "download_count": 4572193, + "project": "basictracer" + }, + { + "download_count": 4567533, + "project": "macholib" + }, + { + "download_count": 4563623, + "project": "cligj" + }, + { + "download_count": 4560977, + "project": "google-cloud-container" + }, + { + "download_count": 4553683, + "project": "oslo-serialization" + }, + { + "download_count": 4544031, + "project": "logging" + }, + { + "download_count": 4543347, + "project": "click-completion" + }, + { + "download_count": 4542581, + "project": "pycares" + }, + { + "download_count": 4461143, + "project": "fiona" + }, + { + "download_count": 4454845, + "project": "mmh3" + }, + { + "download_count": 4447608, + "project": "jws" + }, + { + "download_count": 4433310, + "project": "python-docx" + }, + { + "download_count": 4432803, + "project": "mleap" + }, + { + "download_count": 4430881, + "project": "extras" + }, + { + "download_count": 4394588, + "project": "dataclasses" + }, + { + "download_count": 4384805, + "project": "fixtures" + }, + { + "download_count": 4368983, + "project": "cfn-lint" + }, + { + "download_count": 4347507, + "project": "cairosvg" + }, + { + "download_count": 4345671, + "project": "lz4" + }, + { + "download_count": 4341286, + "project": "flask-script" + }, + { + "download_count": 4335840, + "project": "statistics" + }, + { + "download_count": 4332342, + "project": "fbprophet" + }, + { + "download_count": 4329185, + "project": "cmd2" + }, + { + "download_count": 4323965, + "project": "brotli" + }, + { + "download_count": 4323647, + "project": "cytoolz" + }, + { + "download_count": 4315817, + "project": "polyaxon-client" + }, + { + "download_count": 4309639, + "project": "portalocker" + }, + { + "download_count": 4302427, + "project": "torchvision" + }, + { + "download_count": 4299923, + "project": "bumpversion" + }, + { + "download_count": 4291946, + "project": "python-jwt" + }, + { + "download_count": 4264873, + "project": "polyaxon-cli" + }, + { + "download_count": 4263296, + "project": "polyaxon-deploy" + }, + { + "download_count": 4260496, + "project": "coveralls" + }, + { + "download_count": 4256821, + "project": "python-geohash" + }, + { + "download_count": 4247442, + "project": "flask-caching" + }, + { + "download_count": 4223430, + "project": "cssselect2" + }, + { + "download_count": 4217166, + "project": "behave" + }, + { + "download_count": 4198998, + "project": "mozfile" + }, + { + "download_count": 4198846, + "project": "ddt" + }, + { + "download_count": 4192314, + "project": "aiodns" + }, + { + "download_count": 4180658, + "project": "googleads" + }, + { + "download_count": 4151629, + "project": "flake8-polyfill" + }, + { + "download_count": 4142826, + "project": "pyphen" + }, + { + "download_count": 4130090, + "project": "fastparquet" + }, + { + "download_count": 4125828, + "project": "flask-babel" + }, + { + "download_count": 4114954, + "project": "gcloud" + }, + { + "download_count": 4098408, + "project": "google-cloud-bigquery-datatransfer" + }, + { + "download_count": 4088308, + "project": "gorilla" + }, + { + "download_count": 4081407, + "project": "keystoneauth1" + }, + { + "download_count": 4077553, + "project": "requests-futures" + }, + { + "download_count": 4054249, + "project": "azureml-core" + }, + { + "download_count": 4042252, + "project": "python-ldap" + }, + { + "download_count": 4007776, + "project": "pathos" + }, + { + "download_count": 3999757, + "project": "ephem" + }, + { + "download_count": 3969692, + "project": "hyperopt" + }, + { + "download_count": 3949966, + "project": "testfixtures" + }, + { + "download_count": 3937830, + "project": "fonttools" + }, + { + "download_count": 3935226, + "project": "terminaltables" + }, + { + "download_count": 3927254, + "project": "easyprocess" + }, + { + "download_count": 3922990, + "project": "python-gflags" + }, + { + "download_count": 3912801, + "project": "deprecation" + }, + { + "download_count": 3905705, + "project": "nvidia-ml-py" + }, + { + "download_count": 3885807, + "project": "google-cloud-kms" + }, + { + "download_count": 3865843, + "project": "geojson" + }, + { + "download_count": 3828132, + "project": "robotframework" + }, + { + "download_count": 3820453, + "project": "gcsfs" + }, + { + "download_count": 3810489, + "project": "convertdate" + }, + { + "download_count": 3809802, + "project": "sockjs-tornado" + }, + { + "download_count": 3799689, + "project": "multipledispatch" + }, + { + "download_count": 3798810, + "project": "weasyprint" + }, + { + "download_count": 3793665, + "project": "tomlkit" + }, + { + "download_count": 3792308, + "project": "python-snappy" + }, + { + "download_count": 3787259, + "project": "django-model-utils" + }, + { + "download_count": 3780397, + "project": "distributed" + }, + { + "download_count": 3775038, + "project": "grequests" + }, + { + "download_count": 3771741, + "project": "flask-bcrypt" + }, + { + "download_count": 3769931, + "project": "fakeredis" + }, + { + "download_count": 3752939, + "project": "schedule" + }, + { + "download_count": 3746896, + "project": "validators" + }, + { + "download_count": 3721493, + "project": "knack" + }, + { + "download_count": 3693854, + "project": "pox" + }, + { + "download_count": 3682964, + "project": "sshtunnel" + }, + { + "download_count": 3681065, + "project": "tftpy" + }, + { + "download_count": 3676291, + "project": "pdfminer" + }, + { + "download_count": 3664933, + "project": "google-compute-engine" + }, + { + "download_count": 3647507, + "project": "graphene" + }, + { + "download_count": 3639253, + "project": "setuptools-git" + }, + { + "download_count": 3630380, + "project": "unittest-xml-reporting" + }, + { + "download_count": 3627156, + "project": "ciso8601" + }, + { + "download_count": 3627033, + "project": "sockjs" + }, + { + "download_count": 3625069, + "project": "shortuuid" + }, + { + "download_count": 3616592, + "project": "ray" + }, + { + "download_count": 3613699, + "project": "ppft" + }, + { + "download_count": 3597147, + "project": "shap" + }, + { + "download_count": 3590917, + "project": "azureml-model-management-sdk" + }, + { + "download_count": 3588391, + "project": "pygsheets" + }, + { + "download_count": 3584999, + "project": "flask-swagger" + }, + { + "download_count": 3575551, + "project": "cssutils" + }, + { + "download_count": 3568283, + "project": "pattern" + }, + { + "download_count": 3549188, + "project": "pylev" + }, + { + "download_count": 3544798, + "project": "ibm-db-sa" + }, + { + "download_count": 3526181, + "project": "pyathenajdbc" + }, + { + "download_count": 3518011, + "project": "pylint-plugin-utils" + }, + { + "download_count": 3517988, + "project": "pg8000" + }, + { + "download_count": 3517712, + "project": "tensorflow-model-analysis" + }, + { + "download_count": 3507991, + "project": "os-service-types" + }, + { + "download_count": 3489788, + "project": "python-swiftclient" + }, + { + "download_count": 3477450, + "project": "openstacksdk" + }, + { + "download_count": 3465240, + "project": "cfn-flip" + }, + { + "download_count": 3459223, + "project": "catkin-pkg" + }, + { + "download_count": 3455963, + "project": "cleo" + }, + { + "download_count": 3448945, + "project": "python-keystoneclient" + }, + { + "download_count": 3448335, + "project": "jellyfish" + }, + { + "download_count": 3444950, + "project": "apispec" + }, + { + "download_count": 3443490, + "project": "pastel" + }, + { + "download_count": 3434078, + "project": "django-tables2" + }, + { + "download_count": 3429540, + "project": "qrcode" + }, + { + "download_count": 3426160, + "project": "collectd-nvidianvml" + }, + { + "download_count": 3420045, + "project": "apache-airflow" + }, + { + "download_count": 3411604, + "project": "prison" + }, + { + "download_count": 3402478, + "project": "pefile" + }, + { + "download_count": 3393690, + "project": "commonmark" + }, + { + "download_count": 3388484, + "project": "tablib" + }, + { + "download_count": 3384168, + "project": "ntlm-auth" + }, + { + "download_count": 3377675, + "project": "geopandas" + }, + { + "download_count": 3366350, + "project": "jsmin" + }, + { + "download_count": 3361635, + "project": "antlr4-python3-runtime" + }, + { + "download_count": 3340033, + "project": "polyaxon-dockerizer" + }, + { + "download_count": 3293582, + "project": "odfpy" + }, + { + "download_count": 3269264, + "project": "openapi-codec" + }, + { + "download_count": 3258675, + "project": "utm" + }, + { + "download_count": 3251855, + "project": "pyvmomi" + }, + { + "download_count": 3251588, + "project": "poetry" + }, + { + "download_count": 3247520, + "project": "bitarray" + }, + { + "download_count": 3244587, + "project": "python-crontab" + }, + { + "download_count": 3243979, + "project": "django-mysql" + }, + { + "download_count": 3242901, + "project": "databricks-pypi1" + }, + { + "download_count": 3238235, + "project": "marshmallow-sqlalchemy" + }, + { + "download_count": 3226761, + "project": "emoji" + }, + { + "download_count": 3224704, + "project": "initools" + }, + { + "download_count": 3209542, + "project": "capstone" + }, + { + "download_count": 3200795, + "project": "djangorestframework-jwt" + }, + { + "download_count": 3184641, + "project": "django-rest-swagger" + }, + { + "download_count": 3181604, + "project": "tensorflow-hub" + }, + { + "download_count": 3179141, + "project": "ratelimit" + }, + { + "download_count": 3176283, + "project": "asyncio" + }, + { + "download_count": 3176119, + "project": "spark-sklearn" + }, + { + "download_count": 3173008, + "project": "paste" + }, + { + "download_count": 3169917, + "project": "pytest-asyncio" + }, + { + "download_count": 3159532, + "project": "django-crispy-forms" + }, + { + "download_count": 3156134, + "project": "cachy" + }, + { + "download_count": 3150001, + "project": "asgiref" + }, + { + "download_count": 3138323, + "project": "django-environ" + }, + { + "download_count": 3127100, + "project": "fire" + }, + { + "download_count": 3123851, + "project": "salesforce-bulk" + }, + { + "download_count": 3117730, + "project": "lightstep" + }, + { + "download_count": 3116358, + "project": "azure-cli-core" + }, + { + "download_count": 3110959, + "project": "recommonmark" + }, + { + "download_count": 3095813, + "project": "pysqlite" + }, + { + "download_count": 3088484, + "project": "clickclick" + }, + { + "download_count": 3077942, + "project": "heapdict" + }, + { + "download_count": 3077928, + "project": "google-cloud-dataflow" + }, + { + "download_count": 3073863, + "project": "spotinst-agent" + }, + { + "download_count": 3073217, + "project": "analytics-python" + }, + { + "download_count": 3065872, + "project": "nose-timer" + }, + { + "download_count": 3064209, + "project": "rq" + }, + { + "download_count": 3062467, + "project": "wandb" + }, + { + "download_count": 3060966, + "project": "jsonfield" + }, + { + "download_count": 3050206, + "project": "pyinotify" + }, + { + "download_count": 3048455, + "project": "pygame" + }, + { + "download_count": 3043542, + "project": "intel-openmp" + }, + { + "download_count": 3042574, + "project": "zict" + }, + { + "download_count": 3040916, + "project": "pytest-split-tests" + }, + { + "download_count": 3036872, + "project": "pep8-naming" + }, + { + "download_count": 3029439, + "project": "ordered-set" + }, + { + "download_count": 3025549, + "project": "graphql-relay" + }, + { + "download_count": 3019093, + "project": "troposphere" + }, + { + "download_count": 3009250, + "project": "azure-kusto-data" + }, + { + "download_count": 3008025, + "project": "opencv-contrib-python" + }, + { + "download_count": 3003750, + "project": "requests-ntlm" + }, + { + "download_count": 3003003, + "project": "tb-nightly" + }, + { + "download_count": 2996766, + "project": "credstash" + }, + { + "download_count": 2989520, + "project": "flask-appbuilder" + }, + { + "download_count": 2980537, + "project": "plumbum" + }, + { + "download_count": 2973597, + "project": "pager" + }, + { + "download_count": 2967237, + "project": "schema" + }, + { + "download_count": 2965535, + "project": "mkl" + }, + { + "download_count": 2963377, + "project": "blessed" + }, + { + "download_count": 2953182, + "project": "datashape" + }, + { + "download_count": 2941855, + "project": "validate-email" + }, + { + "download_count": 2939744, + "project": "pylint-django" + }, + { + "download_count": 2938945, + "project": "webapp2" + }, + { + "download_count": 2936891, + "project": "livereload" + }, + { + "download_count": 2935073, + "project": "cvxopt" + }, + { + "download_count": 2934589, + "project": "cement" + }, + { + "download_count": 2931314, + "project": "tfx-bsl" + }, + { + "download_count": 2922270, + "project": "rospkg" + }, + { + "download_count": 2912677, + "project": "flaky" + }, + { + "download_count": 2909121, + "project": "filemagic" + }, + { + "download_count": 2902933, + "project": "msgpack-numpy" + }, + { + "download_count": 2895921, + "project": "uamqp" + }, + { + "download_count": 2895636, + "project": "accumulation-tree" + }, + { + "download_count": 2894366, + "project": "pyudorandom" + }, + { + "download_count": 2892673, + "project": "tdigest" + }, + { + "download_count": 2888615, + "project": "tensorflow-data-validation" + }, + { + "download_count": 2886531, + "project": "python-subunit" + }, + { + "download_count": 2878388, + "project": "gitdb" + }, + { + "download_count": 2874189, + "project": "python-novaclient" + }, + { + "download_count": 2857065, + "project": "asyncpg" + }, + { + "download_count": 2847295, + "project": "social-auth-core" + }, + { + "download_count": 2838600, + "project": "azure-cli-nspkg" + }, + { + "download_count": 2838428, + "project": "requestsexceptions" + }, + { + "download_count": 2834024, + "project": "filechunkio" + }, + { + "download_count": 2828975, + "project": "argon2-cffi" + }, + { + "download_count": 2822266, + "project": "beautifulsoup" + }, + { + "download_count": 2821979, + "project": "smmap" + }, + { + "download_count": 2819754, + "project": "django-multiselectfield" + }, + { + "download_count": 2815640, + "project": "drf-yasg" + }, + { + "download_count": 2813694, + "project": "boltons" + }, + { + "download_count": 2810269, + "project": "httpretty" + }, + { + "download_count": 2806190, + "project": "pyqt5" + }, + { + "download_count": 2802770, + "project": "hashids" + }, + { + "download_count": 2792830, + "project": "pdfrw" + }, + { + "download_count": 2792334, + "project": "flask-openid" + }, + { + "download_count": 2791834, + "project": "gapic-google-cloud-error-reporting-v1beta1" + }, + { + "download_count": 2790983, + "project": "cookiejar" + }, + { + "download_count": 2788259, + "project": "proto-google-cloud-error-reporting-v1beta1" + }, + { + "download_count": 2779755, + "project": "flask-marshmallow" + }, + { + "download_count": 2753420, + "project": "pyinstaller" + }, + { + "download_count": 2752867, + "project": "sqlalchemy-redshift" + }, + { + "download_count": 2749279, + "project": "python-logstash" + }, + { + "download_count": 2747409, + "project": "django-nose" + }, + { + "download_count": 2744486, + "project": "azure-cosmos" + }, + { + "download_count": 2738853, + "project": "verboselogs" + }, + { + "download_count": 2724920, + "project": "googlemaps" + }, + { + "download_count": 2722861, + "project": "social-auth-app-django" + }, + { + "download_count": 2706844, + "project": "async-generator" + }, + { + "download_count": 2704711, + "project": "funcy" + }, + { + "download_count": 2703274, + "project": "clint" + }, + { + "download_count": 2701212, + "project": "pytest-sugar" + }, + { + "download_count": 2699840, + "project": "django-timezone-field" + }, + { + "download_count": 2697450, + "project": "jaydebeapi" + }, + { + "download_count": 2693049, + "project": "brotlipy" + }, + { + "download_count": 2686973, + "project": "args" + }, + { + "download_count": 2683870, + "project": "vcrpy" + }, + { + "download_count": 2677855, + "project": "marshmallow-enum" + }, + { + "download_count": 2673327, + "project": "peewee" + }, + { + "download_count": 2670889, + "project": "osc-lib" + }, + { + "download_count": 2670484, + "project": "langdetect" + }, + { + "download_count": 2663228, + "project": "enum" + }, + { + "download_count": 2655265, + "project": "azure-cli-telemetry" + }, + { + "download_count": 2651881, + "project": "tables" + }, + { + "download_count": 2649758, + "project": "pastedeploy" + }, + { + "download_count": 2646163, + "project": "swagger-spec-validator" + }, + { + "download_count": 2644724, + "project": "tld" + }, + { + "download_count": 2642975, + "project": "kafka" + }, + { + "download_count": 2641270, + "project": "cchardet" + }, + { + "download_count": 2636532, + "project": "timezonefinder" + }, + { + "download_count": 2634114, + "project": "mongoengine" + }, + { + "download_count": 2615568, + "project": "python-crfsuite" + }, + { + "download_count": 2600491, + "project": "timeout-decorator" + }, + { + "download_count": 2592520, + "project": "rjsmin" + }, + { + "download_count": 2589546, + "project": "brunel" + }, + { + "download_count": 2585708, + "project": "autobahn" + }, + { + "download_count": 2584709, + "project": "webargs" + }, + { + "download_count": 2584111, + "project": "pyvirtualdisplay" + }, + { + "download_count": 2580140, + "project": "descartes" + }, + { + "download_count": 2551557, + "project": "cassandra-driver" + }, + { + "download_count": 2549257, + "project": "aws-requests-auth" + }, + { + "download_count": 2540875, + "project": "rope" + }, + { + "download_count": 2538617, + "project": "aiofiles" + }, + { + "download_count": 2532557, + "project": "pycountry-convert" + }, + { + "download_count": 2528277, + "project": "branca" + }, + { + "download_count": 2524264, + "project": "mechanize" + }, + { + "download_count": 2519234, + "project": "mysql-connector-python-rf" + }, + { + "download_count": 2517497, + "project": "pywebhdfs" + }, + { + "download_count": 2503645, + "project": "folium" + }, + { + "download_count": 2498263, + "project": "aiohttp-cors" + }, + { + "download_count": 2497590, + "project": "flask-httpauth" + }, + { + "download_count": 2495242, + "project": "django-ipware" + }, + { + "download_count": 2494397, + "project": "jupyterlab" + }, + { + "download_count": 2493673, + "project": "pybind11" + }, + { + "download_count": 2492477, + "project": "diff-match-patch" + }, + { + "download_count": 2491248, + "project": "jupyter-pip" + }, + { + "download_count": 2488659, + "project": "dpath" + }, + { + "download_count": 2488591, + "project": "marionette-driver" + }, + { + "download_count": 2484149, + "project": "dotnetcore2" + }, + { + "download_count": 2478052, + "project": "pythonwhois" + }, + { + "download_count": 2470002, + "project": "google-cloud-dataproc" + }, + { + "download_count": 2458163, + "project": "enum-compat" + }, + { + "download_count": 2455272, + "project": "awsebcli" + }, + { + "download_count": 2454145, + "project": "django-celery-beat" + }, + { + "download_count": 2453795, + "project": "rfc3987" + }, + { + "download_count": 2447431, + "project": "py-bcrypt" + }, + { + "download_count": 2442569, + "project": "python-gitlab" + }, + { + "download_count": 2439713, + "project": "translationstring" + }, + { + "download_count": 2439355, + "project": "yq" + }, + { + "download_count": 2435098, + "project": "pysnmp" + }, + { + "download_count": 2432521, + "project": "first" + }, + { + "download_count": 2429585, + "project": "hpack" + }, + { + "download_count": 2428283, + "project": "python-glanceclient" + }, + { + "download_count": 2422100, + "project": "venusian" + }, + { + "download_count": 2416591, + "project": "bitstring" + }, + { + "download_count": 2408841, + "project": "flake8-docstrings" + }, + { + "download_count": 2407495, + "project": "attrdict" + }, + { + "download_count": 2404932, + "project": "ws4py" + }, + { + "download_count": 2402857, + "project": "os-client-config" + }, + { + "download_count": 2401078, + "project": "locustio" + }, + { + "download_count": 2398281, + "project": "junit-xml" + }, + { + "download_count": 2395343, + "project": "mozversion" + }, + { + "download_count": 2395052, + "project": "azureml-dataprep" + }, + { + "download_count": 2390036, + "project": "sshpubkeys" + }, + { + "download_count": 2387469, + "project": "h2" + }, + { + "download_count": 2386629, + "project": "ansible-lint" + }, + { + "download_count": 2381639, + "project": "txaio" + }, + { + "download_count": 2380783, + "project": "wget" + }, + { + "download_count": 2375129, + "project": "pytest-rerunfailures" + }, + { + "download_count": 2371842, + "project": "oslo-log" + }, + { + "download_count": 2370221, + "project": "hyperframe" + }, + { + "download_count": 2364172, + "project": "python-openid" + }, + { + "download_count": 2357263, + "project": "flask-jwt-extended" + }, + { + "download_count": 2354920, + "project": "azureml-dataprep-native" + }, + { + "download_count": 2346411, + "project": "flake8-import-order" + }, + { + "download_count": 2334525, + "project": "pypandoc" + }, + { + "download_count": 2329461, + "project": "pysmi" + }, + { + "download_count": 2328121, + "project": "json-merge-patch" + }, + { + "download_count": 2325050, + "project": "falcon" + }, + { + "download_count": 2314962, + "project": "google-cloud-automl" + }, + { + "download_count": 2313548, + "project": "azure-kusto-ingest" + }, + { + "download_count": 2311574, + "project": "aioredis" + }, + { + "download_count": 2307595, + "project": "py-cpuinfo" + }, + { + "download_count": 2305070, + "project": "imbalanced-learn" + }, + { + "download_count": 2304296, + "project": "django-compressor" + }, + { + "download_count": 2304263, + "project": "memoized-property" + }, + { + "download_count": 2304114, + "project": "azureml-telemetry" + }, + { + "download_count": 2301461, + "project": "textblob" + }, + { + "download_count": 2299510, + "project": "snowflake-sqlalchemy" + }, + { + "download_count": 2287102, + "project": "schematics" + }, + { + "download_count": 2276329, + "project": "virtualenvwrapper" + }, + { + "download_count": 2272329, + "project": "aws-encryption-sdk" + }, + { + "download_count": 2272227, + "project": "opencensus" + }, + { + "download_count": 2267894, + "project": "django-allauth" + }, + { + "download_count": 2267072, + "project": "ibm-db" + }, + { + "download_count": 2258528, + "project": "python-cinderclient" + }, + { + "download_count": 2252312, + "project": "objectpath" + }, + { + "download_count": 2242218, + "project": "tf-estimator-nightly" + }, + { + "download_count": 2231619, + "project": "flask-compress" + }, + { + "download_count": 2224267, + "project": "azureml-pipeline-core" + }, + { + "download_count": 2221757, + "project": "connexion" + }, + { + "download_count": 2219740, + "project": "django-phonenumber-field" + }, + { + "download_count": 2214496, + "project": "warlock" + }, + { + "download_count": 2213923, + "project": "pyqt5-sip" + }, + { + "download_count": 2210221, + "project": "phonenumberslite" + }, + { + "download_count": 2209512, + "project": "oslo-context" + }, + { + "download_count": 2194021, + "project": "azure-cli-command-modules-nspkg" + }, + { + "download_count": 2185051, + "project": "pathlib-mate" + }, + { + "download_count": 2184347, + "project": "jsonref" + }, + { + "download_count": 2182555, + "project": "pytimeparse" + }, + { + "download_count": 2180696, + "project": "databricks-pypi2" + }, + { + "download_count": 2178821, + "project": "natsort" + }, + { + "download_count": 2176243, + "project": "ipaddr" + }, + { + "download_count": 2171374, + "project": "path-py" + }, + { + "download_count": 2170378, + "project": "azure-mgmt-hdinsight" + }, + { + "download_count": 2153590, + "project": "firebase-admin" + }, + { + "download_count": 2150903, + "project": "azureml-train-core" + }, + { + "download_count": 2148663, + "project": "pypyodbc" + }, + { + "download_count": 2145885, + "project": "uszipcode" + }, + { + "download_count": 2145383, + "project": "azureml-train-restclients-hyperdrive" + }, + { + "download_count": 2142865, + "project": "premailer" + }, + { + "download_count": 2137325, + "project": "h11" + }, + { + "download_count": 2132743, + "project": "pyformance" + }, + { + "download_count": 2132535, + "project": "shellescape" + }, + { + "download_count": 2130341, + "project": "django-import-export" + }, + { + "download_count": 2127667, + "project": "wsaccel" + }, + { + "download_count": 2126611, + "project": "django-js-asset" + }, + { + "download_count": 2126191, + "project": "snakebite" + }, + { + "download_count": 2124659, + "project": "wordcloud" + }, + { + "download_count": 2109163, + "project": "antlr4-python2-runtime" + }, + { + "download_count": 2099008, + "project": "naked" + }, + { + "download_count": 2098854, + "project": "jinja2-cli" + }, + { + "download_count": 2097764, + "project": "onnx" + }, + { + "download_count": 2081320, + "project": "pytesseract" + }, + { + "download_count": 2076961, + "project": "azureml-pipeline-steps" + }, + { + "download_count": 2073133, + "project": "flask-testing" + }, + { + "download_count": 2072907, + "project": "pytest-env" + }, + { + "download_count": 2072150, + "project": "django-widget-tweaks" + }, + { + "download_count": 2070728, + "project": "django-webpack-loader" + }, + { + "download_count": 2069730, + "project": "azureml-pipeline" + }, + { + "download_count": 2069241, + "project": "mrjob" + }, + { + "download_count": 2055974, + "project": "public" + }, + { + "download_count": 2053631, + "project": "python-whois" + }, + { + "download_count": 2052521, + "project": "safety" + }, + { + "download_count": 2038912, + "project": "azure-multiapi-storage" + }, + { + "download_count": 2038114, + "project": "google-cloud-tasks" + }, + { + "download_count": 2037912, + "project": "partd" + }, + { + "download_count": 2033573, + "project": "rcssmin" + }, + { + "download_count": 2032537, + "project": "uuid" + }, + { + "download_count": 2030463, + "project": "azureml-train" + }, + { + "download_count": 2028467, + "project": "vsts-cd-manager" + }, + { + "download_count": 2025661, + "project": "pyjks" + }, + { + "download_count": 2025022, + "project": "flake8-quotes" + }, + { + "download_count": 2022199, + "project": "python-socketio" + }, + { + "download_count": 2021994, + "project": "slimit" + }, + { + "download_count": 2021337, + "project": "pygeocoder" + }, + { + "download_count": 2020656, + "project": "javaobj-py3" + }, + { + "download_count": 2019345, + "project": "tweepy" + }, + { + "download_count": 2015977, + "project": "grpc-google-logging-v2" + }, + { + "download_count": 2013359, + "project": "twofish" + }, + { + "download_count": 2010440, + "project": "urwid" + }, + { + "download_count": 2008501, + "project": "pyathena" + }, + { + "download_count": 2004648, + "project": "azureml-sdk" + }, + { + "download_count": 2002586, + "project": "pdfminer-six" + }, + { + "download_count": 2000934, + "project": "grpc-google-pubsub-v1" + }, + { + "download_count": 1999960, + "project": "astral" + }, + { + "download_count": 1996773, + "project": "python-box" + }, + { + "download_count": 1992382, + "project": "python-openstackclient" + }, + { + "download_count": 1987939, + "project": "toposort" + }, + { + "download_count": 1984547, + "project": "httptools" + }, + { + "download_count": 1980989, + "project": "asynctest" + }, + { + "download_count": 1978811, + "project": "pycalverter" + }, + { + "download_count": 1975990, + "project": "django-mptt" + }, + { + "download_count": 1974600, + "project": "nameparser" + }, + { + "download_count": 1974472, + "project": "geomet" + }, + { + "download_count": 1974084, + "project": "rtree" + }, + { + "download_count": 1970886, + "project": "gax-google-logging-v2" + }, + { + "download_count": 1967604, + "project": "openapi-spec-validator" + }, + { + "download_count": 1966141, + "project": "simpleeval" + }, + { + "download_count": 1965371, + "project": "gax-google-pubsub-v1" + }, + { + "download_count": 1964155, + "project": "pympler" + }, + { + "download_count": 1957946, + "project": "pint" + }, + { + "download_count": 1954321, + "project": "django-celery-results" + }, + { + "download_count": 1950586, + "project": "oauth2" + }, + { + "download_count": 1947313, + "project": "collections-extended" + }, + { + "download_count": 1943588, + "project": "dparse" + }, + { + "download_count": 1937747, + "project": "azure-mgmt-botservice" + }, + { + "download_count": 1935888, + "project": "facebook-business" + }, + { + "download_count": 1932910, + "project": "django-localflavor" + }, + { + "download_count": 1931470, + "project": "slackweb" + }, + { + "download_count": 1919103, + "project": "azure-eventhub" + }, + { + "download_count": 1918652, + "project": "django-braces" + }, + { + "download_count": 1917375, + "project": "fake-useragent" + }, + { + "download_count": 1916732, + "project": "python-engineio" + }, + { + "download_count": 1904465, + "project": "django-countries" + }, + { + "download_count": 1901273, + "project": "ptvsd" + }, + { + "download_count": 1899393, + "project": "orderedmultidict" + }, + { + "download_count": 1897121, + "project": "jwcrypto" + }, + { + "download_count": 1895022, + "project": "azure-mgmt-security" + }, + { + "download_count": 1893082, + "project": "awacs" + }, + { + "download_count": 1889385, + "project": "azure-functions-devops-build" + }, + { + "download_count": 1884376, + "project": "locket" + }, + { + "download_count": 1882404, + "project": "ctutlz" + }, + { + "download_count": 1875062, + "project": "snapshottest" + }, + { + "download_count": 1874184, + "project": "pdfkit" + }, + { + "download_count": 1870591, + "project": "scapy" + }, + { + "download_count": 1869037, + "project": "opencensus-context" + }, + { + "download_count": 1862753, + "project": "flask-mail" + }, + { + "download_count": 1860985, + "project": "intervaltree" + }, + { + "download_count": 1856012, + "project": "azure-mgmt-sqlvirtualmachine" + }, + { + "download_count": 1853788, + "project": "azure-mgmt-kusto" + }, + { + "download_count": 1853245, + "project": "luigi" + }, + { + "download_count": 1852083, + "project": "pylru" + }, + { + "download_count": 1848356, + "project": "sklearn-pandas" + }, + { + "download_count": 1846838, + "project": "pydantic" + }, + { + "download_count": 1845633, + "project": "email-validator" + }, + { + "download_count": 1844376, + "project": "pyquery" + }, + { + "download_count": 1841139, + "project": "django-oauth-toolkit" + }, + { + "download_count": 1839835, + "project": "memory-profiler" + }, + { + "download_count": 1839825, + "project": "jupyterlab-server" + }, + { + "download_count": 1835726, + "project": "sqlalchemy-migrate" + }, + { + "download_count": 1832053, + "project": "retry-decorator" + }, + { + "download_count": 1830194, + "project": "robotframework-seleniumlibrary" + }, + { + "download_count": 1825914, + "project": "koalas" + }, + { + "download_count": 1822090, + "project": "amazon-dax-client" + }, + { + "download_count": 1821759, + "project": "python-nvd3" + }, + { + "download_count": 1818147, + "project": "utlz" + }, + { + "download_count": 1813328, + "project": "requests-kerberos" + }, + { + "download_count": 1803051, + "project": "ftfy" + }, + { + "download_count": 1798001, + "project": "crypto" + }, + { + "download_count": 1792237, + "project": "distlib" + }, + { + "download_count": 1791068, + "project": "wordsegment" + }, + { + "download_count": 1790178, + "project": "django-taggit" + }, + { + "download_count": 1783750, + "project": "suds" + }, + { + "download_count": 1782898, + "project": "fabric3" + }, + { + "download_count": 1782756, + "project": "socksipy-branch" + }, + { + "download_count": 1778530, + "project": "webcolors" + }, + { + "download_count": 1773769, + "project": "orderedset" + }, + { + "download_count": 1770892, + "project": "mxnet" + }, + { + "download_count": 1767740, + "project": "mixpanel" + }, + { + "download_count": 1766756, + "project": "python-stdnum" + }, + { + "download_count": 1765611, + "project": "polib" + }, + { + "download_count": 1762017, + "project": "pysaml2" + }, + { + "download_count": 1760938, + "project": "pywinpty" + }, + { + "download_count": 1760472, + "project": "curlify" + }, + { + "download_count": 1759532, + "project": "dulwich" + }, + { + "download_count": 1755858, + "project": "tzwhere" + }, + { + "download_count": 1753697, + "project": "pyotp" + }, + { + "download_count": 1752520, + "project": "dropbox" + }, + { + "download_count": 1748789, + "project": "thriftpy" + }, + { + "download_count": 1744492, + "project": "yattag" + }, + { + "download_count": 1744207, + "project": "xxhash" + }, + { + "download_count": 1740901, + "project": "colorlover" + }, + { + "download_count": 1740812, + "project": "mkdocs" + }, + { + "download_count": 1723311, + "project": "iso3166" + }, + { + "download_count": 1722795, + "project": "gcs-oauth2-boto-plugin" + }, + { + "download_count": 1720946, + "project": "protorpc" + }, + { + "download_count": 1717972, + "project": "sentinels" + }, + { + "download_count": 1716396, + "project": "pykalman" + }, + { + "download_count": 1715123, + "project": "pkgconfig" + }, + { + "download_count": 1714704, + "project": "geohash" + }, + { + "download_count": 1712854, + "project": "google-cloud-dlp" + }, + { + "download_count": 1711556, + "project": "resampy" + }, + { + "download_count": 1705164, + "project": "request" + }, + { + "download_count": 1696070, + "project": "usaddress" + }, + { + "download_count": 1694720, + "project": "superlance" + }, + { + "download_count": 1692010, + "project": "librato-metrics" + }, + { + "download_count": 1690356, + "project": "flask-oauthlib" + }, + { + "download_count": 1686047, + "project": "google-cloud-texttospeech" + }, + { + "download_count": 1677666, + "project": "post" + }, + { + "download_count": 1675876, + "project": "get" + }, + { + "download_count": 1669578, + "project": "daphne" + }, + { + "download_count": 1665895, + "project": "librosa" + }, + { + "download_count": 1665557, + "project": "pyelftools" + }, + { + "download_count": 1665384, + "project": "query-string" + }, + { + "download_count": 1663244, + "project": "pywinrm" + }, + { + "download_count": 1660863, + "project": "pyreadline" + }, + { + "download_count": 1657504, + "project": "ez-setup" + }, + { + "download_count": 1656438, + "project": "channels" + }, + { + "download_count": 1640299, + "project": "node-semver" + }, + { + "download_count": 1638276, + "project": "tensorboardx" + }, + { + "download_count": 1631659, + "project": "htmlmin" + }, + { + "download_count": 1625146, + "project": "tensorflow-datasets" + }, + { + "download_count": 1624914, + "project": "audioread" + }, + { + "download_count": 1621703, + "project": "couchdb" + }, + { + "download_count": 1618223, + "project": "google-reauth" + }, + { + "download_count": 1616648, + "project": "google-cloud-redis" + }, + { + "download_count": 1615335, + "project": "autograd" + }, + { + "download_count": 1609038, + "project": "rollbar" + }, + { + "download_count": 1608426, + "project": "pyu2f" + }, + { + "download_count": 1603406, + "project": "iptools" + }, + { + "download_count": 1601716, + "project": "compatibility-lib" + }, + { + "download_count": 1599718, + "project": "google-cloud-asset" + }, + { + "download_count": 1599709, + "project": "azure-mgmt-privatedns" + }, + { + "download_count": 1596670, + "project": "python-decouple" + }, + { + "download_count": 1592734, + "project": "oslo-concurrency" + }, + { + "download_count": 1590149, + "project": "mongomock" + }, + { + "download_count": 1590067, + "project": "fluent-logger" + }, + { + "download_count": 1589332, + "project": "pygrok" + }, + { + "download_count": 1586920, + "project": "rauth" + }, + { + "download_count": 1585024, + "project": "probableparsing" + }, + { + "download_count": 1580625, + "project": "dominate" + }, + { + "download_count": 1577725, + "project": "pykerberos" + }, + { + "download_count": 1577380, + "project": "pyramid" + }, + { + "download_count": 1575279, + "project": "flask-cache" + }, + { + "download_count": 1575048, + "project": "pytest-cache" + }, + { + "download_count": 1574450, + "project": "pyee" + }, + { + "download_count": 1572539, + "project": "bingads" + }, + { + "download_count": 1569151, + "project": "appium-python-client" + }, + { + "download_count": 1567159, + "project": "pygam" + }, + { + "download_count": 1564680, + "project": "fysom" + }, + { + "download_count": 1563117, + "project": "tempita" + }, + { + "download_count": 1561979, + "project": "pywin32-ctypes" + }, + { + "download_count": 1561323, + "project": "diskcache" + }, + { + "download_count": 1558407, + "project": "pyhs2" + }, + { + "download_count": 1556417, + "project": "frozendict" + }, + { + "download_count": 1556392, + "project": "immutables" + }, + { + "download_count": 1550611, + "project": "python-neutronclient" + }, + { + "download_count": 1549879, + "project": "gspread-dataframe" + }, + { + "download_count": 1545947, + "project": "pyro4" + }, + { + "download_count": 1539049, + "project": "vertica-python" + }, + { + "download_count": 1538249, + "project": "google-cloud-securitycenter" + }, + { + "download_count": 1532048, + "project": "m3u8" + }, + { + "download_count": 1530674, + "project": "serpent" + }, + { + "download_count": 1527389, + "project": "aiobotocore" + }, + { + "download_count": 1526900, + "project": "django-reversion" + }, + { + "download_count": 1525911, + "project": "tox-travis" + }, + { + "download_count": 1524549, + "project": "pluginbase" + }, + { + "download_count": 1523680, + "project": "google-cloud-iot" + }, + { + "download_count": 1523139, + "project": "pykafka" + }, + { + "download_count": 1522621, + "project": "anyconfig" + }, + { + "download_count": 1520539, + "project": "pyjwkest" + }, + { + "download_count": 1520176, + "project": "django-formtools" + }, + { + "download_count": 1519701, + "project": "vowpalwabbit" + }, + { + "download_count": 1518864, + "project": "gprof2dot" + }, + { + "download_count": 1517841, + "project": "presto-python-client" + }, + { + "download_count": 1515284, + "project": "delorean" + }, + { + "download_count": 1514817, + "project": "json5" + }, + { + "download_count": 1511462, + "project": "num2words" + }, + { + "download_count": 1507178, + "project": "pylibmc" + }, + { + "download_count": 1505966, + "project": "httpagentparser" + }, + { + "download_count": 1504331, + "project": "drf-nested-routers" + }, + { + "download_count": 1504075, + "project": "icalendar" + }, + { + "download_count": 1503765, + "project": "google-cloud-websecurityscanner" + }, + { + "download_count": 1501399, + "project": "lru-dict" + }, + { + "download_count": 1496923, + "project": "cloudant" + }, + { + "download_count": 1493340, + "project": "keyrings-alt" + }, + { + "download_count": 1492739, + "project": "cattrs" + }, + { + "download_count": 1491297, + "project": "model-mommy" + }, + { + "download_count": 1490933, + "project": "jenkinsapi" + }, + { + "download_count": 1488901, + "project": "workalendar" + }, + { + "download_count": 1486683, + "project": "lifetimes" + }, + { + "download_count": 1484449, + "project": "sseclient-py" + }, + { + "download_count": 1481519, + "project": "python-etcd" + }, + { + "download_count": 1480386, + "project": "testinfra" + }, + { + "download_count": 1479219, + "project": "sentencepiece" + }, + { + "download_count": 1479194, + "project": "scikit-optimize" + }, + { + "download_count": 1477712, + "project": "flask-responses" + }, + { + "download_count": 1468207, + "project": "django-polymorphic" + }, + { + "download_count": 1467601, + "project": "azure-mgmt-deploymentmanager" + }, + { + "download_count": 1464092, + "project": "routes" + }, + { + "download_count": 1463152, + "project": "editdistance" + }, + { + "download_count": 1460523, + "project": "bugsnag" + }, + { + "download_count": 1453426, + "project": "conan" + }, + { + "download_count": 1449766, + "project": "autowrapt" + }, + { + "download_count": 1448235, + "project": "fasttext" + }, + { + "download_count": 1445709, + "project": "django-rest-auth" + }, + { + "download_count": 1444092, + "project": "catboost" + }, + { + "download_count": 1442809, + "project": "pydash" + }, + { + "download_count": 1442503, + "project": "libsass" + }, + { + "download_count": 1441996, + "project": "importlib" + }, + { + "download_count": 1440920, + "project": "pytest-flask" + }, + { + "download_count": 1440731, + "project": "django-simple-history" + }, + { + "download_count": 1439129, + "project": "django-picklefield" + }, + { + "download_count": 1437255, + "project": "trollius" + }, + { + "download_count": 1433413, + "project": "ml-metadata" + }, + { + "download_count": 1428493, + "project": "port-for" + }, + { + "download_count": 1426881, + "project": "flake8-bugbear" + }, + { + "download_count": 1425070, + "project": "python-nmap" + }, + { + "download_count": 1424275, + "project": "newlinejson" + }, + { + "download_count": 1423507, + "project": "pytest-benchmark" + }, + { + "download_count": 1422061, + "project": "hacking" + }, + { + "download_count": 1420833, + "project": "ratelim" + }, + { + "download_count": 1416683, + "project": "rdflib" + }, + { + "download_count": 1415247, + "project": "ninja" + }, + { + "download_count": 1413811, + "project": "geocoder" + }, + { + "download_count": 1413778, + "project": "parsimonious" + }, + { + "download_count": 1409060, + "project": "xmlsec" + }, + { + "download_count": 1407612, + "project": "jsonpath-ng" + }, + { + "download_count": 1404958, + "project": "authy" + }, + { + "download_count": 1399670, + "project": "python3-saml" + }, + { + "download_count": 1399023, + "project": "django-ratelimit" + }, + { + "download_count": 1398229, + "project": "watson-machine-learning-client" + }, + { + "download_count": 1397882, + "project": "motor" + }, + { + "download_count": 1397503, + "project": "pyusb" + }, + { + "download_count": 1393071, + "project": "eli5" + }, + { + "download_count": 1392124, + "project": "facebook-sdk" + }, + { + "download_count": 1391265, + "project": "py-zabbix" + }, + { + "download_count": 1390039, + "project": "threatconnect" + }, + { + "download_count": 1389772, + "project": "github3-py" + }, + { + "download_count": 1384962, + "project": "dash-renderer" + }, + { + "download_count": 1384373, + "project": "pyzipcode3" + }, + { + "download_count": 1384208, + "project": "transaction" + }, + { + "download_count": 1377748, + "project": "dash" + }, + { + "download_count": 1377392, + "project": "contextvars" + }, + { + "download_count": 1375491, + "project": "pyppeteer" + }, + { + "download_count": 1374745, + "project": "imutils" + }, + { + "download_count": 1373022, + "project": "predicthq" + }, + { + "download_count": 1371449, + "project": "furl" + }, + { + "download_count": 1370079, + "project": "graypy" + }, + { + "download_count": 1368582, + "project": "ipy" + }, + { + "download_count": 1365609, + "project": "apache-libcloud" + }, + { + "download_count": 1363504, + "project": "langid" + }, + { + "download_count": 1362248, + "project": "happybase" + }, + { + "download_count": 1362080, + "project": "wand" + }, + { + "download_count": 1359167, + "project": "dash-core-components" + }, + { + "download_count": 1355835, + "project": "teamcity-messages" + }, + { + "download_count": 1353938, + "project": "django-treebeard" + }, + { + "download_count": 1353094, + "project": "bottleneck" + }, + { + "download_count": 1347193, + "project": "pipdeptree" + }, + { + "download_count": 1346804, + "project": "flask-socketio" + }, + { + "download_count": 1345086, + "project": "feather-format" + }, + { + "download_count": 1345015, + "project": "pyshp" + }, + { + "download_count": 1340081, + "project": "cerberus-python-client" + }, + { + "download_count": 1339531, + "project": "pytest-ordering" + }, + { + "download_count": 1337974, + "project": "dateutils" + }, + { + "download_count": 1337690, + "project": "ccy" + }, + { + "download_count": 1336766, + "project": "ec2-metadata" + }, + { + "download_count": 1336028, + "project": "gevent-websocket" + }, + { + "download_count": 1333439, + "project": "pyenchant" + }, + { + "download_count": 1333043, + "project": "pykwalify" + }, + { + "download_count": 1331164, + "project": "ptable" + }, + { + "download_count": 1324399, + "project": "dash-html-components" + }, + { + "download_count": 1323369, + "project": "wmctrl" + }, + { + "download_count": 1322854, + "project": "markdown2" + }, + { + "download_count": 1320709, + "project": "fancycompleter" + }, + { + "download_count": 1320502, + "project": "genson" + }, + { + "download_count": 1317756, + "project": "pyhocon" + }, + { + "download_count": 1317236, + "project": "pdbpp" + }, + { + "download_count": 1316522, + "project": "crc16" + }, + { + "download_count": 1310312, + "project": "gnupg" + }, + { + "download_count": 1306934, + "project": "palettable" + }, + { + "download_count": 1306842, + "project": "fake-factory" + }, + { + "download_count": 1302234, + "project": "bson" + }, + { + "download_count": 1293536, + "project": "jsonpath-rw-ext" + }, + { + "download_count": 1291830, + "project": "graphene-django" + }, + { + "download_count": 1288532, + "project": "elasticsearch-curator" + }, + { + "download_count": 1287159, + "project": "agate" + }, + { + "download_count": 1286419, + "project": "pyluach" + }, + { + "download_count": 1276264, + "project": "pytoml" + }, + { + "download_count": 1275859, + "project": "xhtml2pdf" + }, + { + "download_count": 1275165, + "project": "mandrill" + }, + { + "download_count": 1274724, + "project": "aws-sam-cli" + }, + { + "download_count": 1274476, + "project": "aws-lambda-builders" + }, + { + "download_count": 1274226, + "project": "algoliasearch" + }, + { + "download_count": 1273921, + "project": "hupper" + }, + { + "download_count": 1261688, + "project": "testscenarios" + }, + { + "download_count": 1259972, + "project": "cufflinks" + }, + { + "download_count": 1258105, + "project": "signalfx" + }, + { + "download_count": 1257144, + "project": "moviepy" + }, + { + "download_count": 1255798, + "project": "objgraph" + }, + { + "download_count": 1252062, + "project": "chevron" + }, + { + "download_count": 1235194, + "project": "pdf2image" + }, + { + "download_count": 1234160, + "project": "uvicorn" + }, + { + "download_count": 1233486, + "project": "tlslite" + }, + { + "download_count": 1231831, + "project": "pybase64" + }, + { + "download_count": 1230654, + "project": "createsend" + }, + { + "download_count": 1230170, + "project": "gql" + }, + { + "download_count": 1230039, + "project": "imagehash" + }, + { + "download_count": 1228048, + "project": "azureml-defaults" + }, + { + "download_count": 1227477, + "project": "azure-mgmt-imagebuilder" + }, + { + "download_count": 1226165, + "project": "serverlessrepo" + }, + { + "download_count": 1221206, + "project": "pytest-watch" + }, + { + "download_count": 1220741, + "project": "google-cloud-bigquery-storage" + }, + { + "download_count": 1218278, + "project": "django-ses" + }, + { + "download_count": 1217113, + "project": "luminol" + }, + { + "download_count": 1213653, + "project": "pyaes" + }, + { + "download_count": 1213392, + "project": "flask-mongoalchemy" + }, + { + "download_count": 1212483, + "project": "flake8-print" + }, + { + "download_count": 1208573, + "project": "resource" + }, + { + "download_count": 1207795, + "project": "stemming" + }, + { + "download_count": 1206452, + "project": "python-easyconfig" + }, + { + "download_count": 1206109, + "project": "jsonform" + }, + { + "download_count": 1205968, + "project": "jsonsir" + }, + { + "download_count": 1202856, + "project": "logbook" + }, + { + "download_count": 1198077, + "project": "import-from-github-com" + }, + { + "download_count": 1195471, + "project": "mss" + }, + { + "download_count": 1195405, + "project": "robotframework-requests" + }, + { + "download_count": 1194828, + "project": "nose2" + }, + { + "download_count": 1194314, + "project": "fusepy" + }, + { + "download_count": 1193288, + "project": "cmake" + }, + { + "download_count": 1192641, + "project": "httpbin" + }, + { + "download_count": 1190084, + "project": "graphql-server-core" + }, + { + "download_count": 1189375, + "project": "stestr" + }, + { + "download_count": 1188229, + "project": "recordclass" + }, + { + "download_count": 1186101, + "project": "django-bootstrap4" + }, + { + "download_count": 1181472, + "project": "tree-format" + }, + { + "download_count": 1180564, + "project": "django-guardian" + }, + { + "download_count": 1180286, + "project": "django-celery" + }, + { + "download_count": 1179046, + "project": "publicsuffix" + }, + { + "download_count": 1178235, + "project": "astropy" + }, + { + "download_count": 1177835, + "project": "konlpy" + }, + { + "download_count": 1174516, + "project": "threadloop" + }, + { + "download_count": 1174367, + "project": "radon" + }, + { + "download_count": 1172767, + "project": "azure-cli-profile" + }, + { + "download_count": 1172663, + "project": "jieba" + }, + { + "download_count": 1172300, + "project": "pyfakefs" + }, + { + "download_count": 1172278, + "project": "namedlist" + }, + { + "download_count": 1171988, + "project": "pubnub" + }, + { + "download_count": 1170778, + "project": "flasgger" + }, + { + "download_count": 1168270, + "project": "pymeeus" + }, + { + "download_count": 1164230, + "project": "transitions" + }, + { + "download_count": 1163775, + "project": "visitor" + }, + { + "download_count": 1161777, + "project": "django-redis-cache" + }, + { + "download_count": 1161264, + "project": "lmdb" + }, + { + "download_count": 1160572, + "project": "json-logging-py" + }, + { + "download_count": 1159436, + "project": "protobuf3-to-dict" + }, + { + "download_count": 1153262, + "project": "patch" + }, + { + "download_count": 1152875, + "project": "horovod" + }, + { + "download_count": 1152461, + "project": "pyzabbix" + }, + { + "download_count": 1148339, + "project": "tailer" + }, + { + "download_count": 1146680, + "project": "azure-cli-resource" + }, + { + "download_count": 1145300, + "project": "etcd3" + }, + { + "download_count": 1143148, + "project": "azure-cli-iot" + }, + { + "download_count": 1143069, + "project": "djangorestframework-xml" + }, + { + "download_count": 1139676, + "project": "logutils" + }, + { + "download_count": 1138222, + "project": "javaproperties" + }, + { + "download_count": 1137231, + "project": "azure-cli-extension" + }, + { + "download_count": 1137033, + "project": "python-telegram-bot" + }, + { + "download_count": 1135140, + "project": "platformio" + }, + { + "download_count": 1134846, + "project": "xvfbwrapper" + }, + { + "download_count": 1133241, + "project": "pytest-pythonpath" + }, + { + "download_count": 1129508, + "project": "google-cloud-iam" + }, + { + "download_count": 1129177, + "project": "pydrive" + }, + { + "download_count": 1128895, + "project": "minio" + }, + { + "download_count": 1128310, + "project": "python-heatclient" + }, + { + "download_count": 1127447, + "project": "azure-cli-dls" + }, + { + "download_count": 1127383, + "project": "demjson" + }, + { + "download_count": 1126928, + "project": "pygal" + }, + { + "download_count": 1123556, + "project": "azure-cli-role" + }, + { + "download_count": 1123087, + "project": "azure-cli-monitor" + }, + { + "download_count": 1121560, + "project": "azure-cli-storage" + }, + { + "download_count": 1121500, + "project": "azure-cli-sql" + }, + { + "download_count": 1121354, + "project": "azure-cli-keyvault" + }, + { + "download_count": 1121021, + "project": "azure-cli-network" + }, + { + "download_count": 1120955, + "project": "azure-cli-interactive" + }, + { + "download_count": 1120732, + "project": "azure-cli-container" + }, + { + "download_count": 1120661, + "project": "azure-cli-appservice" + }, + { + "download_count": 1120619, + "project": "azure-cli-lab" + }, + { + "download_count": 1120596, + "project": "pydub" + }, + { + "download_count": 1120448, + "project": "azure-cli-acr" + }, + { + "download_count": 1120440, + "project": "pem" + }, + { + "download_count": 1119943, + "project": "azure-cli-acs" + }, + { + "download_count": 1119731, + "project": "azure-cli-cognitiveservices" + }, + { + "download_count": 1118667, + "project": "azure-cli-batch" + }, + { + "download_count": 1118554, + "project": "azure-cli-rdbms" + }, + { + "download_count": 1118179, + "project": "dumbyaml" + }, + { + "download_count": 1118164, + "project": "azure-cli-cosmosdb" + }, + { + "download_count": 1117990, + "project": "azure-cli-dla" + }, + { + "download_count": 1117671, + "project": "azure-cli-vm" + }, + { + "download_count": 1117663, + "project": "graphite-web" + }, + { + "download_count": 1117633, + "project": "easy-thumbnails" + }, + { + "download_count": 1117629, + "project": "ggplot" + }, + { + "download_count": 1117326, + "project": "ncclient" + }, + { + "download_count": 1115734, + "project": "azure-cli-cdn" + }, + { + "download_count": 1115095, + "project": "ipyparallel" + }, + { + "download_count": 1114052, + "project": "uritemplate-py" + }, + { + "download_count": 1113849, + "project": "azure-cli-servicefabric" + }, + { + "download_count": 1112830, + "project": "azure-cli-batchai" + }, + { + "download_count": 1112111, + "project": "colander" + }, + { + "download_count": 1112004, + "project": "libhoney" + }, + { + "download_count": 1111031, + "project": "robotframework-selenium2library" + }, + { + "download_count": 1110924, + "project": "azure-cli-reservations" + }, + { + "download_count": 1110554, + "project": "selectors34" + }, + { + "download_count": 1109781, + "project": "python-redis-lock" + }, + { + "download_count": 1109474, + "project": "django-waffle" + }, + { + "download_count": 1109341, + "project": "construct" + }, + { + "download_count": 1107612, + "project": "pyhcl" + }, + { + "download_count": 1107023, + "project": "allure-python-commons" + }, + { + "download_count": 1106855, + "project": "opencv-python-headless" + }, + { + "download_count": 1104732, + "project": "nibabel" + }, + { + "download_count": 1104394, + "project": "ntplib" + }, + { + "download_count": 1101855, + "project": "gsutil" + }, + { + "download_count": 1099271, + "project": "python-redis" + }, + { + "download_count": 1099171, + "project": "honeycomb-beeline" + }, + { + "download_count": 1095266, + "project": "google-cloud-profiler" + }, + { + "download_count": 1094548, + "project": "djangorestframework-csv" + }, + { + "download_count": 1093507, + "project": "imageio-ffmpeg" + }, + { + "download_count": 1093006, + "project": "rpyc" + }, + { + "download_count": 1092127, + "project": "databricks-api" + }, + { + "download_count": 1091012, + "project": "django-otp" + }, + { + "download_count": 1089786, + "project": "atlassian-jwt-auth" + }, + { + "download_count": 1089668, + "project": "pyscreeze" + }, + { + "download_count": 1088119, + "project": "jsonlines" + }, + { + "download_count": 1087785, + "project": "google-cloud-scheduler" + }, + { + "download_count": 1086837, + "project": "py-moneyed" + }, + { + "download_count": 1086168, + "project": "prospector" + }, + { + "download_count": 1084845, + "project": "pyfcm" + }, + { + "download_count": 1084588, + "project": "leather" + }, + { + "download_count": 1083842, + "project": "flask-session" + }, + { + "download_count": 1083772, + "project": "flask-principal" + }, + { + "download_count": 1081797, + "project": "azure-mgmt-managedservices" + }, + { + "download_count": 1080061, + "project": "zope-sqlalchemy" + }, + { + "download_count": 1079118, + "project": "wikipedia" + }, + { + "download_count": 1078680, + "project": "pyopengl" + }, + { + "download_count": 1077281, + "project": "django-anymail" + }, + { + "download_count": 1075981, + "project": "cov-core" + }, + { + "download_count": 1075897, + "project": "azure-mgmt-netapp" + }, + { + "download_count": 1074798, + "project": "pytest-flake8" + }, + { + "download_count": 1071887, + "project": "requests-cache" + }, + { + "download_count": 1071617, + "project": "plaster-pastedeploy" + }, + { + "download_count": 1071057, + "project": "boxsdk" + }, + { + "download_count": 1070181, + "project": "numpydoc" + }, + { + "download_count": 1069130, + "project": "dodgy" + }, + { + "download_count": 1067802, + "project": "sphinxcontrib-httpdomain" + }, + { + "download_count": 1067667, + "project": "git-url-parse" + }, + { + "download_count": 1065839, + "project": "restructuredtext-lint" + }, + { + "download_count": 1063327, + "project": "django-storages-redux" + }, + { + "download_count": 1061635, + "project": "h2o-pysparkling-2-4" + }, + { + "download_count": 1060942, + "project": "flatbuffers" + }, + { + "download_count": 1059650, + "project": "webassets" + }, + { + "download_count": 1057175, + "project": "gdata" + }, + { + "download_count": 1055836, + "project": "pytest-pep8" + }, + { + "download_count": 1054787, + "project": "setoptconf" + }, + { + "download_count": 1053777, + "project": "flask-graphql" + }, + { + "download_count": 1051978, + "project": "lark-parser" + }, + { + "download_count": 1046552, + "project": "google-cloud-datacatalog" + }, + { + "download_count": 1045356, + "project": "requirements-detector" + }, + { + "download_count": 1043870, + "project": "google-cloud-talent" + }, + { + "download_count": 1043546, + "project": "utils" + }, + { + "download_count": 1043075, + "project": "google-cloud-datalabeling" + }, + { + "download_count": 1042791, + "project": "django-mailgun" + }, + { + "download_count": 1041833, + "project": "google-cloud-os-login" + }, + { + "download_count": 1040789, + "project": "plaster" + }, + { + "download_count": 1040645, + "project": "google-cloud-webrisk" + }, + { + "download_count": 1040329, + "project": "beaker" + }, + { + "download_count": 1039677, + "project": "django-fsm" + }, + { + "download_count": 1039618, + "project": "grpcio-health-checking" + }, + { + "download_count": 1039569, + "project": "flask-apispec" + }, + { + "download_count": 1037586, + "project": "flake8-comprehensions" + }, + { + "download_count": 1036471, + "project": "pylint-flask" + }, + { + "download_count": 1036185, + "project": "pygerduty" + }, + { + "download_count": 1036096, + "project": "pudb" + }, + { + "download_count": 1036044, + "project": "biopython" + }, + { + "download_count": 1035148, + "project": "brewer2mpl" + }, + { + "download_count": 1034346, + "project": "rpy2" + }, + { + "download_count": 1033958, + "project": "dash-table" + }, + { + "download_count": 1033827, + "project": "base58" + }, + { + "download_count": 1033818, + "project": "proto-google-cloud-pubsub-v1" + }, + { + "download_count": 1033419, + "project": "maxminddb-geolite2" + }, + { + "download_count": 1032216, + "project": "bravado-core" + }, + { + "download_count": 1031978, + "project": "starlette" + }, + { + "download_count": 1031797, + "project": "cftime" + }, + { + "download_count": 1030527, + "project": "papermill" + }, + { + "download_count": 1030356, + "project": "pytest-aiohttp" + }, + { + "download_count": 1028784, + "project": "neotime" + }, + { + "download_count": 1028024, + "project": "django-grappelli" + }, + { + "download_count": 1026556, + "project": "csvkit" + }, + { + "download_count": 1026453, + "project": "azure-mgmt-appconfiguration" + }, + { + "download_count": 1025532, + "project": "mando" + }, + { + "download_count": 1025061, + "project": "python-pptx" + }, + { + "download_count": 1024849, + "project": "futurist" + }, + { + "download_count": 1024564, + "project": "tfx" + }, + { + "download_count": 1023148, + "project": "shyaml" + }, + { + "download_count": 1020560, + "project": "whoosh" + }, + { + "download_count": 1019249, + "project": "netcdf4" + }, + { + "download_count": 1018441, + "project": "braintree" + }, + { + "download_count": 1017498, + "project": "pylint-celery" + }, + { + "download_count": 1015935, + "project": "pyautogui" + }, + { + "download_count": 1015329, + "project": "uritools" + }, + { + "download_count": 1014941, + "project": "openshift" + }, + { + "download_count": 1014682, + "project": "jinjasql" + }, + { + "download_count": 1011470, + "project": "bunch" + }, + { + "download_count": 1011345, + "project": "tribool" + }, + { + "download_count": 1010041, + "project": "shade" + }, + { + "download_count": 1009923, + "project": "geoalchemy2" + }, + { + "download_count": 1007914, + "project": "stups-tokens" + }, + { + "download_count": 1007728, + "project": "django-health-check" + }, + { + "download_count": 1006511, + "project": "ansiwrap" + }, + { + "download_count": 1005973, + "project": "djangorestframework-simplejwt" + }, + { + "download_count": 1004447, + "project": "repoze-who" + }, + { + "download_count": 1003341, + "project": "u-msgpack-python" + }, + { + "download_count": 1002884, + "project": "psycogreen" + }, + { + "download_count": 1002180, + "project": "pyroute2" + }, + { + "download_count": 997107, + "project": "impyla" + }, + { + "download_count": 997057, + "project": "functools" + }, + { + "download_count": 995470, + "project": "rq-scheduler" + }, + { + "download_count": 995174, + "project": "xarray" + }, + { + "download_count": 995018, + "project": "dictionaries" + }, + { + "download_count": 995017, + "project": "django-haystack" + }, + { + "download_count": 992160, + "project": "check-manifest" + }, + { + "download_count": 990507, + "project": "python-rapidjson" + }, + { + "download_count": 989611, + "project": "py-vapid" + }, + { + "download_count": 989525, + "project": "textwrap3" + }, + { + "download_count": 988451, + "project": "soundfile" + }, + { + "download_count": 987924, + "project": "python-string-utils" + }, + { + "download_count": 987136, + "project": "pywinauto" + }, + { + "download_count": 985267, + "project": "oslo-db" + }, + { + "download_count": 984514, + "project": "xmlrunner" + }, + { + "download_count": 983293, + "project": "pymdown-extensions" + }, + { + "download_count": 982272, + "project": "sphinx-autobuild" + }, + { + "download_count": 981717, + "project": "django-ckeditor" + }, + { + "download_count": 979521, + "project": "sorl-thumbnail" + }, + { + "download_count": 979220, + "project": "pysmb" + }, + { + "download_count": 978290, + "project": "pymsgbox" + }, + { + "download_count": 977363, + "project": "gapic-google-cloud-pubsub-v1" + }, + { + "download_count": 977316, + "project": "flake8-isort" + }, + { + "download_count": 976939, + "project": "tensorflow-probability" + }, + { + "download_count": 976069, + "project": "oslo-messaging" + }, + { + "download_count": 975772, + "project": "python-coveralls" + }, + { + "download_count": 975418, + "project": "flex" + }, + { + "download_count": 973597, + "project": "seleniumbase" + }, + { + "download_count": 972851, + "project": "flake8-commas" + }, + { + "download_count": 972025, + "project": "dirq" + }, + { + "download_count": 971725, + "project": "glfw" + }, + { + "download_count": 968128, + "project": "trains" + }, + { + "download_count": 967325, + "project": "hjson" + }, + { + "download_count": 966886, + "project": "fs" + }, + { + "download_count": 965395, + "project": "pyahocorasick" + }, + { + "download_count": 965068, + "project": "pytest-repeat" + }, + { + "download_count": 964628, + "project": "swagger-ui-bundle" + }, + { + "download_count": 964597, + "project": "typing-inspect" + }, + { + "download_count": 964448, + "project": "sagemaker" + }, + { + "download_count": 964057, + "project": "vobject" + }, + { + "download_count": 963489, + "project": "dbfread" + }, + { + "download_count": 962456, + "project": "bidict" + }, + { + "download_count": 960677, + "project": "google-python-cloud-debugger" + }, + { + "download_count": 958036, + "project": "cognite-sdk" + }, + { + "download_count": 957690, + "project": "vulture" + }, + { + "download_count": 957559, + "project": "pytweening" + }, + { + "download_count": 954913, + "project": "circleci" + }, + { + "download_count": 954734, + "project": "onnxmltools" + }, + { + "download_count": 953896, + "project": "django-jsonfield" + }, + { + "download_count": 952673, + "project": "skl2onnx" + }, + { + "download_count": 951906, + "project": "azure-cli-configure" + }, + { + "download_count": 951530, + "project": "readerwriterlock" + }, + { + "download_count": 951124, + "project": "django-silk" + }, + { + "download_count": 948790, + "project": "json-log-formatter" + }, + { + "download_count": 948696, + "project": "stups-zign" + }, + { + "download_count": 948084, + "project": "commentjson" + }, + { + "download_count": 947759, + "project": "opentracing-instrumentation" + }, + { + "download_count": 947140, + "project": "hurry-filesize" + }, + { + "download_count": 946596, + "project": "httpie" + }, + { + "download_count": 945434, + "project": "comtypes" + }, + { + "download_count": 944648, + "project": "azure-cli-cloud" + }, + { + "download_count": 942122, + "project": "stups-cli-support" + }, + { + "download_count": 941812, + "project": "textfsm" + }, + { + "download_count": 941227, + "project": "django-bulk-update" + }, + { + "download_count": 940485, + "project": "pydotplus" + }, + { + "download_count": 939994, + "project": "logilab-common" + }, + { + "download_count": 939219, + "project": "thriftpy2" + }, + { + "download_count": 937977, + "project": "pyldap" + }, + { + "download_count": 937103, + "project": "progressbar" + }, + { + "download_count": 936822, + "project": "limits" + }, + { + "download_count": 935302, + "project": "empy" + }, + { + "download_count": 933336, + "project": "interval" + }, + { + "download_count": 933102, + "project": "twitter-common-lang" + }, + { + "download_count": 932594, + "project": "sanic" + }, + { + "download_count": 932344, + "project": "twitter-common-dirutil" + }, + { + "download_count": 931618, + "project": "uhashring" + }, + { + "download_count": 929734, + "project": "asana" + }, + { + "download_count": 926851, + "project": "base64io" + }, + { + "download_count": 925789, + "project": "django-user-agents" + }, + { + "download_count": 924447, + "project": "reno" + }, + { + "download_count": 923715, + "project": "netmiko" + }, + { + "download_count": 923299, + "project": "twitter-common-options" + }, + { + "download_count": 923153, + "project": "twitter-common-log" + }, + { + "download_count": 923141, + "project": "parsley" + }, + { + "download_count": 921602, + "project": "azure-cli-find" + }, + { + "download_count": 920951, + "project": "azure-cli-redis" + }, + { + "download_count": 920654, + "project": "aws-encryption-sdk-cli" + }, + { + "download_count": 920109, + "project": "stop-words" + }, + { + "download_count": 919963, + "project": "azure-cli-consumption" + }, + { + "download_count": 919735, + "project": "pydevd" + }, + { + "download_count": 919608, + "project": "azure-cli-billing" + }, + { + "download_count": 919364, + "project": "azure-cli-feedback" + }, + { + "download_count": 919204, + "project": "click-log" + }, + { + "download_count": 916168, + "project": "pypd" + }, + { + "download_count": 914683, + "project": "azure-cli-advisor" + }, + { + "download_count": 914682, + "project": "neobolt" + }, + { + "download_count": 911537, + "project": "azure-cli-eventgrid" + }, + { + "download_count": 911471, + "project": "annoy" + }, + { + "download_count": 910544, + "project": "scramp" + }, + { + "download_count": 910046, + "project": "azure-cli-backup" + }, + { + "download_count": 908651, + "project": "flask-assets" + }, + { + "download_count": 908244, + "project": "oslo-service" + }, + { + "download_count": 905587, + "project": "flask-bootstrap" + }, + { + "download_count": 903282, + "project": "proglog" + }, + { + "download_count": 903200, + "project": "keras2onnx" + }, + { + "download_count": 902334, + "project": "plyvel" + }, + { + "download_count": 900779, + "project": "pybluez" + }, + { + "download_count": 899502, + "project": "pyudev" + }, + { + "download_count": 899012, + "project": "testrepository" + }, + { + "download_count": 898793, + "project": "oslo-policy" + }, + { + "download_count": 897914, + "project": "pmdarima" + }, + { + "download_count": 897653, + "project": "django-autocomplete-light" + }, + { + "download_count": 895791, + "project": "artifactory" + }, + { + "download_count": 895766, + "project": "pytest-variables" + }, + { + "download_count": 895437, + "project": "azure-cli-eventhubs" + }, + { + "download_count": 895142, + "project": "twitter-common-collections" + }, + { + "download_count": 894979, + "project": "azure-cli-servicebus" + }, + { + "download_count": 894815, + "project": "testresources" + }, + { + "download_count": 894191, + "project": "pybs" + }, + { + "download_count": 893842, + "project": "azure-cli-dms" + }, + { + "download_count": 893592, + "project": "channels-redis" + }, + { + "download_count": 893412, + "project": "junitparser" + }, + { + "download_count": 891540, + "project": "tifffile" + }, + { + "download_count": 891533, + "project": "easydict" + }, + { + "download_count": 891481, + "project": "json2parquet" + }, + { + "download_count": 891341, + "project": "pyicu" + }, + { + "download_count": 888690, + "project": "azure-cli-ams" + }, + { + "download_count": 886402, + "project": "pyeapi" + }, + { + "download_count": 885171, + "project": "python-gilt" + }, + { + "download_count": 884033, + "project": "azure-cli-search" + }, + { + "download_count": 882989, + "project": "jupyter-nbextensions-configurator" + }, + { + "download_count": 881790, + "project": "monthdelta" + }, + { + "download_count": 880765, + "project": "pynput" + }, + { + "download_count": 880406, + "project": "pyfiglet" + }, + { + "download_count": 878563, + "project": "jsonnet" + }, + { + "download_count": 874987, + "project": "pvlib" + }, + { + "download_count": 874000, + "project": "jupyter-contrib-core" + }, + { + "download_count": 872790, + "project": "mockito" + }, + { + "download_count": 872554, + "project": "nosexcover" + }, + { + "download_count": 872485, + "project": "peakutils" + }, + { + "download_count": 872331, + "project": "rednose" + }, + { + "download_count": 872127, + "project": "ansicolors" + }, + { + "download_count": 871498, + "project": "j2cli" + }, + { + "download_count": 868629, + "project": "awsiotpythonsdk" + }, + { + "download_count": 867297, + "project": "pywfm" + }, + { + "download_count": 866741, + "project": "lml" + }, + { + "download_count": 865346, + "project": "imblearn" + }, + { + "download_count": 863870, + "project": "openstackdocstheme" + }, + { + "download_count": 863120, + "project": "jupyter-contrib-nbextensions" + }, + { + "download_count": 860421, + "project": "molecule" + }, + { + "download_count": 858716, + "project": "zstandard" + }, + { + "download_count": 858408, + "project": "pyqrcode" + }, + { + "download_count": 856466, + "project": "line-profiler" + }, + { + "download_count": 856334, + "project": "flask-api" + }, + { + "download_count": 856299, + "project": "honcho" + }, + { + "download_count": 856226, + "project": "jplephem" + }, + { + "download_count": 855767, + "project": "rpqueue" + }, + { + "download_count": 854839, + "project": "autoflake" + }, + { + "download_count": 854260, + "project": "azure-mgmt-apimanagement" + }, + { + "download_count": 854182, + "project": "cognite-model-hosting" + }, + { + "download_count": 852933, + "project": "pytest-dependency" + }, + { + "download_count": 852580, + "project": "pytest-pylint" + }, + { + "download_count": 852418, + "project": "deepmerge" + }, + { + "download_count": 850683, + "project": "jupyter-latex-envs" + }, + { + "download_count": 849484, + "project": "polyline" + }, + { + "download_count": 849092, + "project": "yappi" + }, + { + "download_count": 849002, + "project": "logmatic-python" + }, + { + "download_count": 848508, + "project": "sgp4" + }, + { + "download_count": 848205, + "project": "onnxconverter-common" + }, + { + "download_count": 847724, + "project": "django-pipeline" + }, + { + "download_count": 847508, + "project": "envs" + }, + { + "download_count": 847487, + "project": "jupyter-highlight-selected-word" + }, + { + "download_count": 846088, + "project": "googletrans" + }, + { + "download_count": 845652, + "project": "mkdocs-material" + }, + { + "download_count": 845331, + "project": "django-bootstrap3" + }, + { + "download_count": 843583, + "project": "isoweek" + }, + { + "download_count": 843510, + "project": "image" + }, + { + "download_count": 842232, + "project": "solartime" + }, + { + "download_count": 841714, + "project": "flask-debugtoolbar" + }, + { + "download_count": 840214, + "project": "rasterio" + }, + { + "download_count": 839139, + "project": "diamond" + }, + { + "download_count": 837673, + "project": "mailchimp3" + }, + { + "download_count": 835610, + "project": "oslo-middleware" + }, + { + "download_count": 835257, + "project": "mutagen" + }, + { + "download_count": 834695, + "project": "catalogue" + }, + { + "download_count": 834133, + "project": "faulthandler" + }, + { + "download_count": 832671, + "project": "sacrebleu" + }, + { + "download_count": 832545, + "project": "python-jose-cryptodome" + }, + { + "download_count": 831517, + "project": "zeroconf" + }, + { + "download_count": 830534, + "project": "jinja2-pluralize" + }, + { + "download_count": 829948, + "project": "suds-py3" + }, + { + "download_count": 829228, + "project": "pandasql" + }, + { + "download_count": 828892, + "project": "logstash-formatter" + }, + { + "download_count": 828549, + "project": "lifelines" + }, + { + "download_count": 827727, + "project": "liac-arff" + }, + { + "download_count": 827554, + "project": "diff-cover" + }, + { + "download_count": 826205, + "project": "elastic-apm" + }, + { + "download_count": 826135, + "project": "django-coverage-plugin" + }, + { + "download_count": 825300, + "project": "skyfield" + }, + { + "download_count": 824924, + "project": "drf-extensions" + }, + { + "download_count": 823613, + "project": "databricks-pypi-extras" + }, + { + "download_count": 823180, + "project": "azure-cli-relay" + }, + { + "download_count": 822954, + "project": "azure-cli-iotcentral" + }, + { + "download_count": 822898, + "project": "azure-cli-hdinsight" + }, + { + "download_count": 822664, + "project": "azure-cli-maps" + }, + { + "download_count": 822562, + "project": "azure-cli-botservice" + }, + { + "download_count": 822180, + "project": "azure-cli-signalr" + }, + { + "download_count": 822129, + "project": "lime" + }, + { + "download_count": 821534, + "project": "transifex-client" + }, + { + "download_count": 820293, + "project": "azure-cli-policyinsights" + }, + { + "download_count": 819714, + "project": "django-classy-tags" + }, + { + "download_count": 818561, + "project": "clickhouse-driver" + }, + { + "download_count": 815459, + "project": "scrapy-splash" + }, + { + "download_count": 815166, + "project": "pybrake" + }, + { + "download_count": 814136, + "project": "carbon" + }, + { + "download_count": 813628, + "project": "wmi" + }, + { + "download_count": 810452, + "project": "python-ironicclient" + }, + { + "download_count": 808082, + "project": "pusher" + }, + { + "download_count": 806951, + "project": "datadiff" + }, + { + "download_count": 806876, + "project": "js2py" + }, + { + "download_count": 805430, + "project": "urlobject" + }, + { + "download_count": 804845, + "project": "tinydb" + }, + { + "download_count": 804621, + "project": "pytest-randomly" + }, + { + "download_count": 804371, + "project": "placebo" + }, + { + "download_count": 804270, + "project": "progress" + }, + { + "download_count": 804201, + "project": "nimbusml" + }, + { + "download_count": 803677, + "project": "ffmpeg-python" + }, + { + "download_count": 803390, + "project": "pandas-profiling" + }, + { + "download_count": 803033, + "project": "pyspark-flame" + }, + { + "download_count": 802518, + "project": "nose-xunitmp" + }, + { + "download_count": 801270, + "project": "ftputil" + }, + { + "download_count": 800466, + "project": "pyexcel-io" + }, + { + "download_count": 800452, + "project": "pysam" + }, + { + "download_count": 800033, + "project": "oslo-cache" + }, + { + "download_count": 799400, + "project": "jinja2schema" + }, + { + "download_count": 797811, + "project": "skyfield-data" + }, + { + "download_count": 797080, + "project": "bashate" + }, + { + "download_count": 796778, + "project": "pytest-base-url" + }, + { + "download_count": 795722, + "project": "mpld3" + }, + { + "download_count": 795138, + "project": "pytest-selenium" + }, + { + "download_count": 794945, + "project": "facebookads" + }, + { + "download_count": 792726, + "project": "testing-common-database" + }, + { + "download_count": 792699, + "project": "requests-unixsocket" + }, + { + "download_count": 791454, + "project": "ansible-tower-cli" + }, + { + "download_count": 790178, + "project": "dlib" + }, + { + "download_count": 788016, + "project": "web3" + }, + { + "download_count": 787379, + "project": "pygresql" + }, + { + "download_count": 786501, + "project": "update-checker" + }, + { + "download_count": 784385, + "project": "pygetwindow" + }, + { + "download_count": 783264, + "project": "allure-pytest" + }, + { + "download_count": 782719, + "project": "pycontracts" + }, + { + "download_count": 782492, + "project": "wsgi-request-logger" + }, + { + "download_count": 780141, + "project": "m2crypto" + }, + { + "download_count": 779854, + "project": "scrapyd" + }, + { + "download_count": 779681, + "project": "centrosome" + }, + { + "download_count": 779517, + "project": "flask-mongoengine" + }, + { + "download_count": 778027, + "project": "dataclasses-json" + }, + { + "download_count": 777762, + "project": "splinter" + }, + { + "download_count": 777345, + "project": "htmlparser" + }, + { + "download_count": 775376, + "project": "loguru" + }, + { + "download_count": 774793, + "project": "dumb-init" + }, + { + "download_count": 774504, + "project": "python-designateclient" + }, + { + "download_count": 774495, + "project": "speaklater" + }, + { + "download_count": 773679, + "project": "eth-utils" + }, + { + "download_count": 772719, + "project": "spark-df-profiling" + }, + { + "download_count": 772355, + "project": "javabridge" + }, + { + "download_count": 771179, + "project": "us" + }, + { + "download_count": 769552, + "project": "xdg" + }, + { + "download_count": 769306, + "project": "librabbitmq" + }, + { + "download_count": 769240, + "project": "lepl" + }, + { + "download_count": 769163, + "project": "pysolr" + }, + { + "download_count": 768526, + "project": "google-cloud-happybase" + }, + { + "download_count": 768426, + "project": "graphene-sqlalchemy" + }, + { + "download_count": 768057, + "project": "google-endpoints-api-management" + }, + { + "download_count": 767991, + "project": "affine" + }, + { + "download_count": 767570, + "project": "colour" + }, + { + "download_count": 764562, + "project": "django-constance" + }, + { + "download_count": 762359, + "project": "infinity" + }, + { + "download_count": 761920, + "project": "djangorestframework-filters" + }, + { + "download_count": 760164, + "project": "robotremoteserver" + }, + { + "download_count": 759992, + "project": "keystonemiddleware" + }, + { + "download_count": 758677, + "project": "distribute" + }, + { + "download_count": 757044, + "project": "hyper" + }, + { + "download_count": 755707, + "project": "pyscreenshot" + }, + { + "download_count": 755554, + "project": "google-endpoints" + }, + { + "download_count": 754592, + "project": "intervals" + }, + { + "download_count": 754564, + "project": "pysal" + }, + { + "download_count": 754317, + "project": "svgwrite" + }, + { + "download_count": 753732, + "project": "cognite-logger" + }, + { + "download_count": 753586, + "project": "pytest-spark" + }, + { + "download_count": 753503, + "project": "nose-parallel" + }, + { + "download_count": 753048, + "project": "dynaconf" + }, + { + "download_count": 752651, + "project": "mahotas" + }, + { + "download_count": 751112, + "project": "databricks-pypi" + }, + { + "download_count": 749141, + "project": "mysql" + }, + { + "download_count": 749102, + "project": "flake8-builtins" + }, + { + "download_count": 748778, + "project": "humpty" + }, + { + "download_count": 748490, + "project": "pyspark-dist-explore" + }, + { + "download_count": 746836, + "project": "django-annoying" + }, + { + "download_count": 746781, + "project": "tinyrpc" + }, + { + "download_count": 746415, + "project": "wincertstore" + }, + { + "download_count": 745591, + "project": "django-axes" + }, + { + "download_count": 742692, + "project": "aerospike" + }, + { + "download_count": 739560, + "project": "pycadf" + }, + { + "download_count": 739333, + "project": "django-csp" + }, + { + "download_count": 737212, + "project": "django-compat" + }, + { + "download_count": 735567, + "project": "azure-cli-security" + }, + { + "download_count": 735347, + "project": "asyncssh" + }, + { + "download_count": 734370, + "project": "robotframework-sshlibrary" + }, + { + "download_count": 734265, + "project": "concurrentloghandler" + }, + { + "download_count": 734033, + "project": "django-object-actions" + }, + { + "download_count": 733362, + "project": "azure-cli-kusto" + }, + { + "download_count": 733347, + "project": "tensorflowonspark" + }, + { + "download_count": 732849, + "project": "aioresponses" + }, + { + "download_count": 731576, + "project": "jenkins-job-builder" + }, + { + "download_count": 731088, + "project": "bravado" + }, + { + "download_count": 728665, + "project": "prometheus-flask-exporter" + }, + { + "download_count": 727540, + "project": "pprint" + }, + { + "download_count": 726931, + "project": "jaeger-client" + }, + { + "download_count": 726893, + "project": "nose-parameterized" + }, + { + "download_count": 726613, + "project": "pyrect" + }, + { + "download_count": 726590, + "project": "htcondor" + }, + { + "download_count": 723307, + "project": "pip-licenses" + }, + { + "download_count": 723172, + "project": "mlxtend" + }, + { + "download_count": 721353, + "project": "py2-ipaddress" + }, + { + "download_count": 719973, + "project": "osprofiler" + }, + { + "download_count": 719532, + "project": "pandas-datareader" + }, + { + "download_count": 718534, + "project": "ngram" + }, + { + "download_count": 718362, + "project": "h2o" + }, + { + "download_count": 717198, + "project": "homeassistant" + }, + { + "download_count": 716605, + "project": "pytest-mypy" + }, + { + "download_count": 716398, + "project": "eth-typing" + }, + { + "download_count": 716263, + "project": "django-auth-ldap" + }, + { + "download_count": 714558, + "project": "jsonmerge" + }, + { + "download_count": 714088, + "project": "django-cacheops" + }, + { + "download_count": 713825, + "project": "python-bioformats" + }, + { + "download_count": 713644, + "project": "stomp-py" + }, + { + "download_count": 713346, + "project": "scrypt" + }, + { + "download_count": 710233, + "project": "prokaryote" + }, + { + "download_count": 709352, + "project": "testing-postgresql" + }, + { + "download_count": 708670, + "project": "azure-cli-sqlvm" + }, + { + "download_count": 708401, + "project": "shrub-py" + }, + { + "download_count": 708219, + "project": "django-tinymce" + }, + { + "download_count": 708181, + "project": "scrapyd-client" + }, + { + "download_count": 707527, + "project": "apiclient" + }, + { + "download_count": 707254, + "project": "imgaug" + }, + { + "download_count": 707113, + "project": "nbsphinx" + }, + { + "download_count": 707083, + "project": "waiting" + }, + { + "download_count": 705264, + "project": "colorclass" + }, + { + "download_count": 703706, + "project": "consul-kv" + }, + { + "download_count": 702978, + "project": "html" + }, + { + "download_count": 702738, + "project": "rlp" + }, + { + "download_count": 702351, + "project": "nose-cov" + }, + { + "download_count": 702193, + "project": "python-twitter" + }, + { + "download_count": 701163, + "project": "splunk-sdk" + }, + { + "download_count": 700250, + "project": "fastcluster" + }, + { + "download_count": 698719, + "project": "yamale" + }, + { + "download_count": 698219, + "project": "pyramid-arima" + }, + { + "download_count": 697868, + "project": "termstyle" + }, + { + "download_count": 697474, + "project": "xstatic-bootstrap-scss" + }, + { + "download_count": 695211, + "project": "pyrouge" + }, + { + "download_count": 694603, + "project": "snuggs" + }, + { + "download_count": 693279, + "project": "python-barbicanclient" + }, + { + "download_count": 693249, + "project": "pyaudio" + }, + { + "download_count": 692957, + "project": "cvxpy" + }, + { + "download_count": 692001, + "project": "async-lru" + }, + { + "download_count": 691907, + "project": "mizani" + }, + { + "download_count": 691307, + "project": "petname" + }, + { + "download_count": 691300, + "project": "rouge" + }, + { + "download_count": 689543, + "project": "agate-dbf" + }, + { + "download_count": 688981, + "project": "fastapi" + }, + { + "download_count": 687783, + "project": "category-encoders" + }, + { + "download_count": 687548, + "project": "oyaml" + }, + { + "download_count": 687522, + "project": "gnureadline" + }, + { + "download_count": 687081, + "project": "rake-nltk" + }, + { + "download_count": 686921, + "project": "titlecase" + }, + { + "download_count": 685900, + "project": "robotframework-pabot" + }, + { + "download_count": 685000, + "project": "pygraphviz" + }, + { + "download_count": 684549, + "project": "awesome-slugify" + }, + { + "download_count": 684157, + "project": "ibmiotf" + }, + { + "download_count": 683792, + "project": "cpplint" + }, + { + "download_count": 683191, + "project": "transforms3d" + }, + { + "download_count": 681681, + "project": "junos-eznc" + }, + { + "download_count": 680817, + "project": "edn-format" + }, + { + "download_count": 680484, + "project": "kappa" + }, + { + "download_count": 680439, + "project": "dist-keras" + }, + { + "download_count": 679352, + "project": "wagtail" + }, + { + "download_count": 679107, + "project": "xstatic" + }, + { + "download_count": 678488, + "project": "sparkpost" + }, + { + "download_count": 677907, + "project": "django-configurations" + }, + { + "download_count": 676671, + "project": "warrant" + }, + { + "download_count": 675669, + "project": "coremltools" + }, + { + "download_count": 675660, + "project": "pystemmer" + }, + { + "download_count": 674957, + "project": "piexif" + }, + { + "download_count": 674880, + "project": "xstatic-jquery" + }, + { + "download_count": 674487, + "project": "ebaysdk" + }, + { + "download_count": 672829, + "project": "durationpy" + }, + { + "download_count": 670913, + "project": "odo" + }, + { + "download_count": 670060, + "project": "django-admin-rangefilter" + }, + { + "download_count": 669445, + "project": "pytrie" + }, + { + "download_count": 669083, + "project": "wxpython" + }, + { + "download_count": 667717, + "project": "ovs" + }, + { + "download_count": 667474, + "project": "ecos" + }, + { + "download_count": 666906, + "project": "tinycss" + }, + { + "download_count": 666871, + "project": "osqp" + }, + { + "download_count": 666786, + "project": "eth-hash" + }, + { + "download_count": 666275, + "project": "requirements-parser" + }, + { + "download_count": 665693, + "project": "glom" + }, + { + "download_count": 661492, + "project": "cbor" + }, + { + "download_count": 661312, + "project": "typeguard" + }, + { + "download_count": 660570, + "project": "auth0-python" + }, + { + "download_count": 660013, + "project": "grpcio-opentracing" + }, + { + "download_count": 659377, + "project": "fastcache" + }, + { + "download_count": 659193, + "project": "eth-abi" + }, + { + "download_count": 659114, + "project": "django-modelcluster" + }, + { + "download_count": 657030, + "project": "jgscm" + }, + { + "download_count": 656904, + "project": "xlocal" + }, + { + "download_count": 656475, + "project": "plotnine" + }, + { + "download_count": 655373, + "project": "oslo-reports" + }, + { + "download_count": 654961, + "project": "selectors2" + }, + { + "download_count": 653743, + "project": "pyexcel" + }, + { + "download_count": 653621, + "project": "mongoalchemy" + }, + { + "download_count": 652980, + "project": "django-celery-monitor" + }, + { + "download_count": 652428, + "project": "django-modeltranslation" + }, + { + "download_count": 651995, + "project": "m3-cdecimal" + }, + { + "download_count": 651743, + "project": "django-prometheus" + }, + { + "download_count": 649810, + "project": "pylama" + }, + { + "download_count": 649753, + "project": "pygtrie" + }, + { + "download_count": 649300, + "project": "zappa" + }, + { + "download_count": 648596, + "project": "lambda-packages" + }, + { + "download_count": 648298, + "project": "chainmap" + }, + { + "download_count": 648259, + "project": "sqlitedict" + }, + { + "download_count": 646634, + "project": "weakrefmethod" + }, + { + "download_count": 646583, + "project": "pyephem" + }, + { + "download_count": 646316, + "project": "pecan" + }, + { + "download_count": 646192, + "project": "grpcio-testing" + }, + { + "download_count": 645984, + "project": "ptpython" + }, + { + "download_count": 645726, + "project": "uwsgitop" + }, + { + "download_count": 645705, + "project": "xattr" + }, + { + "download_count": 645542, + "project": "sseclient" + }, + { + "download_count": 644773, + "project": "distance" + }, + { + "download_count": 641990, + "project": "crayons" + }, + { + "download_count": 641666, + "project": "scs" + }, + { + "download_count": 641155, + "project": "youtube-dl-server" + }, + { + "download_count": 640583, + "project": "pydicom" + }, + { + "download_count": 640562, + "project": "disklist" + }, + { + "download_count": 640283, + "project": "oslo-versionedobjects" + }, + { + "download_count": 639381, + "project": "property-manager" + }, + { + "download_count": 639343, + "project": "pyramid-tm" + }, + { + "download_count": 638235, + "project": "civis" + }, + { + "download_count": 638153, + "project": "flask-sslify" + }, + { + "download_count": 637064, + "project": "tflearn" + }, + { + "download_count": 635676, + "project": "pygeoif" + }, + { + "download_count": 635375, + "project": "anytree" + }, + { + "download_count": 634585, + "project": "prawcore" + }, + { + "download_count": 633579, + "project": "httmock" + }, + { + "download_count": 633551, + "project": "praw" + }, + { + "download_count": 633536, + "project": "blaze" + }, + { + "download_count": 630085, + "project": "dogstatsd-python" + }, + { + "download_count": 629789, + "project": "df2gspread" + }, + { + "download_count": 629728, + "project": "intelhex" + }, + { + "download_count": 628881, + "project": "flask-pymongo" + }, + { + "download_count": 628208, + "project": "ara" + }, + { + "download_count": 628016, + "project": "supervisor-checks" + }, + { + "download_count": 626928, + "project": "portpicker" + }, + { + "download_count": 626822, + "project": "willow" + }, + { + "download_count": 624147, + "project": "django-admin-sortable2" + }, + { + "download_count": 623219, + "project": "py2neo" + }, + { + "download_count": 622538, + "project": "dis3" + }, + { + "download_count": 621132, + "project": "dask-ml" + }, + { + "download_count": 620942, + "project": "doc8" + }, + { + "download_count": 620211, + "project": "duo-client" + }, + { + "download_count": 620141, + "project": "django-rq" + }, + { + "download_count": 619804, + "project": "cronex" + }, + { + "download_count": 619350, + "project": "quandl" + }, + { + "download_count": 616490, + "project": "fpdf" + }, + { + "download_count": 615575, + "project": "dpkt" + }, + { + "download_count": 615407, + "project": "img2pdf" + }, + { + "download_count": 614677, + "project": "twython" + }, + { + "download_count": 612945, + "project": "django-tastypie" + }, + { + "download_count": 612710, + "project": "fastkml" + }, + { + "download_count": 611741, + "project": "pychef" + }, + { + "download_count": 611286, + "project": "pbkdf2" + }, + { + "download_count": 611114, + "project": "envparse" + }, + { + "download_count": 610989, + "project": "pytest-profiling" + }, + { + "download_count": 610971, + "project": "face" + }, + { + "download_count": 609341, + "project": "sphinxcontrib-plantuml" + }, + { + "download_count": 609245, + "project": "pockets" + }, + { + "download_count": 609190, + "project": "pex" + }, + { + "download_count": 607985, + "project": "codacy-coverage" + }, + { + "download_count": 607915, + "project": "smtpapi" + }, + { + "download_count": 607247, + "project": "recordtype" + }, + { + "download_count": 604747, + "project": "django-sekizai" + }, + { + "download_count": 604376, + "project": "glances" + }, + { + "download_count": 603378, + "project": "pysha3" + }, + { + "download_count": 602654, + "project": "sphinxcontrib-napoleon" + }, + { + "download_count": 601446, + "project": "authlib" + }, + { + "download_count": 601374, + "project": "python-intercom" + }, + { + "download_count": 600575, + "project": "flask-limiter" + }, + { + "download_count": 600277, + "project": "python-statsd" + }, + { + "download_count": 599602, + "project": "draftjs-exporter" + }, + { + "download_count": 598699, + "project": "flake8-debugger" + }, + { + "download_count": 598674, + "project": "oslo-upgradecheck" + }, + { + "download_count": 598119, + "project": "libvirt-python" + }, + { + "download_count": 597629, + "project": "cron-descriptor" + }, + { + "download_count": 597332, + "project": "wsproto" + }, + { + "download_count": 597238, + "project": "asyncio-nats-client" + }, + { + "download_count": 597234, + "project": "pytorch-pretrained-bert" + }, + { + "download_count": 597090, + "project": "fixture" + }, + { + "download_count": 596614, + "project": "alpha-vantage" + }, + { + "download_count": 596308, + "project": "edgegrid-python" + }, + { + "download_count": 596233, + "project": "eth-keys" + }, + { + "download_count": 596043, + "project": "impacket" + }, + { + "download_count": 595545, + "project": "win-inet-pton" + }, + { + "download_count": 595350, + "project": "mox3" + }, + { + "download_count": 595102, + "project": "rarfile" + }, + { + "download_count": 593426, + "project": "yarn-api-client" + }, + { + "download_count": 593291, + "project": "colored" + }, + { + "download_count": 592042, + "project": "txaws" + }, + { + "download_count": 591199, + "project": "speechrecognition" + }, + { + "download_count": 591134, + "project": "frozen-flask" + }, + { + "download_count": 590993, + "project": "django-log-request-id" + }, + { + "download_count": 589804, + "project": "funcparserlib" + }, + { + "download_count": 589445, + "project": "djangorestframework-camel-case" + }, + { + "download_count": 588165, + "project": "oslo-privsep" + }, + { + "download_count": 587455, + "project": "tf-nightly" + }, + { + "download_count": 587372, + "project": "caniusepython3" + }, + { + "download_count": 586559, + "project": "envtpl" + }, + { + "download_count": 586159, + "project": "mockredispy" + }, + { + "download_count": 586076, + "project": "properties" + }, + { + "download_count": 585723, + "project": "ansi2html" + }, + { + "download_count": 585253, + "project": "pyzipcode" + }, + { + "download_count": 584788, + "project": "sphinx-autodoc-typehints" + }, + { + "download_count": 583551, + "project": "environs" + }, + { + "download_count": 583517, + "project": "junit2html" + }, + { + "download_count": 583339, + "project": "yoyo-migrations" + }, + { + "download_count": 582030, + "project": "junitxml" + }, + { + "download_count": 580290, + "project": "django-heroku" + }, + { + "download_count": 579947, + "project": "chart-studio" + }, + { + "download_count": 579171, + "project": "pyexecjs" + }, + { + "download_count": 578063, + "project": "datasketch" + }, + { + "download_count": 577373, + "project": "django-autoslug" + }, + { + "download_count": 577155, + "project": "pyrepl" + }, + { + "download_count": 576195, + "project": "polygon-geohasher" + }, + { + "download_count": 575933, + "project": "addict" + }, + { + "download_count": 575932, + "project": "tooz" + }, + { + "download_count": 575622, + "project": "mecab-python3" + }, + { + "download_count": 575453, + "project": "shippo" + }, + { + "download_count": 575188, + "project": "bindep" + }, + { + "download_count": 574250, + "project": "requests-html" + }, + { + "download_count": 573651, + "project": "python-louvain" + }, + { + "download_count": 572787, + "project": "zmq" + }, + { + "download_count": 571317, + "project": "eth-account" + }, + { + "download_count": 571250, + "project": "ortools" + }, + { + "download_count": 570798, + "project": "automaton" + }, + { + "download_count": 570379, + "project": "django-cors-middleware" + }, + { + "download_count": 570213, + "project": "rq-dashboard" + }, + { + "download_count": 569967, + "project": "oslo-rootwrap" + }, + { + "download_count": 569775, + "project": "pilkit" + }, + { + "download_count": 569584, + "project": "readthedocs-sphinx-ext" + }, + { + "download_count": 569334, + "project": "latexcodec" + }, + { + "download_count": 568887, + "project": "south" + }, + { + "download_count": 568427, + "project": "agate-excel" + }, + { + "download_count": 568046, + "project": "hexbytes" + }, + { + "download_count": 567653, + "project": "django-money" + }, + { + "download_count": 567483, + "project": "agate-sql" + }, + { + "download_count": 566872, + "project": "kitchen" + }, + { + "download_count": 566696, + "project": "unipath" + }, + { + "download_count": 566631, + "project": "sshuttle" + }, + { + "download_count": 566158, + "project": "robotframework-faker" + }, + { + "download_count": 565395, + "project": "pybtex" + }, + { + "download_count": 565136, + "project": "django-nested-admin" + }, + { + "download_count": 564284, + "project": "eth-keyfile" + }, + { + "download_count": 564232, + "project": "djangorestframework-bulk" + }, + { + "download_count": 564010, + "project": "dataset" + }, + { + "download_count": 563254, + "project": "trafaret" + }, + { + "download_count": 562622, + "project": "cheetah3" + }, + { + "download_count": 561733, + "project": "flask-security" + }, + { + "download_count": 560775, + "project": "aliyun-python-sdk-core-v3" + }, + { + "download_count": 560763, + "project": "azureml-train-automl" + }, + { + "download_count": 559850, + "project": "control" + }, + { + "download_count": 559644, + "project": "implicit" + }, + { + "download_count": 559092, + "project": "dependency-injector" + }, + { + "download_count": 558284, + "project": "lazy" + }, + { + "download_count": 558189, + "project": "unidiff" + }, + { + "download_count": 557350, + "project": "textdistance" + }, + { + "download_count": 557098, + "project": "python-monkey-business" + }, + { + "download_count": 556600, + "project": "untangle" + }, + { + "download_count": 556409, + "project": "reverse-geocoder" + }, + { + "download_count": 556261, + "project": "pygeoip" + }, + { + "download_count": 554953, + "project": "eth-rlp" + }, + { + "download_count": 552622, + "project": "databricks" + }, + { + "download_count": 552459, + "project": "pyvim" + }, + { + "download_count": 551935, + "project": "taskflow" + }, + { + "download_count": 551365, + "project": "ifaddr" + }, + { + "download_count": 549608, + "project": "eeweather" + }, + { + "download_count": 549360, + "project": "clickhouse-cityhash" + }, + { + "download_count": 548549, + "project": "django-hijack" + }, + { + "download_count": 547813, + "project": "names" + }, + { + "download_count": 547796, + "project": "castellan" + }, + { + "download_count": 547711, + "project": "sacremoses" + }, + { + "download_count": 547488, + "project": "flake8-blind-except" + }, + { + "download_count": 547363, + "project": "mozdebug" + }, + { + "download_count": 547215, + "project": "ofxparse" + }, + { + "download_count": 546668, + "project": "vatnumber" + }, + { + "download_count": 546665, + "project": "remoto" + }, + { + "download_count": 546052, + "project": "checksumdir" + }, + { + "download_count": 545735, + "project": "pyowm" + }, + { + "download_count": 545330, + "project": "poster" + }, + { + "download_count": 543997, + "project": "lzstring" + }, + { + "download_count": 543850, + "project": "pyminizip" + }, + { + "download_count": 543634, + "project": "np-utils" + }, + { + "download_count": 543596, + "project": "injector" + }, + { + "download_count": 543183, + "project": "django-imagekit" + }, + { + "download_count": 542497, + "project": "five9" + }, + { + "download_count": 542414, + "project": "static3" + }, + { + "download_count": 541667, + "project": "oset" + }, + { + "download_count": 540962, + "project": "jsbeautifier" + }, + { + "download_count": 540750, + "project": "hdbscan" + }, + { + "download_count": 540280, + "project": "os-testr" + }, + { + "download_count": 540000, + "project": "flask-babelex" + }, + { + "download_count": 539901, + "project": "positional" + }, + { + "download_count": 539021, + "project": "profilehooks" + }, + { + "download_count": 538332, + "project": "flask-rq2" + }, + { + "download_count": 538314, + "project": "pygpgme" + }, + { + "download_count": 538159, + "project": "ts-flint" + }, + { + "download_count": 538112, + "project": "google-api-helper" + }, + { + "download_count": 537857, + "project": "markuppy" + }, + { + "download_count": 537565, + "project": "keras-mxnet" + }, + { + "download_count": 535795, + "project": "kwargs-only" + }, + { + "download_count": 534335, + "project": "django-mathfilters" + }, + { + "download_count": 534222, + "project": "dj-static" + }, + { + "download_count": 533502, + "project": "web-py" + }, + { + "download_count": 533322, + "project": "zenpy" + }, + { + "download_count": 533300, + "project": "django-enumfields" + }, + { + "download_count": 533281, + "project": "georaptor" + }, + { + "download_count": 533198, + "project": "heroku3" + }, + { + "download_count": 533034, + "project": "oci" + }, + { + "download_count": 532545, + "project": "django-fernet-fields" + }, + { + "download_count": 531368, + "project": "pyftpdlib" + }, + { + "download_count": 529065, + "project": "neutron-lib" + }, + { + "download_count": 529026, + "project": "grpcio-reflection" + }, + { + "download_count": 528753, + "project": "python-jsonschema-objects" + }, + { + "download_count": 528555, + "project": "django-dynamic-fixture" + }, + { + "download_count": 528426, + "project": "pyod" + }, + { + "download_count": 528307, + "project": "simplekml" + }, + { + "download_count": 527593, + "project": "overrides" + }, + { + "download_count": 526989, + "project": "ovsdbapp" + }, + { + "download_count": 526603, + "project": "tavern" + }, + { + "download_count": 526180, + "project": "peppercorn" + }, + { + "download_count": 526018, + "project": "cbapi" + }, + { + "download_count": 525952, + "project": "twitter-common-contextutil" + }, + { + "download_count": 523345, + "project": "pypdf" + }, + { + "download_count": 523091, + "project": "couchbase" + }, + { + "download_count": 522723, + "project": "profanityfilter" + }, + { + "download_count": 522269, + "project": "blist" + }, + { + "download_count": 522185, + "project": "pydns" + }, + { + "download_count": 521431, + "project": "stopit" + }, + { + "download_count": 521064, + "project": "keyboard" + }, + { + "download_count": 520346, + "project": "twitter-common-util" + }, + { + "download_count": 520255, + "project": "flatten-json" + }, + { + "download_count": 519427, + "project": "twitter-common-string" + }, + { + "download_count": 519406, + "project": "tableauserverclient" + }, + { + "download_count": 519368, + "project": "m2r" + }, + { + "download_count": 519326, + "project": "twitter-common-process" + }, + { + "download_count": 519222, + "project": "twitter-common-app" + }, + { + "download_count": 518985, + "project": "json-rpc" + }, + { + "download_count": 517770, + "project": "slack-webhook-cli" + }, + { + "download_count": 517297, + "project": "antigate" + }, + { + "download_count": 516754, + "project": "sphinxcontrib-bibtex" + }, + { + "download_count": 516195, + "project": "pybtex-docutils" + }, + { + "download_count": 515133, + "project": "rfc6266-parser" + }, + { + "download_count": 514541, + "project": "nflx-genie-client" + }, + { + "download_count": 513202, + "project": "missingno" + }, + { + "download_count": 513069, + "project": "mitmproxy" + }, + { + "download_count": 512838, + "project": "conan-package-tools" + }, + { + "download_count": 512668, + "project": "xlutils" + }, + { + "download_count": 512441, + "project": "pprintpp" + }, + { + "download_count": 512440, + "project": "os-traits" + }, + { + "download_count": 512397, + "project": "svglib" + }, + { + "download_count": 510713, + "project": "btrees" + }, + { + "download_count": 510636, + "project": "graphframes" + }, + { + "download_count": 509946, + "project": "sarge" + }, + { + "download_count": 509466, + "project": "shadowsocks" + }, + { + "download_count": 509388, + "project": "hmsclient" + }, + { + "download_count": 509166, + "project": "azure-mgmt-servermanager" + }, + { + "download_count": 508757, + "project": "elasticache-pyclient" + }, + { + "download_count": 508756, + "project": "xstatic-patternfly" + }, + { + "download_count": 508352, + "project": "pep257" + }, + { + "download_count": 508010, + "project": "xstatic-patternfly-bootstrap-treeview" + }, + { + "download_count": 507803, + "project": "xstatic-datatables" + }, + { + "download_count": 507499, + "project": "django-recaptcha" + }, + { + "download_count": 507473, + "project": "persistent" + }, + { + "download_count": 507135, + "project": "altair" + }, + { + "download_count": 505888, + "project": "edx-enterprise" + }, + { + "download_count": 505690, + "project": "graphy" + }, + { + "download_count": 505101, + "project": "redlock-py" + }, + { + "download_count": 504911, + "project": "pymc3" + }, + { + "download_count": 504787, + "project": "mercantile" + }, + { + "download_count": 504175, + "project": "lftools" + }, + { + "download_count": 502985, + "project": "robotframework-httplibrary" + }, + { + "download_count": 501914, + "project": "tsfresh" + }, + { + "download_count": 501627, + "project": "fitbit" + }, + { + "download_count": 501439, + "project": "lightfm" + }, + { + "download_count": 501354, + "project": "djoser" + }, + { + "download_count": 501217, + "project": "pytest-faulthandler" + }, + { + "download_count": 500476, + "project": "formencode" + }, + { + "download_count": 500465, + "project": "spyne" + }, + { + "download_count": 500288, + "project": "backports-os" + }, + { + "download_count": 500147, + "project": "customerio" + }, + { + "download_count": 499726, + "project": "os-win" + }, + { + "download_count": 499639, + "project": "neptune-client" + }, + { + "download_count": 499204, + "project": "googleappenginecloudstorageclient" + }, + { + "download_count": 498658, + "project": "sparqlwrapper" + }, + { + "download_count": 498519, + "project": "sphinxcontrib-spelling" + }, + { + "download_count": 498177, + "project": "geotext" + }, + { + "download_count": 497560, + "project": "pytest-lazy-fixture" + }, + { + "download_count": 497085, + "project": "pyarabic" + }, + { + "download_count": 497017, + "project": "auditwheel" + }, + { + "download_count": 496676, + "project": "django-debug-panel" + }, + { + "download_count": 495919, + "project": "cssmin" + }, + { + "download_count": 495656, + "project": "nose-progressive" + }, + { + "download_count": 495187, + "project": "django-suit" + }, + { + "download_count": 495183, + "project": "mercurial" + }, + { + "download_count": 495032, + "project": "python-hosts" + }, + { + "download_count": 494652, + "project": "pywatchman" + }, + { + "download_count": 494192, + "project": "pip-lock" + }, + { + "download_count": 494177, + "project": "clikit" + }, + { + "download_count": 494100, + "project": "flake8-per-file-ignores" + }, + { + "download_count": 493208, + "project": "os-brick" + }, + { + "download_count": 492737, + "project": "cloudinary" + }, + { + "download_count": 492342, + "project": "pyroma" + }, + { + "download_count": 491821, + "project": "aiohttp-jinja2" + }, + { + "download_count": 491668, + "project": "func-timeout" + }, + { + "download_count": 491557, + "project": "ldapdomaindump" + }, + { + "download_count": 490771, + "project": "logzio-python-handler" + }, + { + "download_count": 490651, + "project": "yarg" + }, + { + "download_count": 490261, + "project": "python-geoip" + }, + { + "download_count": 489169, + "project": "gremlinpython" + }, + { + "download_count": 488646, + "project": "uplink" + }, + { + "download_count": 487621, + "project": "pyjarowinkler" + }, + { + "download_count": 485859, + "project": "qt4reactor" + }, + { + "download_count": 485712, + "project": "records" + }, + { + "download_count": 485512, + "project": "flake8-string-format" + }, + { + "download_count": 485371, + "project": "django-rest-framework" + }, + { + "download_count": 485084, + "project": "pydruid" + }, + { + "download_count": 484914, + "project": "meson" + }, + { + "download_count": 484556, + "project": "django-select2" + }, + { + "download_count": 484267, + "project": "pamqp" + }, + { + "download_count": 484090, + "project": "xmljson" + }, + { + "download_count": 483920, + "project": "slots" + }, + { + "download_count": 483748, + "project": "doublemetaphone" + }, + { + "download_count": 483545, + "project": "pycli" + }, + { + "download_count": 483354, + "project": "jupyterlab-launcher" + }, + { + "download_count": 482936, + "project": "editorconfig" + }, + { + "download_count": 482719, + "project": "pamela" + }, + { + "download_count": 482539, + "project": "rdpy" + }, + { + "download_count": 482395, + "project": "word2number" + }, + { + "download_count": 482346, + "project": "pykmip" + }, + { + "download_count": 480460, + "project": "recurly" + }, + { + "download_count": 479945, + "project": "datarobot" + }, + { + "download_count": 479251, + "project": "email-reply-parser" + }, + { + "download_count": 479059, + "project": "geohash2" + }, + { + "download_count": 478838, + "project": "readchar" + }, + { + "download_count": 478822, + "project": "mohawk" + }, + { + "download_count": 478394, + "project": "orjson" + }, + { + "download_count": 478032, + "project": "pycocotools" + }, + { + "download_count": 477626, + "project": "pythonnet" + }, + { + "download_count": 477384, + "project": "deap" + }, + { + "download_count": 476311, + "project": "cursor" + }, + { + "download_count": 475480, + "project": "django-jenkins" + }, + { + "download_count": 475049, + "project": "azureml-automl-core" + }, + { + "download_count": 474562, + "project": "sklearn-crfsuite" + }, + { + "download_count": 472571, + "project": "azure-mgmt-documentdb" + }, + { + "download_count": 471293, + "project": "paretochart" + }, + { + "download_count": 471137, + "project": "python-debian" + }, + { + "download_count": 471045, + "project": "rply" + }, + { + "download_count": 469934, + "project": "pynliner" + }, + { + "download_count": 469110, + "project": "ipwhois" + }, + { + "download_count": 468984, + "project": "pylint-quotes" + }, + { + "download_count": 468853, + "project": "sfmergeutility" + }, + { + "download_count": 468745, + "project": "pyside2" + }, + { + "download_count": 468673, + "project": "cupy-cuda100" + }, + { + "download_count": 468012, + "project": "tokenize-rt" + }, + { + "download_count": 467174, + "project": "halo" + }, + { + "download_count": 467029, + "project": "pyblake2" + }, + { + "download_count": 466658, + "project": "python-keyczar" + }, + { + "download_count": 466596, + "project": "pytest-factoryboy" + }, + { + "download_count": 466322, + "project": "pyramid-mako" + }, + { + "download_count": 465692, + "project": "speedtest-cli" + }, + { + "download_count": 465559, + "project": "ansible-vault" + }, + { + "download_count": 465439, + "project": "sure" + }, + { + "download_count": 465170, + "project": "h3" + }, + { + "download_count": 464606, + "project": "pysolar" + }, + { + "download_count": 464135, + "project": "os-vif" + }, + { + "download_count": 462962, + "project": "gcovr" + }, + { + "download_count": 462652, + "project": "gputil" + }, + { + "download_count": 462649, + "project": "pyexcel-xlsx" + }, + { + "download_count": 462258, + "project": "pytest-bdd" + }, + { + "download_count": 462062, + "project": "qtpy" + }, + { + "download_count": 461447, + "project": "marshmallow-jsonschema" + }, + { + "download_count": 461130, + "project": "xmlschema" + }, + { + "download_count": 461066, + "project": "log-symbols" + }, + { + "download_count": 461026, + "project": "aiopg" + }, + { + "download_count": 461021, + "project": "paypalrestsdk" + }, + { + "download_count": 459361, + "project": "bpython" + }, + { + "download_count": 459221, + "project": "django-memoize" + }, + { + "download_count": 458741, + "project": "pastescript" + }, + { + "download_count": 458467, + "project": "djangorestframework-gis" + }, + { + "download_count": 458421, + "project": "yamlordereddictloader" + }, + { + "download_count": 458237, + "project": "azure-cli-privatedns" + }, + { + "download_count": 457094, + "project": "jupyterhub" + }, + { + "download_count": 457021, + "project": "pytest-random-order" + }, + { + "download_count": 456889, + "project": "cli-helpers" + }, + { + "download_count": 456492, + "project": "django-jet" + }, + { + "download_count": 456487, + "project": "django-solo" + }, + { + "download_count": 455927, + "project": "easypkg" + }, + { + "download_count": 455745, + "project": "oslotest" + }, + { + "download_count": 455660, + "project": "td-client" + }, + { + "download_count": 455550, + "project": "docker-buildtool" + }, + { + "download_count": 455228, + "project": "pyactiveresource" + }, + { + "download_count": 455148, + "project": "filetype" + }, + { + "download_count": 454275, + "project": "integrationhelper" + }, + { + "download_count": 454060, + "project": "treeinterpreter" + }, + { + "download_count": 453726, + "project": "spinners" + }, + { + "download_count": 453478, + "project": "tinys3" + }, + { + "download_count": 452911, + "project": "google-nucleus" + }, + { + "download_count": 452905, + "project": "sfctl" + }, + { + "download_count": 452659, + "project": "wsme" + }, + { + "download_count": 452548, + "project": "cloudml-hypertune" + }, + { + "download_count": 452284, + "project": "djrill" + }, + { + "download_count": 451894, + "project": "rdflib-jsonld" + }, + { + "download_count": 451751, + "project": "pyhull" + }, + { + "download_count": 451388, + "project": "weka-easypy" + }, + { + "download_count": 451340, + "project": "zerorpc" + }, + { + "download_count": 450074, + "project": "requests-aws-sign" + }, + { + "download_count": 449859, + "project": "apns2" + }, + { + "download_count": 449829, + "project": "pytest-freezegun" + }, + { + "download_count": 449733, + "project": "logentries" + }, + { + "download_count": 449274, + "project": "polling" + }, + { + "download_count": 449144, + "project": "ner" + }, + { + "download_count": 448946, + "project": "pycuber" + }, + { + "download_count": 448187, + "project": "dfply" + }, + { + "download_count": 447960, + "project": "elasticsearch5" + }, + { + "download_count": 447647, + "project": "pyramid-debugtoolbar" + }, + { + "download_count": 447433, + "project": "dohq-artifactory" + }, + { + "download_count": 447042, + "project": "graphyte" + }, + { + "download_count": 446699, + "project": "gtts-token" + }, + { + "download_count": 446599, + "project": "s3io" + }, + { + "download_count": 446457, + "project": "pyldavis" + }, + { + "download_count": 446070, + "project": "dm-xmlsec-binding" + }, + { + "download_count": 445558, + "project": "oslo-vmware" + }, + { + "download_count": 445493, + "project": "mkdocs-minify-plugin" + }, + { + "download_count": 442789, + "project": "systemd-python" + }, + { + "download_count": 441825, + "project": "django-daterange-filter" + }, + { + "download_count": 441288, + "project": "pycld2" + }, + { + "download_count": 441011, + "project": "ffmpy" + }, + { + "download_count": 440747, + "project": "onnxruntime" + }, + { + "download_count": 440442, + "project": "pathmatch" + }, + { + "download_count": 440074, + "project": "beatbox" + }, + { + "download_count": 439695, + "project": "dotmap" + }, + { + "download_count": 439566, + "project": "atari-py" + }, + { + "download_count": 436976, + "project": "pytest-socket" + }, + { + "download_count": 436145, + "project": "matplotlib-venn" + }, + { + "download_count": 434595, + "project": "dnslib" + }, + { + "download_count": 434167, + "project": "leveldb" + }, + { + "download_count": 433865, + "project": "django-dirtyfields" + }, + { + "download_count": 433860, + "project": "shiboken2" + }, + { + "download_count": 433596, + "project": "chameleon" + }, + { + "download_count": 433574, + "project": "python-social-auth" + }, + { + "download_count": 433514, + "project": "xunitparser" + }, + { + "download_count": 433494, + "project": "tempest" + }, + { + "download_count": 433330, + "project": "django-extra-views" + }, + { + "download_count": 433032, + "project": "django-sslserver" + }, + { + "download_count": 432924, + "project": "netstorageapi" + }, + { + "download_count": 432577, + "project": "django-bootstrap-form" + }, + { + "download_count": 431716, + "project": "aio-pika" + }, + { + "download_count": 431533, + "project": "curtsies" + }, + { + "download_count": 431368, + "project": "edx-proctoring" + }, + { + "download_count": 429918, + "project": "rules" + }, + { + "download_count": 429501, + "project": "treq" + }, + { + "download_count": 429446, + "project": "python2-pythondialog" + }, + { + "download_count": 429251, + "project": "shopifyapi" + }, + { + "download_count": 429239, + "project": "pyros-genmsg" + }, + { + "download_count": 428668, + "project": "pyros-genpy" + }, + { + "download_count": 427728, + "project": "django-webtest" + }, + { + "download_count": 427374, + "project": "cpp-coveralls" + }, + { + "download_count": 426629, + "project": "hyperloglog" + }, + { + "download_count": 425518, + "project": "pathvalidate" + }, + { + "download_count": 424129, + "project": "marisa-trie" + }, + { + "download_count": 423827, + "project": "graphene-file-upload" + }, + { + "download_count": 423528, + "project": "wurlitzer" + }, + { + "download_count": 423446, + "project": "geoip" + }, + { + "download_count": 423400, + "project": "nameko" + }, + { + "download_count": 422280, + "project": "pipreqs" + }, + { + "download_count": 422034, + "project": "airbrake" + }, + { + "download_count": 421423, + "project": "python-barcode" + }, + { + "download_count": 420487, + "project": "featuretools" + }, + { + "download_count": 420463, + "project": "pydes" + }, + { + "download_count": 420080, + "project": "oss2" + }, + { + "download_count": 419064, + "project": "win-unicode-console" + }, + { + "download_count": 418651, + "project": "aiocontextvars" + }, + { + "download_count": 417979, + "project": "flake8-logging-format" + }, + { + "download_count": 417452, + "project": "aiokafka" + }, + { + "download_count": 416219, + "project": "astunparse" + }, + { + "download_count": 414872, + "project": "doit" + }, + { + "download_count": 414706, + "project": "scikit-surprise" + }, + { + "download_count": 414280, + "project": "flask-mysql" + }, + { + "download_count": 414268, + "project": "pygerrit2" + }, + { + "download_count": 412851, + "project": "requests-http-signature" + }, + { + "download_count": 412476, + "project": "django-dotenv" + }, + { + "download_count": 412152, + "project": "ffmpeg-quality-metrics" + }, + { + "download_count": 412022, + "project": "spotify-tensorflow" + }, + { + "download_count": 411026, + "project": "wsgi-intercept" + }, + { + "download_count": 410904, + "project": "breathe" + }, + { + "download_count": 410783, + "project": "google-api-python-client-uritemplate" + }, + { + "download_count": 408750, + "project": "django-ajax-selects" + }, + { + "download_count": 408606, + "project": "websocket" + }, + { + "download_count": 408486, + "project": "healthcheck" + }, + { + "download_count": 408427, + "project": "redo" + }, + { + "download_count": 408117, + "project": "pypiserver" + }, + { + "download_count": 408017, + "project": "localstack-client" + }, + { + "download_count": 407856, + "project": "fastai" + }, + { + "download_count": 407560, + "project": "django-impersonate" + }, + { + "download_count": 407287, + "project": "zipcodes" + }, + { + "download_count": 407121, + "project": "treelib" + }, + { + "download_count": 407028, + "project": "django-stubs" + }, + { + "download_count": 406712, + "project": "django-two-factor-auth" + }, + { + "download_count": 405396, + "project": "json-delta" + }, + { + "download_count": 405170, + "project": "socketio-client" + }, + { + "download_count": 405065, + "project": "gin-config" + }, + { + "download_count": 405060, + "project": "coverage-badge" + }, + { + "download_count": 404993, + "project": "django-sendgrid-v5" + }, + { + "download_count": 404902, + "project": "shutilwhich" + }, + { + "download_count": 404866, + "project": "flask-redis" + }, + { + "download_count": 404373, + "project": "pep562" + }, + { + "download_count": 404209, + "project": "niet" + }, + { + "download_count": 403508, + "project": "dask-glm" + }, + { + "download_count": 402928, + "project": "evergreen-py" + }, + { + "download_count": 402697, + "project": "zxcvbn" + }, + { + "download_count": 402692, + "project": "dataproperty" + }, + { + "download_count": 402398, + "project": "pygeohash" + }, + { + "download_count": 401062, + "project": "ast" + }, + { + "download_count": 400982, + "project": "pyobjc-core" + }, + { + "download_count": 400958, + "project": "http-ece" + }, + { + "download_count": 400803, + "project": "readline" + }, + { + "download_count": 400450, + "project": "django-elasticsearch-dsl" + }, + { + "download_count": 400436, + "project": "python-xlib" + }, + { + "download_count": 400407, + "project": "flatten-dict" + }, + { + "download_count": 399614, + "project": "gherkin-official" + }, + { + "download_count": 399263, + "project": "elementpath" + }, + { + "download_count": 399214, + "project": "gdal" + }, + { + "download_count": 399000, + "project": "roman" + }, + { + "download_count": 398885, + "project": "click-spinner" + }, + { + "download_count": 398873, + "project": "chalice" + }, + { + "download_count": 398463, + "project": "django-filer" + }, + { + "download_count": 398402, + "project": "ldclient-py" + }, + { + "download_count": 398269, + "project": "gtts" + }, + { + "download_count": 397948, + "project": "django-registration" + }, + { + "download_count": 397646, + "project": "collectfast" + }, + { + "download_count": 396999, + "project": "django-jinja" + }, + { + "download_count": 396968, + "project": "eradicate" + }, + { + "download_count": 396714, + "project": "neo4j-driver" + }, + { + "download_count": 396369, + "project": "cybox" + }, + { + "download_count": 396364, + "project": "asgi-redis" + }, + { + "download_count": 396056, + "project": "boto3-type-annotations" + }, + { + "download_count": 395861, + "project": "etcd3gw" + }, + { + "download_count": 395415, + "project": "face-recognition" + }, + { + "download_count": 395184, + "project": "os-xenapi" + }, + { + "download_count": 395153, + "project": "neo4j" + }, + { + "download_count": 394185, + "project": "pytrends" + }, + { + "download_count": 393950, + "project": "grpcio-status" + }, + { + "download_count": 393467, + "project": "sailthru-client" + }, + { + "download_count": 393315, + "project": "repoze-sendmail" + }, + { + "download_count": 393244, + "project": "bayesian-optimization" + }, + { + "download_count": 393069, + "project": "pillow-simd" + }, + { + "download_count": 392655, + "project": "inquirer" + }, + { + "download_count": 391989, + "project": "watson-developer-cloud" + }, + { + "download_count": 391807, + "project": "assertpy" + }, + { + "download_count": 391722, + "project": "chainer" + }, + { + "download_count": 391162, + "project": "aiogithubapi" + }, + { + "download_count": 391117, + "project": "pyclustering" + }, + { + "download_count": 390635, + "project": "django-test-plus" + }, + { + "download_count": 389572, + "project": "azureml-explain-model" + }, + { + "download_count": 389554, + "project": "param" + }, + { + "download_count": 388843, + "project": "smartsheet-python-sdk" + }, + { + "download_count": 388646, + "project": "google-ads" + }, + { + "download_count": 387346, + "project": "unicode-slugify" + }, + { + "download_count": 387007, + "project": "django-smtp-ssl" + }, + { + "download_count": 386636, + "project": "udatetime" + }, + { + "download_count": 386540, + "project": "pyobjc-framework-cocoa" + }, + { + "download_count": 386296, + "project": "confuse" + }, + { + "download_count": 386037, + "project": "hdfs3" + }, + { + "download_count": 385593, + "project": "moznetwork" + }, + { + "download_count": 385320, + "project": "pydot2" + }, + { + "download_count": 385150, + "project": "djangocms-admin-style" + }, + { + "download_count": 384650, + "project": "pyquaternion" + }, + { + "download_count": 384272, + "project": "xblock" + }, + { + "download_count": 384195, + "project": "flask-talisman" + }, + { + "download_count": 383670, + "project": "paver" + }, + { + "download_count": 383579, + "project": "pytorch-transformers" + }, + { + "download_count": 383499, + "project": "netdisco" + }, + { + "download_count": 383345, + "project": "kivy" + }, + { + "download_count": 383182, + "project": "django-uuidfield" + }, + { + "download_count": 382848, + "project": "jwt" + }, + { + "download_count": 382404, + "project": "logdna" + }, + { + "download_count": 382235, + "project": "relativetimebuilder" + }, + { + "download_count": 381845, + "project": "json2html" + }, + { + "download_count": 381570, + "project": "pytest-helpers-namespace" + }, + { + "download_count": 381409, + "project": "codespell" + }, + { + "download_count": 381241, + "project": "open3d-python" + }, + { + "download_count": 381173, + "project": "aws" + }, + { + "download_count": 381129, + "project": "plyfile" + }, + { + "download_count": 380993, + "project": "py-spy" + }, + { + "download_count": 380964, + "project": "aliyun-python-sdk-kms" + }, + { + "download_count": 380771, + "project": "stix" + }, + { + "download_count": 379960, + "project": "pywebpush" + }, + { + "download_count": 379915, + "project": "paramiko-expect" + }, + { + "download_count": 379467, + "project": "face-recognition-models" + }, + { + "download_count": 379302, + "project": "umap-learn" + }, + { + "download_count": 378977, + "project": "cbor2" + }, + { + "download_count": 378025, + "project": "django-redis-sessions" + }, + { + "download_count": 377737, + "project": "pymisp" + }, + { + "download_count": 377661, + "project": "django-test-without-migrations" + }, + { + "download_count": 377526, + "project": "readability-lxml" + }, + { + "download_count": 377300, + "project": "python-jsonrpc-server" + }, + { + "download_count": 377259, + "project": "yara-python" + }, + { + "download_count": 376371, + "project": "scikit-build" + }, + { + "download_count": 376213, + "project": "wasmer" + }, + { + "download_count": 376182, + "project": "django-templated-email" + }, + { + "download_count": 375778, + "project": "www-authenticate" + }, + { + "download_count": 375656, + "project": "plaid-python" + }, + { + "download_count": 375163, + "project": "mixbox" + }, + { + "download_count": 374823, + "project": "fastdiff" + }, + { + "download_count": 374712, + "project": "pyang" + }, + { + "download_count": 373785, + "project": "flake8-tidy-imports" + }, + { + "download_count": 373672, + "project": "dnspython3" + }, + { + "download_count": 373668, + "project": "twitter-common-confluence" + }, + { + "download_count": 373502, + "project": "cursive" + }, + { + "download_count": 372891, + "project": "requests-oauth" + }, + { + "download_count": 372768, + "project": "edx-opaque-keys" + }, + { + "download_count": 372679, + "project": "flake8-mutable" + }, + { + "download_count": 372516, + "project": "docxtpl" + }, + { + "download_count": 372505, + "project": "reloader" + }, + { + "download_count": 371987, + "project": "ibm-cos-sdk" + }, + { + "download_count": 371891, + "project": "python-multipart" + }, + { + "download_count": 371361, + "project": "shodan" + }, + { + "download_count": 370894, + "project": "glance-store" + }, + { + "download_count": 370618, + "project": "blobxfer" + }, + { + "download_count": 370307, + "project": "mailchimp" + }, + { + "download_count": 370281, + "project": "amazon-kclpy" + }, + { + "download_count": 369713, + "project": "azure-cli-deploymentmanager" + }, + { + "download_count": 369303, + "project": "cfscrape" + }, + { + "download_count": 369271, + "project": "gabbi" + }, + { + "download_count": 368704, + "project": "docker-registry-client" + }, + { + "download_count": 368627, + "project": "visdom" + }, + { + "download_count": 368133, + "project": "djangosaml2" + }, + { + "download_count": 367774, + "project": "torchfile" + }, + { + "download_count": 367743, + "project": "python-language-server" + }, + { + "download_count": 367741, + "project": "django-registration-redux" + }, + { + "download_count": 366408, + "project": "pypowervm" + }, + { + "download_count": 365959, + "project": "pypubsub" + }, + { + "download_count": 365726, + "project": "flake8-mypy" + }, + { + "download_count": 365550, + "project": "mixer" + }, + { + "download_count": 365313, + "project": "config" + }, + { + "download_count": 365224, + "project": "pytorch" + }, + { + "download_count": 364756, + "project": "py-geohash-any" + }, + { + "download_count": 364330, + "project": "pantsbuild-pants" + }, + { + "download_count": 364200, + "project": "strif" + }, + { + "download_count": 364189, + "project": "pgc-interface" + }, + { + "download_count": 363919, + "project": "pyrasite" + }, + { + "download_count": 363463, + "project": "browsermob-proxy" + }, + { + "download_count": 362770, + "project": "marshmallow-oneofschema" + }, + { + "download_count": 362569, + "project": "python-saml" + }, + { + "download_count": 362447, + "project": "pymc" + }, + { + "download_count": 362409, + "project": "vadersentiment" + }, + { + "download_count": 362107, + "project": "pyxero" + }, + { + "download_count": 361277, + "project": "ccxt" + }, + { + "download_count": 361145, + "project": "executor" + }, + { + "download_count": 360517, + "project": "requests-pkcs12" + }, + { + "download_count": 360423, + "project": "instaclone" + }, + { + "download_count": 360015, + "project": "exchangelib" + }, + { + "download_count": 359650, + "project": "lomond" + }, + { + "download_count": 359422, + "project": "mibian" + }, + { + "download_count": 359376, + "project": "sip" + }, + { + "download_count": 358575, + "project": "django-ordered-model" + }, + { + "download_count": 358484, + "project": "eyed3" + }, + { + "download_count": 358443, + "project": "pysendfile" + }, + { + "download_count": 358260, + "project": "nose-testconfig" + }, + { + "download_count": 358034, + "project": "delegator-py" + }, + { + "download_count": 357573, + "project": "currencyconverter" + }, + { + "download_count": 356478, + "project": "backports-lzma" + }, + { + "download_count": 356429, + "project": "p4python" + }, + { + "download_count": 356412, + "project": "zope-index" + }, + { + "download_count": 356169, + "project": "cloudflare" + }, + { + "download_count": 356004, + "project": "cql" + }, + { + "download_count": 355945, + "project": "dacite" + }, + { + "download_count": 355827, + "project": "python-cjson" + }, + { + "download_count": 355794, + "project": "marshmallow-arrow" + }, + { + "download_count": 355729, + "project": "mbstrdecoder" + }, + { + "download_count": 354987, + "project": "urlextract" + }, + { + "download_count": 354886, + "project": "typepy" + }, + { + "download_count": 354885, + "project": "htpasswd" + }, + { + "download_count": 354555, + "project": "mod-wsgi" + }, + { + "download_count": 354506, + "project": "django-cms" + }, + { + "download_count": 353955, + "project": "flask-apscheduler" + }, + { + "download_count": 353201, + "project": "pymobiledetect" + }, + { + "download_count": 353184, + "project": "times" + }, + { + "download_count": 352996, + "project": "zabbix-api" + }, + { + "download_count": 352927, + "project": "bcdoc" + }, + { + "download_count": 352725, + "project": "torchtext" + }, + { + "download_count": 352313, + "project": "flashtext" + }, + { + "download_count": 351678, + "project": "referer-parser" + }, + { + "download_count": 350758, + "project": "pyexcel-xls" + }, + { + "download_count": 350681, + "project": "edx-drf-extensions" + }, + { + "download_count": 350665, + "project": "falcon-multipart" + }, + { + "download_count": 350619, + "project": "inotify" + }, + { + "download_count": 350184, + "project": "tpot" + }, + { + "download_count": 349490, + "project": "mypy-protobuf" + }, + { + "download_count": 349330, + "project": "pygit2" + }, + { + "download_count": 348567, + "project": "robotbackgroundlogger" + }, + { + "download_count": 348256, + "project": "traces" + }, + { + "download_count": 348166, + "project": "django-extra-fields" + }, + { + "download_count": 348009, + "project": "rook" + }, + { + "download_count": 348008, + "project": "ssh2-python" + }, + { + "download_count": 347979, + "project": "jupytext" + }, + { + "download_count": 347497, + "project": "optunity" + }, + { + "download_count": 347125, + "project": "django-safedelete" + }, + { + "download_count": 347040, + "project": "django-jsonview" + }, + { + "download_count": 347003, + "project": "allure-behave" + }, + { + "download_count": 346883, + "project": "forex-python" + }, + { + "download_count": 346742, + "project": "logger" + }, + { + "download_count": 346329, + "project": "django-choices" + }, + { + "download_count": 345484, + "project": "xdis" + }, + { + "download_count": 345296, + "project": "django-babel" + }, + { + "download_count": 345262, + "project": "parse-accept-language" + }, + { + "download_count": 344856, + "project": "scons" + }, + { + "download_count": 344819, + "project": "klein" + }, + { + "download_count": 344742, + "project": "flask-shell-ipython" + }, + { + "download_count": 344586, + "project": "amqplib" + }, + { + "download_count": 344301, + "project": "betamax" + }, + { + "download_count": 344260, + "project": "flask-basicauth" + }, + { + "download_count": 344021, + "project": "pybarcode" + }, + { + "download_count": 343992, + "project": "pytest-json" + }, + { + "download_count": 343912, + "project": "uiautomation" + }, + { + "download_count": 343788, + "project": "pyemd" + }, + { + "download_count": 343547, + "project": "flufl-enum" + }, + { + "download_count": 342092, + "project": "normality" + }, + { + "download_count": 341312, + "project": "osc-placement" + }, + { + "download_count": 340998, + "project": "pytest-parallel" + }, + { + "download_count": 340763, + "project": "crochet" + }, + { + "download_count": 340105, + "project": "proximityhash" + }, + { + "download_count": 339952, + "project": "pyscss" + }, + { + "download_count": 339480, + "project": "python-qpid-proton" + }, + { + "download_count": 339302, + "project": "vtk" + }, + { + "download_count": 338910, + "project": "hmmlearn" + }, + { + "download_count": 338542, + "project": "pyqtwebengine" + }, + { + "download_count": 337957, + "project": "django-watchman" + }, + { + "download_count": 337701, + "project": "python-igraph" + }, + { + "download_count": 337586, + "project": "edxval" + }, + { + "download_count": 337501, + "project": "ibm-cos-sdk-core" + }, + { + "download_count": 337200, + "project": "edx-django-utils" + }, + { + "download_count": 336856, + "project": "ibm-cos-sdk-s3transfer" + }, + { + "download_count": 336294, + "project": "spark-nlp" + }, + { + "download_count": 335964, + "project": "rhea" + }, + { + "download_count": 335873, + "project": "exifread" + }, + { + "download_count": 335709, + "project": "tensorflow-estimator-2-0-preview" + }, + { + "download_count": 335463, + "project": "python-binary-memcached" + }, + { + "download_count": 335218, + "project": "spyder" + }, + { + "download_count": 334977, + "project": "rstr" + }, + { + "download_count": 334204, + "project": "asteval" + }, + { + "download_count": 333818, + "project": "uncompyle6" + }, + { + "download_count": 333754, + "project": "requests-async" + }, + { + "download_count": 333266, + "project": "kaitaistruct" + }, + { + "download_count": 332129, + "project": "multiprocessing" + }, + { + "download_count": 332061, + "project": "chromedriver" + }, + { + "download_count": 332013, + "project": "iso-639" + }, + { + "download_count": 331946, + "project": "daiquiri" + }, + { + "download_count": 331588, + "project": "tendo" + }, + { + "download_count": 331525, + "project": "spark-parser" + }, + { + "download_count": 331379, + "project": "setuptools-git-version" + }, + { + "download_count": 331153, + "project": "priority" + }, + { + "download_count": 330940, + "project": "cachelib" + }, + { + "download_count": 330879, + "project": "os-ken" + }, + { + "download_count": 330608, + "project": "microversion-parse" + }, + { + "download_count": 329253, + "project": "django-contrib-comments" + }, + { + "download_count": 329155, + "project": "o365" + }, + { + "download_count": 328801, + "project": "panda" + }, + { + "download_count": 328625, + "project": "ed25519" + }, + { + "download_count": 327877, + "project": "pyxb" + }, + { + "download_count": 327798, + "project": "rest-condition" + }, + { + "download_count": 327008, + "project": "pandavro" + }, + { + "download_count": 326932, + "project": "flask-autoindex" + }, + { + "download_count": 326745, + "project": "jieba3k" + }, + { + "download_count": 326444, + "project": "pipfile" + }, + { + "download_count": 325679, + "project": "js2xml" + }, + { + "download_count": 325610, + "project": "freetype-py" + }, + { + "download_count": 325570, + "project": "sigopt" + }, + { + "download_count": 325566, + "project": "flask-silk" + }, + { + "download_count": 325431, + "project": "pynvim" + }, + { + "download_count": 324936, + "project": "hunspell" + }, + { + "download_count": 324782, + "project": "pytest-localserver" + }, + { + "download_count": 324466, + "project": "genshi" + }, + { + "download_count": 324252, + "project": "pyqtgraph" + }, + { + "download_count": 324239, + "project": "backport-collections" + }, + { + "download_count": 324070, + "project": "daemonize" + }, + { + "download_count": 324045, + "project": "pafy" + }, + { + "download_count": 323910, + "project": "pyvcloud" + }, + { + "download_count": 322541, + "project": "imapclient" + }, + { + "download_count": 321480, + "project": "tika" + }, + { + "download_count": 321355, + "project": "simplekv" + }, + { + "download_count": 321196, + "project": "rtslib-fb" + }, + { + "download_count": 321126, + "project": "flake8-colors" + }, + { + "download_count": 321035, + "project": "helper" + }, + { + "download_count": 320909, + "project": "guessit" + }, + { + "download_count": 320580, + "project": "ryu" + }, + { + "download_count": 320316, + "project": "salt" + }, + { + "download_count": 320262, + "project": "flexmock" + }, + { + "download_count": 320230, + "project": "pytils" + }, + { + "download_count": 320212, + "project": "phik" + }, + { + "download_count": 319164, + "project": "sphinx-bootstrap-theme" + }, + { + "download_count": 319042, + "project": "flake8-pep3101" + }, + { + "download_count": 318722, + "project": "turicreate" + }, + { + "download_count": 318705, + "project": "attr" + }, + { + "download_count": 318586, + "project": "spyder-kernels" + }, + { + "download_count": 318398, + "project": "drf-writable-nested" + }, + { + "download_count": 318092, + "project": "future-fstrings" + }, + { + "download_count": 317793, + "project": "python-mistralclient" + }, + { + "download_count": 317688, + "project": "fuzzy" + }, + { + "download_count": 317529, + "project": "pyxlsb" + }, + { + "download_count": 317467, + "project": "twitter" + }, + { + "download_count": 317447, + "project": "slumber" + }, + { + "download_count": 316898, + "project": "protobuf-to-dict" + }, + { + "download_count": 316783, + "project": "djangorestframework-recursive" + }, + { + "download_count": 316760, + "project": "treeherder-client" + }, + { + "download_count": 316758, + "project": "python-nomad" + }, + { + "download_count": 316352, + "project": "click-default-group" + }, + { + "download_count": 316307, + "project": "logzero" + }, + { + "download_count": 316290, + "project": "orionsdk" + }, + { + "download_count": 316243, + "project": "sanic-cors" + }, + { + "download_count": 316239, + "project": "fastdtw" + }, + { + "download_count": 315929, + "project": "python-moztelemetry" + }, + { + "download_count": 315911, + "project": "pytest-azurepipelines" + }, + { + "download_count": 315673, + "project": "expects" + }, + { + "download_count": 314691, + "project": "feedfinder2" + }, + { + "download_count": 314446, + "project": "multimethod" + }, + { + "download_count": 314259, + "project": "janome" + }, + { + "download_count": 314133, + "project": "voluptuous-serialize" + }, + { + "download_count": 314097, + "project": "pyculiar" + }, + { + "download_count": 314051, + "project": "mozdownload" + }, + { + "download_count": 313826, + "project": "pylzma" + }, + { + "download_count": 313796, + "project": "qtawesome" + }, + { + "download_count": 313736, + "project": "everett" + }, + { + "download_count": 313653, + "project": "coincurve" + }, + { + "download_count": 313244, + "project": "characteristic" + }, + { + "download_count": 312696, + "project": "python-can" + }, + { + "download_count": 312614, + "project": "planout" + }, + { + "download_count": 312044, + "project": "submit50" + }, + { + "download_count": 312044, + "project": "transformers" + }, + { + "download_count": 311745, + "project": "django-celery-email" + }, + { + "download_count": 311632, + "project": "check50" + }, + { + "download_count": 311531, + "project": "ansimarkup" + }, + { + "download_count": 311273, + "project": "flatdict" + }, + { + "download_count": 311140, + "project": "minimal-snowplow-tracker" + }, + { + "download_count": 311122, + "project": "python-troveclient" + }, + { + "download_count": 310826, + "project": "pycpfcnpj" + }, + { + "download_count": 310446, + "project": "python-lzf" + }, + { + "download_count": 310429, + "project": "apsw" + }, + { + "download_count": 310269, + "project": "stem" + }, + { + "download_count": 310019, + "project": "mozinstall" + }, + { + "download_count": 309655, + "project": "os-resource-classes" + }, + { + "download_count": 309355, + "project": "mimeparse" + }, + { + "download_count": 309293, + "project": "comet-ml" + }, + { + "download_count": 309286, + "project": "serpy" + }, + { + "download_count": 309092, + "project": "skimage" + }, + { + "download_count": 308894, + "project": "pandas-ml" + }, + { + "download_count": 308548, + "project": "python-magnumclient" + }, + { + "download_count": 307984, + "project": "azure-devtools" + }, + { + "download_count": 307690, + "project": "typesentry" + }, + { + "download_count": 307277, + "project": "awslogs" + }, + { + "download_count": 306928, + "project": "pytest-flakes" + }, + { + "download_count": 306784, + "project": "thespian" + }, + { + "download_count": 305826, + "project": "pykcs11" + }, + { + "download_count": 305226, + "project": "singer-python" + }, + { + "download_count": 304755, + "project": "pyprind" + }, + { + "download_count": 304717, + "project": "abbyy" + }, + { + "download_count": 304490, + "project": "flask-restful-swagger" + }, + { + "download_count": 304399, + "project": "os-api-ref" + }, + { + "download_count": 304195, + "project": "simpleitk" + }, + { + "download_count": 304060, + "project": "unicorn" + }, + { + "download_count": 304021, + "project": "jobspy" + }, + { + "download_count": 303998, + "project": "devpi-common" + }, + { + "download_count": 303970, + "project": "jsonpath" + }, + { + "download_count": 303806, + "project": "pysubnettree" + }, + { + "download_count": 303693, + "project": "hypercorn" + }, + { + "download_count": 303592, + "project": "scrapy-random-useragent" + }, + { + "download_count": 303497, + "project": "zope-schema" + }, + { + "download_count": 303260, + "project": "newspaper3k" + }, + { + "download_count": 302739, + "project": "pyspellchecker" + }, + { + "download_count": 302714, + "project": "password" + }, + { + "download_count": 302400, + "project": "testlink-api-python-client" + }, + { + "download_count": 302299, + "project": "dogpile-core" + }, + { + "download_count": 302266, + "project": "nilearn" + }, + { + "download_count": 302076, + "project": "pylibftdi" + }, + { + "download_count": 301868, + "project": "python-termstyle" + }, + { + "download_count": 301830, + "project": "pybreaker" + }, + { + "download_count": 301435, + "project": "django-wkhtmltopdf" + }, + { + "download_count": 300585, + "project": "pyxdameraulevenshtein" + }, + { + "download_count": 300425, + "project": "hpsklearn" + }, + { + "download_count": 300421, + "project": "tesserocr" + }, + { + "download_count": 300359, + "project": "django-templated-mail" + }, + { + "download_count": 300207, + "project": "comet-git-pure" + }, + { + "download_count": 299910, + "project": "httpcore" + }, + { + "download_count": 299706, + "project": "simhash" + }, + { + "download_count": 299276, + "project": "aspy-refactor-imports" + }, + { + "download_count": 298943, + "project": "fcm-django" + }, + { + "download_count": 298927, + "project": "flask-jwt" + }, + { + "download_count": 298823, + "project": "serial" + }, + { + "download_count": 298802, + "project": "binary" + }, + { + "download_count": 298544, + "project": "plaidml" + }, + { + "download_count": 298085, + "project": "python-oauth2" + }, + { + "download_count": 297969, + "project": "opencv-contrib-python-headless" + }, + { + "download_count": 297585, + "project": "djangocms-text-ckeditor" + }, + { + "download_count": 297361, + "project": "better-exceptions-fork" + }, + { + "download_count": 297253, + "project": "dynamodb-json" + }, + { + "download_count": 297052, + "project": "bitmath" + }, + { + "download_count": 296269, + "project": "condor-git-config" + }, + { + "download_count": 296162, + "project": "cornice" + }, + { + "download_count": 295986, + "project": "polyglot" + }, + { + "download_count": 295722, + "project": "pytelegrambotapi" + }, + { + "download_count": 295667, + "project": "mbed-cloud-sdk" + }, + { + "download_count": 295592, + "project": "behave-django" + }, + { + "download_count": 295509, + "project": "modernize" + }, + { + "download_count": 295419, + "project": "libusb1" + }, + { + "download_count": 295355, + "project": "edx-organizations" + }, + { + "download_count": 294743, + "project": "sendgrid-django" + }, + { + "download_count": 294453, + "project": "sniffio" + }, + { + "download_count": 294364, + "project": "slugid" + }, + { + "download_count": 294093, + "project": "pypika" + }, + { + "download_count": 293799, + "project": "oci-cli" + }, + { + "download_count": 293404, + "project": "django-rosetta" + }, + { + "download_count": 293277, + "project": "proxmoxer" + }, + { + "download_count": 292761, + "project": "anytemplate" + }, + { + "download_count": 292649, + "project": "raven-aiohttp" + }, + { + "download_count": 292327, + "project": "bbcode" + }, + { + "download_count": 292281, + "project": "protego" + }, + { + "download_count": 292277, + "project": "securesystemslib" + }, + { + "download_count": 292249, + "project": "outcome" + }, + { + "download_count": 291695, + "project": "crontab" + }, + { + "download_count": 291636, + "project": "pytelegraf" + }, + { + "download_count": 291495, + "project": "pylbfgs" + }, + { + "download_count": 291341, + "project": "asttokens" + }, + { + "download_count": 291275, + "project": "wtforms-components" + }, + { + "download_count": 291039, + "project": "elasticsearch-async" + }, + { + "download_count": 290811, + "project": "py-dateutil" + }, + { + "download_count": 290793, + "project": "buildbot-worker" + }, + { + "download_count": 290753, + "project": "atpublic" + }, + { + "download_count": 290628, + "project": "django-cleanup" + }, + { + "download_count": 290574, + "project": "urlopen" + }, + { + "download_count": 290457, + "project": "cleanco" + }, + { + "download_count": 290025, + "project": "home-assistant-frontend" + }, + { + "download_count": 289983, + "project": "azureml-widgets" + }, + { + "download_count": 289907, + "project": "pycallgraph" + }, + { + "download_count": 289633, + "project": "biplist" + }, + { + "download_count": 289587, + "project": "django-datatables-view" + }, + { + "download_count": 289573, + "project": "guppy" + }, + { + "download_count": 289366, + "project": "kaggle" + }, + { + "download_count": 289053, + "project": "ratelimiter" + }, + { + "download_count": 288392, + "project": "requests-aws" + }, + { + "download_count": 288145, + "project": "prov" + }, + { + "download_count": 288066, + "project": "xmodem" + }, + { + "download_count": 287756, + "project": "pyobjc-framework-fsevents" + }, + { + "download_count": 287736, + "project": "djangorestframework-stubs" + }, + { + "download_count": 287716, + "project": "dailymotion" + }, + { + "download_count": 287610, + "project": "airspeed" + }, + { + "download_count": 287211, + "project": "pdfminer3k" + }, + { + "download_count": 286932, + "project": "django-admin-tools" + }, + { + "download_count": 286676, + "project": "rfc3339" + }, + { + "download_count": 286568, + "project": "runlike" + }, + { + "download_count": 286494, + "project": "pyobjc-framework-systemconfiguration" + }, + { + "download_count": 286287, + "project": "flask-swagger-ui" + }, + { + "download_count": 286286, + "project": "pyrabbit" + }, + { + "download_count": 286217, + "project": "pyobjc-framework-cfnetwork" + }, + { + "download_count": 285962, + "project": "django-htmlmin" + }, + { + "download_count": 285937, + "project": "affinegap" + }, + { + "download_count": 285640, + "project": "django-smart-selects" + }, + { + "download_count": 285368, + "project": "jaraco-classes" + }, + { + "download_count": 285182, + "project": "pyjq" + }, + { + "download_count": 284862, + "project": "plaidml-keras" + }, + { + "download_count": 284806, + "project": "pyobjc-framework-webkit" + }, + { + "download_count": 284790, + "project": "jq" + }, + { + "download_count": 284781, + "project": "django-taggit-serializer" + }, + { + "download_count": 284424, + "project": "robotframework-databaselibrary" + }, + { + "download_count": 284410, + "project": "httpsig-cffi" + }, + { + "download_count": 284050, + "project": "instaloader" + }, + { + "download_count": 284049, + "project": "powerline-status" + }, + { + "download_count": 283986, + "project": "tap-py" + }, + { + "download_count": 283939, + "project": "devpi-client" + }, + { + "download_count": 283785, + "project": "banal" + }, + { + "download_count": 283663, + "project": "docx" + }, + { + "download_count": 283563, + "project": "python-geoip-geolite2" + }, + { + "download_count": 283441, + "project": "bitstruct" + }, + { + "download_count": 283402, + "project": "pyramid-jinja2" + }, + { + "download_count": 283279, + "project": "graphitesend" + }, + { + "download_count": 283227, + "project": "metafone" + }, + { + "download_count": 283149, + "project": "tinysegmenter" + }, + { + "download_count": 282747, + "project": "sqlalchemy-continuum" + }, + { + "download_count": 282696, + "project": "opencensus-ext-stackdriver" + }, + { + "download_count": 282668, + "project": "waiter" + }, + { + "download_count": 282655, + "project": "sphinx-gallery" + }, + { + "download_count": 282575, + "project": "git-pylint-commit-hook" + }, + { + "download_count": 282479, + "project": "fuzzyset" + }, + { + "download_count": 282254, + "project": "pytest-custom-exit-code" + }, + { + "download_count": 281823, + "project": "hyperas" + }, + { + "download_count": 281726, + "project": "django-simple-captcha" + }, + { + "download_count": 281640, + "project": "dynamodb-encryption-sdk" + }, + { + "download_count": 281597, + "project": "openexr" + }, + { + "download_count": 281522, + "project": "pid" + }, + { + "download_count": 281467, + "project": "irc3-plugins-test" + }, + { + "download_count": 280788, + "project": "murmurhash3" + }, + { + "download_count": 280402, + "project": "quart" + }, + { + "download_count": 280081, + "project": "salesforce-bulkipy" + }, + { + "download_count": 279935, + "project": "sphinx-argparse" + }, + { + "download_count": 279690, + "project": "pptree" + }, + { + "download_count": 279227, + "project": "djangorestframework-jsonapi" + }, + { + "download_count": 279117, + "project": "marshmallow-polyfield" + }, + { + "download_count": 278996, + "project": "tls-syslog" + }, + { + "download_count": 278801, + "project": "fastprogress" + }, + { + "download_count": 278661, + "project": "style" + }, + { + "download_count": 278616, + "project": "pyjsparser" + }, + { + "download_count": 278381, + "project": "celery-redbeat" + }, + { + "download_count": 278041, + "project": "dbutils" + }, + { + "download_count": 277922, + "project": "zvmcloudconnector" + }, + { + "download_count": 277703, + "project": "blockdiag" + }, + { + "download_count": 277555, + "project": "jsl" + }, + { + "download_count": 277355, + "project": "aiomysql" + }, + { + "download_count": 277155, + "project": "softlayer" + }, + { + "download_count": 276993, + "project": "levenshtein-search" + }, + { + "download_count": 276886, + "project": "gender-guesser" + }, + { + "download_count": 276825, + "project": "msal" + }, + { + "download_count": 276567, + "project": "sqlalchemy-stubs" + }, + { + "download_count": 276536, + "project": "pyliblzma" + }, + { + "download_count": 276486, + "project": "django-sass-processor" + }, + { + "download_count": 276464, + "project": "django-url-filter" + }, + { + "download_count": 276353, + "project": "sanic-plugins-framework" + }, + { + "download_count": 276240, + "project": "jxmlease" + }, + { + "download_count": 275861, + "project": "purl" + }, + { + "download_count": 275254, + "project": "base36" + }, + { + "download_count": 275159, + "project": "pytools" + }, + { + "download_count": 275147, + "project": "datrie" + }, + { + "download_count": 274643, + "project": "zxcvbn-python" + }, + { + "download_count": 274395, + "project": "pytest-datafiles" + }, + { + "download_count": 273920, + "project": "pyspark-stubs" + }, + { + "download_count": 273728, + "project": "natto-py" + }, + { + "download_count": 273719, + "project": "mechanicalsoup" + }, + { + "download_count": 273603, + "project": "sqlalchemy-postgres-copy" + }, + { + "download_count": 273574, + "project": "pycosat" + }, + { + "download_count": 273348, + "project": "q" + }, + { + "download_count": 273202, + "project": "backpack" + }, + { + "download_count": 273056, + "project": "gmplot" + }, + { + "download_count": 273050, + "project": "websockify" + }, + { + "download_count": 273001, + "project": "measurement" + }, + { + "download_count": 272990, + "project": "hass-nabucasa" + }, + { + "download_count": 272948, + "project": "virtualenvwrapper-win" + }, + { + "download_count": 272942, + "project": "email" + }, + { + "download_count": 272542, + "project": "pyobjc-framework-launchservices" + }, + { + "download_count": 272383, + "project": "webdriver-manager" + }, + { + "download_count": 272315, + "project": "google-oauth" + }, + { + "download_count": 272029, + "project": "django-js-reverse" + }, + { + "download_count": 271929, + "project": "meinheld" + }, + { + "download_count": 271914, + "project": "yapsy" + }, + { + "download_count": 271877, + "project": "nteract-scrapbook" + }, + { + "download_count": 271874, + "project": "mouseinfo" + }, + { + "download_count": 271864, + "project": "pyobjc-framework-exceptionhandling" + }, + { + "download_count": 271786, + "project": "dbt" + }, + { + "download_count": 271483, + "project": "django-tagging" + }, + { + "download_count": 271439, + "project": "taskcluster" + }, + { + "download_count": 271349, + "project": "evdev" + }, + { + "download_count": 270918, + "project": "dedupe-hcluster" + }, + { + "download_count": 270898, + "project": "tensor2tensor" + }, + { + "download_count": 270014, + "project": "pymacaroons" + }, + { + "download_count": 269770, + "project": "kivy-garden" + }, + { + "download_count": 269533, + "project": "nine" + }, + { + "download_count": 269249, + "project": "highered" + }, + { + "download_count": 269216, + "project": "sounddevice" + }, + { + "download_count": 268421, + "project": "docx2txt" + }, + { + "download_count": 268411, + "project": "robotframework-debuglibrary" + }, + { + "download_count": 268172, + "project": "aioamqp" + }, + { + "download_count": 268107, + "project": "cma" + }, + { + "download_count": 267772, + "project": "netstruct" + }, + { + "download_count": 267766, + "project": "pyhacrf-datamade" + }, + { + "download_count": 267588, + "project": "flake8-junit-report" + }, + { + "download_count": 267292, + "project": "wptools" + }, + { + "download_count": 266807, + "project": "bump2version" + }, + { + "download_count": 266733, + "project": "lesscpy" + }, + { + "download_count": 266561, + "project": "pytest-vcr" + }, + { + "download_count": 266544, + "project": "pyexcel-webio" + }, + { + "download_count": 266422, + "project": "maya" + }, + { + "download_count": 266355, + "project": "robotframework-xvfb" + }, + { + "download_count": 266132, + "project": "dedupe" + }, + { + "download_count": 266017, + "project": "pyminifier" + }, + { + "download_count": 265818, + "project": "winkerberos" + }, + { + "download_count": 265798, + "project": "mozanalysis" + }, + { + "download_count": 265437, + "project": "username-generator" + }, + { + "download_count": 265328, + "project": "phpserialize" + }, + { + "download_count": 265105, + "project": "crc32c" + }, + { + "download_count": 264933, + "project": "pretrainedmodels" + }, + { + "download_count": 264845, + "project": "pytest-remotedata" + }, + { + "download_count": 264729, + "project": "python-owasp-zap-v2-4" + }, + { + "download_count": 264669, + "project": "nexpose" + }, + { + "download_count": 264414, + "project": "http-parser" + }, + { + "download_count": 264412, + "project": "pyobjc-framework-diskarbitration" + }, + { + "download_count": 264322, + "project": "dsp3" + }, + { + "download_count": 264189, + "project": "rlr" + }, + { + "download_count": 263902, + "project": "pyqt5-tools" + }, + { + "download_count": 263840, + "project": "json-tricks" + }, + { + "download_count": 263390, + "project": "categorical-distance" + }, + { + "download_count": 263282, + "project": "datalab" + }, + { + "download_count": 263021, + "project": "update" + }, + { + "download_count": 262783, + "project": "blobfile" + }, + { + "download_count": 262644, + "project": "zc-buildout" + }, + { + "download_count": 262529, + "project": "dedupe-variable-datetime" + }, + { + "download_count": 262152, + "project": "simplecosine" + }, + { + "download_count": 261988, + "project": "pytest-mockito" + }, + { + "download_count": 261860, + "project": "django-otp-twilio" + }, + { + "download_count": 261797, + "project": "django-chartit" + }, + { + "download_count": 261611, + "project": "datetime-distance" + }, + { + "download_count": 260878, + "project": "jaraco-text" + }, + { + "download_count": 260837, + "project": "fastrlock" + }, + { + "download_count": 260816, + "project": "flake8-future-import" + }, + { + "download_count": 260795, + "project": "pyghmi" + }, + { + "download_count": 260576, + "project": "orator" + }, + { + "download_count": 260536, + "project": "flake8-tuple" + }, + { + "download_count": 260250, + "project": "aiocache" + }, + { + "download_count": 260202, + "project": "cli53" + }, + { + "download_count": 260043, + "project": "untokenize" + }, + { + "download_count": 259904, + "project": "newrelic-plugin-agent" + }, + { + "download_count": 259773, + "project": "pyangbind" + }, + { + "download_count": 259756, + "project": "django-pyodbc-azure" + }, + { + "download_count": 259273, + "project": "zstd" + }, + { + "download_count": 258974, + "project": "pymodbus" + }, + { + "download_count": 258942, + "project": "jupyter-spark" + }, + { + "download_count": 258875, + "project": "django-sortedm2m" + }, + { + "download_count": 258300, + "project": "python-logstash-async" + }, + { + "download_count": 258254, + "project": "django-graphql-jwt" + }, + { + "download_count": 257389, + "project": "elasticquery" + }, + { + "download_count": 257227, + "project": "python-keycloak" + }, + { + "download_count": 257086, + "project": "dbus-python" + }, + { + "download_count": 257005, + "project": "cmarkgfm" + }, + { + "download_count": 256972, + "project": "pysrt" + }, + { + "download_count": 256801, + "project": "pyobjc-framework-coreservices" + }, + { + "download_count": 256683, + "project": "django-paypal" + }, + { + "download_count": 256576, + "project": "spur" + }, + { + "download_count": 256447, + "project": "iniparse" + }, + { + "download_count": 256111, + "project": "python-terraform" + }, + { + "download_count": 255860, + "project": "djangorestframework-jsonp" + }, + { + "download_count": 255835, + "project": "rethinkdb" + }, + { + "download_count": 255719, + "project": "mozcrash" + }, + { + "download_count": 255201, + "project": "pyobjc-framework-quartz" + }, + { + "download_count": 254935, + "project": "django-organizations" + }, + { + "download_count": 254677, + "project": "django-colorfield" + }, + { + "download_count": 254646, + "project": "marshmallow-jsonapi" + }, + { + "download_count": 254107, + "project": "djangorestframework-expander" + }, + { + "download_count": 253885, + "project": "dci-utils" + }, + { + "download_count": 253884, + "project": "pql" + }, + { + "download_count": 253867, + "project": "tf-nightly-2-0-preview" + }, + { + "download_count": 253608, + "project": "django-parler" + }, + { + "download_count": 253475, + "project": "telethon" + }, + { + "download_count": 253099, + "project": "celery-once" + }, + { + "download_count": 253054, + "project": "scales" + }, + { + "download_count": 253035, + "project": "rocketchat-api" + }, + { + "download_count": 252896, + "project": "jaraco-collections" + }, + { + "download_count": 252760, + "project": "yaql" + }, + { + "download_count": 252588, + "project": "pyinquirer" + }, + { + "download_count": 252471, + "project": "django-session-security" + }, + { + "download_count": 252413, + "project": "django-rest-knox" + }, + { + "download_count": 252295, + "project": "django-redshift-backend" + }, + { + "download_count": 251901, + "project": "sphinx-markdown-tables" + }, + { + "download_count": 251862, + "project": "sceptre" + }, + { + "download_count": 251840, + "project": "py-mini-racer" + }, + { + "download_count": 251759, + "project": "python-rake" + }, + { + "download_count": 251594, + "project": "oauth2-client" + }, + { + "download_count": 251347, + "project": "env" + }, + { + "download_count": 251337, + "project": "timedelta" + }, + { + "download_count": 250784, + "project": "awkward" + }, + { + "download_count": 250362, + "project": "edx-rbac" + }, + { + "download_count": 250192, + "project": "flask-log-request-id" + }, + { + "download_count": 250110, + "project": "globre" + }, + { + "download_count": 249752, + "project": "django-easy-pdf" + }, + { + "download_count": 249646, + "project": "prettyexc" + }, + { + "download_count": 249416, + "project": "django-notifications-hq" + }, + { + "download_count": 249316, + "project": "mozleak" + }, + { + "download_count": 249286, + "project": "autograd-gamma" + }, + { + "download_count": 249216, + "project": "flask-injector" + }, + { + "download_count": 249101, + "project": "holoviews" + }, + { + "download_count": 249064, + "project": "inflector" + }, + { + "download_count": 248895, + "project": "django-honeypot" + }, + { + "download_count": 248839, + "project": "pip-api" + }, + { + "download_count": 248670, + "project": "pytest-testmon" + }, + { + "download_count": 248527, + "project": "pycapnp" + }, + { + "download_count": 248395, + "project": "pgpy" + }, + { + "download_count": 248134, + "project": "pretend" + }, + { + "download_count": 247952, + "project": "webhelpers" + }, + { + "download_count": 247612, + "project": "iso4217" + }, + { + "download_count": 247588, + "project": "chargebee" + }, + { + "download_count": 247194, + "project": "logging-tree" + }, + { + "download_count": 247097, + "project": "bcolz" + }, + { + "download_count": 247095, + "project": "pydomo" + }, + { + "download_count": 247093, + "project": "pyviz-comms" + }, + { + "download_count": 246905, + "project": "pyes" + }, + { + "download_count": 246637, + "project": "patool" + }, + { + "download_count": 246609, + "project": "django-saml2-auth" + }, + { + "download_count": 246442, + "project": "lorem" + }, + { + "download_count": 246345, + "project": "kociemba" + }, + { + "download_count": 245924, + "project": "nylas" + }, + { + "download_count": 245599, + "project": "urlparse3" + }, + { + "download_count": 245592, + "project": "pytest-tornado" + }, + { + "download_count": 245425, + "project": "inject" + }, + { + "download_count": 244242, + "project": "tabledata" + }, + { + "download_count": 244197, + "project": "percy" + }, + { + "download_count": 243680, + "project": "snitun" + }, + { + "download_count": 243665, + "project": "django-debug-toolbar-line-profiler" + }, + { + "download_count": 243077, + "project": "bottlenose" + }, + { + "download_count": 242781, + "project": "infi-clickhouse-orm" + }, + { + "download_count": 242659, + "project": "reppy" + }, + { + "download_count": 242378, + "project": "in-toto" + }, + { + "download_count": 242112, + "project": "azureml" + }, + { + "download_count": 242067, + "project": "django-common-helpers" + }, + { + "download_count": 241994, + "project": "django-hijack-admin" + }, + { + "download_count": 241868, + "project": "cmreshandler" + }, + { + "download_count": 241645, + "project": "ruptures" + }, + { + "download_count": 241594, + "project": "goslate" + }, + { + "download_count": 241370, + "project": "aggdraw" + }, + { + "download_count": 241223, + "project": "django-boto" + }, + { + "download_count": 240546, + "project": "svn" + }, + { + "download_count": 240121, + "project": "ssh" + }, + { + "download_count": 240049, + "project": "py3dns" + }, + { + "download_count": 239971, + "project": "pymonkey" + }, + { + "download_count": 239838, + "project": "great-expectations" + }, + { + "download_count": 239830, + "project": "pip-custom-platform" + }, + { + "download_count": 239729, + "project": "django-libsass" + }, + { + "download_count": 239683, + "project": "mirakuru" + }, + { + "download_count": 239680, + "project": "microsoftgraph-python" + }, + { + "download_count": 239524, + "project": "gnocchiclient" + }, + { + "download_count": 239407, + "project": "pyct" + }, + { + "download_count": 239390, + "project": "ansible-runner" + }, + { + "download_count": 239360, + "project": "dbt-core" + }, + { + "download_count": 239183, + "project": "hellosign-python-sdk" + }, + { + "download_count": 239095, + "project": "pyaudioanalysis" + }, + { + "download_count": 239001, + "project": "reportportal-client" + }, + { + "download_count": 238983, + "project": "itunes-iap" + }, + { + "download_count": 238603, + "project": "terminalone" + }, + { + "download_count": 238597, + "project": "snaptime" + }, + { + "download_count": 238394, + "project": "aiormq" + }, + { + "download_count": 238154, + "project": "djangocms-attributes-field" + }, + { + "download_count": 238141, + "project": "django-versatileimagefield" + }, + { + "download_count": 237972, + "project": "django-push-notifications" + }, + { + "download_count": 237750, + "project": "transliterate" + }, + { + "download_count": 237652, + "project": "whaaaaat" + }, + { + "download_count": 237622, + "project": "django-sslify" + }, + { + "download_count": 237558, + "project": "towncrier" + }, + { + "download_count": 237018, + "project": "py-lz4framed" + }, + { + "download_count": 236912, + "project": "uproot-methods" + }, + { + "download_count": 236619, + "project": "django-statici18n" + }, + { + "download_count": 236529, + "project": "pytd" + }, + { + "download_count": 236270, + "project": "pep517" + }, + { + "download_count": 236180, + "project": "py-ecc" + }, + { + "download_count": 236180, + "project": "layered-yaml-attrdict-config" + }, + { + "download_count": 235952, + "project": "varint" + }, + { + "download_count": 235921, + "project": "spotipy" + }, + { + "download_count": 235732, + "project": "django-markdown-deux" + }, + { + "download_count": 235635, + "project": "geventhttpclient-wheels" + }, + { + "download_count": 235481, + "project": "parallel-ssh" + }, + { + "download_count": 235241, + "project": "event-tracking" + }, + { + "download_count": 234835, + "project": "jupyterthemes" + }, + { + "download_count": 234721, + "project": "django-pandas" + }, + { + "download_count": 234582, + "project": "stackprinter" + }, + { + "download_count": 234393, + "project": "probablepeople" + }, + { + "download_count": 234334, + "project": "flake8-eradicate" + }, + { + "download_count": 234277, + "project": "mode" + }, + { + "download_count": 234271, + "project": "asset" + }, + { + "download_count": 234150, + "project": "loggly-python-handler" + }, + { + "download_count": 233705, + "project": "supervisor-wildcards" + }, + { + "download_count": 233601, + "project": "edx-bulk-grades" + }, + { + "download_count": 233407, + "project": "glean-parser" + }, + { + "download_count": 233242, + "project": "morfessor" + }, + { + "download_count": 233191, + "project": "pyzbar" + }, + { + "download_count": 232874, + "project": "nbstripout" + }, + { + "download_count": 232838, + "project": "mnemonic" + }, + { + "download_count": 232704, + "project": "pyeclib" + }, + { + "download_count": 232607, + "project": "flask-sockets" + }, + { + "download_count": 232578, + "project": "esrally" + }, + { + "download_count": 232565, + "project": "django-crontab" + }, + { + "download_count": 232517, + "project": "standardjson" + }, + { + "download_count": 232389, + "project": "sphinxcontrib-svg2pdfconverter" + }, + { + "download_count": 232208, + "project": "jep" + }, + { + "download_count": 231947, + "project": "contractions" + }, + { + "download_count": 231914, + "project": "hashlib" + }, + { + "download_count": 231894, + "project": "hdrhistogram" + }, + { + "download_count": 231873, + "project": "pydoe" + }, + { + "download_count": 231818, + "project": "colorhash" + }, + { + "download_count": 231678, + "project": "venv-update" + }, + { + "download_count": 231678, + "project": "pytidylib" + }, + { + "download_count": 231634, + "project": "sas7bdat" + }, + { + "download_count": 231555, + "project": "pybrain" + }, + { + "download_count": 231491, + "project": "locust" + }, + { + "download_count": 231449, + "project": "easygui" + }, + { + "download_count": 231322, + "project": "pytest-qt" + }, + { + "download_count": 231297, + "project": "prance" + }, + { + "download_count": 231250, + "project": "nose-ignore-docstring" + }, + { + "download_count": 231113, + "project": "snakeviz" + }, + { + "download_count": 231027, + "project": "pygaljs" + }, + { + "download_count": 230954, + "project": "rainbow-saddle" + }, + { + "download_count": 230879, + "project": "wsgiref" + }, + { + "download_count": 230659, + "project": "django-config-models" + }, + { + "download_count": 230631, + "project": "django-partial-index" + }, + { + "download_count": 230614, + "project": "restrictedpython" + }, + { + "download_count": 230470, + "project": "consulate" + }, + { + "download_count": 230441, + "project": "django-s3-storage" + }, + { + "download_count": 230436, + "project": "jenkins" + }, + { + "download_count": 230427, + "project": "mtranslate" + }, + { + "download_count": 230393, + "project": "aiosmtplib" + }, + { + "download_count": 230248, + "project": "django-statsd-mozilla" + }, + { + "download_count": 229850, + "project": "ffmpeg" + }, + { + "download_count": 229620, + "project": "django-ranged-response" + }, + { + "download_count": 229579, + "project": "pytest-cover" + }, + { + "download_count": 229403, + "project": "flexget" + }, + { + "download_count": 229292, + "project": "django-cachalot" + }, + { + "download_count": 229142, + "project": "django-activity-stream" + }, + { + "download_count": 229046, + "project": "daemonocle" + }, + { + "download_count": 228702, + "project": "mimerender" + }, + { + "download_count": 228552, + "project": "mathematics-dataset" + }, + { + "download_count": 228521, + "project": "money" + }, + { + "download_count": 228488, + "project": "flake8-formatter-junit-xml" + }, + { + "download_count": 228281, + "project": "python-vagrant" + }, + { + "download_count": 228240, + "project": "parquet" + }, + { + "download_count": 228235, + "project": "asciimatics" + }, + { + "download_count": 228066, + "project": "singleton-decorator" + }, + { + "download_count": 228004, + "project": "petl" + }, + { + "download_count": 227997, + "project": "dogpile" + }, + { + "download_count": 227746, + "project": "beaver" + }, + { + "download_count": 227738, + "project": "dbt-postgres" + }, + { + "download_count": 227570, + "project": "patch-ng" + }, + { + "download_count": 227212, + "project": "pytest-replay" + }, + { + "download_count": 227202, + "project": "django-settings-export" + }, + { + "download_count": 227048, + "project": "traittypes" + }, + { + "download_count": 227010, + "project": "ipcalc" + }, + { + "download_count": 226931, + "project": "django-elasticache" + }, + { + "download_count": 226656, + "project": "pywsd" + }, + { + "download_count": 226426, + "project": "flask-kvsession" + }, + { + "download_count": 226328, + "project": "pytest-logging" + }, + { + "download_count": 226143, + "project": "java-random" + }, + { + "download_count": 226134, + "project": "flask-seasurf" + }, + { + "download_count": 226129, + "project": "posix-ipc" + }, + { + "download_count": 226063, + "project": "zconfig" + }, + { + "download_count": 225964, + "project": "flask-uuid" + }, + { + "download_count": 225932, + "project": "djangorestframework-oauth" + }, + { + "download_count": 225898, + "project": "nest-asyncio" + }, + { + "download_count": 225852, + "project": "flock" + }, + { + "download_count": 225551, + "project": "taskcluster-urls" + }, + { + "download_count": 225391, + "project": "cntk" + }, + { + "download_count": 224972, + "project": "lolcat" + }, + { + "download_count": 224933, + "project": "pyramid-beaker" + }, + { + "download_count": 224799, + "project": "pytest-allure-adaptor" + }, + { + "download_count": 224606, + "project": "openapi-core" + }, + { + "download_count": 224528, + "project": "jaraco-itertools" + }, + { + "download_count": 224426, + "project": "emcee" + }, + { + "download_count": 224246, + "project": "trio" + }, + { + "download_count": 224218, + "project": "plotly-express" + }, + { + "download_count": 224064, + "project": "hexdump" + }, + { + "download_count": 224043, + "project": "binpacking" + }, + { + "download_count": 224021, + "project": "babelfish" + }, + { + "download_count": 223853, + "project": "bincrafters-package-tools" + }, + { + "download_count": 223736, + "project": "edx-rest-api-client" + }, + { + "download_count": 223721, + "project": "rstcheck" + }, + { + "download_count": 223494, + "project": "pylogo" + }, + { + "download_count": 223248, + "project": "h2o-pysparkling-2-3" + }, + { + "download_count": 223214, + "project": "pybloom" + }, + { + "download_count": 222931, + "project": "python3-memcached" + }, + { + "download_count": 222858, + "project": "conda" + }, + { + "download_count": 222781, + "project": "confusable-homoglyphs" + }, + { + "download_count": 222739, + "project": "loky" + }, + { + "download_count": 222684, + "project": "super-csv" + }, + { + "download_count": 222634, + "project": "jprops" + }, + { + "download_count": 222587, + "project": "keyvaultlib" + }, + { + "download_count": 222554, + "project": "fbmessenger" + }, + { + "download_count": 222508, + "project": "wiremock" + }, + { + "download_count": 222412, + "project": "django-prettyjson" + }, + { + "download_count": 222176, + "project": "hug" + }, + { + "download_count": 222175, + "project": "mws" + }, + { + "download_count": 221970, + "project": "dash-daq" + }, + { + "download_count": 221895, + "project": "slycot" + }, + { + "download_count": 221892, + "project": "flask-uploads" + }, + { + "download_count": 221647, + "project": "alooma" + }, + { + "download_count": 221631, + "project": "muffnn" + }, + { + "download_count": 221604, + "project": "python-gettext" + }, + { + "download_count": 221598, + "project": "civisml-extensions" + }, + { + "download_count": 221440, + "project": "jaydebeapi3" + }, + { + "download_count": 221407, + "project": "scikit-plot" + }, + { + "download_count": 220993, + "project": "twitter-ads" + }, + { + "download_count": 220495, + "project": "pandoc" + }, + { + "download_count": 220301, + "project": "nplusone" + }, + { + "download_count": 220198, + "project": "sudachipy" + }, + { + "download_count": 220107, + "project": "django-render-block" + }, + { + "download_count": 219983, + "project": "pyrebase" + }, + { + "download_count": 219731, + "project": "fabric2" + }, + { + "download_count": 219711, + "project": "cloudfoundry-client" + }, + { + "download_count": 219544, + "project": "edx-completion" + }, + { + "download_count": 219404, + "project": "tabulator" + }, + { + "download_count": 219376, + "project": "django-cron" + }, + { + "download_count": 219261, + "project": "sk-video" + }, + { + "download_count": 219216, + "project": "zope-i18nmessageid" + }, + { + "download_count": 218973, + "project": "colorful" + }, + { + "download_count": 218307, + "project": "s4cmd" + }, + { + "download_count": 218171, + "project": "pychromecast" + }, + { + "download_count": 218073, + "project": "pyvisa" + }, + { + "download_count": 217824, + "project": "bok-choy" + }, + { + "download_count": 217614, + "project": "py-zipkin" + }, + { + "download_count": 217311, + "project": "ansible-modules-hashivault" + }, + { + "download_count": 217201, + "project": "datefinder" + }, + { + "download_count": 217188, + "project": "json-logic-qubit" + }, + { + "download_count": 216980, + "project": "sparse-dot-topn" + }, + { + "download_count": 216825, + "project": "flask-dance" + }, + { + "download_count": 216707, + "project": "aiml" + }, + { + "download_count": 216645, + "project": "certipy" + }, + { + "download_count": 216205, + "project": "area" + }, + { + "download_count": 216115, + "project": "sphinx-click" + }, + { + "download_count": 215902, + "project": "pylint-common" + }, + { + "download_count": 215763, + "project": "stompest" + }, + { + "download_count": 215715, + "project": "questionary" + }, + { + "download_count": 215011, + "project": "lupa" + }, + { + "download_count": 214880, + "project": "usbinfo" + }, + { + "download_count": 214864, + "project": "marshmallow-objects" + }, + { + "download_count": 214855, + "project": "django-encrypted-filefield" + }, + { + "download_count": 214793, + "project": "kerberos" + }, + { + "download_count": 214757, + "project": "isim" + }, + { + "download_count": 214507, + "project": "flask-moment" + }, + { + "download_count": 214468, + "project": "boto3-session-cache" + }, + { + "download_count": 214280, + "project": "yacs" + }, + { + "download_count": 214088, + "project": "bigquery-python" + }, + { + "download_count": 213952, + "project": "mobly" + }, + { + "download_count": 213688, + "project": "pyethash" + }, + { + "download_count": 213494, + "project": "django-colorful" + }, + { + "download_count": 213445, + "project": "ics" + }, + { + "download_count": 213185, + "project": "eyes-selenium" + }, + { + "download_count": 213156, + "project": "zdesk" + }, + { + "download_count": 213151, + "project": "requests-credssp" + }, + { + "download_count": 213071, + "project": "autosemver" + }, + { + "download_count": 212879, + "project": "ffx" + }, + { + "download_count": 212740, + "project": "wn" + }, + { + "download_count": 212739, + "project": "linear-tsv" + }, + { + "download_count": 212738, + "project": "webexteamssdk" + }, + { + "download_count": 212640, + "project": "circus" + }, + { + "download_count": 212529, + "project": "multiaddr" + }, + { + "download_count": 212516, + "project": "zipcode" + }, + { + "download_count": 212435, + "project": "dbt-bigquery" + }, + { + "download_count": 212295, + "project": "androguard" + }, + { + "download_count": 212275, + "project": "gapic-google-cloud-spanner-v1" + }, + { + "download_count": 212211, + "project": "gapic-google-cloud-spanner-admin-database-v1" + }, + { + "download_count": 212204, + "project": "gapic-google-cloud-spanner-admin-instance-v1" + }, + { + "download_count": 212074, + "project": "proto-google-cloud-spanner-v1" + }, + { + "download_count": 211988, + "project": "pip-review" + }, + { + "download_count": 211861, + "project": "passwordmeter" + }, + { + "download_count": 211783, + "project": "dbt-redshift" + }, + { + "download_count": 211766, + "project": "proto-google-cloud-spanner-admin-database-v1" + }, + { + "download_count": 211758, + "project": "proto-google-cloud-spanner-admin-instance-v1" + }, + { + "download_count": 211695, + "project": "python-prctl" + }, + { + "download_count": 211523, + "project": "dbt-snowflake" + }, + { + "download_count": 211483, + "project": "aws-kinesis-agg" + }, + { + "download_count": 211368, + "project": "pwntools" + }, + { + "download_count": 211309, + "project": "fs-s3fs" + }, + { + "download_count": 211286, + "project": "cloudshell-automation-api" + }, + { + "download_count": 211188, + "project": "postgres" + }, + { + "download_count": 211130, + "project": "pymeta3" + }, + { + "download_count": 210970, + "project": "robotframework-jsonlibrary" + }, + { + "download_count": 210929, + "project": "conllu" + }, + { + "download_count": 210633, + "project": "rpi-gpio" + }, + { + "download_count": 210596, + "project": "aresponses" + }, + { + "download_count": 210520, + "project": "textacy" + }, + { + "download_count": 210501, + "project": "djangocms-link" + }, + { + "download_count": 210080, + "project": "uproot" + }, + { + "download_count": 209987, + "project": "django-fsm-admin" + }, + { + "download_count": 209975, + "project": "anybadge" + }, + { + "download_count": 209424, + "project": "clearbit" + }, + { + "download_count": 209150, + "project": "fakenewsredis" + }, + { + "download_count": 209126, + "project": "sdnotify" + }, + { + "download_count": 209028, + "project": "python-baseconv" + }, + { + "download_count": 208950, + "project": "pytest-dotenv" + }, + { + "download_count": 208654, + "project": "pytest-logger" + }, + { + "download_count": 208524, + "project": "c7n" + }, + { + "download_count": 208338, + "project": "webium" + }, + { + "download_count": 208232, + "project": "eliot" + }, + { + "download_count": 208191, + "project": "anaconda" + }, + { + "download_count": 208167, + "project": "zope-configuration" + }, + { + "download_count": 208131, + "project": "talon" + }, + { + "download_count": 208092, + "project": "django-split-settings" + }, + { + "download_count": 207912, + "project": "elasticsearch6" + }, + { + "download_count": 207665, + "project": "cx-freeze" + }, + { + "download_count": 207551, + "project": "pyclipper" + }, + { + "download_count": 207474, + "project": "duo-web" + }, + { + "download_count": 207412, + "project": "django-easy-select2" + }, + { + "download_count": 207319, + "project": "pytricia" + }, + { + "download_count": 207241, + "project": "pyecharts" + }, + { + "download_count": 207068, + "project": "zendesk" + }, + { + "download_count": 206988, + "project": "zodbpickle" + }, + { + "download_count": 206923, + "project": "scout-apm" + }, + { + "download_count": 206832, + "project": "contexttimer" + }, + { + "download_count": 206379, + "project": "ngxtop" + }, + { + "download_count": 206215, + "project": "python-xmp-toolkit" + }, + { + "download_count": 205992, + "project": "redlock" + }, + { + "download_count": 205889, + "project": "smartypants" + }, + { + "download_count": 205562, + "project": "flake8-coding" + }, + { + "download_count": 205284, + "project": "zodb" + }, + { + "download_count": 205270, + "project": "django-reversion-compare" + }, + { + "download_count": 205192, + "project": "html-linter" + }, + { + "download_count": 205141, + "project": "client" + }, + { + "download_count": 205070, + "project": "backports-shutil-which" + }, + { + "download_count": 204937, + "project": "frida" + }, + { + "download_count": 204809, + "project": "dawg-python" + }, + { + "download_count": 204696, + "project": "django-transaction-hooks" + }, + { + "download_count": 204486, + "project": "aiotask-context" + }, + { + "download_count": 204328, + "project": "lazy-property" + }, + { + "download_count": 204268, + "project": "urlparse2" + }, + { + "download_count": 204251, + "project": "template-remover" + }, + { + "download_count": 204130, + "project": "pyttsx3" + }, + { + "download_count": 204053, + "project": "mesh-tensorflow" + }, + { + "download_count": 203892, + "project": "django-crum" + }, + { + "download_count": 203786, + "project": "asciitree" + }, + { + "download_count": 203548, + "project": "flake8-deprecated" + }, + { + "download_count": 203495, + "project": "weberror" + }, + { + "download_count": 203493, + "project": "shudder" + }, + { + "download_count": 203310, + "project": "dash-auth" + }, + { + "download_count": 203161, + "project": "rasa-nlu" + }, + { + "download_count": 203073, + "project": "conf-d" + }, + { + "download_count": 202765, + "project": "django-slack" + }, + { + "download_count": 202648, + "project": "pocketsphinx" + }, + { + "download_count": 202044, + "project": "pydivert" + }, + { + "download_count": 202007, + "project": "blosc" + }, + { + "download_count": 201958, + "project": "zipstream" + }, + { + "download_count": 201831, + "project": "parallel-sync" + }, + { + "download_count": 201651, + "project": "pycuda" + }, + { + "download_count": 201622, + "project": "ta-lib" + }, + { + "download_count": 201459, + "project": "jmxquery" + }, + { + "download_count": 201457, + "project": "tabula-py" + }, + { + "download_count": 201395, + "project": "pytest-flask-sqlalchemy" + }, + { + "download_count": 201101, + "project": "collectd" + }, + { + "download_count": 201096, + "project": "django-rest-multiple-models" + }, + { + "download_count": 201084, + "project": "pyobjc-framework-coretext" + }, + { + "download_count": 200633, + "project": "smart-getenv" + }, + { + "download_count": 200507, + "project": "pyramid-retry" + }, + { + "download_count": 200444, + "project": "codeclimate-test-reporter" + }, + { + "download_count": 200411, + "project": "publicsuffixlist" + }, + { + "download_count": 200394, + "project": "algoliasearch-django" + }, + { + "download_count": 200267, + "project": "pytest-salt" + }, + { + "download_count": 200235, + "project": "pytest-doctestplus" + }, + { + "download_count": 200035, + "project": "zope-lifecycleevent" + }, + { + "download_count": 199808, + "project": "python-zaqarclient" + }, + { + "download_count": 199774, + "project": "iniherit" + }, + { + "download_count": 199753, + "project": "pymorphy2-dicts" + }, + { + "download_count": 199695, + "project": "hanging-threads" + }, + { + "download_count": 199645, + "project": "flask-classful" + }, + { + "download_count": 199602, + "project": "pyrad" + }, + { + "download_count": 199568, + "project": "jsoncompare" + }, + { + "download_count": 199376, + "project": "python-graph-core" + }, + { + "download_count": 199234, + "project": "flask-mysqldb" + }, + { + "download_count": 199123, + "project": "pymorphy2" + }, + { + "download_count": 199116, + "project": "uncertainties" + }, + { + "download_count": 198904, + "project": "jdatetime" + }, + { + "download_count": 198768, + "project": "package" + }, + { + "download_count": 198699, + "project": "django-user-sessions" + }, + { + "download_count": 198662, + "project": "jproperties" + }, + { + "download_count": 198655, + "project": "optional-django" + }, + { + "download_count": 198573, + "project": "azure-mgmt-common" + }, + { + "download_count": 198386, + "project": "csscompressor" + }, + { + "download_count": 198360, + "project": "robotframework-lint" + }, + { + "download_count": 198297, + "project": "bintrees" + }, + { + "download_count": 198099, + "project": "esptool" + }, + { + "download_count": 198014, + "project": "sox" + }, + { + "download_count": 197847, + "project": "cotyledon" + }, + { + "download_count": 197484, + "project": "kafka-utils" + }, + { + "download_count": 197448, + "project": "pingparsing" + }, + { + "download_count": 197436, + "project": "semidbm" + }, + { + "download_count": 197405, + "project": "polyaxon-schemas" + }, + { + "download_count": 196830, + "project": "python-mozaggregator" + }, + { + "download_count": 196757, + "project": "pandas-summary" + }, + { + "download_count": 196390, + "project": "nbval" + }, + { + "download_count": 196154, + "project": "python3-xlib" + }, + { + "download_count": 195862, + "project": "pyobjc-framework-coredata" + }, + { + "download_count": 195697, + "project": "django-json-widget" + }, + { + "download_count": 194638, + "project": "trimesh" + }, + { + "download_count": 194604, + "project": "pyobjc-framework-addressbook" + }, + { + "download_count": 194552, + "project": "sq-blocks" + }, + { + "download_count": 194524, + "project": "simple-crypt" + }, + { + "download_count": 194469, + "project": "imgkit" + }, + { + "download_count": 194216, + "project": "pytype" + }, + { + "download_count": 193866, + "project": "aiohttp-session" + }, + { + "download_count": 193810, + "project": "lib" + }, + { + "download_count": 193713, + "project": "pyobjc-framework-screensaver" + }, + { + "download_count": 193702, + "project": "remote-pdb" + }, + { + "download_count": 193646, + "project": "pyobjc-framework-syncservices" + }, + { + "download_count": 193463, + "project": "pyobjc-framework-scriptingbridge" + }, + { + "download_count": 193206, + "project": "glmnet-py" + }, + { + "download_count": 193173, + "project": "edx-django-release-util" + }, + { + "download_count": 193118, + "project": "pyobjc-framework-corelocation" + }, + { + "download_count": 193105, + "project": "pyobjc-framework-inputmethodkit" + }, + { + "download_count": 193099, + "project": "lob" + }, + { + "download_count": 192939, + "project": "deb-pkg-tools" + }, + { + "download_count": 192929, + "project": "traits" + }, + { + "download_count": 192741, + "project": "django-revproxy" + }, + { + "download_count": 192721, + "project": "edx-submissions" + }, + { + "download_count": 192662, + "project": "simpy" + }, + { + "download_count": 192636, + "project": "ebooklib" + }, + { + "download_count": 192632, + "project": "importlab" + }, + { + "download_count": 192581, + "project": "tweet-preprocessor" + }, + { + "download_count": 192462, + "project": "eight" + }, + { + "download_count": 192349, + "project": "edx-when" + }, + { + "download_count": 192282, + "project": "telepot" + }, + { + "download_count": 192227, + "project": "django-recaptcha2" + }, + { + "download_count": 192174, + "project": "fastjsonschema" + }, + { + "download_count": 191971, + "project": "rebulk" + }, + { + "download_count": 191767, + "project": "zope-dottedname" + }, + { + "download_count": 191702, + "project": "cli-proton-python" + }, + { + "download_count": 191581, + "project": "schema-salad" + }, + { + "download_count": 191533, + "project": "progressbar33" + }, + { + "download_count": 191495, + "project": "libnacl" + }, + { + "download_count": 191407, + "project": "mattermostwrapper" + }, + { + "download_count": 191403, + "project": "mox" + }, + { + "download_count": 191379, + "project": "esprima" + }, + { + "download_count": 191100, + "project": "tf-nightly-gpu" + }, + { + "download_count": 191091, + "project": "python-firebase" + }, + { + "download_count": 190890, + "project": "flake8-bandit" + }, + { + "download_count": 190752, + "project": "python3-logstash" + }, + { + "download_count": 190743, + "project": "pyutilib" + }, + { + "download_count": 190491, + "project": "easypost" + }, + { + "download_count": 190474, + "project": "web-fragments" + }, + { + "download_count": 190430, + "project": "pytest-coverage" + }, + { + "download_count": 190275, + "project": "mailjet-rest" + }, + { + "download_count": 190267, + "project": "riemann-client" + }, + { + "download_count": 190168, + "project": "pytest-test-groups" + }, + { + "download_count": 189997, + "project": "dialogflow" + }, + { + "download_count": 189912, + "project": "tableschema" + }, + { + "download_count": 189480, + "project": "segtok" + }, + { + "download_count": 189475, + "project": "contentful" + }, + { + "download_count": 189290, + "project": "ropgadget" + }, + { + "download_count": 189289, + "project": "user-agent" + }, + { + "download_count": 189193, + "project": "django-profiler" + }, + { + "download_count": 189156, + "project": "devstack-tools" + }, + { + "download_count": 188865, + "project": "django-leaflet" + }, + { + "download_count": 188683, + "project": "datetime-truncate" + }, + { + "download_count": 188451, + "project": "pyjslint" + }, + { + "download_count": 188348, + "project": "dvc" + }, + { + "download_count": 188172, + "project": "zope-cachedescriptors" + }, + { + "download_count": 188122, + "project": "onetoken" + }, + { + "download_count": 188063, + "project": "ipfshttpclient" + }, + { + "download_count": 187976, + "project": "azure-functions" + }, + { + "download_count": 187875, + "project": "optimizely-sdk" + }, + { + "download_count": 187858, + "project": "cwltool" + }, + { + "download_count": 187574, + "project": "seqdiag" + }, + { + "download_count": 187547, + "project": "libthumbor" + }, + { + "download_count": 187440, + "project": "atlassian-python-api" + }, + { + "download_count": 187397, + "project": "pyobjc-framework-corewlan" + }, + { + "download_count": 187363, + "project": "azure-cli-natgateway" + }, + { + "download_count": 187117, + "project": "pyobjc-framework-imagecapturecore" + }, + { + "download_count": 186984, + "project": "django-hosts" + }, + { + "download_count": 186865, + "project": "pytest-reportportal" + }, + { + "download_count": 186711, + "project": "pyobjc-framework-avfoundation" + }, + { + "download_count": 186705, + "project": "pyobjc-framework-corebluetooth" + }, + { + "download_count": 186590, + "project": "glog" + }, + { + "download_count": 186547, + "project": "pyobjc-framework-mapkit" + }, + { + "download_count": 186536, + "project": "pyobjc-framework-avkit" + }, + { + "download_count": 186474, + "project": "pyobjc-framework-storekit" + }, + { + "download_count": 186445, + "project": "pypom" + }, + { + "download_count": 186363, + "project": "pyobjc-framework-multipeerconnectivity" + }, + { + "download_count": 186349, + "project": "pyobjc-framework-scenekit" + }, + { + "download_count": 186324, + "project": "richenum" + }, + { + "download_count": 186299, + "project": "pyobjc-framework-imserviceplugin" + }, + { + "download_count": 186260, + "project": "pyobjc-framework-gamecenter" + }, + { + "download_count": 186239, + "project": "boto3-type-annotations-with-docs" + }, + { + "download_count": 186229, + "project": "pyobjc-framework-spritekit" + }, + { + "download_count": 186187, + "project": "pyobjc-framework-notificationcenter" + }, + { + "download_count": 186170, + "project": "salttesting" + }, + { + "download_count": 186131, + "project": "you-get" + }, + { + "download_count": 186067, + "project": "pyobjc-framework-cryptotokenkit" + }, + { + "download_count": 186058, + "project": "pytest-catchlog" + }, + { + "download_count": 185930, + "project": "iptcinfo" + }, + { + "download_count": 185874, + "project": "hashin" + }, + { + "download_count": 185785, + "project": "colormath" + }, + { + "download_count": 185776, + "project": "nanotime" + }, + { + "download_count": 185712, + "project": "python-saharaclient" + }, + { + "download_count": 185687, + "project": "yanc" + }, + { + "download_count": 185684, + "project": "methodtools" + }, + { + "download_count": 185575, + "project": "pytest-openfiles" + }, + { + "download_count": 185568, + "project": "zope-security" + }, + { + "download_count": 185489, + "project": "django-crequest" + }, + { + "download_count": 185383, + "project": "pymemoize" + }, + { + "download_count": 185321, + "project": "django-fsm-log" + }, + { + "download_count": 185307, + "project": "django-warrant" + }, + { + "download_count": 185226, + "project": "acora" + }, + { + "download_count": 184984, + "project": "python-hpilo" + }, + { + "download_count": 184866, + "project": "zope-exceptions" + }, + { + "download_count": 184842, + "project": "ase" + }, + { + "download_count": 184834, + "project": "django-debug-toolbar-request-history" + }, + { + "download_count": 184816, + "project": "clipboard" + }, + { + "download_count": 184780, + "project": "manifest-tool" + }, + { + "download_count": 184769, + "project": "pdftotext" + }, + { + "download_count": 184767, + "project": "events" + }, + { + "download_count": 184609, + "project": "zope-contenttype" + }, + { + "download_count": 184473, + "project": "django-discover-runner" + }, + { + "download_count": 184469, + "project": "libtiff" + }, + { + "download_count": 184406, + "project": "sqlacodegen" + }, + { + "download_count": 184172, + "project": "pyomo" + }, + { + "download_count": 184107, + "project": "django-admin-sortable" + }, + { + "download_count": 183722, + "project": "oic" + }, + { + "download_count": 183626, + "project": "django-user-tasks" + }, + { + "download_count": 183425, + "project": "edx-lint" + }, + { + "download_count": 183383, + "project": "netfilterqueue" + }, + { + "download_count": 183355, + "project": "zope-location" + }, + { + "download_count": 183073, + "project": "pyobjc-framework-qtkit" + }, + { + "download_count": 183058, + "project": "apispec-webframeworks" + }, + { + "download_count": 183054, + "project": "django-dbbackup" + }, + { + "download_count": 182995, + "project": "interpret-core" + }, + { + "download_count": 182971, + "project": "docker-compose-wait" + }, + { + "download_count": 182913, + "project": "socketpool" + }, + { + "download_count": 182775, + "project": "qgrid" + }, + { + "download_count": 182678, + "project": "localstack-ext" + }, + { + "download_count": 182643, + "project": "munkres" + }, + { + "download_count": 182633, + "project": "django-admin-list-filter-dropdown" + }, + { + "download_count": 182500, + "project": "edx-ccx-keys" + }, + { + "download_count": 182205, + "project": "jsonrpclib" + }, + { + "download_count": 182178, + "project": "pyinstrument-cext" + }, + { + "download_count": 182161, + "project": "wsgiproxy2" + }, + { + "download_count": 182080, + "project": "msgfy" + }, + { + "download_count": 182061, + "project": "localstack" + }, + { + "download_count": 182033, + "project": "mpl-finance" + }, + { + "download_count": 182028, + "project": "sinon" + }, + { + "download_count": 181902, + "project": "pyobjc-framework-photos" + }, + { + "download_count": 181883, + "project": "pyobjc-framework-contacts" + }, + { + "download_count": 181832, + "project": "pyobjc-framework-safariservices" + }, + { + "download_count": 181822, + "project": "nagiosplugin" + }, + { + "download_count": 181811, + "project": "hbmqtt" + }, + { + "download_count": 181809, + "project": "pyobjc-framework-photosui" + }, + { + "download_count": 181782, + "project": "rfc6266" + }, + { + "download_count": 181770, + "project": "wtforms-alchemy" + }, + { + "download_count": 181753, + "project": "pyobjc-framework-modelio" + }, + { + "download_count": 181752, + "project": "gocardless-pro" + }, + { + "download_count": 181742, + "project": "pyobjc-framework-applicationservices" + }, + { + "download_count": 181658, + "project": "datadog-checks-base" + }, + { + "download_count": 181619, + "project": "pyobjc-framework-contactsui" + }, + { + "download_count": 181492, + "project": "zope-publisher" + }, + { + "download_count": 181460, + "project": "pyobjc-framework-applescriptkit" + }, + { + "download_count": 181449, + "project": "pyobjc-framework-networkextension" + }, + { + "download_count": 181408, + "project": "zope-i18n" + }, + { + "download_count": 181315, + "project": "recordio" + }, + { + "download_count": 181306, + "project": "pyobjc-framework-preferencepanes" + }, + { + "download_count": 181204, + "project": "pyobjc-framework-installerplugins" + }, + { + "download_count": 181198, + "project": "pyobjc-framework-automator" + }, + { + "download_count": 181194, + "project": "python-interface" + }, + { + "download_count": 181178, + "project": "dogslow" + }, + { + "download_count": 181007, + "project": "s3pypi" + }, + { + "download_count": 180930, + "project": "arpeggio" + }, + { + "download_count": 180918, + "project": "pyobjc-framework-searchkit" + }, + { + "download_count": 180910, + "project": "pyobjc-framework-latentsemanticmapping" + }, + { + "download_count": 180898, + "project": "imgurpython" + }, + { + "download_count": 180787, + "project": "huey" + }, + { + "download_count": 180646, + "project": "pyobjc-framework-applescriptobjc" + }, + { + "download_count": 180541, + "project": "pyobjc-framework-instantmessage" + }, + { + "download_count": 180484, + "project": "pyclamd" + }, + { + "download_count": 180478, + "project": "pyobjc-framework-accounts" + }, + { + "download_count": 180443, + "project": "pyobjc-framework-servicemanagement" + }, + { + "download_count": 180359, + "project": "sortedcollections" + }, + { + "download_count": 180352, + "project": "pyobjc-framework-dictionaryservices" + }, + { + "download_count": 180326, + "project": "pyobjc-framework-pubsub" + }, + { + "download_count": 180234, + "project": "pyobjc-framework-collaboration" + }, + { + "download_count": 180184, + "project": "cqlsh" + }, + { + "download_count": 180108, + "project": "hacs-frontend" + }, + { + "download_count": 179819, + "project": "pyobjc-framework-social" + }, + { + "download_count": 179803, + "project": "pybars3" + }, + { + "download_count": 179768, + "project": "pyobjc-framework-eventkit" + }, + { + "download_count": 179757, + "project": "pyobjc-framework-opendirectory" + }, + { + "download_count": 179716, + "project": "chatterbot" + }, + { + "download_count": 179610, + "project": "neovim" + }, + { + "download_count": 179540, + "project": "json-logging" + }, + { + "download_count": 179401, + "project": "pytest-splinter" + }, + { + "download_count": 179317, + "project": "fig" + }, + { + "download_count": 179255, + "project": "pyte" + }, + { + "download_count": 179193, + "project": "bagit" + }, + { + "download_count": 179031, + "project": "aiohttp-swagger" + }, + { + "download_count": 178930, + "project": "django-cronman" + }, + { + "download_count": 178836, + "project": "robotframework-pageobjectlibrary" + }, + { + "download_count": 178805, + "project": "django-tenant-schemas" + }, + { + "download_count": 178606, + "project": "pypcd" + }, + { + "download_count": 178579, + "project": "s3contents" + }, + { + "download_count": 178532, + "project": "pytube" + }, + { + "download_count": 178420, + "project": "srvlookup" + }, + { + "download_count": 178249, + "project": "django-cache-url" + }, + { + "download_count": 178237, + "project": "pytest-sanic" + }, + { + "download_count": 178164, + "project": "pybase62" + }, + { + "download_count": 178040, + "project": "modulegraph" + }, + { + "download_count": 177513, + "project": "flufl-lock" + }, + { + "download_count": 177343, + "project": "pyobjc-framework-intents" + }, + { + "download_count": 177128, + "project": "playsound" + }, + { + "download_count": 177060, + "project": "django-sql-explorer" + }, + { + "download_count": 177040, + "project": "pymavlink" + }, + { + "download_count": 176939, + "project": "snowflake" + }, + { + "download_count": 176684, + "project": "drfdocs" + }, + { + "download_count": 176663, + "project": "django-sendfile" + }, + { + "download_count": 176504, + "project": "zope-testing" + }, + { + "download_count": 176439, + "project": "autocorrect" + }, + { + "download_count": 176429, + "project": "django-filters" + }, + { + "download_count": 176316, + "project": "delighted" + }, + { + "download_count": 176189, + "project": "pick" + }, + { + "download_count": 176166, + "project": "restricted-pkg" + }, + { + "download_count": 176069, + "project": "tlslite-ng" + }, + { + "download_count": 175910, + "project": "click-datetime" + }, + { + "download_count": 175901, + "project": "mapbox" + }, + { + "download_count": 175833, + "project": "zope-traversing" + }, + { + "download_count": 175827, + "project": "yagmail" + }, + { + "download_count": 175386, + "project": "os-diskconfig-python-novaclient-ext" + }, + { + "download_count": 175252, + "project": "env-utils" + }, + { + "download_count": 175153, + "project": "pyramid-chameleon" + }, + { + "download_count": 175039, + "project": "pysphere" + }, + { + "download_count": 174995, + "project": "pyobjc-framework-calendarstore" + }, + { + "download_count": 174675, + "project": "tfrecord-lite" + }, + { + "download_count": 174598, + "project": "zope-container" + }, + { + "download_count": 174537, + "project": "pyobjc-framework-iosurface" + }, + { + "download_count": 174516, + "project": "pyobjc-framework-netfs" + }, + { + "download_count": 174283, + "project": "zope-browser" + }, + { + "download_count": 174221, + "project": "cymysql" + }, + { + "download_count": 174210, + "project": "scrapy-fake-useragent" + }, + { + "download_count": 174182, + "project": "pysnooper" + }, + { + "download_count": 174143, + "project": "allennlp" + }, + { + "download_count": 174141, + "project": "itchat" + }, + { + "download_count": 174002, + "project": "pytest-arraydiff" + }, + { + "download_count": 174001, + "project": "multimethods" + }, + { + "download_count": 173985, + "project": "concurrencytest" + }, + { + "download_count": 173985, + "project": "pyxattr" + }, + { + "download_count": 173977, + "project": "pyobjc-framework-medialibrary" + }, + { + "download_count": 173974, + "project": "python-vlc" + }, + { + "download_count": 173922, + "project": "django-summernote" + }, + { + "download_count": 173897, + "project": "msal-extensions" + }, + { + "download_count": 173878, + "project": "pyobjc-framework-gamecontroller" + }, + { + "download_count": 173812, + "project": "pyobjc-framework-findersync" + }, + { + "download_count": 173771, + "project": "pyobjc-framework-cloudkit" + }, + { + "download_count": 173753, + "project": "pyobjc-framework-localauthentication" + }, + { + "download_count": 173686, + "project": "pyobjc-framework-mediaaccessibility" + }, + { + "download_count": 173647, + "project": "vega" + }, + { + "download_count": 173582, + "project": "textstat" + }, + { + "download_count": 173469, + "project": "neomodel" + }, + { + "download_count": 173417, + "project": "pyobjc" + }, + { + "download_count": 173414, + "project": "check-puppet-agent" + }, + { + "download_count": 173066, + "project": "os-networksv2-python-novaclient-ext" + }, + { + "download_count": 173034, + "project": "vcd-cli" + }, + { + "download_count": 172953, + "project": "numdifftools" + }, + { + "download_count": 172704, + "project": "tensorflow-graphics" + }, + { + "download_count": 172697, + "project": "pysqslistener" + }, + { + "download_count": 172681, + "project": "kazurator" + }, + { + "download_count": 172661, + "project": "xstatic-roboto-fontface" + }, + { + "download_count": 172595, + "project": "asyncio-nats-streaming" + }, + { + "download_count": 172285, + "project": "slugify" + }, + { + "download_count": 172276, + "project": "jupyter-notebook-gist" + }, + { + "download_count": 172213, + "project": "awsretry" + }, + { + "download_count": 172075, + "project": "flup" + }, + { + "download_count": 172011, + "project": "tornado-aws" + }, + { + "download_count": 171812, + "project": "rackspace-novaclient" + }, + { + "download_count": 171679, + "project": "django-q" + }, + { + "download_count": 171593, + "project": "rax-default-network-flags-python-novaclient-ext" + }, + { + "download_count": 171548, + "project": "object-pool" + }, + { + "download_count": 171504, + "project": "xstatic-font-awesome" + }, + { + "download_count": 171492, + "project": "rackspace-auth-openstack" + }, + { + "download_count": 171339, + "project": "qdarkstyle" + }, + { + "download_count": 171275, + "project": "tox-monorepo" + } + ] +} diff --git a/ast3/Tools/peg_generator/data/xxl.zip b/ast3/Tools/peg_generator/data/xxl.zip new file mode 100644 index 0000000000000000000000000000000000000000..5421408809b0d023733d7dd3b6f0285c22c97a16 GIT binary patch literal 18771 zcmeI)%`3xk0LSs~Y@TxTkmlh}z(F~9$Wd*F9ViFkHcv%qdo@vMQ|wYdpSlw-cXDcEq3R4mSsH+moB;V{1Ww!$t44 zdp$UM66~nHc?vviy}W%~E=HmsfzImH-1GOnuGCd>*j<~M*JuAhB%F!YagQGSe}6ZL z|F3sAEOCj00{W|fP_#_qG)izt;vf_)lQ@kM9FjN)Mav{kqXdT}4nol~iPI>-A&G-f zv`peON^nTxAQUZ=IE@k-A&G-f zv`peON^nTxAQUZ=IE@k(uoRXYDV@~G6LFNb|EO{Bm59DtPleE`z0 W!;gHP?3{GvuwP#L^VvQ+$(S#v3X~N9 literal 0 HcmV?d00001 diff --git a/ast3/Tools/peg_generator/mypy.ini b/ast3/Tools/peg_generator/mypy.ini new file mode 100644 index 00000000..80d5c057 --- /dev/null +++ b/ast3/Tools/peg_generator/mypy.ini @@ -0,0 +1,26 @@ +[mypy] +files = pegen, scripts + +follow_imports = error +no_implicit_optional = True +strict_optional = True + +#check_untyped_defs = True +disallow_untyped_calls = True +disallow_untyped_defs = True + +disallow_any_generics = true +disallow_any_unimported = True +disallow_incomplete_defs = True +disallow_subclassing_any = True + +warn_unused_configs = True +warn_unused_ignores = true +warn_redundant_casts = true +warn_no_return = True + +show_traceback = True +show_error_codes = True + +[mypy-pegen.grammar_parser] +strict_optional = False diff --git a/ast3/Tools/peg_generator/peg_extension/__init__.py b/ast3/Tools/peg_generator/peg_extension/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/ast3/Tools/peg_generator/peg_extension/peg_extension.c b/ast3/Tools/peg_generator/peg_extension/peg_extension.c new file mode 100644 index 00000000..fb552eed --- /dev/null +++ b/ast3/Tools/peg_generator/peg_extension/peg_extension.c @@ -0,0 +1,154 @@ +#include "pegen.h" + +PyObject * +_build_return_object(mod_ty module, int mode, PyObject *filename_ob, PyArena *arena) +{ + PyObject *result = NULL; + + if (mode == 2) { + result = (PyObject *)PyAST_CompileObject(module, filename_ob, NULL, -1, arena); + } else if (mode == 1) { + result = PyAST_mod2obj(module); + } else { + result = Py_None; + Py_INCREF(result); + } + + return result; +} + +static PyObject * +parse_file(PyObject *self, PyObject *args, PyObject *kwds) +{ + static char *keywords[] = {"file", "mode", NULL}; + const char *filename; + int mode = 2; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|i", keywords, &filename, &mode)) { + return NULL; + } + if (mode < 0 || mode > 2) { + return PyErr_Format(PyExc_ValueError, "Bad mode, must be 0 <= mode <= 2"); + } + + PyArena *arena = PyArena_New(); + if (arena == NULL) { + return NULL; + } + + PyObject *result = NULL; + + PyObject *filename_ob = PyUnicode_FromString(filename); + if (filename_ob == NULL) { + goto error; + } + + PyCompilerFlags flags = _PyCompilerFlags_INIT; + mod_ty res = _PyPegen_run_parser_from_file(filename, Py_file_input, filename_ob, &flags, arena); + if (res == NULL) { + goto error; + } + + result = _build_return_object(res, mode, filename_ob, arena); + +error: + Py_XDECREF(filename_ob); + PyArena_Free(arena); + return result; +} + +static PyObject * +parse_string(PyObject *self, PyObject *args, PyObject *kwds) +{ + static char *keywords[] = {"str", "mode", NULL}; + const char *the_string; + int mode = 2; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|i", keywords, &the_string, &mode)) { + return NULL; + } + if (mode < 0 || mode > 2) { + return PyErr_Format(PyExc_ValueError, "Bad mode, must be 0 <= mode <= 2"); + } + + PyArena *arena = PyArena_New(); + if (arena == NULL) { + return NULL; + } + + PyObject *result = NULL; + + PyObject *filename_ob = PyUnicode_FromString(""); + if (filename_ob == NULL) { + goto error; + } + + PyCompilerFlags flags = _PyCompilerFlags_INIT; + mod_ty res = _PyPegen_run_parser_from_string(the_string, Py_file_input, filename_ob, + &flags, arena); + if (res == NULL) { + goto error; + } + result = _build_return_object(res, mode, filename_ob, arena); + +error: + Py_XDECREF(filename_ob); + PyArena_Free(arena); + return result; +} + +static PyObject * +clear_memo_stats() +{ + _PyPegen_clear_memo_statistics(); + Py_RETURN_NONE; +} + +static PyObject * +get_memo_stats() +{ + return _PyPegen_get_memo_statistics(); +} + +// TODO: Write to Python's sys.stdout instead of C's stdout. +static PyObject * +dump_memo_stats() +{ + PyObject *list = _PyPegen_get_memo_statistics(); + if (list == NULL) { + return NULL; + } + Py_ssize_t len = PyList_Size(list); + for (Py_ssize_t i = 0; i < len; i++) { + PyObject *value = PyList_GetItem(list, i); // Borrowed reference. + long count = PyLong_AsLong(value); + if (count < 0) { + break; + } + if (count > 0) { + printf("%4ld %9ld\n", i, count); + } + } + Py_DECREF(list); + Py_RETURN_NONE; +} + +static PyMethodDef ParseMethods[] = { + {"parse_file", (PyCFunction)(void(*)(void))parse_file, METH_VARARGS|METH_KEYWORDS, "Parse a file."}, + {"parse_string", (PyCFunction)(void(*)(void))parse_string, METH_VARARGS|METH_KEYWORDS, "Parse a string."}, + {"clear_memo_stats", clear_memo_stats, METH_NOARGS}, + {"dump_memo_stats", dump_memo_stats, METH_NOARGS}, + {"get_memo_stats", get_memo_stats, METH_NOARGS}, + {NULL, NULL, 0, NULL} /* Sentinel */ +}; + +static struct PyModuleDef parsemodule = { + PyModuleDef_HEAD_INIT, + .m_name = "parse", + .m_doc = "A parser.", + .m_methods = ParseMethods, +}; + +PyMODINIT_FUNC +PyInit_parse(void) +{ + return PyModule_Create(&parsemodule); +} diff --git a/ast3/Tools/peg_generator/pegen/__init__.py b/ast3/Tools/peg_generator/pegen/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/ast3/Tools/peg_generator/pegen/__main__.py b/ast3/Tools/peg_generator/pegen/__main__.py new file mode 100755 index 00000000..1dcbaad1 --- /dev/null +++ b/ast3/Tools/peg_generator/pegen/__main__.py @@ -0,0 +1,182 @@ +#!/usr/bin/env python3.8 + +"""pegen -- PEG Generator. + +Search the web for PEG Parsers for reference. +""" + +import argparse +import sys +import time +import token +import traceback + +from typing import Tuple + +from pegen.build import Grammar, Parser, Tokenizer, ParserGenerator + + +def generate_c_code( + args: argparse.Namespace, +) -> Tuple[Grammar, Parser, Tokenizer, ParserGenerator]: + from pegen.build import build_c_parser_and_generator + + verbose = args.verbose + verbose_tokenizer = verbose >= 3 + verbose_parser = verbose == 2 or verbose >= 4 + try: + grammar, parser, tokenizer, gen = build_c_parser_and_generator( + args.grammar_filename, + args.tokens_filename, + args.output, + args.compile_extension, + verbose_tokenizer, + verbose_parser, + args.verbose, + keep_asserts_in_extension=False if args.optimized else True, + skip_actions=args.skip_actions, + ) + return grammar, parser, tokenizer, gen + except Exception as err: + if args.verbose: + raise # Show traceback + traceback.print_exception(err.__class__, err, None) + sys.stderr.write("For full traceback, use -v\n") + sys.exit(1) + + +def generate_python_code( + args: argparse.Namespace, +) -> Tuple[Grammar, Parser, Tokenizer, ParserGenerator]: + from pegen.build import build_python_parser_and_generator + + verbose = args.verbose + verbose_tokenizer = verbose >= 3 + verbose_parser = verbose == 2 or verbose >= 4 + try: + grammar, parser, tokenizer, gen = build_python_parser_and_generator( + args.grammar_filename, + args.output, + verbose_tokenizer, + verbose_parser, + skip_actions=args.skip_actions, + ) + return grammar, parser, tokenizer, gen + except Exception as err: + if args.verbose: + raise # Show traceback + traceback.print_exception(err.__class__, err, None) + sys.stderr.write("For full traceback, use -v\n") + sys.exit(1) + + +argparser = argparse.ArgumentParser( + prog="pegen", description="Experimental PEG-like parser generator" +) +argparser.add_argument("-q", "--quiet", action="store_true", help="Don't print the parsed grammar") +argparser.add_argument( + "-v", + "--verbose", + action="count", + default=0, + help="Print timing stats; repeat for more debug output", +) +subparsers = argparser.add_subparsers(help="target language for the generated code") + +c_parser = subparsers.add_parser("c", help="Generate C code for inclusion into CPython") +c_parser.set_defaults(func=generate_c_code) +c_parser.add_argument("grammar_filename", help="Grammar description") +c_parser.add_argument("tokens_filename", help="Tokens description") +c_parser.add_argument( + "-o", "--output", metavar="OUT", default="parse.c", help="Where to write the generated parser" +) +c_parser.add_argument( + "--compile-extension", + action="store_true", + help="Compile generated C code into an extension module", +) +c_parser.add_argument( + "--optimized", action="store_true", help="Compile the extension in optimized mode" +) +c_parser.add_argument( + "--skip-actions", action="store_true", help="Suppress code emission for rule actions", +) + +python_parser = subparsers.add_parser("python", help="Generate Python code") +python_parser.set_defaults(func=generate_python_code) +python_parser.add_argument("grammar_filename", help="Grammar description") +python_parser.add_argument( + "-o", + "--output", + metavar="OUT", + default="parse.py", + help="Where to write the generated parser", +) +python_parser.add_argument( + "--skip-actions", action="store_true", help="Suppress code emission for rule actions", +) + + +def main() -> None: + from pegen.testutil import print_memstats + + args = argparser.parse_args() + if "func" not in args: + argparser.error("Must specify the target language mode ('c' or 'python')") + + t0 = time.time() + grammar, parser, tokenizer, gen = args.func(args) + t1 = time.time() + + if not args.quiet: + if args.verbose: + print("Raw Grammar:") + for line in repr(grammar).splitlines(): + print(" ", line) + + print("Clean Grammar:") + for line in str(grammar).splitlines(): + print(" ", line) + + if args.verbose: + print("First Graph:") + for src, dsts in gen.first_graph.items(): + print(f" {src} -> {', '.join(dsts)}") + print("First SCCS:") + for scc in gen.first_sccs: + print(" ", scc, end="") + if len(scc) > 1: + print( + " # Indirectly left-recursive; leaders:", + {name for name in scc if grammar.rules[name].leader}, + ) + else: + name = next(iter(scc)) + if name in gen.first_graph[name]: + print(" # Left-recursive") + else: + print() + + if args.verbose: + dt = t1 - t0 + diag = tokenizer.diagnose() + nlines = diag.end[0] + if diag.type == token.ENDMARKER: + nlines -= 1 + print(f"Total time: {dt:.3f} sec; {nlines} lines", end="") + if dt: + print(f"; {nlines / dt:.0f} lines/sec") + else: + print() + print("Caches sizes:") + print(f" token array : {len(tokenizer._tokens):10}") + print(f" cache : {len(parser._cache):10}") + if not print_memstats(): + print("(Can't find psutil; install it for memory stats.)") + + +if __name__ == "__main__": + if sys.version_info < (3, 8): + print("ERROR: using pegen requires at least Python 3.8!", file=sys.stderr) + sys.exit(1) + main() diff --git a/ast3/Tools/peg_generator/pegen/ast_dump.py b/ast3/Tools/peg_generator/pegen/ast_dump.py new file mode 100644 index 00000000..93dfbfd9 --- /dev/null +++ b/ast3/Tools/peg_generator/pegen/ast_dump.py @@ -0,0 +1,63 @@ +""" +Copy-parse of ast.dump, removing the `isinstance` checks. This is needed, +because testing pegen requires generating a C extension module, which contains +a copy of the symbols defined in Python-ast.c. Thus, the isinstance check would +always fail. We rely on string comparison of the base classes instead. +TODO: Remove the above-described hack. +""" + + +def ast_dump(node, annotate_fields=True, include_attributes=False, *, indent=None): + def _format(node, level=0): + if indent is not None: + level += 1 + prefix = "\n" + indent * level + sep = ",\n" + indent * level + else: + prefix = "" + sep = ", " + if any(cls.__name__ == "AST" for cls in node.__class__.__mro__): + cls = type(node) + args = [] + allsimple = True + keywords = annotate_fields + for name in node._fields: + try: + value = getattr(node, name) + except AttributeError: + keywords = True + continue + if value is None and getattr(cls, name, ...) is None: + keywords = True + continue + value, simple = _format(value, level) + allsimple = allsimple and simple + if keywords: + args.append("%s=%s" % (name, value)) + else: + args.append(value) + if include_attributes and node._attributes: + for name in node._attributes: + try: + value = getattr(node, name) + except AttributeError: + continue + if value is None and getattr(cls, name, ...) is None: + continue + value, simple = _format(value, level) + allsimple = allsimple and simple + args.append("%s=%s" % (name, value)) + if allsimple and len(args) <= 3: + return "%s(%s)" % (node.__class__.__name__, ", ".join(args)), not args + return "%s(%s%s)" % (node.__class__.__name__, prefix, sep.join(args)), False + elif isinstance(node, list): + if not node: + return "[]", True + return "[%s%s]" % (prefix, sep.join(_format(x, level)[0] for x in node)), False + return repr(node), True + + if all(cls.__name__ != "AST" for cls in node.__class__.__mro__): + raise TypeError("expected AST, got %r" % node.__class__.__name__) + if indent is not None and not isinstance(indent, str): + indent = " " * indent + return _format(node)[0] diff --git a/ast3/Tools/peg_generator/pegen/build.py b/ast3/Tools/peg_generator/pegen/build.py new file mode 100644 index 00000000..931ffc78 --- /dev/null +++ b/ast3/Tools/peg_generator/pegen/build.py @@ -0,0 +1,248 @@ +import pathlib +import shutil +import tokenize +import sysconfig +import tempfile +import itertools + +from typing import Optional, Tuple, List, IO, Set, Dict + +from pegen.c_generator import CParserGenerator +from pegen.grammar import Grammar +from pegen.grammar_parser import GeneratedParser as GrammarParser +from pegen.parser import Parser +from pegen.parser_generator import ParserGenerator +from pegen.python_generator import PythonParserGenerator +from pegen.tokenizer import Tokenizer + +MOD_DIR = pathlib.Path(__file__).resolve().parent + +TokenDefinitions = Tuple[Dict[int, str], Dict[str, int], Set[str]] + + +def get_extra_flags(compiler_flags: str, compiler_py_flags_nodist: str) -> List[str]: + flags = sysconfig.get_config_var(compiler_flags) + py_flags_nodist = sysconfig.get_config_var(compiler_py_flags_nodist) + if flags is None or py_flags_nodist is None: + return [] + return f"{flags} {py_flags_nodist}".split() + + +def compile_c_extension( + generated_source_path: str, + build_dir: Optional[str] = None, + verbose: bool = False, + keep_asserts: bool = True, +) -> str: + """Compile the generated source for a parser generator into an extension module. + + The extension module will be generated in the same directory as the provided path + for the generated source, with the same basename (in addition to extension module + metadata). For example, for the source mydir/parser.c the generated extension + in a darwin system with python 3.8 will be mydir/parser.cpython-38-darwin.so. + + If *build_dir* is provided, that path will be used as the temporary build directory + of distutils (this is useful in case you want to use a temporary directory). + """ + import distutils.log + from distutils.core import Distribution, Extension + from distutils.command.clean import clean # type: ignore + from distutils.command.build_ext import build_ext # type: ignore + from distutils.tests.support import fixup_build_ext # type: ignore + + if verbose: + distutils.log.set_verbosity(distutils.log.DEBUG) + + source_file_path = pathlib.Path(generated_source_path) + extension_name = source_file_path.stem + extra_compile_args = get_extra_flags("CFLAGS", "PY_CFLAGS_NODIST") + extra_link_args = get_extra_flags("LDFLAGS", "PY_LDFLAGS_NODIST") + if keep_asserts: + extra_compile_args.append("-UNDEBUG") + extension = [ + Extension( + extension_name, + sources=[ + str(MOD_DIR.parent.parent.parent / "Python" / "Python-ast.c"), + str(MOD_DIR.parent.parent.parent / "Python" / "asdl.c"), + str(MOD_DIR.parent.parent.parent / "Parser" / "tokenizer.c"), + str(MOD_DIR.parent.parent.parent / "Parser" / "pegen" / "pegen.c"), + str(MOD_DIR.parent.parent.parent / "Parser" / "pegen" / "parse_string.c"), + str(MOD_DIR.parent / "peg_extension" / "peg_extension.c"), + generated_source_path, + ], + include_dirs=[ + str(MOD_DIR.parent.parent.parent / "Include" / "internal"), + str(MOD_DIR.parent.parent.parent / "Parser"), + str(MOD_DIR.parent.parent.parent / "Parser" / "pegen"), + ], + extra_compile_args=extra_compile_args, + extra_link_args=extra_link_args, + ) + ] + dist = Distribution({"name": extension_name, "ext_modules": extension}) + cmd = build_ext(dist) + fixup_build_ext(cmd) + cmd.inplace = True + if build_dir: + cmd.build_temp = build_dir + cmd.build_lib = build_dir + cmd.ensure_finalized() + cmd.run() + + extension_path = source_file_path.parent / cmd.get_ext_filename(extension_name) + shutil.move(cmd.get_ext_fullpath(extension_name), extension_path) + + cmd = clean(dist) + cmd.finalize_options() + cmd.run() + + return extension_path + + +def build_parser( + grammar_file: str, verbose_tokenizer: bool = False, verbose_parser: bool = False +) -> Tuple[Grammar, Parser, Tokenizer]: + with open(grammar_file) as file: + tokenizer = Tokenizer(tokenize.generate_tokens(file.readline), verbose=verbose_tokenizer) + parser = GrammarParser(tokenizer, verbose=verbose_parser) + grammar = parser.start() + + if not grammar: + raise parser.make_syntax_error(grammar_file) + + return grammar, parser, tokenizer + + +def generate_token_definitions(tokens: IO[str]) -> TokenDefinitions: + all_tokens = {} + exact_tokens = {} + non_exact_tokens = set() + numbers = itertools.count(0) + + for line in tokens: + line = line.strip() + + if not line or line.startswith("#"): + continue + + pieces = line.split() + index = next(numbers) + + if len(pieces) == 1: + (token,) = pieces + non_exact_tokens.add(token) + all_tokens[index] = token + elif len(pieces) == 2: + token, op = pieces + exact_tokens[op.strip("'")] = index + all_tokens[index] = token + else: + raise ValueError(f"Unexpected line found in Tokens file: {line}") + + return all_tokens, exact_tokens, non_exact_tokens + + +def build_c_generator( + grammar: Grammar, + grammar_file: str, + tokens_file: str, + output_file: str, + compile_extension: bool = False, + verbose_c_extension: bool = False, + keep_asserts_in_extension: bool = True, + skip_actions: bool = False, +) -> ParserGenerator: + with open(tokens_file, "r") as tok_file: + all_tokens, exact_tok, non_exact_tok = generate_token_definitions(tok_file) + with open(output_file, "w") as file: + gen: ParserGenerator = CParserGenerator( + grammar, all_tokens, exact_tok, non_exact_tok, file, skip_actions=skip_actions + ) + gen.generate(grammar_file) + + if compile_extension: + with tempfile.TemporaryDirectory() as build_dir: + compile_c_extension( + output_file, + build_dir=build_dir, + verbose=verbose_c_extension, + keep_asserts=keep_asserts_in_extension, + ) + return gen + + +def build_python_generator( + grammar: Grammar, grammar_file: str, output_file: str, skip_actions: bool = False, +) -> ParserGenerator: + with open(output_file, "w") as file: + gen: ParserGenerator = PythonParserGenerator(grammar, file) # TODO: skip_actions + gen.generate(grammar_file) + return gen + + +def build_c_parser_and_generator( + grammar_file: str, + tokens_file: str, + output_file: str, + compile_extension: bool = False, + verbose_tokenizer: bool = False, + verbose_parser: bool = False, + verbose_c_extension: bool = False, + keep_asserts_in_extension: bool = True, + skip_actions: bool = False, +) -> Tuple[Grammar, Parser, Tokenizer, ParserGenerator]: + """Generate rules, C parser, tokenizer, parser generator for a given grammar + + Args: + grammar_file (string): Path for the grammar file + tokens_file (string): Path for the tokens file + output_file (string): Path for the output file + compile_extension (bool, optional): Whether to compile the C extension. + Defaults to False. + verbose_tokenizer (bool, optional): Whether to display additional output + when generating the tokenizer. Defaults to False. + verbose_parser (bool, optional): Whether to display additional output + when generating the parser. Defaults to False. + verbose_c_extension (bool, optional): Whether to display additional + output when compiling the C extension . Defaults to False. + keep_asserts_in_extension (bool, optional): Whether to keep the assert statements + when compiling the extension module. Defaults to True. + skip_actions (bool, optional): Whether to pretend no rule has any actions. + """ + grammar, parser, tokenizer = build_parser(grammar_file, verbose_tokenizer, verbose_parser) + gen = build_c_generator( + grammar, + grammar_file, + tokens_file, + output_file, + compile_extension, + verbose_c_extension, + keep_asserts_in_extension, + skip_actions=skip_actions, + ) + + return grammar, parser, tokenizer, gen + + +def build_python_parser_and_generator( + grammar_file: str, + output_file: str, + verbose_tokenizer: bool = False, + verbose_parser: bool = False, + skip_actions: bool = False, +) -> Tuple[Grammar, Parser, Tokenizer, ParserGenerator]: + """Generate rules, python parser, tokenizer, parser generator for a given grammar + + Args: + grammar_file (string): Path for the grammar file + output_file (string): Path for the output file + verbose_tokenizer (bool, optional): Whether to display additional output + when generating the tokenizer. Defaults to False. + verbose_parser (bool, optional): Whether to display additional output + when generating the parser. Defaults to False. + skip_actions (bool, optional): Whether to pretend no rule has any actions. + """ + grammar, parser, tokenizer = build_parser(grammar_file, verbose_tokenizer, verbose_parser) + gen = build_python_generator(grammar, grammar_file, output_file, skip_actions=skip_actions,) + return grammar, parser, tokenizer, gen diff --git a/ast3/Tools/peg_generator/pegen/c_generator.py b/ast3/Tools/peg_generator/pegen/c_generator.py new file mode 100644 index 00000000..3bf6d9ed --- /dev/null +++ b/ast3/Tools/peg_generator/pegen/c_generator.py @@ -0,0 +1,729 @@ +import ast +from dataclasses import dataclass, field +import re +from typing import Any, Dict, IO, Optional, List, Text, Tuple, Set +from enum import Enum + +from pegen import grammar +from pegen.grammar import ( + Alt, + Cut, + Gather, + GrammarVisitor, + Group, + Lookahead, + NamedItem, + NameLeaf, + NegativeLookahead, + Opt, + PositiveLookahead, + Repeat0, + Repeat1, + Rhs, + Rule, + StringLeaf, +) +from pegen.parser_generator import ParserGenerator + +EXTENSION_PREFIX = """\ +#include "pegen.h" + +""" + + +EXTENSION_SUFFIX = """ +void * +_PyPegen_parse(Parser *p) +{ + // Initialize keywords + p->keywords = reserved_keywords; + p->n_keyword_lists = n_keyword_lists; + + return start_rule(p); +} +""" + + +class NodeTypes(Enum): + NAME_TOKEN = 0 + NUMBER_TOKEN = 1 + STRING_TOKEN = 2 + GENERIC_TOKEN = 3 + KEYWORD = 4 + CUT_OPERATOR = 5 + + +BASE_NODETYPES = { + "NAME": NodeTypes.NAME_TOKEN, + "NUMBER": NodeTypes.NUMBER_TOKEN, + "STRING": NodeTypes.STRING_TOKEN, +} + + +@dataclass +class FunctionCall: + function: str + arguments: Optional[List[Any]] = None + assigned_variable: Optional[str] = None + return_type: Optional[str] = None + nodetype: Optional[NodeTypes] = None + force_true: bool = False + comment: Optional[str] = None + + def __str__(self) -> str: + parts = [] + parts.append(self.function) + if self.arguments: + parts.append(f"({', '.join(map(str, self.arguments))})") + if self.force_true: + parts.append(", 1") + if self.assigned_variable: + parts = ["(", self.assigned_variable, " = ", *parts, ")"] + if self.comment: + parts.append(f" // {self.comment}") + return "".join(parts) + + +class CCallMakerVisitor(GrammarVisitor): + def __init__( + self, + parser_generator: ParserGenerator, + exact_tokens: Dict[str, int], + non_exact_tokens: Set[str], + ): + self.gen = parser_generator + self.exact_tokens = exact_tokens + self.non_exact_tokens = non_exact_tokens + self.cache: Dict[Any, Any] = {} + self.keyword_cache: Dict[str, int] = {} + + def keyword_helper(self, keyword: str) -> FunctionCall: + if keyword not in self.keyword_cache: + self.keyword_cache[keyword] = self.gen.keyword_type() + return FunctionCall( + assigned_variable="keyword", + function="_PyPegen_expect_token", + arguments=["p", self.keyword_cache[keyword]], + return_type="Token *", + nodetype=NodeTypes.KEYWORD, + comment=f"token='{keyword}'", + ) + + def visit_NameLeaf(self, node: NameLeaf) -> FunctionCall: + name = node.value + if name in self.non_exact_tokens: + if name in BASE_NODETYPES: + return FunctionCall( + assigned_variable=f"{name.lower()}_var", + function=f"_PyPegen_{name.lower()}_token", + arguments=["p"], + nodetype=BASE_NODETYPES[name], + return_type="expr_ty", + comment=name, + ) + return FunctionCall( + assigned_variable=f"{name.lower()}_var", + function=f"_PyPegen_expect_token", + arguments=["p", name], + nodetype=NodeTypes.GENERIC_TOKEN, + return_type="Token *", + comment=f"token='{name}'", + ) + + type = None + rule = self.gen.all_rules.get(name.lower()) + if rule is not None: + type = "asdl_seq *" if rule.is_loop() or rule.is_gather() else rule.type + + return FunctionCall( + assigned_variable=f"{name}_var", + function=f"{name}_rule", + arguments=["p"], + return_type=type, + comment=f"{node}" + ) + + def visit_StringLeaf(self, node: StringLeaf) -> FunctionCall: + val = ast.literal_eval(node.value) + if re.match(r"[a-zA-Z_]\w*\Z", val): # This is a keyword + return self.keyword_helper(val) + else: + assert val in self.exact_tokens, f"{node.value} is not a known literal" + type = self.exact_tokens[val] + return FunctionCall( + assigned_variable="literal", + function=f"_PyPegen_expect_token", + arguments=["p", type], + nodetype=NodeTypes.GENERIC_TOKEN, + return_type="Token *", + comment=f"token='{val}'", + ) + + def visit_Rhs(self, node: Rhs) -> FunctionCall: + def can_we_inline(node: Rhs) -> int: + if len(node.alts) != 1 or len(node.alts[0].items) != 1: + return False + # If the alternative has an action we cannot inline + if getattr(node.alts[0], "action", None) is not None: + return False + return True + + if node in self.cache: + return self.cache[node] + if can_we_inline(node): + self.cache[node] = self.visit(node.alts[0].items[0]) + else: + name = self.gen.name_node(node) + self.cache[node] = FunctionCall( + assigned_variable=f"{name}_var", function=f"{name}_rule", arguments=["p"], + comment=f"{node}" + ) + return self.cache[node] + + def visit_NamedItem(self, node: NamedItem) -> FunctionCall: + call = self.visit(node.item) + if node.name: + call.assigned_variable = node.name + return call + + def lookahead_call_helper(self, node: Lookahead, positive: int) -> FunctionCall: + call = self.visit(node.node) + if call.nodetype == NodeTypes.NAME_TOKEN: + return FunctionCall( + function=f"_PyPegen_lookahead_with_name", + arguments=[positive, call.function, *call.arguments], + return_type="int", + ) + elif call.nodetype in {NodeTypes.GENERIC_TOKEN, NodeTypes.KEYWORD}: + return FunctionCall( + function=f"_PyPegen_lookahead_with_int", + arguments=[positive, call.function, *call.arguments], + return_type="int", + comment=f"token={node.node}", + ) + else: + return FunctionCall( + function=f"_PyPegen_lookahead", + arguments=[positive, call.function, *call.arguments], + return_type="int", + ) + + def visit_PositiveLookahead(self, node: PositiveLookahead) -> FunctionCall: + return self.lookahead_call_helper(node, 1) + + def visit_NegativeLookahead(self, node: NegativeLookahead) -> FunctionCall: + return self.lookahead_call_helper(node, 0) + + def visit_Opt(self, node: Opt) -> FunctionCall: + call = self.visit(node.node) + return FunctionCall( + assigned_variable="opt_var", + function=call.function, + arguments=call.arguments, + force_true=True, + comment=f"{node}" + ) + + def visit_Repeat0(self, node: Repeat0) -> FunctionCall: + if node in self.cache: + return self.cache[node] + name = self.gen.name_loop(node.node, False) + self.cache[node] = FunctionCall( + assigned_variable=f"{name}_var", + function=f"{name}_rule", + arguments=["p"], + return_type="asdl_seq *", + comment=f"{node}", + ) + return self.cache[node] + + def visit_Repeat1(self, node: Repeat1) -> FunctionCall: + if node in self.cache: + return self.cache[node] + name = self.gen.name_loop(node.node, True) + self.cache[node] = FunctionCall( + assigned_variable=f"{name}_var", + function=f"{name}_rule", + arguments=["p"], + return_type="asdl_seq *", + comment=f"{node}", + ) + return self.cache[node] + + def visit_Gather(self, node: Gather) -> FunctionCall: + if node in self.cache: + return self.cache[node] + name = self.gen.name_gather(node) + self.cache[node] = FunctionCall( + assigned_variable=f"{name}_var", + function=f"{name}_rule", + arguments=["p"], + return_type="asdl_seq *", + comment=f"{node}", + ) + return self.cache[node] + + def visit_Group(self, node: Group) -> FunctionCall: + return self.visit(node.rhs) + + def visit_Cut(self, node: Cut) -> FunctionCall: + return FunctionCall( + assigned_variable="cut_var", + return_type="int", + function="1", + nodetype=NodeTypes.CUT_OPERATOR, + ) + + +class CParserGenerator(ParserGenerator, GrammarVisitor): + def __init__( + self, + grammar: grammar.Grammar, + tokens: Dict[int, str], + exact_tokens: Dict[str, int], + non_exact_tokens: Set[str], + file: Optional[IO[Text]], + debug: bool = False, + skip_actions: bool = False, + ): + super().__init__(grammar, tokens, file) + self.callmakervisitor: CCallMakerVisitor = CCallMakerVisitor( + self, exact_tokens, non_exact_tokens + ) + self._varname_counter = 0 + self.debug = debug + self.skip_actions = skip_actions + + def unique_varname(self, name: str = "tmpvar") -> str: + new_var = name + "_" + str(self._varname_counter) + self._varname_counter += 1 + return new_var + + def call_with_errorcheck_return(self, call_text: str, returnval: str) -> None: + error_var = self.unique_varname() + self.print(f"int {error_var} = {call_text};") + self.print(f"if ({error_var}) {{") + with self.indent(): + self.print(f"return {returnval};") + self.print(f"}}") + + def call_with_errorcheck_goto(self, call_text: str, goto_target: str) -> None: + error_var = self.unique_varname() + self.print(f"int {error_var} = {call_text};") + self.print(f"if ({error_var}) {{") + with self.indent(): + self.print(f"goto {goto_target};") + self.print(f"}}") + + def out_of_memory_return( + self, + expr: str, + returnval: str, + message: str = "Parser out of memory", + cleanup_code: Optional[str] = None, + ) -> None: + self.print(f"if ({expr}) {{") + with self.indent(): + self.print(f'PyErr_Format(PyExc_MemoryError, "{message}");') + if cleanup_code is not None: + self.print(cleanup_code) + self.print(f"return {returnval};") + self.print(f"}}") + + def out_of_memory_goto( + self, expr: str, goto_target: str, message: str = "Parser out of memory" + ) -> None: + self.print(f"if ({expr}) {{") + with self.indent(): + self.print(f'PyErr_Format(PyExc_MemoryError, "{message}");') + self.print(f"goto {goto_target};") + self.print(f"}}") + + def generate(self, filename: str) -> None: + self.collect_todo() + self.print(f"// @generated by pegen.py from {filename}") + header = self.grammar.metas.get("header", EXTENSION_PREFIX) + if header: + self.print(header.rstrip("\n")) + subheader = self.grammar.metas.get("subheader", "") + if subheader: + self.print(subheader) + self._setup_keywords() + for i, (rulename, rule) in enumerate(self.todo.items(), 1000): + comment = " // Left-recursive" if rule.left_recursive else "" + self.print(f"#define {rulename}_type {i}{comment}") + self.print() + for rulename, rule in self.todo.items(): + if rule.is_loop() or rule.is_gather(): + type = "asdl_seq *" + elif rule.type: + type = rule.type + " " + else: + type = "void *" + self.print(f"static {type}{rulename}_rule(Parser *p);") + self.print() + while self.todo: + for rulename, rule in list(self.todo.items()): + del self.todo[rulename] + self.print() + if rule.left_recursive: + self.print("// Left-recursive") + self.visit(rule) + if self.skip_actions: + mode = 0 + else: + mode = int(self.rules["start"].type == "mod_ty") if "start" in self.rules else 1 + if mode == 1 and self.grammar.metas.get("bytecode"): + mode += 1 + modulename = self.grammar.metas.get("modulename", "parse") + trailer = self.grammar.metas.get("trailer", EXTENSION_SUFFIX) + if trailer: + self.print(trailer.rstrip("\n") % dict(mode=mode, modulename=modulename)) + + def _group_keywords_by_length(self) -> Dict[int, List[Tuple[str, int]]]: + groups: Dict[int, List[Tuple[str, int]]] = {} + for keyword_str, keyword_type in self.callmakervisitor.keyword_cache.items(): + length = len(keyword_str) + if length in groups: + groups[length].append((keyword_str, keyword_type)) + else: + groups[length] = [(keyword_str, keyword_type)] + return groups + + def _setup_keywords(self) -> None: + keyword_cache = self.callmakervisitor.keyword_cache + n_keyword_lists = ( + len(max(keyword_cache.keys(), key=len)) + 1 if len(keyword_cache) > 0 else 0 + ) + self.print(f"static const int n_keyword_lists = {n_keyword_lists};") + groups = self._group_keywords_by_length() + self.print("static KeywordToken *reserved_keywords[] = {") + with self.indent(): + num_groups = max(groups) + 1 if groups else 1 + for keywords_length in range(num_groups): + if keywords_length not in groups.keys(): + self.print("NULL,") + else: + self.print("(KeywordToken[]) {") + with self.indent(): + for keyword_str, keyword_type in groups[keywords_length]: + self.print(f'{{"{keyword_str}", {keyword_type}}},') + self.print("{NULL, -1},") + self.print("},") + self.print("};") + + def _set_up_token_start_metadata_extraction(self) -> None: + self.print("if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) {") + with self.indent(): + self.print("p->error_indicator = 1;") + self.print("return NULL;") + self.print("}") + self.print("int start_lineno = p->tokens[mark]->lineno;") + self.print("UNUSED(start_lineno); // Only used by EXTRA macro") + self.print("int start_col_offset = p->tokens[mark]->col_offset;") + self.print("UNUSED(start_col_offset); // Only used by EXTRA macro") + + def _set_up_token_end_metadata_extraction(self) -> None: + self.print("Token *token = _PyPegen_get_last_nonnwhitespace_token(p);") + self.print("if (token == NULL) {") + with self.indent(): + self.print("return NULL;") + self.print("}") + self.print(f"int end_lineno = token->end_lineno;") + self.print("UNUSED(end_lineno); // Only used by EXTRA macro") + self.print(f"int end_col_offset = token->end_col_offset;") + self.print("UNUSED(end_col_offset); // Only used by EXTRA macro") + + def _set_up_rule_memoization(self, node: Rule, result_type: str) -> None: + self.print("{") + with self.indent(): + self.print(f"{result_type} res = NULL;") + self.print(f"if (_PyPegen_is_memoized(p, {node.name}_type, &res))") + with self.indent(): + self.print("return res;") + self.print("int mark = p->mark;") + self.print("int resmark = p->mark;") + self.print("while (1) {") + with self.indent(): + self.call_with_errorcheck_return( + f"_PyPegen_update_memo(p, mark, {node.name}_type, res)", "res" + ) + self.print("p->mark = mark;") + self.print(f"void *raw = {node.name}_raw(p);") + self.print("if (raw == NULL || p->mark <= resmark)") + with self.indent(): + self.print("break;") + self.print("resmark = p->mark;") + self.print("res = raw;") + self.print("}") + self.print("p->mark = resmark;") + self.print("return res;") + self.print("}") + self.print(f"static {result_type}") + self.print(f"{node.name}_raw(Parser *p)") + + def _should_memoize(self, node: Rule) -> bool: + return node.memo and not node.left_recursive + + def _handle_default_rule_body(self, node: Rule, rhs: Rhs, result_type: str) -> None: + memoize = self._should_memoize(node) + + with self.indent(): + self.print("if (p->error_indicator) {") + with self.indent(): + self.print("return NULL;") + self.print("}") + self.print(f"{result_type} res = NULL;") + if memoize: + self.print(f"if (_PyPegen_is_memoized(p, {node.name}_type, &res))") + with self.indent(): + self.print("return res;") + self.print("int mark = p->mark;") + if any(alt.action and "EXTRA" in alt.action for alt in rhs.alts): + self._set_up_token_start_metadata_extraction() + self.visit( + rhs, + is_loop=False, + is_gather=node.is_gather(), + rulename=node.name if memoize else None, + ) + if self.debug: + self.print(f'fprintf(stderr, "Fail at %d: {node.name}\\n", p->mark);') + self.print("res = NULL;") + self.print(" done:") + with self.indent(): + if memoize: + self.print(f"_PyPegen_insert_memo(p, mark, {node.name}_type, res);") + self.print("return res;") + + def _handle_loop_rule_body(self, node: Rule, rhs: Rhs) -> None: + memoize = self._should_memoize(node) + is_repeat1 = node.name.startswith("_loop1") + + with self.indent(): + self.print("if (p->error_indicator) {") + with self.indent(): + self.print("return NULL;") + self.print("}") + self.print(f"void *res = NULL;") + if memoize: + self.print(f"if (_PyPegen_is_memoized(p, {node.name}_type, &res))") + with self.indent(): + self.print("return res;") + self.print("int mark = p->mark;") + self.print("int start_mark = p->mark;") + self.print("void **children = PyMem_Malloc(sizeof(void *));") + self.out_of_memory_return(f"!children", "NULL") + self.print("ssize_t children_capacity = 1;") + self.print("ssize_t n = 0;") + if any(alt.action and "EXTRA" in alt.action for alt in rhs.alts): + self._set_up_token_start_metadata_extraction() + self.visit( + rhs, + is_loop=True, + is_gather=node.is_gather(), + rulename=node.name if memoize else None, + ) + if is_repeat1: + self.print("if (n == 0) {") + with self.indent(): + self.print("PyMem_Free(children);") + self.print("return NULL;") + self.print("}") + self.print("asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);") + self.out_of_memory_return( + f"!seq", + "NULL", + message=f"asdl_seq_new {node.name}", + cleanup_code="PyMem_Free(children);", + ) + self.print("for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);") + self.print("PyMem_Free(children);") + if node.name: + self.print(f"_PyPegen_insert_memo(p, start_mark, {node.name}_type, seq);") + self.print("return seq;") + + def visit_Rule(self, node: Rule) -> None: + is_loop = node.is_loop() + is_gather = node.is_gather() + rhs = node.flatten() + if is_loop or is_gather: + result_type = "asdl_seq *" + elif node.type: + result_type = node.type + else: + result_type = "void *" + + for line in str(node).splitlines(): + self.print(f"// {line}") + if node.left_recursive and node.leader: + self.print(f"static {result_type} {node.name}_raw(Parser *);") + + self.print(f"static {result_type}") + self.print(f"{node.name}_rule(Parser *p)") + + if node.left_recursive and node.leader: + self._set_up_rule_memoization(node, result_type) + + self.print("{") + if is_loop: + self._handle_loop_rule_body(node, rhs) + else: + self._handle_default_rule_body(node, rhs, result_type) + self.print("}") + + def visit_NamedItem(self, node: NamedItem) -> None: + call = self.callmakervisitor.visit(node) + if call.assigned_variable: + call.assigned_variable = self.dedupe(call.assigned_variable) + self.print(call) + + def visit_Rhs( + self, node: Rhs, is_loop: bool, is_gather: bool, rulename: Optional[str] + ) -> None: + if is_loop: + assert len(node.alts) == 1 + for alt in node.alts: + self.visit(alt, is_loop=is_loop, is_gather=is_gather, rulename=rulename) + + def join_conditions(self, keyword: str, node: Any) -> None: + self.print(f"{keyword} (") + with self.indent(): + first = True + for item in node.items: + if first: + first = False + else: + self.print("&&") + self.visit(item) + self.print(")") + + def emit_action(self, node: Alt, cleanup_code: Optional[str] = None) -> None: + self.print(f"res = {node.action};") + + self.print("if (res == NULL && PyErr_Occurred()) {") + with self.indent(): + self.print("p->error_indicator = 1;") + if cleanup_code: + self.print(cleanup_code) + self.print("return NULL;") + self.print("}") + + if self.debug: + self.print( + f'fprintf(stderr, "Hit with action [%d-%d]: %s\\n", mark, p->mark, "{node}");' + ) + + def emit_default_action(self, is_gather: bool, node: Alt) -> None: + if len(self.local_variable_names) > 1: + if is_gather: + assert len(self.local_variable_names) == 2 + self.print( + f"res = _PyPegen_seq_insert_in_front(p, " + f"{self.local_variable_names[0]}, {self.local_variable_names[1]});" + ) + else: + if self.debug: + self.print( + f'fprintf(stderr, "Hit without action [%d:%d]: %s\\n", mark, p->mark, "{node}");' + ) + self.print( + f"res = _PyPegen_dummy_name(p, {', '.join(self.local_variable_names)});" + ) + else: + if self.debug: + self.print( + f'fprintf(stderr, "Hit with default action [%d:%d]: %s\\n", mark, p->mark, "{node}");' + ) + self.print(f"res = {self.local_variable_names[0]};") + + def emit_dummy_action(self) -> None: + self.print(f"res = _PyPegen_dummy_name(p);") + + def handle_alt_normal(self, node: Alt, is_gather: bool) -> None: + self.join_conditions(keyword="if", node=node) + self.print("{") + # We have parsed successfully all the conditions for the option. + with self.indent(): + # Prepare to emmit the rule action and do so + if node.action and "EXTRA" in node.action: + self._set_up_token_end_metadata_extraction() + if self.skip_actions: + self.emit_dummy_action() + elif node.action: + self.emit_action(node) + else: + self.emit_default_action(is_gather, node) + + # As the current option has parsed correctly, do not continue with the rest. + self.print(f"goto done;") + self.print("}") + + def handle_alt_loop(self, node: Alt, is_gather: bool, rulename: Optional[str]) -> None: + # Condition of the main body of the alternative + self.join_conditions(keyword="while", node=node) + self.print("{") + # We have parsed successfully one item! + with self.indent(): + # Prepare to emit the rule action and do so + if node.action and "EXTRA" in node.action: + self._set_up_token_end_metadata_extraction() + if self.skip_actions: + self.emit_dummy_action() + elif node.action: + self.emit_action(node, cleanup_code="PyMem_Free(children);") + else: + self.emit_default_action(is_gather, node) + + # Add the result of rule to the temporary buffer of children. This buffer + # will populate later an asdl_seq with all elements to return. + self.print("if (n == children_capacity) {") + with self.indent(): + self.print("children_capacity *= 2;") + self.print("children = PyMem_Realloc(children, children_capacity*sizeof(void *));") + self.out_of_memory_return(f"!children", "NULL", message=f"realloc {rulename}") + self.print("}") + self.print(f"children[n++] = res;") + self.print("mark = p->mark;") + self.print("}") + + def visit_Alt( + self, node: Alt, is_loop: bool, is_gather: bool, rulename: Optional[str] + ) -> None: + self.print(f"{{ // {node}") + with self.indent(): + # Prepare variable declarations for the alternative + vars = self.collect_vars(node) + for v, var_type in sorted(item for item in vars.items() if item[0] is not None): + if not var_type: + var_type = "void *" + else: + var_type += " " + if v == "cut_var": + v += " = 0" # cut_var must be initialized + self.print(f"{var_type}{v};") + if v == "opt_var": + self.print("UNUSED(opt_var); // Silence compiler warnings") + + with self.local_variable_context(): + if is_loop: + self.handle_alt_loop(node, is_gather, rulename) + else: + self.handle_alt_normal(node, is_gather) + + self.print("p->mark = mark;") + if "cut_var" in vars: + self.print("if (cut_var) return NULL;") + self.print("}") + + def collect_vars(self, node: Alt) -> Dict[Optional[str], Optional[str]]: + types = {} + with self.local_variable_context(): + for item in node.items: + name, type = self.add_var(item) + types[name] = type + return types + + def add_var(self, node: NamedItem) -> Tuple[Optional[str], Optional[str]]: + call = self.callmakervisitor.visit(node.item) + return self.dedupe(node.name if node.name else call.assigned_variable), call.return_type diff --git a/ast3/Tools/peg_generator/pegen/first_sets.py b/ast3/Tools/peg_generator/pegen/first_sets.py new file mode 100755 index 00000000..71be5a2e --- /dev/null +++ b/ast3/Tools/peg_generator/pegen/first_sets.py @@ -0,0 +1,152 @@ +#!/usr/bin/env python3.8 + +import argparse +import pprint +import sys +from typing import Set, Dict + +from pegen.build import build_parser +from pegen.grammar import ( + Alt, + Cut, + Gather, + Grammar, + GrammarVisitor, + Group, + Leaf, + Lookahead, + NamedItem, + NameLeaf, + NegativeLookahead, + Opt, + Repeat, + Repeat0, + Repeat1, + Rhs, + Rule, + StringLeaf, + PositiveLookahead, +) + +argparser = argparse.ArgumentParser( + prog="calculate_first_sets", description="Calculate the first sets of a grammar", +) +argparser.add_argument("grammar_file", help="The grammar file") + + +class FirstSetCalculator(GrammarVisitor): + def __init__(self, rules: Dict[str, Rule]) -> None: + self.rules = rules + for rule in rules.values(): + rule.nullable_visit(rules) + self.first_sets: Dict[str, Set[str]] = dict() + self.in_process: Set[str] = set() + + def calculate(self) -> Dict[str, Set[str]]: + for name, rule in self.rules.items(): + self.visit(rule) + return self.first_sets + + def visit_Alt(self, item: Alt) -> Set[str]: + result: Set[str] = set() + to_remove: Set[str] = set() + for other in item.items: + new_terminals = self.visit(other) + if isinstance(other.item, NegativeLookahead): + to_remove |= new_terminals + result |= new_terminals + if to_remove: + result -= to_remove + + # If the set of new terminals can start with the empty string, + # it means that the item is completelly nullable and we should + # also considering at least the next item in case the current + # one fails to parse. + + if "" in new_terminals: + continue + + if not isinstance(other.item, (Opt, NegativeLookahead, Repeat0)): + break + + # Do not allow the empty string to propagate. + result.discard("") + + return result + + def visit_Cut(self, item: Cut) -> Set[str]: + return set() + + def visit_Group(self, item: Group) -> Set[str]: + return self.visit(item.rhs) + + def visit_PositiveLookahead(self, item: Lookahead) -> Set[str]: + return self.visit(item.node) + + def visit_NegativeLookahead(self, item: NegativeLookahead) -> Set[str]: + return self.visit(item.node) + + def visit_NamedItem(self, item: NamedItem) -> Set[str]: + return self.visit(item.item) + + def visit_Opt(self, item: Opt) -> Set[str]: + return self.visit(item.node) + + def visit_Gather(self, item: Gather) -> Set[str]: + return self.visit(item.node) + + def visit_Repeat0(self, item: Repeat0) -> Set[str]: + return self.visit(item.node) + + def visit_Repeat1(self, item: Repeat1) -> Set[str]: + return self.visit(item.node) + + def visit_NameLeaf(self, item: NameLeaf) -> Set[str]: + if item.value not in self.rules: + return {item.value} + + if item.value not in self.first_sets: + self.first_sets[item.value] = self.visit(self.rules[item.value]) + return self.first_sets[item.value] + elif item.value in self.in_process: + return set() + + return self.first_sets[item.value] + + def visit_StringLeaf(self, item: StringLeaf) -> Set[str]: + return {item.value} + + def visit_Rhs(self, item: Rhs) -> Set[str]: + result: Set[str] = set() + for alt in item.alts: + result |= self.visit(alt) + return result + + def visit_Rule(self, item: Rule) -> Set[str]: + if item.name in self.in_process: + return set() + elif item.name not in self.first_sets: + self.in_process.add(item.name) + terminals = self.visit(item.rhs) + if item.nullable: + terminals.add("") + self.first_sets[item.name] = terminals + self.in_process.remove(item.name) + return self.first_sets[item.name] + + +def main() -> None: + args = argparser.parse_args() + + try: + grammar, parser, tokenizer = build_parser(args.grammar_file) + except Exception as err: + print("ERROR: Failed to parse grammar file", file=sys.stderr) + sys.exit(1) + + firs_sets = FirstSetCalculator(grammar.rules).calculate() + pprint.pprint(firs_sets) + + +if __name__ == "__main__": + main() diff --git a/ast3/Tools/peg_generator/pegen/grammar.py b/ast3/Tools/peg_generator/pegen/grammar.py new file mode 100644 index 00000000..78edf412 --- /dev/null +++ b/ast3/Tools/peg_generator/pegen/grammar.py @@ -0,0 +1,467 @@ +from __future__ import annotations + +from abc import abstractmethod +from typing import ( + AbstractSet, + Any, + Dict, + Iterable, + Iterator, + List, + Optional, + Set, + Tuple, + TYPE_CHECKING, + Union, +) + + +if TYPE_CHECKING: + from pegen.parser_generator import ParserGenerator + + +class GrammarError(Exception): + pass + + +class GrammarVisitor: + def visit(self, node: Any, *args: Any, **kwargs: Any) -> Any: + """Visit a node.""" + method = "visit_" + node.__class__.__name__ + visitor = getattr(self, method, self.generic_visit) + return visitor(node, *args, **kwargs) + + def generic_visit(self, node: Iterable[Any], *args: Any, **kwargs: Any) -> None: + """Called if no explicit visitor function exists for a node.""" + for value in node: + if isinstance(value, list): + for item in value: + self.visit(item, *args, **kwargs) + else: + self.visit(value, *args, **kwargs) + + +class Grammar: + def __init__(self, rules: Iterable[Rule], metas: Iterable[Tuple[str, Optional[str]]]): + self.rules = {rule.name: rule for rule in rules} + self.metas = dict(metas) + + def __str__(self) -> str: + return "\n".join(str(rule) for name, rule in self.rules.items()) + + def __repr__(self) -> str: + lines = ["Grammar("] + lines.append(" [") + for rule in self.rules.values(): + lines.append(f" {repr(rule)},") + lines.append(" ],") + lines.append(" {repr(list(self.metas.items()))}") + lines.append(")") + return "\n".join(lines) + + def __iter__(self) -> Iterator[Rule]: + yield from self.rules.values() + + +# Global flag whether we want actions in __str__() -- default off. +SIMPLE_STR = True + + +class Rule: + def __init__(self, name: str, type: Optional[str], rhs: Rhs, memo: Optional[object] = None): + self.name = name + self.type = type + self.rhs = rhs + self.memo = bool(memo) + self.visited = False + self.nullable = False + self.left_recursive = False + self.leader = False + + def is_loop(self) -> bool: + return self.name.startswith("_loop") + + def is_gather(self) -> bool: + return self.name.startswith("_gather") + + def __str__(self) -> str: + if SIMPLE_STR or self.type is None: + res = f"{self.name}: {self.rhs}" + else: + res = f"{self.name}[{self.type}]: {self.rhs}" + if len(res) < 88: + return res + lines = [res.split(":")[0] + ":"] + lines += [f" | {alt}" for alt in self.rhs.alts] + return "\n".join(lines) + + def __repr__(self) -> str: + return f"Rule({self.name!r}, {self.type!r}, {self.rhs!r})" + + def __iter__(self) -> Iterator[Rhs]: + yield self.rhs + + def nullable_visit(self, rules: Dict[str, Rule]) -> bool: + if self.visited: + # A left-recursive rule is considered non-nullable. + return False + self.visited = True + self.nullable = self.rhs.nullable_visit(rules) + return self.nullable + + def initial_names(self) -> AbstractSet[str]: + return self.rhs.initial_names() + + def flatten(self) -> Rhs: + # If it's a single parenthesized group, flatten it. + rhs = self.rhs + if ( + not self.is_loop() + and len(rhs.alts) == 1 + and len(rhs.alts[0].items) == 1 + and isinstance(rhs.alts[0].items[0].item, Group) + ): + rhs = rhs.alts[0].items[0].item.rhs + return rhs + + def collect_todo(self, gen: ParserGenerator) -> None: + rhs = self.flatten() + rhs.collect_todo(gen) + + +class Leaf: + def __init__(self, value: str): + self.value = value + + def __str__(self) -> str: + return self.value + + def __iter__(self) -> Iterable[str]: + if False: + yield + + @abstractmethod + def nullable_visit(self, rules: Dict[str, Rule]) -> bool: + raise NotImplementedError + + @abstractmethod + def initial_names(self) -> AbstractSet[str]: + raise NotImplementedError + + +class NameLeaf(Leaf): + """The value is the name.""" + + def __str__(self) -> str: + if self.value == "ENDMARKER": + return "$" + return super().__str__() + + def __repr__(self) -> str: + return f"NameLeaf({self.value!r})" + + def nullable_visit(self, rules: Dict[str, Rule]) -> bool: + if self.value in rules: + return rules[self.value].nullable_visit(rules) + # Token or unknown; never empty. + return False + + def initial_names(self) -> AbstractSet[str]: + return {self.value} + + +class StringLeaf(Leaf): + """The value is a string literal, including quotes.""" + + def __repr__(self) -> str: + return f"StringLeaf({self.value!r})" + + def nullable_visit(self, rules: Dict[str, Rule]) -> bool: + # The string token '' is considered empty. + return not self.value + + def initial_names(self) -> AbstractSet[str]: + return set() + + +class Rhs: + def __init__(self, alts: List[Alt]): + self.alts = alts + self.memo: Optional[Tuple[Optional[str], str]] = None + + def __str__(self) -> str: + return " | ".join(str(alt) for alt in self.alts) + + def __repr__(self) -> str: + return f"Rhs({self.alts!r})" + + def __iter__(self) -> Iterator[List[Alt]]: + yield self.alts + + def nullable_visit(self, rules: Dict[str, Rule]) -> bool: + for alt in self.alts: + if alt.nullable_visit(rules): + return True + return False + + def initial_names(self) -> AbstractSet[str]: + names: Set[str] = set() + for alt in self.alts: + names |= alt.initial_names() + return names + + def collect_todo(self, gen: ParserGenerator) -> None: + for alt in self.alts: + alt.collect_todo(gen) + + +class Alt: + def __init__(self, items: List[NamedItem], *, icut: int = -1, action: Optional[str] = None): + self.items = items + self.icut = icut + self.action = action + + def __str__(self) -> str: + core = " ".join(str(item) for item in self.items) + if not SIMPLE_STR and self.action: + return f"{core} {{ {self.action} }}" + else: + return core + + def __repr__(self) -> str: + args = [repr(self.items)] + if self.icut >= 0: + args.append(f"icut={self.icut}") + if self.action: + args.append(f"action={self.action!r}") + return f"Alt({', '.join(args)})" + + def __iter__(self) -> Iterator[List[NamedItem]]: + yield self.items + + def nullable_visit(self, rules: Dict[str, Rule]) -> bool: + for item in self.items: + if not item.nullable_visit(rules): + return False + return True + + def initial_names(self) -> AbstractSet[str]: + names: Set[str] = set() + for item in self.items: + names |= item.initial_names() + if not item.nullable: + break + return names + + def collect_todo(self, gen: ParserGenerator) -> None: + for item in self.items: + item.collect_todo(gen) + + +class NamedItem: + def __init__(self, name: Optional[str], item: Item): + self.name = name + self.item = item + self.nullable = False + + def __str__(self) -> str: + if not SIMPLE_STR and self.name: + return f"{self.name}={self.item}" + else: + return str(self.item) + + def __repr__(self) -> str: + return f"NamedItem({self.name!r}, {self.item!r})" + + def __iter__(self) -> Iterator[Item]: + yield self.item + + def nullable_visit(self, rules: Dict[str, Rule]) -> bool: + self.nullable = self.item.nullable_visit(rules) + return self.nullable + + def initial_names(self) -> AbstractSet[str]: + return self.item.initial_names() + + def collect_todo(self, gen: ParserGenerator) -> None: + gen.callmakervisitor.visit(self.item) + + +class Lookahead: + def __init__(self, node: Plain, sign: str): + self.node = node + self.sign = sign + + def __str__(self) -> str: + return f"{self.sign}{self.node}" + + def __iter__(self) -> Iterator[Plain]: + yield self.node + + def nullable_visit(self, rules: Dict[str, Rule]) -> bool: + return True + + def initial_names(self) -> AbstractSet[str]: + return set() + + +class PositiveLookahead(Lookahead): + def __init__(self, node: Plain): + super().__init__(node, "&") + + def __repr__(self) -> str: + return f"PositiveLookahead({self.node!r})" + + +class NegativeLookahead(Lookahead): + def __init__(self, node: Plain): + super().__init__(node, "!") + + def __repr__(self) -> str: + return f"NegativeLookahead({self.node!r})" + + +class Opt: + def __init__(self, node: Item): + self.node = node + + def __str__(self) -> str: + s = str(self.node) + # TODO: Decide whether to use [X] or X? based on type of X + if " " in s: + return f"[{s}]" + else: + return f"{s}?" + + def __repr__(self) -> str: + return f"Opt({self.node!r})" + + def __iter__(self) -> Iterator[Item]: + yield self.node + + def nullable_visit(self, rules: Dict[str, Rule]) -> bool: + return True + + def initial_names(self) -> AbstractSet[str]: + return self.node.initial_names() + + +class Repeat: + """Shared base class for x* and x+.""" + + def __init__(self, node: Plain): + self.node = node + self.memo: Optional[Tuple[Optional[str], str]] = None + + @abstractmethod + def nullable_visit(self, rules: Dict[str, Rule]) -> bool: + raise NotImplementedError + + def __iter__(self) -> Iterator[Plain]: + yield self.node + + def initial_names(self) -> AbstractSet[str]: + return self.node.initial_names() + + +class Repeat0(Repeat): + def __str__(self) -> str: + s = str(self.node) + # TODO: Decide whether to use (X)* or X* based on type of X + if " " in s: + return f"({s})*" + else: + return f"{s}*" + + def __repr__(self) -> str: + return f"Repeat0({self.node!r})" + + def nullable_visit(self, rules: Dict[str, Rule]) -> bool: + return True + + +class Repeat1(Repeat): + def __str__(self) -> str: + s = str(self.node) + # TODO: Decide whether to use (X)+ or X+ based on type of X + if " " in s: + return f"({s})+" + else: + return f"{s}+" + + def __repr__(self) -> str: + return f"Repeat1({self.node!r})" + + def nullable_visit(self, rules: Dict[str, Rule]) -> bool: + return False + + +class Gather(Repeat): + def __init__(self, separator: Plain, node: Plain): + self.separator = separator + self.node = node + + def __str__(self) -> str: + return f"{self.separator!s}.{self.node!s}+" + + def __repr__(self) -> str: + return f"Gather({self.separator!r}, {self.node!r})" + + def nullable_visit(self, rules: Dict[str, Rule]) -> bool: + return False + + +class Group: + def __init__(self, rhs: Rhs): + self.rhs = rhs + + def __str__(self) -> str: + return f"({self.rhs})" + + def __repr__(self) -> str: + return f"Group({self.rhs!r})" + + def __iter__(self) -> Iterator[Rhs]: + yield self.rhs + + def nullable_visit(self, rules: Dict[str, Rule]) -> bool: + return self.rhs.nullable_visit(rules) + + def initial_names(self) -> AbstractSet[str]: + return self.rhs.initial_names() + + +class Cut: + def __init__(self) -> None: + pass + + def __repr__(self) -> str: + return f"Cut()" + + def __str__(self) -> str: + return f"~" + + def __iter__(self) -> Iterator[Tuple[str, str]]: + if False: + yield + + def __eq__(self, other: object) -> bool: + if not isinstance(other, Cut): + return NotImplemented + return True + + def nullable_visit(self, rules: Dict[str, Rule]) -> bool: + return True + + def initial_names(self) -> AbstractSet[str]: + return set() + + +Plain = Union[Leaf, Group] +Item = Union[Plain, Opt, Repeat, Lookahead, Rhs, Cut] +RuleName = Tuple[str, str] +MetaTuple = Tuple[str, Optional[str]] +MetaList = List[MetaTuple] +RuleList = List[Rule] +NamedItemList = List[NamedItem] +LookaheadOrCut = Union[Lookahead, Cut] diff --git a/ast3/Tools/peg_generator/pegen/grammar_parser.py b/ast3/Tools/peg_generator/pegen/grammar_parser.py new file mode 100644 index 00000000..c784cfdf --- /dev/null +++ b/ast3/Tools/peg_generator/pegen/grammar_parser.py @@ -0,0 +1,677 @@ +#!/usr/bin/env python3.8 +# @generated by pegen from ./Tools/peg_generator/pegen/metagrammar.gram + +import ast +import sys +import tokenize + +from typing import Any, Optional + +from pegen.parser import memoize, memoize_left_rec, logger, Parser +from ast import literal_eval + +from pegen.grammar import ( + Alt, + Cut, + Gather, + Group, + Item, + Lookahead, + LookaheadOrCut, + MetaTuple, + MetaList, + NameLeaf, + NamedItem, + NamedItemList, + NegativeLookahead, + Opt, + Plain, + PositiveLookahead, + Repeat0, + Repeat1, + Rhs, + Rule, + RuleList, + RuleName, + Grammar, + StringLeaf, +) + +class GeneratedParser(Parser): + + @memoize + def start(self) -> Optional[Grammar]: + # start: grammar $ + mark = self.mark() + cut = False + if ( + (grammar := self.grammar()) + and + (endmarker := self.expect('ENDMARKER')) + ): + return grammar + self.reset(mark) + if cut: return None + return None + + @memoize + def grammar(self) -> Optional[Grammar]: + # grammar: metas rules | rules + mark = self.mark() + cut = False + if ( + (metas := self.metas()) + and + (rules := self.rules()) + ): + return Grammar ( rules , metas ) + self.reset(mark) + if cut: return None + cut = False + if ( + (rules := self.rules()) + ): + return Grammar ( rules , [ ] ) + self.reset(mark) + if cut: return None + return None + + @memoize + def metas(self) -> Optional[MetaList]: + # metas: meta metas | meta + mark = self.mark() + cut = False + if ( + (meta := self.meta()) + and + (metas := self.metas()) + ): + return [ meta ] + metas + self.reset(mark) + if cut: return None + cut = False + if ( + (meta := self.meta()) + ): + return [ meta ] + self.reset(mark) + if cut: return None + return None + + @memoize + def meta(self) -> Optional[MetaTuple]: + # meta: "@" NAME NEWLINE | "@" NAME NAME NEWLINE | "@" NAME STRING NEWLINE + mark = self.mark() + cut = False + if ( + (literal := self.expect("@")) + and + (name := self.name()) + and + (newline := self.expect('NEWLINE')) + ): + return ( name . string , None ) + self.reset(mark) + if cut: return None + cut = False + if ( + (literal := self.expect("@")) + and + (a := self.name()) + and + (b := self.name()) + and + (newline := self.expect('NEWLINE')) + ): + return ( a . string , b . string ) + self.reset(mark) + if cut: return None + cut = False + if ( + (literal := self.expect("@")) + and + (name := self.name()) + and + (string := self.string()) + and + (newline := self.expect('NEWLINE')) + ): + return ( name . string , literal_eval ( string . string ) ) + self.reset(mark) + if cut: return None + return None + + @memoize + def rules(self) -> Optional[RuleList]: + # rules: rule rules | rule + mark = self.mark() + cut = False + if ( + (rule := self.rule()) + and + (rules := self.rules()) + ): + return [ rule ] + rules + self.reset(mark) + if cut: return None + cut = False + if ( + (rule := self.rule()) + ): + return [ rule ] + self.reset(mark) + if cut: return None + return None + + @memoize + def rule(self) -> Optional[Rule]: + # rule: rulename memoflag? ":" alts NEWLINE INDENT more_alts DEDENT | rulename memoflag? ":" NEWLINE INDENT more_alts DEDENT | rulename memoflag? ":" alts NEWLINE + mark = self.mark() + cut = False + if ( + (rulename := self.rulename()) + and + (opt := self.memoflag(),) + and + (literal := self.expect(":")) + and + (alts := self.alts()) + and + (newline := self.expect('NEWLINE')) + and + (indent := self.expect('INDENT')) + and + (more_alts := self.more_alts()) + and + (dedent := self.expect('DEDENT')) + ): + return Rule ( rulename [ 0 ] , rulename [ 1 ] , Rhs ( alts . alts + more_alts . alts ) , memo = opt ) + self.reset(mark) + if cut: return None + cut = False + if ( + (rulename := self.rulename()) + and + (opt := self.memoflag(),) + and + (literal := self.expect(":")) + and + (newline := self.expect('NEWLINE')) + and + (indent := self.expect('INDENT')) + and + (more_alts := self.more_alts()) + and + (dedent := self.expect('DEDENT')) + ): + return Rule ( rulename [ 0 ] , rulename [ 1 ] , more_alts , memo = opt ) + self.reset(mark) + if cut: return None + cut = False + if ( + (rulename := self.rulename()) + and + (opt := self.memoflag(),) + and + (literal := self.expect(":")) + and + (alts := self.alts()) + and + (newline := self.expect('NEWLINE')) + ): + return Rule ( rulename [ 0 ] , rulename [ 1 ] , alts , memo = opt ) + self.reset(mark) + if cut: return None + return None + + @memoize + def rulename(self) -> Optional[RuleName]: + # rulename: NAME '[' NAME '*' ']' | NAME '[' NAME ']' | NAME + mark = self.mark() + cut = False + if ( + (name := self.name()) + and + (literal := self.expect('[')) + and + (type := self.name()) + and + (literal_1 := self.expect('*')) + and + (literal_2 := self.expect(']')) + ): + return ( name . string , type . string + "*" ) + self.reset(mark) + if cut: return None + cut = False + if ( + (name := self.name()) + and + (literal := self.expect('[')) + and + (type := self.name()) + and + (literal_1 := self.expect(']')) + ): + return ( name . string , type . string ) + self.reset(mark) + if cut: return None + cut = False + if ( + (name := self.name()) + ): + return ( name . string , None ) + self.reset(mark) + if cut: return None + return None + + @memoize + def memoflag(self) -> Optional[str]: + # memoflag: '(' 'memo' ')' + mark = self.mark() + cut = False + if ( + (literal := self.expect('(')) + and + (literal_1 := self.expect('memo')) + and + (literal_2 := self.expect(')')) + ): + return "memo" + self.reset(mark) + if cut: return None + return None + + @memoize + def alts(self) -> Optional[Rhs]: + # alts: alt "|" alts | alt + mark = self.mark() + cut = False + if ( + (alt := self.alt()) + and + (literal := self.expect("|")) + and + (alts := self.alts()) + ): + return Rhs ( [ alt ] + alts . alts ) + self.reset(mark) + if cut: return None + cut = False + if ( + (alt := self.alt()) + ): + return Rhs ( [ alt ] ) + self.reset(mark) + if cut: return None + return None + + @memoize + def more_alts(self) -> Optional[Rhs]: + # more_alts: "|" alts NEWLINE more_alts | "|" alts NEWLINE + mark = self.mark() + cut = False + if ( + (literal := self.expect("|")) + and + (alts := self.alts()) + and + (newline := self.expect('NEWLINE')) + and + (more_alts := self.more_alts()) + ): + return Rhs ( alts . alts + more_alts . alts ) + self.reset(mark) + if cut: return None + cut = False + if ( + (literal := self.expect("|")) + and + (alts := self.alts()) + and + (newline := self.expect('NEWLINE')) + ): + return Rhs ( alts . alts ) + self.reset(mark) + if cut: return None + return None + + @memoize + def alt(self) -> Optional[Alt]: + # alt: items '$' action | items '$' | items action | items + mark = self.mark() + cut = False + if ( + (items := self.items()) + and + (literal := self.expect('$')) + and + (action := self.action()) + ): + return Alt ( items + [ NamedItem ( None , NameLeaf ( 'ENDMARKER' ) ) ] , action = action ) + self.reset(mark) + if cut: return None + cut = False + if ( + (items := self.items()) + and + (literal := self.expect('$')) + ): + return Alt ( items + [ NamedItem ( None , NameLeaf ( 'ENDMARKER' ) ) ] , action = None ) + self.reset(mark) + if cut: return None + cut = False + if ( + (items := self.items()) + and + (action := self.action()) + ): + return Alt ( items , action = action ) + self.reset(mark) + if cut: return None + cut = False + if ( + (items := self.items()) + ): + return Alt ( items , action = None ) + self.reset(mark) + if cut: return None + return None + + @memoize + def items(self) -> Optional[NamedItemList]: + # items: named_item items | named_item + mark = self.mark() + cut = False + if ( + (named_item := self.named_item()) + and + (items := self.items()) + ): + return [ named_item ] + items + self.reset(mark) + if cut: return None + cut = False + if ( + (named_item := self.named_item()) + ): + return [ named_item ] + self.reset(mark) + if cut: return None + return None + + @memoize + def named_item(self) -> Optional[NamedItem]: + # named_item: NAME '=' ~ item | item | lookahead + mark = self.mark() + cut = False + if ( + (name := self.name()) + and + (literal := self.expect('=')) + and + (cut := True) + and + (item := self.item()) + ): + return NamedItem ( name . string , item ) + self.reset(mark) + if cut: return None + cut = False + if ( + (item := self.item()) + ): + return NamedItem ( None , item ) + self.reset(mark) + if cut: return None + cut = False + if ( + (it := self.lookahead()) + ): + return NamedItem ( None , it ) + self.reset(mark) + if cut: return None + return None + + @memoize + def lookahead(self) -> Optional[LookaheadOrCut]: + # lookahead: '&' ~ atom | '!' ~ atom | '~' + mark = self.mark() + cut = False + if ( + (literal := self.expect('&')) + and + (cut := True) + and + (atom := self.atom()) + ): + return PositiveLookahead ( atom ) + self.reset(mark) + if cut: return None + cut = False + if ( + (literal := self.expect('!')) + and + (cut := True) + and + (atom := self.atom()) + ): + return NegativeLookahead ( atom ) + self.reset(mark) + if cut: return None + cut = False + if ( + (literal := self.expect('~')) + ): + return Cut ( ) + self.reset(mark) + if cut: return None + return None + + @memoize + def item(self) -> Optional[Item]: + # item: '[' ~ alts ']' | atom '?' | atom '*' | atom '+' | atom '.' atom '+' | atom + mark = self.mark() + cut = False + if ( + (literal := self.expect('[')) + and + (cut := True) + and + (alts := self.alts()) + and + (literal_1 := self.expect(']')) + ): + return Opt ( alts ) + self.reset(mark) + if cut: return None + cut = False + if ( + (atom := self.atom()) + and + (literal := self.expect('?')) + ): + return Opt ( atom ) + self.reset(mark) + if cut: return None + cut = False + if ( + (atom := self.atom()) + and + (literal := self.expect('*')) + ): + return Repeat0 ( atom ) + self.reset(mark) + if cut: return None + cut = False + if ( + (atom := self.atom()) + and + (literal := self.expect('+')) + ): + return Repeat1 ( atom ) + self.reset(mark) + if cut: return None + cut = False + if ( + (sep := self.atom()) + and + (literal := self.expect('.')) + and + (node := self.atom()) + and + (literal_1 := self.expect('+')) + ): + return Gather ( sep , node ) + self.reset(mark) + if cut: return None + cut = False + if ( + (atom := self.atom()) + ): + return atom + self.reset(mark) + if cut: return None + return None + + @memoize + def atom(self) -> Optional[Plain]: + # atom: '(' ~ alts ')' | NAME | STRING + mark = self.mark() + cut = False + if ( + (literal := self.expect('(')) + and + (cut := True) + and + (alts := self.alts()) + and + (literal_1 := self.expect(')')) + ): + return Group ( alts ) + self.reset(mark) + if cut: return None + cut = False + if ( + (name := self.name()) + ): + return NameLeaf ( name . string ) + self.reset(mark) + if cut: return None + cut = False + if ( + (string := self.string()) + ): + return StringLeaf ( string . string ) + self.reset(mark) + if cut: return None + return None + + @memoize + def action(self) -> Optional[str]: + # action: "{" ~ target_atoms "}" + mark = self.mark() + cut = False + if ( + (literal := self.expect("{")) + and + (cut := True) + and + (target_atoms := self.target_atoms()) + and + (literal_1 := self.expect("}")) + ): + return target_atoms + self.reset(mark) + if cut: return None + return None + + @memoize + def target_atoms(self) -> Optional[str]: + # target_atoms: target_atom target_atoms | target_atom + mark = self.mark() + cut = False + if ( + (target_atom := self.target_atom()) + and + (target_atoms := self.target_atoms()) + ): + return target_atom + " " + target_atoms + self.reset(mark) + if cut: return None + cut = False + if ( + (target_atom := self.target_atom()) + ): + return target_atom + self.reset(mark) + if cut: return None + return None + + @memoize + def target_atom(self) -> Optional[str]: + # target_atom: "{" ~ target_atoms "}" | NAME | NUMBER | STRING | "?" | ":" | !"}" OP + mark = self.mark() + cut = False + if ( + (literal := self.expect("{")) + and + (cut := True) + and + (target_atoms := self.target_atoms()) + and + (literal_1 := self.expect("}")) + ): + return "{" + target_atoms + "}" + self.reset(mark) + if cut: return None + cut = False + if ( + (name := self.name()) + ): + return name . string + self.reset(mark) + if cut: return None + cut = False + if ( + (number := self.number()) + ): + return number . string + self.reset(mark) + if cut: return None + cut = False + if ( + (string := self.string()) + ): + return string . string + self.reset(mark) + if cut: return None + cut = False + if ( + (literal := self.expect("?")) + ): + return "?" + self.reset(mark) + if cut: return None + cut = False + if ( + (literal := self.expect(":")) + ): + return ":" + self.reset(mark) + if cut: return None + cut = False + if ( + self.negative_lookahead(self.expect, "}") + and + (op := self.op()) + ): + return op . string + self.reset(mark) + if cut: return None + return None + + +if __name__ == '__main__': + from pegen.parser import simple_parser_main + simple_parser_main(GeneratedParser) diff --git a/ast3/Tools/peg_generator/pegen/grammar_visualizer.py b/ast3/Tools/peg_generator/pegen/grammar_visualizer.py new file mode 100644 index 00000000..7362ec5f --- /dev/null +++ b/ast3/Tools/peg_generator/pegen/grammar_visualizer.py @@ -0,0 +1,65 @@ +import argparse +import sys + +from typing import Any, Iterator, Callable + +from pegen.build import build_parser +from pegen.grammar import Grammar, Rule + +argparser = argparse.ArgumentParser( + prog="pegen", description="Pretty print the AST for a given PEG grammar" +) +argparser.add_argument("filename", help="Grammar description") + + +class ASTGrammarPrinter: + def children(self, node: Rule) -> Iterator[Any]: + for value in node: + if isinstance(value, list): + yield from value + else: + yield value + + def name(self, node: Rule) -> str: + if not list(self.children(node)): + return repr(node) + return node.__class__.__name__ + + def print_grammar_ast(self, grammar: Grammar, printer: Callable[..., None] = print) -> None: + for rule in grammar.rules.values(): + printer(self.print_nodes_recursively(rule)) + + def print_nodes_recursively(self, node: Rule, prefix: str = "", istail: bool = True) -> str: + + children = list(self.children(node)) + value = self.name(node) + + line = prefix + ("└──" if istail else "├──") + value + "\n" + sufix = " " if istail else "│ " + + if not children: + return line + + *children, last = children + for child in children: + line += self.print_nodes_recursively(child, prefix + sufix, False) + line += self.print_nodes_recursively(last, prefix + sufix, True) + + return line + + +def main() -> None: + args = argparser.parse_args() + + try: + grammar, parser, tokenizer = build_parser(args.filename) + except Exception as err: + print("ERROR: Failed to parse grammar file", file=sys.stderr) + sys.exit(1) + + visitor = ASTGrammarPrinter() + visitor.print_grammar_ast(grammar) + + +if __name__ == "__main__": + main() diff --git a/ast3/Tools/peg_generator/pegen/metagrammar.gram b/ast3/Tools/peg_generator/pegen/metagrammar.gram new file mode 100644 index 00000000..f0c5ac3a --- /dev/null +++ b/ast3/Tools/peg_generator/pegen/metagrammar.gram @@ -0,0 +1,123 @@ +@subheader """\ +from ast import literal_eval + +from pegen.grammar import ( + Alt, + Cut, + Gather, + Group, + Item, + Lookahead, + LookaheadOrCut, + MetaTuple, + MetaList, + NameLeaf, + NamedItem, + NamedItemList, + NegativeLookahead, + Opt, + Plain, + PositiveLookahead, + Repeat0, + Repeat1, + Rhs, + Rule, + RuleList, + RuleName, + Grammar, + StringLeaf, +) +""" + +start[Grammar]: grammar ENDMARKER { grammar } + +grammar[Grammar]: + | metas rules { Grammar(rules, metas) } + | rules { Grammar(rules, []) } + +metas[MetaList]: + | meta metas { [meta] + metas } + | meta { [meta] } + +meta[MetaTuple]: + | "@" NAME NEWLINE { (name.string, None) } + | "@" a=NAME b=NAME NEWLINE { (a.string, b.string) } + | "@" NAME STRING NEWLINE { (name.string, literal_eval(string.string)) } + +rules[RuleList]: + | rule rules { [rule] + rules } + | rule { [rule] } + +rule[Rule]: + | rulename memoflag? ":" alts NEWLINE INDENT more_alts DEDENT { + Rule(rulename[0], rulename[1], Rhs(alts.alts + more_alts.alts), memo=opt) } + | rulename memoflag? ":" NEWLINE INDENT more_alts DEDENT { + Rule(rulename[0], rulename[1], more_alts, memo=opt) } + | rulename memoflag? ":" alts NEWLINE { Rule(rulename[0], rulename[1], alts, memo=opt) } + +rulename[RuleName]: + | NAME '[' type=NAME '*' ']' { (name.string, type.string+"*") } + | NAME '[' type=NAME ']' { (name.string, type.string) } + | NAME { (name.string, None) } + +# In the future this may return something more complicated +memoflag[str]: + | '(' 'memo' ')' { "memo" } + +alts[Rhs]: + | alt "|" alts { Rhs([alt] + alts.alts)} + | alt { Rhs([alt]) } + +more_alts[Rhs]: + | "|" alts NEWLINE more_alts { Rhs(alts.alts + more_alts.alts) } + | "|" alts NEWLINE { Rhs(alts.alts) } + +alt[Alt]: + | items '$' action { Alt(items + [NamedItem(None, NameLeaf('ENDMARKER'))], action=action) } + | items '$' { Alt(items + [NamedItem(None, NameLeaf('ENDMARKER'))], action=None) } + | items action { Alt(items, action=action) } + | items { Alt(items, action=None) } + +items[NamedItemList]: + | named_item items { [named_item] + items } + | named_item { [named_item] } + +named_item[NamedItem]: + | NAME '=' ~ item {NamedItem(name.string, item)} + | item {NamedItem(None, item)} + | it=lookahead {NamedItem(None, it)} + +lookahead[LookaheadOrCut]: + | '&' ~ atom {PositiveLookahead(atom)} + | '!' ~ atom {NegativeLookahead(atom)} + | '~' {Cut()} + +item[Item]: + | '[' ~ alts ']' {Opt(alts)} + | atom '?' {Opt(atom)} + | atom '*' {Repeat0(atom)} + | atom '+' {Repeat1(atom)} + | sep=atom '.' node=atom '+' {Gather(sep, node)} + | atom {atom} + +atom[Plain]: + | '(' ~ alts ')' {Group(alts)} + | NAME {NameLeaf(name.string) } + | STRING {StringLeaf(string.string)} + +# Mini-grammar for the actions + +action[str]: "{" ~ target_atoms "}" { target_atoms } + +target_atoms[str]: + | target_atom target_atoms { target_atom + " " + target_atoms } + | target_atom { target_atom } + +target_atom[str]: + | "{" ~ target_atoms "}" { "{" + target_atoms + "}" } + | NAME { name.string } + | NUMBER { number.string } + | STRING { string.string } + | "?" { "?" } + | ":" { ":" } + | !"}" OP { op.string } diff --git a/ast3/Tools/peg_generator/pegen/parser.py b/ast3/Tools/peg_generator/pegen/parser.py new file mode 100644 index 00000000..16d954dc --- /dev/null +++ b/ast3/Tools/peg_generator/pegen/parser.py @@ -0,0 +1,310 @@ +import argparse +import sys +import time +import token +import tokenize +import traceback + +from abc import abstractmethod +from typing import Any, Callable, cast, Dict, Optional, Tuple, Type, TypeVar + +from pegen.tokenizer import exact_token_types +from pegen.tokenizer import Mark +from pegen.tokenizer import Tokenizer + +T = TypeVar("T") +P = TypeVar("P", bound="Parser") +F = TypeVar("F", bound=Callable[..., Any]) + + +def logger(method: F) -> F: + """For non-memoized functions that we want to be logged. + + (In practice this is only non-leader left-recursive functions.) + """ + method_name = method.__name__ + + def logger_wrapper(self: P, *args: object) -> T: + if not self._verbose: + return method(self, *args) + argsr = ",".join(repr(arg) for arg in args) + fill = " " * self._level + print(f"{fill}{method_name}({argsr}) .... (looking at {self.showpeek()})") + self._level += 1 + tree = method(self, *args) + self._level -= 1 + print(f"{fill}... {method_name}({argsr}) --> {tree!s:.200}") + return tree + + logger_wrapper.__wrapped__ = method # type: ignore + return cast(F, logger_wrapper) + + +def memoize(method: F) -> F: + """Memoize a symbol method.""" + method_name = method.__name__ + + def memoize_wrapper(self: P, *args: object) -> T: + mark = self.mark() + key = mark, method_name, args + # Fast path: cache hit, and not verbose. + if key in self._cache and not self._verbose: + tree, endmark = self._cache[key] + self.reset(endmark) + return tree + # Slow path: no cache hit, or verbose. + verbose = self._verbose + argsr = ",".join(repr(arg) for arg in args) + fill = " " * self._level + if key not in self._cache: + if verbose: + print(f"{fill}{method_name}({argsr}) ... (looking at {self.showpeek()})") + self._level += 1 + tree = method(self, *args) + self._level -= 1 + if verbose: + print(f"{fill}... {method_name}({argsr}) -> {tree!s:.200}") + endmark = self.mark() + self._cache[key] = tree, endmark + else: + tree, endmark = self._cache[key] + if verbose: + print(f"{fill}{method_name}({argsr}) -> {tree!s:.200}") + self.reset(endmark) + return tree + + memoize_wrapper.__wrapped__ = method # type: ignore + return cast(F, memoize_wrapper) + + +def memoize_left_rec(method: Callable[[P], Optional[T]]) -> Callable[[P], Optional[T]]: + """Memoize a left-recursive symbol method.""" + method_name = method.__name__ + + def memoize_left_rec_wrapper(self: P) -> Optional[T]: + mark = self.mark() + key = mark, method_name, () + # Fast path: cache hit, and not verbose. + if key in self._cache and not self._verbose: + tree, endmark = self._cache[key] + self.reset(endmark) + return tree + # Slow path: no cache hit, or verbose. + verbose = self._verbose + fill = " " * self._level + if key not in self._cache: + if verbose: + print(f"{fill}{method_name} ... (looking at {self.showpeek()})") + self._level += 1 + + # For left-recursive rules we manipulate the cache and + # loop until the rule shows no progress, then pick the + # previous result. For an explanation why this works, see + # https://github.com/PhilippeSigaud/Pegged/wiki/Left-Recursion + # (But we use the memoization cache instead of a static + # variable; perhaps this is similar to a paper by Warth et al. + # (http://web.cs.ucla.edu/~todd/research/pub.php?id=pepm08). + + # Prime the cache with a failure. + self._cache[key] = None, mark + lastresult, lastmark = None, mark + depth = 0 + if verbose: + print(f"{fill}Recursive {method_name} at {mark} depth {depth}") + + while True: + self.reset(mark) + result = method(self) + endmark = self.mark() + depth += 1 + if verbose: + print( + f"{fill}Recursive {method_name} at {mark} depth {depth}: {result!s:.200} to {endmark}" + ) + if not result: + if verbose: + print(f"{fill}Fail with {lastresult!s:.200} to {lastmark}") + break + if endmark <= lastmark: + if verbose: + print(f"{fill}Bailing with {lastresult!s:.200} to {lastmark}") + break + self._cache[key] = lastresult, lastmark = result, endmark + + self.reset(lastmark) + tree = lastresult + + self._level -= 1 + if verbose: + print(f"{fill}{method_name}() -> {tree!s:.200} [cached]") + if tree: + endmark = self.mark() + else: + endmark = mark + self.reset(endmark) + self._cache[key] = tree, endmark + else: + tree, endmark = self._cache[key] + if verbose: + print(f"{fill}{method_name}() -> {tree!s:.200} [fresh]") + if tree: + self.reset(endmark) + return tree + + memoize_left_rec_wrapper.__wrapped__ = method # type: ignore + return memoize_left_rec_wrapper + + +class Parser: + """Parsing base class.""" + + def __init__(self, tokenizer: Tokenizer, *, verbose: bool = False): + self._tokenizer = tokenizer + self._verbose = verbose + self._level = 0 + self._cache: Dict[Tuple[Mark, str, Tuple[Any, ...]], Tuple[Any, Mark]] = {} + # Pass through common tokenizer methods. + # TODO: Rename to _mark and _reset. + self.mark = self._tokenizer.mark + self.reset = self._tokenizer.reset + + @abstractmethod + def start(self) -> Any: + pass + + def showpeek(self) -> str: + tok = self._tokenizer.peek() + return f"{tok.start[0]}.{tok.start[1]}: {token.tok_name[tok.type]}:{tok.string!r}" + + @memoize + def name(self) -> Optional[tokenize.TokenInfo]: + tok = self._tokenizer.peek() + if tok.type == token.NAME: + return self._tokenizer.getnext() + return None + + @memoize + def number(self) -> Optional[tokenize.TokenInfo]: + tok = self._tokenizer.peek() + if tok.type == token.NUMBER: + return self._tokenizer.getnext() + return None + + @memoize + def string(self) -> Optional[tokenize.TokenInfo]: + tok = self._tokenizer.peek() + if tok.type == token.STRING: + return self._tokenizer.getnext() + return None + + @memoize + def op(self) -> Optional[tokenize.TokenInfo]: + tok = self._tokenizer.peek() + if tok.type == token.OP: + return self._tokenizer.getnext() + return None + + @memoize + def expect(self, type: str) -> Optional[tokenize.TokenInfo]: + tok = self._tokenizer.peek() + if tok.string == type: + return self._tokenizer.getnext() + if type in exact_token_types: + if tok.type == exact_token_types[type]: + return self._tokenizer.getnext() + if type in token.__dict__: + if tok.type == token.__dict__[type]: + return self._tokenizer.getnext() + if tok.type == token.OP and tok.string == type: + return self._tokenizer.getnext() + return None + + def positive_lookahead(self, func: Callable[..., T], *args: object) -> T: + mark = self.mark() + ok = func(*args) + self.reset(mark) + return ok + + def negative_lookahead(self, func: Callable[..., object], *args: object) -> bool: + mark = self.mark() + ok = func(*args) + self.reset(mark) + return not ok + + def make_syntax_error(self, filename: str = "") -> SyntaxError: + tok = self._tokenizer.diagnose() + return SyntaxError( + "pegen parse failure", (filename, tok.start[0], 1 + tok.start[1], tok.line) + ) + + +def simple_parser_main(parser_class: Type[Parser]) -> None: + argparser = argparse.ArgumentParser() + argparser.add_argument( + "-v", + "--verbose", + action="count", + default=0, + help="Print timing stats; repeat for more debug output", + ) + argparser.add_argument( + "-q", "--quiet", action="store_true", help="Don't print the parsed program" + ) + argparser.add_argument("filename", help="Input file ('-' to use stdin)") + + args = argparser.parse_args() + verbose = args.verbose + verbose_tokenizer = verbose >= 3 + verbose_parser = verbose == 2 or verbose >= 4 + + t0 = time.time() + + filename = args.filename + if filename == "" or filename == "-": + filename = "" + file = sys.stdin + else: + file = open(args.filename) + try: + tokengen = tokenize.generate_tokens(file.readline) + tokenizer = Tokenizer(tokengen, verbose=verbose_tokenizer) + parser = parser_class(tokenizer, verbose=verbose_parser) + tree = parser.start() + try: + if file.isatty(): + endpos = 0 + else: + endpos = file.tell() + except IOError: + endpos = 0 + finally: + if file is not sys.stdin: + file.close() + + t1 = time.time() + + if not tree: + err = parser.make_syntax_error(filename) + traceback.print_exception(err.__class__, err, None) + sys.exit(1) + + if not args.quiet: + print(tree) + + if verbose: + dt = t1 - t0 + diag = tokenizer.diagnose() + nlines = diag.end[0] + if diag.type == token.ENDMARKER: + nlines -= 1 + print(f"Total time: {dt:.3f} sec; {nlines} lines", end="") + if endpos: + print(f" ({endpos} bytes)", end="") + if dt: + print(f"; {nlines / dt:.0f} lines/sec") + else: + print() + print("Caches sizes:") + print(f" token array : {len(tokenizer._tokens):10}") + print(f" cache : {len(parser._cache):10}") + ## print_memstats() diff --git a/ast3/Tools/peg_generator/pegen/parser_generator.py b/ast3/Tools/peg_generator/pegen/parser_generator.py new file mode 100644 index 00000000..03452510 --- /dev/null +++ b/ast3/Tools/peg_generator/pegen/parser_generator.py @@ -0,0 +1,198 @@ +import contextlib +from abc import abstractmethod + +from typing import AbstractSet, Dict, IO, Iterator, List, Optional, Set, Text, Tuple + +from pegen import sccutils +from pegen.grammar import ( + Grammar, + Rule, + Rhs, + Alt, + NamedItem, + Plain, + NameLeaf, + Gather, +) +from pegen.grammar import GrammarError, GrammarVisitor + + +class RuleCheckingVisitor(GrammarVisitor): + def __init__(self, rules: Dict[str, Rule], tokens: Dict[int, str]): + self.rules = rules + self.tokens = tokens + + def visit_NameLeaf(self, node: NameLeaf) -> None: + if node.value not in self.rules and node.value not in self.tokens.values(): + # TODO: Add line/col info to (leaf) nodes + raise GrammarError(f"Dangling reference to rule {node.value!r}") + + +class ParserGenerator: + + callmakervisitor: GrammarVisitor + + def __init__(self, grammar: Grammar, tokens: Dict[int, str], file: Optional[IO[Text]]): + self.grammar = grammar + self.tokens = tokens + self.rules = grammar.rules + if "trailer" not in grammar.metas and "start" not in self.rules: + raise GrammarError("Grammar without a trailer must have a 'start' rule") + checker = RuleCheckingVisitor(self.rules, self.tokens) + for rule in self.rules.values(): + checker.visit(rule) + self.file = file + self.level = 0 + compute_nullables(self.rules) + self.first_graph, self.first_sccs = compute_left_recursives(self.rules) + self.todo = self.rules.copy() # Rules to generate + self.counter = 0 # For name_rule()/name_loop() + self.keyword_counter = 499 # For keyword_type() + self.all_rules: Dict[str, Rule] = {} # Rules + temporal rules + self._local_variable_stack: List[List[str]] = [] + + @contextlib.contextmanager + def local_variable_context(self) -> Iterator[None]: + self._local_variable_stack.append([]) + yield + self._local_variable_stack.pop() + + @property + def local_variable_names(self) -> List[str]: + return self._local_variable_stack[-1] + + @abstractmethod + def generate(self, filename: str) -> None: + raise NotImplementedError + + @contextlib.contextmanager + def indent(self) -> Iterator[None]: + self.level += 1 + try: + yield + finally: + self.level -= 1 + + def print(self, *args: object) -> None: + if not args: + print(file=self.file) + else: + print(" " * self.level, end="", file=self.file) + print(*args, file=self.file) + + def printblock(self, lines: str) -> None: + for line in lines.splitlines(): + self.print(line) + + def collect_todo(self) -> None: + done: Set[str] = set() + while True: + alltodo = list(self.todo) + self.all_rules.update(self.todo) + todo = [i for i in alltodo if i not in done] + if not todo: + break + for rulename in todo: + self.todo[rulename].collect_todo(self) + done = set(alltodo) + + def keyword_type(self) -> int: + self.keyword_counter += 1 + return self.keyword_counter + + def name_node(self, rhs: Rhs) -> str: + self.counter += 1 + name = f"_tmp_{self.counter}" # TODO: Pick a nicer name. + self.todo[name] = Rule(name, None, rhs) + return name + + def name_loop(self, node: Plain, is_repeat1: bool) -> str: + self.counter += 1 + if is_repeat1: + prefix = "_loop1_" + else: + prefix = "_loop0_" + name = f"{prefix}{self.counter}" # TODO: It's ugly to signal via the name. + self.todo[name] = Rule(name, None, Rhs([Alt([NamedItem(None, node)])])) + return name + + def name_gather(self, node: Gather) -> str: + self.counter += 1 + name = f"_gather_{self.counter}" + self.counter += 1 + extra_function_name = f"_loop0_{self.counter}" + extra_function_alt = Alt( + [NamedItem(None, node.separator), NamedItem("elem", node.node)], action="elem", + ) + self.todo[extra_function_name] = Rule( + extra_function_name, None, Rhs([extra_function_alt]), + ) + alt = Alt([NamedItem("elem", node.node), NamedItem("seq", NameLeaf(extra_function_name))],) + self.todo[name] = Rule(name, None, Rhs([alt]),) + return name + + def dedupe(self, name: str) -> str: + origname = name + counter = 0 + while name in self.local_variable_names: + counter += 1 + name = f"{origname}_{counter}" + self.local_variable_names.append(name) + return name + + +def compute_nullables(rules: Dict[str, Rule]) -> None: + """Compute which rules in a grammar are nullable. + + Thanks to TatSu (tatsu/leftrec.py) for inspiration. + """ + for rule in rules.values(): + rule.nullable_visit(rules) + + +def compute_left_recursives( + rules: Dict[str, Rule] +) -> Tuple[Dict[str, AbstractSet[str]], List[AbstractSet[str]]]: + graph = make_first_graph(rules) + sccs = list(sccutils.strongly_connected_components(graph.keys(), graph)) + for scc in sccs: + if len(scc) > 1: + for name in scc: + rules[name].left_recursive = True + # Try to find a leader such that all cycles go through it. + leaders = set(scc) + for start in scc: + for cycle in sccutils.find_cycles_in_scc(graph, scc, start): + # print("Cycle:", " -> ".join(cycle)) + leaders -= scc - set(cycle) + if not leaders: + raise ValueError( + f"SCC {scc} has no leadership candidate (no element is included in all cycles)" + ) + # print("Leaders:", leaders) + leader = min(leaders) # Pick an arbitrary leader from the candidates. + rules[leader].leader = True + else: + name = min(scc) # The only element. + if name in graph[name]: + rules[name].left_recursive = True + rules[name].leader = True + return graph, sccs + + +def make_first_graph(rules: Dict[str, Rule]) -> Dict[str, AbstractSet[str]]: + """Compute the graph of left-invocations. + + There's an edge from A to B if A may invoke B at its initial + position. + + Note that this requires the nullable flags to have been computed. + """ + graph = {} + vertices: Set[str] = set() + for rulename, rhs in rules.items(): + graph[rulename] = names = rhs.initial_names() + vertices |= names + for vertex in vertices: + graph.setdefault(vertex, set()) + return graph diff --git a/ast3/Tools/peg_generator/pegen/python_generator.py b/ast3/Tools/peg_generator/pegen/python_generator.py new file mode 100644 index 00000000..64336552 --- /dev/null +++ b/ast3/Tools/peg_generator/pegen/python_generator.py @@ -0,0 +1,232 @@ +import token +from typing import Any, Dict, Optional, IO, Text, Tuple + +from pegen.grammar import ( + Cut, + GrammarVisitor, + NameLeaf, + StringLeaf, + Rhs, + NamedItem, + Lookahead, + PositiveLookahead, + NegativeLookahead, + Opt, + Repeat0, + Repeat1, + Gather, + Group, + Rule, + Alt, +) +from pegen import grammar +from pegen.parser_generator import ParserGenerator + +MODULE_PREFIX = """\ +#!/usr/bin/env python3.8 +# @generated by pegen from {filename} + +import ast +import sys +import tokenize + +from typing import Any, Optional + +from pegen.parser import memoize, memoize_left_rec, logger, Parser + +""" +MODULE_SUFFIX = """ + +if __name__ == '__main__': + from pegen.parser import simple_parser_main + simple_parser_main(GeneratedParser) +""" + + +class PythonCallMakerVisitor(GrammarVisitor): + def __init__(self, parser_generator: ParserGenerator): + self.gen = parser_generator + self.cache: Dict[Any, Any] = {} + + def visit_NameLeaf(self, node: NameLeaf) -> Tuple[Optional[str], str]: + name = node.value + if name in ("NAME", "NUMBER", "STRING", "OP"): + name = name.lower() + return name, f"self.{name}()" + if name in ("NEWLINE", "DEDENT", "INDENT", "ENDMARKER", "ASYNC", "AWAIT"): + return name.lower(), f"self.expect({name!r})" + return name, f"self.{name}()" + + def visit_StringLeaf(self, node: StringLeaf) -> Tuple[str, str]: + return "literal", f"self.expect({node.value})" + + def visit_Rhs(self, node: Rhs) -> Tuple[Optional[str], str]: + if node in self.cache: + return self.cache[node] + if len(node.alts) == 1 and len(node.alts[0].items) == 1: + self.cache[node] = self.visit(node.alts[0].items[0]) + else: + name = self.gen.name_node(node) + self.cache[node] = name, f"self.{name}()" + return self.cache[node] + + def visit_NamedItem(self, node: NamedItem) -> Tuple[Optional[str], str]: + name, call = self.visit(node.item) + if node.name: + name = node.name + return name, call + + def lookahead_call_helper(self, node: Lookahead) -> Tuple[str, str]: + name, call = self.visit(node.node) + head, tail = call.split("(", 1) + assert tail[-1] == ")" + tail = tail[:-1] + return head, tail + + def visit_PositiveLookahead(self, node: PositiveLookahead) -> Tuple[None, str]: + head, tail = self.lookahead_call_helper(node) + return None, f"self.positive_lookahead({head}, {tail})" + + def visit_NegativeLookahead(self, node: NegativeLookahead) -> Tuple[None, str]: + head, tail = self.lookahead_call_helper(node) + return None, f"self.negative_lookahead({head}, {tail})" + + def visit_Opt(self, node: Opt) -> Tuple[str, str]: + name, call = self.visit(node.node) + return "opt", f"{call}," # Note trailing comma! + + def visit_Repeat0(self, node: Repeat0) -> Tuple[str, str]: + if node in self.cache: + return self.cache[node] + name = self.gen.name_loop(node.node, False) + self.cache[node] = name, f"self.{name}()," # Also a trailing comma! + return self.cache[node] + + def visit_Repeat1(self, node: Repeat1) -> Tuple[str, str]: + if node in self.cache: + return self.cache[node] + name = self.gen.name_loop(node.node, True) + self.cache[node] = name, f"self.{name}()" # But no trailing comma here! + return self.cache[node] + + def visit_Gather(self, node: Gather) -> Tuple[str, str]: + if node in self.cache: + return self.cache[node] + name = self.gen.name_gather(node) + self.cache[node] = name, f"self.{name}()" # No trailing comma here either! + return self.cache[node] + + def visit_Group(self, node: Group) -> Tuple[Optional[str], str]: + return self.visit(node.rhs) + + def visit_Cut(self, node: Cut) -> Tuple[str, str]: + return "cut", "True" + + +class PythonParserGenerator(ParserGenerator, GrammarVisitor): + def __init__( + self, + grammar: grammar.Grammar, + file: Optional[IO[Text]], + tokens: Dict[int, str] = token.tok_name, + ): + super().__init__(grammar, tokens, file) + self.callmakervisitor = PythonCallMakerVisitor(self) + + def generate(self, filename: str) -> None: + header = self.grammar.metas.get("header", MODULE_PREFIX) + if header is not None: + self.print(header.rstrip("\n").format(filename=filename)) + subheader = self.grammar.metas.get("subheader", "") + if subheader: + self.print(subheader.format(filename=filename)) + self.print("class GeneratedParser(Parser):") + while self.todo: + for rulename, rule in list(self.todo.items()): + del self.todo[rulename] + self.print() + with self.indent(): + self.visit(rule) + trailer = self.grammar.metas.get("trailer", MODULE_SUFFIX) + if trailer is not None: + self.print(trailer.rstrip("\n")) + + def visit_Rule(self, node: Rule) -> None: + is_loop = node.is_loop() + is_gather = node.is_gather() + rhs = node.flatten() + if node.left_recursive: + if node.leader: + self.print("@memoize_left_rec") + else: + # Non-leader rules in a cycle are not memoized, + # but they must still be logged. + self.print("@logger") + else: + self.print("@memoize") + node_type = node.type or "Any" + self.print(f"def {node.name}(self) -> Optional[{node_type}]:") + with self.indent(): + self.print(f"# {node.name}: {rhs}") + if node.nullable: + self.print(f"# nullable={node.nullable}") + self.print("mark = self.mark()") + if is_loop: + self.print("children = []") + self.visit(rhs, is_loop=is_loop, is_gather=is_gather) + if is_loop: + self.print("return children") + else: + self.print("return None") + + def visit_NamedItem(self, node: NamedItem) -> None: + name, call = self.callmakervisitor.visit(node.item) + if node.name: + name = node.name + if not name: + self.print(call) + else: + if name != "cut": + name = self.dedupe(name) + self.print(f"({name} := {call})") + + def visit_Rhs(self, node: Rhs, is_loop: bool = False, is_gather: bool = False) -> None: + if is_loop: + assert len(node.alts) == 1 + for alt in node.alts: + self.visit(alt, is_loop=is_loop, is_gather=is_gather) + + def visit_Alt(self, node: Alt, is_loop: bool, is_gather: bool) -> None: + with self.local_variable_context(): + self.print("cut = False") # TODO: Only if needed. + if is_loop: + self.print("while (") + else: + self.print("if (") + with self.indent(): + first = True + for item in node.items: + if first: + first = False + else: + self.print("and") + self.visit(item) + self.print("):") + with self.indent(): + action = node.action + if not action: + if is_gather: + assert len(self.local_variable_names) == 2 + action = ( + f"[{self.local_variable_names[0]}] + {self.local_variable_names[1]}" + ) + else: + action = f"[{', '.join(self.local_variable_names)}]" + if is_loop: + self.print(f"children.append({action})") + self.print(f"mark = self.mark()") + else: + self.print(f"return {action}") + self.print("self.reset(mark)") + # Skip remaining alternatives if a cut was reached. + self.print("if cut: return None") # TODO: Only if needed. diff --git a/ast3/Tools/peg_generator/pegen/sccutils.py b/ast3/Tools/peg_generator/pegen/sccutils.py new file mode 100644 index 00000000..1f0586bb --- /dev/null +++ b/ast3/Tools/peg_generator/pegen/sccutils.py @@ -0,0 +1,128 @@ +# Adapted from mypy (mypy/build.py) under the MIT license. + +from typing import * + + +def strongly_connected_components( + vertices: AbstractSet[str], edges: Dict[str, AbstractSet[str]] +) -> Iterator[AbstractSet[str]]: + """Compute Strongly Connected Components of a directed graph. + + Args: + vertices: the labels for the vertices + edges: for each vertex, gives the target vertices of its outgoing edges + + Returns: + An iterator yielding strongly connected components, each + represented as a set of vertices. Each input vertex will occur + exactly once; vertices not part of a SCC are returned as + singleton sets. + + From http://code.activestate.com/recipes/578507/. + """ + identified: Set[str] = set() + stack: List[str] = [] + index: Dict[str, int] = {} + boundaries: List[int] = [] + + def dfs(v: str) -> Iterator[Set[str]]: + index[v] = len(stack) + stack.append(v) + boundaries.append(index[v]) + + for w in edges[v]: + if w not in index: + yield from dfs(w) + elif w not in identified: + while index[w] < boundaries[-1]: + boundaries.pop() + + if boundaries[-1] == index[v]: + boundaries.pop() + scc = set(stack[index[v] :]) + del stack[index[v] :] + identified.update(scc) + yield scc + + for v in vertices: + if v not in index: + yield from dfs(v) + + +def topsort( + data: Dict[AbstractSet[str], Set[AbstractSet[str]]] +) -> Iterable[AbstractSet[AbstractSet[str]]]: + """Topological sort. + + Args: + data: A map from SCCs (represented as frozen sets of strings) to + sets of SCCs, its dependencies. NOTE: This data structure + is modified in place -- for normalization purposes, + self-dependencies are removed and entries representing + orphans are added. + + Returns: + An iterator yielding sets of SCCs that have an equivalent + ordering. NOTE: The algorithm doesn't care about the internal + structure of SCCs. + + Example: + Suppose the input has the following structure: + + {A: {B, C}, B: {D}, C: {D}} + + This is normalized to: + + {A: {B, C}, B: {D}, C: {D}, D: {}} + + The algorithm will yield the following values: + + {D} + {B, C} + {A} + + From http://code.activestate.com/recipes/577413/. + """ + # TODO: Use a faster algorithm? + for k, v in data.items(): + v.discard(k) # Ignore self dependencies. + for item in set.union(*data.values()) - set(data.keys()): + data[item] = set() + while True: + ready = {item for item, dep in data.items() if not dep} + if not ready: + break + yield ready + data = {item: (dep - ready) for item, dep in data.items() if item not in ready} + assert not data, "A cyclic dependency exists amongst %r" % data + + +def find_cycles_in_scc( + graph: Dict[str, AbstractSet[str]], scc: AbstractSet[str], start: str +) -> Iterable[List[str]]: + """Find cycles in SCC emanating from start. + + Yields lists of the form ['A', 'B', 'C', 'A'], which means there's + a path from A -> B -> C -> A. The first item is always the start + argument, but the last item may be another element, e.g. ['A', + 'B', 'C', 'B'] means there's a path from A to B and there's a + cycle from B to C and back. + """ + # Basic input checks. + assert start in scc, (start, scc) + assert scc <= graph.keys(), scc - graph.keys() + + # Reduce the graph to nodes in the SCC. + graph = {src: {dst for dst in dsts if dst in scc} for src, dsts in graph.items() if src in scc} + assert start in graph + + # Recursive helper that yields cycles. + def dfs(node: str, path: List[str]) -> Iterator[List[str]]: + if node in path: + yield path + [node] + return + path = path + [node] # TODO: Make this not quadratic. + for child in graph[node]: + yield from dfs(child, path) + + yield from dfs(start, []) diff --git a/ast3/Tools/peg_generator/pegen/testutil.py b/ast3/Tools/peg_generator/pegen/testutil.py new file mode 100644 index 00000000..264659e7 --- /dev/null +++ b/ast3/Tools/peg_generator/pegen/testutil.py @@ -0,0 +1,133 @@ +import importlib.util +import io +import os +import pathlib +import sys +import textwrap +import tokenize +import token + +from typing import Any, cast, Dict, IO, Type, Final + +from pegen.build import compile_c_extension +from pegen.c_generator import CParserGenerator +from pegen.grammar import Grammar +from pegen.grammar_parser import GeneratedParser as GrammarParser +from pegen.parser import Parser +from pegen.python_generator import PythonParserGenerator +from pegen.tokenizer import Tokenizer + +ALL_TOKENS = token.tok_name +EXACT_TOKENS = token.EXACT_TOKEN_TYPES # type: ignore +NON_EXACT_TOKENS = { + name for index, name in token.tok_name.items() if index not in EXACT_TOKENS.values() +} + + +def generate_parser(grammar: Grammar) -> Type[Parser]: + # Generate a parser. + out = io.StringIO() + genr = PythonParserGenerator(grammar, out) + genr.generate("") + + # Load the generated parser class. + ns: Dict[str, Any] = {} + exec(out.getvalue(), ns) + return ns["GeneratedParser"] + + +def run_parser(file: IO[bytes], parser_class: Type[Parser], *, verbose: bool = False) -> Any: + # Run a parser on a file (stream). + tokenizer = Tokenizer(tokenize.generate_tokens(file.readline)) # type: ignore # typeshed issue #3515 + parser = parser_class(tokenizer, verbose=verbose) + result = parser.start() + if result is None: + raise parser.make_syntax_error() + return result + + +def parse_string( + source: str, parser_class: Type[Parser], *, dedent: bool = True, verbose: bool = False +) -> Any: + # Run the parser on a string. + if dedent: + source = textwrap.dedent(source) + file = io.StringIO(source) + return run_parser(file, parser_class, verbose=verbose) # type: ignore # typeshed issue #3515 + + +def make_parser(source: str) -> Type[Parser]: + # Combine parse_string() and generate_parser(). + grammar = parse_string(source, GrammarParser) + return generate_parser(grammar) + + +def import_file(full_name: str, path: str) -> Any: + """Import a python module from a path""" + + spec = importlib.util.spec_from_file_location(full_name, path) + mod = importlib.util.module_from_spec(spec) + + # We assume this is not None and has an exec_module() method. + # See https://docs.python.org/3/reference/import.html?highlight=exec_module#loading + loader = cast(Any, spec.loader) + loader.exec_module(mod) + return mod + + +def generate_c_parser_source(grammar: Grammar) -> str: + out = io.StringIO() + genr = CParserGenerator(grammar, ALL_TOKENS, EXACT_TOKENS, NON_EXACT_TOKENS, out) + genr.generate("") + return out.getvalue() + + +def generate_parser_c_extension( + grammar: Grammar, path: pathlib.PurePath, debug: bool = False +) -> Any: + """Generate a parser c extension for the given grammar in the given path + + Returns a module object with a parse_string() method. + TODO: express that using a Protocol. + """ + # Make sure that the working directory is empty: reusing non-empty temporary + # directories when generating extensions can lead to segmentation faults. + # Check issue #95 (https://github.com/gvanrossum/pegen/issues/95) for more + # context. + assert not os.listdir(path) + source = path / "parse.c" + with open(source, "w") as file: + genr = CParserGenerator( + grammar, ALL_TOKENS, EXACT_TOKENS, NON_EXACT_TOKENS, file, debug=debug + ) + genr.generate("parse.c") + compile_c_extension(str(source), build_dir=str(path)) + + +def print_memstats() -> bool: + MiB: Final = 2 ** 20 + try: + import psutil # type: ignore + except ImportError: + return False + print("Memory stats:") + process = psutil.Process() + meminfo = process.memory_info() + res = {} + res["rss"] = meminfo.rss / MiB + res["vms"] = meminfo.vms / MiB + if sys.platform == "win32": + res["maxrss"] = meminfo.peak_wset / MiB + else: + # See https://stackoverflow.com/questions/938733/total-memory-used-by-python-process + import resource # Since it doesn't exist on Windows. + + rusage = resource.getrusage(resource.RUSAGE_SELF) + if sys.platform == "darwin": + factor = 1 + else: + factor = 1024 # Linux + res["maxrss"] = rusage.ru_maxrss * factor / MiB + for key, value in res.items(): + print(f" {key:12.12s}: {value:10.0f} MiB") + return True diff --git a/ast3/Tools/peg_generator/pegen/tokenizer.py b/ast3/Tools/peg_generator/pegen/tokenizer.py new file mode 100644 index 00000000..61a28efc --- /dev/null +++ b/ast3/Tools/peg_generator/pegen/tokenizer.py @@ -0,0 +1,86 @@ +import token +import tokenize +from typing import List, Iterator + +Mark = int # NewType('Mark', int) + +exact_token_types = token.EXACT_TOKEN_TYPES # type: ignore + + +def shorttok(tok: tokenize.TokenInfo) -> str: + return "%-25.25s" % f"{tok.start[0]}.{tok.start[1]}: {token.tok_name[tok.type]}:{tok.string!r}" + + +class Tokenizer: + """Caching wrapper for the tokenize module. + + This is pretty tied to Python's syntax. + """ + + _tokens: List[tokenize.TokenInfo] + + def __init__(self, tokengen: Iterator[tokenize.TokenInfo], *, verbose: bool = False): + self._tokengen = tokengen + self._tokens = [] + self._index = 0 + self._verbose = verbose + if verbose: + self.report(False, False) + + def getnext(self) -> tokenize.TokenInfo: + """Return the next token and updates the index.""" + cached = True + while self._index == len(self._tokens): + tok = next(self._tokengen) + if tok.type in (tokenize.NL, tokenize.COMMENT): + continue + if tok.type == token.ERRORTOKEN and tok.string.isspace(): + continue + self._tokens.append(tok) + cached = False + tok = self._tokens[self._index] + self._index += 1 + if self._verbose: + self.report(cached, False) + return tok + + def peek(self) -> tokenize.TokenInfo: + """Return the next token *without* updating the index.""" + while self._index == len(self._tokens): + tok = next(self._tokengen) + if tok.type in (tokenize.NL, tokenize.COMMENT): + continue + if tok.type == token.ERRORTOKEN and tok.string.isspace(): + continue + self._tokens.append(tok) + return self._tokens[self._index] + + def diagnose(self) -> tokenize.TokenInfo: + if not self._tokens: + self.getnext() + return self._tokens[-1] + + def mark(self) -> Mark: + return self._index + + def reset(self, index: Mark) -> None: + if index == self._index: + return + assert 0 <= index <= len(self._tokens), (index, len(self._tokens)) + old_index = self._index + self._index = index + if self._verbose: + self.report(True, index < old_index) + + def report(self, cached: bool, back: bool) -> None: + if back: + fill = "-" * self._index + "-" + elif cached: + fill = "-" * self._index + ">" + else: + fill = "-" * self._index + "*" + if self._index == 0: + print(f"{fill} (Bof)") + else: + tok = self._tokens[self._index - 1] + print(f"{fill} {shorttok(tok)}") diff --git a/ast3/Tools/peg_generator/pyproject.toml b/ast3/Tools/peg_generator/pyproject.toml new file mode 100644 index 00000000..f69c5b5e --- /dev/null +++ b/ast3/Tools/peg_generator/pyproject.toml @@ -0,0 +1,9 @@ +[tool.black] +line-length = 99 +target_version = ['py38'] +exclude = ''' +( + /pegen/grammar_parser.py # generated file + | /test/test_data/ # test files +) +''' diff --git a/ast3/Tools/peg_generator/requirements.pip b/ast3/Tools/peg_generator/requirements.pip new file mode 100644 index 00000000..190b3488 --- /dev/null +++ b/ast3/Tools/peg_generator/requirements.pip @@ -0,0 +1,2 @@ +memory-profiler==0.57.0 +psutil==5.7.0 diff --git a/ast3/Tools/peg_generator/scripts/__init__.py b/ast3/Tools/peg_generator/scripts/__init__.py new file mode 100644 index 00000000..1e423f48 --- /dev/null +++ b/ast3/Tools/peg_generator/scripts/__init__.py @@ -0,0 +1 @@ +# This exists to let mypy find modules here diff --git a/ast3/Tools/peg_generator/scripts/ast_timings.py b/ast3/Tools/peg_generator/scripts/ast_timings.py new file mode 100644 index 00000000..ca252208 --- /dev/null +++ b/ast3/Tools/peg_generator/scripts/ast_timings.py @@ -0,0 +1,26 @@ +import ast +import sys +import time + +from pegen.testutil import print_memstats + + +def main() -> None: + t0 = time.time() + for filename in sys.argv[1:]: + print(filename, end="\r") + try: + with open(filename) as file: + source = file.read() + tree = ast.parse(source, filename) + except Exception as err: + print(f"{filename}: {err.__class__.__name__}: {err}", file=sys.stderr) + tok = None + t1 = time.time() + dt = t1 - t0 + print(f"Parsed in {dt:.3f} secs", file=sys.stderr) + print_memstats() + + +if __name__ == "__main__": + main() diff --git a/ast3/Tools/peg_generator/scripts/benchmark.py b/ast3/Tools/peg_generator/scripts/benchmark.py new file mode 100644 index 00000000..d39ac3dc --- /dev/null +++ b/ast3/Tools/peg_generator/scripts/benchmark.py @@ -0,0 +1,137 @@ +#!/usr/bin/env python3.9 + +import argparse +import ast +import sys +import os +from time import time + +import memory_profiler + +sys.path.insert(0, os.getcwd()) +from peg_extension import parse +from pegen.build import build_c_parser_and_generator +from scripts.test_parse_directory import parse_directory + +argparser = argparse.ArgumentParser( + prog="benchmark", description="Reproduce the various pegen benchmarks" +) +argparser.add_argument( + "--parser", + action="store", + choices=["pegen", "cpython"], + default="pegen", + help="Which parser to benchmark (default is pegen)", +) +argparser.add_argument( + "--target", + action="store", + choices=["xxl", "stdlib"], + default="xxl", + help="Which target to use for the benchmark (default is xxl.py)", +) + +subcommands = argparser.add_subparsers(title="Benchmarks", dest="subcommand") +command_compile = subcommands.add_parser( + "compile", help="Benchmark parsing and compiling to bytecode" +) +command_parse = subcommands.add_parser("parse", help="Benchmark parsing and generating an ast.AST") +command_check = subcommands.add_parser( + "check", help="Benchmark parsing and throwing the tree away" +) + + +def benchmark(func): + def wrapper(*args): + times = list() + for _ in range(3): + start = time() + result = func(*args) + end = time() + times.append(end - start) + memory = memory_profiler.memory_usage((func, args)) + print(f"{func.__name__}") + print(f"\tTime: {sum(times)/3:.3f} seconds on an average of 3 runs") + print(f"\tMemory: {max(memory)} MiB on an average of 3 runs") + return result + + return wrapper + + +@benchmark +def time_compile(source, parser): + if parser == "cpython": + return compile(source, os.path.join("data", "xxl.py"), "exec") + else: + return parse.parse_string(source, mode=2) + + +@benchmark +def time_parse(source, parser): + if parser == "cpython": + return ast.parse(source, os.path.join("data", "xxl.py"), "exec") + else: + return parse.parse_string(source, mode=1) + + +@benchmark +def time_check(source): + return parse.parse_string(source, mode=0) + + +def run_benchmark_xxl(subcommand, parser, source): + if subcommand == "compile": + time_compile(source, parser) + elif subcommand == "parse": + time_parse(source, parser) + elif subcommand == "check": + time_check(source) + + +def run_benchmark_stdlib(subcommand, parser): + modes = {"compile": 2, "parse": 1, "check": 0} + extension = None + if parser == "pegen": + extension = build_c_parser_and_generator( + "../../Grammar/python.gram", + "../../Grammar/Tokens", + "peg_extension/parse.c", + compile_extension=True, + skip_actions=False, + ) + for _ in range(3): + parse_directory( + "../../Lib", + "../../Grammar/python.gram", + verbose=False, + excluded_files=["*/bad*", "*/lib2to3/tests/data/*",], + skip_actions=False, + tree_arg=0, + short=True, + extension=extension, + mode=modes[subcommand], + parser=parser, + ) + + +def main(): + args = argparser.parse_args() + subcommand = args.subcommand + parser = args.parser + target = args.target + + if subcommand is None: + argparser.error("A benchmark to run is required") + if subcommand == "check" and parser == "cpython": + argparser.error("Cannot use check target with the CPython parser") + + if target == "xxl": + with open(os.path.join("data", "xxl.py"), "r") as f: + source = f.read() + run_benchmark_xxl(subcommand, parser, source) + elif target == "stdlib": + run_benchmark_stdlib(subcommand, parser) + + +if __name__ == "__main__": + main() diff --git a/ast3/Tools/peg_generator/scripts/download_pypi_packages.py b/ast3/Tools/peg_generator/scripts/download_pypi_packages.py new file mode 100755 index 00000000..9874202d --- /dev/null +++ b/ast3/Tools/peg_generator/scripts/download_pypi_packages.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python3.8 + +import argparse +import os +import json + +from typing import Dict, Any +from urllib.request import urlretrieve + +argparser = argparse.ArgumentParser( + prog="download_pypi_packages", description="Helper program to download PyPI packages", +) +argparser.add_argument( + "-n", "--number", type=int, default=100, help="Number of packages to download" +) +argparser.add_argument( + "-a", "--all", action="store_true", help="Download all packages listed in the json file" +) + + +def load_json(filename: str) -> Dict[Any, Any]: + with open(os.path.join("data", f"{filename}.json"), "r") as f: + j = json.loads(f.read()) + return j + + +def remove_json(filename: str) -> None: + path = os.path.join("data", f"{filename}.json") + os.remove(path) + + +def download_package_json(package_name: str) -> None: + url = f"https://pypi.org/pypi/{package_name}/json" + urlretrieve(url, os.path.join("data", f"{package_name}.json")) + + +def download_package_code(name: str, package_json: Dict[Any, Any]) -> None: + source_index = -1 + for idx, url_info in enumerate(package_json["urls"]): + if url_info["python_version"] == "source": + source_index = idx + break + filename = package_json["urls"][source_index]["filename"] + url = package_json["urls"][source_index]["url"] + urlretrieve(url, os.path.join("data", "pypi", filename)) + + +def main() -> None: + args = argparser.parse_args() + number_packages = args.number + all_packages = args.all + + top_pypi_packages = load_json("top-pypi-packages-365-days") + if all_packages: + top_pypi_packages = top_pypi_packages["rows"] + elif number_packages >= 0 and number_packages <= 4000: + top_pypi_packages = top_pypi_packages["rows"][:number_packages] + else: + raise AssertionError("Unknown value for NUMBER_OF_PACKAGES") + + try: + os.mkdir(os.path.join("data", "pypi")) + except FileExistsError: + pass + + for package in top_pypi_packages: + package_name = package["project"] + + print(f"Downloading JSON Data for {package_name}... ", end="") + download_package_json(package_name) + print("Done") + + package_json = load_json(package_name) + try: + print(f"Dowloading and compressing package {package_name} ... ", end="") + download_package_code(package_name, package_json) + print("Done") + except (IndexError, KeyError): + print(f"Could not locate source for {package_name}") + continue + finally: + remove_json(package_name) + + +if __name__ == "__main__": + main() diff --git a/ast3/Tools/peg_generator/scripts/find_max_nesting.py b/ast3/Tools/peg_generator/scripts/find_max_nesting.py new file mode 100755 index 00000000..f2fdd00b --- /dev/null +++ b/ast3/Tools/peg_generator/scripts/find_max_nesting.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3.8 +"""Find the maximum amount of nesting for an expression that can be parsed +without causing a parse error. + +Starting at the INITIAL_NESTING_DEPTH, an expression containing n parenthesis +around a 0 is generated then tested with both the C and Python parsers. We +continue incrementing the number of parenthesis by 10 until both parsers have +failed. As soon as a single parser fails, we stop testing that parser. + +The grammar file, initial nesting size, and amount by which the nested size is +incremented on each success can be controlled by changing the GRAMMAR_FILE, +INITIAL_NESTING_DEPTH, or NESTED_INCR_AMT variables. + +Usage: python -m scripts.find_max_nesting +""" +import sys + +from _peg_parser import parse_string + +GRAMMAR_FILE = "data/python.gram" +INITIAL_NESTING_DEPTH = 10 +NESTED_INCR_AMT = 10 + + +FAIL = "\033[91m" +ENDC = "\033[0m" + + +def check_nested_expr(nesting_depth: int) -> bool: + expr = f"{'(' * nesting_depth}0{')' * nesting_depth}" + + try: + parse_string(expr) + print(f"Nesting depth of {nesting_depth} is successful") + return True + except Exception as err: + print(f"{FAIL}(Failed with nesting depth of {nesting_depth}{ENDC}") + print(f"{FAIL}\t{err}{ENDC}") + return False + + +def main() -> None: + print(f"Testing {GRAMMAR_FILE} starting at nesting depth of {INITIAL_NESTING_DEPTH}...") + + nesting_depth = INITIAL_NESTING_DEPTH + succeeded = True + while succeeded: + expr = f"{'(' * nesting_depth}0{')' * nesting_depth}" + if succeeded: + succeeded = check_nested_expr(nesting_depth) + nesting_depth += NESTED_INCR_AMT + + sys.exit(1) + + +if __name__ == "__main__": + main() diff --git a/ast3/Tools/peg_generator/scripts/grammar_grapher.py b/ast3/Tools/peg_generator/scripts/grammar_grapher.py new file mode 100755 index 00000000..3aa25466 --- /dev/null +++ b/ast3/Tools/peg_generator/scripts/grammar_grapher.py @@ -0,0 +1,111 @@ +#!/usr/bin/env python3.8 + +""" Convert a grammar into a dot-file suitable for use with GraphViz + + For example: + Generate the GraphViz file: + # scripts/grammar_grapher.py data/python.gram > python.gv + + Then generate the graph... + + # twopi python.gv -Tpng > python_twopi.png + + or + + # dot python.gv -Tpng > python_dot.png + + NOTE: The _dot_ and _twopi_ tools seem to produce the most useful results. + The _circo_ tool is the worst of the bunch. Don't even bother. +""" + +import argparse +import sys + +from typing import Any, List + +sys.path.insert(0, ".") + +from pegen.build import build_parser +from pegen.grammar import ( + Alt, + Cut, + Grammar, + Group, + Leaf, + Lookahead, + Rule, + NameLeaf, + NamedItem, + Opt, + Repeat, + Rhs, +) + +argparser = argparse.ArgumentParser(prog="graph_grammar", description="Graph a grammar tree",) +argparser.add_argument("grammar_file", help="The grammar file to graph") + + +def references_for_item(item: Any) -> List[Any]: + if isinstance(item, Alt): + return [_ref for _item in item.items for _ref in references_for_item(_item)] + elif isinstance(item, Cut): + return [] + elif isinstance(item, Group): + return references_for_item(item.rhs) + elif isinstance(item, Lookahead): + return references_for_item(item.node) + elif isinstance(item, NamedItem): + return references_for_item(item.item) + + # NOTE NameLeaf must be before Leaf + elif isinstance(item, NameLeaf): + if item.value == "ENDMARKER": + return [] + return [item.value] + elif isinstance(item, Leaf): + return [] + + elif isinstance(item, Opt): + return references_for_item(item.node) + elif isinstance(item, Repeat): + return references_for_item(item.node) + elif isinstance(item, Rhs): + return [_ref for alt in item.alts for _ref in references_for_item(alt)] + elif isinstance(item, Rule): + return references_for_item(item.rhs) + else: + raise RuntimeError(f"Unknown item: {type(item)}") + + +def main() -> None: + args = argparser.parse_args() + + try: + grammar, parser, tokenizer = build_parser(args.grammar_file) + except Exception as err: + print("ERROR: Failed to parse grammar file", file=sys.stderr) + sys.exit(1) + + references = {} + for name, rule in grammar.rules.items(): + references[name] = set(references_for_item(rule)) + + # Flatten the start node if has only a single reference + root_node = "start" + if start := references["start"]: + if len(start) == 1: + root_node = list(start)[0] + del references["start"] + + print("digraph g1 {") + print('\toverlap="scale";') # Force twopi to scale the graph to avoid overlaps + print(f'\troot="{root_node}";') + print(f"\t{root_node} [color=green, shape=circle]") + for name, refs in references.items(): + if refs: # Ignore empty sets + print(f"\t{name} -> {','.join(refs)};") + print("}") + + +if __name__ == "__main__": + main() diff --git a/ast3/Tools/peg_generator/scripts/joinstats.py b/ast3/Tools/peg_generator/scripts/joinstats.py new file mode 100644 index 00000000..b2d762b3 --- /dev/null +++ b/ast3/Tools/peg_generator/scripts/joinstats.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python3.8 + +"""Produce a report about the most-memoable types. + +Reads a list of statistics from stdin. Each line must be two numbers, +being a type and a count. We then read some other files and produce a +list sorted by most frequent type. + +There should also be something to recognize left-recursive rules. +""" + +import os +import re +import sys + +from typing import Dict + +reporoot = os.path.dirname(os.path.dirname(__file__)) +parse_c = os.path.join(reporoot, "peg_extension", "parse.c") + + +class TypeMapper: + """State used to map types to names.""" + + def __init__(self, filename: str) -> None: + self.table: Dict[int, str] = {} + with open(filename) as f: + for line in f: + match = re.match(r"#define (\w+)_type (\d+)", line) + if match: + name, type = match.groups() + if "left" in line.lower(): + name += " // Left-recursive" + self.table[int(type)] = name + + def lookup(self, type: int) -> str: + return self.table.get(type, str(type)) + + +def main() -> None: + mapper = TypeMapper(parse_c) + table = [] + filename = sys.argv[1] + with open(filename) as f: + for lineno, line in enumerate(f, 1): + line = line.strip() + if not line or line.startswith("#"): + continue + parts = line.split() + # Extra fields ignored + if len(parts) < 2: + print(f"{lineno}: bad input ({line!r})") + continue + try: + type, count = map(int, parts[:2]) + except ValueError as err: + print(f"{lineno}: non-integer input ({line!r})") + continue + table.append((type, count)) + table.sort(key=lambda values: -values[1]) + for type, count in table: + print(f"{type:4d} {count:9d} {mapper.lookup(type)}") + + +if __name__ == "__main__": + main() diff --git a/ast3/Tools/peg_generator/scripts/show_parse.py b/ast3/Tools/peg_generator/scripts/show_parse.py new file mode 100755 index 00000000..1a0410e1 --- /dev/null +++ b/ast3/Tools/peg_generator/scripts/show_parse.py @@ -0,0 +1,120 @@ +#!/usr/bin/env python3.8 + +"""Show the parse tree for a given program, nicely formatted. + +Example: + +$ scripts/show_parse.py a+b +Module( + body=[ + Expr( + value=BinOp( + left=Name(id="a", ctx=Load()), op=Add(), right=Name(id="b", ctx=Load()) + ) + ) + ], + type_ignores=[], +) +$ + +Use -v to show line numbers and column offsets. + +The formatting is done using black. You can also import this module +and call one of its functions. +""" + +import argparse +import ast +import difflib +import os +import sys +import tempfile + +from typing import List + +sys.path.insert(0, os.getcwd()) +from pegen.ast_dump import ast_dump + +parser = argparse.ArgumentParser() +parser.add_argument( + "-d", "--diff", action="store_true", help="show diff between grammar and ast (requires -g)" +) +parser.add_argument("-g", "--grammar-file", help="grammar to use (default: use the ast module)") +parser.add_argument( + "-m", + "--multiline", + action="store_true", + help="concatenate program arguments using newline instead of space", +) +parser.add_argument("-v", "--verbose", action="store_true", help="show line/column numbers") +parser.add_argument("program", nargs="+", help="program to parse (will be concatenated)") + + +def format_tree(tree: ast.AST, verbose: bool = False) -> str: + with tempfile.NamedTemporaryFile("w+") as tf: + tf.write(ast_dump(tree, include_attributes=verbose)) + tf.write("\n") + tf.flush() + cmd = f"black -q {tf.name}" + sts = os.system(cmd) + if sts: + raise RuntimeError(f"Command {cmd!r} failed with status 0x{sts:x}") + tf.seek(0) + return tf.read() + + +def diff_trees(a: ast.AST, b: ast.AST, verbose: bool = False) -> List[str]: + sa = format_tree(a, verbose) + sb = format_tree(b, verbose) + la = sa.splitlines() + lb = sb.splitlines() + return list(difflib.unified_diff(la, lb, "a", "b", lineterm="")) + + +def show_parse(source: str, verbose: bool = False) -> str: + tree = ast.parse(source) + return format_tree(tree, verbose).rstrip("\n") + + +def print_parse(source: str, verbose: bool = False) -> None: + print(show_parse(source, verbose)) + + +def main() -> None: + args = parser.parse_args() + if args.diff and not args.grammar_file: + parser.error("-d/--diff requires -g/--grammar-file") + if args.multiline: + sep = "\n" + else: + sep = " " + program = sep.join(args.program) + if args.grammar_file: + sys.path.insert(0, os.curdir) + from pegen.build import build_parser_and_generator + + build_parser_and_generator(args.grammar_file, "peg_parser/parse.c", compile_extension=True) + from pegen.parse import parse_string # type: ignore[import] + + tree = parse_string(program, mode=1) + + if args.diff: + a = tree + b = ast.parse(program) + diff = diff_trees(a, b, args.verbose) + if diff: + for line in diff: + print(line) + else: + print("# Trees are the same") + else: + print(f"# Parsed using {args.grammar_file}") + print(format_tree(tree, args.verbose)) + else: + tree = ast.parse(program) + print("# Parse using ast.parse()") + print(format_tree(tree, args.verbose)) + + +if __name__ == "__main__": + main() diff --git a/ast3/Tools/peg_generator/scripts/test_parse_directory.py b/ast3/Tools/peg_generator/scripts/test_parse_directory.py new file mode 100755 index 00000000..aef9c74b --- /dev/null +++ b/ast3/Tools/peg_generator/scripts/test_parse_directory.py @@ -0,0 +1,296 @@ +#!/usr/bin/env python3.8 + +import argparse +import ast +import os +import sys +import time +import traceback +from glob import glob +from pathlib import PurePath + +from typing import List, Optional, Any + +sys.path.insert(0, os.getcwd()) +from pegen.build import build_c_parser_and_generator +from pegen.ast_dump import ast_dump +from pegen.testutil import print_memstats +from scripts import show_parse + +SUCCESS = "\033[92m" +FAIL = "\033[91m" +ENDC = "\033[0m" + +argparser = argparse.ArgumentParser( + prog="test_parse_directory", + description="Helper program to test directories or files for pegen", +) +argparser.add_argument("-d", "--directory", help="Directory path containing files to test") +argparser.add_argument("--grammar-file", help="Grammar file path") +argparser.add_argument("--tokens-file", help="Tokens file path") +argparser.add_argument( + "-e", "--exclude", action="append", default=[], help="Glob(s) for matching files to exclude" +) +argparser.add_argument( + "-s", "--short", action="store_true", help="Only show errors, in a more Emacs-friendly format" +) +argparser.add_argument( + "-v", "--verbose", action="store_true", help="Display detailed errors for failures" +) +argparser.add_argument( + "--skip-actions", action="store_true", help="Suppress code emission for rule actions", +) +argparser.add_argument( + "-t", "--tree", action="count", help="Compare parse tree to official AST", default=0 +) + + +def report_status( + succeeded: bool, + file: str, + verbose: bool, + error: Optional[Exception] = None, + short: bool = False, +) -> None: + if short and succeeded: + return + + if succeeded is True: + status = "OK" + COLOR = SUCCESS + else: + status = "Fail" + COLOR = FAIL + + if short: + lineno = 0 + offset = 0 + if isinstance(error, SyntaxError): + lineno = error.lineno or 1 + offset = error.offset or 1 + message = error.args[0] + else: + message = f"{error.__class__.__name__}: {error}" + print(f"{file}:{lineno}:{offset}: {message}") + else: + print(f"{COLOR}{file:60} {status}{ENDC}") + + if error and verbose: + print(f" {str(error.__class__.__name__)}: {error}") + + +def compare_trees( + actual_tree: ast.AST, file: str, verbose: bool, include_attributes: bool = False, +) -> int: + with open(file) as f: + expected_tree = ast.parse(f.read()) + + expected_text = ast_dump(expected_tree, include_attributes=include_attributes) + actual_text = ast_dump(actual_tree, include_attributes=include_attributes) + if actual_text == expected_text: + if verbose: + print("Tree for {file}:") + print(show_parse.format_tree(actual_tree, include_attributes)) + return 0 + + print(f"Diffing ASTs for {file} ...") + + expected = show_parse.format_tree(expected_tree, include_attributes) + actual = show_parse.format_tree(actual_tree, include_attributes) + + if verbose: + print("Expected for {file}:") + print(expected) + print("Actual for {file}:") + print(actual) + print(f"Diff for {file}:") + + diff = show_parse.diff_trees(expected_tree, actual_tree, include_attributes) + for line in diff: + print(line) + + return 1 + + +def parse_directory( + directory: str, + grammar_file: str, + tokens_file: str, + verbose: bool, + excluded_files: List[str], + skip_actions: bool, + tree_arg: int, + short: bool, + extension: Any, + mode: int, + parser: str, +) -> int: + if parser == "cpython" and (tree_arg or mode == 0): + print("Cannot specify tree argument or mode=0 with the cpython parser.", file=sys.stderr) + return 1 + + if not directory: + print("You must specify a directory of files to test.", file=sys.stderr) + return 1 + + if grammar_file and tokens_file: + if not os.path.exists(grammar_file): + print(f"The specified grammar file, {grammar_file}, does not exist.", file=sys.stderr) + return 1 + + try: + if not extension and parser == "pegen": + build_c_parser_and_generator( + grammar_file, + tokens_file, + "peg_extension/parse.c", + compile_extension=True, + skip_actions=skip_actions, + ) + except Exception as err: + print( + f"{FAIL}The following error occurred when generating the parser. Please check your grammar file.\n{ENDC}", + file=sys.stderr, + ) + traceback.print_exception(err.__class__, err, None) + + return 1 + + else: + print( + "A grammar file or a tokens file was not provided - attempting to use existing parser from stdlib...\n" + ) + + if parser == "pegen": + try: + from peg_extension import parse # type: ignore + except Exception as e: + print( + "An existing parser was not found. Please run `make` or specify a grammar file with the `-g` flag.", + file=sys.stderr, + ) + return 1 + + # For a given directory, traverse files and attempt to parse each one + # - Output success/failure for each file + errors = 0 + files = [] + trees = {} # Trees to compare (after everything else is done) + + t0 = time.time() + for file in sorted(glob(f"{directory}/**/*.py", recursive=True)): + # Only attempt to parse Python files and files that are not excluded + should_exclude_file = False + for pattern in excluded_files: + if PurePath(file).match(pattern): + should_exclude_file = True + break + + if not should_exclude_file: + try: + if tree_arg: + mode = 1 + if parser == "cpython": + with open(file, "r") as f: + source = f.read() + if mode == 2: + compile(source, file, "exec") + elif mode == 1: + ast.parse(source, file, "exec") + else: + tree = parse.parse_file(file, mode=mode) + if tree_arg: + trees[file] = tree + if not short: + report_status(succeeded=True, file=file, verbose=verbose) + except Exception as error: + try: + ast.parse(file) + except Exception: + if not short: + print(f"File {file} cannot be parsed by either pegen or the ast module.") + else: + report_status( + succeeded=False, file=file, verbose=verbose, error=error, short=short + ) + errors += 1 + files.append(file) + t1 = time.time() + + total_seconds = t1 - t0 + total_files = len(files) + + total_bytes = 0 + total_lines = 0 + for file in files: + # Count lines and bytes separately + with open(file, "rb") as f: + total_lines += sum(1 for _ in f) + total_bytes += f.tell() + + print( + f"Checked {total_files:,} files, {total_lines:,} lines,", + f"{total_bytes:,} bytes in {total_seconds:,.3f} seconds.", + ) + if total_seconds > 0: + print( + f"That's {total_lines / total_seconds :,.0f} lines/sec,", + f"or {total_bytes / total_seconds :,.0f} bytes/sec.", + ) + + if parser == "pegen": + # Dump memo stats to @data. + with open("@data", "w") as datafile: + for i, count in enumerate(parse.get_memo_stats()): + if count: + datafile.write(f"{i:4d} {count:9d}\n") + + if short: + print_memstats() + + if errors: + print(f"Encountered {errors} failures.", file=sys.stderr) + + # Compare trees (the dict is empty unless -t is given) + compare_trees_errors = 0 + for file, tree in trees.items(): + if not short: + print("Comparing ASTs for", file) + if compare_trees(tree, file, verbose, tree_arg >= 2) == 1: + compare_trees_errors += 1 + + if errors or compare_trees_errors: + return 1 + + return 0 + + +def main() -> None: + args = argparser.parse_args() + directory = args.directory + grammar_file = args.grammar_file + tokens_file = args.tokens_file + verbose = args.verbose + excluded_files = args.exclude + skip_actions = args.skip_actions + tree = args.tree + short = args.short + sys.exit( + parse_directory( + directory, + grammar_file, + tokens_file, + verbose, + excluded_files, + skip_actions, + tree, + short, + None, + 0, + "pegen", + ) + ) + + +if __name__ == "__main__": + main() diff --git a/ast3/Tools/peg_generator/scripts/test_pypi_packages.py b/ast3/Tools/peg_generator/scripts/test_pypi_packages.py new file mode 100755 index 00000000..7586b1a2 --- /dev/null +++ b/ast3/Tools/peg_generator/scripts/test_pypi_packages.py @@ -0,0 +1,111 @@ +#!/usr/bin/env python3.8 + +import argparse +import os +import glob +import tarfile +import zipfile +import shutil +import pathlib +import sys + +from typing import Generator, Any + +sys.path.insert(0, ".") + +from pegen import build +from scripts import test_parse_directory + +HERE = pathlib.Path(__file__).resolve().parent + +argparser = argparse.ArgumentParser( + prog="test_pypi_packages", description="Helper program to test parsing PyPI packages", +) +argparser.add_argument( + "-t", "--tree", action="count", help="Compare parse tree to official AST", default=0 +) + + +def get_packages() -> Generator[str, None, None]: + all_packages = ( + glob.glob("./data/pypi/*.tar.gz") + + glob.glob("./data/pypi/*.zip") + + glob.glob("./data/pypi/*.tgz") + ) + for package in all_packages: + yield package + + +def extract_files(filename: str) -> None: + savedir = os.path.join("data", "pypi") + if tarfile.is_tarfile(filename): + tarfile.open(filename).extractall(savedir) + elif zipfile.is_zipfile(filename): + zipfile.ZipFile(filename).extractall(savedir) + else: + raise ValueError(f"Could not identify type of compressed file {filename}") + + +def find_dirname(package_name: str) -> str: + for name in os.listdir(os.path.join("data", "pypi")): + full_path = os.path.join("data", "pypi", name) + if os.path.isdir(full_path) and name in package_name: + return full_path + assert False # This is to fix mypy, should never be reached + + +def run_tests(dirname: str, tree: int, extension: Any) -> int: + return test_parse_directory.parse_directory( + dirname, + HERE / ".." / ".." / ".." / "Grammar" / "python.gram", + HERE / ".." / ".." / ".." / "Grammar" / "Tokens", + verbose=False, + excluded_files=[ + "*/failset/*", + "*/failset/**", + "*/failset/**/*", + "*/test2to3/*", + "*/test2to3/**/*", + "*/bad*", + "*/lib2to3/tests/data/*", + ], + skip_actions=False, + tree_arg=tree, + short=True, + extension=extension, + mode=1, + parser="pegen", + ) + + +def main() -> None: + args = argparser.parse_args() + tree = args.tree + + extension = build.build_c_parser_and_generator( + HERE / ".." / ".." / ".." / "Grammar" / "python.gram", + HERE / ".." / ".." / ".." / "Grammar" / "Tokens", + "peg_extension/parse.c", + compile_extension=True, + ) + + for package in get_packages(): + print(f"Extracting files from {package}... ", end="") + try: + extract_files(package) + print("Done") + except ValueError as e: + print(e) + continue + + print(f"Trying to parse all python files ... ") + dirname = find_dirname(package) + status = run_tests(dirname, tree, extension) + if status == 0: + shutil.rmtree(dirname) + else: + print(f"Failed to parse {dirname}") + + +if __name__ == "__main__": + main() From 1791235fbc20f4e93c7593b5a4f60d764f81b365 Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Sun, 10 May 2020 02:56:20 -0700 Subject: [PATCH 3/7] Update header guards --- ast3/Include/Python-ast.h | 6 +++--- ast3/Include/asdl.h | 6 +++--- ast3/Include/pegen_interface.h | 6 +++--- ast3/Include/token.h | 6 +++--- ast3/Parser/pegen/parse_string.h | 4 ++-- ast3/Parser/pegen/pegen.h | 4 ++-- ast3/Parser/tokenizer.h | 6 +++--- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/ast3/Include/Python-ast.h b/ast3/Include/Python-ast.h index e7afa1e6..23effd5c 100644 --- a/ast3/Include/Python-ast.h +++ b/ast3/Include/Python-ast.h @@ -1,7 +1,7 @@ /* File automatically generated by Parser/asdl_c.py. */ -#ifndef Py_PYTHON_AST_H -#define Py_PYTHON_AST_H +#ifndef Ta3_PYTHON_AST_H +#define Ta3_PYTHON_AST_H #ifdef __cplusplus extern "C" { #endif @@ -694,4 +694,4 @@ int PyAST_Check(PyObject* obj); #ifdef __cplusplus } #endif -#endif /* !Py_PYTHON_AST_H */ +#endif /* !Ta3_PYTHON_AST_H */ diff --git a/ast3/Include/asdl.h b/ast3/Include/asdl.h index e962560b..5c6292e3 100644 --- a/ast3/Include/asdl.h +++ b/ast3/Include/asdl.h @@ -1,6 +1,6 @@ #ifndef Py_LIMITED_API -#ifndef Py_ASDL_H -#define Py_ASDL_H +#ifndef Ta3_ASDL_H +#define Ta3_ASDL_H typedef PyObject * identifier; typedef PyObject * string; @@ -42,5 +42,5 @@ asdl_int_seq *_Py_asdl_int_seq_new(Py_ssize_t size, PyArena *arena); #define asdl_seq_SET(S, I, V) (S)->elements[I] = (V) #endif -#endif /* !Py_ASDL_H */ +#endif /* !Ta3_ASDL_H */ #endif /* Py_LIMITED_API */ diff --git a/ast3/Include/pegen_interface.h b/ast3/Include/pegen_interface.h index ee4c77ec..bbacb831 100644 --- a/ast3/Include/pegen_interface.h +++ b/ast3/Include/pegen_interface.h @@ -1,5 +1,5 @@ -#ifndef Py_PEGENINTERFACE -#define Py_PEGENINTERFACE +#ifndef Ta3_PEGENINTERFACE +#define Ta3_PEGENINTERFACE #ifdef __cplusplus extern "C" { #endif @@ -43,4 +43,4 @@ PyAPI_FUNC(mod_ty) PyPegen_ASTFromFilename( #ifdef __cplusplus } #endif -#endif /* !Py_PEGENINTERFACE*/ +#endif /* !Ta3_PEGENINTERFACE*/ diff --git a/ast3/Include/token.h b/ast3/Include/token.h index 9b8a3aae..a5dee82e 100644 --- a/ast3/Include/token.h +++ b/ast3/Include/token.h @@ -2,8 +2,8 @@ /* Token types */ #ifndef Py_LIMITED_API -#ifndef Py_TOKEN_H -#define Py_TOKEN_H +#ifndef Ta3_TOKEN_H +#define Ta3_TOKEN_H #ifdef __cplusplus extern "C" { #endif @@ -92,5 +92,5 @@ PyAPI_FUNC(int) PyToken_ThreeChars(int, int, int); #ifdef __cplusplus } #endif -#endif /* !Py_TOKEN_H */ +#endif /* !Ta3_TOKEN_H */ #endif /* Py_LIMITED_API */ diff --git a/ast3/Parser/pegen/parse_string.h b/ast3/Parser/pegen/parse_string.h index cd85bd57..07f81661 100644 --- a/ast3/Parser/pegen/parse_string.h +++ b/ast3/Parser/pegen/parse_string.h @@ -1,5 +1,5 @@ -#ifndef STRINGS_H -#define STRINGS_H +#ifndef Ta3_STRINGS_H +#define Ta3_STRINGS_H #include #include diff --git a/ast3/Parser/pegen/pegen.h b/ast3/Parser/pegen/pegen.h index ffb18e47..39d69e8c 100644 --- a/ast3/Parser/pegen/pegen.h +++ b/ast3/Parser/pegen/pegen.h @@ -1,5 +1,5 @@ -#ifndef PEGEN_H -#define PEGEN_H +#ifndef Ta3_PEGEN_H +#define Ta3_PEGEN_H #define PY_SSIZE_T_CLEAN #include diff --git a/ast3/Parser/tokenizer.h b/ast3/Parser/tokenizer.h index 5660ea38..d9f87b3e 100644 --- a/ast3/Parser/tokenizer.h +++ b/ast3/Parser/tokenizer.h @@ -1,5 +1,5 @@ -#ifndef Py_TOKENIZER_H -#define Py_TOKENIZER_H +#ifndef Ta3_TOKENIZER_H +#define Ta3_TOKENIZER_H #ifdef __cplusplus extern "C" { #endif @@ -85,4 +85,4 @@ extern int PyTokenizer_Get(struct tok_state *, const char **, const char **); #ifdef __cplusplus } #endif -#endif /* !Py_TOKENIZER_H */ +#endif /* !Ta3_TOKENIZER_H */ From 80f3bbb32a4774cb6b25c6cc42f6b8952d50a014 Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Sun, 10 May 2020 03:05:02 -0700 Subject: [PATCH 4/7] Add custom files --- ast3/Custom/ta3_compat.c | 66 ++++++++++ ast3/Custom/typed_ast.c | 251 ++++----------------------------------- 2 files changed, 86 insertions(+), 231 deletions(-) create mode 100644 ast3/Custom/ta3_compat.c diff --git a/ast3/Custom/ta3_compat.c b/ast3/Custom/ta3_compat.c new file mode 100644 index 00000000..c338a1fb --- /dev/null +++ b/ast3/Custom/ta3_compat.c @@ -0,0 +1,66 @@ +#include "../Include/ta3_compat.h" + +// Backport of _PyObject_LookupAttr for 3.6 +int +_Pegen_PyObject_LookupAttr(PyObject *v, PyObject *name, PyObject **result) +{ + PyTypeObject *tp = Py_TYPE(v); + + if (!PyUnicode_Check(name)) { + PyErr_Format(PyExc_TypeError, + "attribute name must be string, not '%.200s'", + Py_TYPE(name)->tp_name); + *result = NULL; + return -1; + } + + if (tp->tp_getattro == PyObject_GenericGetAttr) { + *result = PyObject_GenericGetAttr(v, name); + if (*result != NULL) { + return 1; + } + if (PyErr_Occurred()) { + return -1; + } + return 0; + } + if (tp->tp_getattro != NULL) { + *result = (*tp->tp_getattro)(v, name); + } + else if (tp->tp_getattr != NULL) { + const char *name_str = PyUnicode_AsUTF8(name); + if (name_str == NULL) { + *result = NULL; + return -1; + } + *result = (*tp->tp_getattr)(v, (char *)name_str); + } + else { + *result = NULL; + return 0; + } + + if (*result != NULL) { + return 1; + } + if (!PyErr_ExceptionMatches(PyExc_AttributeError)) { + return -1; + } + PyErr_Clear(); + return 0; +} + +// Backports of _PyType_Name for Python 3.6 +const char * +_Ta3Type_Name(PyTypeObject *type) +{ + assert(type->tp_name != NULL); + const char *s = strrchr(type->tp_name, '.'); + if (s == NULL) { + s = type->tp_name; + } + else { + s++; + } + return s; +} diff --git a/ast3/Custom/typed_ast.c b/ast3/Custom/typed_ast.c index 28612a8a..d6243bdd 100644 --- a/ast3/Custom/typed_ast.c +++ b/ast3/Custom/typed_ast.c @@ -1,18 +1,15 @@ +#define Py_PYTHON_AST_H #include "Python.h" #include "../Include/Python-ast.h" -#include "../Include/node.h" -#include "../Include/grammar.h" #include "../Include/token.h" -#include "../Include/ast.h" -#include "../Include/parsetok.h" -#include "../Include/errcode.h" -#include "../Include/graminit.h" +#include "errcode.h" +#include "../Include/ta3_compat.h" +#include "../Include/pegen_interface.h" +#include "../Parser/pegen/pegen.h" -extern grammar _Ta3Parser_Grammar; /* from graminit.c */ - -// from Python/bltinmodule.c -static const char * -source_as_string(PyObject *cmd, const char *funcname, const char *what, PyCompilerFlags *cf, PyObject **cmd_copy) +// from Python/pythonrun.c +const char * +_Pegen_SourceAsString(PyObject *cmd, const char *funcname, const char *what, PegenCompilerFlags *cf, PyObject **cmd_copy) { const char *str; Py_ssize_t size; @@ -46,233 +43,24 @@ source_as_string(PyObject *cmd, const char *funcname, const char *what, PyCompil } else { PyErr_Format(PyExc_TypeError, - "%s() arg 1 must be a %s object", - funcname, what); + "%s() arg 1 must be a %s object", + funcname, what); return NULL; } if (strlen(str) != (size_t)size) { PyErr_SetString(PyExc_ValueError, - "source code string cannot contain null bytes"); + "source code string cannot contain null bytes"); Py_CLEAR(*cmd_copy); return NULL; } return str; } -// from Python/pythonrun.c -/* compute parser flags based on compiler flags */ -static int PARSER_FLAGS(PyCompilerFlags *flags) -{ - int parser_flags = 0; - if (!flags) - return 0; - if (flags->cf_flags & PyCF_DONT_IMPLY_DEDENT) - parser_flags |= PyPARSE_DONT_IMPLY_DEDENT; - if (flags->cf_flags & PyCF_IGNORE_COOKIE) - parser_flags |= PyPARSE_IGNORE_COOKIE; - if (flags->cf_flags & CO_FUTURE_BARRY_AS_BDFL) - parser_flags |= PyPARSE_BARRY_AS_BDFL; - return parser_flags; -} - -// from Python/pythonrun.c -/* Set the error appropriate to the given input error code (see errcode.h) */ -static void -err_input(perrdetail *err) -{ - PyObject *v, *w, *errtype, *errtext; - PyObject *msg_obj = NULL; - char *msg = NULL; - int offset = err->offset; - - errtype = PyExc_SyntaxError; - switch (err->error) { - case E_ERROR: - return; - case E_SYNTAX: - errtype = PyExc_IndentationError; - if (err->expected == INDENT) - msg = "expected an indented block"; - else if (err->token == INDENT) - msg = "unexpected indent"; - else if (err->token == DEDENT) - msg = "unexpected unindent"; - else { - errtype = PyExc_SyntaxError; - if (err->token == TYPE_COMMENT) - msg = "misplaced type annotation"; - else - msg = "invalid syntax"; - } - break; - case E_TOKEN: - msg = "invalid token"; - break; - case E_EOFS: - msg = "EOF while scanning triple-quoted string literal"; - break; - case E_EOLS: - msg = "EOL while scanning string literal"; - break; - case E_INTR: - if (!PyErr_Occurred()) - PyErr_SetNone(PyExc_KeyboardInterrupt); - goto cleanup; - case E_NOMEM: - PyErr_NoMemory(); - goto cleanup; - case E_EOF: - msg = "unexpected EOF while parsing"; - break; - case E_TABSPACE: - errtype = PyExc_TabError; - msg = "inconsistent use of tabs and spaces in indentation"; - break; - case E_OVERFLOW: - msg = "expression too long"; - break; - case E_DEDENT: - errtype = PyExc_IndentationError; - msg = "unindent does not match any outer indentation level"; - break; - case E_TOODEEP: - errtype = PyExc_IndentationError; - msg = "too many levels of indentation"; - break; - case E_DECODE: { - PyObject *type, *value, *tb; - PyErr_Fetch(&type, &value, &tb); - msg = "unknown decode error"; - if (value != NULL) - msg_obj = PyObject_Str(value); - Py_XDECREF(type); - Py_XDECREF(value); - Py_XDECREF(tb); - break; - } - case E_LINECONT: - msg = "unexpected character after line continuation character"; - break; - - case E_IDENTIFIER: - msg = "invalid character in identifier"; - break; - case E_BADSINGLE: - msg = "multiple statements found while compiling a single statement"; - break; - default: - fprintf(stderr, "error=%d\n", err->error); - msg = "unknown parsing error"; - break; - } - /* err->text may not be UTF-8 in case of decoding errors. - Explicitly convert to an object. */ - if (!err->text) { - errtext = Py_None; - Py_INCREF(Py_None); - } else { - errtext = PyUnicode_DecodeUTF8(err->text, err->offset, - "replace"); - if (errtext != NULL) { - Py_ssize_t len = strlen(err->text); - offset = (int)PyUnicode_GET_LENGTH(errtext); - if (len != err->offset) { - Py_DECREF(errtext); - errtext = PyUnicode_DecodeUTF8(err->text, len, - "replace"); - } - } - } - v = Py_BuildValue("(OiiN)", err->filename, - err->lineno, offset, errtext); - if (v != NULL) { - if (msg_obj) - w = Py_BuildValue("(OO)", msg_obj, v); - else - w = Py_BuildValue("(sO)", msg, v); - } else - w = NULL; - Py_XDECREF(v); - PyErr_SetObject(errtype, w); - Py_XDECREF(w); -cleanup: - Py_XDECREF(msg_obj); - if (err->text != NULL) { - PyObject_FREE(err->text); - err->text = NULL; - } -} - -// from Python/pythonrun.c -static void -err_free(perrdetail *err) -{ - Py_CLEAR(err->filename); -} - -// from Python/pythonrun.c -node * -Ta3Parser_SimpleParseStringFlagsFilename(const char *str, const char *filename, - int start, int flags) -{ - perrdetail err; - node *n = Ta3Parser_ParseStringFlagsFilename(str, filename, - &_Ta3Parser_Grammar, start, &err, flags); - if (n == NULL) - err_input(&err); - err_free(&err); - return n; -} - -/* update compiler and parser flags based on feature version */ -void -_Ta3Parser_UpdateFlags(PyCompilerFlags *flags, int *iflags, int feature_version) -{ - *iflags = PARSER_FLAGS(flags); - if (feature_version >= 7) - *iflags |= PyPARSE_ASYNC_ALWAYS; - flags->cf_flags |= *iflags & PyCF_MASK; -} - -// copy of PyParser_ASTFromStringObject in Python/pythonrun.c -/* Preferred access to parser is through AST. */ -static mod_ty -string_object_to_c_ast(const char *s, PyObject *filename, int start, - PyCompilerFlags *flags, int feature_version, - PyArena *arena) -{ - mod_ty mod; - PyCompilerFlags localflags; - perrdetail err; - node *n; - int iflags; - - if (flags == NULL) { - localflags.cf_flags = 0; - flags = &localflags; - } - _Ta3Parser_UpdateFlags(flags, &iflags, feature_version); - n = Ta3Parser_ParseStringObject(s, filename, - &_Ta3Parser_Grammar, start, &err, - &iflags); - if (n) { - flags->cf_flags |= iflags & PyCF_MASK; - mod = Ta3AST_FromNodeObject(n, flags, filename, feature_version, arena); - Ta3Node_Free(n); - } - else { - err_input(&err); - mod = NULL; - } - err_free(&err); - return mod; -} - // adapted from Py_CompileStringObject in Python/pythonrun.c static PyObject * -string_object_to_py_ast(const char *str, PyObject *filename, int start, - PyCompilerFlags *flags, int feature_version) +string_object_to_py_ast(const char *str, PyObject *filename, int mode, + PegenCompilerFlags *flags) { mod_ty mod; PyObject *result; @@ -280,7 +68,7 @@ string_object_to_py_ast(const char *str, PyObject *filename, int start, if (arena == NULL) return NULL; - mod = string_object_to_c_ast(str, filename, start, flags, feature_version, arena); + mod = Ta3Pegen_ASTFromStringObject(str, filename, mode, flags, arena); if (mod == NULL) { PyArena_Free(arena); return NULL; @@ -301,11 +89,12 @@ ast3_parse_impl(PyObject *source, PyObject *source_copy; const char *str; int compile_mode = -1; - PyCompilerFlags cf; - int start[] = {file_input, eval_input, single_input, func_type_input}; + PegenCompilerFlags cf; + //int start[] = {file_input, eval_input, single_input, func_type_input}; PyObject *result; cf.cf_flags = PyCF_ONLY_AST | PyCF_SOURCE_IS_UTF8; + cf.cf_feature_version = feature_version; if (strcmp(mode, "exec") == 0) compile_mode = 0; @@ -321,11 +110,11 @@ ast3_parse_impl(PyObject *source, goto error; } - str = source_as_string(source, "parse", "string or bytes", &cf, &source_copy); + str = _Pegen_SourceAsString(source, "parse", "string or bytes", &cf, &source_copy); if (str == NULL) goto error; - result = string_object_to_py_ast(str, filename, start[compile_mode], &cf, feature_version); + result = string_object_to_py_ast(str, filename, compile_mode, &cf); Py_XDECREF(source_copy); goto finally; @@ -336,7 +125,7 @@ ast3_parse_impl(PyObject *source, return result; } -// adapted from builtin_compile in Python/clinic/bltinmodule.c.h +// adapted from old typed_ast based on builtin_compile in Python/clinic/bltinmodule.c.h PyObject * ast3_parse(PyObject *self, PyObject *args) { From 5be6a5b9cf71c27747387be585e9ee06ad1df4b9 Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Sun, 10 May 2020 03:05:27 -0700 Subject: [PATCH 5/7] Update exported symbols --- ast3/Grammar/python.gram | 438 ++-- ast3/Include/Python-ast.h | 439 ++-- ast3/Include/asdl.h | 4 +- ast3/Include/pegen_interface.h | 16 +- ast3/Include/ta3_compat.h | 78 + ast3/Parser/asdl_c.py | 56 +- ast3/Parser/pegen/parse.c | 2189 +++++++++-------- ast3/Parser/pegen/parse_string.c | 52 +- ast3/Parser/pegen/parse_string.h | 12 +- ast3/Parser/pegen/peg_api.c | 22 +- ast3/Parser/pegen/pegen.c | 278 +-- ast3/Parser/pegen/pegen.h | 138 +- ast3/Parser/tokenizer.c | 38 +- ast3/Parser/tokenizer.h | 10 +- ast3/Python/Python-ast.c | 846 ++++--- ast3/Python/asdl.c | 4 +- .../peg_extension/peg_extension.c | 16 +- ast3/Tools/peg_generator/pegen/c_generator.py | 42 +- setup.py | 37 +- 19 files changed, 2448 insertions(+), 2267 deletions(-) create mode 100644 ast3/Include/ta3_compat.h diff --git a/ast3/Grammar/python.gram b/ast3/Grammar/python.gram index 574e1e14..f91a9b97 100644 --- a/ast3/Grammar/python.gram +++ b/ast3/Grammar/python.gram @@ -3,7 +3,7 @@ @bytecode True @trailer ''' void * -_PyPegen_parse(Parser *p) +_Ta3Pegen_parse(Parser *p) { // Initialize keywords p->keywords = reserved_keywords; @@ -28,7 +28,7 @@ _PyPegen_parse(Parser *p) // The end ''' -file[mod_ty]: a=[statements] ENDMARKER { _PyPegen_make_module(p, a) } +file[mod_ty]: a=[statements] ENDMARKER { _Ta3Pegen_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) } @@ -37,39 +37,39 @@ 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) } + _Ta3Pegen_seq_append_to_end(p, CHECK(_Ta3Pegen_seq_append_to_end(p, a, b)), c) } + | a=','.expression+ ',' '*' b=expression { _Ta3Pegen_seq_append_to_end(p, a, b) } + | a=','.expression+ ',' '**' b=expression { _Ta3Pegen_seq_append_to_end(p, a, b) } | '*' a=expression ',' '**' b=expression { - _PyPegen_seq_append_to_end(p, CHECK(_PyPegen_singleton_seq(p, a)), b) } - | '*' a=expression { _PyPegen_singleton_seq(p, a) } - | '**' a=expression { _PyPegen_singleton_seq(p, a) } + _Ta3Pegen_seq_append_to_end(p, CHECK(_Ta3Pegen_singleton_seq(p, a)), b) } + | '*' a=expression { _Ta3Pegen_singleton_seq(p, a) } + | '**' a=expression { _Ta3Pegen_singleton_seq(p, a) } | ','.expression+ -statements[asdl_seq*]: a=statement+ { _PyPegen_seq_flatten(p, a) } -statement[asdl_seq*]: a=compound_stmt { _PyPegen_singleton_seq(p, a) } | simple_stmt +statements[asdl_seq*]: a=statement+ { _Ta3Pegen_seq_flatten(p, a) } +statement[asdl_seq*]: a=compound_stmt { _Ta3Pegen_singleton_seq(p, a) } | simple_stmt statement_newline[asdl_seq*]: - | a=compound_stmt NEWLINE { _PyPegen_singleton_seq(p, a) } + | a=compound_stmt NEWLINE { _Ta3Pegen_singleton_seq(p, a) } | simple_stmt - | NEWLINE { _PyPegen_singleton_seq(p, CHECK(_Py_Pass(EXTRA))) } - | ENDMARKER { _PyPegen_interactive_exit(p) } + | NEWLINE { _Ta3Pegen_singleton_seq(p, CHECK(_Ta3_Pass(EXTRA))) } + | ENDMARKER { _Ta3Pegen_interactive_exit(p) } simple_stmt[asdl_seq*]: - | a=small_stmt !';' NEWLINE { _PyPegen_singleton_seq(p, a) } # Not needed, there for speedup + | a=small_stmt !';' NEWLINE { _Ta3Pegen_singleton_seq(p, a) } # Not needed, there for speedup | a=';'.small_stmt+ [';'] NEWLINE { a } # NOTE: assignment MUST precede expression, else parsing a simple assignment # will throw a SyntaxError. small_stmt[stmt_ty] (memo): | assignment - | e=star_expressions { _Py_Expr(e, EXTRA) } + | e=star_expressions { _Ta3_Expr(e, EXTRA) } | &'return' return_stmt | &('import' | 'from') import_stmt | &'raise' raise_stmt - | 'pass' { _Py_Pass(EXTRA) } + | 'pass' { _Ta3_Pass(EXTRA) } | &'del' del_stmt | &'yield' yield_stmt | &'assert' assert_stmt - | 'break' { _Py_Break(EXTRA) } - | 'continue' { _Py_Continue(EXTRA) } + | 'break' { _Ta3_Break(EXTRA) } + | 'continue' { _Ta3_Continue(EXTRA) } | &'global' global_stmt | &'nonlocal' nonlocal_stmt compound_stmt[stmt_ty]: @@ -87,131 +87,131 @@ assignment[stmt_ty]: CHECK_VERSION( 6, "Variable annotation syntax is", - _Py_AnnAssign(CHECK(_PyPegen_set_expr_context(p, a, Store)), b, c, 1, EXTRA) + _Ta3_AnnAssign(CHECK(_Ta3Pegen_set_expr_context(p, a, Store)), b, c, 1, EXTRA) ) } | a=('(' b=inside_paren_ann_assign_target ')' { b } | ann_assign_subscript_attribute_target) ':' b=expression c=['=' d=annotated_rhs { d }] { - CHECK_VERSION(6, "Variable annotations syntax is", _Py_AnnAssign(a, b, c, 0, EXTRA)) } + CHECK_VERSION(6, "Variable annotations syntax is", _Ta3_AnnAssign(a, b, c, 0, EXTRA)) } | a=(z=star_targets '=' { z })+ b=(yield_expr | star_expressions) tc=[TYPE_COMMENT] { - _Py_Assign(a, b, NEW_TYPE_COMMENT(p, tc), EXTRA) } + _Ta3_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) } + _Ta3_AugAssign(a, b->kind, c, EXTRA) } | invalid_assignment augassign[AugOperator*]: - | '+=' { _PyPegen_augoperator(p, Add) } - | '-=' { _PyPegen_augoperator(p, Sub) } - | '*=' { _PyPegen_augoperator(p, Mult) } - | '@=' { CHECK_VERSION(5, "The '@' operator is", _PyPegen_augoperator(p, MatMult)) } - | '/=' { _PyPegen_augoperator(p, Div) } - | '%=' { _PyPegen_augoperator(p, Mod) } - | '&=' { _PyPegen_augoperator(p, BitAnd) } - | '|=' { _PyPegen_augoperator(p, BitOr) } - | '^=' { _PyPegen_augoperator(p, BitXor) } - | '<<=' { _PyPegen_augoperator(p, LShift) } - | '>>=' { _PyPegen_augoperator(p, RShift) } - | '**=' { _PyPegen_augoperator(p, Pow) } - | '//=' { _PyPegen_augoperator(p, FloorDiv) } + | '+=' { _Ta3Pegen_augoperator(p, Add) } + | '-=' { _Ta3Pegen_augoperator(p, Sub) } + | '*=' { _Ta3Pegen_augoperator(p, Mult) } + | '@=' { CHECK_VERSION(5, "The '@' operator is", _Ta3Pegen_augoperator(p, MatMult)) } + | '/=' { _Ta3Pegen_augoperator(p, Div) } + | '%=' { _Ta3Pegen_augoperator(p, Mod) } + | '&=' { _Ta3Pegen_augoperator(p, BitAnd) } + | '|=' { _Ta3Pegen_augoperator(p, BitOr) } + | '^=' { _Ta3Pegen_augoperator(p, BitXor) } + | '<<=' { _Ta3Pegen_augoperator(p, LShift) } + | '>>=' { _Ta3Pegen_augoperator(p, RShift) } + | '**=' { _Ta3Pegen_augoperator(p, Pow) } + | '//=' { _Ta3Pegen_augoperator(p, FloorDiv) } global_stmt[stmt_ty]: 'global' a=','.NAME+ { - _Py_Global(CHECK(_PyPegen_map_names_to_ids(p, a)), EXTRA) } + _Ta3_Global(CHECK(_Ta3Pegen_map_names_to_ids(p, a)), EXTRA) } nonlocal_stmt[stmt_ty]: 'nonlocal' a=','.NAME+ { - _Py_Nonlocal(CHECK(_PyPegen_map_names_to_ids(p, a)), EXTRA) } + _Ta3_Nonlocal(CHECK(_Ta3Pegen_map_names_to_ids(p, a)), EXTRA) } -yield_stmt[stmt_ty]: y=yield_expr { _Py_Expr(y, EXTRA) } +yield_stmt[stmt_ty]: y=yield_expr { _Ta3_Expr(y, EXTRA) } -assert_stmt[stmt_ty]: 'assert' a=expression b=[',' z=expression { z }] { _Py_Assert(a, b, EXTRA) } +assert_stmt[stmt_ty]: 'assert' a=expression b=[',' z=expression { z }] { _Ta3_Assert(a, b, EXTRA) } -del_stmt[stmt_ty]: 'del' a=del_targets { _Py_Delete(a, EXTRA) } +del_stmt[stmt_ty]: 'del' a=del_targets { _Ta3_Delete(a, EXTRA) } import_stmt[stmt_ty]: import_name | import_from -import_name[stmt_ty]: 'import' a=dotted_as_names { _Py_Import(a, EXTRA) } +import_name[stmt_ty]: 'import' a=dotted_as_names { _Ta3_Import(a, EXTRA) } # note below: the ('.' | '...') is necessary because '...' is tokenized as ELLIPSIS import_from[stmt_ty]: | 'from' a=('.' | '...')* b=dotted_name 'import' c=import_from_targets { - _Py_ImportFrom(b->v.Name.id, c, _PyPegen_seq_count_dots(a), EXTRA) } + _Ta3_ImportFrom(b->v.Name.id, c, _Ta3Pegen_seq_count_dots(a), EXTRA) } | 'from' a=('.' | '...')+ 'import' b=import_from_targets { - _Py_ImportFrom(NULL, b, _PyPegen_seq_count_dots(a), EXTRA) } + _Ta3_ImportFrom(NULL, b, _Ta3Pegen_seq_count_dots(a), EXTRA) } import_from_targets[asdl_seq*]: | '(' a=import_from_as_names [','] ')' { a } | import_from_as_names - | '*' { _PyPegen_singleton_seq(p, CHECK(_PyPegen_alias_for_star(p))) } + | '*' { _Ta3Pegen_singleton_seq(p, CHECK(_Ta3Pegen_alias_for_star(p))) } import_from_as_names[asdl_seq*]: | a=','.import_from_as_name+ { a } import_from_as_name[alias_ty]: - | a=NAME b=['as' z=NAME { z }] { _Py_alias(a->v.Name.id, + | a=NAME b=['as' z=NAME { z }] { _Ta3_alias(a->v.Name.id, (b) ? ((expr_ty) b)->v.Name.id : NULL, p->arena) } dotted_as_names[asdl_seq*]: | a=','.dotted_as_name+ { a } dotted_as_name[alias_ty]: - | a=dotted_name b=['as' z=NAME { z }] { _Py_alias(a->v.Name.id, + | a=dotted_name b=['as' z=NAME { z }] { _Ta3_alias(a->v.Name.id, (b) ? ((expr_ty) b)->v.Name.id : NULL, p->arena) } dotted_name[expr_ty]: - | a=dotted_name '.' b=NAME { _PyPegen_join_names_with_dot(p, a, b) } + | a=dotted_name '.' b=NAME { _Ta3Pegen_join_names_with_dot(p, a, b) } | NAME if_stmt[stmt_ty]: - | 'if' a=named_expression ':' b=block c=elif_stmt { _Py_If(a, b, CHECK(_PyPegen_singleton_seq(p, c)), EXTRA) } - | 'if' a=named_expression ':' b=block c=[else_block] { _Py_If(a, b, c, EXTRA) } + | 'if' a=named_expression ':' b=block c=elif_stmt { _Ta3_If(a, b, CHECK(_Ta3Pegen_singleton_seq(p, c)), EXTRA) } + | 'if' a=named_expression ':' b=block c=[else_block] { _Ta3_If(a, b, c, EXTRA) } elif_stmt[stmt_ty]: - | 'elif' a=named_expression ':' b=block c=elif_stmt { _Py_If(a, b, CHECK(_PyPegen_singleton_seq(p, c)), EXTRA) } - | 'elif' a=named_expression ':' b=block c=[else_block] { _Py_If(a, b, c, EXTRA) } + | 'elif' a=named_expression ':' b=block c=elif_stmt { _Ta3_If(a, b, CHECK(_Ta3Pegen_singleton_seq(p, c)), EXTRA) } + | 'elif' a=named_expression ':' b=block c=[else_block] { _Ta3_If(a, b, c, EXTRA) } else_block[asdl_seq*]: 'else' ':' b=block { b } while_stmt[stmt_ty]: - | 'while' a=named_expression ':' b=block c=[else_block] { _Py_While(a, b, c, EXTRA) } + | 'while' a=named_expression ':' b=block c=[else_block] { _Ta3_While(a, b, c, EXTRA) } for_stmt[stmt_ty]: | 'for' t=star_targets 'in' ex=star_expressions ':' tc=[TYPE_COMMENT] b=block el=[else_block] { - _Py_For(t, ex, b, el, NEW_TYPE_COMMENT(p, tc), EXTRA) } + _Ta3_For(t, ex, b, el, NEW_TYPE_COMMENT(p, tc), EXTRA) } | ASYNC 'for' t=star_targets 'in' ex=star_expressions ':' tc=[TYPE_COMMENT] b=block el=[else_block] { - CHECK_VERSION(5, "Async for loops are", _Py_AsyncFor(t, ex, b, el, NEW_TYPE_COMMENT(p, tc), EXTRA)) } + CHECK_VERSION(5, "Async for loops are", _Ta3_AsyncFor(t, ex, b, el, NEW_TYPE_COMMENT(p, tc), EXTRA)) } with_stmt[stmt_ty]: | 'with' '(' a=','.with_item+ ','? ')' ':' b=block { - _Py_With(a, b, NULL, EXTRA) } + _Ta3_With(a, b, NULL, EXTRA) } | 'with' a=','.with_item+ ':' tc=[TYPE_COMMENT] b=block { - _Py_With(a, b, NEW_TYPE_COMMENT(p, tc), EXTRA) } + _Ta3_With(a, b, NEW_TYPE_COMMENT(p, tc), EXTRA) } | ASYNC 'with' '(' a=','.with_item+ ','? ')' ':' b=block { - CHECK_VERSION(5, "Async with statements are", _Py_AsyncWith(a, b, NULL, EXTRA)) } + CHECK_VERSION(5, "Async with statements are", _Ta3_AsyncWith(a, b, NULL, EXTRA)) } | ASYNC 'with' a=','.with_item+ ':' tc=[TYPE_COMMENT] b=block { - CHECK_VERSION(5, "Async with statements are", _Py_AsyncWith(a, b, NEW_TYPE_COMMENT(p, tc), EXTRA)) } + CHECK_VERSION(5, "Async with statements are", _Ta3_AsyncWith(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) } + | e=expression o=['as' t=target { t }] { _Ta3_withitem(e, o, p->arena) } try_stmt[stmt_ty]: - | 'try' ':' b=block f=finally_block { _Py_Try(b, NULL, NULL, f, EXTRA) } - | 'try' ':' b=block ex=except_block+ el=[else_block] f=[finally_block] { _Py_Try(b, ex, el, f, EXTRA) } + | 'try' ':' b=block f=finally_block { _Ta3_Try(b, NULL, NULL, f, EXTRA) } + | 'try' ':' b=block ex=except_block+ el=[else_block] f=[finally_block] { _Ta3_Try(b, ex, el, f, EXTRA) } except_block[excepthandler_ty]: | 'except' e=expression t=['as' z=target { z }] ':' b=block { - _Py_ExceptHandler(e, (t) ? ((expr_ty) t)->v.Name.id : NULL, b, EXTRA) } - | 'except' ':' b=block { _Py_ExceptHandler(NULL, NULL, b, EXTRA) } + _Ta3_ExceptHandler(e, (t) ? ((expr_ty) t)->v.Name.id : NULL, b, EXTRA) } + | 'except' ':' b=block { _Ta3_ExceptHandler(NULL, NULL, b, EXTRA) } finally_block[asdl_seq*]: 'finally' ':' a=block { a } return_stmt[stmt_ty]: - | 'return' a=[star_expressions] { _Py_Return(a, EXTRA) } + | 'return' a=[star_expressions] { _Ta3_Return(a, EXTRA) } raise_stmt[stmt_ty]: - | 'raise' a=expression b=['from' z=expression { z }] { _Py_Raise(a, b, EXTRA) } - | 'raise' { _Py_Raise(NULL, NULL, EXTRA) } + | 'raise' a=expression b=['from' z=expression { z }] { _Ta3_Raise(a, b, EXTRA) } + | 'raise' { _Ta3_Raise(NULL, NULL, EXTRA) } function_def[stmt_ty]: - | d=decorators f=function_def_raw { _PyPegen_function_def_decorators(p, d, f) } + | d=decorators f=function_def_raw { _Ta3Pegen_function_def_decorators(p, d, f) } | function_def_raw function_def_raw[stmt_ty]: | 'def' n=NAME '(' params=[params] ')' a=['->' z=expression { z }] ':' tc=[func_type_comment] b=block { - _Py_FunctionDef(n->v.Name.id, - (params) ? params : CHECK(_PyPegen_empty_arguments(p)), + _Ta3_FunctionDef(n->v.Name.id, + (params) ? params : CHECK(_Ta3Pegen_empty_arguments(p)), b, NULL, a, NEW_TYPE_COMMENT(p, tc), EXTRA) } | ASYNC 'def' n=NAME '(' params=[params] ')' a=['->' z=expression { z }] ':' tc=[func_type_comment] b=block { CHECK_VERSION( 5, "Async functions are", - _Py_AsyncFunctionDef(n->v.Name.id, - (params) ? params : CHECK(_PyPegen_empty_arguments(p)), + _Ta3_AsyncFunctionDef(n->v.Name.id, + (params) ? params : CHECK(_Ta3Pegen_empty_arguments(p)), b, NULL, a, NEW_TYPE_COMMENT(p, tc), EXTRA) ) } func_type_comment[Token*]: @@ -225,13 +225,13 @@ params[arguments_ty]: parameters[arguments_ty]: | a=slash_no_default b=param_no_default* c=param_with_default* d=[star_etc] { - _PyPegen_make_arguments(p, a, NULL, b, c, d) } + _Ta3Pegen_make_arguments(p, a, NULL, b, c, d) } | a=slash_with_default b=param_with_default* c=[star_etc] { - _PyPegen_make_arguments(p, NULL, a, NULL, b, c) } + _Ta3Pegen_make_arguments(p, NULL, a, NULL, b, c) } | a=param_no_default+ b=param_with_default* c=[star_etc] { - _PyPegen_make_arguments(p, NULL, NULL, a, b, c) } - | 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) } + _Ta3Pegen_make_arguments(p, NULL, NULL, a, b, c) } + | a=param_with_default+ b=[star_etc] { _Ta3Pegen_make_arguments(p, NULL, NULL, NULL, a, b)} + | a=star_etc { _Ta3Pegen_make_arguments(p, NULL, NULL, NULL, NULL, a) } # Some duplication here because we can't write (',' | &')'), # which is because we don't support empty alternatives (yet). @@ -240,15 +240,15 @@ 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) } + | a=param_no_default* b=param_with_default+ '/' ',' { _Ta3Pegen_slash_with_default(p, a, b) } + | a=param_no_default* b=param_with_default+ '/' &')' { _Ta3Pegen_slash_with_default(p, a, b) } star_etc[StarEtc*]: | '*' a=param_no_default b=param_maybe_default* c=[kwds] { - _PyPegen_star_etc(p, a, b, c) } + _Ta3Pegen_star_etc(p, a, b, c) } | '*' ',' b=param_maybe_default+ c=[kwds] { - _PyPegen_star_etc(p, NULL, b, c) } - | a=kwds { _PyPegen_star_etc(p, NULL, NULL, a) } + _Ta3Pegen_star_etc(p, NULL, b, c) } + | a=kwds { _Ta3Pegen_star_etc(p, NULL, NULL, a) } | invalid_star_etc kwds[arg_ty]: '**' a=param_no_default { a } @@ -266,15 +266,15 @@ kwds[arg_ty]: '**' a=param_no_default { a } # 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) } + | a=param ',' tc=TYPE_COMMENT? { _Ta3Pegen_add_type_comment_to_arg(p, a, tc) } + | a=param tc=TYPE_COMMENT? &')' { _Ta3Pegen_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) } + | a=param c=default ',' tc=TYPE_COMMENT? { _Ta3Pegen_name_default_pair(p, a, c, tc) } + | a=param c=default tc=TYPE_COMMENT? &')' { _Ta3Pegen_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) } + | a=param c=default? ',' tc=TYPE_COMMENT? { _Ta3Pegen_name_default_pair(p, a, c, tc) } + | a=param c=default? tc=TYPE_COMMENT? &')' { _Ta3Pegen_name_default_pair(p, a, c, tc) } +param[arg_ty]: a=NAME b=annotation? { _Ta3_arg(a->v.Name.id, b, NULL, EXTRA) } annotation[expr_ty]: ':' a=expression { a } default[expr_ty]: '=' a=expression { a } @@ -282,11 +282,11 @@ default[expr_ty]: '=' a=expression { a } decorators[asdl_seq*]: a=('@' f=named_expression NEWLINE { f })+ { a } class_def[stmt_ty]: - | a=decorators b=class_def_raw { _PyPegen_class_def_decorators(p, a, b) } + | a=decorators b=class_def_raw { _Ta3Pegen_class_def_decorators(p, a, b) } | class_def_raw class_def_raw[stmt_ty]: | 'class' a=NAME b=['(' z=[arguments] ')' { z }] ':' c=block { - _Py_ClassDef(a->v.Name.id, + _Ta3_ClassDef(a->v.Name.id, (b) ? ((expr_ty) b)->v.Call.args : NULL, (b) ? ((expr_ty) b)->v.Call.keywords : NULL, c, NULL, EXTRA) } @@ -299,19 +299,19 @@ block[asdl_seq*] (memo): expressions_list[asdl_seq*]: a=','.star_expression+ [','] { a } star_expressions[expr_ty]: | a=star_expression b=(',' c=star_expression { c })+ [','] { - _Py_Tuple(CHECK(_PyPegen_seq_insert_in_front(p, a, b)), Load, EXTRA) } - | a=star_expression ',' { _Py_Tuple(CHECK(_PyPegen_singleton_seq(p, a)), Load, EXTRA) } + _Ta3_Tuple(CHECK(_Ta3Pegen_seq_insert_in_front(p, a, b)), Load, EXTRA) } + | a=star_expression ',' { _Ta3_Tuple(CHECK(_Ta3Pegen_singleton_seq(p, a)), Load, EXTRA) } | star_expression star_expression[expr_ty] (memo): - | '*' a=bitwise_or { _Py_Starred(a, Load, EXTRA) } + | '*' a=bitwise_or { _Ta3_Starred(a, Load, EXTRA) } | expression star_named_expressions[asdl_seq*]: a=','.star_named_expression+ [','] { a } star_named_expression[expr_ty]: - | '*' a=bitwise_or { _Py_Starred(a, Load, EXTRA) } + | '*' a=bitwise_or { _Ta3_Starred(a, Load, EXTRA) } | named_expression named_expression[expr_ty]: - | a=NAME ':=' b=expression { _Py_NamedExpr(CHECK(_PyPegen_set_expr_context(p, a, Store)), b, EXTRA) } + | a=NAME ':=' b=expression { _Ta3_NamedExpr(CHECK(_Ta3Pegen_set_expr_context(p, a, Store)), b, EXTRA) } | expression !':=' | invalid_named_expression @@ -319,16 +319,16 @@ annotated_rhs[expr_ty]: yield_expr | star_expressions expressions[expr_ty]: | a=expression b=(',' c=expression { c })+ [','] { - _Py_Tuple(CHECK(_PyPegen_seq_insert_in_front(p, a, b)), Load, EXTRA) } - | a=expression ',' { _Py_Tuple(CHECK(_PyPegen_singleton_seq(p, a)), Load, EXTRA) } + _Ta3_Tuple(CHECK(_Ta3Pegen_seq_insert_in_front(p, a, b)), Load, EXTRA) } + | a=expression ',' { _Ta3_Tuple(CHECK(_Ta3Pegen_singleton_seq(p, a)), Load, EXTRA) } | expression expression[expr_ty] (memo): - | a=disjunction 'if' b=disjunction 'else' c=expression { _Py_IfExp(b, a, c, EXTRA) } + | a=disjunction 'if' b=disjunction 'else' c=expression { _Ta3_IfExp(b, a, c, EXTRA) } | disjunction | lambdef lambdef[expr_ty]: - | 'lambda' a=[lambda_parameters] ':' b=expression { _Py_Lambda((a) ? a : CHECK(_PyPegen_empty_arguments(p)), b, EXTRA) } + | 'lambda' a=[lambda_parameters] ':' b=expression { _Ta3_Lambda((a) ? a : CHECK(_Ta3Pegen_empty_arguments(p)), b, EXTRA) } # lambda_parameters etc. duplicates parameters but without annotations # or type comments, and if there's no comma after a parameter, we expect @@ -336,27 +336,27 @@ lambdef[expr_ty]: # lambda_parameters[arguments_ty]: | a=lambda_slash_no_default b=lambda_param_no_default* c=lambda_param_with_default* d=[lambda_star_etc] { - _PyPegen_make_arguments(p, a, NULL, b, c, d) } + _Ta3Pegen_make_arguments(p, a, NULL, b, c, d) } | a=lambda_slash_with_default b=lambda_param_with_default* c=[lambda_star_etc] { - _PyPegen_make_arguments(p, NULL, a, NULL, b, c) } + _Ta3Pegen_make_arguments(p, NULL, a, NULL, b, c) } | a=lambda_param_no_default+ b=lambda_param_with_default* c=[lambda_star_etc] { - _PyPegen_make_arguments(p, NULL, NULL, a, b, c) } - | a=lambda_param_with_default+ b=[lambda_star_etc] { _PyPegen_make_arguments(p, NULL, NULL, NULL, a, b)} - | a=lambda_star_etc { _PyPegen_make_arguments(p, NULL, NULL, NULL, NULL, a) } + _Ta3Pegen_make_arguments(p, NULL, NULL, a, b, c) } + | a=lambda_param_with_default+ b=[lambda_star_etc] { _Ta3Pegen_make_arguments(p, NULL, NULL, NULL, a, b)} + | a=lambda_star_etc { _Ta3Pegen_make_arguments(p, NULL, NULL, NULL, NULL, a) } lambda_slash_no_default[asdl_seq*]: | a=lambda_param_no_default+ '/' ',' { a } | a=lambda_param_no_default+ '/' &':' { a } lambda_slash_with_default[SlashWithDefault*]: - | a=lambda_param_no_default* b=lambda_param_with_default+ '/' ',' { _PyPegen_slash_with_default(p, a, b) } - | a=lambda_param_no_default* b=lambda_param_with_default+ '/' &':' { _PyPegen_slash_with_default(p, a, b) } + | a=lambda_param_no_default* b=lambda_param_with_default+ '/' ',' { _Ta3Pegen_slash_with_default(p, a, b) } + | a=lambda_param_no_default* b=lambda_param_with_default+ '/' &':' { _Ta3Pegen_slash_with_default(p, a, b) } lambda_star_etc[StarEtc*]: | '*' a=lambda_param_no_default b=lambda_param_maybe_default* c=[lambda_kwds] { - _PyPegen_star_etc(p, a, b, c) } + _Ta3Pegen_star_etc(p, a, b, c) } | '*' ',' b=lambda_param_maybe_default+ c=[lambda_kwds] { - _PyPegen_star_etc(p, NULL, b, c) } - | a=lambda_kwds { _PyPegen_star_etc(p, NULL, NULL, a) } + _Ta3Pegen_star_etc(p, NULL, b, c) } + | a=lambda_kwds { _Ta3Pegen_star_etc(p, NULL, NULL, a) } | invalid_lambda_star_etc lambda_kwds[arg_ty]: '**' a=lambda_param_no_default { a } @@ -365,31 +365,31 @@ lambda_param_no_default[arg_ty]: | a=lambda_param ',' { a } | a=lambda_param &':' { a } lambda_param_with_default[NameDefaultPair*]: - | a=lambda_param c=default ',' { _PyPegen_name_default_pair(p, a, c, NULL) } - | a=lambda_param c=default &':' { _PyPegen_name_default_pair(p, a, c, NULL) } + | a=lambda_param c=default ',' { _Ta3Pegen_name_default_pair(p, a, c, NULL) } + | a=lambda_param c=default &':' { _Ta3Pegen_name_default_pair(p, a, c, NULL) } lambda_param_maybe_default[NameDefaultPair*]: - | a=lambda_param c=default? ',' { _PyPegen_name_default_pair(p, a, c, NULL) } - | a=lambda_param c=default? &':' { _PyPegen_name_default_pair(p, a, c, NULL) } -lambda_param[arg_ty]: a=NAME { _Py_arg(a->v.Name.id, NULL, NULL, EXTRA) } + | a=lambda_param c=default? ',' { _Ta3Pegen_name_default_pair(p, a, c, NULL) } + | a=lambda_param c=default? &':' { _Ta3Pegen_name_default_pair(p, a, c, NULL) } +lambda_param[arg_ty]: a=NAME { _Ta3_arg(a->v.Name.id, NULL, NULL, EXTRA) } disjunction[expr_ty] (memo): - | a=conjunction b=('or' c=conjunction { c })+ { _Py_BoolOp( + | a=conjunction b=('or' c=conjunction { c })+ { _Ta3_BoolOp( Or, - CHECK(_PyPegen_seq_insert_in_front(p, a, b)), + CHECK(_Ta3Pegen_seq_insert_in_front(p, a, b)), EXTRA) } | conjunction conjunction[expr_ty] (memo): - | a=inversion b=('and' c=inversion { c })+ { _Py_BoolOp( + | a=inversion b=('and' c=inversion { c })+ { _Ta3_BoolOp( And, - CHECK(_PyPegen_seq_insert_in_front(p, a, b)), + CHECK(_Ta3Pegen_seq_insert_in_front(p, a, b)), EXTRA) } | inversion inversion[expr_ty] (memo): - | 'not' a=inversion { _Py_UnaryOp(Not, a, EXTRA) } + | 'not' a=inversion { _Ta3_UnaryOp(Not, a, EXTRA) } | comparison comparison[expr_ty]: | a=bitwise_or b=compare_op_bitwise_or_pair+ { - _Py_Compare(a, CHECK(_PyPegen_get_cmpops(p, b)), CHECK(_PyPegen_get_exprs(p, b)), EXTRA) } + _Ta3_Compare(a, CHECK(_Ta3Pegen_get_cmpops(p, b)), CHECK(_Ta3Pegen_get_exprs(p, b)), EXTRA) } | bitwise_or compare_op_bitwise_or_pair[CmpopExprPair*]: | eq_bitwise_or @@ -402,218 +402,218 @@ compare_op_bitwise_or_pair[CmpopExprPair*]: | in_bitwise_or | isnot_bitwise_or | is_bitwise_or -eq_bitwise_or[CmpopExprPair*]: '==' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, Eq, a) } +eq_bitwise_or[CmpopExprPair*]: '==' a=bitwise_or { _Ta3Pegen_cmpop_expr_pair(p, Eq, a) } noteq_bitwise_or[CmpopExprPair*]: - | (tok='!=' {_PyPegen_check_barry_as_flufl(p) ? NULL : tok}) a=bitwise_or {_PyPegen_cmpop_expr_pair(p, NotEq, a) } -lte_bitwise_or[CmpopExprPair*]: '<=' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, LtE, a) } -lt_bitwise_or[CmpopExprPair*]: '<' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, Lt, a) } -gte_bitwise_or[CmpopExprPair*]: '>=' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, GtE, a) } -gt_bitwise_or[CmpopExprPair*]: '>' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, Gt, a) } -notin_bitwise_or[CmpopExprPair*]: 'not' 'in' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, NotIn, a) } -in_bitwise_or[CmpopExprPair*]: 'in' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, In, a) } -isnot_bitwise_or[CmpopExprPair*]: 'is' 'not' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, IsNot, a) } -is_bitwise_or[CmpopExprPair*]: 'is' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, Is, a) } + | (tok='!=' {_Ta3Pegen_check_barry_as_flufl(p) ? NULL : tok}) a=bitwise_or {_Ta3Pegen_cmpop_expr_pair(p, NotEq, a) } +lte_bitwise_or[CmpopExprPair*]: '<=' a=bitwise_or { _Ta3Pegen_cmpop_expr_pair(p, LtE, a) } +lt_bitwise_or[CmpopExprPair*]: '<' a=bitwise_or { _Ta3Pegen_cmpop_expr_pair(p, Lt, a) } +gte_bitwise_or[CmpopExprPair*]: '>=' a=bitwise_or { _Ta3Pegen_cmpop_expr_pair(p, GtE, a) } +gt_bitwise_or[CmpopExprPair*]: '>' a=bitwise_or { _Ta3Pegen_cmpop_expr_pair(p, Gt, a) } +notin_bitwise_or[CmpopExprPair*]: 'not' 'in' a=bitwise_or { _Ta3Pegen_cmpop_expr_pair(p, NotIn, a) } +in_bitwise_or[CmpopExprPair*]: 'in' a=bitwise_or { _Ta3Pegen_cmpop_expr_pair(p, In, a) } +isnot_bitwise_or[CmpopExprPair*]: 'is' 'not' a=bitwise_or { _Ta3Pegen_cmpop_expr_pair(p, IsNot, a) } +is_bitwise_or[CmpopExprPair*]: 'is' a=bitwise_or { _Ta3Pegen_cmpop_expr_pair(p, Is, a) } bitwise_or[expr_ty]: - | a=bitwise_or '|' b=bitwise_xor { _Py_BinOp(a, BitOr, b, EXTRA) } + | a=bitwise_or '|' b=bitwise_xor { _Ta3_BinOp(a, BitOr, b, EXTRA) } | bitwise_xor bitwise_xor[expr_ty]: - | a=bitwise_xor '^' b=bitwise_and { _Py_BinOp(a, BitXor, b, EXTRA) } + | a=bitwise_xor '^' b=bitwise_and { _Ta3_BinOp(a, BitXor, b, EXTRA) } | bitwise_and bitwise_and[expr_ty]: - | a=bitwise_and '&' b=shift_expr { _Py_BinOp(a, BitAnd, b, EXTRA) } + | a=bitwise_and '&' b=shift_expr { _Ta3_BinOp(a, BitAnd, b, EXTRA) } | shift_expr shift_expr[expr_ty]: - | a=shift_expr '<<' b=sum { _Py_BinOp(a, LShift, b, EXTRA) } - | a=shift_expr '>>' b=sum { _Py_BinOp(a, RShift, b, EXTRA) } + | a=shift_expr '<<' b=sum { _Ta3_BinOp(a, LShift, b, EXTRA) } + | a=shift_expr '>>' b=sum { _Ta3_BinOp(a, RShift, b, EXTRA) } | sum sum[expr_ty]: - | a=sum '+' b=term { _Py_BinOp(a, Add, b, EXTRA) } - | a=sum '-' b=term { _Py_BinOp(a, Sub, b, EXTRA) } + | a=sum '+' b=term { _Ta3_BinOp(a, Add, b, EXTRA) } + | a=sum '-' b=term { _Ta3_BinOp(a, Sub, b, EXTRA) } | term term[expr_ty]: - | a=term '*' b=factor { _Py_BinOp(a, Mult, b, EXTRA) } - | a=term '/' b=factor { _Py_BinOp(a, Div, b, EXTRA) } - | a=term '//' b=factor { _Py_BinOp(a, FloorDiv, b, EXTRA) } - | a=term '%' b=factor { _Py_BinOp(a, Mod, b, EXTRA) } - | a=term '@' b=factor { CHECK_VERSION(5, "The '@' operator is", _Py_BinOp(a, MatMult, b, EXTRA)) } + | a=term '*' b=factor { _Ta3_BinOp(a, Mult, b, EXTRA) } + | a=term '/' b=factor { _Ta3_BinOp(a, Div, b, EXTRA) } + | a=term '//' b=factor { _Ta3_BinOp(a, FloorDiv, b, EXTRA) } + | a=term '%' b=factor { _Ta3_BinOp(a, Mod, b, EXTRA) } + | a=term '@' b=factor { CHECK_VERSION(5, "The '@' operator is", _Ta3_BinOp(a, MatMult, b, EXTRA)) } | factor factor[expr_ty] (memo): - | '+' a=factor { _Py_UnaryOp(UAdd, a, EXTRA) } - | '-' a=factor { _Py_UnaryOp(USub, a, EXTRA) } - | '~' a=factor { _Py_UnaryOp(Invert, a, EXTRA) } + | '+' a=factor { _Ta3_UnaryOp(UAdd, a, EXTRA) } + | '-' a=factor { _Ta3_UnaryOp(USub, a, EXTRA) } + | '~' a=factor { _Ta3_UnaryOp(Invert, a, EXTRA) } | power power[expr_ty]: - | a=await_primary '**' b=factor { _Py_BinOp(a, Pow, b, EXTRA) } + | a=await_primary '**' b=factor { _Ta3_BinOp(a, Pow, b, EXTRA) } | await_primary await_primary[expr_ty] (memo): - | AWAIT a=primary { CHECK_VERSION(5, "Await expressions are", _Py_Await(a, EXTRA)) } + | AWAIT a=primary { CHECK_VERSION(5, "Await expressions are", _Ta3_Await(a, EXTRA)) } | primary primary[expr_ty]: - | a=primary '.' b=NAME { _Py_Attribute(a, b->v.Name.id, Load, EXTRA) } - | a=primary b=genexp { _Py_Call(a, CHECK(_PyPegen_singleton_seq(p, b)), NULL, EXTRA) } + | a=primary '.' b=NAME { _Ta3_Attribute(a, b->v.Name.id, Load, EXTRA) } + | a=primary b=genexp { _Ta3_Call(a, CHECK(_Ta3Pegen_singleton_seq(p, b)), NULL, EXTRA) } | a=primary '(' b=[arguments] ')' { - _Py_Call(a, + _Ta3_Call(a, (b) ? ((expr_ty) b)->v.Call.args : NULL, (b) ? ((expr_ty) b)->v.Call.keywords : NULL, EXTRA) } - | a=primary '[' b=slices ']' { _Py_Subscript(a, b, Load, EXTRA) } + | a=primary '[' b=slices ']' { _Ta3_Subscript(a, b, Load, EXTRA) } | atom slices[expr_ty]: | a=slice !',' { a } - | a=','.slice+ [','] { _Py_Tuple(a, Load, EXTRA) } + | a=','.slice+ [','] { _Ta3_Tuple(a, Load, EXTRA) } slice[expr_ty]: - | a=[expression] ':' b=[expression] c=[':' d=[expression] { d }] { _Py_Slice(a, b, c, EXTRA) } + | a=[expression] ':' b=[expression] c=[':' d=[expression] { d }] { _Ta3_Slice(a, b, c, EXTRA) } | a=expression { a } atom[expr_ty]: | NAME - | 'True' { _Py_Constant(Py_True, NULL, EXTRA) } - | 'False' { _Py_Constant(Py_False, NULL, EXTRA) } - | 'None' { _Py_Constant(Py_None, NULL, EXTRA) } + | 'True' { _Ta3_Constant(Py_True, NULL, EXTRA) } + | 'False' { _Ta3_Constant(Py_False, NULL, EXTRA) } + | 'None' { _Ta3_Constant(Py_None, NULL, EXTRA) } | '__new_parser__' { RAISE_SYNTAX_ERROR("You found it!") } | &STRING strings | NUMBER | &'(' (tuple | group | genexp) | &'[' (list | listcomp) | &'{' (dict | set | dictcomp | setcomp) - | '...' { _Py_Constant(Py_Ellipsis, NULL, EXTRA) } + | '...' { _Ta3_Constant(Py_Ellipsis, NULL, EXTRA) } -strings[expr_ty] (memo): a=STRING+ { _PyPegen_concatenate_strings(p, a) } +strings[expr_ty] (memo): a=STRING+ { _Ta3Pegen_concatenate_strings(p, a) } list[expr_ty]: - | '[' a=[star_named_expressions] ']' { _Py_List(a, Load, EXTRA) } + | '[' a=[star_named_expressions] ']' { _Ta3_List(a, Load, EXTRA) } listcomp[expr_ty]: - | '[' a=named_expression b=for_if_clauses ']' { _Py_ListComp(a, b, EXTRA) } + | '[' a=named_expression b=for_if_clauses ']' { _Ta3_ListComp(a, b, EXTRA) } | invalid_comprehension tuple[expr_ty]: - | '(' a=[y=star_named_expression ',' z=[star_named_expressions] { _PyPegen_seq_insert_in_front(p, y, z) } ] ')' { - _Py_Tuple(a, Load, EXTRA) } + | '(' a=[y=star_named_expression ',' z=[star_named_expressions] { _Ta3Pegen_seq_insert_in_front(p, y, z) } ] ')' { + _Ta3_Tuple(a, Load, EXTRA) } group[expr_ty]: '(' a=(yield_expr | named_expression) ')' { a } genexp[expr_ty]: - | '(' a=expression b=for_if_clauses ')' { _Py_GeneratorExp(a, b, EXTRA) } + | '(' a=expression b=for_if_clauses ')' { _Ta3_GeneratorExp(a, b, EXTRA) } | invalid_comprehension -set[expr_ty]: '{' a=expressions_list '}' { _Py_Set(a, EXTRA) } +set[expr_ty]: '{' a=expressions_list '}' { _Ta3_Set(a, EXTRA) } setcomp[expr_ty]: - | '{' a=expression b=for_if_clauses '}' { _Py_SetComp(a, b, EXTRA) } + | '{' a=expression b=for_if_clauses '}' { _Ta3_SetComp(a, b, EXTRA) } | invalid_comprehension dict[expr_ty]: - | '{' a=[kvpairs] '}' { _Py_Dict(CHECK(_PyPegen_get_keys(p, a)), - CHECK(_PyPegen_get_values(p, a)), EXTRA) } + | '{' a=[kvpairs] '}' { _Ta3_Dict(CHECK(_Ta3Pegen_get_keys(p, a)), + CHECK(_Ta3Pegen_get_values(p, a)), EXTRA) } dictcomp[expr_ty]: - | '{' a=kvpair b=for_if_clauses '}' { _Py_DictComp(a->key, a->value, b, EXTRA) } + | '{' a=kvpair b=for_if_clauses '}' { _Ta3_DictComp(a->key, a->value, b, EXTRA) } kvpairs[asdl_seq*]: a=','.kvpair+ [','] { a } kvpair[KeyValuePair*]: - | '**' a=bitwise_or { _PyPegen_key_value_pair(p, NULL, a) } - | a=expression ':' b=expression { _PyPegen_key_value_pair(p, a, b) } + | '**' a=bitwise_or { _Ta3Pegen_key_value_pair(p, NULL, a) } + | a=expression ':' b=expression { _Ta3Pegen_key_value_pair(p, a, b) } for_if_clauses[asdl_seq*]: | for_if_clause+ for_if_clause[comprehension_ty]: | ASYNC 'for' a=star_targets 'in' b=disjunction c=('if' z=disjunction { z })* { - CHECK_VERSION(6, "Async comprehensions are", _Py_comprehension(a, b, c, 1, p->arena)) } + CHECK_VERSION(6, "Async comprehensions are", _Ta3_comprehension(a, b, c, 1, p->arena)) } | 'for' a=star_targets 'in' b=disjunction c=('if' z=disjunction { z })* { - _Py_comprehension(a, b, c, 0, p->arena) } + _Ta3_comprehension(a, b, c, 0, p->arena) } yield_expr[expr_ty]: - | 'yield' 'from' a=expression { _Py_YieldFrom(a, EXTRA) } - | 'yield' a=[star_expressions] { _Py_Yield(a, EXTRA) } + | 'yield' 'from' a=expression { _Ta3_YieldFrom(a, EXTRA) } + | 'yield' a=[star_expressions] { _Ta3_Yield(a, EXTRA) } arguments[expr_ty] (memo): | a=args [','] &')' { a } | incorrect_arguments args[expr_ty]: | a=starred_expression b=[',' c=args { c }] { - _Py_Call(_PyPegen_dummy_name(p), - (b) ? CHECK(_PyPegen_seq_insert_in_front(p, a, ((expr_ty) b)->v.Call.args)) - : CHECK(_PyPegen_singleton_seq(p, a)), + _Ta3_Call(_Ta3Pegen_dummy_name(p), + (b) ? CHECK(_Ta3Pegen_seq_insert_in_front(p, a, ((expr_ty) b)->v.Call.args)) + : CHECK(_Ta3Pegen_singleton_seq(p, a)), (b) ? ((expr_ty) b)->v.Call.keywords : NULL, EXTRA) } - | a=kwargs { _Py_Call(_PyPegen_dummy_name(p), - CHECK_NULL_ALLOWED(_PyPegen_seq_extract_starred_exprs(p, a)), - CHECK_NULL_ALLOWED(_PyPegen_seq_delete_starred_exprs(p, a)), + | a=kwargs { _Ta3_Call(_Ta3Pegen_dummy_name(p), + CHECK_NULL_ALLOWED(_Ta3Pegen_seq_extract_starred_exprs(p, a)), + CHECK_NULL_ALLOWED(_Ta3Pegen_seq_delete_starred_exprs(p, a)), EXTRA) } | a=named_expression b=[',' c=args { c }] { - _Py_Call(_PyPegen_dummy_name(p), - (b) ? CHECK(_PyPegen_seq_insert_in_front(p, a, ((expr_ty) b)->v.Call.args)) - : CHECK(_PyPegen_singleton_seq(p, a)), + _Ta3_Call(_Ta3Pegen_dummy_name(p), + (b) ? CHECK(_Ta3Pegen_seq_insert_in_front(p, a, ((expr_ty) b)->v.Call.args)) + : CHECK(_Ta3Pegen_singleton_seq(p, a)), (b) ? ((expr_ty) b)->v.Call.keywords : NULL, EXTRA) } kwargs[asdl_seq*]: - | a=','.kwarg_or_starred+ ',' b=','.kwarg_or_double_starred+ { _PyPegen_join_sequences(p, a, b) } + | a=','.kwarg_or_starred+ ',' b=','.kwarg_or_double_starred+ { _Ta3Pegen_join_sequences(p, a, b) } | ','.kwarg_or_starred+ | ','.kwarg_or_double_starred+ starred_expression[expr_ty]: - | '*' a=expression { _Py_Starred(a, Load, EXTRA) } + | '*' a=expression { _Ta3_Starred(a, Load, EXTRA) } kwarg_or_starred[KeywordOrStarred*]: | a=NAME '=' b=expression { - _PyPegen_keyword_or_starred(p, CHECK(_Py_keyword(a->v.Name.id, b, EXTRA)), 1) } - | a=starred_expression { _PyPegen_keyword_or_starred(p, a, 0) } + _Ta3Pegen_keyword_or_starred(p, CHECK(_Ta3_keyword(a->v.Name.id, b, EXTRA)), 1) } + | a=starred_expression { _Ta3Pegen_keyword_or_starred(p, a, 0) } | invalid_kwarg kwarg_or_double_starred[KeywordOrStarred*]: | a=NAME '=' b=expression { - _PyPegen_keyword_or_starred(p, CHECK(_Py_keyword(a->v.Name.id, b, EXTRA)), 1) } - | '**' a=expression { _PyPegen_keyword_or_starred(p, CHECK(_Py_keyword(NULL, a, EXTRA)), 1) } + _Ta3Pegen_keyword_or_starred(p, CHECK(_Ta3_keyword(a->v.Name.id, b, EXTRA)), 1) } + | '**' a=expression { _Ta3Pegen_keyword_or_starred(p, CHECK(_Ta3_keyword(NULL, a, EXTRA)), 1) } | invalid_kwarg # NOTE: star_targets may contain *bitwise_or, targets may not. star_targets[expr_ty]: | a=star_target !',' { a } | a=star_target b=(',' c=star_target { c })* [','] { - _Py_Tuple(CHECK(_PyPegen_seq_insert_in_front(p, a, b)), Store, EXTRA) } + _Ta3_Tuple(CHECK(_Ta3Pegen_seq_insert_in_front(p, a, b)), Store, EXTRA) } star_targets_seq[asdl_seq*]: a=','.star_target+ [','] { a } star_target[expr_ty] (memo): | '*' a=(!'*' star_target) { - _Py_Starred(CHECK(_PyPegen_set_expr_context(p, a, Store)), Store, EXTRA) } - | a=t_primary '.' b=NAME !t_lookahead { _Py_Attribute(a, b->v.Name.id, Store, EXTRA) } - | a=t_primary '[' b=slices ']' !t_lookahead { _Py_Subscript(a, b, Store, EXTRA) } + _Ta3_Starred(CHECK(_Ta3Pegen_set_expr_context(p, a, Store)), Store, EXTRA) } + | a=t_primary '.' b=NAME !t_lookahead { _Ta3_Attribute(a, b->v.Name.id, Store, EXTRA) } + | a=t_primary '[' b=slices ']' !t_lookahead { _Ta3_Subscript(a, b, Store, EXTRA) } | star_atom star_atom[expr_ty]: - | a=NAME { _PyPegen_set_expr_context(p, a, Store) } - | '(' a=star_target ')' { _PyPegen_set_expr_context(p, a, Store) } - | '(' a=[star_targets_seq] ')' { _Py_Tuple(a, Store, EXTRA) } - | '[' a=[star_targets_seq] ']' { _Py_List(a, Store, EXTRA) } + | a=NAME { _Ta3Pegen_set_expr_context(p, a, Store) } + | '(' a=star_target ')' { _Ta3Pegen_set_expr_context(p, a, Store) } + | '(' a=[star_targets_seq] ')' { _Ta3_Tuple(a, Store, EXTRA) } + | '[' a=[star_targets_seq] ']' { _Ta3_List(a, Store, EXTRA) } inside_paren_ann_assign_target[expr_ty]: | ann_assign_subscript_attribute_target - | a=NAME { _PyPegen_set_expr_context(p, a, Store) } + | a=NAME { _Ta3Pegen_set_expr_context(p, a, Store) } | '(' a=inside_paren_ann_assign_target ')' { a } ann_assign_subscript_attribute_target[expr_ty]: - | a=t_primary '.' b=NAME !t_lookahead { _Py_Attribute(a, b->v.Name.id, Store, EXTRA) } - | a=t_primary '[' b=slices ']' !t_lookahead { _Py_Subscript(a, b, Store, EXTRA) } + | a=t_primary '.' b=NAME !t_lookahead { _Ta3_Attribute(a, b->v.Name.id, Store, EXTRA) } + | a=t_primary '[' b=slices ']' !t_lookahead { _Ta3_Subscript(a, b, Store, EXTRA) } del_targets[asdl_seq*]: a=','.del_target+ [','] { a } del_target[expr_ty] (memo): - | a=t_primary '.' b=NAME !t_lookahead { _Py_Attribute(a, b->v.Name.id, Del, EXTRA) } - | a=t_primary '[' b=slices ']' !t_lookahead { _Py_Subscript(a, b, Del, EXTRA) } + | a=t_primary '.' b=NAME !t_lookahead { _Ta3_Attribute(a, b->v.Name.id, Del, EXTRA) } + | a=t_primary '[' b=slices ']' !t_lookahead { _Ta3_Subscript(a, b, Del, EXTRA) } | del_t_atom del_t_atom[expr_ty]: - | a=NAME { _PyPegen_set_expr_context(p, a, Del) } - | '(' a=del_target ')' { _PyPegen_set_expr_context(p, a, Del) } - | '(' a=[del_targets] ')' { _Py_Tuple(a, Del, EXTRA) } - | '[' a=[del_targets] ']' { _Py_List(a, Del, EXTRA) } + | a=NAME { _Ta3Pegen_set_expr_context(p, a, Del) } + | '(' a=del_target ')' { _Ta3Pegen_set_expr_context(p, a, Del) } + | '(' a=[del_targets] ')' { _Ta3_Tuple(a, Del, EXTRA) } + | '[' a=[del_targets] ']' { _Ta3_List(a, Del, EXTRA) } targets[asdl_seq*]: a=','.target+ [','] { a } target[expr_ty] (memo): - | a=t_primary '.' b=NAME !t_lookahead { _Py_Attribute(a, b->v.Name.id, Store, EXTRA) } - | a=t_primary '[' b=slices ']' !t_lookahead { _Py_Subscript(a, b, Store, EXTRA) } + | a=t_primary '.' b=NAME !t_lookahead { _Ta3_Attribute(a, b->v.Name.id, Store, EXTRA) } + | a=t_primary '[' b=slices ']' !t_lookahead { _Ta3_Subscript(a, b, Store, EXTRA) } | t_atom t_primary[expr_ty]: - | a=t_primary '.' b=NAME &t_lookahead { _Py_Attribute(a, b->v.Name.id, Load, EXTRA) } - | a=t_primary '[' b=slices ']' &t_lookahead { _Py_Subscript(a, b, Load, EXTRA) } - | a=t_primary b=genexp &t_lookahead { _Py_Call(a, CHECK(_PyPegen_singleton_seq(p, b)), NULL, EXTRA) } + | a=t_primary '.' b=NAME &t_lookahead { _Ta3_Attribute(a, b->v.Name.id, Load, EXTRA) } + | a=t_primary '[' b=slices ']' &t_lookahead { _Ta3_Subscript(a, b, Load, EXTRA) } + | a=t_primary b=genexp &t_lookahead { _Ta3_Call(a, CHECK(_Ta3Pegen_singleton_seq(p, b)), NULL, EXTRA) } | a=t_primary '(' b=[arguments] ')' &t_lookahead { - _Py_Call(a, + _Ta3_Call(a, (b) ? ((expr_ty) b)->v.Call.args : NULL, (b) ? ((expr_ty) b)->v.Call.keywords : NULL, EXTRA) } | a=atom &t_lookahead { a } t_lookahead: '(' | '[' | '.' t_atom[expr_ty]: - | a=NAME { _PyPegen_set_expr_context(p, a, Store) } - | '(' a=target ')' { _PyPegen_set_expr_context(p, a, Store) } - | '(' b=[targets] ')' { _Py_Tuple(b, Store, EXTRA) } - | '[' b=[targets] ']' { _Py_List(b, Store, EXTRA) } + | a=NAME { _Ta3Pegen_set_expr_context(p, a, Store) } + | '(' a=target ')' { _Ta3Pegen_set_expr_context(p, a, Store) } + | '(' b=[targets] ')' { _Ta3_Tuple(b, Store, EXTRA) } + | '[' b=[targets] ']' { _Ta3_List(b, Store, EXTRA) } # From here on, there are rules for invalid syntax with specialised error messages @@ -621,19 +621,19 @@ incorrect_arguments: | args ',' '*' { RAISE_SYNTAX_ERROR("iterable argument unpacking follows keyword argument unpacking") } | expression for_if_clauses ',' [args | expression for_if_clauses] { RAISE_SYNTAX_ERROR("Generator expression must be parenthesized") } - | a=args ',' args { _PyPegen_arguments_parsing_error(p, a) } + | a=args ',' args { _Ta3Pegen_arguments_parsing_error(p, a) } invalid_kwarg: | expression '=' { RAISE_SYNTAX_ERROR("expression cannot contain assignment, perhaps you meant \"==\"?") } invalid_named_expression: | a=expression ':=' expression { - RAISE_SYNTAX_ERROR("cannot use assignment expressions with %s", _PyPegen_get_expr_name(a)) } + RAISE_SYNTAX_ERROR("cannot use assignment expressions with %s", _Ta3Pegen_get_expr_name(a)) } invalid_assignment: | list ':' { RAISE_SYNTAX_ERROR("only single target (not list) can be annotated") } | tuple ':' { RAISE_SYNTAX_ERROR("only single target (not tuple) can be annotated") } | expression ':' expression ['=' annotated_rhs] { RAISE_SYNTAX_ERROR("illegal target for annotation") } | a=expression ('=' | augassign) (yield_expr | star_expressions) { - RAISE_SYNTAX_ERROR_NO_COL_OFFSET("cannot assign to %s", _PyPegen_get_expr_name(a)) } + RAISE_SYNTAX_ERROR_NO_COL_OFFSET("cannot assign to %s", _Ta3Pegen_get_expr_name(a)) } invalid_block: | NEWLINE !INDENT { RAISE_INDENTATION_ERROR("expected an indented block") } invalid_comprehension: diff --git a/ast3/Include/Python-ast.h b/ast3/Include/Python-ast.h index 23effd5c..55491bce 100644 --- a/ast3/Include/Python-ast.h +++ b/ast3/Include/Python-ast.h @@ -8,7 +8,7 @@ extern "C" { #ifndef Py_LIMITED_API #include "asdl.h" - +#include "../Include/ta3_compat.h" #undef Yield /* undefine macro conflicting with */ typedef struct _mod *mod_ty; @@ -457,238 +457,241 @@ struct _type_ignore { // Note: these macros affect function definitions, not only call sites. -#define Module(a0, a1, a2) _Py_Module(a0, a1, a2) -mod_ty _Py_Module(asdl_seq * body, asdl_seq * type_ignores, PyArena *arena); -#define Interactive(a0, a1) _Py_Interactive(a0, a1) -mod_ty _Py_Interactive(asdl_seq * body, PyArena *arena); -#define Expression(a0, a1) _Py_Expression(a0, a1) -mod_ty _Py_Expression(expr_ty body, PyArena *arena); -#define FunctionType(a0, a1, a2) _Py_FunctionType(a0, a1, a2) -mod_ty _Py_FunctionType(asdl_seq * argtypes, expr_ty returns, PyArena *arena); -#define FunctionDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) _Py_FunctionDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) -stmt_ty _Py_FunctionDef(identifier name, arguments_ty args, asdl_seq * body, - asdl_seq * decorator_list, expr_ty returns, string - type_comment, int lineno, int col_offset, int - end_lineno, int end_col_offset, PyArena *arena); -#define AsyncFunctionDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) _Py_AsyncFunctionDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) -stmt_ty _Py_AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * - body, asdl_seq * decorator_list, expr_ty returns, - string type_comment, int lineno, int col_offset, - int end_lineno, int end_col_offset, PyArena - *arena); -#define ClassDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) _Py_ClassDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) -stmt_ty _Py_ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, - asdl_seq * body, asdl_seq * decorator_list, int lineno, - int col_offset, int end_lineno, int end_col_offset, - PyArena *arena); -#define Return(a0, a1, a2, a3, a4, a5) _Py_Return(a0, a1, a2, a3, a4, a5) -stmt_ty _Py_Return(expr_ty value, int lineno, int col_offset, int end_lineno, - int end_col_offset, PyArena *arena); -#define Delete(a0, a1, a2, a3, a4, a5) _Py_Delete(a0, a1, a2, a3, a4, a5) -stmt_ty _Py_Delete(asdl_seq * targets, int lineno, int col_offset, int - end_lineno, int end_col_offset, PyArena *arena); -#define Assign(a0, a1, a2, a3, a4, a5, a6, a7) _Py_Assign(a0, a1, a2, a3, a4, a5, a6, a7) -stmt_ty _Py_Assign(asdl_seq * targets, expr_ty value, string type_comment, int +#define Module(a0, a1, a2) _Ta3_Module(a0, a1, a2) +mod_ty _Ta3_Module(asdl_seq * body, asdl_seq * type_ignores, PyArena *arena); +#define Interactive(a0, a1) _Ta3_Interactive(a0, a1) +mod_ty _Ta3_Interactive(asdl_seq * body, PyArena *arena); +#define Expression(a0, a1) _Ta3_Expression(a0, a1) +mod_ty _Ta3_Expression(expr_ty body, PyArena *arena); +#define FunctionType(a0, a1, a2) _Ta3_FunctionType(a0, a1, a2) +mod_ty _Ta3_FunctionType(asdl_seq * argtypes, expr_ty returns, PyArena *arena); +#define FunctionDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) _Ta3_FunctionDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) +stmt_ty _Ta3_FunctionDef(identifier name, arguments_ty args, asdl_seq * body, + asdl_seq * decorator_list, expr_ty returns, string + type_comment, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena *arena); +#define AsyncFunctionDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) _Ta3_AsyncFunctionDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) +stmt_ty _Ta3_AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * + body, asdl_seq * decorator_list, expr_ty returns, + string type_comment, int lineno, int col_offset, + int end_lineno, int end_col_offset, PyArena + *arena); +#define ClassDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) _Ta3_ClassDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) +stmt_ty _Ta3_ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, + asdl_seq * body, asdl_seq * decorator_list, int lineno, + int col_offset, int end_lineno, int end_col_offset, + PyArena *arena); +#define Return(a0, a1, a2, a3, a4, a5) _Ta3_Return(a0, a1, a2, a3, a4, a5) +stmt_ty _Ta3_Return(expr_ty value, int lineno, int col_offset, int end_lineno, + int end_col_offset, PyArena *arena); +#define Delete(a0, a1, a2, a3, a4, a5) _Ta3_Delete(a0, a1, a2, a3, a4, a5) +stmt_ty _Ta3_Delete(asdl_seq * targets, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena *arena); +#define Assign(a0, a1, a2, a3, a4, a5, a6, a7) _Ta3_Assign(a0, a1, a2, a3, a4, a5, a6, a7) +stmt_ty _Ta3_Assign(asdl_seq * targets, expr_ty value, string type_comment, int + lineno, int col_offset, int end_lineno, int end_col_offset, + PyArena *arena); +#define AugAssign(a0, a1, a2, a3, a4, a5, a6, a7) _Ta3_AugAssign(a0, a1, a2, a3, a4, a5, a6, a7) +stmt_ty _Ta3_AugAssign(expr_ty target, operator_ty op, expr_ty value, int + lineno, int col_offset, int end_lineno, int + end_col_offset, PyArena *arena); +#define AnnAssign(a0, a1, a2, a3, a4, a5, a6, a7, a8) _Ta3_AnnAssign(a0, a1, a2, a3, a4, a5, a6, a7, a8) +stmt_ty _Ta3_AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int + simple, int lineno, int col_offset, int end_lineno, int + end_col_offset, PyArena *arena); +#define For(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) _Ta3_For(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) +stmt_ty _Ta3_For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * + orelse, string type_comment, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena *arena); +#define AsyncFor(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) _Ta3_AsyncFor(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) +stmt_ty _Ta3_AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * + orelse, string type_comment, int lineno, int col_offset, + int end_lineno, int end_col_offset, PyArena *arena); +#define While(a0, a1, a2, a3, a4, a5, a6, a7) _Ta3_While(a0, a1, a2, a3, a4, a5, a6, a7) +stmt_ty _Ta3_While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena *arena); -#define AugAssign(a0, a1, a2, a3, a4, a5, a6, a7) _Py_AugAssign(a0, a1, a2, a3, a4, a5, a6, a7) -stmt_ty _Py_AugAssign(expr_ty target, operator_ty op, expr_ty value, int - lineno, int col_offset, int end_lineno, int - end_col_offset, PyArena *arena); -#define AnnAssign(a0, a1, a2, a3, a4, a5, a6, a7, a8) _Py_AnnAssign(a0, a1, a2, a3, a4, a5, a6, a7, a8) -stmt_ty _Py_AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int - simple, int lineno, int col_offset, int end_lineno, int - end_col_offset, PyArena *arena); -#define For(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) _Py_For(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) -stmt_ty _Py_For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * - orelse, string type_comment, int lineno, int col_offset, int - end_lineno, int end_col_offset, PyArena *arena); -#define AsyncFor(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) _Py_AsyncFor(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) -stmt_ty _Py_AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * - orelse, string type_comment, int lineno, int col_offset, - int end_lineno, int end_col_offset, PyArena *arena); -#define While(a0, a1, a2, a3, a4, a5, a6, a7) _Py_While(a0, a1, a2, a3, a4, a5, a6, a7) -stmt_ty _Py_While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, - int col_offset, int end_lineno, int end_col_offset, PyArena - *arena); -#define If(a0, a1, a2, a3, a4, a5, a6, a7) _Py_If(a0, a1, a2, a3, a4, a5, a6, a7) -stmt_ty _Py_If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, - int col_offset, int end_lineno, int end_col_offset, PyArena - *arena); -#define With(a0, a1, a2, a3, a4, a5, a6, a7) _Py_With(a0, a1, a2, a3, a4, a5, a6, a7) -stmt_ty _Py_With(asdl_seq * items, asdl_seq * body, string type_comment, int - lineno, int col_offset, int end_lineno, int end_col_offset, - PyArena *arena); -#define AsyncWith(a0, a1, a2, a3, a4, a5, a6, a7) _Py_AsyncWith(a0, a1, a2, a3, a4, a5, a6, a7) -stmt_ty _Py_AsyncWith(asdl_seq * items, asdl_seq * body, string type_comment, - int lineno, int col_offset, int end_lineno, int - end_col_offset, PyArena *arena); -#define Raise(a0, a1, a2, a3, a4, a5, a6) _Py_Raise(a0, a1, a2, a3, a4, a5, a6) -stmt_ty _Py_Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int - end_lineno, int end_col_offset, PyArena *arena); -#define Try(a0, a1, a2, a3, a4, a5, a6, a7, a8) _Py_Try(a0, a1, a2, a3, a4, a5, a6, a7, a8) -stmt_ty _Py_Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, - asdl_seq * finalbody, int lineno, int col_offset, int - end_lineno, int end_col_offset, PyArena *arena); -#define Assert(a0, a1, a2, a3, a4, a5, a6) _Py_Assert(a0, a1, a2, a3, a4, a5, a6) -stmt_ty _Py_Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int - end_lineno, int end_col_offset, PyArena *arena); -#define Import(a0, a1, a2, a3, a4, a5) _Py_Import(a0, a1, a2, a3, a4, a5) -stmt_ty _Py_Import(asdl_seq * names, int lineno, int col_offset, int - end_lineno, int end_col_offset, PyArena *arena); -#define ImportFrom(a0, a1, a2, a3, a4, a5, a6, a7) _Py_ImportFrom(a0, a1, a2, a3, a4, a5, a6, a7) -stmt_ty _Py_ImportFrom(identifier module, asdl_seq * names, int level, int - lineno, int col_offset, int end_lineno, int +#define If(a0, a1, a2, a3, a4, a5, a6, a7) _Ta3_If(a0, a1, a2, a3, a4, a5, a6, a7) +stmt_ty _Ta3_If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, + int col_offset, int end_lineno, int end_col_offset, PyArena + *arena); +#define With(a0, a1, a2, a3, a4, a5, a6, a7) _Ta3_With(a0, a1, a2, a3, a4, a5, a6, a7) +stmt_ty _Ta3_With(asdl_seq * items, asdl_seq * body, string type_comment, int + lineno, int col_offset, int end_lineno, int end_col_offset, + PyArena *arena); +#define AsyncWith(a0, a1, a2, a3, a4, a5, a6, a7) _Ta3_AsyncWith(a0, a1, a2, a3, a4, a5, a6, a7) +stmt_ty _Ta3_AsyncWith(asdl_seq * items, asdl_seq * body, string type_comment, + int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena *arena); -#define Global(a0, a1, a2, a3, a4, a5) _Py_Global(a0, a1, a2, a3, a4, a5) -stmt_ty _Py_Global(asdl_seq * names, int lineno, int col_offset, int +#define Raise(a0, a1, a2, a3, a4, a5, a6) _Ta3_Raise(a0, a1, a2, a3, a4, a5, a6) +stmt_ty _Ta3_Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena *arena); -#define Nonlocal(a0, a1, a2, a3, a4, a5) _Py_Nonlocal(a0, a1, a2, a3, a4, a5) -stmt_ty _Py_Nonlocal(asdl_seq * names, int lineno, int col_offset, int - end_lineno, int end_col_offset, PyArena *arena); -#define Expr(a0, a1, a2, a3, a4, a5) _Py_Expr(a0, a1, a2, a3, a4, a5) -stmt_ty _Py_Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int - end_col_offset, PyArena *arena); -#define Pass(a0, a1, a2, a3, a4) _Py_Pass(a0, a1, a2, a3, a4) -stmt_ty _Py_Pass(int lineno, int col_offset, int end_lineno, int - end_col_offset, PyArena *arena); -#define Break(a0, a1, a2, a3, a4) _Py_Break(a0, a1, a2, a3, a4) -stmt_ty _Py_Break(int lineno, int col_offset, int end_lineno, int +#define Try(a0, a1, a2, a3, a4, a5, a6, a7, a8) _Ta3_Try(a0, a1, a2, a3, a4, a5, a6, a7, a8) +stmt_ty _Ta3_Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, + asdl_seq * finalbody, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena *arena); +#define Assert(a0, a1, a2, a3, a4, a5, a6) _Ta3_Assert(a0, a1, a2, a3, a4, a5, a6) +stmt_ty _Ta3_Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena *arena); +#define Import(a0, a1, a2, a3, a4, a5) _Ta3_Import(a0, a1, a2, a3, a4, a5) +stmt_ty _Ta3_Import(asdl_seq * names, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena *arena); +#define ImportFrom(a0, a1, a2, a3, a4, a5, a6, a7) _Ta3_ImportFrom(a0, a1, a2, a3, a4, a5, a6, a7) +stmt_ty _Ta3_ImportFrom(identifier module, asdl_seq * names, int level, int + lineno, int col_offset, int end_lineno, int + end_col_offset, PyArena *arena); +#define Global(a0, a1, a2, a3, a4, a5) _Ta3_Global(a0, a1, a2, a3, a4, a5) +stmt_ty _Ta3_Global(asdl_seq * names, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena *arena); +#define Nonlocal(a0, a1, a2, a3, a4, a5) _Ta3_Nonlocal(a0, a1, a2, a3, a4, a5) +stmt_ty _Ta3_Nonlocal(asdl_seq * names, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena *arena); +#define Expr(a0, a1, a2, a3, a4, a5) _Ta3_Expr(a0, a1, a2, a3, a4, a5) +stmt_ty _Ta3_Expr(expr_ty value, int lineno, int col_offset, int end_lineno, + int end_col_offset, PyArena *arena); +#define Pass(a0, a1, a2, a3, a4) _Ta3_Pass(a0, a1, a2, a3, a4) +stmt_ty _Ta3_Pass(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena *arena); -#define Continue(a0, a1, a2, a3, a4) _Py_Continue(a0, a1, a2, a3, a4) -stmt_ty _Py_Continue(int lineno, int col_offset, int end_lineno, int - end_col_offset, PyArena *arena); -#define BoolOp(a0, a1, a2, a3, a4, a5, a6) _Py_BoolOp(a0, a1, a2, a3, a4, a5, a6) -expr_ty _Py_BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, - int end_lineno, int end_col_offset, PyArena *arena); -#define NamedExpr(a0, a1, a2, a3, a4, a5, a6) _Py_NamedExpr(a0, a1, a2, a3, a4, a5, a6) -expr_ty _Py_NamedExpr(expr_ty target, expr_ty value, int lineno, int - col_offset, int end_lineno, int end_col_offset, PyArena - *arena); -#define BinOp(a0, a1, a2, a3, a4, a5, a6, a7) _Py_BinOp(a0, a1, a2, a3, a4, a5, a6, a7) -expr_ty _Py_BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int - col_offset, int end_lineno, int end_col_offset, PyArena - *arena); -#define UnaryOp(a0, a1, a2, a3, a4, a5, a6) _Py_UnaryOp(a0, a1, a2, a3, a4, a5, a6) -expr_ty _Py_UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, - int end_lineno, int end_col_offset, PyArena *arena); -#define Lambda(a0, a1, a2, a3, a4, a5, a6) _Py_Lambda(a0, a1, a2, a3, a4, a5, a6) -expr_ty _Py_Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, - int end_lineno, int end_col_offset, PyArena *arena); -#define IfExp(a0, a1, a2, a3, a4, a5, a6, a7) _Py_IfExp(a0, a1, a2, a3, a4, a5, a6, a7) -expr_ty _Py_IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int - col_offset, int end_lineno, int end_col_offset, PyArena - *arena); -#define Dict(a0, a1, a2, a3, a4, a5, a6) _Py_Dict(a0, a1, a2, a3, a4, a5, a6) -expr_ty _Py_Dict(asdl_seq * keys, asdl_seq * values, int lineno, int - col_offset, int end_lineno, int end_col_offset, PyArena - *arena); -#define Set(a0, a1, a2, a3, a4, a5) _Py_Set(a0, a1, a2, a3, a4, a5) -expr_ty _Py_Set(asdl_seq * elts, int lineno, int col_offset, int end_lineno, - int end_col_offset, PyArena *arena); -#define ListComp(a0, a1, a2, a3, a4, a5, a6) _Py_ListComp(a0, a1, a2, a3, a4, a5, a6) -expr_ty _Py_ListComp(expr_ty elt, asdl_seq * generators, int lineno, int +#define Break(a0, a1, a2, a3, a4) _Ta3_Break(a0, a1, a2, a3, a4) +stmt_ty _Ta3_Break(int lineno, int col_offset, int end_lineno, int + end_col_offset, PyArena *arena); +#define Continue(a0, a1, a2, a3, a4) _Ta3_Continue(a0, a1, a2, a3, a4) +stmt_ty _Ta3_Continue(int lineno, int col_offset, int end_lineno, int + end_col_offset, PyArena *arena); +#define BoolOp(a0, a1, a2, a3, a4, a5, a6) _Ta3_BoolOp(a0, a1, a2, a3, a4, a5, a6) +expr_ty _Ta3_BoolOp(boolop_ty op, asdl_seq * values, int lineno, int + col_offset, int end_lineno, int end_col_offset, PyArena + *arena); +#define NamedExpr(a0, a1, a2, a3, a4, a5, a6) _Ta3_NamedExpr(a0, a1, a2, a3, a4, a5, a6) +expr_ty _Ta3_NamedExpr(expr_ty target, expr_ty value, int lineno, int + col_offset, int end_lineno, int end_col_offset, PyArena + *arena); +#define BinOp(a0, a1, a2, a3, a4, a5, a6, a7) _Ta3_BinOp(a0, a1, a2, a3, a4, a5, a6, a7) +expr_ty _Ta3_BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int + col_offset, int end_lineno, int end_col_offset, PyArena + *arena); +#define UnaryOp(a0, a1, a2, a3, a4, a5, a6) _Ta3_UnaryOp(a0, a1, a2, a3, a4, a5, a6) +expr_ty _Ta3_UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena *arena); -#define SetComp(a0, a1, a2, a3, a4, a5, a6) _Py_SetComp(a0, a1, a2, a3, a4, a5, a6) -expr_ty _Py_SetComp(expr_ty elt, asdl_seq * generators, int lineno, int +#define Lambda(a0, a1, a2, a3, a4, a5, a6) _Ta3_Lambda(a0, a1, a2, a3, a4, a5, a6) +expr_ty _Ta3_Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena *arena); -#define DictComp(a0, a1, a2, a3, a4, a5, a6, a7) _Py_DictComp(a0, a1, a2, a3, a4, a5, a6, a7) -expr_ty _Py_DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int - lineno, int col_offset, int end_lineno, int - end_col_offset, PyArena *arena); -#define GeneratorExp(a0, a1, a2, a3, a4, a5, a6) _Py_GeneratorExp(a0, a1, a2, a3, a4, a5, a6) -expr_ty _Py_GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int - col_offset, int end_lineno, int end_col_offset, - PyArena *arena); -#define Await(a0, a1, a2, a3, a4, a5) _Py_Await(a0, a1, a2, a3, a4, a5) -expr_ty _Py_Await(expr_ty value, int lineno, int col_offset, int end_lineno, - int end_col_offset, PyArena *arena); -#define Yield(a0, a1, a2, a3, a4, a5) _Py_Yield(a0, a1, a2, a3, a4, a5) -expr_ty _Py_Yield(expr_ty value, int lineno, int col_offset, int end_lineno, - int end_col_offset, PyArena *arena); -#define YieldFrom(a0, a1, a2, a3, a4, a5) _Py_YieldFrom(a0, a1, a2, a3, a4, a5) -expr_ty _Py_YieldFrom(expr_ty value, int lineno, int col_offset, int - end_lineno, int end_col_offset, PyArena *arena); -#define Compare(a0, a1, a2, a3, a4, a5, a6, a7) _Py_Compare(a0, a1, a2, a3, a4, a5, a6, a7) -expr_ty _Py_Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, - int lineno, int col_offset, int end_lineno, int - end_col_offset, PyArena *arena); -#define Call(a0, a1, a2, a3, a4, a5, a6, a7) _Py_Call(a0, a1, a2, a3, a4, a5, a6, a7) -expr_ty _Py_Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, int - lineno, int col_offset, int end_lineno, int end_col_offset, - PyArena *arena); -#define FormattedValue(a0, a1, a2, a3, a4, a5, a6, a7) _Py_FormattedValue(a0, a1, a2, a3, a4, a5, a6, a7) -expr_ty _Py_FormattedValue(expr_ty value, int conversion, expr_ty format_spec, - int lineno, int col_offset, int end_lineno, int - end_col_offset, PyArena *arena); -#define JoinedStr(a0, a1, a2, a3, a4, a5) _Py_JoinedStr(a0, a1, a2, a3, a4, a5) -expr_ty _Py_JoinedStr(asdl_seq * values, int lineno, int col_offset, int - end_lineno, int end_col_offset, PyArena *arena); -#define Constant(a0, a1, a2, a3, a4, a5, a6) _Py_Constant(a0, a1, a2, a3, a4, a5, a6) -expr_ty _Py_Constant(constant value, string kind, int lineno, int col_offset, - int end_lineno, int end_col_offset, PyArena *arena); -#define Attribute(a0, a1, a2, a3, a4, a5, a6, a7) _Py_Attribute(a0, a1, a2, a3, a4, a5, a6, a7) -expr_ty _Py_Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int - lineno, int col_offset, int end_lineno, int - end_col_offset, PyArena *arena); -#define Subscript(a0, a1, a2, a3, a4, a5, a6, a7) _Py_Subscript(a0, a1, a2, a3, a4, a5, a6, a7) -expr_ty _Py_Subscript(expr_ty value, expr_ty slice, expr_context_ty ctx, int +#define IfExp(a0, a1, a2, a3, a4, a5, a6, a7) _Ta3_IfExp(a0, a1, a2, a3, a4, a5, a6, a7) +expr_ty _Ta3_IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int + col_offset, int end_lineno, int end_col_offset, PyArena + *arena); +#define Dict(a0, a1, a2, a3, a4, a5, a6) _Ta3_Dict(a0, a1, a2, a3, a4, a5, a6) +expr_ty _Ta3_Dict(asdl_seq * keys, asdl_seq * values, int lineno, int + col_offset, int end_lineno, int end_col_offset, PyArena + *arena); +#define Set(a0, a1, a2, a3, a4, a5) _Ta3_Set(a0, a1, a2, a3, a4, a5) +expr_ty _Ta3_Set(asdl_seq * elts, int lineno, int col_offset, int end_lineno, + int end_col_offset, PyArena *arena); +#define ListComp(a0, a1, a2, a3, a4, a5, a6) _Ta3_ListComp(a0, a1, a2, a3, a4, a5, a6) +expr_ty _Ta3_ListComp(expr_ty elt, asdl_seq * generators, int lineno, int + col_offset, int end_lineno, int end_col_offset, PyArena + *arena); +#define SetComp(a0, a1, a2, a3, a4, a5, a6) _Ta3_SetComp(a0, a1, a2, a3, a4, a5, a6) +expr_ty _Ta3_SetComp(expr_ty elt, asdl_seq * generators, int lineno, int + col_offset, int end_lineno, int end_col_offset, PyArena + *arena); +#define DictComp(a0, a1, a2, a3, a4, a5, a6, a7) _Ta3_DictComp(a0, a1, a2, a3, a4, a5, a6, a7) +expr_ty _Ta3_DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena *arena); -#define Starred(a0, a1, a2, a3, a4, a5, a6) _Py_Starred(a0, a1, a2, a3, a4, a5, a6) -expr_ty _Py_Starred(expr_ty value, expr_context_ty ctx, int lineno, int - col_offset, int end_lineno, int end_col_offset, PyArena - *arena); -#define Name(a0, a1, a2, a3, a4, a5, a6) _Py_Name(a0, a1, a2, a3, a4, a5, a6) -expr_ty _Py_Name(identifier id, expr_context_ty ctx, int lineno, int - col_offset, int end_lineno, int end_col_offset, PyArena - *arena); -#define List(a0, a1, a2, a3, a4, a5, a6) _Py_List(a0, a1, a2, a3, a4, a5, a6) -expr_ty _Py_List(asdl_seq * elts, expr_context_ty ctx, int lineno, int - col_offset, int end_lineno, int end_col_offset, PyArena - *arena); -#define Tuple(a0, a1, a2, a3, a4, a5, a6) _Py_Tuple(a0, a1, a2, a3, a4, a5, a6) -expr_ty _Py_Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int +#define GeneratorExp(a0, a1, a2, a3, a4, a5, a6) _Ta3_GeneratorExp(a0, a1, a2, a3, a4, a5, a6) +expr_ty _Ta3_GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int + col_offset, int end_lineno, int end_col_offset, + PyArena *arena); +#define Await(a0, a1, a2, a3, a4, a5) _Ta3_Await(a0, a1, a2, a3, a4, a5) +expr_ty _Ta3_Await(expr_ty value, int lineno, int col_offset, int end_lineno, + int end_col_offset, PyArena *arena); +#define Yield(a0, a1, a2, a3, a4, a5) _Ta3_Yield(a0, a1, a2, a3, a4, a5) +expr_ty _Ta3_Yield(expr_ty value, int lineno, int col_offset, int end_lineno, + int end_col_offset, PyArena *arena); +#define YieldFrom(a0, a1, a2, a3, a4, a5) _Ta3_YieldFrom(a0, a1, a2, a3, a4, a5) +expr_ty _Ta3_YieldFrom(expr_ty value, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena *arena); +#define Compare(a0, a1, a2, a3, a4, a5, a6, a7) _Ta3_Compare(a0, a1, a2, a3, a4, a5, a6, a7) +expr_ty _Ta3_Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, + int lineno, int col_offset, int end_lineno, int + end_col_offset, PyArena *arena); +#define Call(a0, a1, a2, a3, a4, a5, a6, a7) _Ta3_Call(a0, a1, a2, a3, a4, a5, a6, a7) +expr_ty _Ta3_Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, int + lineno, int col_offset, int end_lineno, int end_col_offset, + PyArena *arena); +#define FormattedValue(a0, a1, a2, a3, a4, a5, a6, a7) _Ta3_FormattedValue(a0, a1, a2, a3, a4, a5, a6, a7) +expr_ty _Ta3_FormattedValue(expr_ty value, int conversion, expr_ty format_spec, + int lineno, int col_offset, int end_lineno, int + end_col_offset, PyArena *arena); +#define JoinedStr(a0, a1, a2, a3, a4, a5) _Ta3_JoinedStr(a0, a1, a2, a3, a4, a5) +expr_ty _Ta3_JoinedStr(asdl_seq * values, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena *arena); +#define Constant(a0, a1, a2, a3, a4, a5, a6) _Ta3_Constant(a0, a1, a2, a3, a4, a5, a6) +expr_ty _Ta3_Constant(constant value, string kind, int lineno, int col_offset, + int end_lineno, int end_col_offset, PyArena *arena); +#define Attribute(a0, a1, a2, a3, a4, a5, a6, a7) _Ta3_Attribute(a0, a1, a2, a3, a4, a5, a6, a7) +expr_ty _Ta3_Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int + lineno, int col_offset, int end_lineno, int + end_col_offset, PyArena *arena); +#define Subscript(a0, a1, a2, a3, a4, a5, a6, a7) _Ta3_Subscript(a0, a1, a2, a3, a4, a5, a6, a7) +expr_ty _Ta3_Subscript(expr_ty value, expr_ty slice, expr_context_ty ctx, int + lineno, int col_offset, int end_lineno, int + end_col_offset, PyArena *arena); +#define Starred(a0, a1, a2, a3, a4, a5, a6) _Ta3_Starred(a0, a1, a2, a3, a4, a5, a6) +expr_ty _Ta3_Starred(expr_ty value, expr_context_ty ctx, int lineno, int + col_offset, int end_lineno, int end_col_offset, PyArena + *arena); +#define Name(a0, a1, a2, a3, a4, a5, a6) _Ta3_Name(a0, a1, a2, a3, a4, a5, a6) +expr_ty _Ta3_Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena *arena); -#define Slice(a0, a1, a2, a3, a4, a5, a6, a7) _Py_Slice(a0, a1, a2, a3, a4, a5, a6, a7) -expr_ty _Py_Slice(expr_ty lower, expr_ty upper, expr_ty step, int lineno, int +#define List(a0, a1, a2, a3, a4, a5, a6) _Ta3_List(a0, a1, a2, a3, a4, a5, a6) +expr_ty _Ta3_List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena *arena); -#define comprehension(a0, a1, a2, a3, a4) _Py_comprehension(a0, a1, a2, a3, a4) -comprehension_ty _Py_comprehension(expr_ty target, expr_ty iter, asdl_seq * - ifs, int is_async, PyArena *arena); -#define ExceptHandler(a0, a1, a2, a3, a4, a5, a6, a7) _Py_ExceptHandler(a0, a1, a2, a3, a4, a5, a6, a7) -excepthandler_ty _Py_ExceptHandler(expr_ty type, identifier name, asdl_seq * - body, int lineno, int col_offset, int - end_lineno, int end_col_offset, PyArena - *arena); -#define arguments(a0, a1, a2, a3, a4, a5, a6, a7) _Py_arguments(a0, a1, a2, a3, a4, a5, a6, a7) -arguments_ty _Py_arguments(asdl_seq * posonlyargs, asdl_seq * args, arg_ty - vararg, asdl_seq * kwonlyargs, asdl_seq * - kw_defaults, arg_ty kwarg, asdl_seq * defaults, - PyArena *arena); -#define arg(a0, a1, a2, a3, a4, a5, a6, a7) _Py_arg(a0, a1, a2, a3, a4, a5, a6, a7) -arg_ty _Py_arg(identifier arg, expr_ty annotation, string type_comment, int - lineno, int col_offset, int end_lineno, int end_col_offset, - PyArena *arena); -#define keyword(a0, a1, a2, a3, a4, a5, a6) _Py_keyword(a0, a1, a2, a3, a4, a5, a6) -keyword_ty _Py_keyword(identifier arg, expr_ty value, int lineno, int - col_offset, int end_lineno, int end_col_offset, PyArena - *arena); -#define alias(a0, a1, a2) _Py_alias(a0, a1, a2) -alias_ty _Py_alias(identifier name, identifier asname, PyArena *arena); -#define withitem(a0, a1, a2) _Py_withitem(a0, a1, a2) -withitem_ty _Py_withitem(expr_ty context_expr, expr_ty optional_vars, PyArena - *arena); -#define TypeIgnore(a0, a1, a2) _Py_TypeIgnore(a0, a1, a2) -type_ignore_ty _Py_TypeIgnore(int lineno, string tag, PyArena *arena); - -PyObject* PyAST_mod2obj(mod_ty t); -mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode); -int PyAST_Check(PyObject* obj); +#define Tuple(a0, a1, a2, a3, a4, a5, a6) _Ta3_Tuple(a0, a1, a2, a3, a4, a5, a6) +expr_ty _Ta3_Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int + col_offset, int end_lineno, int end_col_offset, PyArena + *arena); +#define Slice(a0, a1, a2, a3, a4, a5, a6, a7) _Ta3_Slice(a0, a1, a2, a3, a4, a5, a6, a7) +expr_ty _Ta3_Slice(expr_ty lower, expr_ty upper, expr_ty step, int lineno, int + col_offset, int end_lineno, int end_col_offset, PyArena + *arena); +#define comprehension(a0, a1, a2, a3, a4) _Ta3_comprehension(a0, a1, a2, a3, a4) +comprehension_ty _Ta3_comprehension(expr_ty target, expr_ty iter, asdl_seq * + ifs, int is_async, PyArena *arena); +#define ExceptHandler(a0, a1, a2, a3, a4, a5, a6, a7) _Ta3_ExceptHandler(a0, a1, a2, a3, a4, a5, a6, a7) +excepthandler_ty _Ta3_ExceptHandler(expr_ty type, identifier name, asdl_seq * + body, int lineno, int col_offset, int + end_lineno, int end_col_offset, PyArena + *arena); +#define arguments(a0, a1, a2, a3, a4, a5, a6, a7) _Ta3_arguments(a0, a1, a2, a3, a4, a5, a6, a7) +arguments_ty _Ta3_arguments(asdl_seq * posonlyargs, asdl_seq * args, arg_ty + vararg, asdl_seq * kwonlyargs, asdl_seq * + kw_defaults, arg_ty kwarg, asdl_seq * defaults, + PyArena *arena); +#define arg(a0, a1, a2, a3, a4, a5, a6, a7) _Ta3_arg(a0, a1, a2, a3, a4, a5, a6, a7) +arg_ty _Ta3_arg(identifier arg, expr_ty annotation, string type_comment, int + lineno, int col_offset, int end_lineno, int end_col_offset, + PyArena *arena); +#define keyword(a0, a1, a2, a3, a4, a5, a6) _Ta3_keyword(a0, a1, a2, a3, a4, a5, a6) +keyword_ty _Ta3_keyword(identifier arg, expr_ty value, int lineno, int + col_offset, int end_lineno, int end_col_offset, PyArena + *arena); +#define alias(a0, a1, a2) _Ta3_alias(a0, a1, a2) +alias_ty _Ta3_alias(identifier name, identifier asname, PyArena *arena); +#define withitem(a0, a1, a2) _Ta3_withitem(a0, a1, a2) +withitem_ty _Ta3_withitem(expr_ty context_expr, expr_ty optional_vars, PyArena + *arena); +#define TypeIgnore(a0, a1, a2) _Ta3_TypeIgnore(a0, a1, a2) +type_ignore_ty _Ta3_TypeIgnore(int lineno, string tag, PyArena *arena); + +PyObject* Ta3AST_mod2obj(mod_ty t); +mod_ty Ta3AST_obj2mod(PyObject* ast, PyArena* arena, int mode); +int Ta3AST_Check(PyObject* obj); #endif /* !Py_LIMITED_API */ #ifdef __cplusplus diff --git a/ast3/Include/asdl.h b/ast3/Include/asdl.h index 5c6292e3..6a881213 100644 --- a/ast3/Include/asdl.h +++ b/ast3/Include/asdl.h @@ -25,8 +25,8 @@ typedef struct { int elements[1]; } asdl_int_seq; -asdl_seq *_Py_asdl_seq_new(Py_ssize_t size, PyArena *arena); -asdl_int_seq *_Py_asdl_int_seq_new(Py_ssize_t size, PyArena *arena); +asdl_seq *_Ta3_asdl_seq_new(Py_ssize_t size, PyArena *arena); +asdl_int_seq *_Ta3_asdl_int_seq_new(Py_ssize_t size, PyArena *arena); #define asdl_seq_GET(S, I) (S)->elements[(I)] #define asdl_seq_LEN(S) ((S) == NULL ? 0 : (S)->size) diff --git a/ast3/Include/pegen_interface.h b/ast3/Include/pegen_interface.h index bbacb831..8cccafa1 100644 --- a/ast3/Include/pegen_interface.h +++ b/ast3/Include/pegen_interface.h @@ -11,32 +11,32 @@ extern "C" { #include "Python.h" #include "Python-ast.h" -PyAPI_FUNC(mod_ty) PyPegen_ASTFromString( +PyAPI_FUNC(mod_ty) Ta3Pegen_ASTFromString( const char *str, const char *filename, int mode, - PyCompilerFlags *flags, + PegenCompilerFlags *flags, PyArena *arena); -PyAPI_FUNC(mod_ty) PyPegen_ASTFromStringObject( +PyAPI_FUNC(mod_ty) Ta3Pegen_ASTFromStringObject( const char *str, PyObject* filename, int mode, - PyCompilerFlags *flags, + PegenCompilerFlags *flags, PyArena *arena); -PyAPI_FUNC(mod_ty) PyPegen_ASTFromFileObject( +PyAPI_FUNC(mod_ty) Ta3Pegen_ASTFromFileObject( FILE *fp, PyObject *filename_ob, int mode, const char *enc, const char *ps1, const char *ps2, - PyCompilerFlags *flags, + PegenCompilerFlags *flags, int *errcode, PyArena *arena); -PyAPI_FUNC(mod_ty) PyPegen_ASTFromFilename( +PyAPI_FUNC(mod_ty) Ta3Pegen_ASTFromFilename( const char *filename, int mode, - PyCompilerFlags *flags, + PegenCompilerFlags *flags, PyArena *arena); diff --git a/ast3/Include/ta3_compat.h b/ast3/Include/ta3_compat.h new file mode 100644 index 00000000..01afe5a2 --- /dev/null +++ b/ast3/Include/ta3_compat.h @@ -0,0 +1,78 @@ +#ifndef Ta3_COMPAT_H +#define Ta3_COMPAT_H + +// Various workarounds to make the parser compatible with older 3.x +#include + +// f-string input is new in 3.9 +#if PY_MINOR_VERSION < 9 +#define Py_fstring_input 800 +#endif + +// top level await new in 3.9 +#if PY_MINOR_VERSION < 8 +#define PyCF_ALLOW_TOP_LEVEL_AWAIT 0x2000 +#endif + +// typed_ast was merged into Python in 3.8 +#if PY_MINOR_VERSION < 8 +#define PyCF_TYPE_COMMENTS 0x1000 +#endif + +typedef struct { + int cf_flags; /* bitmask of CO_xxx flags relevant to future */ + int cf_feature_version; /* minor Python version (PyCF_ONLY_AST) */ +} PegenCompilerFlags; + +#define _PegenCompilerFlags_INIT \ + (PegenCompilerFlags){.cf_flags = 0, .cf_feature_version = PY_MINOR_VERSION} + + +// Define 3.7+ input types +#if PY_MINOR_VERSION < 8 +/* These definitions must match corresponding definitions in graminit.h. */ +#define Py_single_input 256 +#define Py_file_input 257 +#define Py_eval_input 258 +#define Py_func_type_input 345 +#endif + +// Py_UNREACHABLE was defined in 3.7 +#if PY_MINOR_VERSION < 7 +#if defined(RANDALL_WAS_HERE) +# define Py_UNREACHABLE() \ + Py_FatalError( \ + "If you're seeing this, the code is in what I thought was\n" \ + "an unreachable state.\n\n" \ + "I could give you advice for what to do, but honestly, why\n" \ + "should you trust me? I clearly screwed this up. I'm writing\n" \ + "a message that should never appear, yet I know it will\n" \ + "probably appear someday.\n\n" \ + "On a deep level, I know I'm not up to this task.\n" \ + "I'm so sorry.\n" \ + "https://xkcd.com/2200") +#elif defined(Py_DEBUG) +# define Py_UNREACHABLE() \ + Py_FatalError( \ + "We've reached an unreachable state. Anything is possible.\n" \ + "The limits were in our heads all along. Follow your dreams.\n" \ + "https://xkcd.com/2200") +#elif defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER) +# define Py_UNREACHABLE() __builtin_unreachable() +#elif defined(_MSC_VER) +# define Py_UNREACHABLE() __assume(0) +#else +# define Py_UNREACHABLE() \ + Py_FatalError("Unreachable C code path reached") +#endif +#endif + +// 3.7 also introduced _Py_TypeName, which we provide an alternative for it here +const char * _Ta3Type_Name(PyTypeObject *); + +int _Pegen_PyObject_LookupAttr(PyObject *, PyObject *, PyObject **); + +const char * +_Pegen_SourceAsString(PyObject *cmd, const char *funcname, const char *what, PegenCompilerFlags *cf, PyObject **cmd_copy); + +#endif // Ta3_COMPAT_H diff --git a/ast3/Parser/asdl_c.py b/ast3/Parser/asdl_c.py index 59bf03ef..d5cf6051 100755 --- a/ast3/Parser/asdl_c.py +++ b/ast3/Parser/asdl_c.py @@ -292,9 +292,9 @@ def emit_function(self, name, ctype, args, attrs, union=True): margs = "a0" for i in range(1, len(args)+1): margs += ", a%d" % i - self.emit("#define %s(%s) _Py_%s(%s)" % (name, margs, name, margs), 0, + self.emit("#define %s(%s) _Ta3_%s(%s)" % (name, margs, name, margs), 0, reflow=False) - self.emit("%s _Py_%s(%s);" % (ctype, name, argstr), False) + self.emit("%s _Ta3_%s(%s);" % (ctype, name, argstr), False) def visitProduct(self, prod, name): self.emit_function(name, get_c_type(name), @@ -520,7 +520,7 @@ def isSimpleType(self, field): def visitField(self, field, name, sum=None, prod=None, depth=0): ctype = get_c_type(field.type) - line = "if (_PyObject_LookupAttr(obj, astmodulestate_global->%s, &tmp) < 0) {" + line = "if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->%s, &tmp) < 0) {" self.emit(line % field.name, depth) self.emit("return 1;", depth+1) self.emit("}", depth) @@ -548,16 +548,16 @@ def visitField(self, field, name, sum=None, prod=None, depth=0): self.emit("Py_ssize_t i;", depth+1) self.emit("if (!PyList_Check(tmp)) {", depth+1) self.emit("PyErr_Format(PyExc_TypeError, \"%s field \\\"%s\\\" must " - "be a list, not a %%.200s\", _PyType_Name(Py_TYPE(tmp)));" % + "be a list, not a %%.200s\", _Ta3Type_Name(Py_TYPE(tmp)));" % (name, field.name), depth+2, reflow=False) self.emit("goto failed;", depth+2) self.emit("}", depth+1) self.emit("len = PyList_GET_SIZE(tmp);", depth+1) if self.isSimpleType(field): - self.emit("%s = _Py_asdl_int_seq_new(len, arena);" % field.name, depth+1) + self.emit("%s = _Ta3_asdl_int_seq_new(len, arena);" % field.name, depth+1) else: - self.emit("%s = _Py_asdl_seq_new(len, arena);" % field.name, depth+1) + self.emit("%s = _Ta3_asdl_seq_new(len, arena);" % field.name, depth+1) self.emit("if (%s == NULL) goto failed;" % field.name, depth+1) self.emit("for (i = 0; i < len; i++) {", depth+1) self.emit("%s val;" % ctype, depth+2) @@ -685,7 +685,7 @@ def visitModule(self, mod): Py_ssize_t i, numfields = 0; int res = -1; PyObject *key, *value, *fields; - if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), astmodulestate_global->_fields, &fields) < 0) { + if (_Pegen_PyObject_LookupAttr((PyObject*)Py_TYPE(self), astmodulestate_global->_fields, &fields) < 0) { goto cleanup; } if (fields) { @@ -698,7 +698,7 @@ def visitModule(self, mod): if (numfields < PyTuple_GET_SIZE(args)) { PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most " "%zd positional argument%s", - _PyType_Name(Py_TYPE(self)), + _Ta3Type_Name(Py_TYPE(self)), numfields, numfields == 1 ? "" : "s"); res = -1; goto cleanup; @@ -733,7 +733,7 @@ def visitModule(self, mod): ast_type_reduce(PyObject *self, PyObject *unused) { PyObject *dict; - if (_PyObject_LookupAttr(self, astmodulestate_global->__dict__, &dict) < 0) { + if (_Pegen_PyObject_LookupAttr(self, astmodulestate_global->__dict__, &dict) < 0) { return NULL; } if (dict) { @@ -1023,7 +1023,7 @@ class ASTModuleVisitor(PickleVisitor): def visitModule(self, mod): self.emit("PyMODINIT_FUNC", 0) - self.emit("PyInit__ast(void)", 0) + self.emit("PyInit__ast3(void)", 0) self.emit("{", 0) self.emit("PyObject *m;", 1) self.emit("if (!init_types()) return NULL;", 1) @@ -1223,7 +1223,7 @@ def set(self, field, value, depth): class PartingShots(StaticVisitor): CODE = """ -PyObject* PyAST_mod2obj(mod_ty t) +PyObject* Ta3AST_mod2obj(mod_ty t) { if (!init_types()) return NULL; @@ -1231,16 +1231,12 @@ class PartingShots(StaticVisitor): } /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ -mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) +mod_ty Ta3AST_obj2mod(PyObject* ast, PyArena* arena, int mode) { PyObject *req_type[3]; const char * const req_name[] = {"Module", "Expression", "Interactive"}; int isinstance; - if (PySys_Audit("compile", "OO", ast, Py_None) < 0) { - return NULL; - } - req_type[0] = astmodulestate_global->Module_type; req_type[1] = astmodulestate_global->Expression_type; req_type[2] = astmodulestate_global->Interactive_type; @@ -1255,7 +1251,7 @@ class PartingShots(StaticVisitor): return NULL; if (!isinstance) { PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", - req_name[mode], _PyType_Name(Py_TYPE(ast))); + req_name[mode], _Ta3Type_Name(Py_TYPE(ast))); return NULL; } @@ -1266,7 +1262,7 @@ class PartingShots(StaticVisitor): return res; } -int PyAST_Check(PyObject* obj) +int Ta3AST_Check(PyObject* obj) { if (!init_types()) return -1; @@ -1346,10 +1342,10 @@ def generate_module_def(f, mod): static struct PyModuleDef _astmodule = { PyModuleDef_HEAD_INIT, - "_ast", + "_ast3", NULL, sizeof(astmodulestate), - NULL, + ast3_methods, NULL, astmodule_traverse, astmodule_clear, @@ -1387,14 +1383,15 @@ def main(srcfile, dump_module=False): if H_FILE: with open(H_FILE, "w") as f: f.write(auto_gen_msg) - f.write('#ifndef Py_PYTHON_AST_H\n') - f.write('#define Py_PYTHON_AST_H\n') + f.write('#ifndef Ta3_PYTHON_AST_H\n') + f.write('#define Ta3_PYTHON_AST_H\n') f.write('#ifdef __cplusplus\n') f.write('extern "C" {\n') f.write('#endif\n') f.write('\n') f.write('#ifndef Py_LIMITED_API\n') f.write('#include "asdl.h"\n') + f.write('#include "../Include/ta3_compat.h"') f.write('\n') f.write('#undef Yield /* undefine macro conflicting with */\n') f.write('\n') @@ -1405,15 +1402,15 @@ def main(srcfile, dump_module=False): f.write("// Note: these macros affect function definitions, not only call sites.\n") PrototypeVisitor(f).visit(mod) f.write("\n") - f.write("PyObject* PyAST_mod2obj(mod_ty t);\n") - f.write("mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode);\n") - f.write("int PyAST_Check(PyObject* obj);\n") + f.write("PyObject* Ta3AST_mod2obj(mod_ty t);\n") + f.write("mod_ty Ta3AST_obj2mod(PyObject* ast, PyArena* arena, int mode);\n") + f.write("int Ta3AST_Check(PyObject* obj);\n") f.write("#endif /* !Py_LIMITED_API */\n") f.write('\n') f.write('#ifdef __cplusplus\n') f.write('}\n') f.write('#endif\n') - f.write('#endif /* !Py_PYTHON_AST_H */\n') + f.write('#endif /* !Ta3_PYTHON_AST_H */\n') if C_FILE: with open(C_FILE, "w") as f: @@ -1421,9 +1418,14 @@ def main(srcfile, dump_module=False): f.write('#include \n') f.write('\n') f.write('#include "Python.h"\n') - f.write('#include "%s-ast.h"\n' % mod.name) + f.write('#include "../Include/%s-ast.h"\n' % mod.name) f.write('#include "structmember.h" // PyMemberDef\n') f.write('\n') + f.write("PyObject *ast3_parse(PyObject *self, PyObject *args);\n") + f.write("static PyMethodDef ast3_methods[] = {\n") + f.write(' {"_parse", ast3_parse, METH_VARARGS, "Parse string into typed AST."},\n') + f.write(" {NULL, NULL, NULL}\n") + f.write("};\n") generate_module_def(f, mod) diff --git a/ast3/Parser/pegen/parse.c b/ast3/Parser/pegen/parse.c index 3a08abbc..21dbf736 100644 --- a/ast3/Parser/pegen/parse.c +++ b/ast3/Parser/pegen/parse.c @@ -1,5 +1,6 @@ -// @generated by pegen.py from ./Grammar/python.gram +// @generated by pegen.py from ../../Grammar/python.gram #include "pegen.h" +#include "ta3_compat.h" static const int n_keyword_lists = 15; static KeywordToken *reserved_keywords[] = { NULL, @@ -682,10 +683,10 @@ file_rule(Parser *p) if ( (a = statements_rule(p), 1) // statements? && - (endmarker_var = _PyPegen_expect_token(p, ENDMARKER)) // token='ENDMARKER' + (endmarker_var = _Ta3Pegen_expect_token(p, ENDMARKER)) // token='ENDMARKER' ) { - res = _PyPegen_make_module ( p , a ); + res = _Ta3Pegen_make_module ( p , a ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -746,7 +747,7 @@ eval_rule(Parser *p) && (_loop0_1_var = _loop0_1_rule(p)) // NEWLINE* && - (endmarker_var = _PyPegen_expect_token(p, ENDMARKER)) // token='ENDMARKER' + (endmarker_var = _Ta3Pegen_expect_token(p, ENDMARKER)) // token='ENDMARKER' ) { res = Expression ( a , p -> arena ); @@ -781,19 +782,19 @@ func_type_rule(Parser *p) Token * literal_1; Token * literal_2; if ( - (literal = _PyPegen_expect_token(p, 7)) // token='(' + (literal = _Ta3Pegen_expect_token(p, 7)) // token='(' && (a = type_expressions_rule(p), 1) // type_expressions? && - (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + (literal_1 = _Ta3Pegen_expect_token(p, 8)) // token=')' && - (literal_2 = _PyPegen_expect_token(p, 51)) // token='->' + (literal_2 = _Ta3Pegen_expect_token(p, 51)) // token='->' && (b = expression_rule(p)) // expression && (_loop0_2_var = _loop0_2_rule(p)) // NEWLINE* && - (endmarker_var = _PyPegen_expect_token(p, ENDMARKER)) // token='ENDMARKER' + (endmarker_var = _Ta3Pegen_expect_token(p, ENDMARKER)) // token='ENDMARKER' ) { res = FunctionType ( a , b , p -> arena ); @@ -862,20 +863,20 @@ type_expressions_rule(Parser *p) if ( (a = _gather_3_rule(p)) // ','.expression+ && - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && - (literal_1 = _PyPegen_expect_token(p, 16)) // token='*' + (literal_1 = _Ta3Pegen_expect_token(p, 16)) // token='*' && (b = expression_rule(p)) // expression && - (literal_2 = _PyPegen_expect_token(p, 12)) // token=',' + (literal_2 = _Ta3Pegen_expect_token(p, 12)) // token=',' && - (literal_3 = _PyPegen_expect_token(p, 35)) // token='**' + (literal_3 = _Ta3Pegen_expect_token(p, 35)) // token='**' && (c = expression_rule(p)) // expression ) { - res = _PyPegen_seq_append_to_end ( p , CHECK ( _PyPegen_seq_append_to_end ( p , a , b ) ) , c ); + res = _Ta3Pegen_seq_append_to_end ( p , CHECK ( _Ta3Pegen_seq_append_to_end ( p , a , b ) ) , c ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -892,14 +893,14 @@ type_expressions_rule(Parser *p) if ( (a = _gather_5_rule(p)) // ','.expression+ && - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && - (literal_1 = _PyPegen_expect_token(p, 16)) // token='*' + (literal_1 = _Ta3Pegen_expect_token(p, 16)) // token='*' && (b = expression_rule(p)) // expression ) { - res = _PyPegen_seq_append_to_end ( p , a , b ); + res = _Ta3Pegen_seq_append_to_end ( p , a , b ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -916,14 +917,14 @@ type_expressions_rule(Parser *p) if ( (a = _gather_7_rule(p)) // ','.expression+ && - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && - (literal_1 = _PyPegen_expect_token(p, 35)) // token='**' + (literal_1 = _Ta3Pegen_expect_token(p, 35)) // token='**' && (b = expression_rule(p)) // expression ) { - res = _PyPegen_seq_append_to_end ( p , a , b ); + res = _Ta3Pegen_seq_append_to_end ( p , a , b ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -939,18 +940,18 @@ type_expressions_rule(Parser *p) Token * literal_1; Token * literal_2; if ( - (literal = _PyPegen_expect_token(p, 16)) // token='*' + (literal = _Ta3Pegen_expect_token(p, 16)) // token='*' && (a = expression_rule(p)) // expression && - (literal_1 = _PyPegen_expect_token(p, 12)) // token=',' + (literal_1 = _Ta3Pegen_expect_token(p, 12)) // token=',' && - (literal_2 = _PyPegen_expect_token(p, 35)) // token='**' + (literal_2 = _Ta3Pegen_expect_token(p, 35)) // token='**' && (b = expression_rule(p)) // expression ) { - res = _PyPegen_seq_append_to_end ( p , CHECK ( _PyPegen_singleton_seq ( p , a ) ) , b ); + res = _Ta3Pegen_seq_append_to_end ( p , CHECK ( _Ta3Pegen_singleton_seq ( p , a ) ) , b ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -963,12 +964,12 @@ type_expressions_rule(Parser *p) expr_ty a; Token * literal; if ( - (literal = _PyPegen_expect_token(p, 16)) // token='*' + (literal = _Ta3Pegen_expect_token(p, 16)) // token='*' && (a = expression_rule(p)) // expression ) { - res = _PyPegen_singleton_seq ( p , a ); + res = _Ta3Pegen_singleton_seq ( p , a ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -981,12 +982,12 @@ type_expressions_rule(Parser *p) expr_ty a; Token * literal; if ( - (literal = _PyPegen_expect_token(p, 35)) // token='**' + (literal = _Ta3Pegen_expect_token(p, 35)) // token='**' && (a = expression_rule(p)) // expression ) { - res = _PyPegen_singleton_seq ( p , a ); + res = _Ta3Pegen_singleton_seq ( p , a ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -1026,7 +1027,7 @@ statements_rule(Parser *p) (a = _loop1_11_rule(p)) // statement+ ) { - res = _PyPegen_seq_flatten ( p , a ); + res = _Ta3Pegen_seq_flatten ( p , a ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -1055,7 +1056,7 @@ statement_rule(Parser *p) (a = compound_stmt_rule(p)) // compound_stmt ) { - res = _PyPegen_singleton_seq ( p , a ); + res = _Ta3Pegen_singleton_seq ( p , a ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -1089,7 +1090,7 @@ statement_newline_rule(Parser *p) } asdl_seq* res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -1103,10 +1104,10 @@ statement_newline_rule(Parser *p) if ( (a = compound_stmt_rule(p)) // compound_stmt && - (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + (newline_var = _Ta3Pegen_expect_token(p, NEWLINE)) // token='NEWLINE' ) { - res = _PyPegen_singleton_seq ( p , a ); + res = _Ta3Pegen_singleton_seq ( p , a ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -1129,10 +1130,10 @@ statement_newline_rule(Parser *p) { // NEWLINE Token * newline_var; if ( - (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + (newline_var = _Ta3Pegen_expect_token(p, NEWLINE)) // token='NEWLINE' ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -1140,7 +1141,7 @@ statement_newline_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 = _PyPegen_singleton_seq ( p , CHECK ( _Py_Pass ( EXTRA ) ) ); + res = _Ta3Pegen_singleton_seq ( p , CHECK ( _Ta3_Pass ( EXTRA ) ) ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -1152,10 +1153,10 @@ statement_newline_rule(Parser *p) { // $ Token * endmarker_var; if ( - (endmarker_var = _PyPegen_expect_token(p, ENDMARKER)) // token='ENDMARKER' + (endmarker_var = _Ta3Pegen_expect_token(p, ENDMARKER)) // token='ENDMARKER' ) { - res = _PyPegen_interactive_exit ( p ); + res = _Ta3Pegen_interactive_exit ( p ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -1184,12 +1185,12 @@ simple_stmt_rule(Parser *p) if ( (a = small_stmt_rule(p)) // small_stmt && - _PyPegen_lookahead_with_int(0, _PyPegen_expect_token, p, 13) // token=';' + _Ta3Pegen_lookahead_with_int(0, _Ta3Pegen_expect_token, p, 13) // token=';' && - (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + (newline_var = _Ta3Pegen_expect_token(p, NEWLINE)) // token='NEWLINE' ) { - res = _PyPegen_singleton_seq ( p , a ); + res = _Ta3Pegen_singleton_seq ( p , a ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -1206,9 +1207,9 @@ simple_stmt_rule(Parser *p) if ( (a = _gather_12_rule(p)) // ';'.small_stmt+ && - (opt_var = _PyPegen_expect_token(p, 13), 1) // ';'? + (opt_var = _Ta3Pegen_expect_token(p, 13), 1) // ';'? && - (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + (newline_var = _Ta3Pegen_expect_token(p, NEWLINE)) // token='NEWLINE' ) { res = a; @@ -1246,10 +1247,10 @@ small_stmt_rule(Parser *p) return NULL; } stmt_ty res = NULL; - if (_PyPegen_is_memoized(p, small_stmt_type, &res)) + if (_Ta3Pegen_is_memoized(p, small_stmt_type, &res)) return res; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -1274,7 +1275,7 @@ small_stmt_rule(Parser *p) (e = star_expressions_rule(p)) // star_expressions ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -1282,7 +1283,7 @@ small_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 = _Py_Expr ( e , EXTRA ); + res = _Ta3_Expr ( e , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -1294,7 +1295,7 @@ small_stmt_rule(Parser *p) { // &'return' return_stmt stmt_ty return_stmt_var; if ( - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 500) // token='return' + _Ta3Pegen_lookahead_with_int(1, _Ta3Pegen_expect_token, p, 500) // token='return' && (return_stmt_var = return_stmt_rule(p)) // return_stmt ) @@ -1307,7 +1308,7 @@ small_stmt_rule(Parser *p) { // &('import' | 'from') import_stmt stmt_ty import_stmt_var; if ( - _PyPegen_lookahead(1, _tmp_14_rule, p) + _Ta3Pegen_lookahead(1, _tmp_14_rule, p) && (import_stmt_var = import_stmt_rule(p)) // import_stmt ) @@ -1320,7 +1321,7 @@ small_stmt_rule(Parser *p) { // &'raise' raise_stmt stmt_ty raise_stmt_var; if ( - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 501) // token='raise' + _Ta3Pegen_lookahead_with_int(1, _Ta3Pegen_expect_token, p, 501) // token='raise' && (raise_stmt_var = raise_stmt_rule(p)) // raise_stmt ) @@ -1333,10 +1334,10 @@ small_stmt_rule(Parser *p) { // 'pass' Token * keyword; if ( - (keyword = _PyPegen_expect_token(p, 502)) // token='pass' + (keyword = _Ta3Pegen_expect_token(p, 502)) // token='pass' ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -1344,7 +1345,7 @@ small_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 = _Py_Pass ( EXTRA ); + res = _Ta3_Pass ( EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -1356,7 +1357,7 @@ small_stmt_rule(Parser *p) { // &'del' del_stmt stmt_ty del_stmt_var; if ( - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 503) // token='del' + _Ta3Pegen_lookahead_with_int(1, _Ta3Pegen_expect_token, p, 503) // token='del' && (del_stmt_var = del_stmt_rule(p)) // del_stmt ) @@ -1369,7 +1370,7 @@ small_stmt_rule(Parser *p) { // &'yield' yield_stmt stmt_ty yield_stmt_var; if ( - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 504) // token='yield' + _Ta3Pegen_lookahead_with_int(1, _Ta3Pegen_expect_token, p, 504) // token='yield' && (yield_stmt_var = yield_stmt_rule(p)) // yield_stmt ) @@ -1382,7 +1383,7 @@ small_stmt_rule(Parser *p) { // &'assert' assert_stmt stmt_ty assert_stmt_var; if ( - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 505) // token='assert' + _Ta3Pegen_lookahead_with_int(1, _Ta3Pegen_expect_token, p, 505) // token='assert' && (assert_stmt_var = assert_stmt_rule(p)) // assert_stmt ) @@ -1395,10 +1396,10 @@ small_stmt_rule(Parser *p) { // 'break' Token * keyword; if ( - (keyword = _PyPegen_expect_token(p, 506)) // token='break' + (keyword = _Ta3Pegen_expect_token(p, 506)) // token='break' ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -1406,7 +1407,7 @@ small_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 = _Py_Break ( EXTRA ); + res = _Ta3_Break ( EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -1418,10 +1419,10 @@ small_stmt_rule(Parser *p) { // 'continue' Token * keyword; if ( - (keyword = _PyPegen_expect_token(p, 507)) // token='continue' + (keyword = _Ta3Pegen_expect_token(p, 507)) // token='continue' ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -1429,7 +1430,7 @@ small_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 = _Py_Continue ( EXTRA ); + res = _Ta3_Continue ( EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -1441,7 +1442,7 @@ small_stmt_rule(Parser *p) { // &'global' global_stmt stmt_ty global_stmt_var; if ( - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 508) // token='global' + _Ta3Pegen_lookahead_with_int(1, _Ta3Pegen_expect_token, p, 508) // token='global' && (global_stmt_var = global_stmt_rule(p)) // global_stmt ) @@ -1454,7 +1455,7 @@ small_stmt_rule(Parser *p) { // &'nonlocal' nonlocal_stmt stmt_ty nonlocal_stmt_var; if ( - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 509) // token='nonlocal' + _Ta3Pegen_lookahead_with_int(1, _Ta3Pegen_expect_token, p, 509) // token='nonlocal' && (nonlocal_stmt_var = nonlocal_stmt_rule(p)) // nonlocal_stmt ) @@ -1466,7 +1467,7 @@ small_stmt_rule(Parser *p) } res = NULL; done: - _PyPegen_insert_memo(p, mark, small_stmt_type, res); + _Ta3Pegen_insert_memo(p, mark, small_stmt_type, res); return res; } @@ -1489,7 +1490,7 @@ compound_stmt_rule(Parser *p) { // &('def' | '@' | ASYNC) function_def stmt_ty function_def_var; if ( - _PyPegen_lookahead(1, _tmp_15_rule, p) + _Ta3Pegen_lookahead(1, _tmp_15_rule, p) && (function_def_var = function_def_rule(p)) // function_def ) @@ -1502,7 +1503,7 @@ compound_stmt_rule(Parser *p) { // &'if' if_stmt stmt_ty if_stmt_var; if ( - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 510) // token='if' + _Ta3Pegen_lookahead_with_int(1, _Ta3Pegen_expect_token, p, 510) // token='if' && (if_stmt_var = if_stmt_rule(p)) // if_stmt ) @@ -1515,7 +1516,7 @@ compound_stmt_rule(Parser *p) { // &('class' | '@') class_def stmt_ty class_def_var; if ( - _PyPegen_lookahead(1, _tmp_16_rule, p) + _Ta3Pegen_lookahead(1, _tmp_16_rule, p) && (class_def_var = class_def_rule(p)) // class_def ) @@ -1528,7 +1529,7 @@ compound_stmt_rule(Parser *p) { // &('with' | ASYNC) with_stmt stmt_ty with_stmt_var; if ( - _PyPegen_lookahead(1, _tmp_17_rule, p) + _Ta3Pegen_lookahead(1, _tmp_17_rule, p) && (with_stmt_var = with_stmt_rule(p)) // with_stmt ) @@ -1541,7 +1542,7 @@ compound_stmt_rule(Parser *p) { // &('for' | ASYNC) for_stmt stmt_ty for_stmt_var; if ( - _PyPegen_lookahead(1, _tmp_18_rule, p) + _Ta3Pegen_lookahead(1, _tmp_18_rule, p) && (for_stmt_var = for_stmt_rule(p)) // for_stmt ) @@ -1554,7 +1555,7 @@ compound_stmt_rule(Parser *p) { // &'try' try_stmt stmt_ty try_stmt_var; if ( - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 511) // token='try' + _Ta3Pegen_lookahead_with_int(1, _Ta3Pegen_expect_token, p, 511) // token='try' && (try_stmt_var = try_stmt_rule(p)) // try_stmt ) @@ -1567,7 +1568,7 @@ compound_stmt_rule(Parser *p) { // &'while' while_stmt stmt_ty while_stmt_var; if ( - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 512) // token='while' + _Ta3Pegen_lookahead_with_int(1, _Ta3Pegen_expect_token, p, 512) // token='while' && (while_stmt_var = while_stmt_rule(p)) // while_stmt ) @@ -1596,7 +1597,7 @@ assignment_rule(Parser *p) } stmt_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -1610,16 +1611,16 @@ assignment_rule(Parser *p) void *c; Token * literal; if ( - (a = _PyPegen_name_token(p)) // NAME + (a = _Ta3Pegen_name_token(p)) // NAME && - (literal = _PyPegen_expect_token(p, 11)) // token=':' + (literal = _Ta3Pegen_expect_token(p, 11)) // token=':' && (b = expression_rule(p)) // expression && (c = _tmp_19_rule(p), 1) // ['=' annotated_rhs] ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -1627,7 +1628,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 = CHECK_VERSION ( 6 , "Variable annotation syntax is" , _Py_AnnAssign ( CHECK ( _PyPegen_set_expr_context ( p , a , Store ) ) , b , c , 1 , EXTRA ) ); + res = CHECK_VERSION ( 6 , "Variable annotation syntax is" , _Ta3_AnnAssign ( CHECK ( _Ta3Pegen_set_expr_context ( p , a , Store ) ) , b , c , 1 , EXTRA ) ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -1644,14 +1645,14 @@ assignment_rule(Parser *p) if ( (a = _tmp_20_rule(p)) // '(' inside_paren_ann_assign_target ')' | ann_assign_subscript_attribute_target && - (literal = _PyPegen_expect_token(p, 11)) // token=':' + (literal = _Ta3Pegen_expect_token(p, 11)) // token=':' && (b = expression_rule(p)) // expression && (c = _tmp_21_rule(p), 1) // ['=' annotated_rhs] ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -1659,7 +1660,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 = CHECK_VERSION ( 6 , "Variable annotations syntax is" , _Py_AnnAssign ( a , b , c , 0 , EXTRA ) ); + res = CHECK_VERSION ( 6 , "Variable annotations syntax is" , _Ta3_AnnAssign ( a , b , c , 0 , EXTRA ) ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -1677,10 +1678,10 @@ assignment_rule(Parser *p) && (b = _tmp_23_rule(p)) // yield_expr | star_expressions && - (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? + (tc = _Ta3Pegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -1688,7 +1689,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 , NEW_TYPE_COMMENT ( p , tc ) , EXTRA ); + res = _Ta3_Assign ( a , b , NEW_TYPE_COMMENT ( p , tc ) , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -1709,7 +1710,7 @@ assignment_rule(Parser *p) (c = _tmp_24_rule(p)) // yield_expr | star_expressions ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -1717,7 +1718,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_AugAssign ( a , b -> kind , c , EXTRA ); + res = _Ta3_AugAssign ( a , b -> kind , c , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -1767,10 +1768,10 @@ augassign_rule(Parser *p) { // '+=' Token * literal; if ( - (literal = _PyPegen_expect_token(p, 36)) // token='+=' + (literal = _Ta3Pegen_expect_token(p, 36)) // token='+=' ) { - res = _PyPegen_augoperator ( p , Add ); + res = _Ta3Pegen_augoperator ( p , Add ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -1782,10 +1783,10 @@ augassign_rule(Parser *p) { // '-=' Token * literal; if ( - (literal = _PyPegen_expect_token(p, 37)) // token='-=' + (literal = _Ta3Pegen_expect_token(p, 37)) // token='-=' ) { - res = _PyPegen_augoperator ( p , Sub ); + res = _Ta3Pegen_augoperator ( p , Sub ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -1797,10 +1798,10 @@ augassign_rule(Parser *p) { // '*=' Token * literal; if ( - (literal = _PyPegen_expect_token(p, 38)) // token='*=' + (literal = _Ta3Pegen_expect_token(p, 38)) // token='*=' ) { - res = _PyPegen_augoperator ( p , Mult ); + res = _Ta3Pegen_augoperator ( p , Mult ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -1812,10 +1813,10 @@ augassign_rule(Parser *p) { // '@=' Token * literal; if ( - (literal = _PyPegen_expect_token(p, 50)) // token='@=' + (literal = _Ta3Pegen_expect_token(p, 50)) // token='@=' ) { - res = CHECK_VERSION ( 5 , "The '@' operator is" , _PyPegen_augoperator ( p , MatMult ) ); + res = CHECK_VERSION ( 5 , "The '@' operator is" , _Ta3Pegen_augoperator ( p , MatMult ) ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -1827,10 +1828,10 @@ augassign_rule(Parser *p) { // '/=' Token * literal; if ( - (literal = _PyPegen_expect_token(p, 39)) // token='/=' + (literal = _Ta3Pegen_expect_token(p, 39)) // token='/=' ) { - res = _PyPegen_augoperator ( p , Div ); + res = _Ta3Pegen_augoperator ( p , Div ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -1842,10 +1843,10 @@ augassign_rule(Parser *p) { // '%=' Token * literal; if ( - (literal = _PyPegen_expect_token(p, 40)) // token='%=' + (literal = _Ta3Pegen_expect_token(p, 40)) // token='%=' ) { - res = _PyPegen_augoperator ( p , Mod ); + res = _Ta3Pegen_augoperator ( p , Mod ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -1857,10 +1858,10 @@ augassign_rule(Parser *p) { // '&=' Token * literal; if ( - (literal = _PyPegen_expect_token(p, 41)) // token='&=' + (literal = _Ta3Pegen_expect_token(p, 41)) // token='&=' ) { - res = _PyPegen_augoperator ( p , BitAnd ); + res = _Ta3Pegen_augoperator ( p , BitAnd ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -1872,10 +1873,10 @@ augassign_rule(Parser *p) { // '|=' Token * literal; if ( - (literal = _PyPegen_expect_token(p, 42)) // token='|=' + (literal = _Ta3Pegen_expect_token(p, 42)) // token='|=' ) { - res = _PyPegen_augoperator ( p , BitOr ); + res = _Ta3Pegen_augoperator ( p , BitOr ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -1887,10 +1888,10 @@ augassign_rule(Parser *p) { // '^=' Token * literal; if ( - (literal = _PyPegen_expect_token(p, 43)) // token='^=' + (literal = _Ta3Pegen_expect_token(p, 43)) // token='^=' ) { - res = _PyPegen_augoperator ( p , BitXor ); + res = _Ta3Pegen_augoperator ( p , BitXor ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -1902,10 +1903,10 @@ augassign_rule(Parser *p) { // '<<=' Token * literal; if ( - (literal = _PyPegen_expect_token(p, 44)) // token='<<=' + (literal = _Ta3Pegen_expect_token(p, 44)) // token='<<=' ) { - res = _PyPegen_augoperator ( p , LShift ); + res = _Ta3Pegen_augoperator ( p , LShift ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -1917,10 +1918,10 @@ augassign_rule(Parser *p) { // '>>=' Token * literal; if ( - (literal = _PyPegen_expect_token(p, 45)) // token='>>=' + (literal = _Ta3Pegen_expect_token(p, 45)) // token='>>=' ) { - res = _PyPegen_augoperator ( p , RShift ); + res = _Ta3Pegen_augoperator ( p , RShift ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -1932,10 +1933,10 @@ augassign_rule(Parser *p) { // '**=' Token * literal; if ( - (literal = _PyPegen_expect_token(p, 46)) // token='**=' + (literal = _Ta3Pegen_expect_token(p, 46)) // token='**=' ) { - res = _PyPegen_augoperator ( p , Pow ); + res = _Ta3Pegen_augoperator ( p , Pow ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -1947,10 +1948,10 @@ augassign_rule(Parser *p) { // '//=' Token * literal; if ( - (literal = _PyPegen_expect_token(p, 48)) // token='//=' + (literal = _Ta3Pegen_expect_token(p, 48)) // token='//=' ) { - res = _PyPegen_augoperator ( p , FloorDiv ); + res = _Ta3Pegen_augoperator ( p , FloorDiv ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -1973,7 +1974,7 @@ global_stmt_rule(Parser *p) } stmt_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -1985,12 +1986,12 @@ global_stmt_rule(Parser *p) asdl_seq * a; Token * keyword; if ( - (keyword = _PyPegen_expect_token(p, 508)) // token='global' + (keyword = _Ta3Pegen_expect_token(p, 508)) // token='global' && (a = _gather_25_rule(p)) // ','.NAME+ ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -1998,7 +1999,7 @@ global_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 = _Py_Global ( CHECK ( _PyPegen_map_names_to_ids ( p , a ) ) , EXTRA ); + res = _Ta3_Global ( CHECK ( _Ta3Pegen_map_names_to_ids ( p , a ) ) , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -2021,7 +2022,7 @@ nonlocal_stmt_rule(Parser *p) } stmt_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -2033,12 +2034,12 @@ nonlocal_stmt_rule(Parser *p) asdl_seq * a; Token * keyword; if ( - (keyword = _PyPegen_expect_token(p, 509)) // token='nonlocal' + (keyword = _Ta3Pegen_expect_token(p, 509)) // token='nonlocal' && (a = _gather_27_rule(p)) // ','.NAME+ ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -2046,7 +2047,7 @@ nonlocal_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 = _Py_Nonlocal ( CHECK ( _PyPegen_map_names_to_ids ( p , a ) ) , EXTRA ); + res = _Ta3_Nonlocal ( CHECK ( _Ta3Pegen_map_names_to_ids ( p , a ) ) , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -2069,7 +2070,7 @@ yield_stmt_rule(Parser *p) } stmt_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -2083,7 +2084,7 @@ yield_stmt_rule(Parser *p) (y = yield_expr_rule(p)) // yield_expr ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -2091,7 +2092,7 @@ yield_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 = _Py_Expr ( y , EXTRA ); + res = _Ta3_Expr ( y , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -2114,7 +2115,7 @@ assert_stmt_rule(Parser *p) } stmt_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -2127,14 +2128,14 @@ assert_stmt_rule(Parser *p) void *b; Token * keyword; if ( - (keyword = _PyPegen_expect_token(p, 505)) // token='assert' + (keyword = _Ta3Pegen_expect_token(p, 505)) // token='assert' && (a = expression_rule(p)) // expression && (b = _tmp_29_rule(p), 1) // [',' expression] ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -2142,7 +2143,7 @@ assert_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 = _Py_Assert ( a , b , EXTRA ); + res = _Ta3_Assert ( a , b , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -2165,7 +2166,7 @@ del_stmt_rule(Parser *p) } stmt_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -2177,12 +2178,12 @@ del_stmt_rule(Parser *p) asdl_seq* a; Token * keyword; if ( - (keyword = _PyPegen_expect_token(p, 503)) // token='del' + (keyword = _Ta3Pegen_expect_token(p, 503)) // token='del' && (a = del_targets_rule(p)) // del_targets ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -2190,7 +2191,7 @@ del_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 = _Py_Delete ( a , EXTRA ); + res = _Ta3_Delete ( a , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -2249,7 +2250,7 @@ import_name_rule(Parser *p) } stmt_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -2261,12 +2262,12 @@ import_name_rule(Parser *p) asdl_seq* a; Token * keyword; if ( - (keyword = _PyPegen_expect_token(p, 513)) // token='import' + (keyword = _Ta3Pegen_expect_token(p, 513)) // token='import' && (a = dotted_as_names_rule(p)) // dotted_as_names ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -2274,7 +2275,7 @@ import_name_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_Import ( a , EXTRA ); + res = _Ta3_Import ( a , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -2299,7 +2300,7 @@ import_from_rule(Parser *p) } stmt_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -2314,18 +2315,18 @@ import_from_rule(Parser *p) Token * keyword; Token * keyword_1; if ( - (keyword = _PyPegen_expect_token(p, 514)) // token='from' + (keyword = _Ta3Pegen_expect_token(p, 514)) // token='from' && (a = _loop0_30_rule(p)) // (('.' | '...'))* && (b = dotted_name_rule(p)) // dotted_name && - (keyword_1 = _PyPegen_expect_token(p, 513)) // token='import' + (keyword_1 = _Ta3Pegen_expect_token(p, 513)) // token='import' && (c = import_from_targets_rule(p)) // import_from_targets ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -2333,7 +2334,7 @@ import_from_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_ImportFrom ( b -> v . Name . id , c , _PyPegen_seq_count_dots ( a ) , EXTRA ); + res = _Ta3_ImportFrom ( b -> v . Name . id , c , _Ta3Pegen_seq_count_dots ( a ) , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -2348,16 +2349,16 @@ import_from_rule(Parser *p) Token * keyword; Token * keyword_1; if ( - (keyword = _PyPegen_expect_token(p, 514)) // token='from' + (keyword = _Ta3Pegen_expect_token(p, 514)) // token='from' && (a = _loop1_31_rule(p)) // (('.' | '...'))+ && - (keyword_1 = _PyPegen_expect_token(p, 513)) // token='import' + (keyword_1 = _Ta3Pegen_expect_token(p, 513)) // token='import' && (b = import_from_targets_rule(p)) // import_from_targets ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -2365,7 +2366,7 @@ import_from_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_ImportFrom ( NULL , b , _PyPegen_seq_count_dots ( a ) , EXTRA ); + res = _Ta3_ImportFrom ( NULL , b , _Ta3Pegen_seq_count_dots ( a ) , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -2395,13 +2396,13 @@ import_from_targets_rule(Parser *p) void *opt_var; UNUSED(opt_var); // Silence compiler warnings if ( - (literal = _PyPegen_expect_token(p, 7)) // token='(' + (literal = _Ta3Pegen_expect_token(p, 7)) // token='(' && (a = import_from_as_names_rule(p)) // import_from_as_names && - (opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + (opt_var = _Ta3Pegen_expect_token(p, 12), 1) // ','? && - (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + (literal_1 = _Ta3Pegen_expect_token(p, 8)) // token=')' ) { res = a; @@ -2427,10 +2428,10 @@ import_from_targets_rule(Parser *p) { // '*' Token * literal; if ( - (literal = _PyPegen_expect_token(p, 16)) // token='*' + (literal = _Ta3Pegen_expect_token(p, 16)) // token='*' ) { - res = _PyPegen_singleton_seq ( p , CHECK ( _PyPegen_alias_for_star ( p ) ) ); + res = _Ta3Pegen_singleton_seq ( p , CHECK ( _Ta3Pegen_alias_for_star ( p ) ) ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -2486,12 +2487,12 @@ import_from_as_name_rule(Parser *p) expr_ty a; void *b; if ( - (a = _PyPegen_name_token(p)) // NAME + (a = _Ta3Pegen_name_token(p)) // NAME && (b = _tmp_34_rule(p), 1) // ['as' NAME] ) { - res = _Py_alias ( a -> v . Name . id , ( b ) ? ( ( expr_ty ) b ) -> v . Name . id : NULL , p -> arena ); + res = _Ta3_alias ( a -> v . Name . id , ( b ) ? ( ( expr_ty ) b ) -> v . Name . id : NULL , p -> arena ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -2552,7 +2553,7 @@ dotted_as_name_rule(Parser *p) (b = _tmp_37_rule(p), 1) // ['as' NAME] ) { - res = _Py_alias ( a -> v . Name . id , ( b ) ? ( ( expr_ty ) b ) -> v . Name . id : NULL , p -> arena ); + res = _Ta3_alias ( a -> v . Name . id , ( b ) ? ( ( expr_ty ) b ) -> v . Name . id : NULL , p -> arena ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -2573,12 +2574,12 @@ static expr_ty dotted_name_rule(Parser *p) { expr_ty res = NULL; - if (_PyPegen_is_memoized(p, dotted_name_type, &res)) + if (_Ta3Pegen_is_memoized(p, dotted_name_type, &res)) return res; int mark = p->mark; int resmark = p->mark; while (1) { - int tmpvar_0 = _PyPegen_update_memo(p, mark, dotted_name_type, res); + int tmpvar_0 = _Ta3Pegen_update_memo(p, mark, dotted_name_type, res); if (tmpvar_0) { return res; } @@ -2607,12 +2608,12 @@ dotted_name_raw(Parser *p) if ( (a = dotted_name_rule(p)) // dotted_name && - (literal = _PyPegen_expect_token(p, 23)) // token='.' + (literal = _Ta3Pegen_expect_token(p, 23)) // token='.' && - (b = _PyPegen_name_token(p)) // NAME + (b = _Ta3Pegen_name_token(p)) // NAME ) { - res = _PyPegen_join_names_with_dot ( p , a , b ); + res = _Ta3Pegen_join_names_with_dot ( p , a , b ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -2624,7 +2625,7 @@ dotted_name_raw(Parser *p) { // NAME expr_ty name_var; if ( - (name_var = _PyPegen_name_token(p)) // NAME + (name_var = _Ta3Pegen_name_token(p)) // NAME ) { res = name_var; @@ -2648,7 +2649,7 @@ if_stmt_rule(Parser *p) } stmt_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -2663,18 +2664,18 @@ if_stmt_rule(Parser *p) Token * keyword; Token * literal; if ( - (keyword = _PyPegen_expect_token(p, 510)) // token='if' + (keyword = _Ta3Pegen_expect_token(p, 510)) // token='if' && (a = named_expression_rule(p)) // named_expression && - (literal = _PyPegen_expect_token(p, 11)) // token=':' + (literal = _Ta3Pegen_expect_token(p, 11)) // token=':' && (b = block_rule(p)) // block && (c = elif_stmt_rule(p)) // elif_stmt ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -2682,7 +2683,7 @@ if_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 = _Py_If ( a , b , CHECK ( _PyPegen_singleton_seq ( p , c ) ) , EXTRA ); + res = _Ta3_If ( a , b , CHECK ( _Ta3Pegen_singleton_seq ( p , c ) ) , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -2698,18 +2699,18 @@ if_stmt_rule(Parser *p) Token * keyword; Token * literal; if ( - (keyword = _PyPegen_expect_token(p, 510)) // token='if' + (keyword = _Ta3Pegen_expect_token(p, 510)) // token='if' && (a = named_expression_rule(p)) // named_expression && - (literal = _PyPegen_expect_token(p, 11)) // token=':' + (literal = _Ta3Pegen_expect_token(p, 11)) // token=':' && (b = block_rule(p)) // block && (c = else_block_rule(p), 1) // else_block? ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -2717,7 +2718,7 @@ if_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 = _Py_If ( a , b , c , EXTRA ); + res = _Ta3_If ( a , b , c , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -2742,7 +2743,7 @@ elif_stmt_rule(Parser *p) } stmt_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -2757,18 +2758,18 @@ elif_stmt_rule(Parser *p) Token * keyword; Token * literal; if ( - (keyword = _PyPegen_expect_token(p, 515)) // token='elif' + (keyword = _Ta3Pegen_expect_token(p, 515)) // token='elif' && (a = named_expression_rule(p)) // named_expression && - (literal = _PyPegen_expect_token(p, 11)) // token=':' + (literal = _Ta3Pegen_expect_token(p, 11)) // token=':' && (b = block_rule(p)) // block && (c = elif_stmt_rule(p)) // elif_stmt ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -2776,7 +2777,7 @@ elif_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 = _Py_If ( a , b , CHECK ( _PyPegen_singleton_seq ( p , c ) ) , EXTRA ); + res = _Ta3_If ( a , b , CHECK ( _Ta3Pegen_singleton_seq ( p , c ) ) , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -2792,18 +2793,18 @@ elif_stmt_rule(Parser *p) Token * keyword; Token * literal; if ( - (keyword = _PyPegen_expect_token(p, 515)) // token='elif' + (keyword = _Ta3Pegen_expect_token(p, 515)) // token='elif' && (a = named_expression_rule(p)) // named_expression && - (literal = _PyPegen_expect_token(p, 11)) // token=':' + (literal = _Ta3Pegen_expect_token(p, 11)) // token=':' && (b = block_rule(p)) // block && (c = else_block_rule(p), 1) // else_block? ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -2811,7 +2812,7 @@ elif_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 = _Py_If ( a , b , c , EXTRA ); + res = _Ta3_If ( a , b , c , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -2839,9 +2840,9 @@ else_block_rule(Parser *p) Token * keyword; Token * literal; if ( - (keyword = _PyPegen_expect_token(p, 516)) // token='else' + (keyword = _Ta3Pegen_expect_token(p, 516)) // token='else' && - (literal = _PyPegen_expect_token(p, 11)) // token=':' + (literal = _Ta3Pegen_expect_token(p, 11)) // token=':' && (b = block_rule(p)) // block ) @@ -2869,7 +2870,7 @@ while_stmt_rule(Parser *p) } stmt_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -2884,18 +2885,18 @@ while_stmt_rule(Parser *p) Token * keyword; Token * literal; if ( - (keyword = _PyPegen_expect_token(p, 512)) // token='while' + (keyword = _Ta3Pegen_expect_token(p, 512)) // token='while' && (a = named_expression_rule(p)) // named_expression && - (literal = _PyPegen_expect_token(p, 11)) // token=':' + (literal = _Ta3Pegen_expect_token(p, 11)) // token=':' && (b = block_rule(p)) // block && (c = else_block_rule(p), 1) // else_block? ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -2903,7 +2904,7 @@ while_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 = _Py_While ( a , b , c , EXTRA ); + res = _Ta3_While ( a , b , c , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -2928,7 +2929,7 @@ for_stmt_rule(Parser *p) } stmt_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -2946,24 +2947,24 @@ for_stmt_rule(Parser *p) expr_ty t; void *tc; if ( - (keyword = _PyPegen_expect_token(p, 517)) // token='for' + (keyword = _Ta3Pegen_expect_token(p, 517)) // token='for' && (t = star_targets_rule(p)) // star_targets && - (keyword_1 = _PyPegen_expect_token(p, 518)) // token='in' + (keyword_1 = _Ta3Pegen_expect_token(p, 518)) // token='in' && (ex = star_expressions_rule(p)) // star_expressions && - (literal = _PyPegen_expect_token(p, 11)) // token=':' + (literal = _Ta3Pegen_expect_token(p, 11)) // token=':' && - (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? + (tc = _Ta3Pegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? && (b = block_rule(p)) // block && (el = else_block_rule(p), 1) // else_block? ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -2971,7 +2972,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 = _Py_For ( t , ex , b , el , NEW_TYPE_COMMENT ( p , tc ) , EXTRA ); + res = _Ta3_For ( t , ex , b , el , NEW_TYPE_COMMENT ( p , tc ) , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -2991,26 +2992,26 @@ for_stmt_rule(Parser *p) expr_ty t; void *tc; if ( - (async_var = _PyPegen_expect_token(p, ASYNC)) // token='ASYNC' + (async_var = _Ta3Pegen_expect_token(p, ASYNC)) // token='ASYNC' && - (keyword = _PyPegen_expect_token(p, 517)) // token='for' + (keyword = _Ta3Pegen_expect_token(p, 517)) // token='for' && (t = star_targets_rule(p)) // star_targets && - (keyword_1 = _PyPegen_expect_token(p, 518)) // token='in' + (keyword_1 = _Ta3Pegen_expect_token(p, 518)) // token='in' && (ex = star_expressions_rule(p)) // star_expressions && - (literal = _PyPegen_expect_token(p, 11)) // token=':' + (literal = _Ta3Pegen_expect_token(p, 11)) // token=':' && - (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? + (tc = _Ta3Pegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? && (b = block_rule(p)) // block && (el = else_block_rule(p), 1) // else_block? ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -3018,7 +3019,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 = CHECK_VERSION ( 5 , "Async for loops are" , _Py_AsyncFor ( t , ex , b , el , NEW_TYPE_COMMENT ( p , tc ) , EXTRA ) ); + res = CHECK_VERSION ( 5 , "Async for loops are" , _Ta3_AsyncFor ( t , ex , b , el , NEW_TYPE_COMMENT ( p , tc ) , EXTRA ) ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -3045,7 +3046,7 @@ with_stmt_rule(Parser *p) } stmt_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -3063,22 +3064,22 @@ with_stmt_rule(Parser *p) void *opt_var; UNUSED(opt_var); // Silence compiler warnings if ( - (keyword = _PyPegen_expect_token(p, 519)) // token='with' + (keyword = _Ta3Pegen_expect_token(p, 519)) // token='with' && - (literal = _PyPegen_expect_token(p, 7)) // token='(' + (literal = _Ta3Pegen_expect_token(p, 7)) // token='(' && (a = _gather_38_rule(p)) // ','.with_item+ && - (opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + (opt_var = _Ta3Pegen_expect_token(p, 12), 1) // ','? && - (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + (literal_1 = _Ta3Pegen_expect_token(p, 8)) // token=')' && - (literal_2 = _PyPegen_expect_token(p, 11)) // token=':' + (literal_2 = _Ta3Pegen_expect_token(p, 11)) // token=':' && (b = block_rule(p)) // block ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -3086,7 +3087,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 = _Py_With ( a , b , NULL , EXTRA ); + res = _Ta3_With ( a , b , NULL , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -3102,18 +3103,18 @@ with_stmt_rule(Parser *p) Token * literal; void *tc; if ( - (keyword = _PyPegen_expect_token(p, 519)) // token='with' + (keyword = _Ta3Pegen_expect_token(p, 519)) // token='with' && (a = _gather_40_rule(p)) // ','.with_item+ && - (literal = _PyPegen_expect_token(p, 11)) // token=':' + (literal = _Ta3Pegen_expect_token(p, 11)) // token=':' && - (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? + (tc = _Ta3Pegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? && (b = block_rule(p)) // block ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -3121,7 +3122,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 = _Py_With ( a , b , NEW_TYPE_COMMENT ( p , tc ) , EXTRA ); + res = _Ta3_With ( a , b , NEW_TYPE_COMMENT ( p , tc ) , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -3141,24 +3142,24 @@ with_stmt_rule(Parser *p) void *opt_var; UNUSED(opt_var); // Silence compiler warnings if ( - (async_var = _PyPegen_expect_token(p, ASYNC)) // token='ASYNC' + (async_var = _Ta3Pegen_expect_token(p, ASYNC)) // token='ASYNC' && - (keyword = _PyPegen_expect_token(p, 519)) // token='with' + (keyword = _Ta3Pegen_expect_token(p, 519)) // token='with' && - (literal = _PyPegen_expect_token(p, 7)) // token='(' + (literal = _Ta3Pegen_expect_token(p, 7)) // token='(' && (a = _gather_42_rule(p)) // ','.with_item+ && - (opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + (opt_var = _Ta3Pegen_expect_token(p, 12), 1) // ','? && - (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + (literal_1 = _Ta3Pegen_expect_token(p, 8)) // token=')' && - (literal_2 = _PyPegen_expect_token(p, 11)) // token=':' + (literal_2 = _Ta3Pegen_expect_token(p, 11)) // token=':' && (b = block_rule(p)) // block ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -3166,7 +3167,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 = CHECK_VERSION ( 5 , "Async with statements are" , _Py_AsyncWith ( a , b , NULL , EXTRA ) ); + res = CHECK_VERSION ( 5 , "Async with statements are" , _Ta3_AsyncWith ( a , b , NULL , EXTRA ) ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -3183,20 +3184,20 @@ with_stmt_rule(Parser *p) Token * literal; void *tc; if ( - (async_var = _PyPegen_expect_token(p, ASYNC)) // token='ASYNC' + (async_var = _Ta3Pegen_expect_token(p, ASYNC)) // token='ASYNC' && - (keyword = _PyPegen_expect_token(p, 519)) // token='with' + (keyword = _Ta3Pegen_expect_token(p, 519)) // token='with' && (a = _gather_44_rule(p)) // ','.with_item+ && - (literal = _PyPegen_expect_token(p, 11)) // token=':' + (literal = _Ta3Pegen_expect_token(p, 11)) // token=':' && - (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? + (tc = _Ta3Pegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? && (b = block_rule(p)) // block ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -3204,7 +3205,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 = CHECK_VERSION ( 5 , "Async with statements are" , _Py_AsyncWith ( a , b , NEW_TYPE_COMMENT ( p , tc ) , EXTRA ) ); + res = CHECK_VERSION ( 5 , "Async with statements are" , _Ta3_AsyncWith ( a , b , NEW_TYPE_COMMENT ( p , tc ) , EXTRA ) ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -3236,7 +3237,7 @@ with_item_rule(Parser *p) (o = _tmp_46_rule(p), 1) // ['as' target] ) { - res = _Py_withitem ( e , o , p -> arena ); + res = _Ta3_withitem ( e , o , p -> arena ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -3261,7 +3262,7 @@ try_stmt_rule(Parser *p) } stmt_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -3275,16 +3276,16 @@ try_stmt_rule(Parser *p) Token * keyword; Token * literal; if ( - (keyword = _PyPegen_expect_token(p, 511)) // token='try' + (keyword = _Ta3Pegen_expect_token(p, 511)) // token='try' && - (literal = _PyPegen_expect_token(p, 11)) // token=':' + (literal = _Ta3Pegen_expect_token(p, 11)) // token=':' && (b = block_rule(p)) // block && (f = finally_block_rule(p)) // finally_block ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -3292,7 +3293,7 @@ try_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 = _Py_Try ( b , NULL , NULL , f , EXTRA ); + res = _Ta3_Try ( b , NULL , NULL , f , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -3309,9 +3310,9 @@ try_stmt_rule(Parser *p) Token * keyword; Token * literal; if ( - (keyword = _PyPegen_expect_token(p, 511)) // token='try' + (keyword = _Ta3Pegen_expect_token(p, 511)) // token='try' && - (literal = _PyPegen_expect_token(p, 11)) // token=':' + (literal = _Ta3Pegen_expect_token(p, 11)) // token=':' && (b = block_rule(p)) // block && @@ -3322,7 +3323,7 @@ try_stmt_rule(Parser *p) (f = finally_block_rule(p), 1) // finally_block? ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -3330,7 +3331,7 @@ try_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 = _Py_Try ( b , ex , el , f , EXTRA ); + res = _Ta3_Try ( b , ex , el , f , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -3353,7 +3354,7 @@ except_block_rule(Parser *p) } excepthandler_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -3368,18 +3369,18 @@ except_block_rule(Parser *p) Token * literal; void *t; if ( - (keyword = _PyPegen_expect_token(p, 520)) // token='except' + (keyword = _Ta3Pegen_expect_token(p, 520)) // token='except' && (e = expression_rule(p)) // expression && (t = _tmp_48_rule(p), 1) // ['as' target] && - (literal = _PyPegen_expect_token(p, 11)) // token=':' + (literal = _Ta3Pegen_expect_token(p, 11)) // token=':' && (b = block_rule(p)) // block ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -3387,7 +3388,7 @@ except_block_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_ExceptHandler ( e , ( t ) ? ( ( expr_ty ) t ) -> v . Name . id : NULL , b , EXTRA ); + res = _Ta3_ExceptHandler ( e , ( t ) ? ( ( expr_ty ) t ) -> v . Name . id : NULL , b , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -3401,14 +3402,14 @@ except_block_rule(Parser *p) Token * keyword; Token * literal; if ( - (keyword = _PyPegen_expect_token(p, 520)) // token='except' + (keyword = _Ta3Pegen_expect_token(p, 520)) // token='except' && - (literal = _PyPegen_expect_token(p, 11)) // token=':' + (literal = _Ta3Pegen_expect_token(p, 11)) // token=':' && (b = block_rule(p)) // block ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -3416,7 +3417,7 @@ except_block_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_ExceptHandler ( NULL , NULL , b , EXTRA ); + res = _Ta3_ExceptHandler ( NULL , NULL , b , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -3444,9 +3445,9 @@ finally_block_rule(Parser *p) Token * keyword; Token * literal; if ( - (keyword = _PyPegen_expect_token(p, 521)) // token='finally' + (keyword = _Ta3Pegen_expect_token(p, 521)) // token='finally' && - (literal = _PyPegen_expect_token(p, 11)) // token=':' + (literal = _Ta3Pegen_expect_token(p, 11)) // token=':' && (a = block_rule(p)) // block ) @@ -3474,7 +3475,7 @@ return_stmt_rule(Parser *p) } stmt_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -3486,12 +3487,12 @@ return_stmt_rule(Parser *p) void *a; Token * keyword; if ( - (keyword = _PyPegen_expect_token(p, 500)) // token='return' + (keyword = _Ta3Pegen_expect_token(p, 500)) // token='return' && (a = star_expressions_rule(p), 1) // star_expressions? ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -3499,7 +3500,7 @@ return_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 = _Py_Return ( a , EXTRA ); + res = _Ta3_Return ( a , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -3522,7 +3523,7 @@ raise_stmt_rule(Parser *p) } stmt_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -3535,14 +3536,14 @@ raise_stmt_rule(Parser *p) void *b; Token * keyword; if ( - (keyword = _PyPegen_expect_token(p, 501)) // token='raise' + (keyword = _Ta3Pegen_expect_token(p, 501)) // token='raise' && (a = expression_rule(p)) // expression && (b = _tmp_49_rule(p), 1) // ['from' expression] ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -3550,7 +3551,7 @@ raise_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 = _Py_Raise ( a , b , EXTRA ); + res = _Ta3_Raise ( a , b , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -3562,10 +3563,10 @@ raise_stmt_rule(Parser *p) { // 'raise' Token * keyword; if ( - (keyword = _PyPegen_expect_token(p, 501)) // token='raise' + (keyword = _Ta3Pegen_expect_token(p, 501)) // token='raise' ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -3573,7 +3574,7 @@ raise_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 = _Py_Raise ( NULL , NULL , EXTRA ); + res = _Ta3_Raise ( NULL , NULL , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -3605,7 +3606,7 @@ function_def_rule(Parser *p) (f = function_def_raw_rule(p)) // function_def_raw ) { - res = _PyPegen_function_def_decorators ( p , d , f ); + res = _Ta3Pegen_function_def_decorators ( p , d , f ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -3641,7 +3642,7 @@ function_def_raw_rule(Parser *p) } stmt_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -3660,26 +3661,26 @@ function_def_raw_rule(Parser *p) void *params; void *tc; if ( - (keyword = _PyPegen_expect_token(p, 522)) // token='def' + (keyword = _Ta3Pegen_expect_token(p, 522)) // token='def' && - (n = _PyPegen_name_token(p)) // NAME + (n = _Ta3Pegen_name_token(p)) // NAME && - (literal = _PyPegen_expect_token(p, 7)) // token='(' + (literal = _Ta3Pegen_expect_token(p, 7)) // token='(' && (params = params_rule(p), 1) // params? && - (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + (literal_1 = _Ta3Pegen_expect_token(p, 8)) // token=')' && (a = _tmp_50_rule(p), 1) // ['->' expression] && - (literal_2 = _PyPegen_expect_token(p, 11)) // token=':' + (literal_2 = _Ta3Pegen_expect_token(p, 11)) // token=':' && (tc = func_type_comment_rule(p), 1) // func_type_comment? && (b = block_rule(p)) // block ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -3687,7 +3688,7 @@ 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 = _Py_FunctionDef ( n -> v . Name . id , ( params ) ? params : CHECK ( _PyPegen_empty_arguments ( p ) ) , b , NULL , a , NEW_TYPE_COMMENT ( p , tc ) , EXTRA ); + res = _Ta3_FunctionDef ( n -> v . Name . id , ( params ) ? params : CHECK ( _Ta3Pegen_empty_arguments ( p ) ) , b , NULL , a , NEW_TYPE_COMMENT ( p , tc ) , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -3708,28 +3709,28 @@ function_def_raw_rule(Parser *p) void *params; void *tc; if ( - (async_var = _PyPegen_expect_token(p, ASYNC)) // token='ASYNC' + (async_var = _Ta3Pegen_expect_token(p, ASYNC)) // token='ASYNC' && - (keyword = _PyPegen_expect_token(p, 522)) // token='def' + (keyword = _Ta3Pegen_expect_token(p, 522)) // token='def' && - (n = _PyPegen_name_token(p)) // NAME + (n = _Ta3Pegen_name_token(p)) // NAME && - (literal = _PyPegen_expect_token(p, 7)) // token='(' + (literal = _Ta3Pegen_expect_token(p, 7)) // token='(' && (params = params_rule(p), 1) // params? && - (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + (literal_1 = _Ta3Pegen_expect_token(p, 8)) // token=')' && (a = _tmp_51_rule(p), 1) // ['->' expression] && - (literal_2 = _PyPegen_expect_token(p, 11)) // token=':' + (literal_2 = _Ta3Pegen_expect_token(p, 11)) // token=':' && (tc = func_type_comment_rule(p), 1) // func_type_comment? && (b = block_rule(p)) // block ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -3737,7 +3738,7 @@ 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 = CHECK_VERSION ( 5 , "Async functions are" , _Py_AsyncFunctionDef ( n -> v . Name . id , ( params ) ? params : CHECK ( _PyPegen_empty_arguments ( p ) ) , b , NULL , a , NEW_TYPE_COMMENT ( p , tc ) , EXTRA ) ); + res = CHECK_VERSION ( 5 , "Async functions are" , _Ta3_AsyncFunctionDef ( n -> v . Name . id , ( params ) ? params : CHECK ( _Ta3Pegen_empty_arguments ( p ) ) , b , NULL , a , NEW_TYPE_COMMENT ( p , tc ) , EXTRA ) ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -3767,11 +3768,11 @@ func_type_comment_rule(Parser *p) Token * newline_var; Token * t; if ( - (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + (newline_var = _Ta3Pegen_expect_token(p, NEWLINE)) // token='NEWLINE' && - (t = _PyPegen_expect_token(p, TYPE_COMMENT)) // token='TYPE_COMMENT' + (t = _Ta3Pegen_expect_token(p, TYPE_COMMENT)) // token='TYPE_COMMENT' && - _PyPegen_lookahead(1, _tmp_52_rule, p) + _Ta3Pegen_lookahead(1, _tmp_52_rule, p) ) { res = t; @@ -3797,7 +3798,7 @@ func_type_comment_rule(Parser *p) { // TYPE_COMMENT Token * type_comment_var; if ( - (type_comment_var = _PyPegen_expect_token(p, TYPE_COMMENT)) // token='TYPE_COMMENT' + (type_comment_var = _Ta3Pegen_expect_token(p, TYPE_COMMENT)) // token='TYPE_COMMENT' ) { res = type_comment_var; @@ -3875,7 +3876,7 @@ parameters_rule(Parser *p) (d = star_etc_rule(p), 1) // star_etc? ) { - res = _PyPegen_make_arguments ( p , a , NULL , b , c , d ); + res = _Ta3Pegen_make_arguments ( p , a , NULL , b , c , d ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -3896,7 +3897,7 @@ parameters_rule(Parser *p) (c = star_etc_rule(p), 1) // star_etc? ) { - res = _PyPegen_make_arguments ( p , NULL , a , NULL , b , c ); + res = _Ta3Pegen_make_arguments ( p , NULL , a , NULL , b , c ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -3917,7 +3918,7 @@ parameters_rule(Parser *p) (c = star_etc_rule(p), 1) // star_etc? ) { - res = _PyPegen_make_arguments ( p , NULL , NULL , a , b , c ); + res = _Ta3Pegen_make_arguments ( p , NULL , NULL , a , b , c ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -3935,7 +3936,7 @@ parameters_rule(Parser *p) (b = star_etc_rule(p), 1) // star_etc? ) { - res = _PyPegen_make_arguments ( p , NULL , NULL , NULL , a , b ); + res = _Ta3Pegen_make_arguments ( p , NULL , NULL , NULL , a , b ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -3950,7 +3951,7 @@ parameters_rule(Parser *p) (a = star_etc_rule(p)) // star_etc ) { - res = _PyPegen_make_arguments ( p , NULL , NULL , NULL , NULL , a ); + res = _Ta3Pegen_make_arguments ( p , NULL , NULL , NULL , NULL , a ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -3980,9 +3981,9 @@ slash_no_default_rule(Parser *p) if ( (a = _loop1_59_rule(p)) // param_no_default+ && - (literal = _PyPegen_expect_token(p, 17)) // token='/' + (literal = _Ta3Pegen_expect_token(p, 17)) // token='/' && - (literal_1 = _PyPegen_expect_token(p, 12)) // token=',' + (literal_1 = _Ta3Pegen_expect_token(p, 12)) // token=',' ) { res = a; @@ -4000,9 +4001,9 @@ slash_no_default_rule(Parser *p) if ( (a = _loop1_60_rule(p)) // param_no_default+ && - (literal = _PyPegen_expect_token(p, 17)) // token='/' + (literal = _Ta3Pegen_expect_token(p, 17)) // token='/' && - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 8) // token=')' + _Ta3Pegen_lookahead_with_int(1, _Ta3Pegen_expect_token, p, 8) // token=')' ) { res = a; @@ -4040,12 +4041,12 @@ slash_with_default_rule(Parser *p) && (b = _loop1_62_rule(p)) // param_with_default+ && - (literal = _PyPegen_expect_token(p, 17)) // token='/' + (literal = _Ta3Pegen_expect_token(p, 17)) // token='/' && - (literal_1 = _PyPegen_expect_token(p, 12)) // token=',' + (literal_1 = _Ta3Pegen_expect_token(p, 12)) // token=',' ) { - res = _PyPegen_slash_with_default ( p , a , b ); + res = _Ta3Pegen_slash_with_default ( p , a , b ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -4063,12 +4064,12 @@ slash_with_default_rule(Parser *p) && (b = _loop1_64_rule(p)) // param_with_default+ && - (literal = _PyPegen_expect_token(p, 17)) // token='/' + (literal = _Ta3Pegen_expect_token(p, 17)) // token='/' && - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 8) // token=')' + _Ta3Pegen_lookahead_with_int(1, _Ta3Pegen_expect_token, p, 8) // token=')' ) { - res = _PyPegen_slash_with_default ( p , a , b ); + res = _Ta3Pegen_slash_with_default ( p , a , b ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -4101,7 +4102,7 @@ star_etc_rule(Parser *p) void *c; Token * literal; if ( - (literal = _PyPegen_expect_token(p, 16)) // token='*' + (literal = _Ta3Pegen_expect_token(p, 16)) // token='*' && (a = param_no_default_rule(p)) // param_no_default && @@ -4110,7 +4111,7 @@ star_etc_rule(Parser *p) (c = kwds_rule(p), 1) // kwds? ) { - res = _PyPegen_star_etc ( p , a , b , c ); + res = _Ta3Pegen_star_etc ( p , a , b , c ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -4125,16 +4126,16 @@ star_etc_rule(Parser *p) Token * literal; Token * literal_1; if ( - (literal = _PyPegen_expect_token(p, 16)) // token='*' + (literal = _Ta3Pegen_expect_token(p, 16)) // token='*' && - (literal_1 = _PyPegen_expect_token(p, 12)) // token=',' + (literal_1 = _Ta3Pegen_expect_token(p, 12)) // token=',' && (b = _loop1_66_rule(p)) // param_maybe_default+ && (c = kwds_rule(p), 1) // kwds? ) { - res = _PyPegen_star_etc ( p , NULL , b , c ); + res = _Ta3Pegen_star_etc ( p , NULL , b , c ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -4149,7 +4150,7 @@ star_etc_rule(Parser *p) (a = kwds_rule(p)) // kwds ) { - res = _PyPegen_star_etc ( p , NULL , NULL , a ); + res = _Ta3Pegen_star_etc ( p , NULL , NULL , a ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -4187,7 +4188,7 @@ kwds_rule(Parser *p) arg_ty a; Token * literal; if ( - (literal = _PyPegen_expect_token(p, 35)) // token='**' + (literal = _Ta3Pegen_expect_token(p, 35)) // token='**' && (a = param_no_default_rule(p)) // param_no_default ) @@ -4222,12 +4223,12 @@ param_no_default_rule(Parser *p) if ( (a = param_rule(p)) // param && - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && - (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? + (tc = _Ta3Pegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? ) { - res = _PyPegen_add_type_comment_to_arg ( p , a , tc ); + res = _Ta3Pegen_add_type_comment_to_arg ( p , a , tc ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -4242,12 +4243,12 @@ param_no_default_rule(Parser *p) if ( (a = param_rule(p)) // param && - (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? + (tc = _Ta3Pegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? && - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 8) // token=')' + _Ta3Pegen_lookahead_with_int(1, _Ta3Pegen_expect_token, p, 8) // token=')' ) { - res = _PyPegen_add_type_comment_to_arg ( p , a , tc ); + res = _Ta3Pegen_add_type_comment_to_arg ( p , a , tc ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -4280,12 +4281,12 @@ param_with_default_rule(Parser *p) && (c = default_rule(p)) // default && - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && - (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? + (tc = _Ta3Pegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? ) { - res = _PyPegen_name_default_pair ( p , a , c , tc ); + res = _Ta3Pegen_name_default_pair ( p , a , c , tc ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -4303,12 +4304,12 @@ param_with_default_rule(Parser *p) && (c = default_rule(p)) // default && - (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? + (tc = _Ta3Pegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? && - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 8) // token=')' + _Ta3Pegen_lookahead_with_int(1, _Ta3Pegen_expect_token, p, 8) // token=')' ) { - res = _PyPegen_name_default_pair ( p , a , c , tc ); + res = _Ta3Pegen_name_default_pair ( p , a , c , tc ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -4343,12 +4344,12 @@ param_maybe_default_rule(Parser *p) && (c = default_rule(p), 1) // default? && - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && - (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? + (tc = _Ta3Pegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? ) { - res = _PyPegen_name_default_pair ( p , a , c , tc ); + res = _Ta3Pegen_name_default_pair ( p , a , c , tc ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -4366,12 +4367,12 @@ param_maybe_default_rule(Parser *p) && (c = default_rule(p), 1) // default? && - (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? + (tc = _Ta3Pegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? && - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 8) // token=')' + _Ta3Pegen_lookahead_with_int(1, _Ta3Pegen_expect_token, p, 8) // token=')' ) { - res = _PyPegen_name_default_pair ( p , a , c , tc ); + res = _Ta3Pegen_name_default_pair ( p , a , c , tc ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -4394,7 +4395,7 @@ param_rule(Parser *p) } arg_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -4406,12 +4407,12 @@ param_rule(Parser *p) expr_ty a; void *b; if ( - (a = _PyPegen_name_token(p)) // NAME + (a = _Ta3Pegen_name_token(p)) // NAME && (b = annotation_rule(p), 1) // annotation? ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -4419,7 +4420,7 @@ param_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_arg ( a -> v . Name . id , b , NULL , EXTRA ); + res = _Ta3_arg ( a -> v . Name . id , b , NULL , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -4446,7 +4447,7 @@ annotation_rule(Parser *p) expr_ty a; Token * literal; if ( - (literal = _PyPegen_expect_token(p, 11)) // token=':' + (literal = _Ta3Pegen_expect_token(p, 11)) // token=':' && (a = expression_rule(p)) // expression ) @@ -4478,7 +4479,7 @@ default_rule(Parser *p) expr_ty a; Token * literal; if ( - (literal = _PyPegen_expect_token(p, 22)) // token='=' + (literal = _Ta3Pegen_expect_token(p, 22)) // token='=' && (a = expression_rule(p)) // expression ) @@ -4544,7 +4545,7 @@ class_def_rule(Parser *p) (b = class_def_raw_rule(p)) // class_def_raw ) { - res = _PyPegen_class_def_decorators ( p , a , b ); + res = _Ta3Pegen_class_def_decorators ( p , a , b ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -4578,7 +4579,7 @@ class_def_raw_rule(Parser *p) } stmt_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -4593,18 +4594,18 @@ class_def_raw_rule(Parser *p) Token * keyword; Token * literal; if ( - (keyword = _PyPegen_expect_token(p, 523)) // token='class' + (keyword = _Ta3Pegen_expect_token(p, 523)) // token='class' && - (a = _PyPegen_name_token(p)) // NAME + (a = _Ta3Pegen_name_token(p)) // NAME && (b = _tmp_68_rule(p), 1) // ['(' arguments? ')'] && - (literal = _PyPegen_expect_token(p, 11)) // token=':' + (literal = _Ta3Pegen_expect_token(p, 11)) // token=':' && (c = block_rule(p)) // block ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -4612,7 +4613,7 @@ class_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 = _Py_ClassDef ( a -> v . Name . id , ( b ) ? ( ( expr_ty ) b ) -> v . Call . args : NULL , ( b ) ? ( ( expr_ty ) b ) -> v . Call . keywords : NULL , c , NULL , EXTRA ); + res = _Ta3_ClassDef ( a -> v . Name . id , ( b ) ? ( ( expr_ty ) b ) -> v . Call . args : NULL , ( b ) ? ( ( expr_ty ) b ) -> v . Call . keywords : NULL , c , NULL , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -4634,7 +4635,7 @@ block_rule(Parser *p) return NULL; } asdl_seq* res = NULL; - if (_PyPegen_is_memoized(p, block_type, &res)) + if (_Ta3Pegen_is_memoized(p, block_type, &res)) return res; int mark = p->mark; { // NEWLINE INDENT statements DEDENT @@ -4643,13 +4644,13 @@ block_rule(Parser *p) Token * indent_var; Token * newline_var; if ( - (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + (newline_var = _Ta3Pegen_expect_token(p, NEWLINE)) // token='NEWLINE' && - (indent_var = _PyPegen_expect_token(p, INDENT)) // token='INDENT' + (indent_var = _Ta3Pegen_expect_token(p, INDENT)) // token='INDENT' && (a = statements_rule(p)) // statements && - (dedent_var = _PyPegen_expect_token(p, DEDENT)) // token='DEDENT' + (dedent_var = _Ta3Pegen_expect_token(p, DEDENT)) // token='DEDENT' ) { res = a; @@ -4685,7 +4686,7 @@ block_rule(Parser *p) } res = NULL; done: - _PyPegen_insert_memo(p, mark, block_type, res); + _Ta3Pegen_insert_memo(p, mark, block_type, res); return res; } @@ -4705,7 +4706,7 @@ expressions_list_rule(Parser *p) if ( (a = _gather_69_rule(p)) // ','.star_expression+ && - (opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + (opt_var = _Ta3Pegen_expect_token(p, 12), 1) // ','? ) { res = a; @@ -4734,7 +4735,7 @@ star_expressions_rule(Parser *p) } expr_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -4752,10 +4753,10 @@ star_expressions_rule(Parser *p) && (b = _loop1_71_rule(p)) // ((',' star_expression))+ && - (opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + (opt_var = _Ta3Pegen_expect_token(p, 12), 1) // ','? ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -4763,7 +4764,7 @@ star_expressions_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_Tuple ( CHECK ( _PyPegen_seq_insert_in_front ( p , a , b ) ) , Load , EXTRA ); + res = _Ta3_Tuple ( CHECK ( _Ta3Pegen_seq_insert_in_front ( p , a , b ) ) , Load , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -4778,10 +4779,10 @@ star_expressions_rule(Parser *p) if ( (a = star_expression_rule(p)) // star_expression && - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -4789,7 +4790,7 @@ star_expressions_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_Tuple ( CHECK ( _PyPegen_singleton_seq ( p , a ) ) , Load , EXTRA ); + res = _Ta3_Tuple ( CHECK ( _Ta3Pegen_singleton_seq ( p , a ) ) , Load , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -4822,10 +4823,10 @@ star_expression_rule(Parser *p) return NULL; } expr_ty res = NULL; - if (_PyPegen_is_memoized(p, star_expression_type, &res)) + if (_Ta3Pegen_is_memoized(p, star_expression_type, &res)) return res; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -4837,12 +4838,12 @@ star_expression_rule(Parser *p) expr_ty a; Token * literal; if ( - (literal = _PyPegen_expect_token(p, 16)) // token='*' + (literal = _Ta3Pegen_expect_token(p, 16)) // token='*' && (a = bitwise_or_rule(p)) // bitwise_or ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -4850,7 +4851,7 @@ star_expression_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_Starred ( a , Load , EXTRA ); + res = _Ta3_Starred ( a , Load , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -4872,7 +4873,7 @@ star_expression_rule(Parser *p) } res = NULL; done: - _PyPegen_insert_memo(p, mark, star_expression_type, res); + _Ta3Pegen_insert_memo(p, mark, star_expression_type, res); return res; } @@ -4892,7 +4893,7 @@ star_named_expressions_rule(Parser *p) if ( (a = _gather_72_rule(p)) // ','.star_named_expression+ && - (opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + (opt_var = _Ta3Pegen_expect_token(p, 12), 1) // ','? ) { res = a; @@ -4918,7 +4919,7 @@ star_named_expression_rule(Parser *p) } expr_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -4930,12 +4931,12 @@ star_named_expression_rule(Parser *p) expr_ty a; Token * literal; if ( - (literal = _PyPegen_expect_token(p, 16)) // token='*' + (literal = _Ta3Pegen_expect_token(p, 16)) // token='*' && (a = bitwise_or_rule(p)) // bitwise_or ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -4943,7 +4944,7 @@ star_named_expression_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_Starred ( a , Load , EXTRA ); + res = _Ta3_Starred ( a , Load , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -4977,7 +4978,7 @@ named_expression_rule(Parser *p) } expr_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -4990,14 +4991,14 @@ named_expression_rule(Parser *p) expr_ty b; Token * literal; if ( - (a = _PyPegen_name_token(p)) // NAME + (a = _Ta3Pegen_name_token(p)) // NAME && - (literal = _PyPegen_expect_token(p, 53)) // token=':=' + (literal = _Ta3Pegen_expect_token(p, 53)) // token=':=' && (b = expression_rule(p)) // expression ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -5005,7 +5006,7 @@ named_expression_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_NamedExpr ( CHECK ( _PyPegen_set_expr_context ( p , a , Store ) ) , b , EXTRA ); + res = _Ta3_NamedExpr ( CHECK ( _Ta3Pegen_set_expr_context ( p , a , Store ) ) , b , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -5019,7 +5020,7 @@ named_expression_rule(Parser *p) if ( (expression_var = expression_rule(p)) // expression && - _PyPegen_lookahead_with_int(0, _PyPegen_expect_token, p, 53) // token=':=' + _Ta3Pegen_lookahead_with_int(0, _Ta3Pegen_expect_token, p, 53) // token=':=' ) { res = expression_var; @@ -5088,7 +5089,7 @@ expressions_rule(Parser *p) } expr_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -5106,10 +5107,10 @@ expressions_rule(Parser *p) && (b = _loop1_74_rule(p)) // ((',' expression))+ && - (opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + (opt_var = _Ta3Pegen_expect_token(p, 12), 1) // ','? ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -5117,7 +5118,7 @@ expressions_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_Tuple ( CHECK ( _PyPegen_seq_insert_in_front ( p , a , b ) ) , Load , EXTRA ); + res = _Ta3_Tuple ( CHECK ( _Ta3Pegen_seq_insert_in_front ( p , a , b ) ) , Load , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -5132,10 +5133,10 @@ expressions_rule(Parser *p) if ( (a = expression_rule(p)) // expression && - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -5143,7 +5144,7 @@ expressions_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_Tuple ( CHECK ( _PyPegen_singleton_seq ( p , a ) ) , Load , EXTRA ); + res = _Ta3_Tuple ( CHECK ( _Ta3Pegen_singleton_seq ( p , a ) ) , Load , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -5176,10 +5177,10 @@ expression_rule(Parser *p) return NULL; } expr_ty res = NULL; - if (_PyPegen_is_memoized(p, expression_type, &res)) + if (_Ta3Pegen_is_memoized(p, expression_type, &res)) return res; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -5196,16 +5197,16 @@ expression_rule(Parser *p) if ( (a = disjunction_rule(p)) // disjunction && - (keyword = _PyPegen_expect_token(p, 510)) // token='if' + (keyword = _Ta3Pegen_expect_token(p, 510)) // token='if' && (b = disjunction_rule(p)) // disjunction && - (keyword_1 = _PyPegen_expect_token(p, 516)) // token='else' + (keyword_1 = _Ta3Pegen_expect_token(p, 516)) // token='else' && (c = expression_rule(p)) // expression ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -5213,7 +5214,7 @@ expression_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_IfExp ( b , a , c , EXTRA ); + res = _Ta3_IfExp ( b , a , c , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -5246,7 +5247,7 @@ expression_rule(Parser *p) } res = NULL; done: - _PyPegen_insert_memo(p, mark, expression_type, res); + _Ta3Pegen_insert_memo(p, mark, expression_type, res); return res; } @@ -5259,7 +5260,7 @@ lambdef_rule(Parser *p) } expr_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -5273,16 +5274,16 @@ lambdef_rule(Parser *p) Token * keyword; Token * literal; if ( - (keyword = _PyPegen_expect_token(p, 524)) // token='lambda' + (keyword = _Ta3Pegen_expect_token(p, 524)) // token='lambda' && (a = lambda_parameters_rule(p), 1) // lambda_parameters? && - (literal = _PyPegen_expect_token(p, 11)) // token=':' + (literal = _Ta3Pegen_expect_token(p, 11)) // token=':' && (b = expression_rule(p)) // expression ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -5290,7 +5291,7 @@ lambdef_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_Lambda ( ( a ) ? a : CHECK ( _PyPegen_empty_arguments ( p ) ) , b , EXTRA ); + res = _Ta3_Lambda ( ( a ) ? a : CHECK ( _Ta3Pegen_empty_arguments ( p ) ) , b , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -5333,7 +5334,7 @@ lambda_parameters_rule(Parser *p) (d = lambda_star_etc_rule(p), 1) // lambda_star_etc? ) { - res = _PyPegen_make_arguments ( p , a , NULL , b , c , d ); + res = _Ta3Pegen_make_arguments ( p , a , NULL , b , c , d ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -5354,7 +5355,7 @@ lambda_parameters_rule(Parser *p) (c = lambda_star_etc_rule(p), 1) // lambda_star_etc? ) { - res = _PyPegen_make_arguments ( p , NULL , a , NULL , b , c ); + res = _Ta3Pegen_make_arguments ( p , NULL , a , NULL , b , c ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -5375,7 +5376,7 @@ lambda_parameters_rule(Parser *p) (c = lambda_star_etc_rule(p), 1) // lambda_star_etc? ) { - res = _PyPegen_make_arguments ( p , NULL , NULL , a , b , c ); + res = _Ta3Pegen_make_arguments ( p , NULL , NULL , a , b , c ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -5393,7 +5394,7 @@ lambda_parameters_rule(Parser *p) (b = lambda_star_etc_rule(p), 1) // lambda_star_etc? ) { - res = _PyPegen_make_arguments ( p , NULL , NULL , NULL , a , b ); + res = _Ta3Pegen_make_arguments ( p , NULL , NULL , NULL , a , b ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -5408,7 +5409,7 @@ lambda_parameters_rule(Parser *p) (a = lambda_star_etc_rule(p)) // lambda_star_etc ) { - res = _PyPegen_make_arguments ( p , NULL , NULL , NULL , NULL , a ); + res = _Ta3Pegen_make_arguments ( p , NULL , NULL , NULL , NULL , a ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -5440,9 +5441,9 @@ lambda_slash_no_default_rule(Parser *p) if ( (a = _loop1_81_rule(p)) // lambda_param_no_default+ && - (literal = _PyPegen_expect_token(p, 17)) // token='/' + (literal = _Ta3Pegen_expect_token(p, 17)) // token='/' && - (literal_1 = _PyPegen_expect_token(p, 12)) // token=',' + (literal_1 = _Ta3Pegen_expect_token(p, 12)) // token=',' ) { res = a; @@ -5460,9 +5461,9 @@ lambda_slash_no_default_rule(Parser *p) if ( (a = _loop1_82_rule(p)) // lambda_param_no_default+ && - (literal = _PyPegen_expect_token(p, 17)) // token='/' + (literal = _Ta3Pegen_expect_token(p, 17)) // token='/' && - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 11) // token=':' + _Ta3Pegen_lookahead_with_int(1, _Ta3Pegen_expect_token, p, 11) // token=':' ) { res = a; @@ -5500,12 +5501,12 @@ lambda_slash_with_default_rule(Parser *p) && (b = _loop1_84_rule(p)) // lambda_param_with_default+ && - (literal = _PyPegen_expect_token(p, 17)) // token='/' + (literal = _Ta3Pegen_expect_token(p, 17)) // token='/' && - (literal_1 = _PyPegen_expect_token(p, 12)) // token=',' + (literal_1 = _Ta3Pegen_expect_token(p, 12)) // token=',' ) { - res = _PyPegen_slash_with_default ( p , a , b ); + res = _Ta3Pegen_slash_with_default ( p , a , b ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -5523,12 +5524,12 @@ lambda_slash_with_default_rule(Parser *p) && (b = _loop1_86_rule(p)) // lambda_param_with_default+ && - (literal = _PyPegen_expect_token(p, 17)) // token='/' + (literal = _Ta3Pegen_expect_token(p, 17)) // token='/' && - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 11) // token=':' + _Ta3Pegen_lookahead_with_int(1, _Ta3Pegen_expect_token, p, 11) // token=':' ) { - res = _PyPegen_slash_with_default ( p , a , b ); + res = _Ta3Pegen_slash_with_default ( p , a , b ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -5561,7 +5562,7 @@ lambda_star_etc_rule(Parser *p) void *c; Token * literal; if ( - (literal = _PyPegen_expect_token(p, 16)) // token='*' + (literal = _Ta3Pegen_expect_token(p, 16)) // token='*' && (a = lambda_param_no_default_rule(p)) // lambda_param_no_default && @@ -5570,7 +5571,7 @@ lambda_star_etc_rule(Parser *p) (c = lambda_kwds_rule(p), 1) // lambda_kwds? ) { - res = _PyPegen_star_etc ( p , a , b , c ); + res = _Ta3Pegen_star_etc ( p , a , b , c ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -5585,16 +5586,16 @@ lambda_star_etc_rule(Parser *p) Token * literal; Token * literal_1; if ( - (literal = _PyPegen_expect_token(p, 16)) // token='*' + (literal = _Ta3Pegen_expect_token(p, 16)) // token='*' && - (literal_1 = _PyPegen_expect_token(p, 12)) // token=',' + (literal_1 = _Ta3Pegen_expect_token(p, 12)) // token=',' && (b = _loop1_88_rule(p)) // lambda_param_maybe_default+ && (c = lambda_kwds_rule(p), 1) // lambda_kwds? ) { - res = _PyPegen_star_etc ( p , NULL , b , c ); + res = _Ta3Pegen_star_etc ( p , NULL , b , c ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -5609,7 +5610,7 @@ lambda_star_etc_rule(Parser *p) (a = lambda_kwds_rule(p)) // lambda_kwds ) { - res = _PyPegen_star_etc ( p , NULL , NULL , a ); + res = _Ta3Pegen_star_etc ( p , NULL , NULL , a ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -5647,7 +5648,7 @@ lambda_kwds_rule(Parser *p) arg_ty a; Token * literal; if ( - (literal = _PyPegen_expect_token(p, 35)) // token='**' + (literal = _Ta3Pegen_expect_token(p, 35)) // token='**' && (a = lambda_param_no_default_rule(p)) // lambda_param_no_default ) @@ -5681,7 +5682,7 @@ lambda_param_no_default_rule(Parser *p) if ( (a = lambda_param_rule(p)) // lambda_param && - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' ) { res = a; @@ -5698,7 +5699,7 @@ lambda_param_no_default_rule(Parser *p) if ( (a = lambda_param_rule(p)) // lambda_param && - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 11) // token=':' + _Ta3Pegen_lookahead_with_int(1, _Ta3Pegen_expect_token, p, 11) // token=':' ) { res = a; @@ -5733,10 +5734,10 @@ lambda_param_with_default_rule(Parser *p) && (c = default_rule(p)) // default && - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' ) { - res = _PyPegen_name_default_pair ( p , a , c , NULL ); + res = _Ta3Pegen_name_default_pair ( p , a , c , NULL ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -5753,10 +5754,10 @@ lambda_param_with_default_rule(Parser *p) && (c = default_rule(p)) // default && - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 11) // token=':' + _Ta3Pegen_lookahead_with_int(1, _Ta3Pegen_expect_token, p, 11) // token=':' ) { - res = _PyPegen_name_default_pair ( p , a , c , NULL ); + res = _Ta3Pegen_name_default_pair ( p , a , c , NULL ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -5788,10 +5789,10 @@ lambda_param_maybe_default_rule(Parser *p) && (c = default_rule(p), 1) // default? && - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' ) { - res = _PyPegen_name_default_pair ( p , a , c , NULL ); + res = _Ta3Pegen_name_default_pair ( p , a , c , NULL ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -5808,10 +5809,10 @@ lambda_param_maybe_default_rule(Parser *p) && (c = default_rule(p), 1) // default? && - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 11) // token=':' + _Ta3Pegen_lookahead_with_int(1, _Ta3Pegen_expect_token, p, 11) // token=':' ) { - res = _PyPegen_name_default_pair ( p , a , c , NULL ); + res = _Ta3Pegen_name_default_pair ( p , a , c , NULL ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -5834,7 +5835,7 @@ lambda_param_rule(Parser *p) } arg_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -5845,10 +5846,10 @@ lambda_param_rule(Parser *p) { // NAME expr_ty a; if ( - (a = _PyPegen_name_token(p)) // NAME + (a = _Ta3Pegen_name_token(p)) // NAME ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -5856,7 +5857,7 @@ lambda_param_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_arg ( a -> v . Name . id , NULL , NULL , EXTRA ); + res = _Ta3_arg ( a -> v . Name . id , NULL , NULL , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -5878,10 +5879,10 @@ disjunction_rule(Parser *p) return NULL; } expr_ty res = NULL; - if (_PyPegen_is_memoized(p, disjunction_type, &res)) + if (_Ta3Pegen_is_memoized(p, disjunction_type, &res)) return res; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -5898,7 +5899,7 @@ disjunction_rule(Parser *p) (b = _loop1_89_rule(p)) // (('or' conjunction))+ ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -5906,7 +5907,7 @@ disjunction_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_BoolOp ( Or , CHECK ( _PyPegen_seq_insert_in_front ( p , a , b ) ) , EXTRA ); + res = _Ta3_BoolOp ( Or , CHECK ( _Ta3Pegen_seq_insert_in_front ( p , a , b ) ) , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -5928,7 +5929,7 @@ disjunction_rule(Parser *p) } res = NULL; done: - _PyPegen_insert_memo(p, mark, disjunction_type, res); + _Ta3Pegen_insert_memo(p, mark, disjunction_type, res); return res; } @@ -5940,10 +5941,10 @@ conjunction_rule(Parser *p) return NULL; } expr_ty res = NULL; - if (_PyPegen_is_memoized(p, conjunction_type, &res)) + if (_Ta3Pegen_is_memoized(p, conjunction_type, &res)) return res; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -5960,7 +5961,7 @@ conjunction_rule(Parser *p) (b = _loop1_90_rule(p)) // (('and' inversion))+ ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -5968,7 +5969,7 @@ conjunction_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_BoolOp ( And , CHECK ( _PyPegen_seq_insert_in_front ( p , a , b ) ) , EXTRA ); + res = _Ta3_BoolOp ( And , CHECK ( _Ta3Pegen_seq_insert_in_front ( p , a , b ) ) , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -5990,7 +5991,7 @@ conjunction_rule(Parser *p) } res = NULL; done: - _PyPegen_insert_memo(p, mark, conjunction_type, res); + _Ta3Pegen_insert_memo(p, mark, conjunction_type, res); return res; } @@ -6002,10 +6003,10 @@ inversion_rule(Parser *p) return NULL; } expr_ty res = NULL; - if (_PyPegen_is_memoized(p, inversion_type, &res)) + if (_Ta3Pegen_is_memoized(p, inversion_type, &res)) return res; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -6017,12 +6018,12 @@ inversion_rule(Parser *p) expr_ty a; Token * keyword; if ( - (keyword = _PyPegen_expect_token(p, 525)) // token='not' + (keyword = _Ta3Pegen_expect_token(p, 525)) // token='not' && (a = inversion_rule(p)) // inversion ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -6030,7 +6031,7 @@ inversion_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_UnaryOp ( Not , a , EXTRA ); + res = _Ta3_UnaryOp ( Not , a , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -6052,7 +6053,7 @@ inversion_rule(Parser *p) } res = NULL; done: - _PyPegen_insert_memo(p, mark, inversion_type, res); + _Ta3Pegen_insert_memo(p, mark, inversion_type, res); return res; } @@ -6065,7 +6066,7 @@ comparison_rule(Parser *p) } expr_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -6082,7 +6083,7 @@ comparison_rule(Parser *p) (b = _loop1_91_rule(p)) // compare_op_bitwise_or_pair+ ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -6090,7 +6091,7 @@ comparison_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_Compare ( a , CHECK ( _PyPegen_get_cmpops ( p , b ) ) , CHECK ( _PyPegen_get_exprs ( p , b ) ) , EXTRA ); + res = _Ta3_Compare ( a , CHECK ( _Ta3Pegen_get_cmpops ( p , b ) ) , CHECK ( _Ta3Pegen_get_exprs ( p , b ) ) , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -6262,12 +6263,12 @@ eq_bitwise_or_rule(Parser *p) expr_ty a; Token * literal; if ( - (literal = _PyPegen_expect_token(p, 27)) // token='==' + (literal = _Ta3Pegen_expect_token(p, 27)) // token='==' && (a = bitwise_or_rule(p)) // bitwise_or ) { - res = _PyPegen_cmpop_expr_pair ( p , Eq , a ); + res = _Ta3Pegen_cmpop_expr_pair ( p , Eq , a ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -6299,7 +6300,7 @@ noteq_bitwise_or_rule(Parser *p) (a = bitwise_or_rule(p)) // bitwise_or ) { - res = _PyPegen_cmpop_expr_pair ( p , NotEq , a ); + res = _Ta3Pegen_cmpop_expr_pair ( p , NotEq , a ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -6326,12 +6327,12 @@ lte_bitwise_or_rule(Parser *p) expr_ty a; Token * literal; if ( - (literal = _PyPegen_expect_token(p, 29)) // token='<=' + (literal = _Ta3Pegen_expect_token(p, 29)) // token='<=' && (a = bitwise_or_rule(p)) // bitwise_or ) { - res = _PyPegen_cmpop_expr_pair ( p , LtE , a ); + res = _Ta3Pegen_cmpop_expr_pair ( p , LtE , a ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -6358,12 +6359,12 @@ lt_bitwise_or_rule(Parser *p) expr_ty a; Token * literal; if ( - (literal = _PyPegen_expect_token(p, 20)) // token='<' + (literal = _Ta3Pegen_expect_token(p, 20)) // token='<' && (a = bitwise_or_rule(p)) // bitwise_or ) { - res = _PyPegen_cmpop_expr_pair ( p , Lt , a ); + res = _Ta3Pegen_cmpop_expr_pair ( p , Lt , a ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -6390,12 +6391,12 @@ gte_bitwise_or_rule(Parser *p) expr_ty a; Token * literal; if ( - (literal = _PyPegen_expect_token(p, 30)) // token='>=' + (literal = _Ta3Pegen_expect_token(p, 30)) // token='>=' && (a = bitwise_or_rule(p)) // bitwise_or ) { - res = _PyPegen_cmpop_expr_pair ( p , GtE , a ); + res = _Ta3Pegen_cmpop_expr_pair ( p , GtE , a ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -6422,12 +6423,12 @@ gt_bitwise_or_rule(Parser *p) expr_ty a; Token * literal; if ( - (literal = _PyPegen_expect_token(p, 21)) // token='>' + (literal = _Ta3Pegen_expect_token(p, 21)) // token='>' && (a = bitwise_or_rule(p)) // bitwise_or ) { - res = _PyPegen_cmpop_expr_pair ( p , Gt , a ); + res = _Ta3Pegen_cmpop_expr_pair ( p , Gt , a ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -6455,14 +6456,14 @@ notin_bitwise_or_rule(Parser *p) Token * keyword; Token * keyword_1; if ( - (keyword = _PyPegen_expect_token(p, 525)) // token='not' + (keyword = _Ta3Pegen_expect_token(p, 525)) // token='not' && - (keyword_1 = _PyPegen_expect_token(p, 518)) // token='in' + (keyword_1 = _Ta3Pegen_expect_token(p, 518)) // token='in' && (a = bitwise_or_rule(p)) // bitwise_or ) { - res = _PyPegen_cmpop_expr_pair ( p , NotIn , a ); + res = _Ta3Pegen_cmpop_expr_pair ( p , NotIn , a ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -6489,12 +6490,12 @@ in_bitwise_or_rule(Parser *p) expr_ty a; Token * keyword; if ( - (keyword = _PyPegen_expect_token(p, 518)) // token='in' + (keyword = _Ta3Pegen_expect_token(p, 518)) // token='in' && (a = bitwise_or_rule(p)) // bitwise_or ) { - res = _PyPegen_cmpop_expr_pair ( p , In , a ); + res = _Ta3Pegen_cmpop_expr_pair ( p , In , a ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -6522,14 +6523,14 @@ isnot_bitwise_or_rule(Parser *p) Token * keyword; Token * keyword_1; if ( - (keyword = _PyPegen_expect_token(p, 526)) // token='is' + (keyword = _Ta3Pegen_expect_token(p, 526)) // token='is' && - (keyword_1 = _PyPegen_expect_token(p, 525)) // token='not' + (keyword_1 = _Ta3Pegen_expect_token(p, 525)) // token='not' && (a = bitwise_or_rule(p)) // bitwise_or ) { - res = _PyPegen_cmpop_expr_pair ( p , IsNot , a ); + res = _Ta3Pegen_cmpop_expr_pair ( p , IsNot , a ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -6556,12 +6557,12 @@ is_bitwise_or_rule(Parser *p) expr_ty a; Token * keyword; if ( - (keyword = _PyPegen_expect_token(p, 526)) // token='is' + (keyword = _Ta3Pegen_expect_token(p, 526)) // token='is' && (a = bitwise_or_rule(p)) // bitwise_or ) { - res = _PyPegen_cmpop_expr_pair ( p , Is , a ); + res = _Ta3Pegen_cmpop_expr_pair ( p , Is , a ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -6582,12 +6583,12 @@ static expr_ty bitwise_or_rule(Parser *p) { expr_ty res = NULL; - if (_PyPegen_is_memoized(p, bitwise_or_type, &res)) + if (_Ta3Pegen_is_memoized(p, bitwise_or_type, &res)) return res; int mark = p->mark; int resmark = p->mark; while (1) { - int tmpvar_1 = _PyPegen_update_memo(p, mark, bitwise_or_type, res); + int tmpvar_1 = _Ta3Pegen_update_memo(p, mark, bitwise_or_type, res); if (tmpvar_1) { return res; } @@ -6609,7 +6610,7 @@ bitwise_or_raw(Parser *p) } expr_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -6624,12 +6625,12 @@ bitwise_or_raw(Parser *p) if ( (a = bitwise_or_rule(p)) // bitwise_or && - (literal = _PyPegen_expect_token(p, 18)) // token='|' + (literal = _Ta3Pegen_expect_token(p, 18)) // token='|' && (b = bitwise_xor_rule(p)) // bitwise_xor ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -6637,7 +6638,7 @@ bitwise_or_raw(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_BinOp ( a , BitOr , b , EXTRA ); + res = _Ta3_BinOp ( a , BitOr , b , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -6669,12 +6670,12 @@ static expr_ty bitwise_xor_rule(Parser *p) { expr_ty res = NULL; - if (_PyPegen_is_memoized(p, bitwise_xor_type, &res)) + if (_Ta3Pegen_is_memoized(p, bitwise_xor_type, &res)) return res; int mark = p->mark; int resmark = p->mark; while (1) { - int tmpvar_2 = _PyPegen_update_memo(p, mark, bitwise_xor_type, res); + int tmpvar_2 = _Ta3Pegen_update_memo(p, mark, bitwise_xor_type, res); if (tmpvar_2) { return res; } @@ -6696,7 +6697,7 @@ bitwise_xor_raw(Parser *p) } expr_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -6711,12 +6712,12 @@ bitwise_xor_raw(Parser *p) if ( (a = bitwise_xor_rule(p)) // bitwise_xor && - (literal = _PyPegen_expect_token(p, 32)) // token='^' + (literal = _Ta3Pegen_expect_token(p, 32)) // token='^' && (b = bitwise_and_rule(p)) // bitwise_and ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -6724,7 +6725,7 @@ bitwise_xor_raw(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_BinOp ( a , BitXor , b , EXTRA ); + res = _Ta3_BinOp ( a , BitXor , b , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -6756,12 +6757,12 @@ static expr_ty bitwise_and_rule(Parser *p) { expr_ty res = NULL; - if (_PyPegen_is_memoized(p, bitwise_and_type, &res)) + if (_Ta3Pegen_is_memoized(p, bitwise_and_type, &res)) return res; int mark = p->mark; int resmark = p->mark; while (1) { - int tmpvar_3 = _PyPegen_update_memo(p, mark, bitwise_and_type, res); + int tmpvar_3 = _Ta3Pegen_update_memo(p, mark, bitwise_and_type, res); if (tmpvar_3) { return res; } @@ -6783,7 +6784,7 @@ bitwise_and_raw(Parser *p) } expr_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -6798,12 +6799,12 @@ bitwise_and_raw(Parser *p) if ( (a = bitwise_and_rule(p)) // bitwise_and && - (literal = _PyPegen_expect_token(p, 19)) // token='&' + (literal = _Ta3Pegen_expect_token(p, 19)) // token='&' && (b = shift_expr_rule(p)) // shift_expr ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -6811,7 +6812,7 @@ bitwise_and_raw(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_BinOp ( a , BitAnd , b , EXTRA ); + res = _Ta3_BinOp ( a , BitAnd , b , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -6843,12 +6844,12 @@ static expr_ty shift_expr_rule(Parser *p) { expr_ty res = NULL; - if (_PyPegen_is_memoized(p, shift_expr_type, &res)) + if (_Ta3Pegen_is_memoized(p, shift_expr_type, &res)) return res; int mark = p->mark; int resmark = p->mark; while (1) { - int tmpvar_4 = _PyPegen_update_memo(p, mark, shift_expr_type, res); + int tmpvar_4 = _Ta3Pegen_update_memo(p, mark, shift_expr_type, res); if (tmpvar_4) { return res; } @@ -6870,7 +6871,7 @@ shift_expr_raw(Parser *p) } expr_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -6885,12 +6886,12 @@ shift_expr_raw(Parser *p) if ( (a = shift_expr_rule(p)) // shift_expr && - (literal = _PyPegen_expect_token(p, 33)) // token='<<' + (literal = _Ta3Pegen_expect_token(p, 33)) // token='<<' && (b = sum_rule(p)) // sum ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -6898,7 +6899,7 @@ shift_expr_raw(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_BinOp ( a , LShift , b , EXTRA ); + res = _Ta3_BinOp ( a , LShift , b , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -6914,12 +6915,12 @@ shift_expr_raw(Parser *p) if ( (a = shift_expr_rule(p)) // shift_expr && - (literal = _PyPegen_expect_token(p, 34)) // token='>>' + (literal = _Ta3Pegen_expect_token(p, 34)) // token='>>' && (b = sum_rule(p)) // sum ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -6927,7 +6928,7 @@ shift_expr_raw(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_BinOp ( a , RShift , b , EXTRA ); + res = _Ta3_BinOp ( a , RShift , b , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -6959,12 +6960,12 @@ static expr_ty sum_rule(Parser *p) { expr_ty res = NULL; - if (_PyPegen_is_memoized(p, sum_type, &res)) + if (_Ta3Pegen_is_memoized(p, sum_type, &res)) return res; int mark = p->mark; int resmark = p->mark; while (1) { - int tmpvar_5 = _PyPegen_update_memo(p, mark, sum_type, res); + int tmpvar_5 = _Ta3Pegen_update_memo(p, mark, sum_type, res); if (tmpvar_5) { return res; } @@ -6986,7 +6987,7 @@ sum_raw(Parser *p) } expr_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -7001,12 +7002,12 @@ sum_raw(Parser *p) if ( (a = sum_rule(p)) // sum && - (literal = _PyPegen_expect_token(p, 14)) // token='+' + (literal = _Ta3Pegen_expect_token(p, 14)) // token='+' && (b = term_rule(p)) // term ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -7014,7 +7015,7 @@ sum_raw(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_BinOp ( a , Add , b , EXTRA ); + res = _Ta3_BinOp ( a , Add , b , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -7030,12 +7031,12 @@ sum_raw(Parser *p) if ( (a = sum_rule(p)) // sum && - (literal = _PyPegen_expect_token(p, 15)) // token='-' + (literal = _Ta3Pegen_expect_token(p, 15)) // token='-' && (b = term_rule(p)) // term ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -7043,7 +7044,7 @@ sum_raw(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_BinOp ( a , Sub , b , EXTRA ); + res = _Ta3_BinOp ( a , Sub , b , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -7081,12 +7082,12 @@ static expr_ty term_rule(Parser *p) { expr_ty res = NULL; - if (_PyPegen_is_memoized(p, term_type, &res)) + if (_Ta3Pegen_is_memoized(p, term_type, &res)) return res; int mark = p->mark; int resmark = p->mark; while (1) { - int tmpvar_6 = _PyPegen_update_memo(p, mark, term_type, res); + int tmpvar_6 = _Ta3Pegen_update_memo(p, mark, term_type, res); if (tmpvar_6) { return res; } @@ -7108,7 +7109,7 @@ term_raw(Parser *p) } expr_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -7123,12 +7124,12 @@ term_raw(Parser *p) if ( (a = term_rule(p)) // term && - (literal = _PyPegen_expect_token(p, 16)) // token='*' + (literal = _Ta3Pegen_expect_token(p, 16)) // token='*' && (b = factor_rule(p)) // factor ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -7136,7 +7137,7 @@ term_raw(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_BinOp ( a , Mult , b , EXTRA ); + res = _Ta3_BinOp ( a , Mult , b , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -7152,12 +7153,12 @@ term_raw(Parser *p) if ( (a = term_rule(p)) // term && - (literal = _PyPegen_expect_token(p, 17)) // token='/' + (literal = _Ta3Pegen_expect_token(p, 17)) // token='/' && (b = factor_rule(p)) // factor ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -7165,7 +7166,7 @@ term_raw(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_BinOp ( a , Div , b , EXTRA ); + res = _Ta3_BinOp ( a , Div , b , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -7181,12 +7182,12 @@ term_raw(Parser *p) if ( (a = term_rule(p)) // term && - (literal = _PyPegen_expect_token(p, 47)) // token='//' + (literal = _Ta3Pegen_expect_token(p, 47)) // token='//' && (b = factor_rule(p)) // factor ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -7194,7 +7195,7 @@ term_raw(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_BinOp ( a , FloorDiv , b , EXTRA ); + res = _Ta3_BinOp ( a , FloorDiv , b , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -7210,12 +7211,12 @@ term_raw(Parser *p) if ( (a = term_rule(p)) // term && - (literal = _PyPegen_expect_token(p, 24)) // token='%' + (literal = _Ta3Pegen_expect_token(p, 24)) // token='%' && (b = factor_rule(p)) // factor ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -7223,7 +7224,7 @@ term_raw(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_BinOp ( a , Mod , b , EXTRA ); + res = _Ta3_BinOp ( a , Mod , b , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -7239,12 +7240,12 @@ term_raw(Parser *p) if ( (a = term_rule(p)) // term && - (literal = _PyPegen_expect_token(p, 49)) // token='@' + (literal = _Ta3Pegen_expect_token(p, 49)) // token='@' && (b = factor_rule(p)) // factor ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -7252,7 +7253,7 @@ term_raw(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 = CHECK_VERSION ( 5 , "The '@' operator is" , _Py_BinOp ( a , MatMult , b , EXTRA ) ); + res = CHECK_VERSION ( 5 , "The '@' operator is" , _Ta3_BinOp ( a , MatMult , b , EXTRA ) ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -7285,10 +7286,10 @@ factor_rule(Parser *p) return NULL; } expr_ty res = NULL; - if (_PyPegen_is_memoized(p, factor_type, &res)) + if (_Ta3Pegen_is_memoized(p, factor_type, &res)) return res; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -7300,12 +7301,12 @@ factor_rule(Parser *p) expr_ty a; Token * literal; if ( - (literal = _PyPegen_expect_token(p, 14)) // token='+' + (literal = _Ta3Pegen_expect_token(p, 14)) // token='+' && (a = factor_rule(p)) // factor ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -7313,7 +7314,7 @@ factor_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_UnaryOp ( UAdd , a , EXTRA ); + res = _Ta3_UnaryOp ( UAdd , a , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -7326,12 +7327,12 @@ factor_rule(Parser *p) expr_ty a; Token * literal; if ( - (literal = _PyPegen_expect_token(p, 15)) // token='-' + (literal = _Ta3Pegen_expect_token(p, 15)) // token='-' && (a = factor_rule(p)) // factor ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -7339,7 +7340,7 @@ factor_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_UnaryOp ( USub , a , EXTRA ); + res = _Ta3_UnaryOp ( USub , a , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -7352,12 +7353,12 @@ factor_rule(Parser *p) expr_ty a; Token * literal; if ( - (literal = _PyPegen_expect_token(p, 31)) // token='~' + (literal = _Ta3Pegen_expect_token(p, 31)) // token='~' && (a = factor_rule(p)) // factor ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -7365,7 +7366,7 @@ factor_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_UnaryOp ( Invert , a , EXTRA ); + res = _Ta3_UnaryOp ( Invert , a , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -7387,7 +7388,7 @@ factor_rule(Parser *p) } res = NULL; done: - _PyPegen_insert_memo(p, mark, factor_type, res); + _Ta3Pegen_insert_memo(p, mark, factor_type, res); return res; } @@ -7400,7 +7401,7 @@ power_rule(Parser *p) } expr_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -7415,12 +7416,12 @@ power_rule(Parser *p) if ( (a = await_primary_rule(p)) // await_primary && - (literal = _PyPegen_expect_token(p, 35)) // token='**' + (literal = _Ta3Pegen_expect_token(p, 35)) // token='**' && (b = factor_rule(p)) // factor ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -7428,7 +7429,7 @@ power_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_BinOp ( a , Pow , b , EXTRA ); + res = _Ta3_BinOp ( a , Pow , b , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -7461,10 +7462,10 @@ await_primary_rule(Parser *p) return NULL; } expr_ty res = NULL; - if (_PyPegen_is_memoized(p, await_primary_type, &res)) + if (_Ta3Pegen_is_memoized(p, await_primary_type, &res)) return res; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -7476,12 +7477,12 @@ await_primary_rule(Parser *p) expr_ty a; Token * await_var; if ( - (await_var = _PyPegen_expect_token(p, AWAIT)) // token='AWAIT' + (await_var = _Ta3Pegen_expect_token(p, AWAIT)) // token='AWAIT' && (a = primary_rule(p)) // primary ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -7489,7 +7490,7 @@ await_primary_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 = CHECK_VERSION ( 5 , "Await expressions are" , _Py_Await ( a , EXTRA ) ); + res = CHECK_VERSION ( 5 , "Await expressions are" , _Ta3_Await ( a , EXTRA ) ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -7511,7 +7512,7 @@ await_primary_rule(Parser *p) } res = NULL; done: - _PyPegen_insert_memo(p, mark, await_primary_type, res); + _Ta3Pegen_insert_memo(p, mark, await_primary_type, res); return res; } @@ -7527,12 +7528,12 @@ static expr_ty primary_rule(Parser *p) { expr_ty res = NULL; - if (_PyPegen_is_memoized(p, primary_type, &res)) + if (_Ta3Pegen_is_memoized(p, primary_type, &res)) return res; int mark = p->mark; int resmark = p->mark; while (1) { - int tmpvar_7 = _PyPegen_update_memo(p, mark, primary_type, res); + int tmpvar_7 = _Ta3Pegen_update_memo(p, mark, primary_type, res); if (tmpvar_7) { return res; } @@ -7554,7 +7555,7 @@ primary_raw(Parser *p) } expr_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -7569,12 +7570,12 @@ primary_raw(Parser *p) if ( (a = primary_rule(p)) // primary && - (literal = _PyPegen_expect_token(p, 23)) // token='.' + (literal = _Ta3Pegen_expect_token(p, 23)) // token='.' && - (b = _PyPegen_name_token(p)) // NAME + (b = _Ta3Pegen_name_token(p)) // NAME ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -7582,7 +7583,7 @@ primary_raw(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_Attribute ( a , b -> v . Name . id , Load , EXTRA ); + res = _Ta3_Attribute ( a , b -> v . Name . id , Load , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -7600,7 +7601,7 @@ primary_raw(Parser *p) (b = genexp_rule(p)) // genexp ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -7608,7 +7609,7 @@ primary_raw(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_Call ( a , CHECK ( _PyPegen_singleton_seq ( p , b ) ) , NULL , EXTRA ); + res = _Ta3_Call ( a , CHECK ( _Ta3Pegen_singleton_seq ( p , b ) ) , NULL , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -7625,14 +7626,14 @@ primary_raw(Parser *p) if ( (a = primary_rule(p)) // primary && - (literal = _PyPegen_expect_token(p, 7)) // token='(' + (literal = _Ta3Pegen_expect_token(p, 7)) // token='(' && (b = arguments_rule(p), 1) // arguments? && - (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + (literal_1 = _Ta3Pegen_expect_token(p, 8)) // token=')' ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -7640,7 +7641,7 @@ primary_raw(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_Call ( a , ( b ) ? ( ( expr_ty ) b ) -> v . Call . args : NULL , ( b ) ? ( ( expr_ty ) b ) -> v . Call . keywords : NULL , EXTRA ); + res = _Ta3_Call ( a , ( b ) ? ( ( expr_ty ) b ) -> v . Call . args : NULL , ( b ) ? ( ( expr_ty ) b ) -> v . Call . keywords : NULL , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -7657,14 +7658,14 @@ primary_raw(Parser *p) if ( (a = primary_rule(p)) // primary && - (literal = _PyPegen_expect_token(p, 9)) // token='[' + (literal = _Ta3Pegen_expect_token(p, 9)) // token='[' && (b = slices_rule(p)) // slices && - (literal_1 = _PyPegen_expect_token(p, 10)) // token=']' + (literal_1 = _Ta3Pegen_expect_token(p, 10)) // token=']' ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -7672,7 +7673,7 @@ primary_raw(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_Subscript ( a , b , Load , EXTRA ); + res = _Ta3_Subscript ( a , b , Load , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -7706,7 +7707,7 @@ slices_rule(Parser *p) } expr_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -7719,7 +7720,7 @@ slices_rule(Parser *p) if ( (a = slice_rule(p)) // slice && - _PyPegen_lookahead_with_int(0, _PyPegen_expect_token, p, 12) // token=',' + _Ta3Pegen_lookahead_with_int(0, _Ta3Pegen_expect_token, p, 12) // token=',' ) { res = a; @@ -7738,10 +7739,10 @@ slices_rule(Parser *p) if ( (a = _gather_93_rule(p)) // ','.slice+ && - (opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + (opt_var = _Ta3Pegen_expect_token(p, 12), 1) // ','? ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -7749,7 +7750,7 @@ slices_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_Tuple ( a , Load , EXTRA ); + res = _Ta3_Tuple ( a , Load , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -7772,7 +7773,7 @@ slice_rule(Parser *p) } expr_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -7788,14 +7789,14 @@ slice_rule(Parser *p) if ( (a = expression_rule(p), 1) // expression? && - (literal = _PyPegen_expect_token(p, 11)) // token=':' + (literal = _Ta3Pegen_expect_token(p, 11)) // token=':' && (b = expression_rule(p), 1) // expression? && (c = _tmp_95_rule(p), 1) // [':' expression?] ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -7803,7 +7804,7 @@ slice_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_Slice ( a , b , c , EXTRA ); + res = _Ta3_Slice ( a , b , c , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -7852,7 +7853,7 @@ atom_rule(Parser *p) } expr_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -7863,7 +7864,7 @@ atom_rule(Parser *p) { // NAME expr_ty name_var; if ( - (name_var = _PyPegen_name_token(p)) // NAME + (name_var = _Ta3Pegen_name_token(p)) // NAME ) { res = name_var; @@ -7874,10 +7875,10 @@ atom_rule(Parser *p) { // 'True' Token * keyword; if ( - (keyword = _PyPegen_expect_token(p, 527)) // token='True' + (keyword = _Ta3Pegen_expect_token(p, 527)) // token='True' ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -7885,7 +7886,7 @@ atom_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_Constant ( Py_True , NULL , EXTRA ); + res = _Ta3_Constant ( Py_True , NULL , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -7897,10 +7898,10 @@ atom_rule(Parser *p) { // 'False' Token * keyword; if ( - (keyword = _PyPegen_expect_token(p, 528)) // token='False' + (keyword = _Ta3Pegen_expect_token(p, 528)) // token='False' ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -7908,7 +7909,7 @@ atom_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_Constant ( Py_False , NULL , EXTRA ); + res = _Ta3_Constant ( Py_False , NULL , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -7920,10 +7921,10 @@ atom_rule(Parser *p) { // 'None' Token * keyword; if ( - (keyword = _PyPegen_expect_token(p, 529)) // token='None' + (keyword = _Ta3Pegen_expect_token(p, 529)) // token='None' ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -7931,7 +7932,7 @@ atom_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_Constant ( Py_None , NULL , EXTRA ); + res = _Ta3_Constant ( Py_None , NULL , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -7943,7 +7944,7 @@ atom_rule(Parser *p) { // '__new_parser__' Token * keyword; if ( - (keyword = _PyPegen_expect_token(p, 530)) // token='__new_parser__' + (keyword = _Ta3Pegen_expect_token(p, 530)) // token='__new_parser__' ) { res = RAISE_SYNTAX_ERROR ( "You found it!" ); @@ -7958,7 +7959,7 @@ atom_rule(Parser *p) { // &STRING strings expr_ty strings_var; if ( - _PyPegen_lookahead(1, _PyPegen_string_token, p) + _Ta3Pegen_lookahead(1, _Ta3Pegen_string_token, p) && (strings_var = strings_rule(p)) // strings ) @@ -7971,7 +7972,7 @@ atom_rule(Parser *p) { // NUMBER expr_ty number_var; if ( - (number_var = _PyPegen_number_token(p)) // NUMBER + (number_var = _Ta3Pegen_number_token(p)) // NUMBER ) { res = number_var; @@ -7982,7 +7983,7 @@ atom_rule(Parser *p) { // &'(' (tuple | group | genexp) void *_tmp_96_var; if ( - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 7) // token='(' + _Ta3Pegen_lookahead_with_int(1, _Ta3Pegen_expect_token, p, 7) // token='(' && (_tmp_96_var = _tmp_96_rule(p)) // tuple | group | genexp ) @@ -7995,7 +7996,7 @@ atom_rule(Parser *p) { // &'[' (list | listcomp) void *_tmp_97_var; if ( - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 9) // token='[' + _Ta3Pegen_lookahead_with_int(1, _Ta3Pegen_expect_token, p, 9) // token='[' && (_tmp_97_var = _tmp_97_rule(p)) // list | listcomp ) @@ -8008,7 +8009,7 @@ atom_rule(Parser *p) { // &'{' (dict | set | dictcomp | setcomp) void *_tmp_98_var; if ( - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 25) // token='{' + _Ta3Pegen_lookahead_with_int(1, _Ta3Pegen_expect_token, p, 25) // token='{' && (_tmp_98_var = _tmp_98_rule(p)) // dict | set | dictcomp | setcomp ) @@ -8021,10 +8022,10 @@ atom_rule(Parser *p) { // '...' Token * literal; if ( - (literal = _PyPegen_expect_token(p, 52)) // token='...' + (literal = _Ta3Pegen_expect_token(p, 52)) // token='...' ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -8032,7 +8033,7 @@ atom_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_Constant ( Py_Ellipsis , NULL , EXTRA ); + res = _Ta3_Constant ( Py_Ellipsis , NULL , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -8054,7 +8055,7 @@ strings_rule(Parser *p) return NULL; } expr_ty res = NULL; - if (_PyPegen_is_memoized(p, strings_type, &res)) + if (_Ta3Pegen_is_memoized(p, strings_type, &res)) return res; int mark = p->mark; { // STRING+ @@ -8063,7 +8064,7 @@ strings_rule(Parser *p) (a = _loop1_99_rule(p)) // STRING+ ) { - res = _PyPegen_concatenate_strings ( p , a ); + res = _Ta3Pegen_concatenate_strings ( p , a ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -8074,7 +8075,7 @@ strings_rule(Parser *p) } res = NULL; done: - _PyPegen_insert_memo(p, mark, strings_type, res); + _Ta3Pegen_insert_memo(p, mark, strings_type, res); return res; } @@ -8087,7 +8088,7 @@ list_rule(Parser *p) } expr_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -8100,14 +8101,14 @@ list_rule(Parser *p) Token * literal; Token * literal_1; if ( - (literal = _PyPegen_expect_token(p, 9)) // token='[' + (literal = _Ta3Pegen_expect_token(p, 9)) // token='[' && (a = star_named_expressions_rule(p), 1) // star_named_expressions? && - (literal_1 = _PyPegen_expect_token(p, 10)) // token=']' + (literal_1 = _Ta3Pegen_expect_token(p, 10)) // token=']' ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -8115,7 +8116,7 @@ list_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_List ( a , Load , EXTRA ); + res = _Ta3_List ( a , Load , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -8138,7 +8139,7 @@ listcomp_rule(Parser *p) } expr_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -8152,16 +8153,16 @@ listcomp_rule(Parser *p) Token * literal; Token * literal_1; if ( - (literal = _PyPegen_expect_token(p, 9)) // token='[' + (literal = _Ta3Pegen_expect_token(p, 9)) // token='[' && (a = named_expression_rule(p)) // named_expression && (b = for_if_clauses_rule(p)) // for_if_clauses && - (literal_1 = _PyPegen_expect_token(p, 10)) // token=']' + (literal_1 = _Ta3Pegen_expect_token(p, 10)) // token=']' ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -8169,7 +8170,7 @@ listcomp_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_ListComp ( a , b , EXTRA ); + res = _Ta3_ListComp ( a , b , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -8203,7 +8204,7 @@ tuple_rule(Parser *p) } expr_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -8216,14 +8217,14 @@ tuple_rule(Parser *p) Token * literal; Token * literal_1; if ( - (literal = _PyPegen_expect_token(p, 7)) // token='(' + (literal = _Ta3Pegen_expect_token(p, 7)) // token='(' && (a = _tmp_100_rule(p), 1) // [star_named_expression ',' star_named_expressions?] && - (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + (literal_1 = _Ta3Pegen_expect_token(p, 8)) // token=')' ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -8231,7 +8232,7 @@ tuple_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_Tuple ( a , Load , EXTRA ); + res = _Ta3_Tuple ( a , Load , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -8259,11 +8260,11 @@ group_rule(Parser *p) Token * literal; Token * literal_1; if ( - (literal = _PyPegen_expect_token(p, 7)) // token='(' + (literal = _Ta3Pegen_expect_token(p, 7)) // token='(' && (a = _tmp_101_rule(p)) // yield_expr | named_expression && - (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + (literal_1 = _Ta3Pegen_expect_token(p, 8)) // token=')' ) { res = a; @@ -8289,7 +8290,7 @@ genexp_rule(Parser *p) } expr_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -8303,16 +8304,16 @@ genexp_rule(Parser *p) Token * literal; Token * literal_1; if ( - (literal = _PyPegen_expect_token(p, 7)) // token='(' + (literal = _Ta3Pegen_expect_token(p, 7)) // token='(' && (a = expression_rule(p)) // expression && (b = for_if_clauses_rule(p)) // for_if_clauses && - (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + (literal_1 = _Ta3Pegen_expect_token(p, 8)) // token=')' ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -8320,7 +8321,7 @@ genexp_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_GeneratorExp ( a , b , EXTRA ); + res = _Ta3_GeneratorExp ( a , b , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -8354,7 +8355,7 @@ set_rule(Parser *p) } expr_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -8367,14 +8368,14 @@ set_rule(Parser *p) Token * literal; Token * literal_1; if ( - (literal = _PyPegen_expect_token(p, 25)) // token='{' + (literal = _Ta3Pegen_expect_token(p, 25)) // token='{' && (a = expressions_list_rule(p)) // expressions_list && - (literal_1 = _PyPegen_expect_token(p, 26)) // token='}' + (literal_1 = _Ta3Pegen_expect_token(p, 26)) // token='}' ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -8382,7 +8383,7 @@ set_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_Set ( a , EXTRA ); + res = _Ta3_Set ( a , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -8405,7 +8406,7 @@ setcomp_rule(Parser *p) } expr_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -8419,16 +8420,16 @@ setcomp_rule(Parser *p) Token * literal; Token * literal_1; if ( - (literal = _PyPegen_expect_token(p, 25)) // token='{' + (literal = _Ta3Pegen_expect_token(p, 25)) // token='{' && (a = expression_rule(p)) // expression && (b = for_if_clauses_rule(p)) // for_if_clauses && - (literal_1 = _PyPegen_expect_token(p, 26)) // token='}' + (literal_1 = _Ta3Pegen_expect_token(p, 26)) // token='}' ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -8436,7 +8437,7 @@ setcomp_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_SetComp ( a , b , EXTRA ); + res = _Ta3_SetComp ( a , b , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -8470,7 +8471,7 @@ dict_rule(Parser *p) } expr_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -8483,14 +8484,14 @@ dict_rule(Parser *p) Token * literal; Token * literal_1; if ( - (literal = _PyPegen_expect_token(p, 25)) // token='{' + (literal = _Ta3Pegen_expect_token(p, 25)) // token='{' && (a = kvpairs_rule(p), 1) // kvpairs? && - (literal_1 = _PyPegen_expect_token(p, 26)) // token='}' + (literal_1 = _Ta3Pegen_expect_token(p, 26)) // token='}' ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -8498,7 +8499,7 @@ dict_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_Dict ( CHECK ( _PyPegen_get_keys ( p , a ) ) , CHECK ( _PyPegen_get_values ( p , a ) ) , EXTRA ); + res = _Ta3_Dict ( CHECK ( _Ta3Pegen_get_keys ( p , a ) ) , CHECK ( _Ta3Pegen_get_values ( p , a ) ) , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -8521,7 +8522,7 @@ dictcomp_rule(Parser *p) } expr_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -8535,16 +8536,16 @@ dictcomp_rule(Parser *p) Token * literal; Token * literal_1; if ( - (literal = _PyPegen_expect_token(p, 25)) // token='{' + (literal = _Ta3Pegen_expect_token(p, 25)) // token='{' && (a = kvpair_rule(p)) // kvpair && (b = for_if_clauses_rule(p)) // for_if_clauses && - (literal_1 = _PyPegen_expect_token(p, 26)) // token='}' + (literal_1 = _Ta3Pegen_expect_token(p, 26)) // token='}' ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -8552,7 +8553,7 @@ dictcomp_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_DictComp ( a -> key , a -> value , b , EXTRA ); + res = _Ta3_DictComp ( a -> key , a -> value , b , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -8582,7 +8583,7 @@ kvpairs_rule(Parser *p) if ( (a = _gather_102_rule(p)) // ','.kvpair+ && - (opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + (opt_var = _Ta3Pegen_expect_token(p, 12), 1) // ','? ) { res = a; @@ -8612,12 +8613,12 @@ kvpair_rule(Parser *p) expr_ty a; Token * literal; if ( - (literal = _PyPegen_expect_token(p, 35)) // token='**' + (literal = _Ta3Pegen_expect_token(p, 35)) // token='**' && (a = bitwise_or_rule(p)) // bitwise_or ) { - res = _PyPegen_key_value_pair ( p , NULL , a ); + res = _Ta3Pegen_key_value_pair ( p , NULL , a ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -8633,12 +8634,12 @@ kvpair_rule(Parser *p) if ( (a = expression_rule(p)) // expression && - (literal = _PyPegen_expect_token(p, 11)) // token=':' + (literal = _Ta3Pegen_expect_token(p, 11)) // token=':' && (b = expression_rule(p)) // expression ) { - res = _PyPegen_key_value_pair ( p , a , b ); + res = _Ta3Pegen_key_value_pair ( p , a , b ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -8696,20 +8697,20 @@ for_if_clause_rule(Parser *p) Token * keyword; Token * keyword_1; if ( - (async_var = _PyPegen_expect_token(p, ASYNC)) // token='ASYNC' + (async_var = _Ta3Pegen_expect_token(p, ASYNC)) // token='ASYNC' && - (keyword = _PyPegen_expect_token(p, 517)) // token='for' + (keyword = _Ta3Pegen_expect_token(p, 517)) // token='for' && (a = star_targets_rule(p)) // star_targets && - (keyword_1 = _PyPegen_expect_token(p, 518)) // token='in' + (keyword_1 = _Ta3Pegen_expect_token(p, 518)) // token='in' && (b = disjunction_rule(p)) // disjunction && (c = _loop0_105_rule(p)) // (('if' disjunction))* ) { - res = CHECK_VERSION ( 6 , "Async comprehensions are" , _Py_comprehension ( a , b , c , 1 , p -> arena ) ); + res = CHECK_VERSION ( 6 , "Async comprehensions are" , _Ta3_comprehension ( a , b , c , 1 , p -> arena ) ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -8725,18 +8726,18 @@ for_if_clause_rule(Parser *p) Token * keyword; Token * keyword_1; if ( - (keyword = _PyPegen_expect_token(p, 517)) // token='for' + (keyword = _Ta3Pegen_expect_token(p, 517)) // token='for' && (a = star_targets_rule(p)) // star_targets && - (keyword_1 = _PyPegen_expect_token(p, 518)) // token='in' + (keyword_1 = _Ta3Pegen_expect_token(p, 518)) // token='in' && (b = disjunction_rule(p)) // disjunction && (c = _loop0_106_rule(p)) // (('if' disjunction))* ) { - res = _Py_comprehension ( a , b , c , 0 , p -> arena ); + res = _Ta3_comprehension ( a , b , c , 0 , p -> arena ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -8759,7 +8760,7 @@ yield_expr_rule(Parser *p) } expr_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -8772,14 +8773,14 @@ yield_expr_rule(Parser *p) Token * keyword; Token * keyword_1; if ( - (keyword = _PyPegen_expect_token(p, 504)) // token='yield' + (keyword = _Ta3Pegen_expect_token(p, 504)) // token='yield' && - (keyword_1 = _PyPegen_expect_token(p, 514)) // token='from' + (keyword_1 = _Ta3Pegen_expect_token(p, 514)) // token='from' && (a = expression_rule(p)) // expression ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -8787,7 +8788,7 @@ yield_expr_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_YieldFrom ( a , EXTRA ); + res = _Ta3_YieldFrom ( a , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -8800,12 +8801,12 @@ yield_expr_rule(Parser *p) void *a; Token * keyword; if ( - (keyword = _PyPegen_expect_token(p, 504)) // token='yield' + (keyword = _Ta3Pegen_expect_token(p, 504)) // token='yield' && (a = star_expressions_rule(p), 1) // star_expressions? ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -8813,7 +8814,7 @@ yield_expr_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_Yield ( a , EXTRA ); + res = _Ta3_Yield ( a , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -8835,7 +8836,7 @@ arguments_rule(Parser *p) return NULL; } expr_ty res = NULL; - if (_PyPegen_is_memoized(p, arguments_type, &res)) + if (_Ta3Pegen_is_memoized(p, arguments_type, &res)) return res; int mark = p->mark; { // args ','? &')' @@ -8845,9 +8846,9 @@ arguments_rule(Parser *p) if ( (a = args_rule(p)) // args && - (opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + (opt_var = _Ta3Pegen_expect_token(p, 12), 1) // ','? && - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 8) // token=')' + _Ta3Pegen_lookahead_with_int(1, _Ta3Pegen_expect_token, p, 8) // token=')' ) { res = a; @@ -8872,7 +8873,7 @@ arguments_rule(Parser *p) } res = NULL; done: - _PyPegen_insert_memo(p, mark, arguments_type, res); + _Ta3Pegen_insert_memo(p, mark, arguments_type, res); return res; } @@ -8885,7 +8886,7 @@ args_rule(Parser *p) } expr_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -8902,7 +8903,7 @@ args_rule(Parser *p) (b = _tmp_107_rule(p), 1) // [',' args] ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -8910,7 +8911,7 @@ args_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_Call ( _PyPegen_dummy_name ( p ) , ( b ) ? CHECK ( _PyPegen_seq_insert_in_front ( p , a , ( ( expr_ty ) b ) -> v . Call . args ) ) : CHECK ( _PyPegen_singleton_seq ( p , a ) ) , ( b ) ? ( ( expr_ty ) b ) -> v . Call . keywords : NULL , EXTRA ); + res = _Ta3_Call ( _Ta3Pegen_dummy_name ( p ) , ( b ) ? CHECK ( _Ta3Pegen_seq_insert_in_front ( p , a , ( ( expr_ty ) b ) -> v . Call . args ) ) : CHECK ( _Ta3Pegen_singleton_seq ( p , a ) ) , ( b ) ? ( ( expr_ty ) b ) -> v . Call . keywords : NULL , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -8925,7 +8926,7 @@ args_rule(Parser *p) (a = kwargs_rule(p)) // kwargs ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -8933,7 +8934,7 @@ args_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_Call ( _PyPegen_dummy_name ( p ) , CHECK_NULL_ALLOWED ( _PyPegen_seq_extract_starred_exprs ( p , a ) ) , CHECK_NULL_ALLOWED ( _PyPegen_seq_delete_starred_exprs ( p , a ) ) , EXTRA ); + res = _Ta3_Call ( _Ta3Pegen_dummy_name ( p ) , CHECK_NULL_ALLOWED ( _Ta3Pegen_seq_extract_starred_exprs ( p , a ) ) , CHECK_NULL_ALLOWED ( _Ta3Pegen_seq_delete_starred_exprs ( p , a ) ) , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -8951,7 +8952,7 @@ args_rule(Parser *p) (b = _tmp_108_rule(p), 1) // [',' args] ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -8959,7 +8960,7 @@ args_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_Call ( _PyPegen_dummy_name ( p ) , ( b ) ? CHECK ( _PyPegen_seq_insert_in_front ( p , a , ( ( expr_ty ) b ) -> v . Call . args ) ) : CHECK ( _PyPegen_singleton_seq ( p , a ) ) , ( b ) ? ( ( expr_ty ) b ) -> v . Call . keywords : NULL , EXTRA ); + res = _Ta3_Call ( _Ta3Pegen_dummy_name ( p ) , ( b ) ? CHECK ( _Ta3Pegen_seq_insert_in_front ( p , a , ( ( expr_ty ) b ) -> v . Call . args ) ) : CHECK ( _Ta3Pegen_singleton_seq ( p , a ) ) , ( b ) ? ( ( expr_ty ) b ) -> v . Call . keywords : NULL , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -8992,12 +8993,12 @@ kwargs_rule(Parser *p) if ( (a = _gather_109_rule(p)) // ','.kwarg_or_starred+ && - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && (b = _gather_111_rule(p)) // ','.kwarg_or_double_starred+ ) { - res = _PyPegen_join_sequences ( p , a , b ); + res = _Ta3Pegen_join_sequences ( p , a , b ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -9042,7 +9043,7 @@ starred_expression_rule(Parser *p) } expr_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -9054,12 +9055,12 @@ starred_expression_rule(Parser *p) expr_ty a; Token * literal; if ( - (literal = _PyPegen_expect_token(p, 16)) // token='*' + (literal = _Ta3Pegen_expect_token(p, 16)) // token='*' && (a = expression_rule(p)) // expression ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -9067,7 +9068,7 @@ starred_expression_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_Starred ( a , Load , EXTRA ); + res = _Ta3_Starred ( a , Load , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -9090,7 +9091,7 @@ kwarg_or_starred_rule(Parser *p) } KeywordOrStarred* res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -9103,14 +9104,14 @@ kwarg_or_starred_rule(Parser *p) expr_ty b; Token * literal; if ( - (a = _PyPegen_name_token(p)) // NAME + (a = _Ta3Pegen_name_token(p)) // NAME && - (literal = _PyPegen_expect_token(p, 22)) // token='=' + (literal = _Ta3Pegen_expect_token(p, 22)) // token='=' && (b = expression_rule(p)) // expression ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -9118,7 +9119,7 @@ kwarg_or_starred_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 = _PyPegen_keyword_or_starred ( p , CHECK ( _Py_keyword ( a -> v . Name . id , b , EXTRA ) ) , 1 ); + res = _Ta3Pegen_keyword_or_starred ( p , CHECK ( _Ta3_keyword ( a -> v . Name . id , b , EXTRA ) ) , 1 ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -9133,7 +9134,7 @@ kwarg_or_starred_rule(Parser *p) (a = starred_expression_rule(p)) // starred_expression ) { - res = _PyPegen_keyword_or_starred ( p , a , 0 ); + res = _Ta3Pegen_keyword_or_starred ( p , a , 0 ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -9167,7 +9168,7 @@ kwarg_or_double_starred_rule(Parser *p) } KeywordOrStarred* res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -9180,14 +9181,14 @@ kwarg_or_double_starred_rule(Parser *p) expr_ty b; Token * literal; if ( - (a = _PyPegen_name_token(p)) // NAME + (a = _Ta3Pegen_name_token(p)) // NAME && - (literal = _PyPegen_expect_token(p, 22)) // token='=' + (literal = _Ta3Pegen_expect_token(p, 22)) // token='=' && (b = expression_rule(p)) // expression ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -9195,7 +9196,7 @@ kwarg_or_double_starred_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 = _PyPegen_keyword_or_starred ( p , CHECK ( _Py_keyword ( a -> v . Name . id , b , EXTRA ) ) , 1 ); + res = _Ta3Pegen_keyword_or_starred ( p , CHECK ( _Ta3_keyword ( a -> v . Name . id , b , EXTRA ) ) , 1 ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -9208,12 +9209,12 @@ kwarg_or_double_starred_rule(Parser *p) expr_ty a; Token * literal; if ( - (literal = _PyPegen_expect_token(p, 35)) // token='**' + (literal = _Ta3Pegen_expect_token(p, 35)) // token='**' && (a = expression_rule(p)) // expression ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -9221,7 +9222,7 @@ kwarg_or_double_starred_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 = _PyPegen_keyword_or_starred ( p , CHECK ( _Py_keyword ( NULL , a , EXTRA ) ) , 1 ); + res = _Ta3Pegen_keyword_or_starred ( p , CHECK ( _Ta3_keyword ( NULL , a , EXTRA ) ) , 1 ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -9255,7 +9256,7 @@ star_targets_rule(Parser *p) } expr_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -9268,7 +9269,7 @@ star_targets_rule(Parser *p) if ( (a = star_target_rule(p)) // star_target && - _PyPegen_lookahead_with_int(0, _PyPegen_expect_token, p, 12) // token=',' + _Ta3Pegen_lookahead_with_int(0, _Ta3Pegen_expect_token, p, 12) // token=',' ) { res = a; @@ -9290,10 +9291,10 @@ star_targets_rule(Parser *p) && (b = _loop0_117_rule(p)) // ((',' star_target))* && - (opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + (opt_var = _Ta3Pegen_expect_token(p, 12), 1) // ','? ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -9301,7 +9302,7 @@ star_targets_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_Tuple ( CHECK ( _PyPegen_seq_insert_in_front ( p , a , b ) ) , Store , EXTRA ); + res = _Ta3_Tuple ( CHECK ( _Ta3Pegen_seq_insert_in_front ( p , a , b ) ) , Store , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -9331,7 +9332,7 @@ star_targets_seq_rule(Parser *p) if ( (a = _gather_118_rule(p)) // ','.star_target+ && - (opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + (opt_var = _Ta3Pegen_expect_token(p, 12), 1) // ','? ) { res = a; @@ -9360,10 +9361,10 @@ star_target_rule(Parser *p) return NULL; } expr_ty res = NULL; - if (_PyPegen_is_memoized(p, star_target_type, &res)) + if (_Ta3Pegen_is_memoized(p, star_target_type, &res)) return res; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -9375,12 +9376,12 @@ star_target_rule(Parser *p) void *a; Token * literal; if ( - (literal = _PyPegen_expect_token(p, 16)) // token='*' + (literal = _Ta3Pegen_expect_token(p, 16)) // token='*' && (a = _tmp_120_rule(p)) // !'*' star_target ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -9388,7 +9389,7 @@ star_target_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_Starred ( CHECK ( _PyPegen_set_expr_context ( p , a , Store ) ) , Store , EXTRA ); + res = _Ta3_Starred ( CHECK ( _Ta3Pegen_set_expr_context ( p , a , Store ) ) , Store , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -9404,14 +9405,14 @@ star_target_rule(Parser *p) if ( (a = t_primary_rule(p)) // t_primary && - (literal = _PyPegen_expect_token(p, 23)) // token='.' + (literal = _Ta3Pegen_expect_token(p, 23)) // token='.' && - (b = _PyPegen_name_token(p)) // NAME + (b = _Ta3Pegen_name_token(p)) // NAME && - _PyPegen_lookahead(0, t_lookahead_rule, p) + _Ta3Pegen_lookahead(0, t_lookahead_rule, p) ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -9419,7 +9420,7 @@ star_target_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_Attribute ( a , b -> v . Name . id , Store , EXTRA ); + res = _Ta3_Attribute ( a , b -> v . Name . id , Store , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -9436,16 +9437,16 @@ star_target_rule(Parser *p) if ( (a = t_primary_rule(p)) // t_primary && - (literal = _PyPegen_expect_token(p, 9)) // token='[' + (literal = _Ta3Pegen_expect_token(p, 9)) // token='[' && (b = slices_rule(p)) // slices && - (literal_1 = _PyPegen_expect_token(p, 10)) // token=']' + (literal_1 = _Ta3Pegen_expect_token(p, 10)) // token=']' && - _PyPegen_lookahead(0, t_lookahead_rule, p) + _Ta3Pegen_lookahead(0, t_lookahead_rule, p) ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -9453,7 +9454,7 @@ star_target_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_Subscript ( a , b , Store , EXTRA ); + res = _Ta3_Subscript ( a , b , Store , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -9475,7 +9476,7 @@ star_target_rule(Parser *p) } res = NULL; done: - _PyPegen_insert_memo(p, mark, star_target_type, res); + _Ta3Pegen_insert_memo(p, mark, star_target_type, res); return res; } @@ -9492,7 +9493,7 @@ star_atom_rule(Parser *p) } expr_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -9503,10 +9504,10 @@ star_atom_rule(Parser *p) { // NAME expr_ty a; if ( - (a = _PyPegen_name_token(p)) // NAME + (a = _Ta3Pegen_name_token(p)) // NAME ) { - res = _PyPegen_set_expr_context ( p , a , Store ); + res = _Ta3Pegen_set_expr_context ( p , a , Store ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -9520,14 +9521,14 @@ star_atom_rule(Parser *p) Token * literal; Token * literal_1; if ( - (literal = _PyPegen_expect_token(p, 7)) // token='(' + (literal = _Ta3Pegen_expect_token(p, 7)) // token='(' && (a = star_target_rule(p)) // star_target && - (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + (literal_1 = _Ta3Pegen_expect_token(p, 8)) // token=')' ) { - res = _PyPegen_set_expr_context ( p , a , Store ); + res = _Ta3Pegen_set_expr_context ( p , a , Store ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -9541,14 +9542,14 @@ star_atom_rule(Parser *p) Token * literal; Token * literal_1; if ( - (literal = _PyPegen_expect_token(p, 7)) // token='(' + (literal = _Ta3Pegen_expect_token(p, 7)) // token='(' && (a = star_targets_seq_rule(p), 1) // star_targets_seq? && - (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + (literal_1 = _Ta3Pegen_expect_token(p, 8)) // token=')' ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -9556,7 +9557,7 @@ star_atom_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_Tuple ( a , Store , EXTRA ); + res = _Ta3_Tuple ( a , Store , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -9570,14 +9571,14 @@ star_atom_rule(Parser *p) Token * literal; Token * literal_1; if ( - (literal = _PyPegen_expect_token(p, 9)) // token='[' + (literal = _Ta3Pegen_expect_token(p, 9)) // token='[' && (a = star_targets_seq_rule(p), 1) // star_targets_seq? && - (literal_1 = _PyPegen_expect_token(p, 10)) // token=']' + (literal_1 = _Ta3Pegen_expect_token(p, 10)) // token=']' ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -9585,7 +9586,7 @@ star_atom_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_List ( a , Store , EXTRA ); + res = _Ta3_List ( a , Store , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -9625,10 +9626,10 @@ inside_paren_ann_assign_target_rule(Parser *p) { // NAME expr_ty a; if ( - (a = _PyPegen_name_token(p)) // NAME + (a = _Ta3Pegen_name_token(p)) // NAME ) { - res = _PyPegen_set_expr_context ( p , a , Store ); + res = _Ta3Pegen_set_expr_context ( p , a , Store ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -9642,11 +9643,11 @@ inside_paren_ann_assign_target_rule(Parser *p) Token * literal; Token * literal_1; if ( - (literal = _PyPegen_expect_token(p, 7)) // token='(' + (literal = _Ta3Pegen_expect_token(p, 7)) // token='(' && (a = inside_paren_ann_assign_target_rule(p)) // inside_paren_ann_assign_target && - (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + (literal_1 = _Ta3Pegen_expect_token(p, 8)) // token=')' ) { res = a; @@ -9674,7 +9675,7 @@ ann_assign_subscript_attribute_target_rule(Parser *p) } expr_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -9689,14 +9690,14 @@ ann_assign_subscript_attribute_target_rule(Parser *p) if ( (a = t_primary_rule(p)) // t_primary && - (literal = _PyPegen_expect_token(p, 23)) // token='.' + (literal = _Ta3Pegen_expect_token(p, 23)) // token='.' && - (b = _PyPegen_name_token(p)) // NAME + (b = _Ta3Pegen_name_token(p)) // NAME && - _PyPegen_lookahead(0, t_lookahead_rule, p) + _Ta3Pegen_lookahead(0, t_lookahead_rule, p) ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -9704,7 +9705,7 @@ ann_assign_subscript_attribute_target_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_Attribute ( a , b -> v . Name . id , Store , EXTRA ); + res = _Ta3_Attribute ( a , b -> v . Name . id , Store , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -9721,16 +9722,16 @@ ann_assign_subscript_attribute_target_rule(Parser *p) if ( (a = t_primary_rule(p)) // t_primary && - (literal = _PyPegen_expect_token(p, 9)) // token='[' + (literal = _Ta3Pegen_expect_token(p, 9)) // token='[' && (b = slices_rule(p)) // slices && - (literal_1 = _PyPegen_expect_token(p, 10)) // token=']' + (literal_1 = _Ta3Pegen_expect_token(p, 10)) // token=']' && - _PyPegen_lookahead(0, t_lookahead_rule, p) + _Ta3Pegen_lookahead(0, t_lookahead_rule, p) ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -9738,7 +9739,7 @@ ann_assign_subscript_attribute_target_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_Subscript ( a , b , Store , EXTRA ); + res = _Ta3_Subscript ( a , b , Store , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -9768,7 +9769,7 @@ del_targets_rule(Parser *p) if ( (a = _gather_121_rule(p)) // ','.del_target+ && - (opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + (opt_var = _Ta3Pegen_expect_token(p, 12), 1) // ','? ) { res = a; @@ -9796,10 +9797,10 @@ del_target_rule(Parser *p) return NULL; } expr_ty res = NULL; - if (_PyPegen_is_memoized(p, del_target_type, &res)) + if (_Ta3Pegen_is_memoized(p, del_target_type, &res)) return res; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -9814,14 +9815,14 @@ del_target_rule(Parser *p) if ( (a = t_primary_rule(p)) // t_primary && - (literal = _PyPegen_expect_token(p, 23)) // token='.' + (literal = _Ta3Pegen_expect_token(p, 23)) // token='.' && - (b = _PyPegen_name_token(p)) // NAME + (b = _Ta3Pegen_name_token(p)) // NAME && - _PyPegen_lookahead(0, t_lookahead_rule, p) + _Ta3Pegen_lookahead(0, t_lookahead_rule, p) ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -9829,7 +9830,7 @@ del_target_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_Attribute ( a , b -> v . Name . id , Del , EXTRA ); + res = _Ta3_Attribute ( a , b -> v . Name . id , Del , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -9846,16 +9847,16 @@ del_target_rule(Parser *p) if ( (a = t_primary_rule(p)) // t_primary && - (literal = _PyPegen_expect_token(p, 9)) // token='[' + (literal = _Ta3Pegen_expect_token(p, 9)) // token='[' && (b = slices_rule(p)) // slices && - (literal_1 = _PyPegen_expect_token(p, 10)) // token=']' + (literal_1 = _Ta3Pegen_expect_token(p, 10)) // token=']' && - _PyPegen_lookahead(0, t_lookahead_rule, p) + _Ta3Pegen_lookahead(0, t_lookahead_rule, p) ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -9863,7 +9864,7 @@ del_target_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_Subscript ( a , b , Del , EXTRA ); + res = _Ta3_Subscript ( a , b , Del , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -9885,7 +9886,7 @@ del_target_rule(Parser *p) } res = NULL; done: - _PyPegen_insert_memo(p, mark, del_target_type, res); + _Ta3Pegen_insert_memo(p, mark, del_target_type, res); return res; } @@ -9898,7 +9899,7 @@ del_t_atom_rule(Parser *p) } expr_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -9909,10 +9910,10 @@ del_t_atom_rule(Parser *p) { // NAME expr_ty a; if ( - (a = _PyPegen_name_token(p)) // NAME + (a = _Ta3Pegen_name_token(p)) // NAME ) { - res = _PyPegen_set_expr_context ( p , a , Del ); + res = _Ta3Pegen_set_expr_context ( p , a , Del ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -9926,14 +9927,14 @@ del_t_atom_rule(Parser *p) Token * literal; Token * literal_1; if ( - (literal = _PyPegen_expect_token(p, 7)) // token='(' + (literal = _Ta3Pegen_expect_token(p, 7)) // token='(' && (a = del_target_rule(p)) // del_target && - (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + (literal_1 = _Ta3Pegen_expect_token(p, 8)) // token=')' ) { - res = _PyPegen_set_expr_context ( p , a , Del ); + res = _Ta3Pegen_set_expr_context ( p , a , Del ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -9947,14 +9948,14 @@ del_t_atom_rule(Parser *p) Token * literal; Token * literal_1; if ( - (literal = _PyPegen_expect_token(p, 7)) // token='(' + (literal = _Ta3Pegen_expect_token(p, 7)) // token='(' && (a = del_targets_rule(p), 1) // del_targets? && - (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + (literal_1 = _Ta3Pegen_expect_token(p, 8)) // token=')' ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -9962,7 +9963,7 @@ del_t_atom_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_Tuple ( a , Del , EXTRA ); + res = _Ta3_Tuple ( a , Del , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -9976,14 +9977,14 @@ del_t_atom_rule(Parser *p) Token * literal; Token * literal_1; if ( - (literal = _PyPegen_expect_token(p, 9)) // token='[' + (literal = _Ta3Pegen_expect_token(p, 9)) // token='[' && (a = del_targets_rule(p), 1) // del_targets? && - (literal_1 = _PyPegen_expect_token(p, 10)) // token=']' + (literal_1 = _Ta3Pegen_expect_token(p, 10)) // token=']' ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -9991,7 +9992,7 @@ del_t_atom_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_List ( a , Del , EXTRA ); + res = _Ta3_List ( a , Del , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -10021,7 +10022,7 @@ targets_rule(Parser *p) if ( (a = _gather_123_rule(p)) // ','.target+ && - (opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + (opt_var = _Ta3Pegen_expect_token(p, 12), 1) // ','? ) { res = a; @@ -10049,10 +10050,10 @@ target_rule(Parser *p) return NULL; } expr_ty res = NULL; - if (_PyPegen_is_memoized(p, target_type, &res)) + if (_Ta3Pegen_is_memoized(p, target_type, &res)) return res; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -10067,14 +10068,14 @@ target_rule(Parser *p) if ( (a = t_primary_rule(p)) // t_primary && - (literal = _PyPegen_expect_token(p, 23)) // token='.' + (literal = _Ta3Pegen_expect_token(p, 23)) // token='.' && - (b = _PyPegen_name_token(p)) // NAME + (b = _Ta3Pegen_name_token(p)) // NAME && - _PyPegen_lookahead(0, t_lookahead_rule, p) + _Ta3Pegen_lookahead(0, t_lookahead_rule, p) ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -10082,7 +10083,7 @@ target_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_Attribute ( a , b -> v . Name . id , Store , EXTRA ); + res = _Ta3_Attribute ( a , b -> v . Name . id , Store , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -10099,16 +10100,16 @@ target_rule(Parser *p) if ( (a = t_primary_rule(p)) // t_primary && - (literal = _PyPegen_expect_token(p, 9)) // token='[' + (literal = _Ta3Pegen_expect_token(p, 9)) // token='[' && (b = slices_rule(p)) // slices && - (literal_1 = _PyPegen_expect_token(p, 10)) // token=']' + (literal_1 = _Ta3Pegen_expect_token(p, 10)) // token=']' && - _PyPegen_lookahead(0, t_lookahead_rule, p) + _Ta3Pegen_lookahead(0, t_lookahead_rule, p) ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -10116,7 +10117,7 @@ target_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_Subscript ( a , b , Store , EXTRA ); + res = _Ta3_Subscript ( a , b , Store , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -10138,7 +10139,7 @@ target_rule(Parser *p) } res = NULL; done: - _PyPegen_insert_memo(p, mark, target_type, res); + _Ta3Pegen_insert_memo(p, mark, target_type, res); return res; } @@ -10154,12 +10155,12 @@ static expr_ty t_primary_rule(Parser *p) { expr_ty res = NULL; - if (_PyPegen_is_memoized(p, t_primary_type, &res)) + if (_Ta3Pegen_is_memoized(p, t_primary_type, &res)) return res; int mark = p->mark; int resmark = p->mark; while (1) { - int tmpvar_8 = _PyPegen_update_memo(p, mark, t_primary_type, res); + int tmpvar_8 = _Ta3Pegen_update_memo(p, mark, t_primary_type, res); if (tmpvar_8) { return res; } @@ -10181,7 +10182,7 @@ t_primary_raw(Parser *p) } expr_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -10196,14 +10197,14 @@ t_primary_raw(Parser *p) if ( (a = t_primary_rule(p)) // t_primary && - (literal = _PyPegen_expect_token(p, 23)) // token='.' + (literal = _Ta3Pegen_expect_token(p, 23)) // token='.' && - (b = _PyPegen_name_token(p)) // NAME + (b = _Ta3Pegen_name_token(p)) // NAME && - _PyPegen_lookahead(1, t_lookahead_rule, p) + _Ta3Pegen_lookahead(1, t_lookahead_rule, p) ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -10211,7 +10212,7 @@ t_primary_raw(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_Attribute ( a , b -> v . Name . id , Load , EXTRA ); + res = _Ta3_Attribute ( a , b -> v . Name . id , Load , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -10228,16 +10229,16 @@ t_primary_raw(Parser *p) if ( (a = t_primary_rule(p)) // t_primary && - (literal = _PyPegen_expect_token(p, 9)) // token='[' + (literal = _Ta3Pegen_expect_token(p, 9)) // token='[' && (b = slices_rule(p)) // slices && - (literal_1 = _PyPegen_expect_token(p, 10)) // token=']' + (literal_1 = _Ta3Pegen_expect_token(p, 10)) // token=']' && - _PyPegen_lookahead(1, t_lookahead_rule, p) + _Ta3Pegen_lookahead(1, t_lookahead_rule, p) ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -10245,7 +10246,7 @@ t_primary_raw(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_Subscript ( a , b , Load , EXTRA ); + res = _Ta3_Subscript ( a , b , Load , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -10262,10 +10263,10 @@ t_primary_raw(Parser *p) && (b = genexp_rule(p)) // genexp && - _PyPegen_lookahead(1, t_lookahead_rule, p) + _Ta3Pegen_lookahead(1, t_lookahead_rule, p) ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -10273,7 +10274,7 @@ t_primary_raw(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_Call ( a , CHECK ( _PyPegen_singleton_seq ( p , b ) ) , NULL , EXTRA ); + res = _Ta3_Call ( a , CHECK ( _Ta3Pegen_singleton_seq ( p , b ) ) , NULL , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -10290,16 +10291,16 @@ t_primary_raw(Parser *p) if ( (a = t_primary_rule(p)) // t_primary && - (literal = _PyPegen_expect_token(p, 7)) // token='(' + (literal = _Ta3Pegen_expect_token(p, 7)) // token='(' && (b = arguments_rule(p), 1) // arguments? && - (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + (literal_1 = _Ta3Pegen_expect_token(p, 8)) // token=')' && - _PyPegen_lookahead(1, t_lookahead_rule, p) + _Ta3Pegen_lookahead(1, t_lookahead_rule, p) ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -10307,7 +10308,7 @@ t_primary_raw(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_Call ( a , ( b ) ? ( ( expr_ty ) b ) -> v . Call . args : NULL , ( b ) ? ( ( expr_ty ) b ) -> v . Call . keywords : NULL , EXTRA ); + res = _Ta3_Call ( a , ( b ) ? ( ( expr_ty ) b ) -> v . Call . args : NULL , ( b ) ? ( ( expr_ty ) b ) -> v . Call . keywords : NULL , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -10321,7 +10322,7 @@ t_primary_raw(Parser *p) if ( (a = atom_rule(p)) // atom && - _PyPegen_lookahead(1, t_lookahead_rule, p) + _Ta3Pegen_lookahead(1, t_lookahead_rule, p) ) { res = a; @@ -10350,7 +10351,7 @@ t_lookahead_rule(Parser *p) { // '(' Token * literal; if ( - (literal = _PyPegen_expect_token(p, 7)) // token='(' + (literal = _Ta3Pegen_expect_token(p, 7)) // token='(' ) { res = literal; @@ -10361,7 +10362,7 @@ t_lookahead_rule(Parser *p) { // '[' Token * literal; if ( - (literal = _PyPegen_expect_token(p, 9)) // token='[' + (literal = _Ta3Pegen_expect_token(p, 9)) // token='[' ) { res = literal; @@ -10372,7 +10373,7 @@ t_lookahead_rule(Parser *p) { // '.' Token * literal; if ( - (literal = _PyPegen_expect_token(p, 23)) // token='.' + (literal = _Ta3Pegen_expect_token(p, 23)) // token='.' ) { res = literal; @@ -10394,7 +10395,7 @@ t_atom_rule(Parser *p) } expr_ty res = NULL; int mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -10405,10 +10406,10 @@ t_atom_rule(Parser *p) { // NAME expr_ty a; if ( - (a = _PyPegen_name_token(p)) // NAME + (a = _Ta3Pegen_name_token(p)) // NAME ) { - res = _PyPegen_set_expr_context ( p , a , Store ); + res = _Ta3Pegen_set_expr_context ( p , a , Store ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -10422,14 +10423,14 @@ t_atom_rule(Parser *p) Token * literal; Token * literal_1; if ( - (literal = _PyPegen_expect_token(p, 7)) // token='(' + (literal = _Ta3Pegen_expect_token(p, 7)) // token='(' && (a = target_rule(p)) // target && - (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + (literal_1 = _Ta3Pegen_expect_token(p, 8)) // token=')' ) { - res = _PyPegen_set_expr_context ( p , a , Store ); + res = _Ta3Pegen_set_expr_context ( p , a , Store ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -10443,14 +10444,14 @@ t_atom_rule(Parser *p) Token * literal; Token * literal_1; if ( - (literal = _PyPegen_expect_token(p, 7)) // token='(' + (literal = _Ta3Pegen_expect_token(p, 7)) // token='(' && (b = targets_rule(p), 1) // targets? && - (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + (literal_1 = _Ta3Pegen_expect_token(p, 8)) // token=')' ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -10458,7 +10459,7 @@ t_atom_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_Tuple ( b , Store , EXTRA ); + res = _Ta3_Tuple ( b , Store , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -10472,14 +10473,14 @@ t_atom_rule(Parser *p) Token * literal; Token * literal_1; if ( - (literal = _PyPegen_expect_token(p, 9)) // token='[' + (literal = _Ta3Pegen_expect_token(p, 9)) // token='[' && (b = targets_rule(p), 1) // targets? && - (literal_1 = _PyPegen_expect_token(p, 10)) // token=']' + (literal_1 = _Ta3Pegen_expect_token(p, 10)) // token=']' ) { - Token *token = _PyPegen_get_last_nonnwhitespace_token(p); + Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p); if (token == NULL) { return NULL; } @@ -10487,7 +10488,7 @@ t_atom_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_List ( b , Store , EXTRA ); + res = _Ta3_List ( b , Store , EXTRA ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -10520,9 +10521,9 @@ incorrect_arguments_rule(Parser *p) if ( (args_var = args_rule(p)) // args && - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && - (literal_1 = _PyPegen_expect_token(p, 16)) // token='*' + (literal_1 = _Ta3Pegen_expect_token(p, 16)) // token='*' ) { res = RAISE_SYNTAX_ERROR ( "iterable argument unpacking follows keyword argument unpacking" ); @@ -10545,7 +10546,7 @@ incorrect_arguments_rule(Parser *p) && (for_if_clauses_var = for_if_clauses_rule(p)) // for_if_clauses && - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && (opt_var = _tmp_125_rule(p), 1) // [args | expression for_if_clauses] ) @@ -10566,12 +10567,12 @@ incorrect_arguments_rule(Parser *p) if ( (a = args_rule(p)) // args && - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && (args_var = args_rule(p)) // args ) { - res = _PyPegen_arguments_parsing_error ( p , a ); + res = _Ta3Pegen_arguments_parsing_error ( p , a ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -10600,7 +10601,7 @@ invalid_kwarg_rule(Parser *p) if ( (expression_var = expression_rule(p)) // expression && - (literal = _PyPegen_expect_token(p, 22)) // token='=' + (literal = _Ta3Pegen_expect_token(p, 22)) // token='=' ) { res = RAISE_SYNTAX_ERROR ( "expression cannot contain assignment, perhaps you meant \"==\"?" ); @@ -10633,12 +10634,12 @@ invalid_named_expression_rule(Parser *p) if ( (a = expression_rule(p)) // expression && - (literal = _PyPegen_expect_token(p, 53)) // token=':=' + (literal = _Ta3Pegen_expect_token(p, 53)) // token=':=' && (expression_var = expression_rule(p)) // expression ) { - res = RAISE_SYNTAX_ERROR ( "cannot use assignment expressions with %s" , _PyPegen_get_expr_name ( a ) ); + res = RAISE_SYNTAX_ERROR ( "cannot use assignment expressions with %s" , _Ta3Pegen_get_expr_name ( a ) ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -10671,7 +10672,7 @@ invalid_assignment_rule(Parser *p) if ( (list_var = list_rule(p)) // list && - (literal = _PyPegen_expect_token(p, 11)) // token=':' + (literal = _Ta3Pegen_expect_token(p, 11)) // token=':' ) { res = RAISE_SYNTAX_ERROR ( "only single target (not list) can be annotated" ); @@ -10689,7 +10690,7 @@ invalid_assignment_rule(Parser *p) if ( (tuple_var = tuple_rule(p)) // tuple && - (literal = _PyPegen_expect_token(p, 11)) // token=':' + (literal = _Ta3Pegen_expect_token(p, 11)) // token=':' ) { res = RAISE_SYNTAX_ERROR ( "only single target (not tuple) can be annotated" ); @@ -10710,7 +10711,7 @@ invalid_assignment_rule(Parser *p) if ( (expression_var = expression_rule(p)) // expression && - (literal = _PyPegen_expect_token(p, 11)) // token=':' + (literal = _Ta3Pegen_expect_token(p, 11)) // token=':' && (expression_var_1 = expression_rule(p)) // expression && @@ -10738,7 +10739,7 @@ invalid_assignment_rule(Parser *p) (_tmp_128_var = _tmp_128_rule(p)) // yield_expr | star_expressions ) { - res = RAISE_SYNTAX_ERROR_NO_COL_OFFSET ( "cannot assign to %s" , _PyPegen_get_expr_name ( a ) ); + res = RAISE_SYNTAX_ERROR_NO_COL_OFFSET ( "cannot assign to %s" , _Ta3Pegen_get_expr_name ( a ) ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -10764,9 +10765,9 @@ invalid_block_rule(Parser *p) { // NEWLINE !INDENT Token * newline_var; if ( - (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + (newline_var = _Ta3Pegen_expect_token(p, NEWLINE)) // token='NEWLINE' && - _PyPegen_lookahead_with_int(0, _PyPegen_expect_token, p, INDENT) // token=INDENT + _Ta3Pegen_lookahead_with_int(0, _Ta3Pegen_expect_token, p, INDENT) // token=INDENT ) { res = RAISE_INDENTATION_ERROR ( "expected an indented block" ); @@ -10800,7 +10801,7 @@ invalid_comprehension_rule(Parser *p) if ( (_tmp_129_var = _tmp_129_rule(p)) // '[' | '(' | '{' && - (literal = _PyPegen_expect_token(p, 16)) // token='*' + (literal = _Ta3Pegen_expect_token(p, 16)) // token='*' && (expression_var = expression_rule(p)) // expression && @@ -10870,7 +10871,7 @@ invalid_star_etc_rule(Parser *p) void *_tmp_132_var; Token * literal; if ( - (literal = _PyPegen_expect_token(p, 16)) // token='*' + (literal = _Ta3Pegen_expect_token(p, 16)) // token='*' && (_tmp_132_var = _tmp_132_rule(p)) // ')' | ',' (')' | '**') ) @@ -10902,7 +10903,7 @@ invalid_lambda_star_etc_rule(Parser *p) void *_tmp_133_var; Token * literal; if ( - (literal = _PyPegen_expect_token(p, 16)) // token='*' + (literal = _Ta3Pegen_expect_token(p, 16)) // token='*' && (_tmp_133_var = _tmp_133_rule(p)) // ':' | ',' (':' | '**') ) @@ -10937,15 +10938,15 @@ invalid_double_type_comments_rule(Parser *p) Token * type_comment_var; Token * type_comment_var_1; if ( - (type_comment_var = _PyPegen_expect_token(p, TYPE_COMMENT)) // token='TYPE_COMMENT' + (type_comment_var = _Ta3Pegen_expect_token(p, TYPE_COMMENT)) // token='TYPE_COMMENT' && - (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + (newline_var = _Ta3Pegen_expect_token(p, NEWLINE)) // token='NEWLINE' && - (type_comment_var_1 = _PyPegen_expect_token(p, TYPE_COMMENT)) // token='TYPE_COMMENT' + (type_comment_var_1 = _Ta3Pegen_expect_token(p, TYPE_COMMENT)) // token='TYPE_COMMENT' && - (newline_var_1 = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + (newline_var_1 = _Ta3Pegen_expect_token(p, NEWLINE)) // token='NEWLINE' && - (indent_var = _PyPegen_expect_token(p, INDENT)) // token='INDENT' + (indent_var = _Ta3Pegen_expect_token(p, INDENT)) // token='INDENT' ) { res = RAISE_SYNTAX_ERROR ( "Cannot have two type comments on def" ); @@ -10982,7 +10983,7 @@ _loop0_1_rule(Parser *p) { // NEWLINE Token * newline_var; while ( - (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + (newline_var = _Ta3Pegen_expect_token(p, NEWLINE)) // token='NEWLINE' ) { res = newline_var; @@ -10999,7 +11000,7 @@ _loop0_1_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_1"); PyMem_Free(children); @@ -11007,7 +11008,7 @@ _loop0_1_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop0_1_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_1_type, seq); return seq; } @@ -11031,7 +11032,7 @@ _loop0_2_rule(Parser *p) { // NEWLINE Token * newline_var; while ( - (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + (newline_var = _Ta3Pegen_expect_token(p, NEWLINE)) // token='NEWLINE' ) { res = newline_var; @@ -11048,7 +11049,7 @@ _loop0_2_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_2"); PyMem_Free(children); @@ -11056,7 +11057,7 @@ _loop0_2_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop0_2_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_2_type, seq); return seq; } @@ -11081,7 +11082,7 @@ _loop0_4_rule(Parser *p) expr_ty elem; Token * literal; while ( - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && (elem = expression_rule(p)) // expression ) @@ -11105,7 +11106,7 @@ _loop0_4_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_4"); PyMem_Free(children); @@ -11113,7 +11114,7 @@ _loop0_4_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop0_4_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_4_type, seq); return seq; } @@ -11135,7 +11136,7 @@ _gather_3_rule(Parser *p) (seq = _loop0_4_rule(p)) // _loop0_4 ) { - res = _PyPegen_seq_insert_in_front(p, elem, seq); + res = _Ta3Pegen_seq_insert_in_front(p, elem, seq); goto done; } p->mark = mark; @@ -11166,7 +11167,7 @@ _loop0_6_rule(Parser *p) expr_ty elem; Token * literal; while ( - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && (elem = expression_rule(p)) // expression ) @@ -11190,7 +11191,7 @@ _loop0_6_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_6"); PyMem_Free(children); @@ -11198,7 +11199,7 @@ _loop0_6_rule(Parser *p) } 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); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_6_type, seq); return seq; } @@ -11220,7 +11221,7 @@ _gather_5_rule(Parser *p) (seq = _loop0_6_rule(p)) // _loop0_6 ) { - res = _PyPegen_seq_insert_in_front(p, elem, seq); + res = _Ta3Pegen_seq_insert_in_front(p, elem, seq); goto done; } p->mark = mark; @@ -11251,7 +11252,7 @@ _loop0_8_rule(Parser *p) expr_ty elem; Token * literal; while ( - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && (elem = expression_rule(p)) // expression ) @@ -11275,7 +11276,7 @@ _loop0_8_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_8"); PyMem_Free(children); @@ -11283,7 +11284,7 @@ _loop0_8_rule(Parser *p) } 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); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_8_type, seq); return seq; } @@ -11305,7 +11306,7 @@ _gather_7_rule(Parser *p) (seq = _loop0_8_rule(p)) // _loop0_8 ) { - res = _PyPegen_seq_insert_in_front(p, elem, seq); + res = _Ta3Pegen_seq_insert_in_front(p, elem, seq); goto done; } p->mark = mark; @@ -11336,7 +11337,7 @@ _loop0_10_rule(Parser *p) expr_ty elem; Token * literal; while ( - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && (elem = expression_rule(p)) // expression ) @@ -11360,7 +11361,7 @@ _loop0_10_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_10"); PyMem_Free(children); @@ -11368,7 +11369,7 @@ _loop0_10_rule(Parser *p) } 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); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_10_type, seq); return seq; } @@ -11390,7 +11391,7 @@ _gather_9_rule(Parser *p) (seq = _loop0_10_rule(p)) // _loop0_10 ) { - res = _PyPegen_seq_insert_in_front(p, elem, seq); + res = _Ta3Pegen_seq_insert_in_front(p, elem, seq); goto done; } p->mark = mark; @@ -11441,7 +11442,7 @@ _loop1_11_rule(Parser *p) PyMem_Free(children); return NULL; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_11"); PyMem_Free(children); @@ -11449,7 +11450,7 @@ _loop1_11_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop1_11_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop1_11_type, seq); return seq; } @@ -11474,7 +11475,7 @@ _loop0_13_rule(Parser *p) stmt_ty elem; Token * literal; while ( - (literal = _PyPegen_expect_token(p, 13)) // token=';' + (literal = _Ta3Pegen_expect_token(p, 13)) // token=';' && (elem = small_stmt_rule(p)) // small_stmt ) @@ -11498,7 +11499,7 @@ _loop0_13_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_13"); PyMem_Free(children); @@ -11506,7 +11507,7 @@ _loop0_13_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop0_13_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_13_type, seq); return seq; } @@ -11528,7 +11529,7 @@ _gather_12_rule(Parser *p) (seq = _loop0_13_rule(p)) // _loop0_13 ) { - res = _PyPegen_seq_insert_in_front(p, elem, seq); + res = _Ta3Pegen_seq_insert_in_front(p, elem, seq); goto done; } p->mark = mark; @@ -11550,7 +11551,7 @@ _tmp_14_rule(Parser *p) { // 'import' Token * keyword; if ( - (keyword = _PyPegen_expect_token(p, 513)) // token='import' + (keyword = _Ta3Pegen_expect_token(p, 513)) // token='import' ) { res = keyword; @@ -11561,7 +11562,7 @@ _tmp_14_rule(Parser *p) { // 'from' Token * keyword; if ( - (keyword = _PyPegen_expect_token(p, 514)) // token='from' + (keyword = _Ta3Pegen_expect_token(p, 514)) // token='from' ) { res = keyword; @@ -11586,7 +11587,7 @@ _tmp_15_rule(Parser *p) { // 'def' Token * keyword; if ( - (keyword = _PyPegen_expect_token(p, 522)) // token='def' + (keyword = _Ta3Pegen_expect_token(p, 522)) // token='def' ) { res = keyword; @@ -11597,7 +11598,7 @@ _tmp_15_rule(Parser *p) { // '@' Token * literal; if ( - (literal = _PyPegen_expect_token(p, 49)) // token='@' + (literal = _Ta3Pegen_expect_token(p, 49)) // token='@' ) { res = literal; @@ -11608,7 +11609,7 @@ _tmp_15_rule(Parser *p) { // ASYNC Token * async_var; if ( - (async_var = _PyPegen_expect_token(p, ASYNC)) // token='ASYNC' + (async_var = _Ta3Pegen_expect_token(p, ASYNC)) // token='ASYNC' ) { res = async_var; @@ -11633,7 +11634,7 @@ _tmp_16_rule(Parser *p) { // 'class' Token * keyword; if ( - (keyword = _PyPegen_expect_token(p, 523)) // token='class' + (keyword = _Ta3Pegen_expect_token(p, 523)) // token='class' ) { res = keyword; @@ -11644,7 +11645,7 @@ _tmp_16_rule(Parser *p) { // '@' Token * literal; if ( - (literal = _PyPegen_expect_token(p, 49)) // token='@' + (literal = _Ta3Pegen_expect_token(p, 49)) // token='@' ) { res = literal; @@ -11669,7 +11670,7 @@ _tmp_17_rule(Parser *p) { // 'with' Token * keyword; if ( - (keyword = _PyPegen_expect_token(p, 519)) // token='with' + (keyword = _Ta3Pegen_expect_token(p, 519)) // token='with' ) { res = keyword; @@ -11680,7 +11681,7 @@ _tmp_17_rule(Parser *p) { // ASYNC Token * async_var; if ( - (async_var = _PyPegen_expect_token(p, ASYNC)) // token='ASYNC' + (async_var = _Ta3Pegen_expect_token(p, ASYNC)) // token='ASYNC' ) { res = async_var; @@ -11705,7 +11706,7 @@ _tmp_18_rule(Parser *p) { // 'for' Token * keyword; if ( - (keyword = _PyPegen_expect_token(p, 517)) // token='for' + (keyword = _Ta3Pegen_expect_token(p, 517)) // token='for' ) { res = keyword; @@ -11716,7 +11717,7 @@ _tmp_18_rule(Parser *p) { // ASYNC Token * async_var; if ( - (async_var = _PyPegen_expect_token(p, ASYNC)) // token='ASYNC' + (async_var = _Ta3Pegen_expect_token(p, ASYNC)) // token='ASYNC' ) { res = async_var; @@ -11742,7 +11743,7 @@ _tmp_19_rule(Parser *p) expr_ty d; Token * literal; if ( - (literal = _PyPegen_expect_token(p, 22)) // token='=' + (literal = _Ta3Pegen_expect_token(p, 22)) // token='=' && (d = annotated_rhs_rule(p)) // annotated_rhs ) @@ -11775,11 +11776,11 @@ _tmp_20_rule(Parser *p) Token * literal; Token * literal_1; if ( - (literal = _PyPegen_expect_token(p, 7)) // token='(' + (literal = _Ta3Pegen_expect_token(p, 7)) // token='(' && (b = inside_paren_ann_assign_target_rule(p)) // inside_paren_ann_assign_target && - (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + (literal_1 = _Ta3Pegen_expect_token(p, 8)) // token=')' ) { res = b; @@ -11820,7 +11821,7 @@ _tmp_21_rule(Parser *p) expr_ty d; Token * literal; if ( - (literal = _PyPegen_expect_token(p, 22)) // token='=' + (literal = _Ta3Pegen_expect_token(p, 22)) // token='=' && (d = annotated_rhs_rule(p)) // annotated_rhs ) @@ -11880,7 +11881,7 @@ _loop1_22_rule(Parser *p) PyMem_Free(children); return NULL; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_22"); PyMem_Free(children); @@ -11888,7 +11889,7 @@ _loop1_22_rule(Parser *p) } 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); + _Ta3Pegen_insert_memo(p, start_mark, _loop1_22_type, seq); return seq; } @@ -11985,9 +11986,9 @@ _loop0_26_rule(Parser *p) expr_ty elem; Token * literal; while ( - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && - (elem = _PyPegen_name_token(p)) // NAME + (elem = _Ta3Pegen_name_token(p)) // NAME ) { res = elem; @@ -12009,7 +12010,7 @@ _loop0_26_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_26"); PyMem_Free(children); @@ -12017,7 +12018,7 @@ _loop0_26_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop0_26_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_26_type, seq); return seq; } @@ -12034,12 +12035,12 @@ _gather_25_rule(Parser *p) expr_ty elem; asdl_seq * seq; if ( - (elem = _PyPegen_name_token(p)) // NAME + (elem = _Ta3Pegen_name_token(p)) // NAME && (seq = _loop0_26_rule(p)) // _loop0_26 ) { - res = _PyPegen_seq_insert_in_front(p, elem, seq); + res = _Ta3Pegen_seq_insert_in_front(p, elem, seq); goto done; } p->mark = mark; @@ -12070,9 +12071,9 @@ _loop0_28_rule(Parser *p) expr_ty elem; Token * literal; while ( - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && - (elem = _PyPegen_name_token(p)) // NAME + (elem = _Ta3Pegen_name_token(p)) // NAME ) { res = elem; @@ -12094,7 +12095,7 @@ _loop0_28_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_28"); PyMem_Free(children); @@ -12102,7 +12103,7 @@ _loop0_28_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop0_28_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_28_type, seq); return seq; } @@ -12119,12 +12120,12 @@ _gather_27_rule(Parser *p) expr_ty elem; asdl_seq * seq; if ( - (elem = _PyPegen_name_token(p)) // NAME + (elem = _Ta3Pegen_name_token(p)) // NAME && (seq = _loop0_28_rule(p)) // _loop0_28 ) { - res = _PyPegen_seq_insert_in_front(p, elem, seq); + res = _Ta3Pegen_seq_insert_in_front(p, elem, seq); goto done; } p->mark = mark; @@ -12147,7 +12148,7 @@ _tmp_29_rule(Parser *p) Token * literal; expr_ty z; if ( - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && (z = expression_rule(p)) // expression ) @@ -12203,7 +12204,7 @@ _loop0_30_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_30"); PyMem_Free(children); @@ -12211,7 +12212,7 @@ _loop0_30_rule(Parser *p) } 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); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_30_type, seq); return seq; } @@ -12256,7 +12257,7 @@ _loop1_31_rule(Parser *p) PyMem_Free(children); return NULL; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_31"); PyMem_Free(children); @@ -12264,7 +12265,7 @@ _loop1_31_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop1_31_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop1_31_type, seq); return seq; } @@ -12289,7 +12290,7 @@ _loop0_33_rule(Parser *p) alias_ty elem; Token * literal; while ( - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && (elem = import_from_as_name_rule(p)) // import_from_as_name ) @@ -12313,7 +12314,7 @@ _loop0_33_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_33"); PyMem_Free(children); @@ -12321,7 +12322,7 @@ _loop0_33_rule(Parser *p) } 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); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_33_type, seq); return seq; } @@ -12343,7 +12344,7 @@ _gather_32_rule(Parser *p) (seq = _loop0_33_rule(p)) // _loop0_33 ) { - res = _PyPegen_seq_insert_in_front(p, elem, seq); + res = _Ta3Pegen_seq_insert_in_front(p, elem, seq); goto done; } p->mark = mark; @@ -12366,9 +12367,9 @@ _tmp_34_rule(Parser *p) Token * keyword; expr_ty z; if ( - (keyword = _PyPegen_expect_token(p, 531)) // token='as' + (keyword = _Ta3Pegen_expect_token(p, 531)) // token='as' && - (z = _PyPegen_name_token(p)) // NAME + (z = _Ta3Pegen_name_token(p)) // NAME ) { res = z; @@ -12406,7 +12407,7 @@ _loop0_36_rule(Parser *p) alias_ty elem; Token * literal; while ( - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && (elem = dotted_as_name_rule(p)) // dotted_as_name ) @@ -12430,7 +12431,7 @@ _loop0_36_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_36"); PyMem_Free(children); @@ -12438,7 +12439,7 @@ _loop0_36_rule(Parser *p) } 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); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_36_type, seq); return seq; } @@ -12460,7 +12461,7 @@ _gather_35_rule(Parser *p) (seq = _loop0_36_rule(p)) // _loop0_36 ) { - res = _PyPegen_seq_insert_in_front(p, elem, seq); + res = _Ta3Pegen_seq_insert_in_front(p, elem, seq); goto done; } p->mark = mark; @@ -12483,9 +12484,9 @@ _tmp_37_rule(Parser *p) Token * keyword; expr_ty z; if ( - (keyword = _PyPegen_expect_token(p, 531)) // token='as' + (keyword = _Ta3Pegen_expect_token(p, 531)) // token='as' && - (z = _PyPegen_name_token(p)) // NAME + (z = _Ta3Pegen_name_token(p)) // NAME ) { res = z; @@ -12523,7 +12524,7 @@ _loop0_39_rule(Parser *p) withitem_ty elem; Token * literal; while ( - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && (elem = with_item_rule(p)) // with_item ) @@ -12547,7 +12548,7 @@ _loop0_39_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_39"); PyMem_Free(children); @@ -12555,7 +12556,7 @@ _loop0_39_rule(Parser *p) } 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); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_39_type, seq); return seq; } @@ -12577,7 +12578,7 @@ _gather_38_rule(Parser *p) (seq = _loop0_39_rule(p)) // _loop0_39 ) { - res = _PyPegen_seq_insert_in_front(p, elem, seq); + res = _Ta3Pegen_seq_insert_in_front(p, elem, seq); goto done; } p->mark = mark; @@ -12608,7 +12609,7 @@ _loop0_41_rule(Parser *p) withitem_ty elem; Token * literal; while ( - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && (elem = with_item_rule(p)) // with_item ) @@ -12632,7 +12633,7 @@ _loop0_41_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_41"); PyMem_Free(children); @@ -12640,7 +12641,7 @@ _loop0_41_rule(Parser *p) } 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); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_41_type, seq); return seq; } @@ -12662,7 +12663,7 @@ _gather_40_rule(Parser *p) (seq = _loop0_41_rule(p)) // _loop0_41 ) { - res = _PyPegen_seq_insert_in_front(p, elem, seq); + res = _Ta3Pegen_seq_insert_in_front(p, elem, seq); goto done; } p->mark = mark; @@ -12693,7 +12694,7 @@ _loop0_43_rule(Parser *p) withitem_ty elem; Token * literal; while ( - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && (elem = with_item_rule(p)) // with_item ) @@ -12717,7 +12718,7 @@ _loop0_43_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_43"); PyMem_Free(children); @@ -12725,7 +12726,7 @@ _loop0_43_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop0_43_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_43_type, seq); return seq; } @@ -12747,7 +12748,7 @@ _gather_42_rule(Parser *p) (seq = _loop0_43_rule(p)) // _loop0_43 ) { - res = _PyPegen_seq_insert_in_front(p, elem, seq); + res = _Ta3Pegen_seq_insert_in_front(p, elem, seq); goto done; } p->mark = mark; @@ -12778,7 +12779,7 @@ _loop0_45_rule(Parser *p) withitem_ty elem; Token * literal; while ( - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && (elem = with_item_rule(p)) // with_item ) @@ -12802,7 +12803,7 @@ _loop0_45_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_45"); PyMem_Free(children); @@ -12810,7 +12811,7 @@ _loop0_45_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop0_45_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_45_type, seq); return seq; } @@ -12832,7 +12833,7 @@ _gather_44_rule(Parser *p) (seq = _loop0_45_rule(p)) // _loop0_45 ) { - res = _PyPegen_seq_insert_in_front(p, elem, seq); + res = _Ta3Pegen_seq_insert_in_front(p, elem, seq); goto done; } p->mark = mark; @@ -12855,7 +12856,7 @@ _tmp_46_rule(Parser *p) Token * keyword; expr_ty t; if ( - (keyword = _PyPegen_expect_token(p, 531)) // token='as' + (keyword = _Ta3Pegen_expect_token(p, 531)) // token='as' && (t = target_rule(p)) // target ) @@ -12915,7 +12916,7 @@ _loop1_47_rule(Parser *p) PyMem_Free(children); return NULL; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_47"); PyMem_Free(children); @@ -12923,7 +12924,7 @@ _loop1_47_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop1_47_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop1_47_type, seq); return seq; } @@ -12940,7 +12941,7 @@ _tmp_48_rule(Parser *p) Token * keyword; expr_ty z; if ( - (keyword = _PyPegen_expect_token(p, 531)) // token='as' + (keyword = _Ta3Pegen_expect_token(p, 531)) // token='as' && (z = target_rule(p)) // target ) @@ -12972,7 +12973,7 @@ _tmp_49_rule(Parser *p) Token * keyword; expr_ty z; if ( - (keyword = _PyPegen_expect_token(p, 514)) // token='from' + (keyword = _Ta3Pegen_expect_token(p, 514)) // token='from' && (z = expression_rule(p)) // expression ) @@ -13004,7 +13005,7 @@ _tmp_50_rule(Parser *p) Token * literal; expr_ty z; if ( - (literal = _PyPegen_expect_token(p, 51)) // token='->' + (literal = _Ta3Pegen_expect_token(p, 51)) // token='->' && (z = expression_rule(p)) // expression ) @@ -13036,7 +13037,7 @@ _tmp_51_rule(Parser *p) Token * literal; expr_ty z; if ( - (literal = _PyPegen_expect_token(p, 51)) // token='->' + (literal = _Ta3Pegen_expect_token(p, 51)) // token='->' && (z = expression_rule(p)) // expression ) @@ -13068,12 +13069,12 @@ _tmp_52_rule(Parser *p) Token * indent_var; Token * newline_var; if ( - (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + (newline_var = _Ta3Pegen_expect_token(p, NEWLINE)) // token='NEWLINE' && - (indent_var = _PyPegen_expect_token(p, INDENT)) // token='INDENT' + (indent_var = _Ta3Pegen_expect_token(p, INDENT)) // token='INDENT' ) { - res = _PyPegen_dummy_name(p, newline_var, indent_var); + res = _Ta3Pegen_dummy_name(p, newline_var, indent_var); goto done; } p->mark = mark; @@ -13120,7 +13121,7 @@ _loop0_53_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_53"); PyMem_Free(children); @@ -13128,7 +13129,7 @@ _loop0_53_rule(Parser *p) } 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); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_53_type, seq); return seq; } @@ -13169,7 +13170,7 @@ _loop0_54_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_54"); PyMem_Free(children); @@ -13177,7 +13178,7 @@ _loop0_54_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop0_54_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_54_type, seq); return seq; } @@ -13218,7 +13219,7 @@ _loop0_55_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_55"); PyMem_Free(children); @@ -13226,7 +13227,7 @@ _loop0_55_rule(Parser *p) } 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); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_55_type, seq); return seq; } @@ -13271,7 +13272,7 @@ _loop1_56_rule(Parser *p) PyMem_Free(children); return NULL; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_56"); PyMem_Free(children); @@ -13279,7 +13280,7 @@ _loop1_56_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop1_56_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop1_56_type, seq); return seq; } @@ -13320,7 +13321,7 @@ _loop0_57_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_57"); PyMem_Free(children); @@ -13328,7 +13329,7 @@ _loop0_57_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop0_57_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_57_type, seq); return seq; } @@ -13373,7 +13374,7 @@ _loop1_58_rule(Parser *p) PyMem_Free(children); return NULL; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_58"); PyMem_Free(children); @@ -13381,7 +13382,7 @@ _loop1_58_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop1_58_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop1_58_type, seq); return seq; } @@ -13426,7 +13427,7 @@ _loop1_59_rule(Parser *p) PyMem_Free(children); return NULL; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_59"); PyMem_Free(children); @@ -13434,7 +13435,7 @@ _loop1_59_rule(Parser *p) } 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); + _Ta3Pegen_insert_memo(p, start_mark, _loop1_59_type, seq); return seq; } @@ -13479,7 +13480,7 @@ _loop1_60_rule(Parser *p) PyMem_Free(children); return NULL; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_60"); PyMem_Free(children); @@ -13487,7 +13488,7 @@ _loop1_60_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop1_60_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop1_60_type, seq); return seq; } @@ -13528,7 +13529,7 @@ _loop0_61_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_61"); PyMem_Free(children); @@ -13536,7 +13537,7 @@ _loop0_61_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop0_61_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_61_type, seq); return seq; } @@ -13581,7 +13582,7 @@ _loop1_62_rule(Parser *p) PyMem_Free(children); return NULL; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_62"); PyMem_Free(children); @@ -13589,7 +13590,7 @@ _loop1_62_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop1_62_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop1_62_type, seq); return seq; } @@ -13630,7 +13631,7 @@ _loop0_63_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_63"); PyMem_Free(children); @@ -13638,7 +13639,7 @@ _loop0_63_rule(Parser *p) } 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); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_63_type, seq); return seq; } @@ -13683,7 +13684,7 @@ _loop1_64_rule(Parser *p) PyMem_Free(children); return NULL; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_64"); PyMem_Free(children); @@ -13691,7 +13692,7 @@ _loop1_64_rule(Parser *p) } 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); + _Ta3Pegen_insert_memo(p, start_mark, _loop1_64_type, seq); return seq; } @@ -13732,7 +13733,7 @@ _loop0_65_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_65"); PyMem_Free(children); @@ -13740,7 +13741,7 @@ _loop0_65_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop0_65_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_65_type, seq); return seq; } @@ -13785,7 +13786,7 @@ _loop1_66_rule(Parser *p) PyMem_Free(children); return NULL; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_66"); PyMem_Free(children); @@ -13793,7 +13794,7 @@ _loop1_66_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop1_66_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop1_66_type, seq); return seq; } @@ -13838,7 +13839,7 @@ _loop1_67_rule(Parser *p) PyMem_Free(children); return NULL; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_67"); PyMem_Free(children); @@ -13846,7 +13847,7 @@ _loop1_67_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop1_67_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop1_67_type, seq); return seq; } @@ -13864,11 +13865,11 @@ _tmp_68_rule(Parser *p) Token * literal_1; void *z; if ( - (literal = _PyPegen_expect_token(p, 7)) // token='(' + (literal = _Ta3Pegen_expect_token(p, 7)) // token='(' && (z = arguments_rule(p), 1) // arguments? && - (literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + (literal_1 = _Ta3Pegen_expect_token(p, 8)) // token=')' ) { res = z; @@ -13906,7 +13907,7 @@ _loop0_70_rule(Parser *p) expr_ty elem; Token * literal; while ( - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && (elem = star_expression_rule(p)) // star_expression ) @@ -13930,7 +13931,7 @@ _loop0_70_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_70"); PyMem_Free(children); @@ -13938,7 +13939,7 @@ _loop0_70_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop0_70_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_70_type, seq); return seq; } @@ -13960,7 +13961,7 @@ _gather_69_rule(Parser *p) (seq = _loop0_70_rule(p)) // _loop0_70 ) { - res = _PyPegen_seq_insert_in_front(p, elem, seq); + res = _Ta3Pegen_seq_insert_in_front(p, elem, seq); goto done; } p->mark = mark; @@ -14011,7 +14012,7 @@ _loop1_71_rule(Parser *p) PyMem_Free(children); return NULL; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_71"); PyMem_Free(children); @@ -14019,7 +14020,7 @@ _loop1_71_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop1_71_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop1_71_type, seq); return seq; } @@ -14044,7 +14045,7 @@ _loop0_73_rule(Parser *p) expr_ty elem; Token * literal; while ( - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && (elem = star_named_expression_rule(p)) // star_named_expression ) @@ -14068,7 +14069,7 @@ _loop0_73_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_73"); PyMem_Free(children); @@ -14076,7 +14077,7 @@ _loop0_73_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop0_73_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_73_type, seq); return seq; } @@ -14098,7 +14099,7 @@ _gather_72_rule(Parser *p) (seq = _loop0_73_rule(p)) // _loop0_73 ) { - res = _PyPegen_seq_insert_in_front(p, elem, seq); + res = _Ta3Pegen_seq_insert_in_front(p, elem, seq); goto done; } p->mark = mark; @@ -14149,7 +14150,7 @@ _loop1_74_rule(Parser *p) PyMem_Free(children); return NULL; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_74"); PyMem_Free(children); @@ -14157,7 +14158,7 @@ _loop1_74_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop1_74_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop1_74_type, seq); return seq; } @@ -14198,7 +14199,7 @@ _loop0_75_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_75"); PyMem_Free(children); @@ -14206,7 +14207,7 @@ _loop0_75_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop0_75_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_75_type, seq); return seq; } @@ -14247,7 +14248,7 @@ _loop0_76_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_76"); PyMem_Free(children); @@ -14255,7 +14256,7 @@ _loop0_76_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop0_76_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_76_type, seq); return seq; } @@ -14296,7 +14297,7 @@ _loop0_77_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_77"); PyMem_Free(children); @@ -14304,7 +14305,7 @@ _loop0_77_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop0_77_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_77_type, seq); return seq; } @@ -14349,7 +14350,7 @@ _loop1_78_rule(Parser *p) PyMem_Free(children); return NULL; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_78"); PyMem_Free(children); @@ -14357,7 +14358,7 @@ _loop1_78_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop1_78_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop1_78_type, seq); return seq; } @@ -14398,7 +14399,7 @@ _loop0_79_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_79"); PyMem_Free(children); @@ -14406,7 +14407,7 @@ _loop0_79_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop0_79_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_79_type, seq); return seq; } @@ -14451,7 +14452,7 @@ _loop1_80_rule(Parser *p) PyMem_Free(children); return NULL; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_80"); PyMem_Free(children); @@ -14459,7 +14460,7 @@ _loop1_80_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop1_80_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop1_80_type, seq); return seq; } @@ -14504,7 +14505,7 @@ _loop1_81_rule(Parser *p) PyMem_Free(children); return NULL; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_81"); PyMem_Free(children); @@ -14512,7 +14513,7 @@ _loop1_81_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop1_81_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop1_81_type, seq); return seq; } @@ -14557,7 +14558,7 @@ _loop1_82_rule(Parser *p) PyMem_Free(children); return NULL; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_82"); PyMem_Free(children); @@ -14565,7 +14566,7 @@ _loop1_82_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop1_82_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop1_82_type, seq); return seq; } @@ -14606,7 +14607,7 @@ _loop0_83_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_83"); PyMem_Free(children); @@ -14614,7 +14615,7 @@ _loop0_83_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop0_83_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_83_type, seq); return seq; } @@ -14659,7 +14660,7 @@ _loop1_84_rule(Parser *p) PyMem_Free(children); return NULL; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_84"); PyMem_Free(children); @@ -14667,7 +14668,7 @@ _loop1_84_rule(Parser *p) } 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); + _Ta3Pegen_insert_memo(p, start_mark, _loop1_84_type, seq); return seq; } @@ -14708,7 +14709,7 @@ _loop0_85_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_85"); PyMem_Free(children); @@ -14716,7 +14717,7 @@ _loop0_85_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop0_85_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_85_type, seq); return seq; } @@ -14761,7 +14762,7 @@ _loop1_86_rule(Parser *p) PyMem_Free(children); return NULL; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_86"); PyMem_Free(children); @@ -14769,7 +14770,7 @@ _loop1_86_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop1_86_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop1_86_type, seq); return seq; } @@ -14810,7 +14811,7 @@ _loop0_87_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_87"); PyMem_Free(children); @@ -14818,7 +14819,7 @@ _loop0_87_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop0_87_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_87_type, seq); return seq; } @@ -14863,7 +14864,7 @@ _loop1_88_rule(Parser *p) PyMem_Free(children); return NULL; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_88"); PyMem_Free(children); @@ -14871,7 +14872,7 @@ _loop1_88_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop1_88_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop1_88_type, seq); return seq; } @@ -14916,7 +14917,7 @@ _loop1_89_rule(Parser *p) PyMem_Free(children); return NULL; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_89"); PyMem_Free(children); @@ -14924,7 +14925,7 @@ _loop1_89_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop1_89_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop1_89_type, seq); return seq; } @@ -14969,7 +14970,7 @@ _loop1_90_rule(Parser *p) PyMem_Free(children); return NULL; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_90"); PyMem_Free(children); @@ -14977,7 +14978,7 @@ _loop1_90_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop1_90_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop1_90_type, seq); return seq; } @@ -15022,7 +15023,7 @@ _loop1_91_rule(Parser *p) PyMem_Free(children); return NULL; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_91"); PyMem_Free(children); @@ -15030,7 +15031,7 @@ _loop1_91_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop1_91_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop1_91_type, seq); return seq; } @@ -15046,10 +15047,10 @@ _tmp_92_rule(Parser *p) { // '!=' Token * tok; if ( - (tok = _PyPegen_expect_token(p, 28)) // token='!=' + (tok = _Ta3Pegen_expect_token(p, 28)) // token='!=' ) { - res = _PyPegen_check_barry_as_flufl ( p ) ? NULL : tok; + res = _Ta3Pegen_check_barry_as_flufl ( p ) ? NULL : tok; if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -15084,7 +15085,7 @@ _loop0_94_rule(Parser *p) expr_ty elem; Token * literal; while ( - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && (elem = slice_rule(p)) // slice ) @@ -15108,7 +15109,7 @@ _loop0_94_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_94"); PyMem_Free(children); @@ -15116,7 +15117,7 @@ _loop0_94_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop0_94_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_94_type, seq); return seq; } @@ -15138,7 +15139,7 @@ _gather_93_rule(Parser *p) (seq = _loop0_94_rule(p)) // _loop0_94 ) { - res = _PyPegen_seq_insert_in_front(p, elem, seq); + res = _Ta3Pegen_seq_insert_in_front(p, elem, seq); goto done; } p->mark = mark; @@ -15161,7 +15162,7 @@ _tmp_95_rule(Parser *p) void *d; Token * literal; if ( - (literal = _PyPegen_expect_token(p, 11)) // token=':' + (literal = _Ta3Pegen_expect_token(p, 11)) // token=':' && (d = expression_rule(p), 1) // expression? ) @@ -15341,7 +15342,7 @@ _loop1_99_rule(Parser *p) { // STRING expr_ty string_var; while ( - (string_var = _PyPegen_string_token(p)) // STRING + (string_var = _Ta3Pegen_string_token(p)) // STRING ) { res = string_var; @@ -15362,7 +15363,7 @@ _loop1_99_rule(Parser *p) PyMem_Free(children); return NULL; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_99"); PyMem_Free(children); @@ -15370,7 +15371,7 @@ _loop1_99_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop1_99_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop1_99_type, seq); return seq; } @@ -15390,12 +15391,12 @@ _tmp_100_rule(Parser *p) if ( (y = star_named_expression_rule(p)) // star_named_expression && - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && (z = star_named_expressions_rule(p), 1) // star_named_expressions? ) { - res = _PyPegen_seq_insert_in_front ( p , y , z ); + res = _Ta3Pegen_seq_insert_in_front ( p , y , z ); if (res == NULL && PyErr_Occurred()) { p->error_indicator = 1; return NULL; @@ -15466,7 +15467,7 @@ _loop0_103_rule(Parser *p) KeyValuePair* elem; Token * literal; while ( - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && (elem = kvpair_rule(p)) // kvpair ) @@ -15490,7 +15491,7 @@ _loop0_103_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_103"); PyMem_Free(children); @@ -15498,7 +15499,7 @@ _loop0_103_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop0_103_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_103_type, seq); return seq; } @@ -15520,7 +15521,7 @@ _gather_102_rule(Parser *p) (seq = _loop0_103_rule(p)) // _loop0_103 ) { - res = _PyPegen_seq_insert_in_front(p, elem, seq); + res = _Ta3Pegen_seq_insert_in_front(p, elem, seq); goto done; } p->mark = mark; @@ -15571,7 +15572,7 @@ _loop1_104_rule(Parser *p) PyMem_Free(children); return NULL; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_104"); PyMem_Free(children); @@ -15579,7 +15580,7 @@ _loop1_104_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop1_104_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop1_104_type, seq); return seq; } @@ -15620,7 +15621,7 @@ _loop0_105_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_105"); PyMem_Free(children); @@ -15628,7 +15629,7 @@ _loop0_105_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop0_105_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_105_type, seq); return seq; } @@ -15669,7 +15670,7 @@ _loop0_106_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_106"); PyMem_Free(children); @@ -15677,7 +15678,7 @@ _loop0_106_rule(Parser *p) } 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); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_106_type, seq); return seq; } @@ -15694,7 +15695,7 @@ _tmp_107_rule(Parser *p) expr_ty c; Token * literal; if ( - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && (c = args_rule(p)) // args ) @@ -15726,7 +15727,7 @@ _tmp_108_rule(Parser *p) expr_ty c; Token * literal; if ( - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && (c = args_rule(p)) // args ) @@ -15766,7 +15767,7 @@ _loop0_110_rule(Parser *p) KeywordOrStarred* elem; Token * literal; while ( - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && (elem = kwarg_or_starred_rule(p)) // kwarg_or_starred ) @@ -15790,7 +15791,7 @@ _loop0_110_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_110"); PyMem_Free(children); @@ -15798,7 +15799,7 @@ _loop0_110_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop0_110_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_110_type, seq); return seq; } @@ -15820,7 +15821,7 @@ _gather_109_rule(Parser *p) (seq = _loop0_110_rule(p)) // _loop0_110 ) { - res = _PyPegen_seq_insert_in_front(p, elem, seq); + res = _Ta3Pegen_seq_insert_in_front(p, elem, seq); goto done; } p->mark = mark; @@ -15851,7 +15852,7 @@ _loop0_112_rule(Parser *p) KeywordOrStarred* elem; Token * literal; while ( - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && (elem = kwarg_or_double_starred_rule(p)) // kwarg_or_double_starred ) @@ -15875,7 +15876,7 @@ _loop0_112_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_112"); PyMem_Free(children); @@ -15883,7 +15884,7 @@ _loop0_112_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop0_112_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_112_type, seq); return seq; } @@ -15905,7 +15906,7 @@ _gather_111_rule(Parser *p) (seq = _loop0_112_rule(p)) // _loop0_112 ) { - res = _PyPegen_seq_insert_in_front(p, elem, seq); + res = _Ta3Pegen_seq_insert_in_front(p, elem, seq); goto done; } p->mark = mark; @@ -15936,7 +15937,7 @@ _loop0_114_rule(Parser *p) KeywordOrStarred* elem; Token * literal; while ( - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && (elem = kwarg_or_starred_rule(p)) // kwarg_or_starred ) @@ -15960,7 +15961,7 @@ _loop0_114_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_114"); PyMem_Free(children); @@ -15968,7 +15969,7 @@ _loop0_114_rule(Parser *p) } 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); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_114_type, seq); return seq; } @@ -15990,7 +15991,7 @@ _gather_113_rule(Parser *p) (seq = _loop0_114_rule(p)) // _loop0_114 ) { - res = _PyPegen_seq_insert_in_front(p, elem, seq); + res = _Ta3Pegen_seq_insert_in_front(p, elem, seq); goto done; } p->mark = mark; @@ -16021,7 +16022,7 @@ _loop0_116_rule(Parser *p) KeywordOrStarred* elem; Token * literal; while ( - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && (elem = kwarg_or_double_starred_rule(p)) // kwarg_or_double_starred ) @@ -16045,7 +16046,7 @@ _loop0_116_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_116"); PyMem_Free(children); @@ -16053,7 +16054,7 @@ _loop0_116_rule(Parser *p) } 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); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_116_type, seq); return seq; } @@ -16075,7 +16076,7 @@ _gather_115_rule(Parser *p) (seq = _loop0_116_rule(p)) // _loop0_116 ) { - res = _PyPegen_seq_insert_in_front(p, elem, seq); + res = _Ta3Pegen_seq_insert_in_front(p, elem, seq); goto done; } p->mark = mark; @@ -16122,7 +16123,7 @@ _loop0_117_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_117"); PyMem_Free(children); @@ -16130,7 +16131,7 @@ _loop0_117_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop0_117_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_117_type, seq); return seq; } @@ -16155,7 +16156,7 @@ _loop0_119_rule(Parser *p) expr_ty elem; Token * literal; while ( - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && (elem = star_target_rule(p)) // star_target ) @@ -16179,7 +16180,7 @@ _loop0_119_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_119"); PyMem_Free(children); @@ -16187,7 +16188,7 @@ _loop0_119_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop0_119_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_119_type, seq); return seq; } @@ -16209,7 +16210,7 @@ _gather_118_rule(Parser *p) (seq = _loop0_119_rule(p)) // _loop0_119 ) { - res = _PyPegen_seq_insert_in_front(p, elem, seq); + res = _Ta3Pegen_seq_insert_in_front(p, elem, seq); goto done; } p->mark = mark; @@ -16231,7 +16232,7 @@ _tmp_120_rule(Parser *p) { // !'*' star_target expr_ty star_target_var; if ( - _PyPegen_lookahead_with_int(0, _PyPegen_expect_token, p, 16) // token='*' + _Ta3Pegen_lookahead_with_int(0, _Ta3Pegen_expect_token, p, 16) // token='*' && (star_target_var = star_target_rule(p)) // star_target ) @@ -16267,7 +16268,7 @@ _loop0_122_rule(Parser *p) expr_ty elem; Token * literal; while ( - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && (elem = del_target_rule(p)) // del_target ) @@ -16291,7 +16292,7 @@ _loop0_122_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_122"); PyMem_Free(children); @@ -16299,7 +16300,7 @@ _loop0_122_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop0_122_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_122_type, seq); return seq; } @@ -16321,7 +16322,7 @@ _gather_121_rule(Parser *p) (seq = _loop0_122_rule(p)) // _loop0_122 ) { - res = _PyPegen_seq_insert_in_front(p, elem, seq); + res = _Ta3Pegen_seq_insert_in_front(p, elem, seq); goto done; } p->mark = mark; @@ -16352,7 +16353,7 @@ _loop0_124_rule(Parser *p) expr_ty elem; Token * literal; while ( - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && (elem = target_rule(p)) // target ) @@ -16376,7 +16377,7 @@ _loop0_124_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_124"); PyMem_Free(children); @@ -16384,7 +16385,7 @@ _loop0_124_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop0_124_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_124_type, seq); return seq; } @@ -16406,7 +16407,7 @@ _gather_123_rule(Parser *p) (seq = _loop0_124_rule(p)) // _loop0_124 ) { - res = _PyPegen_seq_insert_in_front(p, elem, seq); + res = _Ta3Pegen_seq_insert_in_front(p, elem, seq); goto done; } p->mark = mark; @@ -16445,7 +16446,7 @@ _tmp_125_rule(Parser *p) (for_if_clauses_var = for_if_clauses_rule(p)) // for_if_clauses ) { - res = _PyPegen_dummy_name(p, expression_var, for_if_clauses_var); + res = _Ta3Pegen_dummy_name(p, expression_var, for_if_clauses_var); goto done; } p->mark = mark; @@ -16468,12 +16469,12 @@ _tmp_126_rule(Parser *p) expr_ty annotated_rhs_var; Token * literal; if ( - (literal = _PyPegen_expect_token(p, 22)) // token='=' + (literal = _Ta3Pegen_expect_token(p, 22)) // token='=' && (annotated_rhs_var = annotated_rhs_rule(p)) // annotated_rhs ) { - res = _PyPegen_dummy_name(p, literal, annotated_rhs_var); + res = _Ta3Pegen_dummy_name(p, literal, annotated_rhs_var); goto done; } p->mark = mark; @@ -16495,7 +16496,7 @@ _tmp_127_rule(Parser *p) { // '=' Token * literal; if ( - (literal = _PyPegen_expect_token(p, 22)) // token='=' + (literal = _Ta3Pegen_expect_token(p, 22)) // token='=' ) { res = literal; @@ -16567,7 +16568,7 @@ _tmp_129_rule(Parser *p) { // '[' Token * literal; if ( - (literal = _PyPegen_expect_token(p, 9)) // token='[' + (literal = _Ta3Pegen_expect_token(p, 9)) // token='[' ) { res = literal; @@ -16578,7 +16579,7 @@ _tmp_129_rule(Parser *p) { // '(' Token * literal; if ( - (literal = _PyPegen_expect_token(p, 7)) // token='(' + (literal = _Ta3Pegen_expect_token(p, 7)) // token='(' ) { res = literal; @@ -16589,7 +16590,7 @@ _tmp_129_rule(Parser *p) { // '{' Token * literal; if ( - (literal = _PyPegen_expect_token(p, 25)) // token='{' + (literal = _Ta3Pegen_expect_token(p, 25)) // token='{' ) { res = literal; @@ -16639,7 +16640,7 @@ _loop0_130_rule(Parser *p) } p->mark = mark; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop0_130"); PyMem_Free(children); @@ -16647,7 +16648,7 @@ _loop0_130_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop0_130_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop0_130_type, seq); return seq; } @@ -16699,7 +16700,7 @@ _tmp_132_rule(Parser *p) { // ')' Token * literal; if ( - (literal = _PyPegen_expect_token(p, 8)) // token=')' + (literal = _Ta3Pegen_expect_token(p, 8)) // token=')' ) { res = literal; @@ -16711,12 +16712,12 @@ _tmp_132_rule(Parser *p) void *_tmp_146_var; Token * literal; if ( - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && (_tmp_146_var = _tmp_146_rule(p)) // ')' | '**' ) { - res = _PyPegen_dummy_name(p, literal, _tmp_146_var); + res = _Ta3Pegen_dummy_name(p, literal, _tmp_146_var); goto done; } p->mark = mark; @@ -16738,7 +16739,7 @@ _tmp_133_rule(Parser *p) { // ':' Token * literal; if ( - (literal = _PyPegen_expect_token(p, 11)) // token=':' + (literal = _Ta3Pegen_expect_token(p, 11)) // token=':' ) { res = literal; @@ -16750,12 +16751,12 @@ _tmp_133_rule(Parser *p) void *_tmp_147_var; Token * literal; if ( - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && (_tmp_147_var = _tmp_147_rule(p)) // ':' | '**' ) { - res = _PyPegen_dummy_name(p, literal, _tmp_147_var); + res = _Ta3Pegen_dummy_name(p, literal, _tmp_147_var); goto done; } p->mark = mark; @@ -16780,7 +16781,7 @@ _tmp_134_rule(Parser *p) if ( (z = star_targets_rule(p)) // star_targets && - (literal = _PyPegen_expect_token(p, 22)) // token='=' + (literal = _Ta3Pegen_expect_token(p, 22)) // token='=' ) { res = z; @@ -16809,7 +16810,7 @@ _tmp_135_rule(Parser *p) { // '.' Token * literal; if ( - (literal = _PyPegen_expect_token(p, 23)) // token='.' + (literal = _Ta3Pegen_expect_token(p, 23)) // token='.' ) { res = literal; @@ -16820,7 +16821,7 @@ _tmp_135_rule(Parser *p) { // '...' Token * literal; if ( - (literal = _PyPegen_expect_token(p, 52)) // token='...' + (literal = _Ta3Pegen_expect_token(p, 52)) // token='...' ) { res = literal; @@ -16845,7 +16846,7 @@ _tmp_136_rule(Parser *p) { // '.' Token * literal; if ( - (literal = _PyPegen_expect_token(p, 23)) // token='.' + (literal = _Ta3Pegen_expect_token(p, 23)) // token='.' ) { res = literal; @@ -16856,7 +16857,7 @@ _tmp_136_rule(Parser *p) { // '...' Token * literal; if ( - (literal = _PyPegen_expect_token(p, 52)) // token='...' + (literal = _Ta3Pegen_expect_token(p, 52)) // token='...' ) { res = literal; @@ -16883,11 +16884,11 @@ _tmp_137_rule(Parser *p) Token * literal; Token * newline_var; if ( - (literal = _PyPegen_expect_token(p, 49)) // token='@' + (literal = _Ta3Pegen_expect_token(p, 49)) // token='@' && (f = named_expression_rule(p)) // named_expression && - (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + (newline_var = _Ta3Pegen_expect_token(p, NEWLINE)) // token='NEWLINE' ) { res = f; @@ -16917,7 +16918,7 @@ _tmp_138_rule(Parser *p) expr_ty c; Token * literal; if ( - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && (c = star_expression_rule(p)) // star_expression ) @@ -16949,7 +16950,7 @@ _tmp_139_rule(Parser *p) expr_ty c; Token * literal; if ( - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && (c = expression_rule(p)) // expression ) @@ -16981,7 +16982,7 @@ _tmp_140_rule(Parser *p) expr_ty c; Token * keyword; if ( - (keyword = _PyPegen_expect_token(p, 532)) // token='or' + (keyword = _Ta3Pegen_expect_token(p, 532)) // token='or' && (c = conjunction_rule(p)) // conjunction ) @@ -17013,7 +17014,7 @@ _tmp_141_rule(Parser *p) expr_ty c; Token * keyword; if ( - (keyword = _PyPegen_expect_token(p, 533)) // token='and' + (keyword = _Ta3Pegen_expect_token(p, 533)) // token='and' && (c = inversion_rule(p)) // inversion ) @@ -17045,7 +17046,7 @@ _tmp_142_rule(Parser *p) Token * keyword; expr_ty z; if ( - (keyword = _PyPegen_expect_token(p, 510)) // token='if' + (keyword = _Ta3Pegen_expect_token(p, 510)) // token='if' && (z = disjunction_rule(p)) // disjunction ) @@ -17077,7 +17078,7 @@ _tmp_143_rule(Parser *p) Token * keyword; expr_ty z; if ( - (keyword = _PyPegen_expect_token(p, 510)) // token='if' + (keyword = _Ta3Pegen_expect_token(p, 510)) // token='if' && (z = disjunction_rule(p)) // disjunction ) @@ -17109,7 +17110,7 @@ _tmp_144_rule(Parser *p) expr_ty c; Token * literal; if ( - (literal = _PyPegen_expect_token(p, 12)) // token=',' + (literal = _Ta3Pegen_expect_token(p, 12)) // token=',' && (c = star_target_rule(p)) // star_target ) @@ -17169,7 +17170,7 @@ _loop1_145_rule(Parser *p) PyMem_Free(children); return NULL; } - asdl_seq *seq = _Py_asdl_seq_new(n, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena); if (!seq) { PyErr_Format(PyExc_MemoryError, "asdl_seq_new _loop1_145"); PyMem_Free(children); @@ -17177,7 +17178,7 @@ _loop1_145_rule(Parser *p) } for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]); PyMem_Free(children); - _PyPegen_insert_memo(p, start_mark, _loop1_145_type, seq); + _Ta3Pegen_insert_memo(p, start_mark, _loop1_145_type, seq); return seq; } @@ -17193,7 +17194,7 @@ _tmp_146_rule(Parser *p) { // ')' Token * literal; if ( - (literal = _PyPegen_expect_token(p, 8)) // token=')' + (literal = _Ta3Pegen_expect_token(p, 8)) // token=')' ) { res = literal; @@ -17204,7 +17205,7 @@ _tmp_146_rule(Parser *p) { // '**' Token * literal; if ( - (literal = _PyPegen_expect_token(p, 35)) // token='**' + (literal = _Ta3Pegen_expect_token(p, 35)) // token='**' ) { res = literal; @@ -17229,7 +17230,7 @@ _tmp_147_rule(Parser *p) { // ':' Token * literal; if ( - (literal = _PyPegen_expect_token(p, 11)) // token=':' + (literal = _Ta3Pegen_expect_token(p, 11)) // token=':' ) { res = literal; @@ -17240,7 +17241,7 @@ _tmp_147_rule(Parser *p) { // '**' Token * literal; if ( - (literal = _PyPegen_expect_token(p, 35)) // token='**' + (literal = _Ta3Pegen_expect_token(p, 35)) // token='**' ) { res = literal; @@ -17254,7 +17255,7 @@ _tmp_147_rule(Parser *p) } void * -_PyPegen_parse(Parser *p) +_Ta3Pegen_parse(Parser *p) { // Initialize keywords p->keywords = reserved_keywords; diff --git a/ast3/Parser/pegen/parse_string.c b/ast3/Parser/pegen/parse_string.c index ca4b733c..a7fc8a85 100644 --- a/ast3/Parser/pegen/parse_string.c +++ b/ast3/Parser/pegen/parse_string.c @@ -4,6 +4,8 @@ #include "pegen.h" #include "parse_string.h" +#include "../Include/ta3_compat.h" + //// STRING HANDLING FUNCTIONS //// // These functions are ported directly from Python/ast.c with some modifications @@ -27,7 +29,7 @@ warn_invalid_escape_sequence(Parser *p, unsigned char first_invalid_escape_char, PyErr_Clear(); /* This is needed, in order for the SyntaxError to point to the token t, - since _PyPegen_raise_error uses p->tokens[p->fill - 1] for the + since _Ta3Pegen_raise_error uses p->tokens[p->fill - 1] for the error location, if p->known_err_token is not set. */ p->known_err_token = t; RAISE_SYNTAX_ERROR("invalid escape sequence \\%c", first_invalid_escape_char); @@ -131,7 +133,7 @@ static PyObject * decode_bytes_with_escapes(Parser *p, const char *s, Py_ssize_t len, Token *t) { const char *first_invalid_escape; - PyObject *result = _PyBytes_DecodeEscape(s, len, NULL, &first_invalid_escape); + PyObject *result = _PyBytes_DecodeEscape(s, len, NULL, 0, NULL, &first_invalid_escape); if (result == NULL) { return NULL; } @@ -147,11 +149,11 @@ decode_bytes_with_escapes(Parser *p, const char *s, Py_ssize_t len, Token *t) /* s must include the bracketing quote characters, and r, b, u, &/or f prefixes (if any), and embedded escape sequences (if any). - _PyPegen_parsestr parses it, and sets *result to decoded Python string object. + _Ta3Pegen_parsestr parses it, and sets *result to decoded Python string object. If the string is an f-string, set *fstr and *fstrlen to the unparsed string object. Return 0 if no errors occurred. */ int -_PyPegen_parsestr(Parser *p, int *bytesmode, int *rawmode, PyObject **result, +_Ta3Pegen_parsestr(Parser *p, int *bytesmode, int *rawmode, PyObject **result, const char **fstr, Py_ssize_t *fstrlen, Token *t) { const char *s = PyBytes_AsString(t->bytes); @@ -602,23 +604,23 @@ fstring_compile_expr(Parser *p, const char *expr_start, const char *expr_end, str[len+1] = ')'; str[len+2] = 0; - struct tok_state* tok = PyTokenizer_FromString(str, 1); + struct tok_state* tok = Ta3Tokenizer_FromString(str, 1); if (tok == NULL) { return NULL; } tok->filename = PyUnicode_FromString(""); if (!tok->filename) { - PyTokenizer_Free(tok); + Ta3Tokenizer_Free(tok); return NULL; } - Parser *p2 = _PyPegen_Parser_New(tok, Py_fstring_input, p->flags, p->feature_version, + Parser *p2 = _Ta3Pegen_Parser_New(tok, Py_fstring_input, p->flags, p->feature_version, NULL, p->arena); p2->starting_lineno = p->starting_lineno + p->tok->first_lineno - 1; p2->starting_col_offset = p->tok->first_lineno == p->tok->lineno ? p->starting_col_offset + t->col_offset : 0; - expr = _PyPegen_run_parser(p2); + expr = _Ta3Pegen_run_parser(p2); if (expr == NULL) { goto exit; @@ -632,8 +634,8 @@ fstring_compile_expr(Parser *p, const char *expr_start, const char *expr_end, result = expr; exit: - _PyPegen_Parser_Free(p2); - PyTokenizer_Free(tok); + _Ta3Pegen_Parser_Free(p2); + Ta3Tokenizer_Free(tok); return result; } @@ -1174,7 +1176,7 @@ ExprList_Finish(ExprList *l, PyArena *arena) ExprList_check_invariants(l); /* Allocate the asdl_seq and copy the expressions in to it. */ - seq = _Py_asdl_seq_new(l->size, arena); + seq = _Ta3_asdl_seq_new(l->size, arena); if (seq) { Py_ssize_t i; for (i = 0; i < l->size; i++) @@ -1197,7 +1199,7 @@ FstringParser_check_invariants(FstringParser *state) #endif void -_PyPegen_FstringParser_Init(FstringParser *state) +_Ta3Pegen_FstringParser_Init(FstringParser *state) { state->last_str = NULL; state->fmode = 0; @@ -1206,7 +1208,7 @@ _PyPegen_FstringParser_Init(FstringParser *state) } void -_PyPegen_FstringParser_Dealloc(FstringParser *state) +_Ta3Pegen_FstringParser_Dealloc(FstringParser *state) { FstringParser_check_invariants(state); @@ -1228,7 +1230,7 @@ make_str_node_and_del(Parser *p, PyObject **str, Token* first_token, Token *last } const char* the_str = PyBytes_AsString(first_token->bytes); if (the_str && the_str[0] == 'u') { - kind = _PyPegen_new_identifier(p, "u"); + kind = _Ta3Pegen_new_identifier(p, "u"); } if (kind == NULL && PyErr_Occurred()) { @@ -1244,7 +1246,7 @@ make_str_node_and_del(Parser *p, PyObject **str, Token* first_token, Token *last /* Add a non-f-string (that is, a regular literal string). str is decref'd. */ int -_PyPegen_FstringParser_ConcatAndDel(FstringParser *state, PyObject *str) +_Ta3Pegen_FstringParser_ConcatAndDel(FstringParser *state, PyObject *str) { FstringParser_check_invariants(state); @@ -1271,7 +1273,7 @@ _PyPegen_FstringParser_ConcatAndDel(FstringParser *state, PyObject *str) /* Parse an f-string. The f-string is in *str to end, with no 'f' or quotes. */ int -_PyPegen_FstringParser_ConcatFstring(Parser *p, FstringParser *state, const char **str, +_Ta3Pegen_FstringParser_ConcatFstring(Parser *p, FstringParser *state, const char **str, const char *end, int raw, int recurse_lvl, Token *first_token, Token* t, Token *last_token) { @@ -1295,12 +1297,12 @@ _PyPegen_FstringParser_ConcatFstring(Parser *p, FstringParser *state, const char return -1; /* Add the literal, if any. */ - if (literal && _PyPegen_FstringParser_ConcatAndDel(state, literal) < 0) { + if (literal && _Ta3Pegen_FstringParser_ConcatAndDel(state, literal) < 0) { Py_XDECREF(expr_text); return -1; } /* Add the expr_text, if any. */ - if (expr_text && _PyPegen_FstringParser_ConcatAndDel(state, expr_text) < 0) { + if (expr_text && _Ta3Pegen_FstringParser_ConcatAndDel(state, expr_text) < 0) { return -1; } @@ -1352,7 +1354,7 @@ _PyPegen_FstringParser_ConcatFstring(Parser *p, FstringParser *state, const char /* Convert the partial state reflected in last_str and expr_list to an expr_ty. The expr_ty can be a Constant, or a JoinedStr. */ expr_ty -_PyPegen_FstringParser_Finish(Parser *p, FstringParser *state, Token* first_token, +_Ta3Pegen_FstringParser_Finish(Parser *p, FstringParser *state, Token* first_token, Token *last_token) { asdl_seq *seq; @@ -1386,11 +1388,11 @@ _PyPegen_FstringParser_Finish(Parser *p, FstringParser *state, Token* first_toke if (!seq) goto error; - return _Py_JoinedStr(seq, first_token->lineno, first_token->col_offset, + return _Ta3_JoinedStr(seq, first_token->lineno, first_token->col_offset, last_token->end_lineno, last_token->end_col_offset, p->arena); error: - _PyPegen_FstringParser_Dealloc(state); + _Ta3Pegen_FstringParser_Dealloc(state); return NULL; } @@ -1403,12 +1405,12 @@ fstring_parse(Parser *p, const char **str, const char *end, int raw, { FstringParser state; - _PyPegen_FstringParser_Init(&state); - if (_PyPegen_FstringParser_ConcatFstring(p, &state, str, end, raw, recurse_lvl, + _Ta3Pegen_FstringParser_Init(&state); + if (_Ta3Pegen_FstringParser_ConcatFstring(p, &state, str, end, raw, recurse_lvl, first_token, t, last_token) < 0) { - _PyPegen_FstringParser_Dealloc(&state); + _Ta3Pegen_FstringParser_Dealloc(&state); return NULL; } - return _PyPegen_FstringParser_Finish(p, &state, t, t); + return _Ta3Pegen_FstringParser_Finish(p, &state, t, t); } diff --git a/ast3/Parser/pegen/parse_string.h b/ast3/Parser/pegen/parse_string.h index 07f81661..95af8546 100644 --- a/ast3/Parser/pegen/parse_string.h +++ b/ast3/Parser/pegen/parse_string.h @@ -33,14 +33,14 @@ typedef struct { int fmode; } FstringParser; -void _PyPegen_FstringParser_Init(FstringParser *); -int _PyPegen_parsestr(Parser *, int *, int *, PyObject **, +void _Ta3Pegen_FstringParser_Init(FstringParser *); +int _Ta3Pegen_parsestr(Parser *, int *, int *, PyObject **, const char **, Py_ssize_t *, Token *); -int _PyPegen_FstringParser_ConcatFstring(Parser *, FstringParser *, const char **, +int _Ta3Pegen_FstringParser_ConcatFstring(Parser *, FstringParser *, const char **, const char *, int, int, Token *, Token *, Token *); -int _PyPegen_FstringParser_ConcatAndDel(FstringParser *, PyObject *); -expr_ty _PyPegen_FstringParser_Finish(Parser *, FstringParser *, Token *, Token *); -void _PyPegen_FstringParser_Dealloc(FstringParser *); +int _Ta3Pegen_FstringParser_ConcatAndDel(FstringParser *, PyObject *); +expr_ty _Ta3Pegen_FstringParser_Finish(Parser *, FstringParser *, Token *, Token *); +void _Ta3Pegen_FstringParser_Dealloc(FstringParser *); #endif diff --git a/ast3/Parser/pegen/peg_api.c b/ast3/Parser/pegen/peg_api.c index 5e71ecdb..d3683c84 100644 --- a/ast3/Parser/pegen/peg_api.c +++ b/ast3/Parser/pegen/peg_api.c @@ -4,51 +4,51 @@ #include "pegen.h" mod_ty -PyPegen_ASTFromString(const char *str, const char *filename, int mode, - PyCompilerFlags *flags, PyArena *arena) +Ta3Pegen_ASTFromString(const char *str, const char *filename, int mode, + PegenCompilerFlags *flags, PyArena *arena) { PyObject *filename_ob = PyUnicode_FromString(filename); if (filename_ob == NULL) { return NULL; } - mod_ty result = PyPegen_ASTFromStringObject(str, filename_ob, mode, flags, arena); + mod_ty result = Ta3Pegen_ASTFromStringObject(str, filename_ob, mode, flags, arena); Py_XDECREF(filename_ob); return result; } mod_ty -PyPegen_ASTFromStringObject(const char *str, PyObject* filename, int mode, - PyCompilerFlags *flags, PyArena *arena) +Ta3Pegen_ASTFromStringObject(const char *str, PyObject* filename, int mode, + PegenCompilerFlags *flags, PyArena *arena) { if (PySys_Audit("compile", "yO", str, filename) < 0) { return NULL; } - mod_ty result = _PyPegen_run_parser_from_string(str, mode, filename, flags, arena); + mod_ty result = _Ta3Pegen_run_parser_from_string(str, mode, filename, flags, arena); return result; } mod_ty -PyPegen_ASTFromFilename(const char *filename, int mode, PyCompilerFlags *flags, PyArena *arena) +Ta3Pegen_ASTFromFilename(const char *filename, int mode, PegenCompilerFlags *flags, PyArena *arena) { PyObject *filename_ob = PyUnicode_FromString(filename); if (filename_ob == NULL) { return NULL; } - mod_ty result = _PyPegen_run_parser_from_file(filename, mode, filename_ob, flags, arena); + mod_ty result = _Ta3Pegen_run_parser_from_file(filename, mode, filename_ob, flags, arena); Py_XDECREF(filename_ob); return result; } mod_ty -PyPegen_ASTFromFileObject(FILE *fp, PyObject *filename_ob, int mode, +Ta3Pegen_ASTFromFileObject(FILE *fp, PyObject *filename_ob, int mode, const char *enc, const char *ps1, const char* ps2, - PyCompilerFlags *flags, int *errcode, PyArena *arena) + PegenCompilerFlags *flags, int *errcode, PyArena *arena) { if (PySys_Audit("compile", "OO", Py_None, filename_ob) < 0) { return NULL; } - return _PyPegen_run_parser_from_file_pointer(fp, mode, filename_ob, enc, ps1, ps2, + return _Ta3Pegen_run_parser_from_file_pointer(fp, mode, filename_ob, enc, ps1, ps2, flags, errcode, arena); } diff --git a/ast3/Parser/pegen/pegen.c b/ast3/Parser/pegen/pegen.c index 06af53b3..8636822e 100644 --- a/ast3/Parser/pegen/pegen.c +++ b/ast3/Parser/pegen/pegen.c @@ -6,7 +6,7 @@ #include "parse_string.h" PyObject * -_PyPegen_new_type_comment(Parser *p, char *s) +_Ta3Pegen_new_type_comment(Parser *p, char *s) { PyObject *res = PyUnicode_DecodeUTF8(s, strlen(s), NULL); if (res == NULL) { @@ -20,7 +20,7 @@ _PyPegen_new_type_comment(Parser *p, char *s) } arg_ty -_PyPegen_add_type_comment_to_arg(Parser *p, arg_ty a, Token *tc) +_Ta3Pegen_add_type_comment_to_arg(Parser *p, arg_ty a, Token *tc) { if (tc == NULL) { return a; @@ -29,7 +29,7 @@ _PyPegen_add_type_comment_to_arg(Parser *p, arg_ty a, Token *tc) if (bytes == NULL) { return NULL; } - PyObject *tco = _PyPegen_new_type_comment(p, bytes); + PyObject *tco = _Ta3Pegen_new_type_comment(p, bytes); if (tco == NULL) { return NULL; } @@ -61,7 +61,7 @@ init_normalization(Parser *p) /* Checks if the NOTEQUAL token is valid given the current parser flags 0 indicates success and nonzero indicates failure (an exception may be set) */ int -_PyPegen_check_barry_as_flufl(Parser *p) { +_Ta3Pegen_check_barry_as_flufl(Parser *p) { Token *t = p->tokens[p->fill - 1]; assert(t->bytes != NULL); assert(t->type == NOTEQUAL); @@ -77,7 +77,7 @@ _PyPegen_check_barry_as_flufl(Parser *p) { } PyObject * -_PyPegen_new_identifier(Parser *p, char *n) +_Ta3Pegen_new_identifier(Parser *p, char *n) { PyObject *id = PyUnicode_DecodeUTF8(n, strlen(n), NULL); if (!id) { @@ -135,7 +135,7 @@ _PyPegen_new_identifier(Parser *p, char *n) static PyObject * _create_dummy_identifier(Parser *p) { - return _PyPegen_new_identifier(p, ""); + return _Ta3Pegen_new_identifier(p, ""); } static inline Py_ssize_t @@ -159,7 +159,7 @@ byte_offset_to_character_offset(PyObject *line, int col_offset) } const char * -_PyPegen_get_expr_name(expr_ty e) +_Ta3Pegen_get_expr_name(expr_ty e) { switch (e->kind) { case Attribute_kind: @@ -377,7 +377,7 @@ tokenizer_error(Parser *p) } void * -_PyPegen_raise_error(Parser *p, PyObject *errtype, int with_col_number, const char *errmsg, ...) +_Ta3Pegen_raise_error(Parser *p, PyObject *errtype, int with_col_number, const char *errmsg, ...) { PyObject *value = NULL; PyObject *errstr = NULL; @@ -439,7 +439,7 @@ _PyPegen_raise_error(Parser *p, PyObject *errtype, int with_col_number, const ch return NULL; } -void *_PyPegen_arguments_parsing_error(Parser *p, expr_ty e) { +void *_Ta3Pegen_arguments_parsing_error(Parser *p, expr_ty e) { int kwarg_unpacking = 0; for (Py_ssize_t i = 0, l = asdl_seq_LEN(e->v.Call.keywords); i < l; i++) { keyword_ty keyword = asdl_seq_GET(e->v.Call.keywords, i); @@ -472,7 +472,7 @@ token_name(int type) // Here, mark is the start of the node, while p->mark is the end. // If node==NULL, they should be the same. int -_PyPegen_insert_memo(Parser *p, int mark, int type, void *node) +_Ta3Pegen_insert_memo(Parser *p, int mark, int type, void *node) { // Insert in front Memo *m = PyArena_Malloc(p->arena, sizeof(Memo)); @@ -487,9 +487,9 @@ _PyPegen_insert_memo(Parser *p, int mark, int type, void *node) return 0; } -// Like _PyPegen_insert_memo(), but updates an existing node if found. +// Like _Ta3Pegen_insert_memo(), but updates an existing node if found. int -_PyPegen_update_memo(Parser *p, int mark, int type, void *node) +_Ta3Pegen_update_memo(Parser *p, int mark, int type, void *node) { for (Memo *m = p->tokens[mark]->memo; m != NULL; m = m->next) { if (m->type == type) { @@ -500,12 +500,12 @@ _PyPegen_update_memo(Parser *p, int mark, int type, void *node) } } // Insert new node. - return _PyPegen_insert_memo(p, mark, type, node); + return _Ta3Pegen_insert_memo(p, mark, type, node); } // Return dummy NAME. void * -_PyPegen_dummy_name(Parser *p, ...) +_Ta3Pegen_dummy_name(Parser *p, ...) { static void *cache = NULL; @@ -572,10 +572,10 @@ growable_comment_array_deallocate(growable_comment_array *arr) { } int -_PyPegen_fill_token(Parser *p) +_Ta3Pegen_fill_token(Parser *p) { const char *start, *end; - int type = PyTokenizer_Get(p->tok, &start, &end); + int type = Ta3Tokenizer_Get(p->tok, &start, &end); // Record and skip '# type: ignore' comments while (type == TYPE_IGNORE) { @@ -592,7 +592,7 @@ _PyPegen_fill_token(Parser *p) PyErr_NoMemory(); return -1; } - type = PyTokenizer_Get(p->tok, &start, &end); + type = Ta3Tokenizer_Get(p->tok, &start, &end); } if (type == ENDMARKER && p->start_rule == Py_single_input && p->parsing_started) { @@ -676,7 +676,7 @@ _PyPegen_fill_token(Parser *p) static long memo_statistics[NSTATISTICS]; void -_PyPegen_clear_memo_statistics() +_Ta3Pegen_clear_memo_statistics() { for (int i = 0; i < NSTATISTICS; i++) { memo_statistics[i] = 0; @@ -684,7 +684,7 @@ _PyPegen_clear_memo_statistics() } PyObject * -_PyPegen_get_memo_statistics() +_Ta3Pegen_get_memo_statistics() { PyObject *ret = PyList_New(NSTATISTICS); if (ret == NULL) { @@ -706,10 +706,10 @@ _PyPegen_get_memo_statistics() } int // bool -_PyPegen_is_memoized(Parser *p, int type, void *pres) +_Ta3Pegen_is_memoized(Parser *p, int type, void *pres) { if (p->mark == p->fill) { - if (_PyPegen_fill_token(p) < 0) { + if (_Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return -1; } @@ -737,7 +737,7 @@ _PyPegen_is_memoized(Parser *p, int type, void *pres) int -_PyPegen_lookahead_with_name(int positive, expr_ty (func)(Parser *), Parser *p) +_Ta3Pegen_lookahead_with_name(int positive, expr_ty (func)(Parser *), Parser *p) { int mark = p->mark; void *res = func(p); @@ -746,7 +746,7 @@ _PyPegen_lookahead_with_name(int positive, expr_ty (func)(Parser *), Parser *p) } int -_PyPegen_lookahead_with_int(int positive, Token *(func)(Parser *, int), Parser *p, int arg) +_Ta3Pegen_lookahead_with_int(int positive, Token *(func)(Parser *, int), Parser *p, int arg) { int mark = p->mark; void *res = func(p, arg); @@ -755,7 +755,7 @@ _PyPegen_lookahead_with_int(int positive, Token *(func)(Parser *, int), Parser * } int -_PyPegen_lookahead(int positive, void *(func)(Parser *), Parser *p) +_Ta3Pegen_lookahead(int positive, void *(func)(Parser *), Parser *p) { int mark = p->mark; void *res = (void*)func(p); @@ -764,10 +764,10 @@ _PyPegen_lookahead(int positive, void *(func)(Parser *), Parser *p) } Token * -_PyPegen_expect_token(Parser *p, int type) +_Ta3Pegen_expect_token(Parser *p, int type) { if (p->mark == p->fill) { - if (_PyPegen_fill_token(p) < 0) { + if (_Ta3Pegen_fill_token(p) < 0) { p->error_indicator = 1; return NULL; } @@ -781,7 +781,7 @@ _PyPegen_expect_token(Parser *p, int type) } Token * -_PyPegen_get_last_nonnwhitespace_token(Parser *p) +_Ta3Pegen_get_last_nonnwhitespace_token(Parser *p) { assert(p->mark >= 0); Token *token = NULL; @@ -795,9 +795,9 @@ _PyPegen_get_last_nonnwhitespace_token(Parser *p) } expr_ty -_PyPegen_name_token(Parser *p) +_Ta3Pegen_name_token(Parser *p) { - Token *t = _PyPegen_expect_token(p, NAME); + Token *t = _Ta3Pegen_expect_token(p, NAME); if (t == NULL) { return NULL; } @@ -805,7 +805,7 @@ _PyPegen_name_token(Parser *p) if (!s) { return NULL; } - PyObject *id = _PyPegen_new_identifier(p, s); + PyObject *id = _Ta3Pegen_new_identifier(p, s); if (id == NULL) { return NULL; } @@ -814,9 +814,9 @@ _PyPegen_name_token(Parser *p) } void * -_PyPegen_string_token(Parser *p) +_Ta3Pegen_string_token(Parser *p) { - return _PyPegen_expect_token(p, STRING); + return _Ta3Pegen_expect_token(p, STRING); } static PyObject * @@ -890,9 +890,9 @@ parsenumber(const char *s) } expr_ty -_PyPegen_number_token(Parser *p) +_Ta3Pegen_number_token(Parser *p) { - Token *t = _PyPegen_expect_token(p, NUMBER); + Token *t = _Ta3Pegen_expect_token(p, NUMBER); if (t == NULL) { return NULL; } @@ -970,7 +970,7 @@ bad_single_statement(Parser *p) } void -_PyPegen_Parser_Free(Parser *p) +_Ta3Pegen_Parser_Free(Parser *p) { Py_XDECREF(p->normalize); for (int i = 0; i < p->size; i++) { @@ -982,7 +982,7 @@ _PyPegen_Parser_Free(Parser *p) } static int -compute_parser_flags(PyCompilerFlags *flags) +compute_parser_flags(PegenCompilerFlags *flags) { int parser_flags = 0; if (!flags) { @@ -1007,7 +1007,7 @@ compute_parser_flags(PyCompilerFlags *flags) } Parser * -_PyPegen_Parser_New(struct tok_state *tok, int start_rule, int flags, +_Ta3Pegen_Parser_New(struct tok_state *tok, int start_rule, int flags, int feature_version, int *errcode, PyArena *arena) { Parser *p = PyMem_Malloc(sizeof(Parser)); @@ -1059,9 +1059,9 @@ _PyPegen_Parser_New(struct tok_state *tok, int start_rule, int flags, } void * -_PyPegen_run_parser(Parser *p) +_Ta3Pegen_run_parser(Parser *p) { - void *res = _PyPegen_parse(p); + void *res = _Ta3Pegen_parse(p); if (res == NULL) { if (PyErr_Occurred()) { return NULL; @@ -1095,11 +1095,11 @@ _PyPegen_run_parser(Parser *p) } mod_ty -_PyPegen_run_parser_from_file_pointer(FILE *fp, int start_rule, PyObject *filename_ob, +_Ta3Pegen_run_parser_from_file_pointer(FILE *fp, int start_rule, PyObject *filename_ob, const char *enc, const char *ps1, const char *ps2, - PyCompilerFlags *flags, int *errcode, PyArena *arena) + PegenCompilerFlags *flags, int *errcode, PyArena *arena) { - struct tok_state *tok = PyTokenizer_FromFile(fp, enc, ps1, ps2); + struct tok_state *tok = Ta3Tokenizer_FromFile(fp, enc, ps1, ps2); if (tok == NULL) { if (PyErr_Occurred()) { raise_tokenizer_init_error(filename_ob); @@ -1115,23 +1115,23 @@ _PyPegen_run_parser_from_file_pointer(FILE *fp, int start_rule, PyObject *filena mod_ty result = NULL; int parser_flags = compute_parser_flags(flags); - Parser *p = _PyPegen_Parser_New(tok, start_rule, parser_flags, PY_MINOR_VERSION, + Parser *p = _Ta3Pegen_Parser_New(tok, start_rule, parser_flags, PY_MINOR_VERSION, errcode, arena); if (p == NULL) { goto error; } - result = _PyPegen_run_parser(p); - _PyPegen_Parser_Free(p); + result = _Ta3Pegen_run_parser(p); + _Ta3Pegen_Parser_Free(p); error: - PyTokenizer_Free(tok); + Ta3Tokenizer_Free(tok); return result; } mod_ty -_PyPegen_run_parser_from_file(const char *filename, int start_rule, - PyObject *filename_ob, PyCompilerFlags *flags, PyArena *arena) +_Ta3Pegen_run_parser_from_file(const char *filename, int start_rule, + PyObject *filename_ob, PegenCompilerFlags *flags, PyArena *arena) { FILE *fp = fopen(filename, "rb"); if (fp == NULL) { @@ -1139,7 +1139,7 @@ _PyPegen_run_parser_from_file(const char *filename, int start_rule, return NULL; } - mod_ty result = _PyPegen_run_parser_from_file_pointer(fp, start_rule, filename_ob, + mod_ty result = _Ta3Pegen_run_parser_from_file_pointer(fp, start_rule, filename_ob, NULL, NULL, NULL, flags, NULL, arena); fclose(fp); @@ -1147,16 +1147,16 @@ _PyPegen_run_parser_from_file(const char *filename, int start_rule, } mod_ty -_PyPegen_run_parser_from_string(const char *str, int start_rule, PyObject *filename_ob, - PyCompilerFlags *flags, PyArena *arena) +_Ta3Pegen_run_parser_from_string(const char *str, int start_rule, PyObject *filename_ob, + PegenCompilerFlags *flags, PyArena *arena) { int exec_input = start_rule == Py_file_input; struct tok_state *tok; if (flags == NULL || flags->cf_flags & PyCF_IGNORE_COOKIE) { - tok = PyTokenizer_FromUTF8(str, exec_input); + tok = Ta3Tokenizer_FromUTF8(str, exec_input); } else { - tok = PyTokenizer_FromString(str, exec_input); + tok = Ta3Tokenizer_FromString(str, exec_input); } if (tok == NULL) { if (PyErr_Occurred()) { @@ -1173,22 +1173,22 @@ _PyPegen_run_parser_from_string(const char *str, int start_rule, PyObject *filen int parser_flags = compute_parser_flags(flags); int feature_version = flags ? flags->cf_feature_version : PY_MINOR_VERSION; - Parser *p = _PyPegen_Parser_New(tok, start_rule, parser_flags, feature_version, + Parser *p = _Ta3Pegen_Parser_New(tok, start_rule, parser_flags, feature_version, NULL, arena); if (p == NULL) { goto error; } - result = _PyPegen_run_parser(p); - _PyPegen_Parser_Free(p); + result = _Ta3Pegen_run_parser(p); + _Ta3Pegen_Parser_Free(p); error: - PyTokenizer_Free(tok); + Ta3Tokenizer_Free(tok); return result; } void * -_PyPegen_interactive_exit(Parser *p) +_Ta3Pegen_interactive_exit(Parser *p) { if (p->errcode) { *(p->errcode) = E_EOF; @@ -1198,10 +1198,10 @@ _PyPegen_interactive_exit(Parser *p) /* Creates a single-element asdl_seq* that contains a */ asdl_seq * -_PyPegen_singleton_seq(Parser *p, void *a) +_Ta3Pegen_singleton_seq(Parser *p, void *a) { assert(a != NULL); - asdl_seq *seq = _Py_asdl_seq_new(1, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(1, p->arena); if (!seq) { return NULL; } @@ -1211,14 +1211,14 @@ _PyPegen_singleton_seq(Parser *p, void *a) /* Creates a copy of seq and prepends a to it */ asdl_seq * -_PyPegen_seq_insert_in_front(Parser *p, void *a, asdl_seq *seq) +_Ta3Pegen_seq_insert_in_front(Parser *p, void *a, asdl_seq *seq) { assert(a != NULL); if (!seq) { - return _PyPegen_singleton_seq(p, a); + return _Ta3Pegen_singleton_seq(p, a); } - asdl_seq *new_seq = _Py_asdl_seq_new(asdl_seq_LEN(seq) + 1, p->arena); + asdl_seq *new_seq = _Ta3_asdl_seq_new(asdl_seq_LEN(seq) + 1, p->arena); if (!new_seq) { return NULL; } @@ -1232,14 +1232,14 @@ _PyPegen_seq_insert_in_front(Parser *p, void *a, asdl_seq *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) +_Ta3Pegen_seq_append_to_end(Parser *p, asdl_seq *seq, void *a) { assert(a != NULL); if (!seq) { - return _PyPegen_singleton_seq(p, a); + return _Ta3Pegen_singleton_seq(p, a); } - asdl_seq *new_seq = _Py_asdl_seq_new(asdl_seq_LEN(seq) + 1, p->arena); + asdl_seq *new_seq = _Ta3_asdl_seq_new(asdl_seq_LEN(seq) + 1, p->arena); if (!new_seq) { return NULL; } @@ -1264,12 +1264,12 @@ _get_flattened_seq_size(asdl_seq *seqs) /* Flattens an asdl_seq* of asdl_seq*s */ asdl_seq * -_PyPegen_seq_flatten(Parser *p, asdl_seq *seqs) +_Ta3Pegen_seq_flatten(Parser *p, asdl_seq *seqs) { Py_ssize_t flattened_seq_size = _get_flattened_seq_size(seqs); assert(flattened_seq_size > 0); - asdl_seq *flattened_seq = _Py_asdl_seq_new(flattened_seq_size, p->arena); + asdl_seq *flattened_seq = _Ta3_asdl_seq_new(flattened_seq_size, p->arena); if (!flattened_seq) { return NULL; } @@ -1288,7 +1288,7 @@ _PyPegen_seq_flatten(Parser *p, asdl_seq *seqs) /* Creates a new name of the form . */ expr_ty -_PyPegen_join_names_with_dot(Parser *p, expr_ty first_name, expr_ty second_name) +_Ta3Pegen_join_names_with_dot(Parser *p, expr_ty first_name, expr_ty second_name) { assert(first_name != NULL && second_name != NULL); PyObject *first_identifier = first_name->v.Name.id; @@ -1338,12 +1338,12 @@ _PyPegen_join_names_with_dot(Parser *p, expr_ty first_name, expr_ty second_name) return NULL; } - return _Py_Name(uni, Load, EXTRA_EXPR(first_name, second_name)); + return _Ta3_Name(uni, Load, EXTRA_EXPR(first_name, second_name)); } /* Counts the total number of dots in seq's tokens */ int -_PyPegen_seq_count_dots(asdl_seq *seq) +_Ta3Pegen_seq_count_dots(asdl_seq *seq) { int number_of_dots = 0; for (Py_ssize_t i = 0, l = asdl_seq_LEN(seq); i < l; i++) { @@ -1365,7 +1365,7 @@ _PyPegen_seq_count_dots(asdl_seq *seq) /* Creates an alias with '*' as the identifier name */ alias_ty -_PyPegen_alias_for_star(Parser *p) +_Ta3Pegen_alias_for_star(Parser *p) { PyObject *str = PyUnicode_InternFromString("*"); if (!str) { @@ -1380,12 +1380,12 @@ _PyPegen_alias_for_star(Parser *p) /* Creates a new asdl_seq* with the identifiers of all the names in seq */ asdl_seq * -_PyPegen_map_names_to_ids(Parser *p, asdl_seq *seq) +_Ta3Pegen_map_names_to_ids(Parser *p, asdl_seq *seq) { Py_ssize_t len = asdl_seq_LEN(seq); assert(len > 0); - asdl_seq *new_seq = _Py_asdl_seq_new(len, p->arena); + asdl_seq *new_seq = _Ta3_asdl_seq_new(len, p->arena); if (!new_seq) { return NULL; } @@ -1398,7 +1398,7 @@ _PyPegen_map_names_to_ids(Parser *p, asdl_seq *seq) /* Constructs a CmpopExprPair */ CmpopExprPair * -_PyPegen_cmpop_expr_pair(Parser *p, cmpop_ty cmpop, expr_ty expr) +_Ta3Pegen_cmpop_expr_pair(Parser *p, cmpop_ty cmpop, expr_ty expr) { assert(expr != NULL); CmpopExprPair *a = PyArena_Malloc(p->arena, sizeof(CmpopExprPair)); @@ -1411,12 +1411,12 @@ _PyPegen_cmpop_expr_pair(Parser *p, cmpop_ty cmpop, expr_ty expr) } asdl_int_seq * -_PyPegen_get_cmpops(Parser *p, asdl_seq *seq) +_Ta3Pegen_get_cmpops(Parser *p, asdl_seq *seq) { Py_ssize_t len = asdl_seq_LEN(seq); assert(len > 0); - asdl_int_seq *new_seq = _Py_asdl_int_seq_new(len, p->arena); + asdl_int_seq *new_seq = _Ta3_asdl_int_seq_new(len, p->arena); if (!new_seq) { return NULL; } @@ -1428,12 +1428,12 @@ _PyPegen_get_cmpops(Parser *p, asdl_seq *seq) } asdl_seq * -_PyPegen_get_exprs(Parser *p, asdl_seq *seq) +_Ta3Pegen_get_exprs(Parser *p, asdl_seq *seq) { Py_ssize_t len = asdl_seq_LEN(seq); assert(len > 0); - asdl_seq *new_seq = _Py_asdl_seq_new(len, p->arena); + asdl_seq *new_seq = _Ta3_asdl_seq_new(len, p->arena); if (!new_seq) { return NULL; } @@ -1453,13 +1453,13 @@ _set_seq_context(Parser *p, asdl_seq *seq, expr_context_ty ctx) return NULL; } - asdl_seq *new_seq = _Py_asdl_seq_new(len, p->arena); + asdl_seq *new_seq = _Ta3_asdl_seq_new(len, p->arena); if (!new_seq) { return NULL; } for (Py_ssize_t i = 0; i < len; i++) { expr_ty e = asdl_seq_GET(seq, i); - asdl_seq_SET(new_seq, i, _PyPegen_set_expr_context(p, e, ctx)); + asdl_seq_SET(new_seq, i, _Ta3Pegen_set_expr_context(p, e, ctx)); } return new_seq; } @@ -1467,42 +1467,42 @@ _set_seq_context(Parser *p, asdl_seq *seq, expr_context_ty ctx) static expr_ty _set_name_context(Parser *p, expr_ty e, expr_context_ty ctx) { - return _Py_Name(e->v.Name.id, ctx, EXTRA_EXPR(e, e)); + return _Ta3_Name(e->v.Name.id, ctx, EXTRA_EXPR(e, e)); } static expr_ty _set_tuple_context(Parser *p, expr_ty e, expr_context_ty ctx) { - return _Py_Tuple(_set_seq_context(p, e->v.Tuple.elts, ctx), ctx, EXTRA_EXPR(e, e)); + return _Ta3_Tuple(_set_seq_context(p, e->v.Tuple.elts, ctx), ctx, EXTRA_EXPR(e, e)); } static expr_ty _set_list_context(Parser *p, expr_ty e, expr_context_ty ctx) { - return _Py_List(_set_seq_context(p, e->v.List.elts, ctx), ctx, EXTRA_EXPR(e, e)); + return _Ta3_List(_set_seq_context(p, e->v.List.elts, ctx), ctx, EXTRA_EXPR(e, e)); } static expr_ty _set_subscript_context(Parser *p, expr_ty e, expr_context_ty ctx) { - return _Py_Subscript(e->v.Subscript.value, e->v.Subscript.slice, ctx, EXTRA_EXPR(e, e)); + return _Ta3_Subscript(e->v.Subscript.value, e->v.Subscript.slice, ctx, EXTRA_EXPR(e, e)); } static expr_ty _set_attribute_context(Parser *p, expr_ty e, expr_context_ty ctx) { - return _Py_Attribute(e->v.Attribute.value, e->v.Attribute.attr, ctx, EXTRA_EXPR(e, e)); + return _Ta3_Attribute(e->v.Attribute.value, e->v.Attribute.attr, ctx, EXTRA_EXPR(e, e)); } static expr_ty _set_starred_context(Parser *p, expr_ty e, expr_context_ty ctx) { - return _Py_Starred(_PyPegen_set_expr_context(p, e->v.Starred.value, ctx), ctx, EXTRA_EXPR(e, e)); + return _Ta3_Starred(_Ta3Pegen_set_expr_context(p, e->v.Starred.value, ctx), ctx, EXTRA_EXPR(e, e)); } /* Creates an `expr_ty` equivalent to `expr` but with `ctx` as context */ expr_ty -_PyPegen_set_expr_context(Parser *p, expr_ty expr, expr_context_ty ctx) +_Ta3Pegen_set_expr_context(Parser *p, expr_ty expr, expr_context_ty ctx) { assert(expr != NULL); @@ -1534,7 +1534,7 @@ _PyPegen_set_expr_context(Parser *p, expr_ty expr, expr_context_ty ctx) /* Constructs a KeyValuePair that is used when parsing a dict's key value pairs */ KeyValuePair * -_PyPegen_key_value_pair(Parser *p, expr_ty key, expr_ty value) +_Ta3Pegen_key_value_pair(Parser *p, expr_ty key, expr_ty value) { KeyValuePair *a = PyArena_Malloc(p->arena, sizeof(KeyValuePair)); if (!a) { @@ -1547,10 +1547,10 @@ _PyPegen_key_value_pair(Parser *p, expr_ty key, expr_ty value) /* Extracts all keys from an asdl_seq* of KeyValuePair*'s */ asdl_seq * -_PyPegen_get_keys(Parser *p, asdl_seq *seq) +_Ta3Pegen_get_keys(Parser *p, asdl_seq *seq) { Py_ssize_t len = asdl_seq_LEN(seq); - asdl_seq *new_seq = _Py_asdl_seq_new(len, p->arena); + asdl_seq *new_seq = _Ta3_asdl_seq_new(len, p->arena); if (!new_seq) { return NULL; } @@ -1563,10 +1563,10 @@ _PyPegen_get_keys(Parser *p, asdl_seq *seq) /* Extracts all values from an asdl_seq* of KeyValuePair*'s */ asdl_seq * -_PyPegen_get_values(Parser *p, asdl_seq *seq) +_Ta3Pegen_get_values(Parser *p, asdl_seq *seq) { Py_ssize_t len = asdl_seq_LEN(seq); - asdl_seq *new_seq = _Py_asdl_seq_new(len, p->arena); + asdl_seq *new_seq = _Ta3_asdl_seq_new(len, p->arena); if (!new_seq) { return NULL; } @@ -1579,20 +1579,20 @@ _PyPegen_get_values(Parser *p, asdl_seq *seq) /* Constructs a NameDefaultPair */ NameDefaultPair * -_PyPegen_name_default_pair(Parser *p, arg_ty arg, expr_ty value, Token *tc) +_Ta3Pegen_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 = _PyPegen_add_type_comment_to_arg(p, arg, tc); + a->arg = _Ta3Pegen_add_type_comment_to_arg(p, arg, tc); a->value = value; return a; } /* Constructs a SlashWithDefault */ SlashWithDefault * -_PyPegen_slash_with_default(Parser *p, asdl_seq *plain_names, asdl_seq *names_with_defaults) +_Ta3Pegen_slash_with_default(Parser *p, asdl_seq *plain_names, asdl_seq *names_with_defaults) { SlashWithDefault *a = PyArena_Malloc(p->arena, sizeof(SlashWithDefault)); if (!a) { @@ -1605,7 +1605,7 @@ _PyPegen_slash_with_default(Parser *p, asdl_seq *plain_names, asdl_seq *names_wi /* Constructs a StarEtc */ StarEtc * -_PyPegen_star_etc(Parser *p, arg_ty vararg, asdl_seq *kwonlyargs, arg_ty kwarg) +_Ta3Pegen_star_etc(Parser *p, arg_ty vararg, asdl_seq *kwonlyargs, arg_ty kwarg) { StarEtc *a = PyArena_Malloc(p->arena, sizeof(StarEtc)); if (!a) { @@ -1618,11 +1618,11 @@ _PyPegen_star_etc(Parser *p, arg_ty vararg, asdl_seq *kwonlyargs, arg_ty kwarg) } asdl_seq * -_PyPegen_join_sequences(Parser *p, asdl_seq *a, asdl_seq *b) +_Ta3Pegen_join_sequences(Parser *p, asdl_seq *a, asdl_seq *b) { Py_ssize_t first_len = asdl_seq_LEN(a); Py_ssize_t second_len = asdl_seq_LEN(b); - asdl_seq *new_seq = _Py_asdl_seq_new(first_len + second_len, p->arena); + asdl_seq *new_seq = _Ta3_asdl_seq_new(first_len + second_len, p->arena); if (!new_seq) { return NULL; } @@ -1642,7 +1642,7 @@ static asdl_seq * _get_names(Parser *p, asdl_seq *names_with_defaults) { Py_ssize_t len = asdl_seq_LEN(names_with_defaults); - asdl_seq *seq = _Py_asdl_seq_new(len, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(len, p->arena); if (!seq) { return NULL; } @@ -1657,7 +1657,7 @@ static asdl_seq * _get_defaults(Parser *p, asdl_seq *names_with_defaults) { Py_ssize_t len = asdl_seq_LEN(names_with_defaults); - asdl_seq *seq = _Py_asdl_seq_new(len, p->arena); + asdl_seq *seq = _Ta3_asdl_seq_new(len, p->arena); if (!seq) { return NULL; } @@ -1670,7 +1670,7 @@ _get_defaults(Parser *p, asdl_seq *names_with_defaults) /* Constructs an arguments_ty object out of all the parsed constructs in the parameters rule */ arguments_ty -_PyPegen_make_arguments(Parser *p, asdl_seq *slash_without_default, +_Ta3Pegen_make_arguments(Parser *p, asdl_seq *slash_without_default, SlashWithDefault *slash_with_default, asdl_seq *plain_names, asdl_seq *names_with_default, StarEtc *star_etc) { @@ -1684,13 +1684,13 @@ _PyPegen_make_arguments(Parser *p, asdl_seq *slash_without_default, if (!slash_with_default_names) { return NULL; } - posonlyargs = _PyPegen_join_sequences(p, slash_with_default->plain_names, slash_with_default_names); + posonlyargs = _Ta3Pegen_join_sequences(p, slash_with_default->plain_names, slash_with_default_names); if (!posonlyargs) { return NULL; } } else { - posonlyargs = _Py_asdl_seq_new(0, p->arena); + posonlyargs = _Ta3_asdl_seq_new(0, p->arena); if (!posonlyargs) { return NULL; } @@ -1702,7 +1702,7 @@ _PyPegen_make_arguments(Parser *p, asdl_seq *slash_without_default, if (!names_with_default_names) { return NULL; } - posargs = _PyPegen_join_sequences(p, plain_names, names_with_default_names); + posargs = _Ta3Pegen_join_sequences(p, plain_names, names_with_default_names); if (!posargs) { return NULL; } @@ -1717,7 +1717,7 @@ _PyPegen_make_arguments(Parser *p, asdl_seq *slash_without_default, posargs = plain_names; } else { - posargs = _Py_asdl_seq_new(0, p->arena); + posargs = _Ta3_asdl_seq_new(0, p->arena); if (!posargs) { return NULL; } @@ -1734,7 +1734,7 @@ _PyPegen_make_arguments(Parser *p, asdl_seq *slash_without_default, if (!names_with_default_values) { return NULL; } - posdefaults = _PyPegen_join_sequences(p, slash_with_default_values, names_with_default_values); + posdefaults = _Ta3Pegen_join_sequences(p, slash_with_default_values, names_with_default_values); if (!posdefaults) { return NULL; } @@ -1752,7 +1752,7 @@ _PyPegen_make_arguments(Parser *p, asdl_seq *slash_without_default, } } else { - posdefaults = _Py_asdl_seq_new(0, p->arena); + posdefaults = _Ta3_asdl_seq_new(0, p->arena); if (!posdefaults) { return NULL; } @@ -1771,7 +1771,7 @@ _PyPegen_make_arguments(Parser *p, asdl_seq *slash_without_default, } } else { - kwonlyargs = _Py_asdl_seq_new(0, p->arena); + kwonlyargs = _Ta3_asdl_seq_new(0, p->arena); if (!kwonlyargs) { return NULL; } @@ -1785,7 +1785,7 @@ _PyPegen_make_arguments(Parser *p, asdl_seq *slash_without_default, } } else { - kwdefaults = _Py_asdl_seq_new(0, p->arena); + kwdefaults = _Ta3_asdl_seq_new(0, p->arena); if (!kwdefaults) { return NULL; } @@ -1796,43 +1796,43 @@ _PyPegen_make_arguments(Parser *p, asdl_seq *slash_without_default, kwarg = star_etc->kwarg; } - return _Py_arguments(posonlyargs, posargs, vararg, kwonlyargs, kwdefaults, kwarg, + return _Ta3_arguments(posonlyargs, posargs, vararg, kwonlyargs, kwdefaults, kwarg, posdefaults, p->arena); } /* Constructs an empty arguments_ty object, that gets used when a function accepts no * arguments. */ arguments_ty -_PyPegen_empty_arguments(Parser *p) +_Ta3Pegen_empty_arguments(Parser *p) { - asdl_seq *posonlyargs = _Py_asdl_seq_new(0, p->arena); + asdl_seq *posonlyargs = _Ta3_asdl_seq_new(0, p->arena); if (!posonlyargs) { return NULL; } - asdl_seq *posargs = _Py_asdl_seq_new(0, p->arena); + asdl_seq *posargs = _Ta3_asdl_seq_new(0, p->arena); if (!posargs) { return NULL; } - asdl_seq *posdefaults = _Py_asdl_seq_new(0, p->arena); + asdl_seq *posdefaults = _Ta3_asdl_seq_new(0, p->arena); if (!posdefaults) { return NULL; } - asdl_seq *kwonlyargs = _Py_asdl_seq_new(0, p->arena); + asdl_seq *kwonlyargs = _Ta3_asdl_seq_new(0, p->arena); if (!kwonlyargs) { return NULL; } - asdl_seq *kwdefaults = _Py_asdl_seq_new(0, p->arena); + asdl_seq *kwdefaults = _Ta3_asdl_seq_new(0, p->arena); if (!kwdefaults) { return NULL; } - return _Py_arguments(posonlyargs, posargs, NULL, kwonlyargs, kwdefaults, NULL, kwdefaults, + return _Ta3_arguments(posonlyargs, posargs, NULL, kwonlyargs, kwdefaults, NULL, kwdefaults, p->arena); } /* Encapsulates the value of an operator_ty into an AugOperator struct */ AugOperator * -_PyPegen_augoperator(Parser *p, operator_ty kind) +_Ta3Pegen_augoperator(Parser *p, operator_ty kind) { AugOperator *a = PyArena_Malloc(p->arena, sizeof(AugOperator)); if (!a) { @@ -1844,11 +1844,11 @@ _PyPegen_augoperator(Parser *p, operator_ty kind) /* Construct a FunctionDef equivalent to function_def, but with decorators */ stmt_ty -_PyPegen_function_def_decorators(Parser *p, asdl_seq *decorators, stmt_ty function_def) +_Ta3Pegen_function_def_decorators(Parser *p, asdl_seq *decorators, stmt_ty function_def) { assert(function_def != NULL); if (function_def->kind == AsyncFunctionDef_kind) { - return _Py_AsyncFunctionDef( + return _Ta3_AsyncFunctionDef( function_def->v.FunctionDef.name, function_def->v.FunctionDef.args, function_def->v.FunctionDef.body, decorators, function_def->v.FunctionDef.returns, function_def->v.FunctionDef.type_comment, function_def->lineno, @@ -1856,7 +1856,7 @@ _PyPegen_function_def_decorators(Parser *p, asdl_seq *decorators, stmt_ty functi p->arena); } - return _Py_FunctionDef(function_def->v.FunctionDef.name, function_def->v.FunctionDef.args, + return _Ta3_FunctionDef(function_def->v.FunctionDef.name, function_def->v.FunctionDef.args, function_def->v.FunctionDef.body, decorators, function_def->v.FunctionDef.returns, function_def->v.FunctionDef.type_comment, function_def->lineno, @@ -1866,10 +1866,10 @@ _PyPegen_function_def_decorators(Parser *p, asdl_seq *decorators, stmt_ty functi /* Construct a ClassDef equivalent to class_def, but with decorators */ stmt_ty -_PyPegen_class_def_decorators(Parser *p, asdl_seq *decorators, stmt_ty class_def) +_Ta3Pegen_class_def_decorators(Parser *p, asdl_seq *decorators, stmt_ty class_def) { assert(class_def != NULL); - return _Py_ClassDef(class_def->v.ClassDef.name, class_def->v.ClassDef.bases, + return _Ta3_ClassDef(class_def->v.ClassDef.name, class_def->v.ClassDef.bases, class_def->v.ClassDef.keywords, class_def->v.ClassDef.body, decorators, class_def->lineno, class_def->col_offset, class_def->end_lineno, class_def->end_col_offset, p->arena); @@ -1877,7 +1877,7 @@ _PyPegen_class_def_decorators(Parser *p, asdl_seq *decorators, stmt_ty class_def /* Construct a KeywordOrStarred */ KeywordOrStarred * -_PyPegen_keyword_or_starred(Parser *p, void *element, int is_keyword) +_Ta3Pegen_keyword_or_starred(Parser *p, void *element, int is_keyword) { KeywordOrStarred *a = PyArena_Malloc(p->arena, sizeof(KeywordOrStarred)); if (!a) { @@ -1904,13 +1904,13 @@ _seq_number_of_starred_exprs(asdl_seq *seq) /* Extract the starred expressions of an asdl_seq* of KeywordOrStarred*s */ asdl_seq * -_PyPegen_seq_extract_starred_exprs(Parser *p, asdl_seq *kwargs) +_Ta3Pegen_seq_extract_starred_exprs(Parser *p, asdl_seq *kwargs) { int new_len = _seq_number_of_starred_exprs(kwargs); if (new_len == 0) { return NULL; } - asdl_seq *new_seq = _Py_asdl_seq_new(new_len, p->arena); + asdl_seq *new_seq = _Ta3_asdl_seq_new(new_len, p->arena); if (!new_seq) { return NULL; } @@ -1927,14 +1927,14 @@ _PyPegen_seq_extract_starred_exprs(Parser *p, asdl_seq *kwargs) /* Return a new asdl_seq* with only the keywords in kwargs */ asdl_seq * -_PyPegen_seq_delete_starred_exprs(Parser *p, asdl_seq *kwargs) +_Ta3Pegen_seq_delete_starred_exprs(Parser *p, asdl_seq *kwargs) { Py_ssize_t len = asdl_seq_LEN(kwargs); Py_ssize_t new_len = len - _seq_number_of_starred_exprs(kwargs); if (new_len == 0) { return NULL; } - asdl_seq *new_seq = _Py_asdl_seq_new(new_len, p->arena); + asdl_seq *new_seq = _Ta3_asdl_seq_new(new_len, p->arena); if (!new_seq) { return NULL; } @@ -1950,7 +1950,7 @@ _PyPegen_seq_delete_starred_exprs(Parser *p, asdl_seq *kwargs) } expr_ty -_PyPegen_concatenate_strings(Parser *p, asdl_seq *strings) +_Ta3Pegen_concatenate_strings(Parser *p, asdl_seq *strings) { Py_ssize_t len = asdl_seq_LEN(strings); assert(len > 0); @@ -1962,7 +1962,7 @@ _PyPegen_concatenate_strings(Parser *p, asdl_seq *strings) PyObject *bytes_str = NULL; FstringParser state; - _PyPegen_FstringParser_Init(&state); + _Ta3Pegen_FstringParser_Init(&state); for (Py_ssize_t i = 0; i < len; i++) { Token *t = asdl_seq_GET(strings, i); @@ -1973,7 +1973,7 @@ _PyPegen_concatenate_strings(Parser *p, asdl_seq *strings) const char *fstr; Py_ssize_t fstrlen = -1; - if (_PyPegen_parsestr(p, &this_bytesmode, &this_rawmode, &s, &fstr, &fstrlen, t) != 0) { + if (_Ta3Pegen_parsestr(p, &this_bytesmode, &this_rawmode, &s, &fstr, &fstrlen, t) != 0) { goto error; } @@ -1988,7 +1988,7 @@ _PyPegen_concatenate_strings(Parser *p, asdl_seq *strings) if (fstr != NULL) { assert(s == NULL && !bytesmode); - int result = _PyPegen_FstringParser_ConcatFstring(p, &state, &fstr, fstr + fstrlen, + int result = _Ta3Pegen_FstringParser_ConcatFstring(p, &state, &fstr, fstr + fstrlen, this_rawmode, 0, first, t, last); if (result < 0) { goto error; @@ -2012,7 +2012,7 @@ _PyPegen_concatenate_strings(Parser *p, asdl_seq *strings) } else { /* This is a regular string. Concatenate it. */ - if (_PyPegen_FstringParser_ConcatAndDel(&state, s) < 0) { + if (_Ta3Pegen_FstringParser_ConcatAndDel(&state, s) < 0) { goto error; } } @@ -2027,11 +2027,11 @@ _PyPegen_concatenate_strings(Parser *p, asdl_seq *strings) last->end_col_offset, p->arena); } - return _PyPegen_FstringParser_Finish(p, &state, first, last); + return _Ta3Pegen_FstringParser_Finish(p, &state, first, last); error: Py_XDECREF(bytes_str); - _PyPegen_FstringParser_Dealloc(&state); + _Ta3Pegen_FstringParser_Dealloc(&state); if (PyErr_Occurred()) { raise_decode_error(p); } @@ -2039,17 +2039,17 @@ _PyPegen_concatenate_strings(Parser *p, asdl_seq *strings) } mod_ty -_PyPegen_make_module(Parser *p, asdl_seq *a) { +_Ta3Pegen_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); + type_ignores = _Ta3_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); + PyObject *tag = _Ta3Pegen_new_type_comment(p, p->type_ignore_comments.items[i].comment); if (tag == NULL) { return NULL; } diff --git a/ast3/Parser/pegen/pegen.h b/ast3/Parser/pegen/pegen.h index 39d69e8c..86d113bb 100644 --- a/ast3/Parser/pegen/pegen.h +++ b/ast3/Parser/pegen/pegen.h @@ -109,33 +109,33 @@ typedef struct { int is_keyword; } KeywordOrStarred; -void _PyPegen_clear_memo_statistics(void); -PyObject *_PyPegen_get_memo_statistics(void); - -int _PyPegen_insert_memo(Parser *p, int mark, int type, void *node); -int _PyPegen_update_memo(Parser *p, int mark, int type, void *node); -int _PyPegen_is_memoized(Parser *p, int type, void *pres); - -int _PyPegen_lookahead_with_name(int, expr_ty (func)(Parser *), Parser *); -int _PyPegen_lookahead_with_int(int, Token *(func)(Parser *, int), Parser *, int); -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); -expr_ty _PyPegen_name_token(Parser *p); -expr_ty _PyPegen_number_token(Parser *p); -void *_PyPegen_string_token(Parser *p); -const char *_PyPegen_get_expr_name(expr_ty); -void *_PyPegen_raise_error(Parser *p, PyObject *errtype, int with_col_number, const char *errmsg, ...); -void *_PyPegen_dummy_name(Parser *p, ...); +void _Ta3Pegen_clear_memo_statistics(void); +PyObject *_Ta3Pegen_get_memo_statistics(void); + +int _Ta3Pegen_insert_memo(Parser *p, int mark, int type, void *node); +int _Ta3Pegen_update_memo(Parser *p, int mark, int type, void *node); +int _Ta3Pegen_is_memoized(Parser *p, int type, void *pres); + +int _Ta3Pegen_lookahead_with_name(int, expr_ty (func)(Parser *), Parser *); +int _Ta3Pegen_lookahead_with_int(int, Token *(func)(Parser *, int), Parser *, int); +int _Ta3Pegen_lookahead(int, void *(func)(Parser *), Parser *); + +Token *_Ta3Pegen_expect_token(Parser *p, int type); +Token *_Ta3Pegen_get_last_nonnwhitespace_token(Parser *); +int _Ta3Pegen_fill_token(Parser *p); +expr_ty _Ta3Pegen_name_token(Parser *p); +expr_ty _Ta3Pegen_number_token(Parser *p); +void *_Ta3Pegen_string_token(Parser *p); +const char *_Ta3Pegen_get_expr_name(expr_ty); +void *_Ta3Pegen_raise_error(Parser *p, PyObject *errtype, int with_col_number, const char *errmsg, ...); +void *_Ta3Pegen_dummy_name(Parser *p, ...); #define UNUSED(expr) do { (void)(expr); } while (0) #define EXTRA_EXPR(head, tail) head->lineno, head->col_offset, tail->end_lineno, tail->end_col_offset, p->arena #define EXTRA start_lineno, start_col_offset, end_lineno, end_col_offset, p->arena -#define RAISE_SYNTAX_ERROR(msg, ...) _PyPegen_raise_error(p, PyExc_SyntaxError, 1, msg, ##__VA_ARGS__) -#define RAISE_INDENTATION_ERROR(msg, ...) _PyPegen_raise_error(p, PyExc_IndentationError, 1, msg, ##__VA_ARGS__) -#define RAISE_SYNTAX_ERROR_NO_COL_OFFSET(msg, ...) _PyPegen_raise_error(p, PyExc_SyntaxError, 0, msg, ##__VA_ARGS__) +#define RAISE_SYNTAX_ERROR(msg, ...) _Ta3Pegen_raise_error(p, PyExc_SyntaxError, 1, msg, ##__VA_ARGS__) +#define RAISE_INDENTATION_ERROR(msg, ...) _Ta3Pegen_raise_error(p, PyExc_IndentationError, 1, msg, ##__VA_ARGS__) +#define RAISE_SYNTAX_ERROR_NO_COL_OFFSET(msg, ...) _Ta3Pegen_raise_error(p, PyExc_SyntaxError, 0, msg, ##__VA_ARGS__) Py_LOCAL_INLINE(void *) CHECK_CALL(Parser *p, void *result) @@ -148,7 +148,7 @@ CHECK_CALL(Parser *p, void *result) } /* This is needed for helper functions that are allowed to - return NULL without an error. Example: _PyPegen_seq_extract_starred_exprs */ + return NULL without an error. Example: _Ta3Pegen_seq_extract_starred_exprs */ Py_LOCAL_INLINE(void *) CHECK_CALL_NULL_ALLOWED(Parser *p, void *result) { @@ -161,7 +161,7 @@ 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 *); +PyObject *_Ta3Pegen_new_type_comment(Parser *, char *); Py_LOCAL_INLINE(PyObject *) NEW_TYPE_COMMENT(Parser *p, Token *tc) @@ -173,7 +173,7 @@ NEW_TYPE_COMMENT(Parser *p, Token *tc) if (bytes == NULL) { goto error; } - PyObject *tco = _PyPegen_new_type_comment(p, bytes); + PyObject *tco = _Ta3Pegen_new_type_comment(p, bytes); if (tco == NULL) { goto error; } @@ -200,49 +200,49 @@ INVALID_VERSION_CHECK(Parser *p, int version, char *msg, void *node) #define CHECK_VERSION(version, msg, node) INVALID_VERSION_CHECK(p, version, msg, node) -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, int *, PyArena *); -void _PyPegen_Parser_Free(Parser *); -mod_ty _PyPegen_run_parser_from_file_pointer(FILE *, int, PyObject *, const char *, - const char *, const char *, PyCompilerFlags *, int *, PyArena *); -void *_PyPegen_run_parser(Parser *); -mod_ty _PyPegen_run_parser_from_file(const char *, int, PyObject *, PyCompilerFlags *, PyArena *); -mod_ty _PyPegen_run_parser_from_string(const char *, int, PyObject *, PyCompilerFlags *, PyArena *); -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 *); -alias_ty _PyPegen_alias_for_star(Parser *); -asdl_seq *_PyPegen_map_names_to_ids(Parser *, asdl_seq *); -CmpopExprPair *_PyPegen_cmpop_expr_pair(Parser *, cmpop_ty, expr_ty); -asdl_int_seq *_PyPegen_get_cmpops(Parser *p, asdl_seq *); -asdl_seq *_PyPegen_get_exprs(Parser *, asdl_seq *); -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, 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 *, +arg_ty _Ta3Pegen_add_type_comment_to_arg(Parser *, arg_ty, Token *); +PyObject *_Ta3Pegen_new_identifier(Parser *, char *); +Parser *_Ta3Pegen_Parser_New(struct tok_state *, int, int, int, int *, PyArena *); +void _Ta3Pegen_Parser_Free(Parser *); +mod_ty _Ta3Pegen_run_parser_from_file_pointer(FILE *, int, PyObject *, const char *, + const char *, const char *, PegenCompilerFlags *, int *, PyArena *); +void *_Ta3Pegen_run_parser(Parser *); +mod_ty _Ta3Pegen_run_parser_from_file(const char *, int, PyObject *, PegenCompilerFlags *, PyArena *); +mod_ty _Ta3Pegen_run_parser_from_string(const char *, int, PyObject *, PegenCompilerFlags *, PyArena *); +void *_Ta3Pegen_interactive_exit(Parser *); +asdl_seq *_Ta3Pegen_singleton_seq(Parser *, void *); +asdl_seq *_Ta3Pegen_seq_insert_in_front(Parser *, void *, asdl_seq *); +asdl_seq *_Ta3Pegen_seq_append_to_end(Parser *, asdl_seq *, void *); +asdl_seq *_Ta3Pegen_seq_flatten(Parser *, asdl_seq *); +expr_ty _Ta3Pegen_join_names_with_dot(Parser *, expr_ty, expr_ty); +int _Ta3Pegen_seq_count_dots(asdl_seq *); +alias_ty _Ta3Pegen_alias_for_star(Parser *); +asdl_seq *_Ta3Pegen_map_names_to_ids(Parser *, asdl_seq *); +CmpopExprPair *_Ta3Pegen_cmpop_expr_pair(Parser *, cmpop_ty, expr_ty); +asdl_int_seq *_Ta3Pegen_get_cmpops(Parser *p, asdl_seq *); +asdl_seq *_Ta3Pegen_get_exprs(Parser *, asdl_seq *); +expr_ty _Ta3Pegen_set_expr_context(Parser *, expr_ty, expr_context_ty); +KeyValuePair *_Ta3Pegen_key_value_pair(Parser *, expr_ty, expr_ty); +asdl_seq *_Ta3Pegen_get_keys(Parser *, asdl_seq *); +asdl_seq *_Ta3Pegen_get_values(Parser *, asdl_seq *); +NameDefaultPair *_Ta3Pegen_name_default_pair(Parser *, arg_ty, expr_ty, Token *); +SlashWithDefault *_Ta3Pegen_slash_with_default(Parser *, asdl_seq *, asdl_seq *); +StarEtc *_Ta3Pegen_star_etc(Parser *, arg_ty, asdl_seq *, arg_ty); +arguments_ty _Ta3Pegen_make_arguments(Parser *, asdl_seq *, SlashWithDefault *, asdl_seq *, asdl_seq *, StarEtc *); -arguments_ty _PyPegen_empty_arguments(Parser *); -AugOperator *_PyPegen_augoperator(Parser*, operator_ty type); -stmt_ty _PyPegen_function_def_decorators(Parser *, asdl_seq *, stmt_ty); -stmt_ty _PyPegen_class_def_decorators(Parser *, asdl_seq *, stmt_ty); -KeywordOrStarred *_PyPegen_keyword_or_starred(Parser *, void *, int); -asdl_seq *_PyPegen_seq_extract_starred_exprs(Parser *, asdl_seq *); -asdl_seq *_PyPegen_seq_delete_starred_exprs(Parser *, asdl_seq *); -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 *); +arguments_ty _Ta3Pegen_empty_arguments(Parser *); +AugOperator *_Ta3Pegen_augoperator(Parser*, operator_ty type); +stmt_ty _Ta3Pegen_function_def_decorators(Parser *, asdl_seq *, stmt_ty); +stmt_ty _Ta3Pegen_class_def_decorators(Parser *, asdl_seq *, stmt_ty); +KeywordOrStarred *_Ta3Pegen_keyword_or_starred(Parser *, void *, int); +asdl_seq *_Ta3Pegen_seq_extract_starred_exprs(Parser *, asdl_seq *); +asdl_seq *_Ta3Pegen_seq_delete_starred_exprs(Parser *, asdl_seq *); +expr_ty _Ta3Pegen_concatenate_strings(Parser *p, asdl_seq *); +asdl_seq *_Ta3Pegen_join_sequences(Parser *, asdl_seq *, asdl_seq *); +void *_Ta3Pegen_arguments_parsing_error(Parser *, expr_ty); +int _Ta3Pegen_check_barry_as_flufl(Parser *); +mod_ty _Ta3Pegen_make_module(Parser *, asdl_seq *); + +void *_Ta3Pegen_parse(Parser *); #endif diff --git a/ast3/Parser/tokenizer.c b/ast3/Parser/tokenizer.c index 0f2b6af5..4d00ffb4 100644 --- a/ast3/Parser/tokenizer.c +++ b/ast3/Parser/tokenizer.c @@ -111,7 +111,7 @@ static char * error_ret(struct tok_state *tok) /* XXX */ { tok->decoding_erred = 1; - if (tok->fp != NULL && tok->buf != NULL) /* see PyTokenizer_Free */ + if (tok->fp != NULL && tok->buf != NULL) /* see Ta3Tokenizer_Free */ PyMem_FREE(tok->buf); tok->buf = tok->cur = tok->inp = NULL; tok->start = NULL; @@ -727,7 +727,7 @@ decode_str(const char *input, int single, struct tok_state *tok) /* Set up tokenizer for string */ struct tok_state * -PyTokenizer_FromString(const char *str, int exec_input) +Ta3Tokenizer_FromString(const char *str, int exec_input) { struct tok_state *tok = tok_new(); char *decoded; @@ -736,7 +736,7 @@ PyTokenizer_FromString(const char *str, int exec_input) return NULL; decoded = decode_str(str, exec_input, tok); if (decoded == NULL) { - PyTokenizer_Free(tok); + Ta3Tokenizer_Free(tok); return NULL; } @@ -746,7 +746,7 @@ PyTokenizer_FromString(const char *str, int exec_input) } struct tok_state * -PyTokenizer_FromUTF8(const char *str, int exec_input) +Ta3Tokenizer_FromUTF8(const char *str, int exec_input) { struct tok_state *tok = tok_new(); char *translated; @@ -754,7 +754,7 @@ PyTokenizer_FromUTF8(const char *str, int exec_input) return NULL; tok->input = translated = translate_newlines(str, exec_input, tok); if (translated == NULL) { - PyTokenizer_Free(tok); + Ta3Tokenizer_Free(tok); return NULL; } tok->decoding_state = STATE_RAW; @@ -763,7 +763,7 @@ PyTokenizer_FromUTF8(const char *str, int exec_input) tok->str = translated; tok->encoding = (char *)PyMem_MALLOC(6); if (!tok->encoding) { - PyTokenizer_Free(tok); + Ta3Tokenizer_Free(tok); return NULL; } strcpy(tok->encoding, "utf-8"); @@ -776,14 +776,14 @@ PyTokenizer_FromUTF8(const char *str, int exec_input) /* Set up tokenizer for file */ struct tok_state * -PyTokenizer_FromFile(FILE *fp, const char* enc, +Ta3Tokenizer_FromFile(FILE *fp, const char* enc, const char *ps1, const char *ps2) { struct tok_state *tok = tok_new(); if (tok == NULL) return NULL; if ((tok->buf = (char *)PyMem_MALLOC(BUFSIZ)) == NULL) { - PyTokenizer_Free(tok); + Ta3Tokenizer_Free(tok); return NULL; } tok->cur = tok->inp = tok->buf; @@ -796,7 +796,7 @@ PyTokenizer_FromFile(FILE *fp, const char* enc, gets copied into the parse tree. */ tok->encoding = PyMem_MALLOC(strlen(enc)+1); if (!tok->encoding) { - PyTokenizer_Free(tok); + Ta3Tokenizer_Free(tok); return NULL; } strcpy(tok->encoding, enc); @@ -809,7 +809,7 @@ PyTokenizer_FromFile(FILE *fp, const char* enc, /* Free a tok_state structure */ void -PyTokenizer_Free(struct tok_state *tok) +Ta3Tokenizer_Free(struct tok_state *tok) { if (tok->encoding != NULL) PyMem_FREE(tok->encoding); @@ -1809,7 +1809,7 @@ tok_get(struct tok_state *tok, const char **p_start, const char **p_end) } int -PyTokenizer_Get(struct tok_state *tok, const char **p_start, const char **p_end) +Ta3Tokenizer_Get(struct tok_state *tok, const char **p_start, const char **p_end) { int result = tok_get(tok, p_start, p_end); if (tok->decoding_erred) { @@ -1822,7 +1822,7 @@ PyTokenizer_Get(struct tok_state *tok, const char **p_start, const char **p_end) /* Get the encoding of a Python file. Check for the coding cookie and check if the file starts with a BOM. - PyTokenizer_FindEncodingFilename() returns NULL when it can't find the + Ta3Tokenizer_FindEncodingFilename() returns NULL when it can't find the encoding in the first or second line of the file (in which case the encoding should be assumed to be UTF-8). @@ -1830,7 +1830,7 @@ PyTokenizer_Get(struct tok_state *tok, const char **p_start, const char **p_end) by the caller. */ char * -PyTokenizer_FindEncodingFilename(int fd, PyObject *filename) +Ta3Tokenizer_FindEncodingFilename(int fd, PyObject *filename) { struct tok_state *tok; FILE *fp; @@ -1847,7 +1847,7 @@ PyTokenizer_FindEncodingFilename(int fd, PyObject *filename) if (fp == NULL) { return NULL; } - tok = PyTokenizer_FromFile(fp, NULL, NULL, NULL); + tok = Ta3Tokenizer_FromFile(fp, NULL, NULL, NULL); if (tok == NULL) { fclose(fp); return NULL; @@ -1860,12 +1860,12 @@ PyTokenizer_FindEncodingFilename(int fd, PyObject *filename) tok->filename = PyUnicode_FromString(""); if (tok->filename == NULL) { fclose(fp); - PyTokenizer_Free(tok); + Ta3Tokenizer_Free(tok); return encoding; } } while (tok->lineno < 2 && tok->done == E_OK) { - PyTokenizer_Get(tok, &p_start, &p_end); + Ta3Tokenizer_Get(tok, &p_start, &p_end); } fclose(fp); if (tok->encoding) { @@ -1873,14 +1873,14 @@ PyTokenizer_FindEncodingFilename(int fd, PyObject *filename) if (encoding) strcpy(encoding, tok->encoding); } - PyTokenizer_Free(tok); + Ta3Tokenizer_Free(tok); return encoding; } char * -PyTokenizer_FindEncoding(int fd) +Ta3Tokenizer_FindEncoding(int fd) { - return PyTokenizer_FindEncodingFilename(fd, NULL); + return Ta3Tokenizer_FindEncodingFilename(fd, NULL); } #ifdef Py_DEBUG diff --git a/ast3/Parser/tokenizer.h b/ast3/Parser/tokenizer.h index d9f87b3e..a81b8c1b 100644 --- a/ast3/Parser/tokenizer.h +++ b/ast3/Parser/tokenizer.h @@ -73,12 +73,12 @@ struct tok_state { NEWLINE token after it. */ }; -extern struct tok_state *PyTokenizer_FromString(const char *, int); -extern struct tok_state *PyTokenizer_FromUTF8(const char *, int); -extern struct tok_state *PyTokenizer_FromFile(FILE *, const char*, +extern struct tok_state *Ta3Tokenizer_FromString(const char *, int); +extern struct tok_state *Ta3Tokenizer_FromUTF8(const char *, int); +extern struct tok_state *Ta3Tokenizer_FromFile(FILE *, const char*, const char *, const char *); -extern void PyTokenizer_Free(struct tok_state *); -extern int PyTokenizer_Get(struct tok_state *, const char **, const char **); +extern void Ta3Tokenizer_Free(struct tok_state *); +extern int Ta3Tokenizer_Get(struct tok_state *, const char **, const char **); #define tok_dump _Py_tok_dump diff --git a/ast3/Python/Python-ast.c b/ast3/Python/Python-ast.c index f34b1450..73a54b7a 100644 --- a/ast3/Python/Python-ast.c +++ b/ast3/Python/Python-ast.c @@ -3,9 +3,14 @@ #include #include "Python.h" -#include "Python-ast.h" +#include "../Include/Python-ast.h" #include "structmember.h" // PyMemberDef +PyObject *ast3_parse(PyObject *self, PyObject *args); +static PyMethodDef ast3_methods[] = { + {"_parse", ast3_parse, METH_VARARGS, "Parse string into typed AST."}, + {NULL, NULL, NULL} +}; typedef struct { int initialized; PyObject *AST_type; @@ -670,10 +675,10 @@ static void astmodule_free(void* module) { static struct PyModuleDef _astmodule = { PyModuleDef_HEAD_INIT, - "_ast", + "_ast3", NULL, sizeof(astmodulestate), - NULL, + ast3_methods, NULL, astmodule_traverse, astmodule_clear, @@ -1126,7 +1131,7 @@ ast_type_init(PyObject *self, PyObject *args, PyObject *kw) Py_ssize_t i, numfields = 0; int res = -1; PyObject *key, *value, *fields; - if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), astmodulestate_global->_fields, &fields) < 0) { + if (_Pegen_PyObject_LookupAttr((PyObject*)Py_TYPE(self), astmodulestate_global->_fields, &fields) < 0) { goto cleanup; } if (fields) { @@ -1139,7 +1144,7 @@ ast_type_init(PyObject *self, PyObject *args, PyObject *kw) if (numfields < PyTuple_GET_SIZE(args)) { PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most " "%zd positional argument%s", - _PyType_Name(Py_TYPE(self)), + _Ta3Type_Name(Py_TYPE(self)), numfields, numfields == 1 ? "" : "s"); res = -1; goto cleanup; @@ -1174,7 +1179,7 @@ static PyObject * ast_type_reduce(PyObject *self, PyObject *unused) { PyObject *dict; - if (_PyObject_LookupAttr(self, astmodulestate_global->__dict__, &dict) < 0) { + if (_Pegen_PyObject_LookupAttr(self, astmodulestate_global->__dict__, &dict) < 0) { return NULL; } if (dict) { @@ -5100,7 +5105,8 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) asdl_seq* body; asdl_seq* type_ignores; - if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -5112,11 +5118,11 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - body = _Py_asdl_seq_new(len, arena); + body = _Ta3_asdl_seq_new(len, arena); if (body == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; @@ -5133,8 +5139,8 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->type_ignores, - &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, + astmodulestate_global->type_ignores, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5146,11 +5152,11 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Module field \"type_ignores\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "Module field \"type_ignores\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - type_ignores = _Py_asdl_seq_new(len, arena); + type_ignores = _Ta3_asdl_seq_new(len, arena); if (type_ignores == NULL) goto failed; for (i = 0; i < len; i++) { type_ignore_ty val; @@ -5179,7 +5185,8 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) if (isinstance) { asdl_seq* body; - if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -5191,11 +5198,11 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - body = _Py_asdl_seq_new(len, arena); + body = _Ta3_asdl_seq_new(len, arena); if (body == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; @@ -5224,7 +5231,8 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) if (isinstance) { expr_ty body; - if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -5250,8 +5258,8 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) asdl_seq* argtypes; expr_ty returns; - if (_PyObject_LookupAttr(obj, astmodulestate_global->argtypes, &tmp) < - 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->argtypes, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5263,11 +5271,11 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "FunctionType field \"argtypes\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "FunctionType field \"argtypes\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - argtypes = _Py_asdl_seq_new(len, arena); + argtypes = _Ta3_asdl_seq_new(len, arena); if (argtypes == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; @@ -5284,8 +5292,8 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < - 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->returns, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5325,7 +5333,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) *out = NULL; return 0; } - if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < + 0) { return 1; } if (tmp == NULL) { @@ -5338,8 +5347,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) - { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5352,8 +5361,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) - { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, + &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -5366,8 +5375,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) - < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, + &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -5393,7 +5402,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) expr_ty returns; string type_comment; - if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -5406,7 +5416,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -5419,7 +5430,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -5431,11 +5443,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - body = _Py_asdl_seq_new(len, arena); + body = _Ta3_asdl_seq_new(len, arena); if (body == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; @@ -5452,8 +5464,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, - &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, + astmodulestate_global->decorator_list, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5465,11 +5477,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - decorator_list = _Py_asdl_seq_new(len, arena); + decorator_list = _Ta3_asdl_seq_new(len, arena); if (decorator_list == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; @@ -5486,8 +5498,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < - 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->returns, + &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -5500,8 +5512,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, - &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, + astmodulestate_global->type_comment, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -5533,7 +5545,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) expr_ty returns; string type_comment; - if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -5546,7 +5559,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -5559,7 +5573,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -5571,11 +5586,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"body\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - body = _Py_asdl_seq_new(len, arena); + body = _Ta3_asdl_seq_new(len, arena); if (body == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; @@ -5592,8 +5607,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, - &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, + astmodulestate_global->decorator_list, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5605,11 +5620,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"decorator_list\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"decorator_list\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - decorator_list = _Py_asdl_seq_new(len, arena); + decorator_list = _Ta3_asdl_seq_new(len, arena); if (decorator_list == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; @@ -5626,8 +5641,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < - 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->returns, + &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -5640,8 +5655,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, - &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, + astmodulestate_global->type_comment, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -5672,7 +5687,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) asdl_seq* body; asdl_seq* decorator_list; - if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -5685,7 +5701,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->bases, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->bases, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -5697,11 +5714,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - bases = _Py_asdl_seq_new(len, arena); + bases = _Ta3_asdl_seq_new(len, arena); if (bases == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; @@ -5718,8 +5735,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) < - 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->keywords, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5731,11 +5748,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - keywords = _Py_asdl_seq_new(len, arena); + keywords = _Ta3_asdl_seq_new(len, arena); if (keywords == NULL) goto failed; for (i = 0; i < len; i++) { keyword_ty val; @@ -5752,7 +5769,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -5764,11 +5782,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - body = _Py_asdl_seq_new(len, arena); + body = _Ta3_asdl_seq_new(len, arena); if (body == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; @@ -5785,8 +5803,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, - &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, + astmodulestate_global->decorator_list, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5798,11 +5816,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - decorator_list = _Py_asdl_seq_new(len, arena); + decorator_list = _Ta3_asdl_seq_new(len, arena); if (decorator_list == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; @@ -5832,7 +5850,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (isinstance) { expr_ty value; - if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) + < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -5858,8 +5877,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (isinstance) { asdl_seq* targets; - if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) < - 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->targets, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5871,11 +5890,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - targets = _Py_asdl_seq_new(len, arena); + targets = _Ta3_asdl_seq_new(len, arena); if (targets == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; @@ -5907,8 +5926,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) expr_ty value; string type_comment; - if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) < - 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->targets, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5920,11 +5939,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - targets = _Py_asdl_seq_new(len, arena); + targets = _Ta3_asdl_seq_new(len, arena); if (targets == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; @@ -5941,7 +5960,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -5954,8 +5974,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, - &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, + astmodulestate_global->type_comment, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -5983,8 +6003,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) operator_ty op; expr_ty value; - if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) - { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->target, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5997,7 +6017,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < + 0) { return 1; } if (tmp == NULL) { @@ -6010,7 +6031,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -6039,8 +6061,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) expr_ty value; int simple; - if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) - { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->target, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6053,8 +6075,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) - < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->annotation, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6067,7 +6089,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) + < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -6080,8 +6103,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->simple, &tmp) < 0) - { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->simple, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6111,8 +6134,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) asdl_seq* orelse; string type_comment; - if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) - { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->target, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6125,7 +6148,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -6138,7 +6162,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -6150,11 +6175,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - body = _Py_asdl_seq_new(len, arena); + body = _Ta3_asdl_seq_new(len, arena); if (body == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; @@ -6171,8 +6196,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) - { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->orelse, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6184,11 +6209,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - orelse = _Py_asdl_seq_new(len, arena); + orelse = _Ta3_asdl_seq_new(len, arena); if (orelse == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; @@ -6205,8 +6230,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, - &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, + astmodulestate_global->type_comment, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -6236,8 +6261,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) asdl_seq* orelse; string type_comment; - if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) - { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->target, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6250,7 +6275,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -6263,7 +6289,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -6275,11 +6302,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "AsyncFor field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "AsyncFor field \"body\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - body = _Py_asdl_seq_new(len, arena); + body = _Ta3_asdl_seq_new(len, arena); if (body == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; @@ -6296,8 +6323,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) - { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->orelse, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6309,11 +6336,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "AsyncFor field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "AsyncFor field \"orelse\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - orelse = _Py_asdl_seq_new(len, arena); + orelse = _Ta3_asdl_seq_new(len, arena); if (orelse == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; @@ -6330,8 +6357,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, - &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, + astmodulestate_global->type_comment, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -6359,7 +6386,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) asdl_seq* body; asdl_seq* orelse; - if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -6372,7 +6400,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -6384,11 +6413,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - body = _Py_asdl_seq_new(len, arena); + body = _Ta3_asdl_seq_new(len, arena); if (body == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; @@ -6405,8 +6434,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) - { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->orelse, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6418,11 +6447,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - orelse = _Py_asdl_seq_new(len, arena); + orelse = _Ta3_asdl_seq_new(len, arena); if (orelse == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; @@ -6454,7 +6483,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) asdl_seq* body; asdl_seq* orelse; - if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -6467,7 +6497,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -6479,11 +6510,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - body = _Py_asdl_seq_new(len, arena); + body = _Ta3_asdl_seq_new(len, arena); if (body == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; @@ -6500,8 +6531,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) - { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->orelse, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6513,11 +6544,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - orelse = _Py_asdl_seq_new(len, arena); + orelse = _Ta3_asdl_seq_new(len, arena); if (orelse == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; @@ -6549,7 +6580,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) asdl_seq* body; string type_comment; - if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -6561,11 +6593,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - items = _Py_asdl_seq_new(len, arena); + items = _Ta3_asdl_seq_new(len, arena); if (items == NULL) goto failed; for (i = 0; i < len; i++) { withitem_ty val; @@ -6582,7 +6614,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -6594,11 +6627,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - body = _Py_asdl_seq_new(len, arena); + body = _Ta3_asdl_seq_new(len, arena); if (body == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; @@ -6615,8 +6648,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, - &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, + astmodulestate_global->type_comment, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -6644,7 +6677,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) asdl_seq* body; string type_comment; - if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -6656,11 +6690,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "AsyncWith field \"items\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "AsyncWith field \"items\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - items = _Py_asdl_seq_new(len, arena); + items = _Ta3_asdl_seq_new(len, arena); if (items == NULL) goto failed; for (i = 0; i < len; i++) { withitem_ty val; @@ -6677,7 +6711,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -6689,11 +6724,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "AsyncWith field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "AsyncWith field \"body\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - body = _Py_asdl_seq_new(len, arena); + body = _Ta3_asdl_seq_new(len, arena); if (body == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; @@ -6710,8 +6745,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, - &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, + astmodulestate_global->type_comment, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -6738,7 +6773,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) expr_ty exc; expr_ty cause; - if (_PyObject_LookupAttr(obj, astmodulestate_global->exc, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->exc, &tmp) < + 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -6751,7 +6787,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->cause, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->cause, &tmp) + < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -6780,7 +6817,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) asdl_seq* orelse; asdl_seq* finalbody; - if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -6792,11 +6830,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - body = _Py_asdl_seq_new(len, arena); + body = _Ta3_asdl_seq_new(len, arena); if (body == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; @@ -6813,8 +6851,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->handlers, &tmp) < - 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->handlers, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6826,11 +6864,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - handlers = _Py_asdl_seq_new(len, arena); + handlers = _Ta3_asdl_seq_new(len, arena); if (handlers == NULL) goto failed; for (i = 0; i < len; i++) { excepthandler_ty val; @@ -6847,8 +6885,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) - { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->orelse, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6860,11 +6898,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - orelse = _Py_asdl_seq_new(len, arena); + orelse = _Ta3_asdl_seq_new(len, arena); if (orelse == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; @@ -6881,8 +6919,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->finalbody, &tmp) < - 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->finalbody, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6894,11 +6932,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - finalbody = _Py_asdl_seq_new(len, arena); + finalbody = _Ta3_asdl_seq_new(len, arena); if (finalbody == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; @@ -6929,7 +6967,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) expr_ty test; expr_ty msg; - if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -6942,7 +6981,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->msg, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->msg, &tmp) < + 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -6968,7 +7008,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (isinstance) { asdl_seq* names; - if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -6980,11 +7021,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - names = _Py_asdl_seq_new(len, arena); + names = _Ta3_asdl_seq_new(len, arena); if (names == NULL) goto failed; for (i = 0; i < len; i++) { alias_ty val; @@ -7016,8 +7057,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) asdl_seq* names; int level; - if (_PyObject_LookupAttr(obj, astmodulestate_global->module, &tmp) < 0) - { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->module, + &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -7030,7 +7071,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -7042,11 +7084,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - names = _Py_asdl_seq_new(len, arena); + names = _Ta3_asdl_seq_new(len, arena); if (names == NULL) goto failed; for (i = 0; i < len; i++) { alias_ty val; @@ -7063,7 +7105,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->level, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->level, &tmp) + < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -7089,7 +7132,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (isinstance) { asdl_seq* names; - if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -7101,11 +7145,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - names = _Py_asdl_seq_new(len, arena); + names = _Ta3_asdl_seq_new(len, arena); if (names == NULL) goto failed; for (i = 0; i < len; i++) { identifier val; @@ -7135,7 +7179,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (isinstance) { asdl_seq* names; - if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -7147,11 +7192,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - names = _Py_asdl_seq_new(len, arena); + names = _Ta3_asdl_seq_new(len, arena); if (names == NULL) goto failed; for (i = 0; i < len; i++) { identifier val; @@ -7181,7 +7226,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (isinstance) { expr_ty value; - if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -7255,7 +7301,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) *out = NULL; return 0; } - if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < + 0) { return 1; } if (tmp == NULL) { @@ -7268,8 +7315,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) - { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7282,8 +7329,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) - { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, + &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -7296,8 +7343,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) - < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, + &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -7319,7 +7366,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) boolop_ty op; asdl_seq* values; - if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < + 0) { return 1; } if (tmp == NULL) { @@ -7332,8 +7380,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) - { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->values, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7345,11 +7393,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - values = _Py_asdl_seq_new(len, arena); + values = _Ta3_asdl_seq_new(len, arena); if (values == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; @@ -7380,8 +7428,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty target; expr_ty value; - if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) - { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->target, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7394,7 +7442,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -7422,7 +7471,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) operator_ty op; expr_ty right; - if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -7435,7 +7485,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < + 0) { return 1; } if (tmp == NULL) { @@ -7448,7 +7499,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->right, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->right, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -7475,7 +7527,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) unaryop_ty op; expr_ty operand; - if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < + 0) { return 1; } if (tmp == NULL) { @@ -7488,8 +7541,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->operand, &tmp) < - 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->operand, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7516,7 +7569,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) arguments_ty args; expr_ty body; - if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -7529,7 +7583,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -7557,7 +7612,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty body; expr_ty orelse; - if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -7570,7 +7626,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -7583,8 +7640,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) - { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->orelse, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7611,7 +7668,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) asdl_seq* keys; asdl_seq* values; - if (_PyObject_LookupAttr(obj, astmodulestate_global->keys, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->keys, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -7623,11 +7681,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - keys = _Py_asdl_seq_new(len, arena); + keys = _Ta3_asdl_seq_new(len, arena); if (keys == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; @@ -7644,8 +7702,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) - { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->values, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7657,11 +7715,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - values = _Py_asdl_seq_new(len, arena); + values = _Ta3_asdl_seq_new(len, arena); if (values == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; @@ -7691,7 +7749,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (isinstance) { asdl_seq* elts; - if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -7703,11 +7762,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - elts = _Py_asdl_seq_new(len, arena); + elts = _Ta3_asdl_seq_new(len, arena); if (elts == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; @@ -7737,7 +7796,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty elt; asdl_seq* generators; - if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < + 0) { return 1; } if (tmp == NULL) { @@ -7750,8 +7810,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) - < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->generators, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7763,11 +7823,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - generators = _Py_asdl_seq_new(len, arena); + generators = _Ta3_asdl_seq_new(len, arena); if (generators == NULL) goto failed; for (i = 0; i < len; i++) { comprehension_ty val; @@ -7798,7 +7858,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty elt; asdl_seq* generators; - if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < + 0) { return 1; } if (tmp == NULL) { @@ -7811,8 +7872,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) - < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->generators, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7824,11 +7885,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - generators = _Py_asdl_seq_new(len, arena); + generators = _Ta3_asdl_seq_new(len, arena); if (generators == NULL) goto failed; for (i = 0; i < len; i++) { comprehension_ty val; @@ -7860,7 +7921,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty value; asdl_seq* generators; - if (_PyObject_LookupAttr(obj, astmodulestate_global->key, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->key, &tmp) < + 0) { return 1; } if (tmp == NULL) { @@ -7873,7 +7935,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -7886,8 +7949,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) - < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->generators, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7899,11 +7962,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - generators = _Py_asdl_seq_new(len, arena); + generators = _Ta3_asdl_seq_new(len, arena); if (generators == NULL) goto failed; for (i = 0; i < len; i++) { comprehension_ty val; @@ -7934,7 +7997,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty elt; asdl_seq* generators; - if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < + 0) { return 1; } if (tmp == NULL) { @@ -7947,8 +8011,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) - < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->generators, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7960,11 +8024,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - generators = _Py_asdl_seq_new(len, arena); + generators = _Ta3_asdl_seq_new(len, arena); if (generators == NULL) goto failed; for (i = 0; i < len; i++) { comprehension_ty val; @@ -7994,7 +8058,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (isinstance) { expr_ty value; - if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -8020,7 +8085,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (isinstance) { expr_ty value; - if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) + < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -8046,7 +8112,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (isinstance) { expr_ty value; - if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -8074,7 +8141,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) asdl_int_seq* ops; asdl_seq* comparators; - if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -8087,7 +8155,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->ops, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->ops, &tmp) < + 0) { return 1; } if (tmp == NULL) { @@ -8099,11 +8168,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - ops = _Py_asdl_int_seq_new(len, arena); + ops = _Ta3_asdl_int_seq_new(len, arena); if (ops == NULL) goto failed; for (i = 0; i < len; i++) { cmpop_ty val; @@ -8120,8 +8189,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->comparators, &tmp) - < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->comparators, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8133,11 +8202,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - comparators = _Py_asdl_seq_new(len, arena); + comparators = _Ta3_asdl_seq_new(len, arena); if (comparators == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; @@ -8169,7 +8238,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) asdl_seq* args; asdl_seq* keywords; - if (_PyObject_LookupAttr(obj, astmodulestate_global->func, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->func, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -8182,7 +8252,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -8194,11 +8265,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - args = _Py_asdl_seq_new(len, arena); + args = _Ta3_asdl_seq_new(len, arena); if (args == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; @@ -8215,8 +8286,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) < - 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->keywords, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8228,11 +8299,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - keywords = _Py_asdl_seq_new(len, arena); + keywords = _Ta3_asdl_seq_new(len, arena); if (keywords == NULL) goto failed; for (i = 0; i < len; i++) { keyword_ty val; @@ -8264,7 +8335,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) int conversion; expr_ty format_spec; - if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -8277,8 +8349,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->conversion, &tmp) - < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->conversion, + &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -8291,8 +8363,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->format_spec, &tmp) - < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->format_spec, + &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -8318,8 +8390,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (isinstance) { asdl_seq* values; - if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) - { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->values, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8331,11 +8403,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "JoinedStr field \"values\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "JoinedStr field \"values\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - values = _Py_asdl_seq_new(len, arena); + values = _Ta3_asdl_seq_new(len, arena); if (values == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; @@ -8366,7 +8438,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) constant value; string kind; - if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -8379,7 +8452,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->kind, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->kind, &tmp) + < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -8407,7 +8481,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) identifier attr; expr_context_ty ctx; - if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -8420,7 +8495,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->attr, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->attr, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -8433,7 +8509,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < + 0) { return 1; } if (tmp == NULL) { @@ -8461,7 +8538,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty slice; expr_context_ty ctx; - if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -8474,7 +8552,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->slice, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->slice, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -8487,7 +8566,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < + 0) { return 1; } if (tmp == NULL) { @@ -8514,7 +8594,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty value; expr_context_ty ctx; - if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -8527,7 +8608,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < + 0) { return 1; } if (tmp == NULL) { @@ -8554,7 +8636,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) identifier id; expr_context_ty ctx; - if (_PyObject_LookupAttr(obj, astmodulestate_global->id, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->id, &tmp) < + 0) { return 1; } if (tmp == NULL) { @@ -8567,7 +8650,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < + 0) { return 1; } if (tmp == NULL) { @@ -8594,7 +8678,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) asdl_seq* elts; expr_context_ty ctx; - if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -8606,11 +8691,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - elts = _Py_asdl_seq_new(len, arena); + elts = _Ta3_asdl_seq_new(len, arena); if (elts == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; @@ -8627,7 +8712,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < + 0) { return 1; } if (tmp == NULL) { @@ -8654,7 +8740,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) asdl_seq* elts; expr_context_ty ctx; - if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -8666,11 +8753,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - elts = _Py_asdl_seq_new(len, arena); + elts = _Ta3_asdl_seq_new(len, arena); if (elts == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; @@ -8687,7 +8774,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < + 0) { return 1; } if (tmp == NULL) { @@ -8715,7 +8803,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty upper; expr_ty step; - if (_PyObject_LookupAttr(obj, astmodulestate_global->lower, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->lower, &tmp) + < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -8728,7 +8817,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->upper, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->upper, &tmp) + < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -8741,7 +8831,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->step, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->step, &tmp) + < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -9081,7 +9172,8 @@ obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) asdl_seq* ifs; int is_async; - if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < + 0) { return 1; } if (tmp == NULL) { @@ -9094,7 +9186,8 @@ obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) + { return 1; } if (tmp == NULL) { @@ -9107,7 +9200,7 @@ obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->ifs, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->ifs, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -9119,11 +9212,11 @@ obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - ifs = _Py_asdl_seq_new(len, arena); + ifs = _Ta3_asdl_seq_new(len, arena); if (ifs == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; @@ -9140,7 +9233,8 @@ obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->is_async, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->is_async, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -9176,7 +9270,8 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) *out = NULL; return 0; } - if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < + 0) { return 1; } if (tmp == NULL) { @@ -9189,8 +9284,8 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) - { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -9203,8 +9298,8 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) - { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, + &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -9217,8 +9312,8 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) - < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, + &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -9241,7 +9336,8 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) identifier name; asdl_seq* body; - if (_PyObject_LookupAttr(obj, astmodulestate_global->type, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->type, &tmp) + < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -9254,7 +9350,8 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) + < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -9267,7 +9364,8 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -9279,11 +9377,11 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - body = _Py_asdl_seq_new(len, arena); + body = _Ta3_asdl_seq_new(len, arena); if (body == NULL) goto failed; for (i = 0; i < len; i++) { stmt_ty val; @@ -9324,8 +9422,8 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) arg_ty kwarg; asdl_seq* defaults; - if (_PyObject_LookupAttr(obj, astmodulestate_global->posonlyargs, &tmp) < - 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->posonlyargs, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -9337,11 +9435,11 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "arguments field \"posonlyargs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "arguments field \"posonlyargs\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - posonlyargs = _Py_asdl_seq_new(len, arena); + posonlyargs = _Ta3_asdl_seq_new(len, arena); if (posonlyargs == NULL) goto failed; for (i = 0; i < len; i++) { arg_ty val; @@ -9358,7 +9456,8 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) + { return 1; } if (tmp == NULL) { @@ -9370,11 +9469,11 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - args = _Py_asdl_seq_new(len, arena); + args = _Ta3_asdl_seq_new(len, arena); if (args == NULL) goto failed; for (i = 0; i < len; i++) { arg_ty val; @@ -9391,7 +9490,8 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->vararg, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->vararg, &tmp) < + 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -9404,8 +9504,8 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->kwonlyargs, &tmp) < 0) - { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->kwonlyargs, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -9417,11 +9517,11 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - kwonlyargs = _Py_asdl_seq_new(len, arena); + kwonlyargs = _Ta3_asdl_seq_new(len, arena); if (kwonlyargs == NULL) goto failed; for (i = 0; i < len; i++) { arg_ty val; @@ -9438,8 +9538,8 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->kw_defaults, &tmp) < - 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->kw_defaults, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -9451,11 +9551,11 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - kw_defaults = _Py_asdl_seq_new(len, arena); + kw_defaults = _Ta3_asdl_seq_new(len, arena); if (kw_defaults == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; @@ -9472,7 +9572,8 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->kwarg, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->kwarg, &tmp) < + 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -9485,7 +9586,8 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->defaults, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->defaults, &tmp) + < 0) { return 1; } if (tmp == NULL) { @@ -9497,11 +9599,11 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", _Ta3Type_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - defaults = _Py_asdl_seq_new(len, arena); + defaults = _Ta3_asdl_seq_new(len, arena); if (defaults == NULL) goto failed; for (i = 0; i < len; i++) { expr_ty val; @@ -9538,7 +9640,7 @@ obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) int end_lineno; int end_col_offset; - if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -9551,8 +9653,8 @@ obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) < 0) - { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->annotation, + &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -9565,8 +9667,8 @@ obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, &tmp) < - 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, + &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -9579,7 +9681,8 @@ obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < + 0) { return 1; } if (tmp == NULL) { @@ -9592,8 +9695,8 @@ obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) - { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -9606,8 +9709,8 @@ obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) - { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, + &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -9620,8 +9723,8 @@ obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) - < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, + &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -9653,7 +9756,7 @@ obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) int end_lineno; int end_col_offset; - if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -9666,7 +9769,8 @@ obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < + 0) { return 1; } if (tmp == NULL) { @@ -9679,7 +9783,8 @@ obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < + 0) { return 1; } if (tmp == NULL) { @@ -9692,8 +9797,8 @@ obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) - { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -9706,8 +9811,8 @@ obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) - { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, + &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -9720,8 +9825,8 @@ obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) - < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, + &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -9749,7 +9854,8 @@ obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) identifier name; identifier asname; - if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) + { return 1; } if (tmp == NULL) { @@ -9762,7 +9868,8 @@ obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->asname, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->asname, &tmp) < + 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -9789,8 +9896,8 @@ obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) expr_ty context_expr; expr_ty optional_vars; - if (_PyObject_LookupAttr(obj, astmodulestate_global->context_expr, &tmp) < - 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->context_expr, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -9803,8 +9910,8 @@ obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->optional_vars, &tmp) < - 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->optional_vars, + &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -9845,8 +9952,8 @@ obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena) int lineno; string tag; - if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) - { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->lineno, + &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -9859,7 +9966,8 @@ obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena) if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->tag, &tmp) < 0) { + if (_Pegen_PyObject_LookupAttr(obj, astmodulestate_global->tag, &tmp) < + 0) { return 1; } if (tmp == NULL) { @@ -9885,7 +9993,7 @@ obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena) PyMODINIT_FUNC -PyInit__ast(void) +PyInit__ast3(void) { PyObject *m; if (!init_types()) return NULL; @@ -10390,7 +10498,7 @@ PyInit__ast(void) } -PyObject* PyAST_mod2obj(mod_ty t) +PyObject* Ta3AST_mod2obj(mod_ty t) { if (!init_types()) return NULL; @@ -10398,16 +10506,12 @@ PyObject* PyAST_mod2obj(mod_ty t) } /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ -mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) +mod_ty Ta3AST_obj2mod(PyObject* ast, PyArena* arena, int mode) { PyObject *req_type[3]; const char * const req_name[] = {"Module", "Expression", "Interactive"}; int isinstance; - if (PySys_Audit("compile", "OO", ast, Py_None) < 0) { - return NULL; - } - req_type[0] = astmodulestate_global->Module_type; req_type[1] = astmodulestate_global->Expression_type; req_type[2] = astmodulestate_global->Interactive_type; @@ -10422,7 +10526,7 @@ mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) return NULL; if (!isinstance) { PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", - req_name[mode], _PyType_Name(Py_TYPE(ast))); + req_name[mode], _Ta3Type_Name(Py_TYPE(ast))); return NULL; } @@ -10433,7 +10537,7 @@ mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) return res; } -int PyAST_Check(PyObject* obj) +int Ta3AST_Check(PyObject* obj) { if (!init_types()) return -1; diff --git a/ast3/Python/asdl.c b/ast3/Python/asdl.c index c2110781..87220575 100644 --- a/ast3/Python/asdl.c +++ b/ast3/Python/asdl.c @@ -2,7 +2,7 @@ #include "asdl.h" asdl_seq * -_Py_asdl_seq_new(Py_ssize_t size, PyArena *arena) +_Ta3_asdl_seq_new(Py_ssize_t size, PyArena *arena) { asdl_seq *seq = NULL; size_t n; @@ -33,7 +33,7 @@ _Py_asdl_seq_new(Py_ssize_t size, PyArena *arena) } asdl_int_seq * -_Py_asdl_int_seq_new(Py_ssize_t size, PyArena *arena) +_Ta3_asdl_int_seq_new(Py_ssize_t size, PyArena *arena) { asdl_int_seq *seq = NULL; size_t n; diff --git a/ast3/Tools/peg_generator/peg_extension/peg_extension.c b/ast3/Tools/peg_generator/peg_extension/peg_extension.c index fb552eed..f6b35e28 100644 --- a/ast3/Tools/peg_generator/peg_extension/peg_extension.c +++ b/ast3/Tools/peg_generator/peg_extension/peg_extension.c @@ -8,7 +8,7 @@ _build_return_object(mod_ty module, int mode, PyObject *filename_ob, PyArena *ar if (mode == 2) { result = (PyObject *)PyAST_CompileObject(module, filename_ob, NULL, -1, arena); } else if (mode == 1) { - result = PyAST_mod2obj(module); + result = Ta3AST_mod2obj(module); } else { result = Py_None; Py_INCREF(result); @@ -42,8 +42,8 @@ parse_file(PyObject *self, PyObject *args, PyObject *kwds) goto error; } - PyCompilerFlags flags = _PyCompilerFlags_INIT; - mod_ty res = _PyPegen_run_parser_from_file(filename, Py_file_input, filename_ob, &flags, arena); + PegenCompilerFlags flags = _PyCompilerFlags_INIT; + mod_ty res = _Ta3Pegen_run_parser_from_file(filename, Py_file_input, filename_ob, &flags, arena); if (res == NULL) { goto error; } @@ -81,8 +81,8 @@ parse_string(PyObject *self, PyObject *args, PyObject *kwds) goto error; } - PyCompilerFlags flags = _PyCompilerFlags_INIT; - mod_ty res = _PyPegen_run_parser_from_string(the_string, Py_file_input, filename_ob, + PegenCompilerFlags flags = _PyCompilerFlags_INIT; + mod_ty res = _Ta3Pegen_run_parser_from_string(the_string, Py_file_input, filename_ob, &flags, arena); if (res == NULL) { goto error; @@ -98,21 +98,21 @@ parse_string(PyObject *self, PyObject *args, PyObject *kwds) static PyObject * clear_memo_stats() { - _PyPegen_clear_memo_statistics(); + _Ta3Pegen_clear_memo_statistics(); Py_RETURN_NONE; } static PyObject * get_memo_stats() { - return _PyPegen_get_memo_statistics(); + return _Ta3Pegen_get_memo_statistics(); } // TODO: Write to Python's sys.stdout instead of C's stdout. static PyObject * dump_memo_stats() { - PyObject *list = _PyPegen_get_memo_statistics(); + PyObject *list = _Ta3Pegen_get_memo_statistics(); if (list == NULL) { return NULL; } diff --git a/ast3/Tools/peg_generator/pegen/c_generator.py b/ast3/Tools/peg_generator/pegen/c_generator.py index 3bf6d9ed..89e6f5e1 100644 --- a/ast3/Tools/peg_generator/pegen/c_generator.py +++ b/ast3/Tools/peg_generator/pegen/c_generator.py @@ -27,13 +27,13 @@ EXTENSION_PREFIX = """\ #include "pegen.h" - +#include "ta3_compat.h" """ EXTENSION_SUFFIX = """ void * -_PyPegen_parse(Parser *p) +_Ta3Pegen_parse(Parser *p) { // Initialize keywords p->keywords = reserved_keywords; @@ -102,7 +102,7 @@ def keyword_helper(self, keyword: str) -> FunctionCall: self.keyword_cache[keyword] = self.gen.keyword_type() return FunctionCall( assigned_variable="keyword", - function="_PyPegen_expect_token", + function="_Ta3Pegen_expect_token", arguments=["p", self.keyword_cache[keyword]], return_type="Token *", nodetype=NodeTypes.KEYWORD, @@ -115,7 +115,7 @@ def visit_NameLeaf(self, node: NameLeaf) -> FunctionCall: if name in BASE_NODETYPES: return FunctionCall( assigned_variable=f"{name.lower()}_var", - function=f"_PyPegen_{name.lower()}_token", + function=f"_Ta3Pegen_{name.lower()}_token", arguments=["p"], nodetype=BASE_NODETYPES[name], return_type="expr_ty", @@ -123,7 +123,7 @@ def visit_NameLeaf(self, node: NameLeaf) -> FunctionCall: ) return FunctionCall( assigned_variable=f"{name.lower()}_var", - function=f"_PyPegen_expect_token", + function=f"_Ta3Pegen_expect_token", arguments=["p", name], nodetype=NodeTypes.GENERIC_TOKEN, return_type="Token *", @@ -152,7 +152,7 @@ def visit_StringLeaf(self, node: StringLeaf) -> FunctionCall: type = self.exact_tokens[val] return FunctionCall( assigned_variable="literal", - function=f"_PyPegen_expect_token", + function=f"_Ta3Pegen_expect_token", arguments=["p", type], nodetype=NodeTypes.GENERIC_TOKEN, return_type="Token *", @@ -190,20 +190,20 @@ def lookahead_call_helper(self, node: Lookahead, positive: int) -> FunctionCall: call = self.visit(node.node) if call.nodetype == NodeTypes.NAME_TOKEN: return FunctionCall( - function=f"_PyPegen_lookahead_with_name", + function=f"_Ta3Pegen_lookahead_with_name", arguments=[positive, call.function, *call.arguments], return_type="int", ) elif call.nodetype in {NodeTypes.GENERIC_TOKEN, NodeTypes.KEYWORD}: return FunctionCall( - function=f"_PyPegen_lookahead_with_int", + function=f"_Ta3Pegen_lookahead_with_int", arguments=[positive, call.function, *call.arguments], return_type="int", comment=f"token={node.node}", ) else: return FunctionCall( - function=f"_PyPegen_lookahead", + function=f"_Ta3Pegen_lookahead", arguments=[positive, call.function, *call.arguments], return_type="int", ) @@ -413,7 +413,7 @@ def _setup_keywords(self) -> None: self.print("};") def _set_up_token_start_metadata_extraction(self) -> None: - self.print("if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) {") + self.print("if (p->mark == p->fill && _Ta3Pegen_fill_token(p) < 0) {") with self.indent(): self.print("p->error_indicator = 1;") self.print("return NULL;") @@ -424,7 +424,7 @@ def _set_up_token_start_metadata_extraction(self) -> None: self.print("UNUSED(start_col_offset); // Only used by EXTRA macro") def _set_up_token_end_metadata_extraction(self) -> None: - self.print("Token *token = _PyPegen_get_last_nonnwhitespace_token(p);") + self.print("Token *token = _Ta3Pegen_get_last_nonnwhitespace_token(p);") self.print("if (token == NULL) {") with self.indent(): self.print("return NULL;") @@ -438,7 +438,7 @@ def _set_up_rule_memoization(self, node: Rule, result_type: str) -> None: self.print("{") with self.indent(): self.print(f"{result_type} res = NULL;") - self.print(f"if (_PyPegen_is_memoized(p, {node.name}_type, &res))") + self.print(f"if (_Ta3Pegen_is_memoized(p, {node.name}_type, &res))") with self.indent(): self.print("return res;") self.print("int mark = p->mark;") @@ -446,7 +446,7 @@ def _set_up_rule_memoization(self, node: Rule, result_type: str) -> None: self.print("while (1) {") with self.indent(): self.call_with_errorcheck_return( - f"_PyPegen_update_memo(p, mark, {node.name}_type, res)", "res" + f"_Ta3Pegen_update_memo(p, mark, {node.name}_type, res)", "res" ) self.print("p->mark = mark;") self.print(f"void *raw = {node.name}_raw(p);") @@ -475,7 +475,7 @@ def _handle_default_rule_body(self, node: Rule, rhs: Rhs, result_type: str) -> N self.print("}") self.print(f"{result_type} res = NULL;") if memoize: - self.print(f"if (_PyPegen_is_memoized(p, {node.name}_type, &res))") + self.print(f"if (_Ta3Pegen_is_memoized(p, {node.name}_type, &res))") with self.indent(): self.print("return res;") self.print("int mark = p->mark;") @@ -493,7 +493,7 @@ def _handle_default_rule_body(self, node: Rule, rhs: Rhs, result_type: str) -> N self.print(" done:") with self.indent(): if memoize: - self.print(f"_PyPegen_insert_memo(p, mark, {node.name}_type, res);") + self.print(f"_Ta3Pegen_insert_memo(p, mark, {node.name}_type, res);") self.print("return res;") def _handle_loop_rule_body(self, node: Rule, rhs: Rhs) -> None: @@ -507,7 +507,7 @@ def _handle_loop_rule_body(self, node: Rule, rhs: Rhs) -> None: self.print("}") self.print(f"void *res = NULL;") if memoize: - self.print(f"if (_PyPegen_is_memoized(p, {node.name}_type, &res))") + self.print(f"if (_Ta3Pegen_is_memoized(p, {node.name}_type, &res))") with self.indent(): self.print("return res;") self.print("int mark = p->mark;") @@ -530,7 +530,7 @@ def _handle_loop_rule_body(self, node: Rule, rhs: Rhs) -> None: self.print("PyMem_Free(children);") self.print("return NULL;") self.print("}") - self.print("asdl_seq *seq = _Py_asdl_seq_new(n, p->arena);") + self.print("asdl_seq *seq = _Ta3_asdl_seq_new(n, p->arena);") self.out_of_memory_return( f"!seq", "NULL", @@ -540,7 +540,7 @@ def _handle_loop_rule_body(self, node: Rule, rhs: Rhs) -> None: self.print("for (int i = 0; i < n; i++) asdl_seq_SET(seq, i, children[i]);") self.print("PyMem_Free(children);") if node.name: - self.print(f"_PyPegen_insert_memo(p, start_mark, {node.name}_type, seq);") + self.print(f"_Ta3Pegen_insert_memo(p, start_mark, {node.name}_type, seq);") self.print("return seq;") def visit_Rule(self, node: Rule) -> None: @@ -619,7 +619,7 @@ def emit_default_action(self, is_gather: bool, node: Alt) -> None: if is_gather: assert len(self.local_variable_names) == 2 self.print( - f"res = _PyPegen_seq_insert_in_front(p, " + f"res = _Ta3Pegen_seq_insert_in_front(p, " f"{self.local_variable_names[0]}, {self.local_variable_names[1]});" ) else: @@ -628,7 +628,7 @@ def emit_default_action(self, is_gather: bool, node: Alt) -> None: f'fprintf(stderr, "Hit without action [%d:%d]: %s\\n", mark, p->mark, "{node}");' ) self.print( - f"res = _PyPegen_dummy_name(p, {', '.join(self.local_variable_names)});" + f"res = _Ta3Pegen_dummy_name(p, {', '.join(self.local_variable_names)});" ) else: if self.debug: @@ -638,7 +638,7 @@ def emit_default_action(self, is_gather: bool, node: Alt) -> None: self.print(f"res = {self.local_variable_names[0]};") def emit_dummy_action(self) -> None: - self.print(f"res = _PyPegen_dummy_name(p);") + self.print(f"res = _Ta3Pegen_dummy_name(p);") def handle_alt_normal(self, node: Alt, is_gather: bool) -> None: self.join_conditions(keyword="if", node=node) diff --git a/setup.py b/setup.py index 693be4d8..e62b7ca2 100644 --- a/setup.py +++ b/setup.py @@ -48,38 +48,29 @@ _ast3 = Extension( '_ast3', - include_dirs = ['ast3/Include'], + include_dirs = ['ast3/Include', 'ast3/Parser'], sources = [ - 'ast3/Parser/acceler.c', - 'ast3/Parser/bitset.c', - 'ast3/Parser/grammar.c', - 'ast3/Parser/grammar1.c', - 'ast3/Parser/node.c', - 'ast3/Parser/parser.c', - 'ast3/Parser/parsetok.c', - 'ast3/Parser/tokenizer.c', - 'ast3/Python/asdl.c', - 'ast3/Python/ast.c', - 'ast3/Python/graminit.c', 'ast3/Python/Python-ast.c', + 'ast3/Python/asdl.c', + 'ast3/Parser/tokenizer.c', + 'ast3/Parser/pegen/pegen.c', + 'ast3/Parser/pegen/peg_api.c', + 'ast3/Parser/pegen/parse_string.c', + 'ast3/Parser/pegen/parse.c', 'ast3/Custom/typed_ast.c', + 'ast3/Custom/ta3_compat.c', ], depends = [ 'ast3/Include/asdl.h', - 'ast3/Include/ast.h', - 'ast3/Include/bitset.h', - 'ast3/Include/compile-ast3.h', - 'ast3/Include/errcode.h', - 'ast3/Include/graminit.h', - 'ast3/Include/grammar.h', - 'ast3/Include/node.h', - 'ast3/Include/parsetok.h', - 'ast3/Include/pgenheaders.h', 'ast3/Include/Python-ast.h', 'ast3/Include/token.h', - 'ast3/Parser/parser.h', + 'ast3/Include/ta3_compat.h', + 'ast3/Parser/pegen/pegen.h', + 'ast3/Parser/pegen/parse_string.h', 'ast3/Parser/tokenizer.h', - ]) + ], + extra_compile_args=["-DPy_BUILD_CORE"] +) long_description = """ `typed_ast` is a Python 3 package that provides a Python 2.7 and Python 3 From a647bb459a90c17c35c1e6ae681bb122e5b391a2 Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Sun, 10 May 2020 03:41:30 -0700 Subject: [PATCH 6/7] Update typed_ast version --- typed_ast/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typed_ast/__init__.py b/typed_ast/__init__.py index bf256159..54ecc089 100644 --- a/typed_ast/__init__.py +++ b/typed_ast/__init__.py @@ -1 +1 @@ -__version__ = "1.4.1" +__version__ = "2.0.0a0" From 752e47eb9f106f94d19fecad8e27a2ec07dd19ad Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Sun, 10 May 2020 03:53:19 -0700 Subject: [PATCH 7/7] Fix small issue --- ast3/Parser/asdl_c.py | 2 +- ast3/Parser/tokenizer.h | 2 +- ast3/Python/Python-ast.c | 2 +- tools/asdl_c.patch | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ast3/Parser/asdl_c.py b/ast3/Parser/asdl_c.py index d5cf6051..2c2fe232 100755 --- a/ast3/Parser/asdl_c.py +++ b/ast3/Parser/asdl_c.py @@ -1424,7 +1424,7 @@ def main(srcfile, dump_module=False): f.write("PyObject *ast3_parse(PyObject *self, PyObject *args);\n") f.write("static PyMethodDef ast3_methods[] = {\n") f.write(' {"_parse", ast3_parse, METH_VARARGS, "Parse string into typed AST."},\n') - f.write(" {NULL, NULL, NULL}\n") + f.write(" {NULL, NULL, 0, NULL}\n") f.write("};\n") generate_module_def(f, mod) diff --git a/ast3/Parser/tokenizer.h b/ast3/Parser/tokenizer.h index a81b8c1b..a323d7b6 100644 --- a/ast3/Parser/tokenizer.h +++ b/ast3/Parser/tokenizer.h @@ -80,7 +80,7 @@ extern struct tok_state *Ta3Tokenizer_FromFile(FILE *, const char*, extern void Ta3Tokenizer_Free(struct tok_state *); extern int Ta3Tokenizer_Get(struct tok_state *, const char **, const char **); -#define tok_dump _Py_tok_dump +#define tok_dump _Ta3_tok_dump #ifdef __cplusplus } diff --git a/ast3/Python/Python-ast.c b/ast3/Python/Python-ast.c index 73a54b7a..911acb43 100644 --- a/ast3/Python/Python-ast.c +++ b/ast3/Python/Python-ast.c @@ -9,7 +9,7 @@ PyObject *ast3_parse(PyObject *self, PyObject *args); static PyMethodDef ast3_methods[] = { {"_parse", ast3_parse, METH_VARARGS, "Parse string into typed AST."}, - {NULL, NULL, NULL} + {NULL, NULL, 0, NULL} }; typedef struct { int initialized; diff --git a/tools/asdl_c.patch b/tools/asdl_c.patch index a14123cd..6521b4d8 100644 --- a/tools/asdl_c.patch +++ b/tools/asdl_c.patch @@ -187,7 +187,7 @@ index 59bf03e..adea54a 100755 + f.write("PyObject *ast3_parse(PyObject *self, PyObject *args);\n") + f.write("static PyMethodDef ast3_methods[] = {\n") + f.write(' {"_parse", ast3_parse, METH_VARARGS, "Parse string into typed AST."},\n') -+ f.write(" {NULL, NULL, NULL}\n") ++ f.write(" {NULL, NULL, 0, NULL}\n") + f.write("};\n") generate_module_def(f, mod)