diff --git a/Lib/dis.py b/Lib/dis.py index d63f35a42b2467..a045d18241b465 100644 --- a/Lib/dis.py +++ b/Lib/dis.py @@ -394,7 +394,7 @@ def _get_name_info(name_index, get_name, **extrainfo): else: return UNKNOWN, '' -def parse_varint(iterator): +def _parse_varint(iterator): b = next(iterator) val = b & 63 while b&64: @@ -403,16 +403,16 @@ def parse_varint(iterator): val |= b&63 return val -def parse_exception_table(code): +def _parse_exception_table(code): iterator = iter(code.co_exceptiontable) entries = [] try: while True: - start = parse_varint(iterator)*2 - length = parse_varint(iterator)*2 + start = _parse_varint(iterator)*2 + length = _parse_varint(iterator)*2 end = start + length - target = parse_varint(iterator)*2 - dl = parse_varint(iterator) + target = _parse_varint(iterator)*2 + dl = _parse_varint(iterator) depth = dl >> 1 lasti = bool(dl&1) entries.append(_ExceptionTableEntry(start, end, target, depth, lasti)) @@ -527,7 +527,7 @@ def _get_instructions_bytes(code, varname_from_oparg=None, def disassemble(co, lasti=-1, *, file=None, show_caches=False, adaptive=False): """Disassemble a code object.""" linestarts = dict(findlinestarts(co)) - exception_entries = parse_exception_table(co) + exception_entries = _parse_exception_table(co) _disassemble_bytes(_get_code_array(co, adaptive), lasti, co._varname_from_oparg, co.co_names, co.co_consts, linestarts, file=file, @@ -717,7 +717,7 @@ def __init__(self, x, *, first_line=None, current_offset=None, show_caches=False self._linestarts = dict(findlinestarts(co)) self._original_object = x self.current_offset = current_offset - self.exception_entries = parse_exception_table(co) + self.exception_entries = _parse_exception_table(co) self.show_caches = show_caches self.adaptive = adaptive diff --git a/Makefile.pre.in b/Makefile.pre.in index 20e66b80348683..89c83ffd40005b 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -346,8 +346,8 @@ PEGEN_OBJS= \ Parser/action_helpers.o \ Parser/parser.o \ Parser/string_parser.o \ - Parser/peg_api.o - + Parser/peg_api.o \ + Parser/vm.o PEGEN_HEADERS= \ $(srcdir)/Include/internal/pycore_parser.h \ @@ -355,7 +355,7 @@ PEGEN_HEADERS= \ $(srcdir)/Parser/string_parser.h POBJS= \ - Parser/token.o \ + Parser/token.o PARSER_OBJS= $(POBJS) $(PEGEN_OBJS) Parser/myreadline.o Parser/tokenizer.o @@ -1633,6 +1633,8 @@ PYTHON_HEADERS= \ $(LIBRARY_OBJS) $(MODOBJS) Programs/python.o: $(PYTHON_HEADERS) +$(srcdir)/Parser/vm.o: $(srcdir)/Parser/vm.h $(srcdir)/Parser/vmparse.h + ###################################################################### diff --git a/Parser/pegen.c b/Parser/pegen.c index dbf105aedcf427..2fb9b981c56f72 100644 --- a/Parser/pegen.c +++ b/Parser/pegen.c @@ -706,6 +706,9 @@ compute_parser_flags(PyCompilerFlags *flags) if (flags->cf_flags & PyCF_TYPE_COMMENTS) { parser_flags |= PyPARSE_TYPE_COMMENTS; } + if (flags->cf_flags & PyCF_VMPARSER) { + parser_flags |= PyPARSE_VMPARSER; + } if ((flags->cf_flags & PyCF_ONLY_AST) && flags->cf_feature_version < 7) { parser_flags |= PyPARSE_ASYNC_HACKS; } @@ -923,7 +926,12 @@ _PyPegen_run_parser_from_string(const char *str, int start_rule, PyObject *filen goto error; } - result = _PyPegen_run_parser(p); + if (parser_flags & PyPARSE_VMPARSER) { + result = _PyPegen_vmparser(p); + } + else { + result = _PyPegen_run_parser(p); + } _PyPegen_Parser_Free(p); error: diff --git a/Parser/pegen.h b/Parser/pegen.h index d8ac7e8cb918f7..edb60d488d7fba 100644 --- a/Parser/pegen.h +++ b/Parser/pegen.h @@ -23,8 +23,8 @@ #define PyPARSE_TYPE_COMMENTS 0x0040 #define PyPARSE_ASYNC_HACKS 0x0080 #define PyPARSE_ALLOW_INCOMPLETE_INPUT 0x0100 - #define CURRENT_POS (-5) +#define PyPARSE_VMPARSER 0x0100 typedef struct _memo { int type; @@ -284,6 +284,15 @@ INVALID_VERSION_CHECK(Parser *p, int version, char *msg, void *node) arg_ty _PyPegen_add_type_comment_to_arg(Parser *, arg_ty, Token *); PyObject *_PyPegen_new_identifier(Parser *, const 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 *); +void *_PyPegen_vmparser(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 *); diff --git a/Parser/vm.c b/Parser/vm.c new file mode 100644 index 00000000000000..0dff69b808d57b --- /dev/null +++ b/Parser/vm.c @@ -0,0 +1,319 @@ +#include +#include +#include "tokenizer.h" + +#include "pegen.h" +#include "string_parser.h" + +#include "vm.h" +#include "vmparse.h" // Generated parser tables + +#undef D +#define DEBUG 0 + +#if DEBUG +#define D(x) x +#else +#define D(x) +#endif + +#define MAXFRAMES 1000 + +typedef struct _stack { + Parser *p; + int top; + Frame frames[MAXFRAMES]; +} Stack; + +static inline Frame * +push_frame(Stack *stack, Rule *rule) +{ + D(printf(" push %s\n", rule->name)); + assert(stack->top < MAXFRAMES); + Frame *f = &stack->frames[stack->top++]; + f->rule = rule; + f->mark = stack->p->mark; + f->ialt = 0; + f->iop = 0; + f->cut = 0; + f->ncollected = 0; + f->capacity = 0; + f->collection = NULL; + f->ival = 0; + return f; +} + +static inline Frame * +pop_frame(Stack *stack, void *v) +{ + assert(stack->top > 1); + Frame *f = &stack->frames[--stack->top]; // Frame being popped + if (f->collection) { + PyMem_Free(f->collection); + } + if (f->rule->memo) { + D(printf(" insert memo %s: val=%p, mark=%d\n", f->rule->name, v, stack->p->mark)); + if (_PyPegen_insert_memo(stack->p, f->mark, f->rule->type + 1000, v) == -1) { + return NULL; + } + } + f = &stack->frames[stack->top - 1]; // New top of stack + D(printf(" pop %s\n", f->rule->name)); + return f; +} + +static inline asdl_seq * +make_asdl_seq(Parser *p, void *collection[], int ncollected) +{ + asdl_seq *seq = _Py_asdl_seq_new(ncollected, p->arena); + if (!seq) { + return NULL; + } + for (int i = 0; i < ncollected; i++) { + asdl_seq_SET(seq, i, collection[i]); + } + return seq; +} + +static void * +run_vm(Parser *p, Rule rules[], int root) +{ + Stack stack = {p, 0, {{0}}}; + Frame *f = push_frame(&stack, &rules[root]); + void *v; + int oparg; + int opc; + + top: + opc = f->rule->opcodes[f->iop]; + if (DEBUG) { + if (p->mark == p->fill) + _PyPegen_fill_token(p); + for (int i = 0; i < stack.top; i++) printf(" "); + printf("Rule: %s; ialt=%d; iop=%d; op=%s; arg=%d, mark=%d; token=%d; p^='%s'\n", + f->rule->name, f->ialt, f->iop, opcode_names[opc], + opc >= OP_TOKEN ? f->rule->opcodes[f->iop + 1] : -1, + p->mark, p->tokens[p->mark]->type, + p->fill > p-> mark ? PyBytes_AsString(p->tokens[p->mark]->bytes) : ""); + } + f->iop++; + switch (opc) { + case OP_NOOP: + goto top; + case OP_CUT: + f->cut = 1; + goto top; + case OP_OPTIONAL: + goto top; + + case OP_NAME: + v = _PyPegen_name_token(p); + break; + case OP_NUMBER: + v = _PyPegen_number_token(p); + break; + case OP_STRING: + v = _PyPegen_string_token(p); + break; + + case OP_LOOP_ITERATE: + f->mark = p->mark; + assert(f->ival == 1 || f->ival == 2); + v = f->vals[0]; + assert(v); + if (f->ncollected >= f->capacity) { + f->capacity = (f->ncollected + 1) * 2; // 2, 6, 14, 30, 62, ... (2**i - 2) + f->collection = PyMem_Realloc(f->collection, (f->capacity) * sizeof(void *)); + if (!f->collection) { + return PyErr_NoMemory(); + } + } + f->collection[f->ncollected++] = v; + f->iop = f->rule->alts[f->ialt]; + f->ival = 0; + goto top; + case OP_LOOP_COLLECT_DELIMITED: + /* Collect one item */ + assert(f->ival == 1); + if (f->ncollected >= f->capacity) { + f->capacity = f->ncollected + 1; // We know there won't be any more + f->collection = PyMem_Realloc(f->collection, (f->capacity) * sizeof(void *)); + if (!f->collection) { + return PyErr_NoMemory(); + } + } + f->collection[f->ncollected++] = v; + // Fallthrough! + case OP_LOOP_COLLECT_NONEMPTY: + if (!f->ncollected) { + D(printf(" Nothing collected for %s\n", f->rule->name)); + v = NULL; + f = pop_frame(&stack, v); + if (!f) { + return NULL; + } + break; + } + // Fallthrough! + case OP_LOOP_COLLECT: + v = make_asdl_seq(p, f->collection, f->ncollected); + if (!v) { + return PyErr_NoMemory(); + } + f = pop_frame(&stack, v); + if (!f) { + return NULL; + } + break; + + case OP_SAVE_MARK: + f->savemark = p->mark; + goto top; + case OP_POS_LOOKAHEAD: + assert(f->ival > 0); + f->ival--; /* Back out last added value */ + p->mark = f->savemark; + goto top; + case OP_NEG_LOOKAHEAD: + v = NULL; + break; + + case OP_SUCCESS: + v = f->vals[0]; + return v; + case OP_FAILURE: + return RAISE_SYNTAX_ERROR("A syntax error"); + + case OP_TOKEN: + oparg = f->rule->opcodes[f->iop++]; + v = _PyPegen_expect_token(p, oparg); + break; + case OP_SOFT_KEYWORD: + oparg = f->rule->opcodes[f->iop++]; + v = _PyPegen_expect_soft_keyword(p, soft_keywords[oparg]); + break; + case OP_RULE: + oparg = f->rule->opcodes[f->iop++]; + Rule *rule = &rules[oparg]; + if (rule->memo || rule->leftrec) { + v = NULL; // In case is_memoized ran into an error + int memo = _PyPegen_is_memoized(p, rule->type + 1000, &v); + if (memo) { + D(printf(" Memo hit %s\n", rule->name)); + // The result is v; if v != NULL, p->mark has been updated + break; + } + } + f = push_frame(&stack, rule); + if (rule->leftrec) { + D(printf(" leftrec %s prep: lastval=NULL, lastmark=%d\n", rule->name, f->mark)); + f->lastval = NULL; + f->lastmark = f->mark; + if (_PyPegen_insert_memo(p, f->mark, rule->type + 1000, NULL) == -1) { + return NULL; + } + } + goto top; + case OP_RETURN: + oparg = f->rule->opcodes[f->iop++]; + v = call_action(p, f, oparg); + if (v) { + if (f->rule->leftrec) { + D(printf(" leftrec %s check\n", f->rule->name)); + if (p->mark > f->lastmark) { // We improved, recurse again + D(printf(" leftrec improved: lastval=%p, lastmark=%d\n", v, p->mark)); + f->lastval = v; + f->lastmark = p->mark; + if (_PyPegen_update_memo(p, f->mark, f->rule->type + 1000, v) == -1) { + return NULL; + } + f->ialt = 0; + f->iop = 0; + f->ival = 0; + p->mark = f->mark; + goto top; + } + else { // End recursion + D(printf(" leftrec end: lastval=%p, lastmark=%d\n", f->lastval, f->lastmark)); + p->mark = f->lastmark; + v = f->lastval; + } + } + f = pop_frame(&stack, v); + if (!f) { + return NULL; + } + } + break; + + default: + printf("opc=%d\n", opc); + assert(0); + } + + ok: + if (v) { + D(printf(" OK\n")); + assert(f->ival < MAXVALS); + f->vals[f->ival++] = v; + goto top; + } + if (PyErr_Occurred()) { + D(printf(" PyErr\n")); + p->error_indicator = 1; + return NULL; + } + + fail: + opc = f->rule->opcodes[f->iop]; + if (opc == OP_OPTIONAL) { + D(printf(" OP_OPTIONAL\n")); + assert(f->ival < MAXVALS); + f->vals[f->ival++] = NULL; + f->iop++; // Skip over the OP_OPTIONAL opcode + goto top; + } + if (opc == OP_NEG_LOOKAHEAD) { + D(printf(" OP_NEG_LOOKAHEAD\n")); + p->mark = f->savemark; + f->iop++; // Skip over the OP_NEG_LOOKAHEAD opcode + goto top; + } + + D(printf(" alternative fails\n")); + p->mark = f->mark; + if (f->cut) + goto pop; + f->iop = f->rule->alts[++f->ialt]; + if (f->iop == -1) + goto pop; + f->ival = 0; + goto top; + + pop: + if (f->rule->leftrec) { + D(printf(" leftrec %s pop!! lastval=%p, lastmark=%d\n", f->rule->name, f->lastval, f->lastmark)); + v = f->lastval; + p->mark = f->lastmark; + if (v) { + D(printf(" leftrec pop okay\n")); + goto ok; + } + D(printf(" leftrec pop fail\n")); + } + + f = pop_frame(&stack, NULL); + if (!f) { + return NULL; + } + goto fail; +} + +void * +_PyPegen_vmparser(Parser *p) +{ + p->keywords = reserved_keywords; + p->n_keyword_lists = n_keyword_lists; + + return run_vm(p, all_rules, R_ROOT); +} diff --git a/Parser/vm.h b/Parser/vm.h new file mode 100644 index 00000000000000..8039e11961100e --- /dev/null +++ b/Parser/vm.h @@ -0,0 +1,75 @@ +typedef enum _opcodes { + OP_NOOP, + OP_CUT, + OP_OPTIONAL, + OP_NAME, + OP_NUMBER, + OP_STRING, + OP_LOOP_ITERATE, + OP_LOOP_COLLECT, + OP_LOOP_COLLECT_NONEMPTY, + OP_LOOP_COLLECT_DELIMITED, + OP_SAVE_MARK, + OP_POS_LOOKAHEAD, + OP_NEG_LOOKAHEAD, + OP_SUCCESS, + OP_FAILURE, + // The rest have an argument + OP_SOFT_KEYWORD, + OP_TOKEN, + OP_RULE, + OP_RETURN, +} Opcode; + +static char *opcode_names[] = { + "OP_NOOP", + "OP_CUT", + "OP_OPTIONAL", + "OP_NAME", + "OP_NUMBER", + "OP_STRING", + "OP_LOOP_ITERATE", + "OP_LOOP_COLLECT", + "OP_LOOP_COLLECT_NONEMPTY", + "OP_LOOP_COLLECT_DELIMITED", + "OP_SAVE_MARK", + "OP_POS_LOOKAHEAD", + "OP_NEG_LOOKAHEAD", + "OP_SUCCESS", + "OP_FAILURE", + // The rest have an argument + "OP_SOFT_KEYWORD", + "OP_TOKEN", + "OP_RULE", + "OP_RETURN", +}; + +#define MAXALTS 15 +#define MAXOPCODES 100 + +typedef struct _rule { + char *name; + short type; + short memo; // memoized rule (not left-recursive) + short leftrec; // left-recursive rule (needs memo lookup) + short alts[MAXALTS]; + short opcodes[MAXOPCODES]; +} Rule; + +#define MAXVALS 10 + +typedef struct _frame { + Rule *rule; + int mark; + int savemark; + int lastmark; + short ialt; + short iop; + short ival; + short cut; + int ncollected; + int capacity; + void *lastval; + void **collection; + void *vals[MAXVALS]; +} Frame; diff --git a/Parser/vmparse.h b/Parser/vmparse.h new file mode 100644 index 00000000000000..a36374255aa22a --- /dev/null +++ b/Parser/vmparse.h @@ -0,0 +1,7114 @@ +static const int n_keyword_lists = 9; +static KeywordToken *reserved_keywords[] = { + NULL, + NULL, + (KeywordToken[]) { + {"if", 510}, + {"in", 518}, + {"as", 520}, + {"is", 527}, + {"or", 531}, + {NULL, -1}, + }, + (KeywordToken[]) { + {"del", 503}, + {"try", 511}, + {"for", 517}, + {"def", 523}, + {"not", 526}, + {"and", 532}, + {NULL, -1}, + }, + (KeywordToken[]) { + {"pass", 502}, + {"from", 514}, + {"elif", 515}, + {"else", 516}, + {"with", 519}, + {"True", 528}, + {"None", 530}, + {NULL, -1}, + }, + (KeywordToken[]) { + {"raise", 501}, + {"yield", 504}, + {"break", 506}, + {"while", 512}, + {"class", 524}, + {"False", 529}, + {NULL, -1}, + }, + (KeywordToken[]) { + {"return", 500}, + {"assert", 505}, + {"global", 508}, + {"import", 513}, + {"except", 521}, + {"lambda", 525}, + {NULL, -1}, + }, + (KeywordToken[]) { + {"finally", 522}, + {NULL, -1}, + }, + (KeywordToken[]) { + {"continue", 507}, + {"nonlocal", 509}, + {NULL, -1}, + }, +}; + +static const char *soft_keywords[] = { +}; + +enum { + R_FILE, + R_INTERACTIVE, + R_EVAL, + R_FUNC_TYPE, + R_FSTRING, + R_TYPE_EXPRESSIONS, + R_STATEMENTS, + R_STATEMENT, + R_STATEMENT_NEWLINE, + R_SIMPLE_STMT, + R_SMALL_STMT, + R_COMPOUND_STMT, + R_ASSIGNMENT, + R_AUGASSIGN, + R_GLOBAL_STMT, + R_NONLOCAL_STMT, + R_YIELD_STMT, + R_ASSERT_STMT, + R_DEL_STMT, + R_IMPORT_STMT, + R_IMPORT_NAME, + R_IMPORT_FROM, + R_IMPORT_FROM_TARGETS, + R_IMPORT_FROM_AS_NAMES, + R_IMPORT_FROM_AS_NAME, + R_DOTTED_AS_NAMES, + R_DOTTED_AS_NAME, + R_DOTTED_NAME, + R_IF_STMT, + R_ELIF_STMT, + R_ELSE_BLOCK, + R_WHILE_STMT, + R_FOR_STMT, + R_WITH_STMT, + R_WITH_ITEM, + R_TRY_STMT, + R_EXCEPT_BLOCK, + R_FINALLY_BLOCK, + R_RETURN_STMT, + R_RAISE_STMT, + R_FUNCTION_DEF, + R_FUNCTION_DEF_RAW, + R_FUNC_TYPE_COMMENT, + R_PARAMS, + R_PARAMETERS, + R_SLASH_NO_DEFAULT, + R_SLASH_WITH_DEFAULT, + R_STAR_ETC, + R_KWDS, + R_PARAM_NO_DEFAULT, + R_PARAM_WITH_DEFAULT, + R_PARAM_MAYBE_DEFAULT, + R_PARAM, + R_ANNOTATION, + R_DEFAULT, + R_DECORATORS, + R_CLASS_DEF, + R_CLASS_DEF_RAW, + R_BLOCK, + R_EXPRESSIONS_LIST, + R_STAR_EXPRESSIONS, + R_STAR_EXPRESSION, + R_STAR_NAMED_EXPRESSIONS, + R_STAR_NAMED_EXPRESSION, + R_NAMED_EXPRESSION, + R_ANNOTATED_RHS, + R_EXPRESSIONS, + R_EXPRESSION, + R_LAMBDEF, + R_LAMBDA_PARAMS, + R_LAMBDA_PARAMETERS, + R_LAMBDA_SLASH_NO_DEFAULT, + R_LAMBDA_SLASH_WITH_DEFAULT, + R_LAMBDA_STAR_ETC, + R_LAMBDA_KWDS, + R_LAMBDA_PARAM_NO_DEFAULT, + R_LAMBDA_PARAM_WITH_DEFAULT, + R_LAMBDA_PARAM_MAYBE_DEFAULT, + R_LAMBDA_PARAM, + R_DISJUNCTION, + R_CONJUNCTION, + R_INVERSION, + R_COMPARISON, + R_COMPARE_OP_BITWISE_OR_PAIR, + R_EQ_BITWISE_OR, + R_NOTEQ_BITWISE_OR, + R_LTE_BITWISE_OR, + R_LT_BITWISE_OR, + R_GTE_BITWISE_OR, + R_GT_BITWISE_OR, + R_NOTIN_BITWISE_OR, + R_IN_BITWISE_OR, + R_ISNOT_BITWISE_OR, + R_IS_BITWISE_OR, + R_BITWISE_OR, + R_BITWISE_XOR, + R_BITWISE_AND, + R_SHIFT_EXPR, + R_SUM, + R_TERM, + R_FACTOR, + R_POWER, + R_AWAIT_PRIMARY, + R_PRIMARY, + R_SLICES, + R_SLICE, + R_ATOM, + R_STRINGS, + R_LIST, + R_LISTCOMP, + R_TUPLE, + R_GROUP, + R_GENEXP, + R_SET, + R_SETCOMP, + R_DICT, + R_DICTCOMP, + R_DOUBLE_STARRED_KVPAIRS, + R_DOUBLE_STARRED_KVPAIR, + R_KVPAIR, + R_FOR_IF_CLAUSES, + R_FOR_IF_CLAUSE, + R_YIELD_EXPR, + R_ARGUMENTS, + R_ARGS, + R_KWARGS, + R_STARRED_EXPRESSION, + R_KWARG_OR_STARRED, + R_KWARG_OR_DOUBLE_STARRED, + R_STAR_TARGETS, + R_STAR_TARGETS_SEQ, + R_STAR_TARGET, + R_STAR_ATOM, + R_SINGLE_TARGET, + R_SINGLE_SUBSCRIPT_ATTRIBUTE_TARGET, + R_DEL_TARGETS, + R_DEL_TARGET, + R_DEL_T_ATOM, + R_TARGETS, + R_TARGET, + R_T_PRIMARY, + R_T_LOOKAHEAD, + R_T_ATOM, + R_INCORRECT_ARGUMENTS, + R_INVALID_KWARG, + R_INVALID_NAMED_EXPRESSION, + R_INVALID_ASSIGNMENT, + R_INVALID_ANN_ASSIGN_TARGET, + R_INVALID_DEL_STMT, + R_INVALID_BLOCK, + R_INVALID_COMPREHENSION, + R_INVALID_DICT_COMPREHENSION, + R_INVALID_PARAMETERS, + R_INVALID_LAMBDA_PARAMETERS, + R_INVALID_STAR_ETC, + R_INVALID_LAMBDA_STAR_ETC, + R_INVALID_DOUBLE_TYPE_COMMENTS, + R_INVALID_WITH_ITEM, + R_INVALID_FOR_TARGET, + R_INVALID_GROUP, + R_INVALID_IMPORT_FROM_TARGETS, + R_ROOT, + R__LOOP0_1, + R__LOOP0_2, + R__GATHER_3, + R__GATHER_4, + R__GATHER_5, + R__GATHER_6, + R__LOOP1_7, + R__GATHER_8, + R__TMP_9, + R__TMP_10, + R__TMP_11, + R__TMP_12, + R__TMP_13, + R__TMP_14, + R__TMP_15, + R__TMP_16, + R__LOOP1_17, + R__TMP_18, + R__TMP_19, + R__GATHER_20, + R__GATHER_21, + R__TMP_22, + R__TMP_23, + R__LOOP0_24, + R__LOOP1_25, + R__GATHER_26, + R__TMP_27, + R__GATHER_28, + R__TMP_29, + R__GATHER_30, + R__GATHER_31, + R__GATHER_32, + R__GATHER_33, + R__TMP_34, + R__LOOP1_35, + R__TMP_36, + R__TMP_37, + R__TMP_38, + R__TMP_39, + R__TMP_40, + R__LOOP0_41, + R__LOOP0_42, + R__LOOP0_43, + R__LOOP1_44, + R__LOOP0_45, + R__LOOP1_46, + R__LOOP1_47, + R__LOOP1_48, + R__LOOP0_49, + R__LOOP1_50, + R__LOOP0_51, + R__LOOP1_52, + R__LOOP0_53, + R__LOOP1_54, + R__LOOP1_55, + R__TMP_56, + R__GATHER_57, + R__LOOP1_58, + R__GATHER_59, + R__LOOP1_60, + R__LOOP0_61, + R__LOOP0_62, + R__LOOP0_63, + R__LOOP1_64, + R__LOOP0_65, + R__LOOP1_66, + R__LOOP1_67, + R__LOOP1_68, + R__LOOP0_69, + R__LOOP1_70, + R__LOOP0_71, + R__LOOP1_72, + R__LOOP0_73, + R__LOOP1_74, + R__LOOP1_75, + R__LOOP1_76, + R__LOOP1_77, + R__TMP_78, + R__GATHER_79, + R__TMP_80, + R__TMP_81, + R__TMP_82, + R__TMP_83, + R__LOOP1_84, + R__TMP_85, + R__TMP_86, + R__GATHER_87, + R__LOOP1_88, + R__LOOP0_89, + R__LOOP0_90, + R__TMP_91, + R__TMP_92, + R__GATHER_93, + R__GATHER_94, + R__GATHER_95, + R__GATHER_96, + R__LOOP0_97, + R__GATHER_98, + R__TMP_99, + R__GATHER_100, + R__GATHER_101, + R__TMP_102, + R__LOOP0_103, + R__LOOP0_104, + R__LOOP0_105, + R__TMP_106, + R__TMP_107, + R__LOOP0_108, + R__TMP_109, + R__LOOP0_110, + R__TMP_111, + R__TMP_112, + R__TMP_113, + R__TMP_114, + R__TMP_115, + R__TMP_116, + R__TMP_117, + R__TMP_118, + R__TMP_119, + R__TMP_120, + R__TMP_121, + R__TMP_122, + R__TMP_123, + R__TMP_124, + R__TMP_125, + R__TMP_126, + R__LOOP1_127, + R__LOOP1_128, + R__TMP_129, + R__TMP_130, +}; + +enum { + A_FILE_0, + A_INTERACTIVE_0, + A_EVAL_0, + A_FUNC_TYPE_0, + A_FSTRING_0, + A_TYPE_EXPRESSIONS_0, + A_TYPE_EXPRESSIONS_1, + A_TYPE_EXPRESSIONS_2, + A_TYPE_EXPRESSIONS_3, + A_TYPE_EXPRESSIONS_4, + A_TYPE_EXPRESSIONS_5, + A_TYPE_EXPRESSIONS_6, + A_STATEMENTS_0, + A_STATEMENT_0, + A_STATEMENT_1, + A_STATEMENT_NEWLINE_0, + A_STATEMENT_NEWLINE_1, + A_STATEMENT_NEWLINE_2, + A_STATEMENT_NEWLINE_3, + A_SIMPLE_STMT_0, + A_SIMPLE_STMT_1, + A_SMALL_STMT_0, + A_SMALL_STMT_1, + A_SMALL_STMT_2, + A_SMALL_STMT_3, + A_SMALL_STMT_4, + A_SMALL_STMT_5, + A_SMALL_STMT_6, + A_SMALL_STMT_7, + A_SMALL_STMT_8, + A_SMALL_STMT_9, + A_SMALL_STMT_10, + A_SMALL_STMT_11, + A_SMALL_STMT_12, + A_COMPOUND_STMT_0, + A_COMPOUND_STMT_1, + A_COMPOUND_STMT_2, + A_COMPOUND_STMT_3, + A_COMPOUND_STMT_4, + A_COMPOUND_STMT_5, + A_COMPOUND_STMT_6, + A_ASSIGNMENT_0, + A_ASSIGNMENT_1, + A_ASSIGNMENT_2, + A_ASSIGNMENT_3, + A_ASSIGNMENT_4, + A_AUGASSIGN_0, + A_AUGASSIGN_1, + A_AUGASSIGN_2, + A_AUGASSIGN_3, + A_AUGASSIGN_4, + A_AUGASSIGN_5, + A_AUGASSIGN_6, + A_AUGASSIGN_7, + A_AUGASSIGN_8, + A_AUGASSIGN_9, + A_AUGASSIGN_10, + A_AUGASSIGN_11, + A_AUGASSIGN_12, + A_GLOBAL_STMT_0, + A_NONLOCAL_STMT_0, + A_YIELD_STMT_0, + A_ASSERT_STMT_0, + A_DEL_STMT_0, + A_DEL_STMT_1, + A_IMPORT_STMT_0, + A_IMPORT_STMT_1, + A_IMPORT_NAME_0, + A_IMPORT_FROM_0, + A_IMPORT_FROM_1, + A_IMPORT_FROM_TARGETS_0, + A_IMPORT_FROM_TARGETS_1, + A_IMPORT_FROM_TARGETS_2, + A_IMPORT_FROM_TARGETS_3, + A_IMPORT_FROM_AS_NAMES_0, + A_IMPORT_FROM_AS_NAME_0, + A_DOTTED_AS_NAMES_0, + A_DOTTED_AS_NAME_0, + A_DOTTED_NAME_0, + A_DOTTED_NAME_1, + A_IF_STMT_0, + A_IF_STMT_1, + A_ELIF_STMT_0, + A_ELIF_STMT_1, + A_ELSE_BLOCK_0, + A_WHILE_STMT_0, + A_FOR_STMT_0, + A_FOR_STMT_1, + A_FOR_STMT_2, + A_WITH_STMT_0, + A_WITH_STMT_1, + A_WITH_STMT_2, + A_WITH_STMT_3, + A_WITH_ITEM_0, + A_WITH_ITEM_1, + A_WITH_ITEM_2, + A_TRY_STMT_0, + A_TRY_STMT_1, + A_EXCEPT_BLOCK_0, + A_EXCEPT_BLOCK_1, + A_FINALLY_BLOCK_0, + A_RETURN_STMT_0, + A_RAISE_STMT_0, + A_RAISE_STMT_1, + A_FUNCTION_DEF_0, + A_FUNCTION_DEF_1, + A_FUNCTION_DEF_RAW_0, + A_FUNCTION_DEF_RAW_1, + A_FUNC_TYPE_COMMENT_0, + A_FUNC_TYPE_COMMENT_1, + A_FUNC_TYPE_COMMENT_2, + A_PARAMS_0, + A_PARAMS_1, + A_PARAMETERS_0, + A_PARAMETERS_1, + A_PARAMETERS_2, + A_PARAMETERS_3, + A_PARAMETERS_4, + A_SLASH_NO_DEFAULT_0, + A_SLASH_NO_DEFAULT_1, + A_SLASH_WITH_DEFAULT_0, + A_SLASH_WITH_DEFAULT_1, + A_STAR_ETC_0, + A_STAR_ETC_1, + A_STAR_ETC_2, + A_STAR_ETC_3, + A_KWDS_0, + A_PARAM_NO_DEFAULT_0, + A_PARAM_NO_DEFAULT_1, + A_PARAM_WITH_DEFAULT_0, + A_PARAM_WITH_DEFAULT_1, + A_PARAM_MAYBE_DEFAULT_0, + A_PARAM_MAYBE_DEFAULT_1, + A_PARAM_0, + A_ANNOTATION_0, + A_DEFAULT_0, + A_DECORATORS_0, + A_CLASS_DEF_0, + A_CLASS_DEF_1, + A_CLASS_DEF_RAW_0, + A_BLOCK_0, + A_BLOCK_1, + A_BLOCK_2, + A_EXPRESSIONS_LIST_0, + A_STAR_EXPRESSIONS_0, + A_STAR_EXPRESSIONS_1, + A_STAR_EXPRESSIONS_2, + A_STAR_EXPRESSION_0, + A_STAR_EXPRESSION_1, + A_STAR_NAMED_EXPRESSIONS_0, + A_STAR_NAMED_EXPRESSION_0, + A_STAR_NAMED_EXPRESSION_1, + A_NAMED_EXPRESSION_0, + A_NAMED_EXPRESSION_1, + A_NAMED_EXPRESSION_2, + A_ANNOTATED_RHS_0, + A_ANNOTATED_RHS_1, + A_EXPRESSIONS_0, + A_EXPRESSIONS_1, + A_EXPRESSIONS_2, + A_EXPRESSION_0, + A_EXPRESSION_1, + A_EXPRESSION_2, + A_LAMBDEF_0, + A_LAMBDA_PARAMS_0, + A_LAMBDA_PARAMS_1, + A_LAMBDA_PARAMETERS_0, + A_LAMBDA_PARAMETERS_1, + A_LAMBDA_PARAMETERS_2, + A_LAMBDA_PARAMETERS_3, + A_LAMBDA_PARAMETERS_4, + A_LAMBDA_SLASH_NO_DEFAULT_0, + A_LAMBDA_SLASH_NO_DEFAULT_1, + A_LAMBDA_SLASH_WITH_DEFAULT_0, + A_LAMBDA_SLASH_WITH_DEFAULT_1, + A_LAMBDA_STAR_ETC_0, + A_LAMBDA_STAR_ETC_1, + A_LAMBDA_STAR_ETC_2, + A_LAMBDA_STAR_ETC_3, + A_LAMBDA_KWDS_0, + A_LAMBDA_PARAM_NO_DEFAULT_0, + A_LAMBDA_PARAM_NO_DEFAULT_1, + A_LAMBDA_PARAM_WITH_DEFAULT_0, + A_LAMBDA_PARAM_WITH_DEFAULT_1, + A_LAMBDA_PARAM_MAYBE_DEFAULT_0, + A_LAMBDA_PARAM_MAYBE_DEFAULT_1, + A_LAMBDA_PARAM_0, + A_DISJUNCTION_0, + A_DISJUNCTION_1, + A_CONJUNCTION_0, + A_CONJUNCTION_1, + A_INVERSION_0, + A_INVERSION_1, + A_COMPARISON_0, + A_COMPARISON_1, + A_COMPARE_OP_BITWISE_OR_PAIR_0, + A_COMPARE_OP_BITWISE_OR_PAIR_1, + A_COMPARE_OP_BITWISE_OR_PAIR_2, + A_COMPARE_OP_BITWISE_OR_PAIR_3, + A_COMPARE_OP_BITWISE_OR_PAIR_4, + A_COMPARE_OP_BITWISE_OR_PAIR_5, + A_COMPARE_OP_BITWISE_OR_PAIR_6, + A_COMPARE_OP_BITWISE_OR_PAIR_7, + A_COMPARE_OP_BITWISE_OR_PAIR_8, + A_COMPARE_OP_BITWISE_OR_PAIR_9, + A_EQ_BITWISE_OR_0, + A_NOTEQ_BITWISE_OR_0, + A_LTE_BITWISE_OR_0, + A_LT_BITWISE_OR_0, + A_GTE_BITWISE_OR_0, + A_GT_BITWISE_OR_0, + A_NOTIN_BITWISE_OR_0, + A_IN_BITWISE_OR_0, + A_ISNOT_BITWISE_OR_0, + A_IS_BITWISE_OR_0, + A_BITWISE_OR_0, + A_BITWISE_OR_1, + A_BITWISE_XOR_0, + A_BITWISE_XOR_1, + A_BITWISE_AND_0, + A_BITWISE_AND_1, + A_SHIFT_EXPR_0, + A_SHIFT_EXPR_1, + A_SHIFT_EXPR_2, + A_SUM_0, + A_SUM_1, + A_SUM_2, + A_TERM_0, + A_TERM_1, + A_TERM_2, + A_TERM_3, + A_TERM_4, + A_TERM_5, + A_FACTOR_0, + A_FACTOR_1, + A_FACTOR_2, + A_FACTOR_3, + A_POWER_0, + A_POWER_1, + A_AWAIT_PRIMARY_0, + A_AWAIT_PRIMARY_1, + A_PRIMARY_0, + A_PRIMARY_1, + A_PRIMARY_2, + A_PRIMARY_3, + A_PRIMARY_4, + A_SLICES_0, + A_SLICES_1, + A_SLICE_0, + A_SLICE_1, + A_ATOM_0, + A_ATOM_1, + A_ATOM_2, + A_ATOM_3, + A_ATOM_4, + A_ATOM_5, + A_ATOM_6, + A_ATOM_7, + A_ATOM_8, + A_ATOM_9, + A_STRINGS_0, + A_LIST_0, + A_LISTCOMP_0, + A_LISTCOMP_1, + A_TUPLE_0, + A_GROUP_0, + A_GROUP_1, + A_GENEXP_0, + A_GENEXP_1, + A_SET_0, + A_SETCOMP_0, + A_SETCOMP_1, + A_DICT_0, + A_DICTCOMP_0, + A_DICTCOMP_1, + A_DOUBLE_STARRED_KVPAIRS_0, + A_DOUBLE_STARRED_KVPAIR_0, + A_DOUBLE_STARRED_KVPAIR_1, + A_KVPAIR_0, + A_FOR_IF_CLAUSES_0, + A_FOR_IF_CLAUSE_0, + A_FOR_IF_CLAUSE_1, + A_FOR_IF_CLAUSE_2, + A_YIELD_EXPR_0, + A_YIELD_EXPR_1, + A_ARGUMENTS_0, + A_ARGUMENTS_1, + A_ARGS_0, + A_ARGS_1, + A_ARGS_2, + A_KWARGS_0, + A_KWARGS_1, + A_KWARGS_2, + A_STARRED_EXPRESSION_0, + A_KWARG_OR_STARRED_0, + A_KWARG_OR_STARRED_1, + A_KWARG_OR_STARRED_2, + A_KWARG_OR_DOUBLE_STARRED_0, + A_KWARG_OR_DOUBLE_STARRED_1, + A_KWARG_OR_DOUBLE_STARRED_2, + A_STAR_TARGETS_0, + A_STAR_TARGETS_1, + A_STAR_TARGETS_SEQ_0, + A_STAR_TARGET_0, + A_STAR_TARGET_1, + A_STAR_TARGET_2, + A_STAR_TARGET_3, + A_STAR_ATOM_0, + A_STAR_ATOM_1, + A_STAR_ATOM_2, + A_STAR_ATOM_3, + A_SINGLE_TARGET_0, + A_SINGLE_TARGET_1, + A_SINGLE_TARGET_2, + A_SINGLE_SUBSCRIPT_ATTRIBUTE_TARGET_0, + A_SINGLE_SUBSCRIPT_ATTRIBUTE_TARGET_1, + A_DEL_TARGETS_0, + A_DEL_TARGET_0, + A_DEL_TARGET_1, + A_DEL_TARGET_2, + A_DEL_T_ATOM_0, + A_DEL_T_ATOM_1, + A_DEL_T_ATOM_2, + A_DEL_T_ATOM_3, + A_TARGETS_0, + A_TARGET_0, + A_TARGET_1, + A_TARGET_2, + A_T_PRIMARY_0, + A_T_PRIMARY_1, + A_T_PRIMARY_2, + A_T_PRIMARY_3, + A_T_PRIMARY_4, + A_T_LOOKAHEAD_0, + A_T_LOOKAHEAD_1, + A_T_LOOKAHEAD_2, + A_T_ATOM_0, + A_T_ATOM_1, + A_T_ATOM_2, + A_T_ATOM_3, + A_INCORRECT_ARGUMENTS_0, + A_INCORRECT_ARGUMENTS_1, + A_INCORRECT_ARGUMENTS_2, + A_INCORRECT_ARGUMENTS_3, + A_INCORRECT_ARGUMENTS_4, + A_INVALID_KWARG_0, + A_INVALID_NAMED_EXPRESSION_0, + A_INVALID_ASSIGNMENT_0, + A_INVALID_ASSIGNMENT_1, + A_INVALID_ASSIGNMENT_2, + A_INVALID_ASSIGNMENT_3, + A_INVALID_ASSIGNMENT_4, + A_INVALID_ASSIGNMENT_5, + A_INVALID_ANN_ASSIGN_TARGET_0, + A_INVALID_ANN_ASSIGN_TARGET_1, + A_INVALID_ANN_ASSIGN_TARGET_2, + A_INVALID_DEL_STMT_0, + A_INVALID_BLOCK_0, + A_INVALID_COMPREHENSION_0, + A_INVALID_DICT_COMPREHENSION_0, + A_INVALID_PARAMETERS_0, + A_INVALID_LAMBDA_PARAMETERS_0, + A_INVALID_STAR_ETC_0, + A_INVALID_STAR_ETC_1, + A_INVALID_LAMBDA_STAR_ETC_0, + A_INVALID_DOUBLE_TYPE_COMMENTS_0, + A_INVALID_WITH_ITEM_0, + A_INVALID_FOR_TARGET_0, + A_INVALID_GROUP_0, + A_INVALID_IMPORT_FROM_TARGETS_0, + A__GATHER_3_0, + A__GATHER_3_1, + A__GATHER_4_0, + A__GATHER_4_1, + A__GATHER_5_0, + A__GATHER_5_1, + A__GATHER_6_0, + A__GATHER_6_1, + A__GATHER_8_0, + A__GATHER_8_1, + A__TMP_9_0, + A__TMP_9_1, + A__TMP_10_0, + A__TMP_10_1, + A__TMP_10_2, + A__TMP_11_0, + A__TMP_11_1, + A__TMP_12_0, + A__TMP_12_1, + A__TMP_13_0, + A__TMP_13_1, + A__TMP_14_0, + A__TMP_15_0, + A__TMP_15_1, + A__TMP_16_0, + A__TMP_18_0, + A__TMP_18_1, + A__TMP_19_0, + A__TMP_19_1, + A__GATHER_20_0, + A__GATHER_20_1, + A__GATHER_21_0, + A__GATHER_21_1, + A__TMP_22_0, + A__TMP_23_0, + A__TMP_23_1, + A__GATHER_26_0, + A__GATHER_26_1, + A__TMP_27_0, + A__GATHER_28_0, + A__GATHER_28_1, + A__TMP_29_0, + A__GATHER_30_0, + A__GATHER_30_1, + A__GATHER_31_0, + A__GATHER_31_1, + A__GATHER_32_0, + A__GATHER_32_1, + A__GATHER_33_0, + A__GATHER_33_1, + A__TMP_34_0, + A__TMP_34_1, + A__TMP_34_2, + A__TMP_36_0, + A__TMP_37_0, + A__TMP_38_0, + A__TMP_39_0, + A__TMP_40_0, + A__TMP_56_0, + A__GATHER_57_0, + A__GATHER_57_1, + A__GATHER_59_0, + A__GATHER_59_1, + A__TMP_78_0, + A__GATHER_79_0, + A__GATHER_79_1, + A__TMP_80_0, + A__TMP_81_0, + A__TMP_81_1, + A__TMP_81_2, + A__TMP_82_0, + A__TMP_82_1, + A__TMP_83_0, + A__TMP_83_1, + A__TMP_83_2, + A__TMP_83_3, + A__TMP_85_0, + A__TMP_86_0, + A__TMP_86_1, + A__GATHER_87_0, + A__GATHER_87_1, + A__TMP_91_0, + A__TMP_92_0, + A__GATHER_93_0, + A__GATHER_93_1, + A__GATHER_94_0, + A__GATHER_94_1, + A__GATHER_95_0, + A__GATHER_95_1, + A__GATHER_96_0, + A__GATHER_96_1, + A__GATHER_98_0, + A__GATHER_98_1, + A__TMP_99_0, + A__GATHER_100_0, + A__GATHER_100_1, + A__GATHER_101_0, + A__GATHER_101_1, + A__TMP_102_0, + A__TMP_102_1, + A__TMP_106_0, + A__TMP_106_1, + A__TMP_107_0, + A__TMP_107_1, + A__TMP_107_2, + A__TMP_109_0, + A__TMP_109_1, + A__TMP_111_0, + A__TMP_111_1, + A__TMP_112_0, + A__TMP_112_1, + A__TMP_113_0, + A__TMP_113_1, + A__TMP_114_0, + A__TMP_115_0, + A__TMP_115_1, + A__TMP_116_0, + A__TMP_116_1, + A__TMP_117_0, + A__TMP_118_0, + A__TMP_119_0, + A__TMP_120_0, + A__TMP_121_0, + A__TMP_122_0, + A__TMP_123_0, + A__TMP_124_0, + A__TMP_125_0, + A__TMP_126_0, + A__TMP_129_0, + A__TMP_129_1, + A__TMP_130_0, + A__TMP_130_1, +}; + +static Rule all_rules[] = { + {"file", + R_FILE, + 0, // memo + 0, // leftrec + {0, -1}, + { + // statements? $ + OP_RULE, R_STATEMENTS, + OP_OPTIONAL, + OP_TOKEN, ENDMARKER, + OP_RETURN, A_FILE_0, + + }, + }, + {"interactive", + R_INTERACTIVE, + 0, // memo + 0, // leftrec + {0, -1}, + { + // statement_newline + OP_RULE, R_STATEMENT_NEWLINE, + OP_RETURN, A_INTERACTIVE_0, + + }, + }, + {"eval", + R_EVAL, + 0, // memo + 0, // leftrec + {0, -1}, + { + // expressions NEWLINE* $ + OP_RULE, R_EXPRESSIONS, + OP_RULE, R__LOOP0_1, + OP_TOKEN, ENDMARKER, + OP_RETURN, A_EVAL_0, + + }, + }, + {"func_type", + R_FUNC_TYPE, + 0, // memo + 0, // leftrec + {0, -1}, + { + // '(' type_expressions? ')' '->' expression NEWLINE* $ + OP_TOKEN, LPAR, + OP_RULE, R_TYPE_EXPRESSIONS, + OP_OPTIONAL, + OP_TOKEN, RPAR, + OP_TOKEN, RARROW, + OP_RULE, R_EXPRESSION, + OP_RULE, R__LOOP0_2, + OP_TOKEN, ENDMARKER, + OP_RETURN, A_FUNC_TYPE_0, + + }, + }, + {"fstring", + R_FSTRING, + 0, // memo + 0, // leftrec + {0, -1}, + { + // star_expressions + OP_RULE, R_STAR_EXPRESSIONS, + OP_RETURN, A_FSTRING_0, + + }, + }, + {"type_expressions", + R_TYPE_EXPRESSIONS, + 0, // memo + 0, // leftrec + {0, 16, 26, 36, 48, 54, 60, -1}, + { + // ','.expression+ ',' '*' expression ',' '**' expression + OP_RULE, R__GATHER_3, + OP_TOKEN, COMMA, + OP_TOKEN, STAR, + OP_RULE, R_EXPRESSION, + OP_TOKEN, COMMA, + OP_TOKEN, DOUBLESTAR, + OP_RULE, R_EXPRESSION, + OP_RETURN, A_TYPE_EXPRESSIONS_0, + + // ','.expression+ ',' '*' expression + OP_RULE, R__GATHER_4, + OP_TOKEN, COMMA, + OP_TOKEN, STAR, + OP_RULE, R_EXPRESSION, + OP_RETURN, A_TYPE_EXPRESSIONS_1, + + // ','.expression+ ',' '**' expression + OP_RULE, R__GATHER_5, + OP_TOKEN, COMMA, + OP_TOKEN, DOUBLESTAR, + OP_RULE, R_EXPRESSION, + OP_RETURN, A_TYPE_EXPRESSIONS_2, + + // '*' expression ',' '**' expression + OP_TOKEN, STAR, + OP_RULE, R_EXPRESSION, + OP_TOKEN, COMMA, + OP_TOKEN, DOUBLESTAR, + OP_RULE, R_EXPRESSION, + OP_RETURN, A_TYPE_EXPRESSIONS_3, + + // '*' expression + OP_TOKEN, STAR, + OP_RULE, R_EXPRESSION, + OP_RETURN, A_TYPE_EXPRESSIONS_4, + + // '**' expression + OP_TOKEN, DOUBLESTAR, + OP_RULE, R_EXPRESSION, + OP_RETURN, A_TYPE_EXPRESSIONS_5, + + // ','.expression+ + OP_RULE, R__GATHER_6, + OP_RETURN, A_TYPE_EXPRESSIONS_6, + + }, + }, + {"statements", + R_STATEMENTS, + 0, // memo + 0, // leftrec + {0, -1}, + { + // statement+ + OP_RULE, R__LOOP1_7, + OP_RETURN, A_STATEMENTS_0, + + }, + }, + {"statement", + R_STATEMENT, + 0, // memo + 0, // leftrec + {0, 4, -1}, + { + // compound_stmt + OP_RULE, R_COMPOUND_STMT, + OP_RETURN, A_STATEMENT_0, + + // simple_stmt + OP_RULE, R_SIMPLE_STMT, + OP_RETURN, A_STATEMENT_1, + + }, + }, + {"statement_newline", + R_STATEMENT_NEWLINE, + 0, // memo + 0, // leftrec + {0, 6, 10, 14, -1}, + { + // compound_stmt NEWLINE + OP_RULE, R_COMPOUND_STMT, + OP_TOKEN, NEWLINE, + OP_RETURN, A_STATEMENT_NEWLINE_0, + + // simple_stmt + OP_RULE, R_SIMPLE_STMT, + OP_RETURN, A_STATEMENT_NEWLINE_1, + + // NEWLINE + OP_TOKEN, NEWLINE, + OP_RETURN, A_STATEMENT_NEWLINE_2, + + // $ + OP_TOKEN, ENDMARKER, + OP_RETURN, A_STATEMENT_NEWLINE_3, + + }, + }, + {"simple_stmt", + R_SIMPLE_STMT, + 0, // memo + 0, // leftrec + {0, 10, -1}, + { + // small_stmt !';' NEWLINE + OP_RULE, R_SMALL_STMT, + OP_SAVE_MARK, + OP_TOKEN, SEMI, + OP_NEG_LOOKAHEAD, + OP_TOKEN, NEWLINE, + OP_RETURN, A_SIMPLE_STMT_0, + + // ';'.small_stmt+ ';'? NEWLINE + OP_RULE, R__GATHER_8, + OP_TOKEN, SEMI, + OP_OPTIONAL, + OP_TOKEN, NEWLINE, + OP_RETURN, A_SIMPLE_STMT_1, + + }, + }, + {"small_stmt", + R_SMALL_STMT, + 1, // memo + 0, // leftrec + {0, 4, 8, 16, 24, 32, 36, 44, 52, 60, 64, 68, 76, -1}, + { + // assignment + OP_RULE, R_ASSIGNMENT, + OP_RETURN, A_SMALL_STMT_0, + + // star_expressions + OP_RULE, R_STAR_EXPRESSIONS, + OP_RETURN, A_SMALL_STMT_1, + + // &'return' return_stmt + OP_SAVE_MARK, + OP_TOKEN, 500, + OP_POS_LOOKAHEAD, + OP_RULE, R_RETURN_STMT, + OP_RETURN, A_SMALL_STMT_2, + + // &('import' | 'from') import_stmt + OP_SAVE_MARK, + OP_RULE, R__TMP_9, + OP_POS_LOOKAHEAD, + OP_RULE, R_IMPORT_STMT, + OP_RETURN, A_SMALL_STMT_3, + + // &'raise' raise_stmt + OP_SAVE_MARK, + OP_TOKEN, 501, + OP_POS_LOOKAHEAD, + OP_RULE, R_RAISE_STMT, + OP_RETURN, A_SMALL_STMT_4, + + // 'pass' + OP_TOKEN, 502, + OP_RETURN, A_SMALL_STMT_5, + + // &'del' del_stmt + OP_SAVE_MARK, + OP_TOKEN, 503, + OP_POS_LOOKAHEAD, + OP_RULE, R_DEL_STMT, + OP_RETURN, A_SMALL_STMT_6, + + // &'yield' yield_stmt + OP_SAVE_MARK, + OP_TOKEN, 504, + OP_POS_LOOKAHEAD, + OP_RULE, R_YIELD_STMT, + OP_RETURN, A_SMALL_STMT_7, + + // &'assert' assert_stmt + OP_SAVE_MARK, + OP_TOKEN, 505, + OP_POS_LOOKAHEAD, + OP_RULE, R_ASSERT_STMT, + OP_RETURN, A_SMALL_STMT_8, + + // 'break' + OP_TOKEN, 506, + OP_RETURN, A_SMALL_STMT_9, + + // 'continue' + OP_TOKEN, 507, + OP_RETURN, A_SMALL_STMT_10, + + // &'global' global_stmt + OP_SAVE_MARK, + OP_TOKEN, 508, + OP_POS_LOOKAHEAD, + OP_RULE, R_GLOBAL_STMT, + OP_RETURN, A_SMALL_STMT_11, + + // &'nonlocal' nonlocal_stmt + OP_SAVE_MARK, + OP_TOKEN, 509, + OP_POS_LOOKAHEAD, + OP_RULE, R_NONLOCAL_STMT, + OP_RETURN, A_SMALL_STMT_12, + + }, + }, + {"compound_stmt", + R_COMPOUND_STMT, + 0, // memo + 0, // leftrec + {0, 8, 16, 24, 32, 40, 48, -1}, + { + // &('def' | '@' | ASYNC) function_def + OP_SAVE_MARK, + OP_RULE, R__TMP_10, + OP_POS_LOOKAHEAD, + OP_RULE, R_FUNCTION_DEF, + OP_RETURN, A_COMPOUND_STMT_0, + + // &'if' if_stmt + OP_SAVE_MARK, + OP_TOKEN, 510, + OP_POS_LOOKAHEAD, + OP_RULE, R_IF_STMT, + OP_RETURN, A_COMPOUND_STMT_1, + + // &('class' | '@') class_def + OP_SAVE_MARK, + OP_RULE, R__TMP_11, + OP_POS_LOOKAHEAD, + OP_RULE, R_CLASS_DEF, + OP_RETURN, A_COMPOUND_STMT_2, + + // &('with' | ASYNC) with_stmt + OP_SAVE_MARK, + OP_RULE, R__TMP_12, + OP_POS_LOOKAHEAD, + OP_RULE, R_WITH_STMT, + OP_RETURN, A_COMPOUND_STMT_3, + + // &('for' | ASYNC) for_stmt + OP_SAVE_MARK, + OP_RULE, R__TMP_13, + OP_POS_LOOKAHEAD, + OP_RULE, R_FOR_STMT, + OP_RETURN, A_COMPOUND_STMT_4, + + // &'try' try_stmt + OP_SAVE_MARK, + OP_TOKEN, 511, + OP_POS_LOOKAHEAD, + OP_RULE, R_TRY_STMT, + OP_RETURN, A_COMPOUND_STMT_5, + + // &'while' while_stmt + OP_SAVE_MARK, + OP_TOKEN, 512, + OP_POS_LOOKAHEAD, + OP_RULE, R_WHILE_STMT, + OP_RETURN, A_COMPOUND_STMT_6, + + }, + }, + {"assignment", + R_ASSIGNMENT, + 0, // memo + 0, // leftrec + {0, 10, 21, 34, 43, -1}, + { + // NAME ':' expression ['=' annotated_rhs] + OP_NAME, + OP_TOKEN, COLON, + OP_RULE, R_EXPRESSION, + OP_RULE, R__TMP_14, + OP_OPTIONAL, + OP_RETURN, A_ASSIGNMENT_0, + + // ('(' single_target ')' | single_subscript_attribute_target) ':' expression ['=' annotated_rhs] + OP_RULE, R__TMP_15, + OP_TOKEN, COLON, + OP_RULE, R_EXPRESSION, + OP_RULE, R__TMP_16, + OP_OPTIONAL, + OP_RETURN, A_ASSIGNMENT_1, + + // ((star_targets '='))+ (yield_expr | star_expressions) !'=' TYPE_COMMENT? + OP_RULE, R__LOOP1_17, + OP_RULE, R__TMP_18, + OP_SAVE_MARK, + OP_TOKEN, EQUAL, + OP_NEG_LOOKAHEAD, + OP_TOKEN, TYPE_COMMENT, + OP_OPTIONAL, + OP_RETURN, A_ASSIGNMENT_2, + + // single_target augassign ~ (yield_expr | star_expressions) + OP_RULE, R_SINGLE_TARGET, + OP_RULE, R_AUGASSIGN, + OP_CUT, + OP_RULE, R__TMP_19, + OP_RETURN, A_ASSIGNMENT_3, + + // invalid_assignment + OP_RULE, R_INVALID_ASSIGNMENT, + OP_RETURN, A_ASSIGNMENT_4, + + }, + }, + {"augassign", + R_AUGASSIGN, + 0, // memo + 0, // leftrec + {0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, -1}, + { + // '+=' + OP_TOKEN, PLUSEQUAL, + OP_RETURN, A_AUGASSIGN_0, + + // '-=' + OP_TOKEN, MINEQUAL, + OP_RETURN, A_AUGASSIGN_1, + + // '*=' + OP_TOKEN, STAREQUAL, + OP_RETURN, A_AUGASSIGN_2, + + // '@=' + OP_TOKEN, ATEQUAL, + OP_RETURN, A_AUGASSIGN_3, + + // '/=' + OP_TOKEN, SLASHEQUAL, + OP_RETURN, A_AUGASSIGN_4, + + // '%=' + OP_TOKEN, PERCENTEQUAL, + OP_RETURN, A_AUGASSIGN_5, + + // '&=' + OP_TOKEN, AMPEREQUAL, + OP_RETURN, A_AUGASSIGN_6, + + // '|=' + OP_TOKEN, VBAREQUAL, + OP_RETURN, A_AUGASSIGN_7, + + // '^=' + OP_TOKEN, CIRCUMFLEXEQUAL, + OP_RETURN, A_AUGASSIGN_8, + + // '<<=' + OP_TOKEN, LEFTSHIFTEQUAL, + OP_RETURN, A_AUGASSIGN_9, + + // '>>=' + OP_TOKEN, RIGHTSHIFTEQUAL, + OP_RETURN, A_AUGASSIGN_10, + + // '**=' + OP_TOKEN, DOUBLESTAREQUAL, + OP_RETURN, A_AUGASSIGN_11, + + // '//=' + OP_TOKEN, DOUBLESLASHEQUAL, + OP_RETURN, A_AUGASSIGN_12, + + }, + }, + {"global_stmt", + R_GLOBAL_STMT, + 0, // memo + 0, // leftrec + {0, -1}, + { + // 'global' ','.NAME+ + OP_TOKEN, 508, + OP_RULE, R__GATHER_20, + OP_RETURN, A_GLOBAL_STMT_0, + + }, + }, + {"nonlocal_stmt", + R_NONLOCAL_STMT, + 0, // memo + 0, // leftrec + {0, -1}, + { + // 'nonlocal' ','.NAME+ + OP_TOKEN, 509, + OP_RULE, R__GATHER_21, + OP_RETURN, A_NONLOCAL_STMT_0, + + }, + }, + {"yield_stmt", + R_YIELD_STMT, + 0, // memo + 0, // leftrec + {0, -1}, + { + // yield_expr + OP_RULE, R_YIELD_EXPR, + OP_RETURN, A_YIELD_STMT_0, + + }, + }, + {"assert_stmt", + R_ASSERT_STMT, + 0, // memo + 0, // leftrec + {0, -1}, + { + // 'assert' expression [',' expression] + OP_TOKEN, 505, + OP_RULE, R_EXPRESSION, + OP_RULE, R__TMP_22, + OP_OPTIONAL, + OP_RETURN, A_ASSERT_STMT_0, + + }, + }, + {"del_stmt", + R_DEL_STMT, + 0, // memo + 0, // leftrec + {0, 10, -1}, + { + // 'del' del_targets &(';' | NEWLINE) + OP_TOKEN, 503, + OP_RULE, R_DEL_TARGETS, + OP_SAVE_MARK, + OP_RULE, R__TMP_23, + OP_POS_LOOKAHEAD, + OP_RETURN, A_DEL_STMT_0, + + // invalid_del_stmt + OP_RULE, R_INVALID_DEL_STMT, + OP_RETURN, A_DEL_STMT_1, + + }, + }, + {"import_stmt", + R_IMPORT_STMT, + 0, // memo + 0, // leftrec + {0, 4, -1}, + { + // import_name + OP_RULE, R_IMPORT_NAME, + OP_RETURN, A_IMPORT_STMT_0, + + // import_from + OP_RULE, R_IMPORT_FROM, + OP_RETURN, A_IMPORT_STMT_1, + + }, + }, + {"import_name", + R_IMPORT_NAME, + 0, // memo + 0, // leftrec + {0, -1}, + { + // 'import' dotted_as_names + OP_TOKEN, 513, + OP_RULE, R_DOTTED_AS_NAMES, + OP_RETURN, A_IMPORT_NAME_0, + + }, + }, + {"import_from", + R_IMPORT_FROM, + 0, // memo + 0, // leftrec + {0, 12, -1}, + { + // 'from' (('.' | '...'))* dotted_name 'import' import_from_targets + OP_TOKEN, 514, + OP_RULE, R__LOOP0_24, + OP_RULE, R_DOTTED_NAME, + OP_TOKEN, 513, + OP_RULE, R_IMPORT_FROM_TARGETS, + OP_RETURN, A_IMPORT_FROM_0, + + // 'from' (('.' | '...'))+ 'import' import_from_targets + OP_TOKEN, 514, + OP_RULE, R__LOOP1_25, + OP_TOKEN, 513, + OP_RULE, R_IMPORT_FROM_TARGETS, + OP_RETURN, A_IMPORT_FROM_1, + + }, + }, + {"import_from_targets", + R_IMPORT_FROM_TARGETS, + 0, // memo + 0, // leftrec + {0, 11, 19, 23, -1}, + { + // '(' import_from_as_names ','? ')' + OP_TOKEN, LPAR, + OP_RULE, R_IMPORT_FROM_AS_NAMES, + OP_TOKEN, COMMA, + OP_OPTIONAL, + OP_TOKEN, RPAR, + OP_RETURN, A_IMPORT_FROM_TARGETS_0, + + // import_from_as_names !',' + OP_RULE, R_IMPORT_FROM_AS_NAMES, + OP_SAVE_MARK, + OP_TOKEN, COMMA, + OP_NEG_LOOKAHEAD, + OP_RETURN, A_IMPORT_FROM_TARGETS_1, + + // '*' + OP_TOKEN, STAR, + OP_RETURN, A_IMPORT_FROM_TARGETS_2, + + // invalid_import_from_targets + OP_RULE, R_INVALID_IMPORT_FROM_TARGETS, + OP_RETURN, A_IMPORT_FROM_TARGETS_3, + + }, + }, + {"import_from_as_names", + R_IMPORT_FROM_AS_NAMES, + 0, // memo + 0, // leftrec + {0, -1}, + { + // ','.import_from_as_name+ + OP_RULE, R__GATHER_26, + OP_RETURN, A_IMPORT_FROM_AS_NAMES_0, + + }, + }, + {"import_from_as_name", + R_IMPORT_FROM_AS_NAME, + 0, // memo + 0, // leftrec + {0, -1}, + { + // NAME ['as' NAME] + OP_NAME, + OP_RULE, R__TMP_27, + OP_OPTIONAL, + OP_RETURN, A_IMPORT_FROM_AS_NAME_0, + + }, + }, + {"dotted_as_names", + R_DOTTED_AS_NAMES, + 0, // memo + 0, // leftrec + {0, -1}, + { + // ','.dotted_as_name+ + OP_RULE, R__GATHER_28, + OP_RETURN, A_DOTTED_AS_NAMES_0, + + }, + }, + {"dotted_as_name", + R_DOTTED_AS_NAME, + 0, // memo + 0, // leftrec + {0, -1}, + { + // dotted_name ['as' NAME] + OP_RULE, R_DOTTED_NAME, + OP_RULE, R__TMP_29, + OP_OPTIONAL, + OP_RETURN, A_DOTTED_AS_NAME_0, + + }, + }, + {"dotted_name", + R_DOTTED_NAME, + 0, // memo + 1, // leftrec + {0, 7, -1}, + { + // dotted_name '.' NAME + OP_RULE, R_DOTTED_NAME, + OP_TOKEN, DOT, + OP_NAME, + OP_RETURN, A_DOTTED_NAME_0, + + // NAME + OP_NAME, + OP_RETURN, A_DOTTED_NAME_1, + + }, + }, + {"if_stmt", + R_IF_STMT, + 0, // memo + 0, // leftrec + {0, 12, -1}, + { + // 'if' named_expression ':' block elif_stmt + OP_TOKEN, 510, + OP_RULE, R_NAMED_EXPRESSION, + OP_TOKEN, COLON, + OP_RULE, R_BLOCK, + OP_RULE, R_ELIF_STMT, + OP_RETURN, A_IF_STMT_0, + + // 'if' named_expression ':' block else_block? + OP_TOKEN, 510, + OP_RULE, R_NAMED_EXPRESSION, + OP_TOKEN, COLON, + OP_RULE, R_BLOCK, + OP_RULE, R_ELSE_BLOCK, + OP_OPTIONAL, + OP_RETURN, A_IF_STMT_1, + + }, + }, + {"elif_stmt", + R_ELIF_STMT, + 0, // memo + 0, // leftrec + {0, 12, -1}, + { + // 'elif' named_expression ':' block elif_stmt + OP_TOKEN, 515, + OP_RULE, R_NAMED_EXPRESSION, + OP_TOKEN, COLON, + OP_RULE, R_BLOCK, + OP_RULE, R_ELIF_STMT, + OP_RETURN, A_ELIF_STMT_0, + + // 'elif' named_expression ':' block else_block? + OP_TOKEN, 515, + OP_RULE, R_NAMED_EXPRESSION, + OP_TOKEN, COLON, + OP_RULE, R_BLOCK, + OP_RULE, R_ELSE_BLOCK, + OP_OPTIONAL, + OP_RETURN, A_ELIF_STMT_1, + + }, + }, + {"else_block", + R_ELSE_BLOCK, + 0, // memo + 0, // leftrec + {0, -1}, + { + // 'else' ':' block + OP_TOKEN, 516, + OP_TOKEN, COLON, + OP_RULE, R_BLOCK, + OP_RETURN, A_ELSE_BLOCK_0, + + }, + }, + {"while_stmt", + R_WHILE_STMT, + 0, // memo + 0, // leftrec + {0, -1}, + { + // 'while' named_expression ':' block else_block? + OP_TOKEN, 512, + OP_RULE, R_NAMED_EXPRESSION, + OP_TOKEN, COLON, + OP_RULE, R_BLOCK, + OP_RULE, R_ELSE_BLOCK, + OP_OPTIONAL, + OP_RETURN, A_WHILE_STMT_0, + + }, + }, + {"for_stmt", + R_FOR_STMT, + 0, // memo + 0, // leftrec + {0, 21, 44, -1}, + { + // 'for' star_targets 'in' ~ star_expressions ':' TYPE_COMMENT? block else_block? + OP_TOKEN, 517, + OP_RULE, R_STAR_TARGETS, + OP_TOKEN, 518, + OP_CUT, + OP_RULE, R_STAR_EXPRESSIONS, + OP_TOKEN, COLON, + OP_TOKEN, TYPE_COMMENT, + OP_OPTIONAL, + OP_RULE, R_BLOCK, + OP_RULE, R_ELSE_BLOCK, + OP_OPTIONAL, + OP_RETURN, A_FOR_STMT_0, + + // ASYNC 'for' star_targets 'in' ~ star_expressions ':' TYPE_COMMENT? block else_block? + OP_TOKEN, ASYNC, + OP_TOKEN, 517, + OP_RULE, R_STAR_TARGETS, + OP_TOKEN, 518, + OP_CUT, + OP_RULE, R_STAR_EXPRESSIONS, + OP_TOKEN, COLON, + OP_TOKEN, TYPE_COMMENT, + OP_OPTIONAL, + OP_RULE, R_BLOCK, + OP_RULE, R_ELSE_BLOCK, + OP_OPTIONAL, + OP_RETURN, A_FOR_STMT_1, + + // invalid_for_target + OP_RULE, R_INVALID_FOR_TARGET, + OP_RETURN, A_FOR_STMT_2, + + }, + }, + {"with_stmt", + R_WITH_STMT, + 0, // memo + 0, // leftrec + {0, 17, 30, 49, -1}, + { + // 'with' '(' ','.with_item+ ','? ')' ':' block + OP_TOKEN, 519, + OP_TOKEN, LPAR, + OP_RULE, R__GATHER_30, + OP_TOKEN, COMMA, + OP_OPTIONAL, + OP_TOKEN, RPAR, + OP_TOKEN, COLON, + OP_RULE, R_BLOCK, + OP_RETURN, A_WITH_STMT_0, + + // 'with' ','.with_item+ ':' TYPE_COMMENT? block + OP_TOKEN, 519, + OP_RULE, R__GATHER_31, + OP_TOKEN, COLON, + OP_TOKEN, TYPE_COMMENT, + OP_OPTIONAL, + OP_RULE, R_BLOCK, + OP_RETURN, A_WITH_STMT_1, + + // ASYNC 'with' '(' ','.with_item+ ','? ')' ':' block + OP_TOKEN, ASYNC, + OP_TOKEN, 519, + OP_TOKEN, LPAR, + OP_RULE, R__GATHER_32, + OP_TOKEN, COMMA, + OP_OPTIONAL, + OP_TOKEN, RPAR, + OP_TOKEN, COLON, + OP_RULE, R_BLOCK, + OP_RETURN, A_WITH_STMT_2, + + // ASYNC 'with' ','.with_item+ ':' TYPE_COMMENT? block + OP_TOKEN, ASYNC, + OP_TOKEN, 519, + OP_RULE, R__GATHER_33, + OP_TOKEN, COLON, + OP_TOKEN, TYPE_COMMENT, + OP_OPTIONAL, + OP_RULE, R_BLOCK, + OP_RETURN, A_WITH_STMT_3, + + }, + }, + {"with_item", + R_WITH_ITEM, + 0, // memo + 0, // leftrec + {0, 12, 16, -1}, + { + // expression 'as' target &(',' | ')' | ':') + OP_RULE, R_EXPRESSION, + OP_TOKEN, 520, + OP_RULE, R_TARGET, + OP_SAVE_MARK, + OP_RULE, R__TMP_34, + OP_POS_LOOKAHEAD, + OP_RETURN, A_WITH_ITEM_0, + + // invalid_with_item + OP_RULE, R_INVALID_WITH_ITEM, + OP_RETURN, A_WITH_ITEM_1, + + // expression + OP_RULE, R_EXPRESSION, + OP_RETURN, A_WITH_ITEM_2, + + }, + }, + {"try_stmt", + R_TRY_STMT, + 0, // memo + 0, // leftrec + {0, 10, -1}, + { + // 'try' ':' block finally_block + OP_TOKEN, 511, + OP_TOKEN, COLON, + OP_RULE, R_BLOCK, + OP_RULE, R_FINALLY_BLOCK, + OP_RETURN, A_TRY_STMT_0, + + // 'try' ':' block except_block+ else_block? finally_block? + OP_TOKEN, 511, + OP_TOKEN, COLON, + OP_RULE, R_BLOCK, + OP_RULE, R__LOOP1_35, + OP_RULE, R_ELSE_BLOCK, + OP_OPTIONAL, + OP_RULE, R_FINALLY_BLOCK, + OP_OPTIONAL, + OP_RETURN, A_TRY_STMT_1, + + }, + }, + {"except_block", + R_EXCEPT_BLOCK, + 0, // memo + 0, // leftrec + {0, 13, -1}, + { + // 'except' expression ['as' NAME] ':' block + OP_TOKEN, 521, + OP_RULE, R_EXPRESSION, + OP_RULE, R__TMP_36, + OP_OPTIONAL, + OP_TOKEN, COLON, + OP_RULE, R_BLOCK, + OP_RETURN, A_EXCEPT_BLOCK_0, + + // 'except' ':' block + OP_TOKEN, 521, + OP_TOKEN, COLON, + OP_RULE, R_BLOCK, + OP_RETURN, A_EXCEPT_BLOCK_1, + + }, + }, + {"finally_block", + R_FINALLY_BLOCK, + 0, // memo + 0, // leftrec + {0, -1}, + { + // 'finally' ':' block + OP_TOKEN, 522, + OP_TOKEN, COLON, + OP_RULE, R_BLOCK, + OP_RETURN, A_FINALLY_BLOCK_0, + + }, + }, + {"return_stmt", + R_RETURN_STMT, + 0, // memo + 0, // leftrec + {0, -1}, + { + // 'return' star_expressions? + OP_TOKEN, 500, + OP_RULE, R_STAR_EXPRESSIONS, + OP_OPTIONAL, + OP_RETURN, A_RETURN_STMT_0, + + }, + }, + {"raise_stmt", + R_RAISE_STMT, + 0, // memo + 0, // leftrec + {0, 9, -1}, + { + // 'raise' expression ['from' expression] + OP_TOKEN, 501, + OP_RULE, R_EXPRESSION, + OP_RULE, R__TMP_37, + OP_OPTIONAL, + OP_RETURN, A_RAISE_STMT_0, + + // 'raise' + OP_TOKEN, 501, + OP_RETURN, A_RAISE_STMT_1, + + }, + }, + {"function_def", + R_FUNCTION_DEF, + 0, // memo + 0, // leftrec + {0, 6, -1}, + { + // decorators function_def_raw + OP_RULE, R_DECORATORS, + OP_RULE, R_FUNCTION_DEF_RAW, + OP_RETURN, A_FUNCTION_DEF_0, + + // function_def_raw + OP_RULE, R_FUNCTION_DEF_RAW, + OP_RETURN, A_FUNCTION_DEF_1, + + }, + }, + {"function_def_raw", + R_FUNCTION_DEF_RAW, + 0, // memo + 0, // leftrec + {0, 22, -1}, + { + // 'def' NAME '(' params? ')' ['->' expression] ':' func_type_comment? block + OP_TOKEN, 523, + OP_NAME, + OP_TOKEN, LPAR, + OP_RULE, R_PARAMS, + OP_OPTIONAL, + OP_TOKEN, RPAR, + OP_RULE, R__TMP_38, + OP_OPTIONAL, + OP_TOKEN, COLON, + OP_RULE, R_FUNC_TYPE_COMMENT, + OP_OPTIONAL, + OP_RULE, R_BLOCK, + OP_RETURN, A_FUNCTION_DEF_RAW_0, + + // ASYNC 'def' NAME '(' params? ')' ['->' expression] ':' func_type_comment? block + OP_TOKEN, ASYNC, + OP_TOKEN, 523, + OP_NAME, + OP_TOKEN, LPAR, + OP_RULE, R_PARAMS, + OP_OPTIONAL, + OP_TOKEN, RPAR, + OP_RULE, R__TMP_39, + OP_OPTIONAL, + OP_TOKEN, COLON, + OP_RULE, R_FUNC_TYPE_COMMENT, + OP_OPTIONAL, + OP_RULE, R_BLOCK, + OP_RETURN, A_FUNCTION_DEF_RAW_1, + + }, + }, + {"func_type_comment", + R_FUNC_TYPE_COMMENT, + 0, // memo + 0, // leftrec + {0, 10, 14, -1}, + { + // NEWLINE TYPE_COMMENT &(NEWLINE INDENT) + OP_TOKEN, NEWLINE, + OP_TOKEN, TYPE_COMMENT, + OP_SAVE_MARK, + OP_RULE, R__TMP_40, + OP_POS_LOOKAHEAD, + OP_RETURN, A_FUNC_TYPE_COMMENT_0, + + // invalid_double_type_comments + OP_RULE, R_INVALID_DOUBLE_TYPE_COMMENTS, + OP_RETURN, A_FUNC_TYPE_COMMENT_1, + + // TYPE_COMMENT + OP_TOKEN, TYPE_COMMENT, + OP_RETURN, A_FUNC_TYPE_COMMENT_2, + + }, + }, + {"params", + R_PARAMS, + 0, // memo + 0, // leftrec + {0, 4, -1}, + { + // invalid_parameters + OP_RULE, R_INVALID_PARAMETERS, + OP_RETURN, A_PARAMS_0, + + // parameters + OP_RULE, R_PARAMETERS, + OP_RETURN, A_PARAMS_1, + + }, + }, + {"parameters", + R_PARAMETERS, + 0, // memo + 0, // leftrec + {0, 11, 20, 29, 36, -1}, + { + // slash_no_default param_no_default* param_with_default* star_etc? + OP_RULE, R_SLASH_NO_DEFAULT, + OP_RULE, R__LOOP0_41, + OP_RULE, R__LOOP0_42, + OP_RULE, R_STAR_ETC, + OP_OPTIONAL, + OP_RETURN, A_PARAMETERS_0, + + // slash_with_default param_with_default* star_etc? + OP_RULE, R_SLASH_WITH_DEFAULT, + OP_RULE, R__LOOP0_43, + OP_RULE, R_STAR_ETC, + OP_OPTIONAL, + OP_RETURN, A_PARAMETERS_1, + + // param_no_default+ param_with_default* star_etc? + OP_RULE, R__LOOP1_44, + OP_RULE, R__LOOP0_45, + OP_RULE, R_STAR_ETC, + OP_OPTIONAL, + OP_RETURN, A_PARAMETERS_2, + + // param_with_default+ star_etc? + OP_RULE, R__LOOP1_46, + OP_RULE, R_STAR_ETC, + OP_OPTIONAL, + OP_RETURN, A_PARAMETERS_3, + + // star_etc + OP_RULE, R_STAR_ETC, + OP_RETURN, A_PARAMETERS_4, + + }, + }, + {"slash_no_default", + R_SLASH_NO_DEFAULT, + 0, // memo + 0, // leftrec + {0, 8, -1}, + { + // param_no_default+ '/' ',' + OP_RULE, R__LOOP1_47, + OP_TOKEN, SLASH, + OP_TOKEN, COMMA, + OP_RETURN, A_SLASH_NO_DEFAULT_0, + + // param_no_default+ '/' &')' + OP_RULE, R__LOOP1_48, + OP_TOKEN, SLASH, + OP_SAVE_MARK, + OP_TOKEN, RPAR, + OP_POS_LOOKAHEAD, + OP_RETURN, A_SLASH_NO_DEFAULT_1, + + }, + }, + {"slash_with_default", + R_SLASH_WITH_DEFAULT, + 0, // memo + 0, // leftrec + {0, 10, -1}, + { + // param_no_default* param_with_default+ '/' ',' + OP_RULE, R__LOOP0_49, + OP_RULE, R__LOOP1_50, + OP_TOKEN, SLASH, + OP_TOKEN, COMMA, + OP_RETURN, A_SLASH_WITH_DEFAULT_0, + + // param_no_default* param_with_default+ '/' &')' + OP_RULE, R__LOOP0_51, + OP_RULE, R__LOOP1_52, + OP_TOKEN, SLASH, + OP_SAVE_MARK, + OP_TOKEN, RPAR, + OP_POS_LOOKAHEAD, + OP_RETURN, A_SLASH_WITH_DEFAULT_1, + + }, + }, + {"star_etc", + R_STAR_ETC, + 0, // memo + 0, // leftrec + {0, 11, 22, 26, -1}, + { + // '*' param_no_default param_maybe_default* kwds? + OP_TOKEN, STAR, + OP_RULE, R_PARAM_NO_DEFAULT, + OP_RULE, R__LOOP0_53, + OP_RULE, R_KWDS, + OP_OPTIONAL, + OP_RETURN, A_STAR_ETC_0, + + // '*' ',' param_maybe_default+ kwds? + OP_TOKEN, STAR, + OP_TOKEN, COMMA, + OP_RULE, R__LOOP1_54, + OP_RULE, R_KWDS, + OP_OPTIONAL, + OP_RETURN, A_STAR_ETC_1, + + // kwds + OP_RULE, R_KWDS, + OP_RETURN, A_STAR_ETC_2, + + // invalid_star_etc + OP_RULE, R_INVALID_STAR_ETC, + OP_RETURN, A_STAR_ETC_3, + + }, + }, + {"kwds", + R_KWDS, + 0, // memo + 0, // leftrec + {0, -1}, + { + // '**' param_no_default + OP_TOKEN, DOUBLESTAR, + OP_RULE, R_PARAM_NO_DEFAULT, + OP_RETURN, A_KWDS_0, + + }, + }, + {"param_no_default", + R_PARAM_NO_DEFAULT, + 0, // memo + 0, // leftrec + {0, 9, -1}, + { + // param ',' TYPE_COMMENT? + OP_RULE, R_PARAM, + OP_TOKEN, COMMA, + OP_TOKEN, TYPE_COMMENT, + OP_OPTIONAL, + OP_RETURN, A_PARAM_NO_DEFAULT_0, + + // param TYPE_COMMENT? &')' + OP_RULE, R_PARAM, + OP_TOKEN, TYPE_COMMENT, + OP_OPTIONAL, + OP_SAVE_MARK, + OP_TOKEN, RPAR, + OP_POS_LOOKAHEAD, + OP_RETURN, A_PARAM_NO_DEFAULT_1, + + }, + }, + {"param_with_default", + R_PARAM_WITH_DEFAULT, + 0, // memo + 0, // leftrec + {0, 11, -1}, + { + // param default ',' TYPE_COMMENT? + OP_RULE, R_PARAM, + OP_RULE, R_DEFAULT, + OP_TOKEN, COMMA, + OP_TOKEN, TYPE_COMMENT, + OP_OPTIONAL, + OP_RETURN, A_PARAM_WITH_DEFAULT_0, + + // param default TYPE_COMMENT? &')' + OP_RULE, R_PARAM, + OP_RULE, R_DEFAULT, + OP_TOKEN, TYPE_COMMENT, + OP_OPTIONAL, + OP_SAVE_MARK, + OP_TOKEN, RPAR, + OP_POS_LOOKAHEAD, + OP_RETURN, A_PARAM_WITH_DEFAULT_1, + + }, + }, + {"param_maybe_default", + R_PARAM_MAYBE_DEFAULT, + 0, // memo + 0, // leftrec + {0, 12, -1}, + { + // param default? ',' TYPE_COMMENT? + OP_RULE, R_PARAM, + OP_RULE, R_DEFAULT, + OP_OPTIONAL, + OP_TOKEN, COMMA, + OP_TOKEN, TYPE_COMMENT, + OP_OPTIONAL, + OP_RETURN, A_PARAM_MAYBE_DEFAULT_0, + + // param default? TYPE_COMMENT? &')' + OP_RULE, R_PARAM, + OP_RULE, R_DEFAULT, + OP_OPTIONAL, + OP_TOKEN, TYPE_COMMENT, + OP_OPTIONAL, + OP_SAVE_MARK, + OP_TOKEN, RPAR, + OP_POS_LOOKAHEAD, + OP_RETURN, A_PARAM_MAYBE_DEFAULT_1, + + }, + }, + {"param", + R_PARAM, + 0, // memo + 0, // leftrec + {0, -1}, + { + // NAME annotation? + OP_NAME, + OP_RULE, R_ANNOTATION, + OP_OPTIONAL, + OP_RETURN, A_PARAM_0, + + }, + }, + {"annotation", + R_ANNOTATION, + 0, // memo + 0, // leftrec + {0, -1}, + { + // ':' expression + OP_TOKEN, COLON, + OP_RULE, R_EXPRESSION, + OP_RETURN, A_ANNOTATION_0, + + }, + }, + {"default", + R_DEFAULT, + 0, // memo + 0, // leftrec + {0, -1}, + { + // '=' expression + OP_TOKEN, EQUAL, + OP_RULE, R_EXPRESSION, + OP_RETURN, A_DEFAULT_0, + + }, + }, + {"decorators", + R_DECORATORS, + 0, // memo + 0, // leftrec + {0, -1}, + { + // (('@' named_expression NEWLINE))+ + OP_RULE, R__LOOP1_55, + OP_RETURN, A_DECORATORS_0, + + }, + }, + {"class_def", + R_CLASS_DEF, + 0, // memo + 0, // leftrec + {0, 6, -1}, + { + // decorators class_def_raw + OP_RULE, R_DECORATORS, + OP_RULE, R_CLASS_DEF_RAW, + OP_RETURN, A_CLASS_DEF_0, + + // class_def_raw + OP_RULE, R_CLASS_DEF_RAW, + OP_RETURN, A_CLASS_DEF_1, + + }, + }, + {"class_def_raw", + R_CLASS_DEF_RAW, + 0, // memo + 0, // leftrec + {0, -1}, + { + // 'class' NAME ['(' arguments? ')'] ':' block + OP_TOKEN, 524, + OP_NAME, + OP_RULE, R__TMP_56, + OP_OPTIONAL, + OP_TOKEN, COLON, + OP_RULE, R_BLOCK, + OP_RETURN, A_CLASS_DEF_RAW_0, + + }, + }, + {"block", + R_BLOCK, + 1, // memo + 0, // leftrec + {0, 10, 14, -1}, + { + // NEWLINE INDENT statements DEDENT + OP_TOKEN, NEWLINE, + OP_TOKEN, INDENT, + OP_RULE, R_STATEMENTS, + OP_TOKEN, DEDENT, + OP_RETURN, A_BLOCK_0, + + // simple_stmt + OP_RULE, R_SIMPLE_STMT, + OP_RETURN, A_BLOCK_1, + + // invalid_block + OP_RULE, R_INVALID_BLOCK, + OP_RETURN, A_BLOCK_2, + + }, + }, + {"expressions_list", + R_EXPRESSIONS_LIST, + 0, // memo + 0, // leftrec + {0, -1}, + { + // ','.star_expression+ ','? + OP_RULE, R__GATHER_57, + OP_TOKEN, COMMA, + OP_OPTIONAL, + OP_RETURN, A_EXPRESSIONS_LIST_0, + + }, + }, + {"star_expressions", + R_STAR_EXPRESSIONS, + 0, // memo + 0, // leftrec + {0, 9, 15, -1}, + { + // star_expression ((',' star_expression))+ ','? + OP_RULE, R_STAR_EXPRESSION, + OP_RULE, R__LOOP1_58, + OP_TOKEN, COMMA, + OP_OPTIONAL, + OP_RETURN, A_STAR_EXPRESSIONS_0, + + // star_expression ',' + OP_RULE, R_STAR_EXPRESSION, + OP_TOKEN, COMMA, + OP_RETURN, A_STAR_EXPRESSIONS_1, + + // star_expression + OP_RULE, R_STAR_EXPRESSION, + OP_RETURN, A_STAR_EXPRESSIONS_2, + + }, + }, + {"star_expression", + R_STAR_EXPRESSION, + 1, // memo + 0, // leftrec + {0, 6, -1}, + { + // '*' bitwise_or + OP_TOKEN, STAR, + OP_RULE, R_BITWISE_OR, + OP_RETURN, A_STAR_EXPRESSION_0, + + // expression + OP_RULE, R_EXPRESSION, + OP_RETURN, A_STAR_EXPRESSION_1, + + }, + }, + {"star_named_expressions", + R_STAR_NAMED_EXPRESSIONS, + 0, // memo + 0, // leftrec + {0, -1}, + { + // ','.star_named_expression+ ','? + OP_RULE, R__GATHER_59, + OP_TOKEN, COMMA, + OP_OPTIONAL, + OP_RETURN, A_STAR_NAMED_EXPRESSIONS_0, + + }, + }, + {"star_named_expression", + R_STAR_NAMED_EXPRESSION, + 0, // memo + 0, // leftrec + {0, 6, -1}, + { + // '*' bitwise_or + OP_TOKEN, STAR, + OP_RULE, R_BITWISE_OR, + OP_RETURN, A_STAR_NAMED_EXPRESSION_0, + + // named_expression + OP_RULE, R_NAMED_EXPRESSION, + OP_RETURN, A_STAR_NAMED_EXPRESSION_1, + + }, + }, + {"named_expression", + R_NAMED_EXPRESSION, + 0, // memo + 0, // leftrec + {0, 8, 16, -1}, + { + // NAME ':=' ~ expression + OP_NAME, + OP_TOKEN, COLONEQUAL, + OP_CUT, + OP_RULE, R_EXPRESSION, + OP_RETURN, A_NAMED_EXPRESSION_0, + + // expression !':=' + OP_RULE, R_EXPRESSION, + OP_SAVE_MARK, + OP_TOKEN, COLONEQUAL, + OP_NEG_LOOKAHEAD, + OP_RETURN, A_NAMED_EXPRESSION_1, + + // invalid_named_expression + OP_RULE, R_INVALID_NAMED_EXPRESSION, + OP_RETURN, A_NAMED_EXPRESSION_2, + + }, + }, + {"annotated_rhs", + R_ANNOTATED_RHS, + 0, // memo + 0, // leftrec + {0, 4, -1}, + { + // yield_expr + OP_RULE, R_YIELD_EXPR, + OP_RETURN, A_ANNOTATED_RHS_0, + + // star_expressions + OP_RULE, R_STAR_EXPRESSIONS, + OP_RETURN, A_ANNOTATED_RHS_1, + + }, + }, + {"expressions", + R_EXPRESSIONS, + 0, // memo + 0, // leftrec + {0, 9, 15, -1}, + { + // expression ((',' expression))+ ','? + OP_RULE, R_EXPRESSION, + OP_RULE, R__LOOP1_60, + OP_TOKEN, COMMA, + OP_OPTIONAL, + OP_RETURN, A_EXPRESSIONS_0, + + // expression ',' + OP_RULE, R_EXPRESSION, + OP_TOKEN, COMMA, + OP_RETURN, A_EXPRESSIONS_1, + + // expression + OP_RULE, R_EXPRESSION, + OP_RETURN, A_EXPRESSIONS_2, + + }, + }, + {"expression", + R_EXPRESSION, + 1, // memo + 0, // leftrec + {0, 12, 16, -1}, + { + // disjunction 'if' disjunction 'else' expression + OP_RULE, R_DISJUNCTION, + OP_TOKEN, 510, + OP_RULE, R_DISJUNCTION, + OP_TOKEN, 516, + OP_RULE, R_EXPRESSION, + OP_RETURN, A_EXPRESSION_0, + + // disjunction + OP_RULE, R_DISJUNCTION, + OP_RETURN, A_EXPRESSION_1, + + // lambdef + OP_RULE, R_LAMBDEF, + OP_RETURN, A_EXPRESSION_2, + + }, + }, + {"lambdef", + R_LAMBDEF, + 0, // memo + 0, // leftrec + {0, -1}, + { + // 'lambda' lambda_params? ':' expression + OP_TOKEN, 525, + OP_RULE, R_LAMBDA_PARAMS, + OP_OPTIONAL, + OP_TOKEN, COLON, + OP_RULE, R_EXPRESSION, + OP_RETURN, A_LAMBDEF_0, + + }, + }, + {"lambda_params", + R_LAMBDA_PARAMS, + 0, // memo + 0, // leftrec + {0, 4, -1}, + { + // invalid_lambda_parameters + OP_RULE, R_INVALID_LAMBDA_PARAMETERS, + OP_RETURN, A_LAMBDA_PARAMS_0, + + // lambda_parameters + OP_RULE, R_LAMBDA_PARAMETERS, + OP_RETURN, A_LAMBDA_PARAMS_1, + + }, + }, + {"lambda_parameters", + R_LAMBDA_PARAMETERS, + 0, // memo + 0, // leftrec + {0, 11, 20, 29, 36, -1}, + { + // lambda_slash_no_default lambda_param_no_default* lambda_param_with_default* lambda_star_etc? + OP_RULE, R_LAMBDA_SLASH_NO_DEFAULT, + OP_RULE, R__LOOP0_61, + OP_RULE, R__LOOP0_62, + OP_RULE, R_LAMBDA_STAR_ETC, + OP_OPTIONAL, + OP_RETURN, A_LAMBDA_PARAMETERS_0, + + // lambda_slash_with_default lambda_param_with_default* lambda_star_etc? + OP_RULE, R_LAMBDA_SLASH_WITH_DEFAULT, + OP_RULE, R__LOOP0_63, + OP_RULE, R_LAMBDA_STAR_ETC, + OP_OPTIONAL, + OP_RETURN, A_LAMBDA_PARAMETERS_1, + + // lambda_param_no_default+ lambda_param_with_default* lambda_star_etc? + OP_RULE, R__LOOP1_64, + OP_RULE, R__LOOP0_65, + OP_RULE, R_LAMBDA_STAR_ETC, + OP_OPTIONAL, + OP_RETURN, A_LAMBDA_PARAMETERS_2, + + // lambda_param_with_default+ lambda_star_etc? + OP_RULE, R__LOOP1_66, + OP_RULE, R_LAMBDA_STAR_ETC, + OP_OPTIONAL, + OP_RETURN, A_LAMBDA_PARAMETERS_3, + + // lambda_star_etc + OP_RULE, R_LAMBDA_STAR_ETC, + OP_RETURN, A_LAMBDA_PARAMETERS_4, + + }, + }, + {"lambda_slash_no_default", + R_LAMBDA_SLASH_NO_DEFAULT, + 0, // memo + 0, // leftrec + {0, 8, -1}, + { + // lambda_param_no_default+ '/' ',' + OP_RULE, R__LOOP1_67, + OP_TOKEN, SLASH, + OP_TOKEN, COMMA, + OP_RETURN, A_LAMBDA_SLASH_NO_DEFAULT_0, + + // lambda_param_no_default+ '/' &':' + OP_RULE, R__LOOP1_68, + OP_TOKEN, SLASH, + OP_SAVE_MARK, + OP_TOKEN, COLON, + OP_POS_LOOKAHEAD, + OP_RETURN, A_LAMBDA_SLASH_NO_DEFAULT_1, + + }, + }, + {"lambda_slash_with_default", + R_LAMBDA_SLASH_WITH_DEFAULT, + 0, // memo + 0, // leftrec + {0, 10, -1}, + { + // lambda_param_no_default* lambda_param_with_default+ '/' ',' + OP_RULE, R__LOOP0_69, + OP_RULE, R__LOOP1_70, + OP_TOKEN, SLASH, + OP_TOKEN, COMMA, + OP_RETURN, A_LAMBDA_SLASH_WITH_DEFAULT_0, + + // lambda_param_no_default* lambda_param_with_default+ '/' &':' + OP_RULE, R__LOOP0_71, + OP_RULE, R__LOOP1_72, + OP_TOKEN, SLASH, + OP_SAVE_MARK, + OP_TOKEN, COLON, + OP_POS_LOOKAHEAD, + OP_RETURN, A_LAMBDA_SLASH_WITH_DEFAULT_1, + + }, + }, + {"lambda_star_etc", + R_LAMBDA_STAR_ETC, + 0, // memo + 0, // leftrec + {0, 11, 22, 26, -1}, + { + // '*' lambda_param_no_default lambda_param_maybe_default* lambda_kwds? + OP_TOKEN, STAR, + OP_RULE, R_LAMBDA_PARAM_NO_DEFAULT, + OP_RULE, R__LOOP0_73, + OP_RULE, R_LAMBDA_KWDS, + OP_OPTIONAL, + OP_RETURN, A_LAMBDA_STAR_ETC_0, + + // '*' ',' lambda_param_maybe_default+ lambda_kwds? + OP_TOKEN, STAR, + OP_TOKEN, COMMA, + OP_RULE, R__LOOP1_74, + OP_RULE, R_LAMBDA_KWDS, + OP_OPTIONAL, + OP_RETURN, A_LAMBDA_STAR_ETC_1, + + // lambda_kwds + OP_RULE, R_LAMBDA_KWDS, + OP_RETURN, A_LAMBDA_STAR_ETC_2, + + // invalid_lambda_star_etc + OP_RULE, R_INVALID_LAMBDA_STAR_ETC, + OP_RETURN, A_LAMBDA_STAR_ETC_3, + + }, + }, + {"lambda_kwds", + R_LAMBDA_KWDS, + 0, // memo + 0, // leftrec + {0, -1}, + { + // '**' lambda_param_no_default + OP_TOKEN, DOUBLESTAR, + OP_RULE, R_LAMBDA_PARAM_NO_DEFAULT, + OP_RETURN, A_LAMBDA_KWDS_0, + + }, + }, + {"lambda_param_no_default", + R_LAMBDA_PARAM_NO_DEFAULT, + 0, // memo + 0, // leftrec + {0, 6, -1}, + { + // lambda_param ',' + OP_RULE, R_LAMBDA_PARAM, + OP_TOKEN, COMMA, + OP_RETURN, A_LAMBDA_PARAM_NO_DEFAULT_0, + + // lambda_param &':' + OP_RULE, R_LAMBDA_PARAM, + OP_SAVE_MARK, + OP_TOKEN, COLON, + OP_POS_LOOKAHEAD, + OP_RETURN, A_LAMBDA_PARAM_NO_DEFAULT_1, + + }, + }, + {"lambda_param_with_default", + R_LAMBDA_PARAM_WITH_DEFAULT, + 0, // memo + 0, // leftrec + {0, 8, -1}, + { + // lambda_param default ',' + OP_RULE, R_LAMBDA_PARAM, + OP_RULE, R_DEFAULT, + OP_TOKEN, COMMA, + OP_RETURN, A_LAMBDA_PARAM_WITH_DEFAULT_0, + + // lambda_param default &':' + OP_RULE, R_LAMBDA_PARAM, + OP_RULE, R_DEFAULT, + OP_SAVE_MARK, + OP_TOKEN, COLON, + OP_POS_LOOKAHEAD, + OP_RETURN, A_LAMBDA_PARAM_WITH_DEFAULT_1, + + }, + }, + {"lambda_param_maybe_default", + R_LAMBDA_PARAM_MAYBE_DEFAULT, + 0, // memo + 0, // leftrec + {0, 9, -1}, + { + // lambda_param default? ',' + OP_RULE, R_LAMBDA_PARAM, + OP_RULE, R_DEFAULT, + OP_OPTIONAL, + OP_TOKEN, COMMA, + OP_RETURN, A_LAMBDA_PARAM_MAYBE_DEFAULT_0, + + // lambda_param default? &':' + OP_RULE, R_LAMBDA_PARAM, + OP_RULE, R_DEFAULT, + OP_OPTIONAL, + OP_SAVE_MARK, + OP_TOKEN, COLON, + OP_POS_LOOKAHEAD, + OP_RETURN, A_LAMBDA_PARAM_MAYBE_DEFAULT_1, + + }, + }, + {"lambda_param", + R_LAMBDA_PARAM, + 0, // memo + 0, // leftrec + {0, -1}, + { + // NAME + OP_NAME, + OP_RETURN, A_LAMBDA_PARAM_0, + + }, + }, + {"disjunction", + R_DISJUNCTION, + 1, // memo + 0, // leftrec + {0, 6, -1}, + { + // conjunction (('or' conjunction))+ + OP_RULE, R_CONJUNCTION, + OP_RULE, R__LOOP1_75, + OP_RETURN, A_DISJUNCTION_0, + + // conjunction + OP_RULE, R_CONJUNCTION, + OP_RETURN, A_DISJUNCTION_1, + + }, + }, + {"conjunction", + R_CONJUNCTION, + 1, // memo + 0, // leftrec + {0, 6, -1}, + { + // inversion (('and' inversion))+ + OP_RULE, R_INVERSION, + OP_RULE, R__LOOP1_76, + OP_RETURN, A_CONJUNCTION_0, + + // inversion + OP_RULE, R_INVERSION, + OP_RETURN, A_CONJUNCTION_1, + + }, + }, + {"inversion", + R_INVERSION, + 1, // memo + 0, // leftrec + {0, 6, -1}, + { + // 'not' inversion + OP_TOKEN, 526, + OP_RULE, R_INVERSION, + OP_RETURN, A_INVERSION_0, + + // comparison + OP_RULE, R_COMPARISON, + OP_RETURN, A_INVERSION_1, + + }, + }, + {"comparison", + R_COMPARISON, + 0, // memo + 0, // leftrec + {0, 6, -1}, + { + // bitwise_or compare_op_bitwise_or_pair+ + OP_RULE, R_BITWISE_OR, + OP_RULE, R__LOOP1_77, + OP_RETURN, A_COMPARISON_0, + + // bitwise_or + OP_RULE, R_BITWISE_OR, + OP_RETURN, A_COMPARISON_1, + + }, + }, + {"compare_op_bitwise_or_pair", + R_COMPARE_OP_BITWISE_OR_PAIR, + 0, // memo + 0, // leftrec + {0, 4, 8, 12, 16, 20, 24, 28, 32, 36, -1}, + { + // eq_bitwise_or + OP_RULE, R_EQ_BITWISE_OR, + OP_RETURN, A_COMPARE_OP_BITWISE_OR_PAIR_0, + + // noteq_bitwise_or + OP_RULE, R_NOTEQ_BITWISE_OR, + OP_RETURN, A_COMPARE_OP_BITWISE_OR_PAIR_1, + + // lte_bitwise_or + OP_RULE, R_LTE_BITWISE_OR, + OP_RETURN, A_COMPARE_OP_BITWISE_OR_PAIR_2, + + // lt_bitwise_or + OP_RULE, R_LT_BITWISE_OR, + OP_RETURN, A_COMPARE_OP_BITWISE_OR_PAIR_3, + + // gte_bitwise_or + OP_RULE, R_GTE_BITWISE_OR, + OP_RETURN, A_COMPARE_OP_BITWISE_OR_PAIR_4, + + // gt_bitwise_or + OP_RULE, R_GT_BITWISE_OR, + OP_RETURN, A_COMPARE_OP_BITWISE_OR_PAIR_5, + + // notin_bitwise_or + OP_RULE, R_NOTIN_BITWISE_OR, + OP_RETURN, A_COMPARE_OP_BITWISE_OR_PAIR_6, + + // in_bitwise_or + OP_RULE, R_IN_BITWISE_OR, + OP_RETURN, A_COMPARE_OP_BITWISE_OR_PAIR_7, + + // isnot_bitwise_or + OP_RULE, R_ISNOT_BITWISE_OR, + OP_RETURN, A_COMPARE_OP_BITWISE_OR_PAIR_8, + + // is_bitwise_or + OP_RULE, R_IS_BITWISE_OR, + OP_RETURN, A_COMPARE_OP_BITWISE_OR_PAIR_9, + + }, + }, + {"eq_bitwise_or", + R_EQ_BITWISE_OR, + 0, // memo + 0, // leftrec + {0, -1}, + { + // '==' bitwise_or + OP_TOKEN, EQEQUAL, + OP_RULE, R_BITWISE_OR, + OP_RETURN, A_EQ_BITWISE_OR_0, + + }, + }, + {"noteq_bitwise_or", + R_NOTEQ_BITWISE_OR, + 0, // memo + 0, // leftrec + {0, -1}, + { + // ('!=') bitwise_or + OP_RULE, R__TMP_78, + OP_RULE, R_BITWISE_OR, + OP_RETURN, A_NOTEQ_BITWISE_OR_0, + + }, + }, + {"lte_bitwise_or", + R_LTE_BITWISE_OR, + 0, // memo + 0, // leftrec + {0, -1}, + { + // '<=' bitwise_or + OP_TOKEN, LESSEQUAL, + OP_RULE, R_BITWISE_OR, + OP_RETURN, A_LTE_BITWISE_OR_0, + + }, + }, + {"lt_bitwise_or", + R_LT_BITWISE_OR, + 0, // memo + 0, // leftrec + {0, -1}, + { + // '<' bitwise_or + OP_TOKEN, LESS, + OP_RULE, R_BITWISE_OR, + OP_RETURN, A_LT_BITWISE_OR_0, + + }, + }, + {"gte_bitwise_or", + R_GTE_BITWISE_OR, + 0, // memo + 0, // leftrec + {0, -1}, + { + // '>=' bitwise_or + OP_TOKEN, GREATEREQUAL, + OP_RULE, R_BITWISE_OR, + OP_RETURN, A_GTE_BITWISE_OR_0, + + }, + }, + {"gt_bitwise_or", + R_GT_BITWISE_OR, + 0, // memo + 0, // leftrec + {0, -1}, + { + // '>' bitwise_or + OP_TOKEN, GREATER, + OP_RULE, R_BITWISE_OR, + OP_RETURN, A_GT_BITWISE_OR_0, + + }, + }, + {"notin_bitwise_or", + R_NOTIN_BITWISE_OR, + 0, // memo + 0, // leftrec + {0, -1}, + { + // 'not' 'in' bitwise_or + OP_TOKEN, 526, + OP_TOKEN, 518, + OP_RULE, R_BITWISE_OR, + OP_RETURN, A_NOTIN_BITWISE_OR_0, + + }, + }, + {"in_bitwise_or", + R_IN_BITWISE_OR, + 0, // memo + 0, // leftrec + {0, -1}, + { + // 'in' bitwise_or + OP_TOKEN, 518, + OP_RULE, R_BITWISE_OR, + OP_RETURN, A_IN_BITWISE_OR_0, + + }, + }, + {"isnot_bitwise_or", + R_ISNOT_BITWISE_OR, + 0, // memo + 0, // leftrec + {0, -1}, + { + // 'is' 'not' bitwise_or + OP_TOKEN, 527, + OP_TOKEN, 526, + OP_RULE, R_BITWISE_OR, + OP_RETURN, A_ISNOT_BITWISE_OR_0, + + }, + }, + {"is_bitwise_or", + R_IS_BITWISE_OR, + 0, // memo + 0, // leftrec + {0, -1}, + { + // 'is' bitwise_or + OP_TOKEN, 527, + OP_RULE, R_BITWISE_OR, + OP_RETURN, A_IS_BITWISE_OR_0, + + }, + }, + {"bitwise_or", + R_BITWISE_OR, + 0, // memo + 1, // leftrec + {0, 8, -1}, + { + // bitwise_or '|' bitwise_xor + OP_RULE, R_BITWISE_OR, + OP_TOKEN, VBAR, + OP_RULE, R_BITWISE_XOR, + OP_RETURN, A_BITWISE_OR_0, + + // bitwise_xor + OP_RULE, R_BITWISE_XOR, + OP_RETURN, A_BITWISE_OR_1, + + }, + }, + {"bitwise_xor", + R_BITWISE_XOR, + 0, // memo + 1, // leftrec + {0, 8, -1}, + { + // bitwise_xor '^' bitwise_and + OP_RULE, R_BITWISE_XOR, + OP_TOKEN, CIRCUMFLEX, + OP_RULE, R_BITWISE_AND, + OP_RETURN, A_BITWISE_XOR_0, + + // bitwise_and + OP_RULE, R_BITWISE_AND, + OP_RETURN, A_BITWISE_XOR_1, + + }, + }, + {"bitwise_and", + R_BITWISE_AND, + 0, // memo + 1, // leftrec + {0, 8, -1}, + { + // bitwise_and '&' shift_expr + OP_RULE, R_BITWISE_AND, + OP_TOKEN, AMPER, + OP_RULE, R_SHIFT_EXPR, + OP_RETURN, A_BITWISE_AND_0, + + // shift_expr + OP_RULE, R_SHIFT_EXPR, + OP_RETURN, A_BITWISE_AND_1, + + }, + }, + {"shift_expr", + R_SHIFT_EXPR, + 0, // memo + 1, // leftrec + {0, 8, 16, -1}, + { + // shift_expr '<<' sum + OP_RULE, R_SHIFT_EXPR, + OP_TOKEN, LEFTSHIFT, + OP_RULE, R_SUM, + OP_RETURN, A_SHIFT_EXPR_0, + + // shift_expr '>>' sum + OP_RULE, R_SHIFT_EXPR, + OP_TOKEN, RIGHTSHIFT, + OP_RULE, R_SUM, + OP_RETURN, A_SHIFT_EXPR_1, + + // sum + OP_RULE, R_SUM, + OP_RETURN, A_SHIFT_EXPR_2, + + }, + }, + {"sum", + R_SUM, + 0, // memo + 1, // leftrec + {0, 8, 16, -1}, + { + // sum '+' term + OP_RULE, R_SUM, + OP_TOKEN, PLUS, + OP_RULE, R_TERM, + OP_RETURN, A_SUM_0, + + // sum '-' term + OP_RULE, R_SUM, + OP_TOKEN, MINUS, + OP_RULE, R_TERM, + OP_RETURN, A_SUM_1, + + // term + OP_RULE, R_TERM, + OP_RETURN, A_SUM_2, + + }, + }, + {"term", + R_TERM, + 0, // memo + 1, // leftrec + {0, 8, 16, 24, 32, 40, -1}, + { + // term '*' factor + OP_RULE, R_TERM, + OP_TOKEN, STAR, + OP_RULE, R_FACTOR, + OP_RETURN, A_TERM_0, + + // term '/' factor + OP_RULE, R_TERM, + OP_TOKEN, SLASH, + OP_RULE, R_FACTOR, + OP_RETURN, A_TERM_1, + + // term '//' factor + OP_RULE, R_TERM, + OP_TOKEN, DOUBLESLASH, + OP_RULE, R_FACTOR, + OP_RETURN, A_TERM_2, + + // term '%' factor + OP_RULE, R_TERM, + OP_TOKEN, PERCENT, + OP_RULE, R_FACTOR, + OP_RETURN, A_TERM_3, + + // term '@' factor + OP_RULE, R_TERM, + OP_TOKEN, AT, + OP_RULE, R_FACTOR, + OP_RETURN, A_TERM_4, + + // factor + OP_RULE, R_FACTOR, + OP_RETURN, A_TERM_5, + + }, + }, + {"factor", + R_FACTOR, + 1, // memo + 0, // leftrec + {0, 6, 12, 18, -1}, + { + // '+' factor + OP_TOKEN, PLUS, + OP_RULE, R_FACTOR, + OP_RETURN, A_FACTOR_0, + + // '-' factor + OP_TOKEN, MINUS, + OP_RULE, R_FACTOR, + OP_RETURN, A_FACTOR_1, + + // '~' factor + OP_TOKEN, TILDE, + OP_RULE, R_FACTOR, + OP_RETURN, A_FACTOR_2, + + // power + OP_RULE, R_POWER, + OP_RETURN, A_FACTOR_3, + + }, + }, + {"power", + R_POWER, + 0, // memo + 0, // leftrec + {0, 8, -1}, + { + // await_primary '**' factor + OP_RULE, R_AWAIT_PRIMARY, + OP_TOKEN, DOUBLESTAR, + OP_RULE, R_FACTOR, + OP_RETURN, A_POWER_0, + + // await_primary + OP_RULE, R_AWAIT_PRIMARY, + OP_RETURN, A_POWER_1, + + }, + }, + {"await_primary", + R_AWAIT_PRIMARY, + 1, // memo + 0, // leftrec + {0, 6, -1}, + { + // AWAIT primary + OP_TOKEN, AWAIT, + OP_RULE, R_PRIMARY, + OP_RETURN, A_AWAIT_PRIMARY_0, + + // primary + OP_RULE, R_PRIMARY, + OP_RETURN, A_AWAIT_PRIMARY_1, + + }, + }, + {"primary", + R_PRIMARY, + 0, // memo + 1, // leftrec + {0, 7, 13, 24, 34, -1}, + { + // primary '.' NAME + OP_RULE, R_PRIMARY, + OP_TOKEN, DOT, + OP_NAME, + OP_RETURN, A_PRIMARY_0, + + // primary genexp + OP_RULE, R_PRIMARY, + OP_RULE, R_GENEXP, + OP_RETURN, A_PRIMARY_1, + + // primary '(' arguments? ')' + OP_RULE, R_PRIMARY, + OP_TOKEN, LPAR, + OP_RULE, R_ARGUMENTS, + OP_OPTIONAL, + OP_TOKEN, RPAR, + OP_RETURN, A_PRIMARY_2, + + // primary '[' slices ']' + OP_RULE, R_PRIMARY, + OP_TOKEN, LSQB, + OP_RULE, R_SLICES, + OP_TOKEN, RSQB, + OP_RETURN, A_PRIMARY_3, + + // atom + OP_RULE, R_ATOM, + OP_RETURN, A_PRIMARY_4, + + }, + }, + {"slices", + R_SLICES, + 0, // memo + 0, // leftrec + {0, 8, -1}, + { + // slice !',' + OP_RULE, R_SLICE, + OP_SAVE_MARK, + OP_TOKEN, COMMA, + OP_NEG_LOOKAHEAD, + OP_RETURN, A_SLICES_0, + + // ','.slice+ ','? + OP_RULE, R__GATHER_79, + OP_TOKEN, COMMA, + OP_OPTIONAL, + OP_RETURN, A_SLICES_1, + + }, + }, + {"slice", + R_SLICE, + 0, // memo + 0, // leftrec + {0, 13, -1}, + { + // expression? ':' expression? [':' expression?] + OP_RULE, R_EXPRESSION, + OP_OPTIONAL, + OP_TOKEN, COLON, + OP_RULE, R_EXPRESSION, + OP_OPTIONAL, + OP_RULE, R__TMP_80, + OP_OPTIONAL, + OP_RETURN, A_SLICE_0, + + // expression + OP_RULE, R_EXPRESSION, + OP_RETURN, A_SLICE_1, + + }, + }, + {"atom", + R_ATOM, + 0, // memo + 0, // leftrec + {0, 3, 7, 11, 15, 22, 25, 33, 41, 49, -1}, + { + // NAME + OP_NAME, + OP_RETURN, A_ATOM_0, + + // 'True' + OP_TOKEN, 528, + OP_RETURN, A_ATOM_1, + + // 'False' + OP_TOKEN, 529, + OP_RETURN, A_ATOM_2, + + // 'None' + OP_TOKEN, 530, + OP_RETURN, A_ATOM_3, + + // &STRING strings + OP_SAVE_MARK, + OP_STRING, + OP_POS_LOOKAHEAD, + OP_RULE, R_STRINGS, + OP_RETURN, A_ATOM_4, + + // NUMBER + OP_NUMBER, + OP_RETURN, A_ATOM_5, + + // &'(' (tuple | group | genexp) + OP_SAVE_MARK, + OP_TOKEN, LPAR, + OP_POS_LOOKAHEAD, + OP_RULE, R__TMP_81, + OP_RETURN, A_ATOM_6, + + // &'[' (list | listcomp) + OP_SAVE_MARK, + OP_TOKEN, LSQB, + OP_POS_LOOKAHEAD, + OP_RULE, R__TMP_82, + OP_RETURN, A_ATOM_7, + + // &'{' (dict | set | dictcomp | setcomp) + OP_SAVE_MARK, + OP_TOKEN, LBRACE, + OP_POS_LOOKAHEAD, + OP_RULE, R__TMP_83, + OP_RETURN, A_ATOM_8, + + // '...' + OP_TOKEN, ELLIPSIS, + OP_RETURN, A_ATOM_9, + + }, + }, + {"strings", + R_STRINGS, + 1, // memo + 0, // leftrec + {0, -1}, + { + // STRING+ + OP_RULE, R__LOOP1_84, + OP_RETURN, A_STRINGS_0, + + }, + }, + {"list", + R_LIST, + 0, // memo + 0, // leftrec + {0, -1}, + { + // '[' star_named_expressions? ']' + OP_TOKEN, LSQB, + OP_RULE, R_STAR_NAMED_EXPRESSIONS, + OP_OPTIONAL, + OP_TOKEN, RSQB, + OP_RETURN, A_LIST_0, + + }, + }, + {"listcomp", + R_LISTCOMP, + 0, // memo + 0, // leftrec + {0, 11, -1}, + { + // '[' named_expression ~ for_if_clauses ']' + OP_TOKEN, LSQB, + OP_RULE, R_NAMED_EXPRESSION, + OP_CUT, + OP_RULE, R_FOR_IF_CLAUSES, + OP_TOKEN, RSQB, + OP_RETURN, A_LISTCOMP_0, + + // invalid_comprehension + OP_RULE, R_INVALID_COMPREHENSION, + OP_RETURN, A_LISTCOMP_1, + + }, + }, + {"tuple", + R_TUPLE, + 0, // memo + 0, // leftrec + {0, -1}, + { + // '(' [star_named_expression ',' star_named_expressions?] ')' + OP_TOKEN, LPAR, + OP_RULE, R__TMP_85, + OP_OPTIONAL, + OP_TOKEN, RPAR, + OP_RETURN, A_TUPLE_0, + + }, + }, + {"group", + R_GROUP, + 0, // memo + 0, // leftrec + {0, 8, -1}, + { + // '(' (yield_expr | named_expression) ')' + OP_TOKEN, LPAR, + OP_RULE, R__TMP_86, + OP_TOKEN, RPAR, + OP_RETURN, A_GROUP_0, + + // invalid_group + OP_RULE, R_INVALID_GROUP, + OP_RETURN, A_GROUP_1, + + }, + }, + {"genexp", + R_GENEXP, + 0, // memo + 0, // leftrec + {0, 11, -1}, + { + // '(' expression ~ for_if_clauses ')' + OP_TOKEN, LPAR, + OP_RULE, R_EXPRESSION, + OP_CUT, + OP_RULE, R_FOR_IF_CLAUSES, + OP_TOKEN, RPAR, + OP_RETURN, A_GENEXP_0, + + // invalid_comprehension + OP_RULE, R_INVALID_COMPREHENSION, + OP_RETURN, A_GENEXP_1, + + }, + }, + {"set", + R_SET, + 0, // memo + 0, // leftrec + {0, -1}, + { + // '{' expressions_list '}' + OP_TOKEN, LBRACE, + OP_RULE, R_EXPRESSIONS_LIST, + OP_TOKEN, RBRACE, + OP_RETURN, A_SET_0, + + }, + }, + {"setcomp", + R_SETCOMP, + 0, // memo + 0, // leftrec + {0, 11, -1}, + { + // '{' expression ~ for_if_clauses '}' + OP_TOKEN, LBRACE, + OP_RULE, R_EXPRESSION, + OP_CUT, + OP_RULE, R_FOR_IF_CLAUSES, + OP_TOKEN, RBRACE, + OP_RETURN, A_SETCOMP_0, + + // invalid_comprehension + OP_RULE, R_INVALID_COMPREHENSION, + OP_RETURN, A_SETCOMP_1, + + }, + }, + {"dict", + R_DICT, + 0, // memo + 0, // leftrec + {0, -1}, + { + // '{' double_starred_kvpairs? '}' + OP_TOKEN, LBRACE, + OP_RULE, R_DOUBLE_STARRED_KVPAIRS, + OP_OPTIONAL, + OP_TOKEN, RBRACE, + OP_RETURN, A_DICT_0, + + }, + }, + {"dictcomp", + R_DICTCOMP, + 0, // memo + 0, // leftrec + {0, 10, -1}, + { + // '{' kvpair for_if_clauses '}' + OP_TOKEN, LBRACE, + OP_RULE, R_KVPAIR, + OP_RULE, R_FOR_IF_CLAUSES, + OP_TOKEN, RBRACE, + OP_RETURN, A_DICTCOMP_0, + + // invalid_dict_comprehension + OP_RULE, R_INVALID_DICT_COMPREHENSION, + OP_RETURN, A_DICTCOMP_1, + + }, + }, + {"double_starred_kvpairs", + R_DOUBLE_STARRED_KVPAIRS, + 0, // memo + 0, // leftrec + {0, -1}, + { + // ','.double_starred_kvpair+ ','? + OP_RULE, R__GATHER_87, + OP_TOKEN, COMMA, + OP_OPTIONAL, + OP_RETURN, A_DOUBLE_STARRED_KVPAIRS_0, + + }, + }, + {"double_starred_kvpair", + R_DOUBLE_STARRED_KVPAIR, + 0, // memo + 0, // leftrec + {0, 6, -1}, + { + // '**' bitwise_or + OP_TOKEN, DOUBLESTAR, + OP_RULE, R_BITWISE_OR, + OP_RETURN, A_DOUBLE_STARRED_KVPAIR_0, + + // kvpair + OP_RULE, R_KVPAIR, + OP_RETURN, A_DOUBLE_STARRED_KVPAIR_1, + + }, + }, + {"kvpair", + R_KVPAIR, + 0, // memo + 0, // leftrec + {0, -1}, + { + // expression ':' expression + OP_RULE, R_EXPRESSION, + OP_TOKEN, COLON, + OP_RULE, R_EXPRESSION, + OP_RETURN, A_KVPAIR_0, + + }, + }, + {"for_if_clauses", + R_FOR_IF_CLAUSES, + 0, // memo + 0, // leftrec + {0, -1}, + { + // for_if_clause+ + OP_RULE, R__LOOP1_88, + OP_RETURN, A_FOR_IF_CLAUSES_0, + + }, + }, + {"for_if_clause", + R_FOR_IF_CLAUSE, + 0, // memo + 0, // leftrec + {0, 15, 28, -1}, + { + // ASYNC 'for' star_targets 'in' ~ disjunction (('if' disjunction))* + OP_TOKEN, ASYNC, + OP_TOKEN, 517, + OP_RULE, R_STAR_TARGETS, + OP_TOKEN, 518, + OP_CUT, + OP_RULE, R_DISJUNCTION, + OP_RULE, R__LOOP0_89, + OP_RETURN, A_FOR_IF_CLAUSE_0, + + // 'for' star_targets 'in' ~ disjunction (('if' disjunction))* + OP_TOKEN, 517, + OP_RULE, R_STAR_TARGETS, + OP_TOKEN, 518, + OP_CUT, + OP_RULE, R_DISJUNCTION, + OP_RULE, R__LOOP0_90, + OP_RETURN, A_FOR_IF_CLAUSE_1, + + // invalid_for_target + OP_RULE, R_INVALID_FOR_TARGET, + OP_RETURN, A_FOR_IF_CLAUSE_2, + + }, + }, + {"yield_expr", + R_YIELD_EXPR, + 0, // memo + 0, // leftrec + {0, 8, -1}, + { + // 'yield' 'from' expression + OP_TOKEN, 504, + OP_TOKEN, 514, + OP_RULE, R_EXPRESSION, + OP_RETURN, A_YIELD_EXPR_0, + + // 'yield' star_expressions? + OP_TOKEN, 504, + OP_RULE, R_STAR_EXPRESSIONS, + OP_OPTIONAL, + OP_RETURN, A_YIELD_EXPR_1, + + }, + }, + {"arguments", + R_ARGUMENTS, + 1, // memo + 0, // leftrec + {0, 11, -1}, + { + // args ','? &')' + OP_RULE, R_ARGS, + OP_TOKEN, COMMA, + OP_OPTIONAL, + OP_SAVE_MARK, + OP_TOKEN, RPAR, + OP_POS_LOOKAHEAD, + OP_RETURN, A_ARGUMENTS_0, + + // incorrect_arguments + OP_RULE, R_INCORRECT_ARGUMENTS, + OP_RETURN, A_ARGUMENTS_1, + + }, + }, + {"args", + R_ARGS, + 0, // memo + 0, // leftrec + {0, 7, 11, -1}, + { + // starred_expression [',' args] + OP_RULE, R_STARRED_EXPRESSION, + OP_RULE, R__TMP_91, + OP_OPTIONAL, + OP_RETURN, A_ARGS_0, + + // kwargs + OP_RULE, R_KWARGS, + OP_RETURN, A_ARGS_1, + + // named_expression [',' args] + OP_RULE, R_NAMED_EXPRESSION, + OP_RULE, R__TMP_92, + OP_OPTIONAL, + OP_RETURN, A_ARGS_2, + + }, + }, + {"kwargs", + R_KWARGS, + 0, // memo + 0, // leftrec + {0, 8, 12, -1}, + { + // ','.kwarg_or_starred+ ',' ','.kwarg_or_double_starred+ + OP_RULE, R__GATHER_93, + OP_TOKEN, COMMA, + OP_RULE, R__GATHER_94, + OP_RETURN, A_KWARGS_0, + + // ','.kwarg_or_starred+ + OP_RULE, R__GATHER_95, + OP_RETURN, A_KWARGS_1, + + // ','.kwarg_or_double_starred+ + OP_RULE, R__GATHER_96, + OP_RETURN, A_KWARGS_2, + + }, + }, + {"starred_expression", + R_STARRED_EXPRESSION, + 0, // memo + 0, // leftrec + {0, -1}, + { + // '*' expression + OP_TOKEN, STAR, + OP_RULE, R_EXPRESSION, + OP_RETURN, A_STARRED_EXPRESSION_0, + + }, + }, + {"kwarg_or_starred", + R_KWARG_OR_STARRED, + 0, // memo + 0, // leftrec + {0, 7, 11, -1}, + { + // NAME '=' expression + OP_NAME, + OP_TOKEN, EQUAL, + OP_RULE, R_EXPRESSION, + OP_RETURN, A_KWARG_OR_STARRED_0, + + // starred_expression + OP_RULE, R_STARRED_EXPRESSION, + OP_RETURN, A_KWARG_OR_STARRED_1, + + // invalid_kwarg + OP_RULE, R_INVALID_KWARG, + OP_RETURN, A_KWARG_OR_STARRED_2, + + }, + }, + {"kwarg_or_double_starred", + R_KWARG_OR_DOUBLE_STARRED, + 0, // memo + 0, // leftrec + {0, 7, 13, -1}, + { + // NAME '=' expression + OP_NAME, + OP_TOKEN, EQUAL, + OP_RULE, R_EXPRESSION, + OP_RETURN, A_KWARG_OR_DOUBLE_STARRED_0, + + // '**' expression + OP_TOKEN, DOUBLESTAR, + OP_RULE, R_EXPRESSION, + OP_RETURN, A_KWARG_OR_DOUBLE_STARRED_1, + + // invalid_kwarg + OP_RULE, R_INVALID_KWARG, + OP_RETURN, A_KWARG_OR_DOUBLE_STARRED_2, + + }, + }, + {"star_targets", + R_STAR_TARGETS, + 0, // memo + 0, // leftrec + {0, 8, -1}, + { + // star_target !',' + OP_RULE, R_STAR_TARGET, + OP_SAVE_MARK, + OP_TOKEN, COMMA, + OP_NEG_LOOKAHEAD, + OP_RETURN, A_STAR_TARGETS_0, + + // star_target ((',' star_target))* ','? + OP_RULE, R_STAR_TARGET, + OP_RULE, R__LOOP0_97, + OP_TOKEN, COMMA, + OP_OPTIONAL, + OP_RETURN, A_STAR_TARGETS_1, + + }, + }, + {"star_targets_seq", + R_STAR_TARGETS_SEQ, + 0, // memo + 0, // leftrec + {0, -1}, + { + // ','.star_target+ ','? + OP_RULE, R__GATHER_98, + OP_TOKEN, COMMA, + OP_OPTIONAL, + OP_RETURN, A_STAR_TARGETS_SEQ_0, + + }, + }, + {"star_target", + R_STAR_TARGET, + 1, // memo + 0, // leftrec + {0, 6, 17, 31, -1}, + { + // '*' (!'*' star_target) + OP_TOKEN, STAR, + OP_RULE, R__TMP_99, + OP_RETURN, A_STAR_TARGET_0, + + // t_primary '.' NAME !t_lookahead + OP_RULE, R_T_PRIMARY, + OP_TOKEN, DOT, + OP_NAME, + OP_SAVE_MARK, + OP_RULE, R_T_LOOKAHEAD, + OP_NEG_LOOKAHEAD, + OP_RETURN, A_STAR_TARGET_1, + + // t_primary '[' slices ']' !t_lookahead + OP_RULE, R_T_PRIMARY, + OP_TOKEN, LSQB, + OP_RULE, R_SLICES, + OP_TOKEN, RSQB, + OP_SAVE_MARK, + OP_RULE, R_T_LOOKAHEAD, + OP_NEG_LOOKAHEAD, + OP_RETURN, A_STAR_TARGET_2, + + // star_atom + OP_RULE, R_STAR_ATOM, + OP_RETURN, A_STAR_TARGET_3, + + }, + }, + {"star_atom", + R_STAR_ATOM, + 0, // memo + 0, // leftrec + {0, 3, 11, 20, -1}, + { + // NAME + OP_NAME, + OP_RETURN, A_STAR_ATOM_0, + + // '(' star_target ')' + OP_TOKEN, LPAR, + OP_RULE, R_STAR_TARGET, + OP_TOKEN, RPAR, + OP_RETURN, A_STAR_ATOM_1, + + // '(' star_targets_seq? ')' + OP_TOKEN, LPAR, + OP_RULE, R_STAR_TARGETS_SEQ, + OP_OPTIONAL, + OP_TOKEN, RPAR, + OP_RETURN, A_STAR_ATOM_2, + + // '[' star_targets_seq? ']' + OP_TOKEN, LSQB, + OP_RULE, R_STAR_TARGETS_SEQ, + OP_OPTIONAL, + OP_TOKEN, RSQB, + OP_RETURN, A_STAR_ATOM_3, + + }, + }, + {"single_target", + R_SINGLE_TARGET, + 0, // memo + 0, // leftrec + {0, 4, 7, -1}, + { + // single_subscript_attribute_target + OP_RULE, R_SINGLE_SUBSCRIPT_ATTRIBUTE_TARGET, + OP_RETURN, A_SINGLE_TARGET_0, + + // NAME + OP_NAME, + OP_RETURN, A_SINGLE_TARGET_1, + + // '(' single_target ')' + OP_TOKEN, LPAR, + OP_RULE, R_SINGLE_TARGET, + OP_TOKEN, RPAR, + OP_RETURN, A_SINGLE_TARGET_2, + + }, + }, + {"single_subscript_attribute_target", + R_SINGLE_SUBSCRIPT_ATTRIBUTE_TARGET, + 0, // memo + 0, // leftrec + {0, 11, -1}, + { + // t_primary '.' NAME !t_lookahead + OP_RULE, R_T_PRIMARY, + OP_TOKEN, DOT, + OP_NAME, + OP_SAVE_MARK, + OP_RULE, R_T_LOOKAHEAD, + OP_NEG_LOOKAHEAD, + OP_RETURN, A_SINGLE_SUBSCRIPT_ATTRIBUTE_TARGET_0, + + // t_primary '[' slices ']' !t_lookahead + OP_RULE, R_T_PRIMARY, + OP_TOKEN, LSQB, + OP_RULE, R_SLICES, + OP_TOKEN, RSQB, + OP_SAVE_MARK, + OP_RULE, R_T_LOOKAHEAD, + OP_NEG_LOOKAHEAD, + OP_RETURN, A_SINGLE_SUBSCRIPT_ATTRIBUTE_TARGET_1, + + }, + }, + {"del_targets", + R_DEL_TARGETS, + 0, // memo + 0, // leftrec + {0, -1}, + { + // ','.del_target+ ','? + OP_RULE, R__GATHER_100, + OP_TOKEN, COMMA, + OP_OPTIONAL, + OP_RETURN, A_DEL_TARGETS_0, + + }, + }, + {"del_target", + R_DEL_TARGET, + 1, // memo + 0, // leftrec + {0, 11, 25, -1}, + { + // t_primary '.' NAME !t_lookahead + OP_RULE, R_T_PRIMARY, + OP_TOKEN, DOT, + OP_NAME, + OP_SAVE_MARK, + OP_RULE, R_T_LOOKAHEAD, + OP_NEG_LOOKAHEAD, + OP_RETURN, A_DEL_TARGET_0, + + // t_primary '[' slices ']' !t_lookahead + OP_RULE, R_T_PRIMARY, + OP_TOKEN, LSQB, + OP_RULE, R_SLICES, + OP_TOKEN, RSQB, + OP_SAVE_MARK, + OP_RULE, R_T_LOOKAHEAD, + OP_NEG_LOOKAHEAD, + OP_RETURN, A_DEL_TARGET_1, + + // del_t_atom + OP_RULE, R_DEL_T_ATOM, + OP_RETURN, A_DEL_TARGET_2, + + }, + }, + {"del_t_atom", + R_DEL_T_ATOM, + 0, // memo + 0, // leftrec + {0, 3, 11, 20, -1}, + { + // NAME + OP_NAME, + OP_RETURN, A_DEL_T_ATOM_0, + + // '(' del_target ')' + OP_TOKEN, LPAR, + OP_RULE, R_DEL_TARGET, + OP_TOKEN, RPAR, + OP_RETURN, A_DEL_T_ATOM_1, + + // '(' del_targets? ')' + OP_TOKEN, LPAR, + OP_RULE, R_DEL_TARGETS, + OP_OPTIONAL, + OP_TOKEN, RPAR, + OP_RETURN, A_DEL_T_ATOM_2, + + // '[' del_targets? ']' + OP_TOKEN, LSQB, + OP_RULE, R_DEL_TARGETS, + OP_OPTIONAL, + OP_TOKEN, RSQB, + OP_RETURN, A_DEL_T_ATOM_3, + + }, + }, + {"targets", + R_TARGETS, + 0, // memo + 0, // leftrec + {0, -1}, + { + // ','.target+ ','? + OP_RULE, R__GATHER_101, + OP_TOKEN, COMMA, + OP_OPTIONAL, + OP_RETURN, A_TARGETS_0, + + }, + }, + {"target", + R_TARGET, + 1, // memo + 0, // leftrec + {0, 11, 25, -1}, + { + // t_primary '.' NAME !t_lookahead + OP_RULE, R_T_PRIMARY, + OP_TOKEN, DOT, + OP_NAME, + OP_SAVE_MARK, + OP_RULE, R_T_LOOKAHEAD, + OP_NEG_LOOKAHEAD, + OP_RETURN, A_TARGET_0, + + // t_primary '[' slices ']' !t_lookahead + OP_RULE, R_T_PRIMARY, + OP_TOKEN, LSQB, + OP_RULE, R_SLICES, + OP_TOKEN, RSQB, + OP_SAVE_MARK, + OP_RULE, R_T_LOOKAHEAD, + OP_NEG_LOOKAHEAD, + OP_RETURN, A_TARGET_1, + + // t_atom + OP_RULE, R_T_ATOM, + OP_RETURN, A_TARGET_2, + + }, + }, + {"t_primary", + R_T_PRIMARY, + 0, // memo + 1, // leftrec + {0, 11, 25, 35, 50, -1}, + { + // t_primary '.' NAME &t_lookahead + OP_RULE, R_T_PRIMARY, + OP_TOKEN, DOT, + OP_NAME, + OP_SAVE_MARK, + OP_RULE, R_T_LOOKAHEAD, + OP_POS_LOOKAHEAD, + OP_RETURN, A_T_PRIMARY_0, + + // t_primary '[' slices ']' &t_lookahead + OP_RULE, R_T_PRIMARY, + OP_TOKEN, LSQB, + OP_RULE, R_SLICES, + OP_TOKEN, RSQB, + OP_SAVE_MARK, + OP_RULE, R_T_LOOKAHEAD, + OP_POS_LOOKAHEAD, + OP_RETURN, A_T_PRIMARY_1, + + // t_primary genexp &t_lookahead + OP_RULE, R_T_PRIMARY, + OP_RULE, R_GENEXP, + OP_SAVE_MARK, + OP_RULE, R_T_LOOKAHEAD, + OP_POS_LOOKAHEAD, + OP_RETURN, A_T_PRIMARY_2, + + // t_primary '(' arguments? ')' &t_lookahead + OP_RULE, R_T_PRIMARY, + OP_TOKEN, LPAR, + OP_RULE, R_ARGUMENTS, + OP_OPTIONAL, + OP_TOKEN, RPAR, + OP_SAVE_MARK, + OP_RULE, R_T_LOOKAHEAD, + OP_POS_LOOKAHEAD, + OP_RETURN, A_T_PRIMARY_3, + + // atom &t_lookahead + OP_RULE, R_ATOM, + OP_SAVE_MARK, + OP_RULE, R_T_LOOKAHEAD, + OP_POS_LOOKAHEAD, + OP_RETURN, A_T_PRIMARY_4, + + }, + }, + {"t_lookahead", + R_T_LOOKAHEAD, + 0, // memo + 0, // leftrec + {0, 4, 8, -1}, + { + // '(' + OP_TOKEN, LPAR, + OP_RETURN, A_T_LOOKAHEAD_0, + + // '[' + OP_TOKEN, LSQB, + OP_RETURN, A_T_LOOKAHEAD_1, + + // '.' + OP_TOKEN, DOT, + OP_RETURN, A_T_LOOKAHEAD_2, + + }, + }, + {"t_atom", + R_T_ATOM, + 0, // memo + 0, // leftrec + {0, 3, 11, 20, -1}, + { + // NAME + OP_NAME, + OP_RETURN, A_T_ATOM_0, + + // '(' target ')' + OP_TOKEN, LPAR, + OP_RULE, R_TARGET, + OP_TOKEN, RPAR, + OP_RETURN, A_T_ATOM_1, + + // '(' targets? ')' + OP_TOKEN, LPAR, + OP_RULE, R_TARGETS, + OP_OPTIONAL, + OP_TOKEN, RPAR, + OP_RETURN, A_T_ATOM_2, + + // '[' targets? ']' + OP_TOKEN, LSQB, + OP_RULE, R_TARGETS, + OP_OPTIONAL, + OP_TOKEN, RSQB, + OP_RETURN, A_T_ATOM_3, + + }, + }, + {"incorrect_arguments", + R_INCORRECT_ARGUMENTS, + 0, // memo + 0, // leftrec + {0, 8, 19, 25, 35, -1}, + { + // args ',' '*' + OP_RULE, R_ARGS, + OP_TOKEN, COMMA, + OP_TOKEN, STAR, + OP_RETURN, A_INCORRECT_ARGUMENTS_0, + + // expression for_if_clauses ',' [args | expression for_if_clauses] + OP_RULE, R_EXPRESSION, + OP_RULE, R_FOR_IF_CLAUSES, + OP_TOKEN, COMMA, + OP_RULE, R__TMP_102, + OP_OPTIONAL, + OP_RETURN, A_INCORRECT_ARGUMENTS_1, + + // args for_if_clauses + OP_RULE, R_ARGS, + OP_RULE, R_FOR_IF_CLAUSES, + OP_RETURN, A_INCORRECT_ARGUMENTS_2, + + // args ',' expression for_if_clauses + OP_RULE, R_ARGS, + OP_TOKEN, COMMA, + OP_RULE, R_EXPRESSION, + OP_RULE, R_FOR_IF_CLAUSES, + OP_RETURN, A_INCORRECT_ARGUMENTS_3, + + // args ',' args + OP_RULE, R_ARGS, + OP_TOKEN, COMMA, + OP_RULE, R_ARGS, + OP_RETURN, A_INCORRECT_ARGUMENTS_4, + + }, + }, + {"invalid_kwarg", + R_INVALID_KWARG, + 0, // memo + 0, // leftrec + {0, -1}, + { + // expression '=' + OP_RULE, R_EXPRESSION, + OP_TOKEN, EQUAL, + OP_RETURN, A_INVALID_KWARG_0, + + }, + }, + {"invalid_named_expression", + R_INVALID_NAMED_EXPRESSION, + 0, // memo + 0, // leftrec + {0, -1}, + { + // expression ':=' expression + OP_RULE, R_EXPRESSION, + OP_TOKEN, COLONEQUAL, + OP_RULE, R_EXPRESSION, + OP_RETURN, A_INVALID_NAMED_EXPRESSION_0, + + }, + }, + {"invalid_assignment", + R_INVALID_ASSIGNMENT, + 0, // memo + 0, // leftrec + {0, 8, 20, 28, 36, 44, -1}, + { + // invalid_ann_assign_target ':' expression + OP_RULE, R_INVALID_ANN_ASSIGN_TARGET, + OP_TOKEN, COLON, + OP_RULE, R_EXPRESSION, + OP_RETURN, A_INVALID_ASSIGNMENT_0, + + // star_named_expression ',' star_named_expressions* ':' expression + OP_RULE, R_STAR_NAMED_EXPRESSION, + OP_TOKEN, COMMA, + OP_RULE, R__LOOP0_103, + OP_TOKEN, COLON, + OP_RULE, R_EXPRESSION, + OP_RETURN, A_INVALID_ASSIGNMENT_1, + + // expression ':' expression + OP_RULE, R_EXPRESSION, + OP_TOKEN, COLON, + OP_RULE, R_EXPRESSION, + OP_RETURN, A_INVALID_ASSIGNMENT_2, + + // ((star_targets '='))* star_expressions '=' + OP_RULE, R__LOOP0_104, + OP_RULE, R_STAR_EXPRESSIONS, + OP_TOKEN, EQUAL, + OP_RETURN, A_INVALID_ASSIGNMENT_3, + + // ((star_targets '='))* yield_expr '=' + OP_RULE, R__LOOP0_105, + OP_RULE, R_YIELD_EXPR, + OP_TOKEN, EQUAL, + OP_RETURN, A_INVALID_ASSIGNMENT_4, + + // star_expressions augassign (yield_expr | star_expressions) + OP_RULE, R_STAR_EXPRESSIONS, + OP_RULE, R_AUGASSIGN, + OP_RULE, R__TMP_106, + OP_RETURN, A_INVALID_ASSIGNMENT_5, + + }, + }, + {"invalid_ann_assign_target", + R_INVALID_ANN_ASSIGN_TARGET, + 0, // memo + 0, // leftrec + {0, 4, 8, -1}, + { + // list + OP_RULE, R_LIST, + OP_RETURN, A_INVALID_ANN_ASSIGN_TARGET_0, + + // tuple + OP_RULE, R_TUPLE, + OP_RETURN, A_INVALID_ANN_ASSIGN_TARGET_1, + + // '(' invalid_ann_assign_target ')' + OP_TOKEN, LPAR, + OP_RULE, R_INVALID_ANN_ASSIGN_TARGET, + OP_TOKEN, RPAR, + OP_RETURN, A_INVALID_ANN_ASSIGN_TARGET_2, + + }, + }, + {"invalid_del_stmt", + R_INVALID_DEL_STMT, + 0, // memo + 0, // leftrec + {0, -1}, + { + // 'del' star_expressions + OP_TOKEN, 503, + OP_RULE, R_STAR_EXPRESSIONS, + OP_RETURN, A_INVALID_DEL_STMT_0, + + }, + }, + {"invalid_block", + R_INVALID_BLOCK, + 0, // memo + 0, // leftrec + {0, -1}, + { + // NEWLINE !INDENT + OP_TOKEN, NEWLINE, + OP_SAVE_MARK, + OP_TOKEN, INDENT, + OP_NEG_LOOKAHEAD, + OP_RETURN, A_INVALID_BLOCK_0, + + }, + }, + {"invalid_comprehension", + R_INVALID_COMPREHENSION, + 0, // memo + 0, // leftrec + {0, -1}, + { + // ('[' | '(' | '{') starred_expression for_if_clauses + OP_RULE, R__TMP_107, + OP_RULE, R_STARRED_EXPRESSION, + OP_RULE, R_FOR_IF_CLAUSES, + OP_RETURN, A_INVALID_COMPREHENSION_0, + + }, + }, + {"invalid_dict_comprehension", + R_INVALID_DICT_COMPREHENSION, + 0, // memo + 0, // leftrec + {0, -1}, + { + // '{' '**' bitwise_or for_if_clauses '}' + OP_TOKEN, LBRACE, + OP_TOKEN, DOUBLESTAR, + OP_RULE, R_BITWISE_OR, + OP_RULE, R_FOR_IF_CLAUSES, + OP_TOKEN, RBRACE, + OP_RETURN, A_INVALID_DICT_COMPREHENSION_0, + + }, + }, + {"invalid_parameters", + R_INVALID_PARAMETERS, + 0, // memo + 0, // leftrec + {0, -1}, + { + // param_no_default* (slash_with_default | param_with_default+) param_no_default + OP_RULE, R__LOOP0_108, + OP_RULE, R__TMP_109, + OP_RULE, R_PARAM_NO_DEFAULT, + OP_RETURN, A_INVALID_PARAMETERS_0, + + }, + }, + {"invalid_lambda_parameters", + R_INVALID_LAMBDA_PARAMETERS, + 0, // memo + 0, // leftrec + {0, -1}, + { + // lambda_param_no_default* (lambda_slash_with_default | lambda_param_with_default+) lambda_param_no_default + OP_RULE, R__LOOP0_110, + OP_RULE, R__TMP_111, + OP_RULE, R_LAMBDA_PARAM_NO_DEFAULT, + OP_RETURN, A_INVALID_LAMBDA_PARAMETERS_0, + + }, + }, + {"invalid_star_etc", + R_INVALID_STAR_ETC, + 0, // memo + 0, // leftrec + {0, 6, -1}, + { + // '*' (')' | ',' (')' | '**')) + OP_TOKEN, STAR, + OP_RULE, R__TMP_112, + OP_RETURN, A_INVALID_STAR_ETC_0, + + // '*' ',' TYPE_COMMENT + OP_TOKEN, STAR, + OP_TOKEN, COMMA, + OP_TOKEN, TYPE_COMMENT, + OP_RETURN, A_INVALID_STAR_ETC_1, + + }, + }, + {"invalid_lambda_star_etc", + R_INVALID_LAMBDA_STAR_ETC, + 0, // memo + 0, // leftrec + {0, -1}, + { + // '*' (':' | ',' (':' | '**')) + OP_TOKEN, STAR, + OP_RULE, R__TMP_113, + OP_RETURN, A_INVALID_LAMBDA_STAR_ETC_0, + + }, + }, + {"invalid_double_type_comments", + R_INVALID_DOUBLE_TYPE_COMMENTS, + 0, // memo + 0, // leftrec + {0, -1}, + { + // TYPE_COMMENT NEWLINE TYPE_COMMENT NEWLINE INDENT + OP_TOKEN, TYPE_COMMENT, + OP_TOKEN, NEWLINE, + OP_TOKEN, TYPE_COMMENT, + OP_TOKEN, NEWLINE, + OP_TOKEN, INDENT, + OP_RETURN, A_INVALID_DOUBLE_TYPE_COMMENTS_0, + + }, + }, + {"invalid_with_item", + R_INVALID_WITH_ITEM, + 0, // memo + 0, // leftrec + {0, -1}, + { + // expression 'as' expression + OP_RULE, R_EXPRESSION, + OP_TOKEN, 520, + OP_RULE, R_EXPRESSION, + OP_RETURN, A_INVALID_WITH_ITEM_0, + + }, + }, + {"invalid_for_target", + R_INVALID_FOR_TARGET, + 0, // memo + 0, // leftrec + {0, -1}, + { + // ASYNC? 'for' star_expressions + OP_TOKEN, ASYNC, + OP_OPTIONAL, + OP_TOKEN, 517, + OP_RULE, R_STAR_EXPRESSIONS, + OP_RETURN, A_INVALID_FOR_TARGET_0, + + }, + }, + {"invalid_group", + R_INVALID_GROUP, + 0, // memo + 0, // leftrec + {0, -1}, + { + // '(' starred_expression ')' + OP_TOKEN, LPAR, + OP_RULE, R_STARRED_EXPRESSION, + OP_TOKEN, RPAR, + OP_RETURN, A_INVALID_GROUP_0, + + }, + }, + {"invalid_import_from_targets", + R_INVALID_IMPORT_FROM_TARGETS, + 0, // memo + 0, // leftrec + {0, -1}, + { + // import_from_as_names ',' + OP_RULE, R_IMPORT_FROM_AS_NAMES, + OP_TOKEN, COMMA, + OP_RETURN, A_INVALID_IMPORT_FROM_TARGETS_0, + + }, + }, + {"root", + R_ROOT, + 0, + 0, + {0, 3, -1}, + { + // + OP_RULE, R_FILE, + OP_SUCCESS, + + // + OP_FAILURE, + + }, + }, + {"_loop0_1", + R__LOOP0_1, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // NEWLINE + OP_TOKEN, NEWLINE, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT, + + }, + }, + {"_loop0_2", + R__LOOP0_2, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // NEWLINE + OP_TOKEN, NEWLINE, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT, + + }, + }, + {"_gather_3", + R__GATHER_3, + 0, // memo + 0, // leftrec + {0, 5, -1}, + { + // expression ',' + OP_RULE, R_EXPRESSION, + OP_TOKEN, COMMA, + OP_LOOP_ITERATE, + + // expression + OP_RULE, R_EXPRESSION, + OP_LOOP_COLLECT_DELIMITED, + + }, + }, + {"_gather_4", + R__GATHER_4, + 0, // memo + 0, // leftrec + {0, 5, -1}, + { + // expression ',' + OP_RULE, R_EXPRESSION, + OP_TOKEN, COMMA, + OP_LOOP_ITERATE, + + // expression + OP_RULE, R_EXPRESSION, + OP_LOOP_COLLECT_DELIMITED, + + }, + }, + {"_gather_5", + R__GATHER_5, + 0, // memo + 0, // leftrec + {0, 5, -1}, + { + // expression ',' + OP_RULE, R_EXPRESSION, + OP_TOKEN, COMMA, + OP_LOOP_ITERATE, + + // expression + OP_RULE, R_EXPRESSION, + OP_LOOP_COLLECT_DELIMITED, + + }, + }, + {"_gather_6", + R__GATHER_6, + 0, // memo + 0, // leftrec + {0, 5, -1}, + { + // expression ',' + OP_RULE, R_EXPRESSION, + OP_TOKEN, COMMA, + OP_LOOP_ITERATE, + + // expression + OP_RULE, R_EXPRESSION, + OP_LOOP_COLLECT_DELIMITED, + + }, + }, + {"_loop1_7", + R__LOOP1_7, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // statement + OP_RULE, R_STATEMENT, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT_NONEMPTY, + + }, + }, + {"_gather_8", + R__GATHER_8, + 0, // memo + 0, // leftrec + {0, 5, -1}, + { + // small_stmt ';' + OP_RULE, R_SMALL_STMT, + OP_TOKEN, SEMI, + OP_LOOP_ITERATE, + + // small_stmt + OP_RULE, R_SMALL_STMT, + OP_LOOP_COLLECT_DELIMITED, + + }, + }, + {"_tmp_9", + R__TMP_9, + 0, // memo + 0, // leftrec + {0, 4, -1}, + { + // 'import' + OP_TOKEN, 513, + OP_RETURN, A__TMP_9_0, + + // 'from' + OP_TOKEN, 514, + OP_RETURN, A__TMP_9_1, + + }, + }, + {"_tmp_10", + R__TMP_10, + 0, // memo + 0, // leftrec + {0, 4, 8, -1}, + { + // 'def' + OP_TOKEN, 523, + OP_RETURN, A__TMP_10_0, + + // '@' + OP_TOKEN, AT, + OP_RETURN, A__TMP_10_1, + + // ASYNC + OP_TOKEN, ASYNC, + OP_RETURN, A__TMP_10_2, + + }, + }, + {"_tmp_11", + R__TMP_11, + 0, // memo + 0, // leftrec + {0, 4, -1}, + { + // 'class' + OP_TOKEN, 524, + OP_RETURN, A__TMP_11_0, + + // '@' + OP_TOKEN, AT, + OP_RETURN, A__TMP_11_1, + + }, + }, + {"_tmp_12", + R__TMP_12, + 0, // memo + 0, // leftrec + {0, 4, -1}, + { + // 'with' + OP_TOKEN, 519, + OP_RETURN, A__TMP_12_0, + + // ASYNC + OP_TOKEN, ASYNC, + OP_RETURN, A__TMP_12_1, + + }, + }, + {"_tmp_13", + R__TMP_13, + 0, // memo + 0, // leftrec + {0, 4, -1}, + { + // 'for' + OP_TOKEN, 517, + OP_RETURN, A__TMP_13_0, + + // ASYNC + OP_TOKEN, ASYNC, + OP_RETURN, A__TMP_13_1, + + }, + }, + {"_tmp_14", + R__TMP_14, + 0, // memo + 0, // leftrec + {0, -1}, + { + // '=' annotated_rhs + OP_TOKEN, EQUAL, + OP_RULE, R_ANNOTATED_RHS, + OP_RETURN, A__TMP_14_0, + + }, + }, + {"_tmp_15", + R__TMP_15, + 0, // memo + 0, // leftrec + {0, 8, -1}, + { + // '(' single_target ')' + OP_TOKEN, LPAR, + OP_RULE, R_SINGLE_TARGET, + OP_TOKEN, RPAR, + OP_RETURN, A__TMP_15_0, + + // single_subscript_attribute_target + OP_RULE, R_SINGLE_SUBSCRIPT_ATTRIBUTE_TARGET, + OP_RETURN, A__TMP_15_1, + + }, + }, + {"_tmp_16", + R__TMP_16, + 0, // memo + 0, // leftrec + {0, -1}, + { + // '=' annotated_rhs + OP_TOKEN, EQUAL, + OP_RULE, R_ANNOTATED_RHS, + OP_RETURN, A__TMP_16_0, + + }, + }, + {"_loop1_17", + R__LOOP1_17, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // (star_targets '=') + OP_RULE, R__TMP_114, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT_NONEMPTY, + + }, + }, + {"_tmp_18", + R__TMP_18, + 0, // memo + 0, // leftrec + {0, 4, -1}, + { + // yield_expr + OP_RULE, R_YIELD_EXPR, + OP_RETURN, A__TMP_18_0, + + // star_expressions + OP_RULE, R_STAR_EXPRESSIONS, + OP_RETURN, A__TMP_18_1, + + }, + }, + {"_tmp_19", + R__TMP_19, + 0, // memo + 0, // leftrec + {0, 4, -1}, + { + // yield_expr + OP_RULE, R_YIELD_EXPR, + OP_RETURN, A__TMP_19_0, + + // star_expressions + OP_RULE, R_STAR_EXPRESSIONS, + OP_RETURN, A__TMP_19_1, + + }, + }, + {"_gather_20", + R__GATHER_20, + 0, // memo + 0, // leftrec + {0, 4, -1}, + { + // NAME ',' + OP_NAME, + OP_TOKEN, COMMA, + OP_LOOP_ITERATE, + + // NAME + OP_NAME, + OP_LOOP_COLLECT_DELIMITED, + + }, + }, + {"_gather_21", + R__GATHER_21, + 0, // memo + 0, // leftrec + {0, 4, -1}, + { + // NAME ',' + OP_NAME, + OP_TOKEN, COMMA, + OP_LOOP_ITERATE, + + // NAME + OP_NAME, + OP_LOOP_COLLECT_DELIMITED, + + }, + }, + {"_tmp_22", + R__TMP_22, + 0, // memo + 0, // leftrec + {0, -1}, + { + // ',' expression + OP_TOKEN, COMMA, + OP_RULE, R_EXPRESSION, + OP_RETURN, A__TMP_22_0, + + }, + }, + {"_tmp_23", + R__TMP_23, + 0, // memo + 0, // leftrec + {0, 4, -1}, + { + // ';' + OP_TOKEN, SEMI, + OP_RETURN, A__TMP_23_0, + + // NEWLINE + OP_TOKEN, NEWLINE, + OP_RETURN, A__TMP_23_1, + + }, + }, + {"_loop0_24", + R__LOOP0_24, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // ('.' | '...') + OP_RULE, R__TMP_115, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT, + + }, + }, + {"_loop1_25", + R__LOOP1_25, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // ('.' | '...') + OP_RULE, R__TMP_116, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT_NONEMPTY, + + }, + }, + {"_gather_26", + R__GATHER_26, + 0, // memo + 0, // leftrec + {0, 5, -1}, + { + // import_from_as_name ',' + OP_RULE, R_IMPORT_FROM_AS_NAME, + OP_TOKEN, COMMA, + OP_LOOP_ITERATE, + + // import_from_as_name + OP_RULE, R_IMPORT_FROM_AS_NAME, + OP_LOOP_COLLECT_DELIMITED, + + }, + }, + {"_tmp_27", + R__TMP_27, + 0, // memo + 0, // leftrec + {0, -1}, + { + // 'as' NAME + OP_TOKEN, 520, + OP_NAME, + OP_RETURN, A__TMP_27_0, + + }, + }, + {"_gather_28", + R__GATHER_28, + 0, // memo + 0, // leftrec + {0, 5, -1}, + { + // dotted_as_name ',' + OP_RULE, R_DOTTED_AS_NAME, + OP_TOKEN, COMMA, + OP_LOOP_ITERATE, + + // dotted_as_name + OP_RULE, R_DOTTED_AS_NAME, + OP_LOOP_COLLECT_DELIMITED, + + }, + }, + {"_tmp_29", + R__TMP_29, + 0, // memo + 0, // leftrec + {0, -1}, + { + // 'as' NAME + OP_TOKEN, 520, + OP_NAME, + OP_RETURN, A__TMP_29_0, + + }, + }, + {"_gather_30", + R__GATHER_30, + 0, // memo + 0, // leftrec + {0, 5, -1}, + { + // with_item ',' + OP_RULE, R_WITH_ITEM, + OP_TOKEN, COMMA, + OP_LOOP_ITERATE, + + // with_item + OP_RULE, R_WITH_ITEM, + OP_LOOP_COLLECT_DELIMITED, + + }, + }, + {"_gather_31", + R__GATHER_31, + 0, // memo + 0, // leftrec + {0, 5, -1}, + { + // with_item ',' + OP_RULE, R_WITH_ITEM, + OP_TOKEN, COMMA, + OP_LOOP_ITERATE, + + // with_item + OP_RULE, R_WITH_ITEM, + OP_LOOP_COLLECT_DELIMITED, + + }, + }, + {"_gather_32", + R__GATHER_32, + 0, // memo + 0, // leftrec + {0, 5, -1}, + { + // with_item ',' + OP_RULE, R_WITH_ITEM, + OP_TOKEN, COMMA, + OP_LOOP_ITERATE, + + // with_item + OP_RULE, R_WITH_ITEM, + OP_LOOP_COLLECT_DELIMITED, + + }, + }, + {"_gather_33", + R__GATHER_33, + 0, // memo + 0, // leftrec + {0, 5, -1}, + { + // with_item ',' + OP_RULE, R_WITH_ITEM, + OP_TOKEN, COMMA, + OP_LOOP_ITERATE, + + // with_item + OP_RULE, R_WITH_ITEM, + OP_LOOP_COLLECT_DELIMITED, + + }, + }, + {"_tmp_34", + R__TMP_34, + 0, // memo + 0, // leftrec + {0, 4, 8, -1}, + { + // ',' + OP_TOKEN, COMMA, + OP_RETURN, A__TMP_34_0, + + // ')' + OP_TOKEN, RPAR, + OP_RETURN, A__TMP_34_1, + + // ':' + OP_TOKEN, COLON, + OP_RETURN, A__TMP_34_2, + + }, + }, + {"_loop1_35", + R__LOOP1_35, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // except_block + OP_RULE, R_EXCEPT_BLOCK, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT_NONEMPTY, + + }, + }, + {"_tmp_36", + R__TMP_36, + 0, // memo + 0, // leftrec + {0, -1}, + { + // 'as' NAME + OP_TOKEN, 520, + OP_NAME, + OP_RETURN, A__TMP_36_0, + + }, + }, + {"_tmp_37", + R__TMP_37, + 0, // memo + 0, // leftrec + {0, -1}, + { + // 'from' expression + OP_TOKEN, 514, + OP_RULE, R_EXPRESSION, + OP_RETURN, A__TMP_37_0, + + }, + }, + {"_tmp_38", + R__TMP_38, + 0, // memo + 0, // leftrec + {0, -1}, + { + // '->' expression + OP_TOKEN, RARROW, + OP_RULE, R_EXPRESSION, + OP_RETURN, A__TMP_38_0, + + }, + }, + {"_tmp_39", + R__TMP_39, + 0, // memo + 0, // leftrec + {0, -1}, + { + // '->' expression + OP_TOKEN, RARROW, + OP_RULE, R_EXPRESSION, + OP_RETURN, A__TMP_39_0, + + }, + }, + {"_tmp_40", + R__TMP_40, + 0, // memo + 0, // leftrec + {0, -1}, + { + // NEWLINE INDENT + OP_TOKEN, NEWLINE, + OP_TOKEN, INDENT, + OP_RETURN, A__TMP_40_0, + + }, + }, + {"_loop0_41", + R__LOOP0_41, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // param_no_default + OP_RULE, R_PARAM_NO_DEFAULT, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT, + + }, + }, + {"_loop0_42", + R__LOOP0_42, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // param_with_default + OP_RULE, R_PARAM_WITH_DEFAULT, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT, + + }, + }, + {"_loop0_43", + R__LOOP0_43, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // param_with_default + OP_RULE, R_PARAM_WITH_DEFAULT, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT, + + }, + }, + {"_loop1_44", + R__LOOP1_44, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // param_no_default + OP_RULE, R_PARAM_NO_DEFAULT, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT_NONEMPTY, + + }, + }, + {"_loop0_45", + R__LOOP0_45, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // param_with_default + OP_RULE, R_PARAM_WITH_DEFAULT, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT, + + }, + }, + {"_loop1_46", + R__LOOP1_46, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // param_with_default + OP_RULE, R_PARAM_WITH_DEFAULT, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT_NONEMPTY, + + }, + }, + {"_loop1_47", + R__LOOP1_47, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // param_no_default + OP_RULE, R_PARAM_NO_DEFAULT, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT_NONEMPTY, + + }, + }, + {"_loop1_48", + R__LOOP1_48, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // param_no_default + OP_RULE, R_PARAM_NO_DEFAULT, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT_NONEMPTY, + + }, + }, + {"_loop0_49", + R__LOOP0_49, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // param_no_default + OP_RULE, R_PARAM_NO_DEFAULT, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT, + + }, + }, + {"_loop1_50", + R__LOOP1_50, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // param_with_default + OP_RULE, R_PARAM_WITH_DEFAULT, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT_NONEMPTY, + + }, + }, + {"_loop0_51", + R__LOOP0_51, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // param_no_default + OP_RULE, R_PARAM_NO_DEFAULT, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT, + + }, + }, + {"_loop1_52", + R__LOOP1_52, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // param_with_default + OP_RULE, R_PARAM_WITH_DEFAULT, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT_NONEMPTY, + + }, + }, + {"_loop0_53", + R__LOOP0_53, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // param_maybe_default + OP_RULE, R_PARAM_MAYBE_DEFAULT, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT, + + }, + }, + {"_loop1_54", + R__LOOP1_54, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // param_maybe_default + OP_RULE, R_PARAM_MAYBE_DEFAULT, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT_NONEMPTY, + + }, + }, + {"_loop1_55", + R__LOOP1_55, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // ('@' named_expression NEWLINE) + OP_RULE, R__TMP_117, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT_NONEMPTY, + + }, + }, + {"_tmp_56", + R__TMP_56, + 0, // memo + 0, // leftrec + {0, -1}, + { + // '(' arguments? ')' + OP_TOKEN, LPAR, + OP_RULE, R_ARGUMENTS, + OP_OPTIONAL, + OP_TOKEN, RPAR, + OP_RETURN, A__TMP_56_0, + + }, + }, + {"_gather_57", + R__GATHER_57, + 0, // memo + 0, // leftrec + {0, 5, -1}, + { + // star_expression ',' + OP_RULE, R_STAR_EXPRESSION, + OP_TOKEN, COMMA, + OP_LOOP_ITERATE, + + // star_expression + OP_RULE, R_STAR_EXPRESSION, + OP_LOOP_COLLECT_DELIMITED, + + }, + }, + {"_loop1_58", + R__LOOP1_58, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // (',' star_expression) + OP_RULE, R__TMP_118, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT_NONEMPTY, + + }, + }, + {"_gather_59", + R__GATHER_59, + 0, // memo + 0, // leftrec + {0, 5, -1}, + { + // star_named_expression ',' + OP_RULE, R_STAR_NAMED_EXPRESSION, + OP_TOKEN, COMMA, + OP_LOOP_ITERATE, + + // star_named_expression + OP_RULE, R_STAR_NAMED_EXPRESSION, + OP_LOOP_COLLECT_DELIMITED, + + }, + }, + {"_loop1_60", + R__LOOP1_60, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // (',' expression) + OP_RULE, R__TMP_119, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT_NONEMPTY, + + }, + }, + {"_loop0_61", + R__LOOP0_61, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // lambda_param_no_default + OP_RULE, R_LAMBDA_PARAM_NO_DEFAULT, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT, + + }, + }, + {"_loop0_62", + R__LOOP0_62, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // lambda_param_with_default + OP_RULE, R_LAMBDA_PARAM_WITH_DEFAULT, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT, + + }, + }, + {"_loop0_63", + R__LOOP0_63, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // lambda_param_with_default + OP_RULE, R_LAMBDA_PARAM_WITH_DEFAULT, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT, + + }, + }, + {"_loop1_64", + R__LOOP1_64, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // lambda_param_no_default + OP_RULE, R_LAMBDA_PARAM_NO_DEFAULT, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT_NONEMPTY, + + }, + }, + {"_loop0_65", + R__LOOP0_65, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // lambda_param_with_default + OP_RULE, R_LAMBDA_PARAM_WITH_DEFAULT, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT, + + }, + }, + {"_loop1_66", + R__LOOP1_66, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // lambda_param_with_default + OP_RULE, R_LAMBDA_PARAM_WITH_DEFAULT, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT_NONEMPTY, + + }, + }, + {"_loop1_67", + R__LOOP1_67, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // lambda_param_no_default + OP_RULE, R_LAMBDA_PARAM_NO_DEFAULT, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT_NONEMPTY, + + }, + }, + {"_loop1_68", + R__LOOP1_68, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // lambda_param_no_default + OP_RULE, R_LAMBDA_PARAM_NO_DEFAULT, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT_NONEMPTY, + + }, + }, + {"_loop0_69", + R__LOOP0_69, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // lambda_param_no_default + OP_RULE, R_LAMBDA_PARAM_NO_DEFAULT, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT, + + }, + }, + {"_loop1_70", + R__LOOP1_70, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // lambda_param_with_default + OP_RULE, R_LAMBDA_PARAM_WITH_DEFAULT, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT_NONEMPTY, + + }, + }, + {"_loop0_71", + R__LOOP0_71, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // lambda_param_no_default + OP_RULE, R_LAMBDA_PARAM_NO_DEFAULT, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT, + + }, + }, + {"_loop1_72", + R__LOOP1_72, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // lambda_param_with_default + OP_RULE, R_LAMBDA_PARAM_WITH_DEFAULT, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT_NONEMPTY, + + }, + }, + {"_loop0_73", + R__LOOP0_73, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // lambda_param_maybe_default + OP_RULE, R_LAMBDA_PARAM_MAYBE_DEFAULT, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT, + + }, + }, + {"_loop1_74", + R__LOOP1_74, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // lambda_param_maybe_default + OP_RULE, R_LAMBDA_PARAM_MAYBE_DEFAULT, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT_NONEMPTY, + + }, + }, + {"_loop1_75", + R__LOOP1_75, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // ('or' conjunction) + OP_RULE, R__TMP_120, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT_NONEMPTY, + + }, + }, + {"_loop1_76", + R__LOOP1_76, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // ('and' inversion) + OP_RULE, R__TMP_121, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT_NONEMPTY, + + }, + }, + {"_loop1_77", + R__LOOP1_77, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // compare_op_bitwise_or_pair + OP_RULE, R_COMPARE_OP_BITWISE_OR_PAIR, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT_NONEMPTY, + + }, + }, + {"_tmp_78", + R__TMP_78, + 0, // memo + 0, // leftrec + {0, -1}, + { + // '!=' + OP_TOKEN, NOTEQUAL, + OP_RETURN, A__TMP_78_0, + + }, + }, + {"_gather_79", + R__GATHER_79, + 0, // memo + 0, // leftrec + {0, 5, -1}, + { + // slice ',' + OP_RULE, R_SLICE, + OP_TOKEN, COMMA, + OP_LOOP_ITERATE, + + // slice + OP_RULE, R_SLICE, + OP_LOOP_COLLECT_DELIMITED, + + }, + }, + {"_tmp_80", + R__TMP_80, + 0, // memo + 0, // leftrec + {0, -1}, + { + // ':' expression? + OP_TOKEN, COLON, + OP_RULE, R_EXPRESSION, + OP_OPTIONAL, + OP_RETURN, A__TMP_80_0, + + }, + }, + {"_tmp_81", + R__TMP_81, + 0, // memo + 0, // leftrec + {0, 4, 8, -1}, + { + // tuple + OP_RULE, R_TUPLE, + OP_RETURN, A__TMP_81_0, + + // group + OP_RULE, R_GROUP, + OP_RETURN, A__TMP_81_1, + + // genexp + OP_RULE, R_GENEXP, + OP_RETURN, A__TMP_81_2, + + }, + }, + {"_tmp_82", + R__TMP_82, + 0, // memo + 0, // leftrec + {0, 4, -1}, + { + // list + OP_RULE, R_LIST, + OP_RETURN, A__TMP_82_0, + + // listcomp + OP_RULE, R_LISTCOMP, + OP_RETURN, A__TMP_82_1, + + }, + }, + {"_tmp_83", + R__TMP_83, + 0, // memo + 0, // leftrec + {0, 4, 8, 12, -1}, + { + // dict + OP_RULE, R_DICT, + OP_RETURN, A__TMP_83_0, + + // set + OP_RULE, R_SET, + OP_RETURN, A__TMP_83_1, + + // dictcomp + OP_RULE, R_DICTCOMP, + OP_RETURN, A__TMP_83_2, + + // setcomp + OP_RULE, R_SETCOMP, + OP_RETURN, A__TMP_83_3, + + }, + }, + {"_loop1_84", + R__LOOP1_84, + 0, // memo + 0, // leftrec + {0, 2, -1}, + { + // STRING + OP_STRING, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT_NONEMPTY, + + }, + }, + {"_tmp_85", + R__TMP_85, + 0, // memo + 0, // leftrec + {0, -1}, + { + // star_named_expression ',' star_named_expressions? + OP_RULE, R_STAR_NAMED_EXPRESSION, + OP_TOKEN, COMMA, + OP_RULE, R_STAR_NAMED_EXPRESSIONS, + OP_OPTIONAL, + OP_RETURN, A__TMP_85_0, + + }, + }, + {"_tmp_86", + R__TMP_86, + 0, // memo + 0, // leftrec + {0, 4, -1}, + { + // yield_expr + OP_RULE, R_YIELD_EXPR, + OP_RETURN, A__TMP_86_0, + + // named_expression + OP_RULE, R_NAMED_EXPRESSION, + OP_RETURN, A__TMP_86_1, + + }, + }, + {"_gather_87", + R__GATHER_87, + 0, // memo + 0, // leftrec + {0, 5, -1}, + { + // double_starred_kvpair ',' + OP_RULE, R_DOUBLE_STARRED_KVPAIR, + OP_TOKEN, COMMA, + OP_LOOP_ITERATE, + + // double_starred_kvpair + OP_RULE, R_DOUBLE_STARRED_KVPAIR, + OP_LOOP_COLLECT_DELIMITED, + + }, + }, + {"_loop1_88", + R__LOOP1_88, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // for_if_clause + OP_RULE, R_FOR_IF_CLAUSE, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT_NONEMPTY, + + }, + }, + {"_loop0_89", + R__LOOP0_89, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // ('if' disjunction) + OP_RULE, R__TMP_122, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT, + + }, + }, + {"_loop0_90", + R__LOOP0_90, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // ('if' disjunction) + OP_RULE, R__TMP_123, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT, + + }, + }, + {"_tmp_91", + R__TMP_91, + 0, // memo + 0, // leftrec + {0, -1}, + { + // ',' args + OP_TOKEN, COMMA, + OP_RULE, R_ARGS, + OP_RETURN, A__TMP_91_0, + + }, + }, + {"_tmp_92", + R__TMP_92, + 0, // memo + 0, // leftrec + {0, -1}, + { + // ',' args + OP_TOKEN, COMMA, + OP_RULE, R_ARGS, + OP_RETURN, A__TMP_92_0, + + }, + }, + {"_gather_93", + R__GATHER_93, + 0, // memo + 0, // leftrec + {0, 5, -1}, + { + // kwarg_or_starred ',' + OP_RULE, R_KWARG_OR_STARRED, + OP_TOKEN, COMMA, + OP_LOOP_ITERATE, + + // kwarg_or_starred + OP_RULE, R_KWARG_OR_STARRED, + OP_LOOP_COLLECT_DELIMITED, + + }, + }, + {"_gather_94", + R__GATHER_94, + 0, // memo + 0, // leftrec + {0, 5, -1}, + { + // kwarg_or_double_starred ',' + OP_RULE, R_KWARG_OR_DOUBLE_STARRED, + OP_TOKEN, COMMA, + OP_LOOP_ITERATE, + + // kwarg_or_double_starred + OP_RULE, R_KWARG_OR_DOUBLE_STARRED, + OP_LOOP_COLLECT_DELIMITED, + + }, + }, + {"_gather_95", + R__GATHER_95, + 0, // memo + 0, // leftrec + {0, 5, -1}, + { + // kwarg_or_starred ',' + OP_RULE, R_KWARG_OR_STARRED, + OP_TOKEN, COMMA, + OP_LOOP_ITERATE, + + // kwarg_or_starred + OP_RULE, R_KWARG_OR_STARRED, + OP_LOOP_COLLECT_DELIMITED, + + }, + }, + {"_gather_96", + R__GATHER_96, + 0, // memo + 0, // leftrec + {0, 5, -1}, + { + // kwarg_or_double_starred ',' + OP_RULE, R_KWARG_OR_DOUBLE_STARRED, + OP_TOKEN, COMMA, + OP_LOOP_ITERATE, + + // kwarg_or_double_starred + OP_RULE, R_KWARG_OR_DOUBLE_STARRED, + OP_LOOP_COLLECT_DELIMITED, + + }, + }, + {"_loop0_97", + R__LOOP0_97, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // (',' star_target) + OP_RULE, R__TMP_124, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT, + + }, + }, + {"_gather_98", + R__GATHER_98, + 0, // memo + 0, // leftrec + {0, 5, -1}, + { + // star_target ',' + OP_RULE, R_STAR_TARGET, + OP_TOKEN, COMMA, + OP_LOOP_ITERATE, + + // star_target + OP_RULE, R_STAR_TARGET, + OP_LOOP_COLLECT_DELIMITED, + + }, + }, + {"_tmp_99", + R__TMP_99, + 0, // memo + 0, // leftrec + {0, -1}, + { + // !'*' star_target + OP_SAVE_MARK, + OP_TOKEN, STAR, + OP_NEG_LOOKAHEAD, + OP_RULE, R_STAR_TARGET, + OP_RETURN, A__TMP_99_0, + + }, + }, + {"_gather_100", + R__GATHER_100, + 0, // memo + 0, // leftrec + {0, 5, -1}, + { + // del_target ',' + OP_RULE, R_DEL_TARGET, + OP_TOKEN, COMMA, + OP_LOOP_ITERATE, + + // del_target + OP_RULE, R_DEL_TARGET, + OP_LOOP_COLLECT_DELIMITED, + + }, + }, + {"_gather_101", + R__GATHER_101, + 0, // memo + 0, // leftrec + {0, 5, -1}, + { + // target ',' + OP_RULE, R_TARGET, + OP_TOKEN, COMMA, + OP_LOOP_ITERATE, + + // target + OP_RULE, R_TARGET, + OP_LOOP_COLLECT_DELIMITED, + + }, + }, + {"_tmp_102", + R__TMP_102, + 0, // memo + 0, // leftrec + {0, 4, -1}, + { + // args + OP_RULE, R_ARGS, + OP_RETURN, A__TMP_102_0, + + // expression for_if_clauses + OP_RULE, R_EXPRESSION, + OP_RULE, R_FOR_IF_CLAUSES, + OP_RETURN, A__TMP_102_1, + + }, + }, + {"_loop0_103", + R__LOOP0_103, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // star_named_expressions + OP_RULE, R_STAR_NAMED_EXPRESSIONS, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT, + + }, + }, + {"_loop0_104", + R__LOOP0_104, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // (star_targets '=') + OP_RULE, R__TMP_125, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT, + + }, + }, + {"_loop0_105", + R__LOOP0_105, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // (star_targets '=') + OP_RULE, R__TMP_126, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT, + + }, + }, + {"_tmp_106", + R__TMP_106, + 0, // memo + 0, // leftrec + {0, 4, -1}, + { + // yield_expr + OP_RULE, R_YIELD_EXPR, + OP_RETURN, A__TMP_106_0, + + // star_expressions + OP_RULE, R_STAR_EXPRESSIONS, + OP_RETURN, A__TMP_106_1, + + }, + }, + {"_tmp_107", + R__TMP_107, + 0, // memo + 0, // leftrec + {0, 4, 8, -1}, + { + // '[' + OP_TOKEN, LSQB, + OP_RETURN, A__TMP_107_0, + + // '(' + OP_TOKEN, LPAR, + OP_RETURN, A__TMP_107_1, + + // '{' + OP_TOKEN, LBRACE, + OP_RETURN, A__TMP_107_2, + + }, + }, + {"_loop0_108", + R__LOOP0_108, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // param_no_default + OP_RULE, R_PARAM_NO_DEFAULT, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT, + + }, + }, + {"_tmp_109", + R__TMP_109, + 0, // memo + 0, // leftrec + {0, 4, -1}, + { + // slash_with_default + OP_RULE, R_SLASH_WITH_DEFAULT, + OP_RETURN, A__TMP_109_0, + + // param_with_default+ + OP_RULE, R__LOOP1_127, + OP_RETURN, A__TMP_109_1, + + }, + }, + {"_loop0_110", + R__LOOP0_110, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // lambda_param_no_default + OP_RULE, R_LAMBDA_PARAM_NO_DEFAULT, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT, + + }, + }, + {"_tmp_111", + R__TMP_111, + 0, // memo + 0, // leftrec + {0, 4, -1}, + { + // lambda_slash_with_default + OP_RULE, R_LAMBDA_SLASH_WITH_DEFAULT, + OP_RETURN, A__TMP_111_0, + + // lambda_param_with_default+ + OP_RULE, R__LOOP1_128, + OP_RETURN, A__TMP_111_1, + + }, + }, + {"_tmp_112", + R__TMP_112, + 0, // memo + 0, // leftrec + {0, 4, -1}, + { + // ')' + OP_TOKEN, RPAR, + OP_RETURN, A__TMP_112_0, + + // ',' (')' | '**') + OP_TOKEN, COMMA, + OP_RULE, R__TMP_129, + OP_RETURN, A__TMP_112_1, + + }, + }, + {"_tmp_113", + R__TMP_113, + 0, // memo + 0, // leftrec + {0, 4, -1}, + { + // ':' + OP_TOKEN, COLON, + OP_RETURN, A__TMP_113_0, + + // ',' (':' | '**') + OP_TOKEN, COMMA, + OP_RULE, R__TMP_130, + OP_RETURN, A__TMP_113_1, + + }, + }, + {"_tmp_114", + R__TMP_114, + 0, // memo + 0, // leftrec + {0, -1}, + { + // star_targets '=' + OP_RULE, R_STAR_TARGETS, + OP_TOKEN, EQUAL, + OP_RETURN, A__TMP_114_0, + + }, + }, + {"_tmp_115", + R__TMP_115, + 0, // memo + 0, // leftrec + {0, 4, -1}, + { + // '.' + OP_TOKEN, DOT, + OP_RETURN, A__TMP_115_0, + + // '...' + OP_TOKEN, ELLIPSIS, + OP_RETURN, A__TMP_115_1, + + }, + }, + {"_tmp_116", + R__TMP_116, + 0, // memo + 0, // leftrec + {0, 4, -1}, + { + // '.' + OP_TOKEN, DOT, + OP_RETURN, A__TMP_116_0, + + // '...' + OP_TOKEN, ELLIPSIS, + OP_RETURN, A__TMP_116_1, + + }, + }, + {"_tmp_117", + R__TMP_117, + 0, // memo + 0, // leftrec + {0, -1}, + { + // '@' named_expression NEWLINE + OP_TOKEN, AT, + OP_RULE, R_NAMED_EXPRESSION, + OP_TOKEN, NEWLINE, + OP_RETURN, A__TMP_117_0, + + }, + }, + {"_tmp_118", + R__TMP_118, + 0, // memo + 0, // leftrec + {0, -1}, + { + // ',' star_expression + OP_TOKEN, COMMA, + OP_RULE, R_STAR_EXPRESSION, + OP_RETURN, A__TMP_118_0, + + }, + }, + {"_tmp_119", + R__TMP_119, + 0, // memo + 0, // leftrec + {0, -1}, + { + // ',' expression + OP_TOKEN, COMMA, + OP_RULE, R_EXPRESSION, + OP_RETURN, A__TMP_119_0, + + }, + }, + {"_tmp_120", + R__TMP_120, + 0, // memo + 0, // leftrec + {0, -1}, + { + // 'or' conjunction + OP_TOKEN, 531, + OP_RULE, R_CONJUNCTION, + OP_RETURN, A__TMP_120_0, + + }, + }, + {"_tmp_121", + R__TMP_121, + 0, // memo + 0, // leftrec + {0, -1}, + { + // 'and' inversion + OP_TOKEN, 532, + OP_RULE, R_INVERSION, + OP_RETURN, A__TMP_121_0, + + }, + }, + {"_tmp_122", + R__TMP_122, + 0, // memo + 0, // leftrec + {0, -1}, + { + // 'if' disjunction + OP_TOKEN, 510, + OP_RULE, R_DISJUNCTION, + OP_RETURN, A__TMP_122_0, + + }, + }, + {"_tmp_123", + R__TMP_123, + 0, // memo + 0, // leftrec + {0, -1}, + { + // 'if' disjunction + OP_TOKEN, 510, + OP_RULE, R_DISJUNCTION, + OP_RETURN, A__TMP_123_0, + + }, + }, + {"_tmp_124", + R__TMP_124, + 0, // memo + 0, // leftrec + {0, -1}, + { + // ',' star_target + OP_TOKEN, COMMA, + OP_RULE, R_STAR_TARGET, + OP_RETURN, A__TMP_124_0, + + }, + }, + {"_tmp_125", + R__TMP_125, + 0, // memo + 0, // leftrec + {0, -1}, + { + // star_targets '=' + OP_RULE, R_STAR_TARGETS, + OP_TOKEN, EQUAL, + OP_RETURN, A__TMP_125_0, + + }, + }, + {"_tmp_126", + R__TMP_126, + 0, // memo + 0, // leftrec + {0, -1}, + { + // star_targets '=' + OP_RULE, R_STAR_TARGETS, + OP_TOKEN, EQUAL, + OP_RETURN, A__TMP_126_0, + + }, + }, + {"_loop1_127", + R__LOOP1_127, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // param_with_default + OP_RULE, R_PARAM_WITH_DEFAULT, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT_NONEMPTY, + + }, + }, + {"_loop1_128", + R__LOOP1_128, + 0, // memo + 0, // leftrec + {0, 3, -1}, + { + // lambda_param_with_default + OP_RULE, R_LAMBDA_PARAM_WITH_DEFAULT, + OP_LOOP_ITERATE, + + // + OP_LOOP_COLLECT_NONEMPTY, + + }, + }, + {"_tmp_129", + R__TMP_129, + 0, // memo + 0, // leftrec + {0, 4, -1}, + { + // ')' + OP_TOKEN, RPAR, + OP_RETURN, A__TMP_129_0, + + // '**' + OP_TOKEN, DOUBLESTAR, + OP_RETURN, A__TMP_129_1, + + }, + }, + {"_tmp_130", + R__TMP_130, + 0, // memo + 0, // leftrec + {0, 4, -1}, + { + // ':' + OP_TOKEN, COLON, + OP_RETURN, A__TMP_130_0, + + // '**' + OP_TOKEN, DOUBLESTAR, + OP_RETURN, A__TMP_130_1, + + }, + }, +}; + +static void * +call_action(Parser *p, Frame *_f, int _iaction) +{ + assert(p->mark > 0); + Token *_t = p->tokens[_f->mark]; + int _start_lineno = _t->lineno; + int _start_col_offset = _t->col_offset; + _t = p->tokens[p->mark - 1]; + int _end_lineno = _t->end_lineno; + int _end_col_offset = _t->end_col_offset; + + switch (_iaction) { + case A_FILE_0: + return _PyPegen_make_module ( p , _f->vals[0] ); + case A_INTERACTIVE_0: + return Interactive ( ((asdl_seq*)_f->vals[0]) , p -> arena ); + case A_EVAL_0: + return Expression ( ((expr_ty)_f->vals[0]) , p -> arena ); + case A_FUNC_TYPE_0: + return FunctionType ( _f->vals[1] , ((expr_ty)_f->vals[4]) , p -> arena ); + case A_FSTRING_0: + case A_DOTTED_NAME_1: + case A_STAR_EXPRESSIONS_2: + case A_STAR_EXPRESSION_1: + case A_STAR_NAMED_EXPRESSION_1: + case A_NAMED_EXPRESSION_1: + case A_ANNOTATED_RHS_0: + case A_ANNOTATED_RHS_1: + case A_EXPRESSIONS_2: + case A_EXPRESSION_1: + case A_EXPRESSION_2: + case A_DISJUNCTION_1: + case A_CONJUNCTION_1: + case A_INVERSION_1: + case A_COMPARISON_1: + case A_BITWISE_OR_1: + case A_BITWISE_XOR_1: + case A_BITWISE_AND_1: + case A_SHIFT_EXPR_2: + case A_SUM_2: + case A_TERM_5: + case A_FACTOR_3: + case A_POWER_1: + case A_AWAIT_PRIMARY_1: + case A_PRIMARY_4: + case A_SLICES_0: + case A_SLICE_1: + case A_ATOM_0: + case A_ARGUMENTS_0: + case A_STAR_TARGETS_0: + case A_STAR_TARGET_3: + case A_SINGLE_TARGET_0: + case A_DEL_TARGET_2: + case A_TARGET_2: + case A_T_PRIMARY_4: + case A_INVALID_ANN_ASSIGN_TARGET_0: + case A_INVALID_ANN_ASSIGN_TARGET_1: + case A__GATHER_3_0: + case A__GATHER_3_1: + case A__GATHER_4_0: + case A__GATHER_4_1: + case A__GATHER_5_0: + case A__GATHER_5_1: + case A__GATHER_6_0: + case A__GATHER_6_1: + case A__TMP_15_1: + case A__TMP_18_0: + case A__TMP_18_1: + case A__TMP_19_0: + case A__TMP_19_1: + case A__GATHER_20_0: + case A__GATHER_20_1: + case A__GATHER_21_0: + case A__GATHER_21_1: + case A__GATHER_57_0: + case A__GATHER_57_1: + case A__GATHER_59_0: + case A__GATHER_59_1: + case A__GATHER_79_0: + case A__GATHER_79_1: + case A__TMP_81_0: + case A__TMP_81_1: + case A__TMP_81_2: + case A__TMP_82_0: + case A__TMP_82_1: + case A__TMP_83_0: + case A__TMP_83_1: + case A__TMP_83_2: + case A__TMP_83_3: + case A__TMP_86_0: + case A__TMP_86_1: + case A__GATHER_98_0: + case A__GATHER_98_1: + case A__GATHER_100_0: + case A__GATHER_100_1: + case A__GATHER_101_0: + case A__GATHER_101_1: + case A__TMP_102_0: + case A__TMP_102_1: + case A__TMP_106_0: + case A__TMP_106_1: + case A__TMP_114_0: + case A__TMP_125_0: + case A__TMP_126_0: + return ((expr_ty)_f->vals[0]); + case A_TYPE_EXPRESSIONS_0: + return _PyPegen_seq_append_to_end ( p , CHECK ( _PyPegen_seq_append_to_end ( p , _f->vals[0] , ((expr_ty)_f->vals[3]) ) ) , ((expr_ty)_f->vals[6]) ); + case A_TYPE_EXPRESSIONS_1: + case A_TYPE_EXPRESSIONS_2: + return _PyPegen_seq_append_to_end ( p , _f->vals[0] , ((expr_ty)_f->vals[3]) ); + case A_TYPE_EXPRESSIONS_3: + return _PyPegen_seq_append_to_end ( p , CHECK ( _PyPegen_singleton_seq ( p , ((expr_ty)_f->vals[1]) ) ) , ((expr_ty)_f->vals[4]) ); + case A_TYPE_EXPRESSIONS_4: + case A_TYPE_EXPRESSIONS_5: + return _PyPegen_singleton_seq ( p , ((expr_ty)_f->vals[1]) ); + case A_TYPE_EXPRESSIONS_6: + case A_SIMPLE_STMT_1: + case A_SMALL_STMT_2: + case A_SMALL_STMT_3: + case A_SMALL_STMT_4: + case A_SMALL_STMT_6: + case A_SMALL_STMT_7: + case A_SMALL_STMT_8: + case A_SMALL_STMT_11: + case A_SMALL_STMT_12: + case A_COMPOUND_STMT_0: + case A_COMPOUND_STMT_1: + case A_COMPOUND_STMT_2: + case A_COMPOUND_STMT_3: + case A_COMPOUND_STMT_4: + case A_COMPOUND_STMT_5: + case A_COMPOUND_STMT_6: + case A_ASSIGNMENT_4: + case A_DEL_STMT_1: + case A_IMPORT_FROM_TARGETS_3: + case A_IMPORT_FROM_AS_NAMES_0: + case A_DOTTED_AS_NAMES_0: + case A_FOR_STMT_2: + case A_WITH_ITEM_1: + case A_FUNC_TYPE_COMMENT_1: + case A_FUNC_TYPE_COMMENT_2: + case A_PARAMS_0: + case A_SLASH_NO_DEFAULT_0: + case A_SLASH_NO_DEFAULT_1: + case A_STAR_ETC_3: + case A_DECORATORS_0: + case A_BLOCK_2: + case A_EXPRESSIONS_LIST_0: + case A_STAR_NAMED_EXPRESSIONS_0: + case A_NAMED_EXPRESSION_2: + case A_LAMBDA_PARAMS_0: + case A_LAMBDA_SLASH_NO_DEFAULT_0: + case A_LAMBDA_SLASH_NO_DEFAULT_1: + case A_LAMBDA_STAR_ETC_3: + case A_ATOM_4: + case A_ATOM_5: + case A_ATOM_6: + case A_ATOM_7: + case A_ATOM_8: + case A_LISTCOMP_1: + case A_GROUP_1: + case A_GENEXP_1: + case A_SETCOMP_1: + case A_DICTCOMP_1: + case A_DOUBLE_STARRED_KVPAIRS_0: + case A_FOR_IF_CLAUSES_0: + case A_FOR_IF_CLAUSE_2: + case A_ARGUMENTS_1: + case A_KWARGS_1: + case A_KWARGS_2: + case A_KWARG_OR_STARRED_2: + case A_KWARG_OR_DOUBLE_STARRED_2: + case A_STAR_TARGETS_SEQ_0: + case A_DEL_TARGETS_0: + case A_TARGETS_0: + case A__TMP_10_2: + case A__TMP_12_1: + case A__TMP_13_1: + case A__TMP_23_1: + case A__TMP_40_0: + case A__TMP_99_0: + case A__TMP_109_1: + case A__TMP_111_1: + return _f->vals[0]; + case A_STATEMENTS_0: + return _PyPegen_seq_flatten ( p , _f->vals[0] ); + case A_STATEMENT_0: + case A_STATEMENT_NEWLINE_0: + case A_SIMPLE_STMT_0: + return _PyPegen_singleton_seq ( p , ((stmt_ty)_f->vals[0]) ); + case A_STATEMENT_1: + case A_STATEMENT_NEWLINE_1: + case A_IMPORT_FROM_TARGETS_1: + case A_BLOCK_1: + return ((asdl_seq*)_f->vals[0]); + case A_STATEMENT_NEWLINE_2: + return _PyPegen_singleton_seq ( p , CHECK ( _Py_Pass ( EXTRA ) ) ); + case A_STATEMENT_NEWLINE_3: + return _PyPegen_interactive_exit ( p ); + case A_SMALL_STMT_0: + case A_IMPORT_STMT_0: + case A_IMPORT_STMT_1: + case A_FUNCTION_DEF_1: + case A_CLASS_DEF_1: + case A__GATHER_8_0: + case A__GATHER_8_1: + return ((stmt_ty)_f->vals[0]); + case A_SMALL_STMT_1: + case A_YIELD_STMT_0: + return _Py_Expr ( ((expr_ty)_f->vals[0]) , EXTRA ); + case A_SMALL_STMT_5: + return _Py_Pass ( EXTRA ); + case A_SMALL_STMT_9: + return _Py_Break ( EXTRA ); + case A_SMALL_STMT_10: + return _Py_Continue ( EXTRA ); + case A_ASSIGNMENT_0: + return CHECK_VERSION ( 6 , "Variable annotation syntax is" , _Py_AnnAssign ( CHECK ( _PyPegen_set_expr_context ( p , ((expr_ty)_f->vals[0]) , Store ) ) , ((expr_ty)_f->vals[2]) , _f->vals[3] , 1 , EXTRA ) ); + case A_ASSIGNMENT_1: + return CHECK_VERSION ( 6 , "Variable annotations syntax is" , _Py_AnnAssign ( _f->vals[0] , ((expr_ty)_f->vals[2]) , _f->vals[3] , 0 , EXTRA ) ); + case A_ASSIGNMENT_2: + return _Py_Assign ( _f->vals[0] , _f->vals[1] , NEW_TYPE_COMMENT ( p , _f->vals[2] ) , EXTRA ); + case A_ASSIGNMENT_3: + return _Py_AugAssign ( ((expr_ty)_f->vals[0]) , ((AugOperator*)_f->vals[1]) -> kind , _f->vals[2] , EXTRA ); + case A_AUGASSIGN_0: + return _PyPegen_augoperator ( p , Add ); + case A_AUGASSIGN_1: + return _PyPegen_augoperator ( p , Sub ); + case A_AUGASSIGN_2: + return _PyPegen_augoperator ( p , Mult ); + case A_AUGASSIGN_3: + return CHECK_VERSION ( 5 , "The '@' operator is" , _PyPegen_augoperator ( p , MatMult ) ); + case A_AUGASSIGN_4: + return _PyPegen_augoperator ( p , Div ); + case A_AUGASSIGN_5: + return _PyPegen_augoperator ( p , Mod ); + case A_AUGASSIGN_6: + return _PyPegen_augoperator ( p , BitAnd ); + case A_AUGASSIGN_7: + return _PyPegen_augoperator ( p , BitOr ); + case A_AUGASSIGN_8: + return _PyPegen_augoperator ( p , BitXor ); + case A_AUGASSIGN_9: + return _PyPegen_augoperator ( p , LShift ); + case A_AUGASSIGN_10: + return _PyPegen_augoperator ( p , RShift ); + case A_AUGASSIGN_11: + return _PyPegen_augoperator ( p , Pow ); + case A_AUGASSIGN_12: + return _PyPegen_augoperator ( p , FloorDiv ); + case A_GLOBAL_STMT_0: + return _Py_Global ( CHECK ( _PyPegen_map_names_to_ids ( p , _f->vals[1] ) ) , EXTRA ); + case A_NONLOCAL_STMT_0: + return _Py_Nonlocal ( CHECK ( _PyPegen_map_names_to_ids ( p , _f->vals[1] ) ) , EXTRA ); + case A_ASSERT_STMT_0: + return _Py_Assert ( ((expr_ty)_f->vals[1]) , _f->vals[2] , EXTRA ); + case A_DEL_STMT_0: + return _Py_Delete ( ((asdl_seq*)_f->vals[1]) , EXTRA ); + case A_IMPORT_NAME_0: + return _Py_Import ( ((asdl_seq*)_f->vals[1]) , EXTRA ); + case A_IMPORT_FROM_0: + return _Py_ImportFrom ( ((expr_ty)_f->vals[2]) -> v . Name . id , ((asdl_seq*)_f->vals[4]) , _PyPegen_seq_count_dots ( _f->vals[1] ) , EXTRA ); + case A_IMPORT_FROM_1: + return _Py_ImportFrom ( NULL , ((asdl_seq*)_f->vals[3]) , _PyPegen_seq_count_dots ( _f->vals[1] ) , EXTRA ); + case A_IMPORT_FROM_TARGETS_0: + return ((asdl_seq*)_f->vals[1]); + case A_IMPORT_FROM_TARGETS_2: + return _PyPegen_singleton_seq ( p , CHECK ( _PyPegen_alias_for_star ( p ) ) ); + case A_IMPORT_FROM_AS_NAME_0: + case A_DOTTED_AS_NAME_0: + return _Py_alias ( ((expr_ty)_f->vals[0]) -> v . Name . id , ( _f->vals[1] ) ? ( ( expr_ty ) _f->vals[1] ) -> v . Name . id : NULL , p -> arena ); + case A_DOTTED_NAME_0: + return _PyPegen_join_names_with_dot ( p , ((expr_ty)_f->vals[0]) , ((expr_ty)_f->vals[2]) ); + case A_IF_STMT_0: + case A_ELIF_STMT_0: + return _Py_If ( ((expr_ty)_f->vals[1]) , ((asdl_seq*)_f->vals[3]) , CHECK ( _PyPegen_singleton_seq ( p , ((stmt_ty)_f->vals[4]) ) ) , EXTRA ); + case A_IF_STMT_1: + case A_ELIF_STMT_1: + return _Py_If ( ((expr_ty)_f->vals[1]) , ((asdl_seq*)_f->vals[3]) , _f->vals[4] , EXTRA ); + case A_ELSE_BLOCK_0: + case A_FINALLY_BLOCK_0: + case A_BLOCK_0: + return ((asdl_seq*)_f->vals[2]); + case A_WHILE_STMT_0: + return _Py_While ( ((expr_ty)_f->vals[1]) , ((asdl_seq*)_f->vals[3]) , _f->vals[4] , EXTRA ); + case A_FOR_STMT_0: + return _Py_For ( ((expr_ty)_f->vals[1]) , _f->vals[3] , _f->vals[6] , ((asdl_seq*)_f->vals[7]) , NEW_TYPE_COMMENT ( p , ((Token *)_f->vals[5]) ) , EXTRA ); + case A_FOR_STMT_1: + return CHECK_VERSION ( 5 , "Async for loops are" , _Py_AsyncFor ( ((expr_ty)_f->vals[2]) , _f->vals[4] , _f->vals[7] , ((asdl_seq*)_f->vals[8]) , NEW_TYPE_COMMENT ( p , ((Token *)_f->vals[6]) ) , EXTRA ) ); + case A_WITH_STMT_0: + return _Py_With ( _f->vals[2] , ((asdl_seq*)_f->vals[6]) , NULL , EXTRA ); + case A_WITH_STMT_1: + return _Py_With ( _f->vals[1] , ((asdl_seq*)_f->vals[4]) , NEW_TYPE_COMMENT ( p , _f->vals[3] ) , EXTRA ); + case A_WITH_STMT_2: + return CHECK_VERSION ( 5 , "Async with statements are" , _Py_AsyncWith ( _f->vals[3] , ((asdl_seq*)_f->vals[7]) , NULL , EXTRA ) ); + case A_WITH_STMT_3: + return CHECK_VERSION ( 5 , "Async with statements are" , _Py_AsyncWith ( _f->vals[2] , ((asdl_seq*)_f->vals[5]) , NEW_TYPE_COMMENT ( p , _f->vals[4] ) , EXTRA ) ); + case A_WITH_ITEM_0: + return _Py_withitem ( ((expr_ty)_f->vals[0]) , ((expr_ty)_f->vals[2]) , p -> arena ); + case A_WITH_ITEM_2: + return _Py_withitem ( ((expr_ty)_f->vals[0]) , NULL , p -> arena ); + case A_TRY_STMT_0: + return _Py_Try ( ((asdl_seq*)_f->vals[2]) , NULL , NULL , ((asdl_seq*)_f->vals[3]) , EXTRA ); + case A_TRY_STMT_1: + return _Py_Try ( ((asdl_seq*)_f->vals[2]) , _f->vals[3] , _f->vals[4] , _f->vals[5] , EXTRA ); + case A_EXCEPT_BLOCK_0: + return _Py_ExceptHandler ( ((expr_ty)_f->vals[1]) , ( _f->vals[2] ) ? ( ( expr_ty ) _f->vals[2] ) -> v . Name . id : NULL , ((asdl_seq*)_f->vals[4]) , EXTRA ); + case A_EXCEPT_BLOCK_1: + return _Py_ExceptHandler ( NULL , NULL , ((asdl_seq*)_f->vals[2]) , EXTRA ); + case A_RETURN_STMT_0: + return _Py_Return ( _f->vals[1] , EXTRA ); + case A_RAISE_STMT_0: + return _Py_Raise ( ((expr_ty)_f->vals[1]) , _f->vals[2] , EXTRA ); + case A_RAISE_STMT_1: + return _Py_Raise ( NULL , NULL , EXTRA ); + case A_FUNCTION_DEF_0: + return _PyPegen_function_def_decorators ( p , ((asdl_seq*)_f->vals[0]) , ((stmt_ty)_f->vals[1]) ); + case A_FUNCTION_DEF_RAW_0: + return _Py_FunctionDef ( ((expr_ty)_f->vals[1]) -> v . Name . id , ( _f->vals[3] ) ? _f->vals[3] : CHECK ( _PyPegen_empty_arguments ( p ) ) , ((asdl_seq*)_f->vals[8]) , NULL , _f->vals[5] , NEW_TYPE_COMMENT ( p , _f->vals[7] ) , EXTRA ); + case A_FUNCTION_DEF_RAW_1: + return CHECK_VERSION ( 5 , "Async functions are" , _Py_AsyncFunctionDef ( ((expr_ty)_f->vals[2]) -> v . Name . id , ( _f->vals[4] ) ? _f->vals[4] : CHECK ( _PyPegen_empty_arguments ( p ) ) , ((asdl_seq*)_f->vals[9]) , NULL , _f->vals[6] , NEW_TYPE_COMMENT ( p , _f->vals[8] ) , EXTRA ) ); + case A_FUNC_TYPE_COMMENT_0: + case A_GROUP_0: + case A__TMP_56_0: + case A__TMP_80_0: + return _f->vals[1]; + case A_PARAMS_1: + case A_LAMBDA_PARAMS_1: + return ((arguments_ty)_f->vals[0]); + case A_PARAMETERS_0: + case A_LAMBDA_PARAMETERS_0: + return _PyPegen_make_arguments ( p , ((asdl_seq*)_f->vals[0]) , NULL , _f->vals[1] , _f->vals[2] , _f->vals[3] ); + case A_PARAMETERS_1: + case A_LAMBDA_PARAMETERS_1: + return _PyPegen_make_arguments ( p , NULL , ((SlashWithDefault*)_f->vals[0]) , NULL , _f->vals[1] , _f->vals[2] ); + case A_PARAMETERS_2: + case A_LAMBDA_PARAMETERS_2: + return _PyPegen_make_arguments ( p , NULL , NULL , _f->vals[0] , _f->vals[1] , _f->vals[2] ); + case A_PARAMETERS_3: + case A_LAMBDA_PARAMETERS_3: + return _PyPegen_make_arguments ( p , NULL , NULL , NULL , _f->vals[0] , _f->vals[1] ); + case A_PARAMETERS_4: + case A_LAMBDA_PARAMETERS_4: + return _PyPegen_make_arguments ( p , NULL , NULL , NULL , NULL , ((StarEtc*)_f->vals[0]) ); + case A_SLASH_WITH_DEFAULT_0: + case A_SLASH_WITH_DEFAULT_1: + case A_LAMBDA_SLASH_WITH_DEFAULT_0: + case A_LAMBDA_SLASH_WITH_DEFAULT_1: + return _PyPegen_slash_with_default ( p , _f->vals[0] , _f->vals[1] ); + case A_STAR_ETC_0: + case A_LAMBDA_STAR_ETC_0: + return _PyPegen_star_etc ( p , ((arg_ty)_f->vals[1]) , _f->vals[2] , _f->vals[3] ); + case A_STAR_ETC_1: + case A_LAMBDA_STAR_ETC_1: + return _PyPegen_star_etc ( p , NULL , _f->vals[2] , _f->vals[3] ); + case A_STAR_ETC_2: + case A_LAMBDA_STAR_ETC_2: + return _PyPegen_star_etc ( p , NULL , NULL , ((arg_ty)_f->vals[0]) ); + case A_KWDS_0: + case A_LAMBDA_KWDS_0: + return ((arg_ty)_f->vals[1]); + case A_PARAM_NO_DEFAULT_0: + return _PyPegen_add_type_comment_to_arg ( p , ((arg_ty)_f->vals[0]) , _f->vals[2] ); + case A_PARAM_NO_DEFAULT_1: + return _PyPegen_add_type_comment_to_arg ( p , ((arg_ty)_f->vals[0]) , _f->vals[1] ); + case A_PARAM_WITH_DEFAULT_0: + return _PyPegen_name_default_pair ( p , ((arg_ty)_f->vals[0]) , ((expr_ty)_f->vals[1]) , _f->vals[3] ); + case A_PARAM_WITH_DEFAULT_1: + return _PyPegen_name_default_pair ( p , ((arg_ty)_f->vals[0]) , ((expr_ty)_f->vals[1]) , _f->vals[2] ); + case A_PARAM_MAYBE_DEFAULT_0: + return _PyPegen_name_default_pair ( p , ((arg_ty)_f->vals[0]) , _f->vals[1] , _f->vals[3] ); + case A_PARAM_MAYBE_DEFAULT_1: + return _PyPegen_name_default_pair ( p , ((arg_ty)_f->vals[0]) , _f->vals[1] , _f->vals[2] ); + case A_PARAM_0: + return _Py_arg ( ((expr_ty)_f->vals[0]) -> v . Name . id , _f->vals[1] , NULL , EXTRA ); + case A_ANNOTATION_0: + case A_DEFAULT_0: + case A_SINGLE_TARGET_2: + case A_INVALID_ANN_ASSIGN_TARGET_2: + case A__TMP_14_0: + case A__TMP_15_0: + case A__TMP_16_0: + case A__TMP_22_0: + case A__TMP_27_0: + case A__TMP_29_0: + case A__TMP_36_0: + case A__TMP_37_0: + case A__TMP_38_0: + case A__TMP_39_0: + case A__TMP_91_0: + case A__TMP_92_0: + case A__TMP_117_0: + case A__TMP_118_0: + case A__TMP_119_0: + case A__TMP_120_0: + case A__TMP_121_0: + case A__TMP_122_0: + case A__TMP_123_0: + case A__TMP_124_0: + return ((expr_ty)_f->vals[1]); + case A_CLASS_DEF_0: + return _PyPegen_class_def_decorators ( p , ((asdl_seq*)_f->vals[0]) , ((stmt_ty)_f->vals[1]) ); + case A_CLASS_DEF_RAW_0: + return _Py_ClassDef ( ((expr_ty)_f->vals[1]) -> v . Name . id , ( _f->vals[2] ) ? ( ( expr_ty ) _f->vals[2] ) -> v . Call . args : NULL , ( _f->vals[2] ) ? ( ( expr_ty ) _f->vals[2] ) -> v . Call . keywords : NULL , ((asdl_seq*)_f->vals[4]) , NULL , EXTRA ); + case A_STAR_EXPRESSIONS_0: + case A_EXPRESSIONS_0: + return _Py_Tuple ( CHECK ( _PyPegen_seq_insert_in_front ( p , ((expr_ty)_f->vals[0]) , _f->vals[1] ) ) , Load , EXTRA ); + case A_STAR_EXPRESSIONS_1: + case A_EXPRESSIONS_1: + return _Py_Tuple ( CHECK ( _PyPegen_singleton_seq ( p , ((expr_ty)_f->vals[0]) ) ) , Load , EXTRA ); + case A_STAR_EXPRESSION_0: + case A_STAR_NAMED_EXPRESSION_0: + case A_STARRED_EXPRESSION_0: + return _Py_Starred ( ((expr_ty)_f->vals[1]) , Load , EXTRA ); + case A_NAMED_EXPRESSION_0: + return _Py_NamedExpr ( CHECK ( _PyPegen_set_expr_context ( p , ((expr_ty)_f->vals[0]) , Store ) ) , _f->vals[2] , EXTRA ); + case A_EXPRESSION_0: + return _Py_IfExp ( ((expr_ty)_f->vals[2]) , ((expr_ty)_f->vals[0]) , ((expr_ty)_f->vals[4]) , EXTRA ); + case A_LAMBDEF_0: + return _Py_Lambda ( ( _f->vals[1] ) ? _f->vals[1] : CHECK ( _PyPegen_empty_arguments ( p ) ) , ((expr_ty)_f->vals[3]) , EXTRA ); + case A_LAMBDA_PARAM_NO_DEFAULT_0: + case A_LAMBDA_PARAM_NO_DEFAULT_1: + return ((arg_ty)_f->vals[0]); + case A_LAMBDA_PARAM_WITH_DEFAULT_0: + case A_LAMBDA_PARAM_WITH_DEFAULT_1: + return _PyPegen_name_default_pair ( p , ((arg_ty)_f->vals[0]) , ((expr_ty)_f->vals[1]) , NULL ); + case A_LAMBDA_PARAM_MAYBE_DEFAULT_0: + case A_LAMBDA_PARAM_MAYBE_DEFAULT_1: + return _PyPegen_name_default_pair ( p , ((arg_ty)_f->vals[0]) , _f->vals[1] , NULL ); + case A_LAMBDA_PARAM_0: + return _Py_arg ( ((expr_ty)_f->vals[0]) -> v . Name . id , NULL , NULL , EXTRA ); + case A_DISJUNCTION_0: + return _Py_BoolOp ( Or , CHECK ( _PyPegen_seq_insert_in_front ( p , ((expr_ty)_f->vals[0]) , _f->vals[1] ) ) , EXTRA ); + case A_CONJUNCTION_0: + return _Py_BoolOp ( And , CHECK ( _PyPegen_seq_insert_in_front ( p , ((expr_ty)_f->vals[0]) , _f->vals[1] ) ) , EXTRA ); + case A_INVERSION_0: + return _Py_UnaryOp ( Not , ((expr_ty)_f->vals[1]) , EXTRA ); + case A_COMPARISON_0: + return _Py_Compare ( ((expr_ty)_f->vals[0]) , CHECK ( _PyPegen_get_cmpops ( p , _f->vals[1] ) ) , CHECK ( _PyPegen_get_exprs ( p , _f->vals[1] ) ) , EXTRA ); + case A_COMPARE_OP_BITWISE_OR_PAIR_0: + case A_COMPARE_OP_BITWISE_OR_PAIR_1: + case A_COMPARE_OP_BITWISE_OR_PAIR_2: + case A_COMPARE_OP_BITWISE_OR_PAIR_3: + case A_COMPARE_OP_BITWISE_OR_PAIR_4: + case A_COMPARE_OP_BITWISE_OR_PAIR_5: + case A_COMPARE_OP_BITWISE_OR_PAIR_6: + case A_COMPARE_OP_BITWISE_OR_PAIR_7: + case A_COMPARE_OP_BITWISE_OR_PAIR_8: + case A_COMPARE_OP_BITWISE_OR_PAIR_9: + return ((CmpopExprPair*)_f->vals[0]); + case A_EQ_BITWISE_OR_0: + return _PyPegen_cmpop_expr_pair ( p , Eq , ((expr_ty)_f->vals[1]) ); + case A_NOTEQ_BITWISE_OR_0: + return _PyPegen_cmpop_expr_pair ( p , NotEq , ((expr_ty)_f->vals[1]) ); + case A_LTE_BITWISE_OR_0: + return _PyPegen_cmpop_expr_pair ( p , LtE , ((expr_ty)_f->vals[1]) ); + case A_LT_BITWISE_OR_0: + return _PyPegen_cmpop_expr_pair ( p , Lt , ((expr_ty)_f->vals[1]) ); + case A_GTE_BITWISE_OR_0: + return _PyPegen_cmpop_expr_pair ( p , GtE , ((expr_ty)_f->vals[1]) ); + case A_GT_BITWISE_OR_0: + return _PyPegen_cmpop_expr_pair ( p , Gt , ((expr_ty)_f->vals[1]) ); + case A_NOTIN_BITWISE_OR_0: + return _PyPegen_cmpop_expr_pair ( p , NotIn , ((expr_ty)_f->vals[2]) ); + case A_IN_BITWISE_OR_0: + return _PyPegen_cmpop_expr_pair ( p , In , ((expr_ty)_f->vals[1]) ); + case A_ISNOT_BITWISE_OR_0: + return _PyPegen_cmpop_expr_pair ( p , IsNot , ((expr_ty)_f->vals[2]) ); + case A_IS_BITWISE_OR_0: + return _PyPegen_cmpop_expr_pair ( p , Is , ((expr_ty)_f->vals[1]) ); + case A_BITWISE_OR_0: + return _Py_BinOp ( ((expr_ty)_f->vals[0]) , BitOr , ((expr_ty)_f->vals[2]) , EXTRA ); + case A_BITWISE_XOR_0: + return _Py_BinOp ( ((expr_ty)_f->vals[0]) , BitXor , ((expr_ty)_f->vals[2]) , EXTRA ); + case A_BITWISE_AND_0: + return _Py_BinOp ( ((expr_ty)_f->vals[0]) , BitAnd , ((expr_ty)_f->vals[2]) , EXTRA ); + case A_SHIFT_EXPR_0: + return _Py_BinOp ( ((expr_ty)_f->vals[0]) , LShift , ((expr_ty)_f->vals[2]) , EXTRA ); + case A_SHIFT_EXPR_1: + return _Py_BinOp ( ((expr_ty)_f->vals[0]) , RShift , ((expr_ty)_f->vals[2]) , EXTRA ); + case A_SUM_0: + return _Py_BinOp ( ((expr_ty)_f->vals[0]) , Add , ((expr_ty)_f->vals[2]) , EXTRA ); + case A_SUM_1: + return _Py_BinOp ( ((expr_ty)_f->vals[0]) , Sub , ((expr_ty)_f->vals[2]) , EXTRA ); + case A_TERM_0: + return _Py_BinOp ( ((expr_ty)_f->vals[0]) , Mult , ((expr_ty)_f->vals[2]) , EXTRA ); + case A_TERM_1: + return _Py_BinOp ( ((expr_ty)_f->vals[0]) , Div , ((expr_ty)_f->vals[2]) , EXTRA ); + case A_TERM_2: + return _Py_BinOp ( ((expr_ty)_f->vals[0]) , FloorDiv , ((expr_ty)_f->vals[2]) , EXTRA ); + case A_TERM_3: + return _Py_BinOp ( ((expr_ty)_f->vals[0]) , Mod , ((expr_ty)_f->vals[2]) , EXTRA ); + case A_TERM_4: + return CHECK_VERSION ( 5 , "The '@' operator is" , _Py_BinOp ( ((expr_ty)_f->vals[0]) , MatMult , ((expr_ty)_f->vals[2]) , EXTRA ) ); + case A_FACTOR_0: + return _Py_UnaryOp ( UAdd , ((expr_ty)_f->vals[1]) , EXTRA ); + case A_FACTOR_1: + return _Py_UnaryOp ( USub , ((expr_ty)_f->vals[1]) , EXTRA ); + case A_FACTOR_2: + return _Py_UnaryOp ( Invert , ((expr_ty)_f->vals[1]) , EXTRA ); + case A_POWER_0: + return _Py_BinOp ( ((expr_ty)_f->vals[0]) , Pow , ((expr_ty)_f->vals[2]) , EXTRA ); + case A_AWAIT_PRIMARY_0: + return CHECK_VERSION ( 5 , "Await expressions are" , _Py_Await ( ((expr_ty)_f->vals[1]) , EXTRA ) ); + case A_PRIMARY_0: + case A_T_PRIMARY_0: + return _Py_Attribute ( ((expr_ty)_f->vals[0]) , ((expr_ty)_f->vals[2]) -> v . Name . id , Load , EXTRA ); + case A_PRIMARY_1: + case A_T_PRIMARY_2: + return _Py_Call ( ((expr_ty)_f->vals[0]) , CHECK ( _PyPegen_singleton_seq ( p , ((expr_ty)_f->vals[1]) ) ) , NULL , EXTRA ); + case A_PRIMARY_2: + case A_T_PRIMARY_3: + return _Py_Call ( ((expr_ty)_f->vals[0]) , ( _f->vals[2] ) ? ( ( expr_ty ) _f->vals[2] ) -> v . Call . args : NULL , ( _f->vals[2] ) ? ( ( expr_ty ) _f->vals[2] ) -> v . Call . keywords : NULL , EXTRA ); + case A_PRIMARY_3: + case A_T_PRIMARY_1: + return _Py_Subscript ( ((expr_ty)_f->vals[0]) , ((expr_ty)_f->vals[2]) , Load , EXTRA ); + case A_SLICES_1: + return _Py_Tuple ( _f->vals[0] , Load , EXTRA ); + case A_SLICE_0: + return _Py_Slice ( _f->vals[0] , _f->vals[2] , _f->vals[3] , EXTRA ); + case A_ATOM_1: + return _Py_Constant ( Py_True , NULL , EXTRA ); + case A_ATOM_2: + return _Py_Constant ( Py_False , NULL , EXTRA ); + case A_ATOM_3: + return _Py_Constant ( Py_None , NULL , EXTRA ); + case A_ATOM_9: + return _Py_Constant ( Py_Ellipsis , NULL , EXTRA ); + case A_STRINGS_0: + return _PyPegen_concatenate_strings ( p , _f->vals[0] ); + case A_LIST_0: + return _Py_List ( _f->vals[1] , Load , EXTRA ); + case A_LISTCOMP_0: + return _Py_ListComp ( ((expr_ty)_f->vals[1]) , _f->vals[2] , EXTRA ); + case A_TUPLE_0: + return _Py_Tuple ( _f->vals[1] , Load , EXTRA ); + case A_GENEXP_0: + return _Py_GeneratorExp ( ((expr_ty)_f->vals[1]) , _f->vals[2] , EXTRA ); + case A_SET_0: + return _Py_Set ( ((asdl_seq*)_f->vals[1]) , EXTRA ); + case A_SETCOMP_0: + return _Py_SetComp ( ((expr_ty)_f->vals[1]) , _f->vals[2] , EXTRA ); + case A_DICT_0: + return _Py_Dict ( CHECK ( _PyPegen_get_keys ( p , _f->vals[1] ) ) , CHECK ( _PyPegen_get_values ( p , _f->vals[1] ) ) , EXTRA ); + case A_DICTCOMP_0: + return _Py_DictComp ( ((KeyValuePair*)_f->vals[1]) -> key , ((KeyValuePair*)_f->vals[1]) -> value , ((asdl_seq*)_f->vals[2]) , EXTRA ); + case A_DOUBLE_STARRED_KVPAIR_0: + return _PyPegen_key_value_pair ( p , NULL , ((expr_ty)_f->vals[1]) ); + case A_DOUBLE_STARRED_KVPAIR_1: + case A__GATHER_87_0: + case A__GATHER_87_1: + return ((KeyValuePair*)_f->vals[0]); + case A_KVPAIR_0: + return _PyPegen_key_value_pair ( p , ((expr_ty)_f->vals[0]) , ((expr_ty)_f->vals[2]) ); + case A_FOR_IF_CLAUSE_0: + return CHECK_VERSION ( 6 , "Async comprehensions are" , _Py_comprehension ( ((expr_ty)_f->vals[2]) , _f->vals[4] , ((expr_ty)_f->vals[5]) , 1 , p -> arena ) ); + case A_FOR_IF_CLAUSE_1: + return _Py_comprehension ( ((expr_ty)_f->vals[1]) , _f->vals[3] , ((expr_ty)_f->vals[4]) , 0 , p -> arena ); + case A_YIELD_EXPR_0: + return _Py_YieldFrom ( ((expr_ty)_f->vals[2]) , EXTRA ); + case A_YIELD_EXPR_1: + return _Py_Yield ( _f->vals[1] , EXTRA ); + case A_ARGS_0: + case A_ARGS_2: + return _Py_Call ( _PyPegen_dummy_name ( p ) , ( _f->vals[1] ) ? CHECK ( _PyPegen_seq_insert_in_front ( p , ((expr_ty)_f->vals[0]) , ( ( expr_ty ) _f->vals[1] ) -> v . Call . args ) ) : CHECK ( _PyPegen_singleton_seq ( p , ((expr_ty)_f->vals[0]) ) ) , ( _f->vals[1] ) ? ( ( expr_ty ) _f->vals[1] ) -> v . Call . keywords : NULL , EXTRA ); + case A_ARGS_1: + return _Py_Call ( _PyPegen_dummy_name ( p ) , CHECK_NULL_ALLOWED ( _PyPegen_seq_extract_starred_exprs ( p , ((asdl_seq*)_f->vals[0]) ) ) , CHECK_NULL_ALLOWED ( _PyPegen_seq_delete_starred_exprs ( p , ((asdl_seq*)_f->vals[0]) ) ) , EXTRA ); + case A_KWARGS_0: + return _PyPegen_join_sequences ( p , _f->vals[0] , _f->vals[2] ); + case A_KWARG_OR_STARRED_0: + case A_KWARG_OR_DOUBLE_STARRED_0: + return _PyPegen_keyword_or_starred ( p , CHECK ( _Py_keyword ( ((expr_ty)_f->vals[0]) -> v . Name . id , ((expr_ty)_f->vals[2]) , EXTRA ) ) , 1 ); + case A_KWARG_OR_STARRED_1: + return _PyPegen_keyword_or_starred ( p , ((expr_ty)_f->vals[0]) , 0 ); + case A_KWARG_OR_DOUBLE_STARRED_1: + return _PyPegen_keyword_or_starred ( p , CHECK ( _Py_keyword ( NULL , ((expr_ty)_f->vals[1]) , EXTRA ) ) , 1 ); + case A_STAR_TARGETS_1: + return _Py_Tuple ( CHECK ( _PyPegen_seq_insert_in_front ( p , ((expr_ty)_f->vals[0]) , _f->vals[1] ) ) , Store , EXTRA ); + case A_STAR_TARGET_0: + return _Py_Starred ( CHECK ( _PyPegen_set_expr_context ( p , _f->vals[1] , Store ) ) , Store , EXTRA ); + case A_STAR_TARGET_1: + case A_SINGLE_SUBSCRIPT_ATTRIBUTE_TARGET_0: + case A_TARGET_0: + return _Py_Attribute ( ((expr_ty)_f->vals[0]) , ((expr_ty)_f->vals[2]) -> v . Name . id , Store , EXTRA ); + case A_STAR_TARGET_2: + case A_SINGLE_SUBSCRIPT_ATTRIBUTE_TARGET_1: + case A_TARGET_1: + return _Py_Subscript ( ((expr_ty)_f->vals[0]) , ((expr_ty)_f->vals[2]) , Store , EXTRA ); + case A_STAR_ATOM_0: + case A_SINGLE_TARGET_1: + case A_T_ATOM_0: + return _PyPegen_set_expr_context ( p , ((expr_ty)_f->vals[0]) , Store ); + case A_STAR_ATOM_1: + case A_T_ATOM_1: + return _PyPegen_set_expr_context ( p , ((expr_ty)_f->vals[1]) , Store ); + case A_STAR_ATOM_2: + case A_T_ATOM_2: + return _Py_Tuple ( _f->vals[1] , Store , EXTRA ); + case A_STAR_ATOM_3: + case A_T_ATOM_3: + return _Py_List ( _f->vals[1] , Store , EXTRA ); + case A_DEL_TARGET_0: + return _Py_Attribute ( ((expr_ty)_f->vals[0]) , ((expr_ty)_f->vals[2]) -> v . Name . id , Del , EXTRA ); + case A_DEL_TARGET_1: + return _Py_Subscript ( ((expr_ty)_f->vals[0]) , ((expr_ty)_f->vals[2]) , Del , EXTRA ); + case A_DEL_T_ATOM_0: + return _PyPegen_set_expr_context ( p , ((expr_ty)_f->vals[0]) , Del ); + case A_DEL_T_ATOM_1: + return _PyPegen_set_expr_context ( p , ((expr_ty)_f->vals[1]) , Del ); + case A_DEL_T_ATOM_2: + return _Py_Tuple ( _f->vals[1] , Del , EXTRA ); + case A_DEL_T_ATOM_3: + return _Py_List ( _f->vals[1] , Del , EXTRA ); + case A_T_LOOKAHEAD_0: + case A_T_LOOKAHEAD_1: + case A_T_LOOKAHEAD_2: + case A__TMP_9_0: + case A__TMP_9_1: + case A__TMP_10_0: + case A__TMP_10_1: + case A__TMP_11_0: + case A__TMP_11_1: + case A__TMP_12_0: + case A__TMP_13_0: + case A__TMP_23_0: + case A__TMP_34_0: + case A__TMP_34_1: + case A__TMP_34_2: + case A__TMP_107_0: + case A__TMP_107_1: + case A__TMP_107_2: + case A__TMP_112_0: + case A__TMP_112_1: + case A__TMP_113_0: + case A__TMP_113_1: + case A__TMP_115_0: + case A__TMP_115_1: + case A__TMP_116_0: + case A__TMP_116_1: + case A__TMP_129_0: + case A__TMP_129_1: + case A__TMP_130_0: + case A__TMP_130_1: + return ((Token *)_f->vals[0]); + case A_INCORRECT_ARGUMENTS_0: + return RAISE_SYNTAX_ERROR ( "iterable argument unpacking follows keyword argument unpacking" ); + case A_INCORRECT_ARGUMENTS_1: + return RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( ((expr_ty)_f->vals[0]) , "Generator expression must be parenthesized" ); + case A_INCORRECT_ARGUMENTS_2: + return _PyPegen_nonparen_genexp_in_call ( p , ((expr_ty)_f->vals[0]) ); + case A_INCORRECT_ARGUMENTS_3: + return RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( ((expr_ty)_f->vals[2]) , "Generator expression must be parenthesized" ); + case A_INCORRECT_ARGUMENTS_4: + return _PyPegen_arguments_parsing_error ( p , ((expr_ty)_f->vals[0]) ); + case A_INVALID_KWARG_0: + return RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( ((expr_ty)_f->vals[0]) , "expression cannot contain assignment, perhaps you meant \"==\"?" ); + case A_INVALID_NAMED_EXPRESSION_0: + return RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( ((expr_ty)_f->vals[0]) , "cannot use assignment expressions with %s" , _PyPegen_get_expr_name ( ((expr_ty)_f->vals[0]) ) ); + case A_INVALID_ASSIGNMENT_0: + return RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( ((expr_ty)_f->vals[0]) , "only single target (not %s) can be annotated" , _PyPegen_get_expr_name ( ((expr_ty)_f->vals[0]) ) ); + case A_INVALID_ASSIGNMENT_1: + return RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( ((expr_ty)_f->vals[0]) , "only single target (not tuple) can be annotated" ); + case A_INVALID_ASSIGNMENT_2: + return RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( ((expr_ty)_f->vals[0]) , "illegal target for annotation" ); + case A_INVALID_ASSIGNMENT_3: + return RAISE_SYNTAX_ERROR_INVALID_TARGET ( STAR_TARGETS , ((expr_ty)_f->vals[1]) ); + case A_INVALID_ASSIGNMENT_4: + return RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( ((expr_ty)_f->vals[1]) , "assignment to yield expression not possible" ); + case A_INVALID_ASSIGNMENT_5: + return RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( ((expr_ty)_f->vals[0]) , "'%s' is an illegal expression for augmented assignment" , _PyPegen_get_expr_name ( ((expr_ty)_f->vals[0]) ) ); + case A_INVALID_DEL_STMT_0: + return RAISE_SYNTAX_ERROR_INVALID_TARGET ( DEL_TARGETS , ((expr_ty)_f->vals[1]) ); + case A_INVALID_BLOCK_0: + return RAISE_INDENTATION_ERROR ( "expected an indented block" ); + case A_INVALID_COMPREHENSION_0: + return RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( ((expr_ty)_f->vals[1]) , "iterable unpacking cannot be used in comprehension" ); + case A_INVALID_DICT_COMPREHENSION_0: + return RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( ((Token *)_f->vals[1]) , "dict unpacking cannot be used in dict comprehension" ); + case A_INVALID_PARAMETERS_0: + case A_INVALID_LAMBDA_PARAMETERS_0: + return RAISE_SYNTAX_ERROR ( "non-default argument follows default argument" ); + case A_INVALID_STAR_ETC_0: + case A_INVALID_LAMBDA_STAR_ETC_0: + return RAISE_SYNTAX_ERROR ( "named arguments must follow bare *" ); + case A_INVALID_STAR_ETC_1: + return RAISE_SYNTAX_ERROR ( "bare * has associated type comment" ); + case A_INVALID_DOUBLE_TYPE_COMMENTS_0: + return RAISE_SYNTAX_ERROR ( "Cannot have two type comments on def" ); + case A_INVALID_WITH_ITEM_0: + return RAISE_SYNTAX_ERROR_INVALID_TARGET ( STAR_TARGETS , ((expr_ty)_f->vals[2]) ); + case A_INVALID_FOR_TARGET_0: + return RAISE_SYNTAX_ERROR_INVALID_TARGET ( FOR_TARGETS , ((expr_ty)_f->vals[2]) ); + case A_INVALID_GROUP_0: + return RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( ((expr_ty)_f->vals[1]) , "can't use starred expression here" ); + case A_INVALID_IMPORT_FROM_TARGETS_0: + return RAISE_SYNTAX_ERROR ( "trailing comma not allowed without surrounding parentheses" ); + case A__GATHER_26_0: + case A__GATHER_26_1: + case A__GATHER_28_0: + case A__GATHER_28_1: + return ((alias_ty)_f->vals[0]); + case A__GATHER_30_0: + case A__GATHER_30_1: + case A__GATHER_31_0: + case A__GATHER_31_1: + case A__GATHER_32_0: + case A__GATHER_32_1: + case A__GATHER_33_0: + case A__GATHER_33_1: + return ((withitem_ty)_f->vals[0]); + case A__TMP_78_0: + return _PyPegen_check_barry_as_flufl ( p ) ? NULL : ((Token *)_f->vals[0]); + case A__TMP_85_0: + return _PyPegen_seq_insert_in_front ( p , ((expr_ty)_f->vals[0]) , _f->vals[2] ); + case A__GATHER_93_0: + case A__GATHER_93_1: + case A__GATHER_94_0: + case A__GATHER_94_1: + case A__GATHER_95_0: + case A__GATHER_95_1: + case A__GATHER_96_0: + case A__GATHER_96_1: + return ((KeywordOrStarred*)_f->vals[0]); + case A__TMP_109_0: + case A__TMP_111_0: + return ((SlashWithDefault*)_f->vals[0]); + default: + assert(0); + RAISE_SYNTAX_ERROR("invalid opcode"); + return NULL; + } +} diff --git a/Parser/vmreadme.md b/Parser/vmreadme.md new file mode 100644 index 00000000000000..c82b83b3464d42 --- /dev/null +++ b/Parser/vmreadme.md @@ -0,0 +1,347 @@ +Pegen Virtual Machine +===================== + +The Pegen VM is an alternative for the recursive-descent Pegen parser. +The grammar (including actions) is identical, but execution does not +use the C stack. We expect this to be faster, and initial +measurements seem to bear this out. But we need to keep diligent, and +if it ever becomes clear that it will *not* be faster, we should stop +working on this project. + +The runtime uses the same `Parser` structure as the recursive-descent +Pegen parser, and the same helper functions +(e.g., `_PyPegen_singleton_seq`). + +The VM uses a stack to hold state during parsing. The grammar is +represented by a few read-only tables. The actions are represented by +a function containing a giant switch with one case per action. (An +optimization here could be to combine identical actions.) + +The grammar tables and the action function are meant to be generated +by a parser generator similar to the current one. Because of the +actions, it needs to generate C code. + +The primary VM state is a stack of `Frame` structures. Each frame +represents a particular attempt to parse a rule at a given point in +the input. The only state separate from the stack is a pointer to the +`Parser` structure. + +The main state in a frame is as follows: + +- `Rule *rule` -- points to the rule being parsed +- `int mark` -- the input position at the start of the rule invocation +- `int ialt` -- indicates which alternative is currently being tried +- `int iop` -- indicates where we are in the current alternative +- `int cut` -- whether a "cut" was executed in the current alternative + +State related to loops is described below. + +Note that `rule` doesn't change after the frame is initialized. Also, +`mark` normally doesn't change, except for loop operations. + +Each frame also has an array of values where successfully recognized +tokens and rules are stores. This uses: + +- `int ival` -- number of values stored so far +- `void *vals[]` -- values stored (the type is `Token *` or an AST + node type; may be NULL) + +A `Rule` structure has the following fields: + +- `char *name` -- rule name, for debugging (e.g., `"start"`) +- `int type` -- rule type, used for memo lookup +- `int alts[]` -- index into `opcodes` array for each alternative, + terminated by `-1` +- `int opcodes[]` -- array of opcodes and their arguments + +All rules are combined in a single array; the index in this array +is used by operations that reference other rules. + +The `opcodes` array is a sequence of operation codes and arguments. +Some opcodes (e.g., `OP_TOKEN`) are followed by an argument; others +(e.g., `OP_NAME`) are not. Both are representable as integers. + + +Operations +---------- + +Most operations can succeed or fail, and produce a vaue if they +succeed. + +If an operation succeeds, the value is appended to the frame's values +array (`vals`), and the VM proceeds to the next opcode. + +If an operation fails, the VM resets the input to the frame's mark, +and resets the value array. It then proceeds to the next alternative +of the frame's rule, if there is one and the frame's `cut` flag is not +set. If the frame's `cut` flag is set, or if its rule has no more +alternatives, the frame is popped off the frame stack and the VM +proceeds with failure there. + +Some operations manipulate other frame fields. + +Calls into the support runtime can produce *errors* -- when an error +is detected, the VM exits immediately, returning `NULL`. + + +### General operations + +The following opcodes take no argument. + +- `OP_NOOP` -- succeed without a value. (Used for opcode padding.) + +- `OP_NAME` -- call `_PyPegen_name_token()`; fail if it returns + `NULL`, otherwise succeeds with the return value. + +- `OP_NUMBER` -- call `_PyPegen_number_token()`; same as `OP_NAME`. + +- `OP_STRING` -- call `_PyPegen_string_token()`; same as `OP_NAME`. + +- `OP_CUT` -- set the frame's `cut` flag; succeed without a value. + +- `OP_OPTIONAL` -- succeed without a value; modifies the *previous* + operation to treat a `NULL` result as a success. (See below.) + +The following operations are followed by a single integer argument. + +- `OP_TOKEN(type)` -- call `_PyPegen_expect_token()` with the `type` + argument; processing is the same as for `OP_NAME`. + +- `OP_RULE(rule)` -- push a new frame onto the stack, initializing it + with the give rule (by index), the current input position (mark), + at the first alternative and opcode. Then proceed to the first + operation of the new frame. + +- `OP_RETURN(action)` -- call the action given by the argument, then + pop the frame off the stack. Execution then proceeds (in the frame + newly revealed by that pop operation) as if the previous operation + succeeded or failed with the return value of the action. + + +### Operations for root rules only + +A grammar must have one or more *root rules*. A root rule is a +synthetic rule that uses `OP_SUCCESS` and `OP_FAILURE` operations to +report overall success or failure. Only root rules may use these +operations, and they must be used in the right format. + +Each root rule must have exactly two alternatives. The first +alternative must be a single operation (generally `OP_RULE`) that +stores a value in the values array, followed by `OP_SUCCESS`. The +second alternative must be the single operation `OP_FAILURE`. + +- `OP_SUCCESS` -- exit the VM with the first value from the `vals` + array as the result. + +- `OP_FAILURE` -- report a syntax error and exit the VM with a NULL + result. + + +### Operations for loop rules only + +For a loop such as `a*` or `a+`, a synthetic rule must be created with +the following structure: + +``` +# First alternative: + +OP_LOOP_ITERATE + +# Second alternative: + +``` + +The values being collected are stored in a `malloc`-ed array named +`collections` that is grown as needed. This uses the following +fields: + +- `ncollected` -- the number of collected values. +- `collection` -- `malloc`-ed array of `void *` values representing + the collected values. + +The operations are defined as follows: + +- `OP_LOOP_ITERATE` -- append the current value to the `collections` + array, save the current input position, and start the next iteration + of the loop (resetting the instruction pointer). + +- `OP_LOOP_COLLECT` -- restore the input position from the last saved + position and pop the frame off the stack, producing a new value that + is an `asdl_seq *` containing the collected values. + +- `OP_LOOP_COLLECT_NONEMPTY` -- like `OP_LOOP_COLLECT` but fails if no + values are collected. + +For a "delimited" loop, written in the metagrammar as `b.a+` (one or +more `a` items separated by the delimiter `b`), the format is +slightly different: + +``` +# First alternative: + + +OP_LOOP_ITERATE + +# Second alternative: + +OP_LOOP_COLLECT_DELIMITED +``` + +The new operation is: + +- `OP_LOOP_COLLECT_DELIMITED` -- Add the first value from the values array + to the collection and then do everything that `OP_LOOP_COLLECT does. + + +### Operations for lookaheads + +Positive lookaheads use the following pattern: + +``` +OP_SAVE_MARK + +OP_POS_LOOKAHEAD +``` + +The operations work as follows: + +- `OP_SAVE_MARK` -- saves the current input position in a dedicated + field of the frame, `savemark`. + +- `OP_POS_LOOKAHEAD` -- restores the current input position from the + frame's `savemark` field. (It does not reset the values array; + values produced by positive lookaheads are ignored by the actions. + +Negative lookaheads use the following pattern: + +``` +OP_SAVE_MARK + +OP_NEG_LOOKAHEAD +``` + +The new operation works as follows: + +- `OP_NEG_LOOKAHEAD` -- fails the current alternative. + +In addition, the standard code for success/failure processing checks +whether the next operation is `OP_NEG_LOOKAHEAD`. If so, it treats +`NULL` as a success and restores the current input position from the +frame's `savemark` field. + + +More about `OP_OPTIONAL` +------------------------ + +The `OP_OPTIONAL` flag is a "postfix" operation. It must *follow* any +operation that may produce a result. The normal way of the VM is that +if the result is `NULL` this is treated as a failure by the VM. But +before treating `NULL` as a failure, the VM checks whether the next +operation is `OP_OPTIONAL`. If so, it treats `NULL` as a success. In +this case a `NULL` is appended to the `vals` array and control flows +to the next operation. + +When the operation preceding `OP_OPTIONAL` succeeds, `OP_OPTIONAL` is +executed as a regular operation, and always succeed. + +The `OP_NEG_LOOKAHEAD` works similar (but it also restores the input +position). + + +Constraints on operation order +------------------------------ + +Note that for operations that succeed with a value or fail, there is +always a next operation. These operations are `OP_NAME`, `OP_NUMBER`, +`OP_STRING`, `OP_TOKEN`, and `OP_RULE`. + +These operations always succeed: `OP_NOOP`, `OP_CUT`, `OP_OPTIONAL`, +`OP_START`. + +These operations must be last in their alternative: `OP_RETURN`, +`OP_SUCCESS`, `OP_FAILURE`, `OP_LOOP_ITERATE`, `OP_LOOP_COLLECT`, +`OP_LOOP_COLLECT_NONEMPTY`. + +This operation must be first in its alternative: `OP_FAILURE`. + + +Grammar for lists of operations +------------------------------- + +This shows the constraints on how operations can be used together. + +``` +rule: root_rule | normal_rule | loop_rule | delimited_rule + +root_rule: success_alt failure_alt + +success_alt: regular_op OP_SUCCESS +failure_alt: OP_FAILURE + +normal_rule: alt+ + +loop_rule: loop_start_alt loop_collect_alt + +loop_start_alt: regular_op OP_LOOP_ITERATE +loop_collect_alt: OP_LOOP_COLLECT | OP_LOOP_COLLECT_NONEMPTY + +delimited_rule: delimited_start_alt delimited_collect_alt + +delimited_start_alt: regular_op regular_op OP_LOOP_ITERATE +delimited_collect_alt: OP_LOOP_COLLECT_DELIMITED + +alt: any_op+ return_op + +any_op: regular_op [OP_OPTIONAL] | lookahead_block | special_op +regular_op: short_op | long_op +short_op: OP_NAME | OP_NUMBER | OP_STRING +long_op: OP_TOKEN | OP_RULE +special_op: OP_NOOP | OP_CUT +return_op: OP_RETURN + +lookahead_block: OP_SAVE_MARK regular_op lookahead_op +lookahead_op: OP_POS_LOOKAHEAD | OP_NEG_LOOKAHEAD +``` + +Ideas +----- + +### Left-recursion + +- First opcode of first alt is `OP_SETUP_LEFT_REC`. This initializes + the memo cache for f->rule->type to `NULL`. + +- All `OP_RETURN` opcodes in a left-rec rule are replaced with + `OP_RETURN_LEFT_REC`. This compares the current position with the + most recently cached position for this rule at this point in the + input. If the new match is *further*, it updates the memo cache, + resets `f->mark`, and resets `f->iop` and `f->ialt` to the start of + the rule. It then goes back to the top (possibly skipping the setup + op). If the new match is not further, it is discarded and the most + recent match from the memo cache is returned as the result (also + updating the end position). + +### Selective memoization + +- We could have a flag in the rule that prevents memo lookups and + inserts. Or we could have separate opcodes, e.g. `OP_RULE_NOMEMO` + and `OP_RETURN_NOMEMO`. + +### Performance tuning + +- To make frames smaller, we could have a separate values stack; the + frame would have a `void** vals` instead of `void *vals[]`. Most + frames won't need 20 values, but we could ensure there are always at + least that many on the stack. + +- Is it faster to check for flags in the rule object (e.g. leftrec) or + is it faster to have dedicated opcodes? My current hunch is that + dedicated opcodes are faster, but I really don't know. Maybe having + fewer opcodes is more important than having smaller Rule objects. + +- Random other C tricks, esp. tricks that might increase the hit rate + in the CPU's L1 cache. (Remember in modern CPUs memory access is + 10-100x slower than cache access.) Who can we tap that knows this + stuff? + +- If we know `x >= -1`, Which is faster: `if (x < 0)` or `if (x == -1)`? diff --git a/Tools/peg_generator/Makefile b/Tools/peg_generator/Makefile index 084da154919e3e..146133efde1a3b 100644 --- a/Tools/peg_generator/Makefile +++ b/Tools/peg_generator/Makefile @@ -25,6 +25,9 @@ build: peg_extension/parse.c peg_extension/parse.c: $(GRAMMAR) $(TOKENS) pegen/*.py peg_extension/peg_extension.c ../../Parser/pegen.c ../../Parser/pegen_errors.c ../../Parser/string_parser.c ../../Parser/action_helpers.c ../../Parser/*.h pegen/grammar_parser.py $(PYTHON) -m pegen -q c $(GRAMMAR) $(TOKENS) -o peg_extension/parse.c --compile-extension +generate_vm: $(GRAMMAR) $(TOKENS) pegen/*.py ../../Parser/pegen/pegen.c ../../Parser/pegen/parse_string.c ../../Parser/pegen/*.h + $(PYTHON) -m pegen -q vm $(GRAMMAR) $(TOKENS) -o ../../Parser/pegen/vmparse.h + clean: -rm -f peg_extension/*.o peg_extension/*.so peg_extension/parse.c -rm -f data/xxl.py diff --git a/Tools/peg_generator/data/simple.gram b/Tools/peg_generator/data/simple.gram new file mode 100644 index 00000000000000..c1261e752e8d58 --- /dev/null +++ b/Tools/peg_generator/data/simple.gram @@ -0,0 +1,18 @@ +start: a=stmt+ ENDMARKER { _PyPegen_make_module(p, a) } +stmt: + | !'if' a=expr NEWLINE { _Py_Expr(a, EXTRA) } + | &'if' a=if_stmt +if_stmt: + | 'if' ~ a=NAME ':' b=stmt { _Py_If(a, CHECK(_PyPegen_singleton_seq(p, b)), NULL, EXTRA) } +expr: + | a=expr '+' b=term { _Py_BinOp(a, Add, b, EXTRA) } + | term +term: + | a=term ['*'] b=factor { _Py_BinOp(a, Mult, b, EXTRA) } + | factor +factor: + | '(' a=expr ')' { a } + | '[' a=','.expr+ ']' { _Py_List(a, Load, EXTRA) } + | NUMBER + | "__peg_parser__" { RAISE_SYNTAX_ERROR("You found it!") } + | NAME diff --git a/Tools/peg_generator/pegen/__main__.py b/Tools/peg_generator/pegen/__main__.py index 2910d6ccf1c694..297c82e6fa768c 100755 --- a/Tools/peg_generator/pegen/__main__.py +++ b/Tools/peg_generator/pegen/__main__.py @@ -16,6 +16,31 @@ from pegen.validator import validate_grammar +def generate_vm_code( + args: argparse.Namespace, +) -> Tuple[Grammar, Parser, Tokenizer, ParserGenerator]: + from pegen.build import build_vm_parser_and_generator + + verbose = args.verbose + verbose_tokenizer = verbose >= 3 + verbose_parser = verbose == 2 or verbose >= 4 + try: + grammar, parser, tokenizer, gen = build_vm_parser_and_generator( + args.grammar_filename, + args.tokens_filename, + args.output, + verbose_tokenizer, + verbose_parser, + ) + 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_c_code( args: argparse.Namespace, ) -> Tuple[Grammar, Parser, Tokenizer, ParserGenerator]: @@ -120,6 +145,18 @@ def generate_python_code( help="Suppress code emission for rule actions", ) +vm_parser = subparsers.add_parser("vm", help="Generate the new VM parser generator") +vm_parser.set_defaults(func=generate_vm_code) +vm_parser.add_argument("grammar_filename", help="Grammar description") +vm_parser.add_argument("tokens_filename", help="Tokens description") +vm_parser.add_argument( + "-o", + "--output", + metavar="OUT", + default="vmparse.h", + help="Where to write the generated parser", +) + def main() -> None: from pegen.testutil import print_memstats diff --git a/Tools/peg_generator/pegen/build.py b/Tools/peg_generator/pegen/build.py index 5805ff63717440..d75b9340ac36c5 100644 --- a/Tools/peg_generator/pegen/build.py +++ b/Tools/peg_generator/pegen/build.py @@ -7,6 +7,7 @@ from typing import IO, Dict, List, Optional, Set, Tuple from pegen.c_generator import CParserGenerator +from pegen.vm_generator import VMParserGenerator from pegen.grammar import Grammar from pegen.grammar_parser import GeneratedParser as GrammarParser from pegen.parser import Parser @@ -249,6 +250,19 @@ def build_python_generator( return gen +def build_vm_generator( + grammar: Grammar, grammar_file: str, tokens_file: str, output_file: str, +) -> 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 = VMParserGenerator( + grammar, all_tokens, exact_tok, non_exact_tok, file + ) + gen.generate(grammar_file) + return gen + + def build_c_parser_and_generator( grammar_file: str, tokens_file: str, @@ -319,3 +333,26 @@ def build_python_parser_and_generator( skip_actions=skip_actions, ) return grammar, parser, tokenizer, gen + + +def build_vm_parser_and_generator( + grammar_file: str, + tokens_file: str, + output_file: str, + verbose_tokenizer: bool = False, + verbose_parser: 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 + 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. + """ + grammar, parser, tokenizer = build_parser(grammar_file, verbose_tokenizer, verbose_parser) + gen = build_vm_generator(grammar, grammar_file, tokens_file, output_file) + return grammar, parser, tokenizer, gen diff --git a/Tools/peg_generator/pegen/vm_generator.py b/Tools/peg_generator/pegen/vm_generator.py new file mode 100644 index 00000000000000..40a724e4aeea9c --- /dev/null +++ b/Tools/peg_generator/pegen/vm_generator.py @@ -0,0 +1,541 @@ +import ast +import contextlib +import dataclasses +import re +import sys +import token +import tokenize +from collections import defaultdict +from itertools import accumulate +from typing import Any, Dict, Iterator, List, Optional, Tuple, Set, IO, Text, Union + +from pegen import grammar +from pegen.grammar import ( + Alt, + Cut, + Gather, + GrammarVisitor, + Group, + Leaf, + Lookahead, + NamedItem, + NameLeaf, + NegativeLookahead, + Opt, + Plain, + PositiveLookahead, + Repeat, + Repeat0, + Repeat1, + Rhs, + Rule, + StringLeaf, +) +from pegen.parser_generator import ParserGenerator + + +@dataclasses.dataclass +class Opcode: + opcode: str + oparg: Optional[Union[int, str]] = None + + def __len__(self) -> int: + return 1 if self.oparg is None else 2 + + +CALL_ACTION_HEAD = """ +static void * +call_action(Parser *p, Frame *_f, int _iaction) +{ + assert(p->mark > 0); + Token *_t = p->tokens[_f->mark]; + int _start_lineno = _t->lineno; + int _start_col_offset = _t->col_offset; + _t = p->tokens[p->mark - 1]; + int _end_lineno = _t->end_lineno; + int _end_col_offset = _t->end_col_offset; + + switch (_iaction) { +""" + +CALL_ACTION_TAIL = """\ + default: + assert(0); + RAISE_SYNTAX_ERROR("invalid opcode"); + return NULL; + } +} +""" + + +class RootRule(Rule): + def __init__(self, name: str, startrulename: str): + super().__init__(name, "void *", Rhs([]), None) + self.startrulename = startrulename + + +class VMCallMakerVisitor(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] = {} + self.soft_keyword_cache: List[str] = [] + + def keyword_helper(self, keyword: str) -> Tuple[str, str]: + if keyword not in self.keyword_cache: + self.keyword_cache[keyword] = self.gen.keyword_type() + return "OP_TOKEN", str(self.keyword_cache[keyword]) + + def soft_keyword_helper(self, keyword: str) -> Tuple[str, str]: + if keyword not in self.soft_keyword_cache: + self.soft_keyword_cache.append(keyword) + return "OP_SOFT_KEYWORD", f"SK_{keyword.upper()}" + + def visit_StringLeaf(self, node: StringLeaf) -> Tuple[str, str]: + val = ast.literal_eval(node.value) + if re.match(r"[a-zA-Z_]\w*\Z", val): # This is a keyword + if node.value.endswith("'"): + return self.keyword_helper(val) + else: + return self.soft_keyword_helper(val) + tok_num: int = self.exact_tokens[val] + return "OP_TOKEN", self.gen.tokens[tok_num] + + def visit_Repeat0(self, node: Repeat0) -> str: + if node in self.cache: + return self.cache[node] + name = self.gen.name_loop(node.node, False) + self.cache[node] = name + return name + + def visit_Repeat1(self, node: Repeat1) -> str: + if node in self.cache: + return self.cache[node] + name = self.gen.name_loop(node.node, True) + self.cache[node] = name + return name + + def visit_Gather(self, node: Gather) -> str: + if node in self.cache: + return self.cache[node] + name = self.gen.name_gather(node) + self.cache[node] = name + return name + + def visit_Group(self, node: Group) -> str: + return self.visit(node.rhs) + + def visit_Rhs(self, node: Rhs) -> Optional[str]: + if node in self.cache: + return self.cache[node] + if can_we_inline(node): + return None + name = self.gen.name_node(node) + self.cache[node] = name + return name + + +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 + + +class VMParserGenerator(ParserGenerator, GrammarVisitor): + def __init__( + self, + grammar: grammar.Grammar, + tokens: Dict[str, int], + exact_tokens: Dict[str, int], + non_exact_tokens: Set[str], + file: Optional[IO[Text]], + ): + super().__init__(grammar, tokens, file) + + self.opcode_buffer: Optional[List[Opcode]] = None + self.callmakervisitor: VMCallMakerVisitor = VMCallMakerVisitor( + self, exact_tokens, non_exact_tokens, + ) + + @contextlib.contextmanager + def set_opcode_buffer(self, buffer: List[Opcode]) -> Iterator[None]: + self.opcode_buffer = buffer + yield + self.opcode_buffer = None + + def add_opcode(self, opcode: str, oparg: Optional[str] = None) -> None: + assert not isinstance(oparg, int) + assert self.opcode_buffer is not None + + self.opcode_buffer.append(Opcode(opcode, oparg)) + + def name_gather(self, node: Gather) -> str: + self.counter += 1 + name = f"_gather_{self.counter}" + alt0 = Alt([NamedItem(None, node.node), NamedItem(None, node.separator)]) + alt1 = Alt([NamedItem(None, node.node)]) + self.todo[name] = Rule(name, None, Rhs([alt0, alt1])) + return name + + def generate(self, filename: str) -> None: + self.add_root_rules() + self.collect_todo() + self.gather_actions() + self._setup_keywords() + self._setup_soft_keywords() + + self.print("enum {") + with self.indent(): + for rulename in self.todo: + self.print(f"R_{rulename.upper()},") + self.print("};") + self.print() + + self.print("enum {") + with self.indent(): + for actionname, action in self.actions.items(): + self.print(f"{actionname},") + self.print("};") + self.print() + + self.print("static Rule all_rules[] = {") + while self.todo: + for rulename, rule in list(self.todo.items()): + del self.todo[rulename] + with self.indent(): + self.visit(rule) + self.print("};") + + self.printblock(CALL_ACTION_HEAD) + with self.indent(): + self.print_action_cases() + self.printblock(CALL_ACTION_TAIL) + + 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("};") + self.print() + + def _setup_soft_keywords(self) -> None: + soft_keywords = self.callmakervisitor.soft_keyword_cache + if soft_keywords: + self.print("enum {") + with self.indent(): + for soft_keyword in soft_keywords: + self.print(f"SK_{soft_keyword.upper()},") + self.print("};") + self.print() + self.print("static const char *soft_keywords[] = {") + with self.indent(): + for soft_keyword in soft_keywords: + self.print(f'"{soft_keyword}",') + self.print("};") + self.print() + + def print_action_cases(self) -> None: + unique_actions: Dict[str, List[str]] = defaultdict(list) + for actionname, action in self.actions.items(): + unique_actions[action].append(actionname) + for action, actionnames in unique_actions.items(): + for actionname in actionnames: + self.print(f"case {actionname}:") + self.print(f" return {action};") + + def gather_actions(self) -> None: + self.actions: Dict[str, str] = {} + for rulename, rule in self.todo.items(): + if not rule.is_loop(): + for index, alt in enumerate(rule.rhs.alts): + actionname = f"A_{rulename.upper()}_{index}" + self.actions[actionname] = self.translate_action(alt) + + def translate_action(self, alt: Alt) -> str: + # Given an alternative like this: + # | a=NAME '=' b=expr { foo(p, a, b) } + # return a string like this: + # "foo(p, _f->vals[0], _f->vals[2])" + # As a special case, if there's no action, return _f->vals[0]. + name_to_index, index = self.map_alt_names_to_vals_index(alt) + if not alt.action: + # TODO: Restore the assert, but expect index == 2 in Gather + ##assert index == 1, "Alternative with >1 item must have an action" + return self.make_typed_var(alt, 0) + # Sadly, the action is given as a string, so tokenize it back. + # We must not substitute item names when preceded by '.' or '->'. + res = [] + prevs = "" + for stuff in tokenize.generate_tokens(iter([alt.action]).__next__): + _, s, _, _, _ = stuff + if prevs not in (".", "->"): + i = name_to_index.get(s) + if i is not None: + s = self.make_typed_var(alt, i) + res.append(s) + prevs = s + return " ".join(res).strip() + + def map_alt_names_to_vals_index(self, alt: Alt) -> Tuple[Dict[str, int], int]: + index = 0 + map: Dict[str, int] = {} + for nameditem in alt.items: + if nameditem.name: + map[nameditem.name] = index + if isinstance(nameditem.item, (Leaf, Group, Opt, Repeat)): + index += 1 + return map, index + + def make_typed_var(self, alt: Alt, index: int) -> str: + var = f"_f->vals[{index}]" + type = self.get_type_of_indexed_item(alt, index) + if type: + var = f"(({type}){var})" + return var + + def get_type_of_indexed_item(self, alt: Alt, index: int) -> Optional[str]: + item = alt.items[index].item + if isinstance(item, NameLeaf): + if item.value in self.rules: + return self.rules[item.value].type + if item.value == "NAME": + return "expr_ty" + if isinstance(item, StringLeaf): + return "Token *" + return None + + def add_root_rules(self) -> None: + assert "root" not in self.todo + assert "root" not in self.rules + root = RootRule("root", "file") # TODO: determine start rules dynamically + self.todo["root"] = root + self.rules["root"] = root + + def visit_RootRule(self, node: RootRule) -> None: + self.print(f'{{"{node.name}",') + self.print(f" R_{node.name.upper()},") + self.print(f" 0,") + self.print(f" 0,") + + first_alt = Alt([]) + second_alt = Alt([]) + + opcodes_by_alt: Dict[Alt, List[Opcode]] = {first_alt: [], second_alt: []} + with self.set_opcode_buffer(opcodes_by_alt[first_alt]): + self.add_opcode("OP_RULE", f"R_{node.startrulename.upper()}") + self.add_opcode("OP_SUCCESS") + with self.set_opcode_buffer(opcodes_by_alt[second_alt]): + self.add_opcode("OP_FAILURE") + self.generate_opcodes(opcodes_by_alt) + self.print("},") + + def visit_Rule(self, node: Rule) -> None: + is_loop = node.is_loop() + is_loop1 = node.name.startswith("_loop1") + is_gather = node.is_gather() + rhs = node.flatten() + self.print(f'{{"{node.name}",') + self.print(f" R_{node.name.upper()},") + self.print(f" {int(node.memo)}, // memo") + self.print(f" {int(node.left_recursive)}, // leftrec") + self.current_rule = node # TODO: make this a context manager + self.visit( + rhs, + is_loop=is_loop, + is_loop1=is_loop1, + is_gather=is_gather, + is_leftrec=node.left_recursive, + ) + self.print("},") + + def visit_NamedItem(self, node: NamedItem) -> None: + self.visit(node.item) + + def visit_PositiveLookahead(self, node: PositiveLookahead) -> None: + self.add_opcode("OP_SAVE_MARK") + self.visit(node.node) + self.add_opcode("OP_POS_LOOKAHEAD") + + def visit_NegativeLookahead(self, node: PositiveLookahead) -> None: + self.add_opcode("OP_SAVE_MARK") + self.visit(node.node) + self.add_opcode("OP_NEG_LOOKAHEAD") + + def _get_rule_opcode(self, name: str) -> str: + return f"R_{name.upper()}" + + def visit_NameLeaf(self, node: NameLeaf) -> None: + name = node.value + if name in ("NAME", "NUMBER", "STRING"): + self.add_opcode(f"OP_{name}") + elif name in ( + "NEWLINE", + "DEDENT", + "INDENT", + "ENDMARKER", + "ASYNC", + "AWAIT", + "TYPE_COMMENT", + ): + self.add_opcode("OP_TOKEN", name) + else: + self.add_opcode("OP_RULE", self._get_rule_opcode(name)) + + def visit_StringLeaf(self, node: StringLeaf) -> None: + op_pair = self.callmakervisitor.visit(node) + self.add_opcode(*op_pair) + + def visit_Cut(self, node: Cut) -> None: + self.add_opcode("OP_CUT") + + def handle_loop_rhs( + self, node: Rhs, opcodes_by_alt: Dict[Alt, List[Opcode]], collect_opcode: str, + ) -> None: + self.handle_default_rhs(node, opcodes_by_alt, is_loop=True, is_gather=False) + loop_alt = Alt([]) + with self.set_opcode_buffer(opcodes_by_alt[loop_alt]): + self.add_opcode(collect_opcode) + + def handle_default_rhs( + self, + node: Rhs, + opcodes_by_alt: Dict[Alt, List[Opcode]], + is_loop: bool = False, + is_loop1: bool = False, + is_gather: bool = False, + is_leftrec: bool = False, + ) -> None: + for index, alt in enumerate(node.alts): + with self.set_opcode_buffer(opcodes_by_alt[alt]): + self.visit(alt, is_loop=False, is_loop1=False, is_gather=False) + assert not ( + alt.action and (is_loop or is_gather) + ) # A loop rule can't have actions + if is_loop or is_gather: + if index == 0: + self.add_opcode("OP_LOOP_ITERATE") + else: + self.add_opcode("OP_LOOP_COLLECT_DELIMITED") + else: + opcode = "OP_RETURN" + self.add_opcode(opcode, f"A_{self.current_rule.name.upper()}_{index}") + + def visit_Rhs( + self, + node: Rhs, + is_loop: bool = False, + is_loop1: bool = False, + is_gather: bool = False, + is_leftrec: bool = False, + ) -> None: + opcodes_by_alt: Dict[Alt, List[Opcode]] = defaultdict(list) + if is_loop: + opcode = "OP_LOOP_COLLECT" + if is_loop1: + opcode += "_NONEMPTY" + self.handle_loop_rhs(node, opcodes_by_alt, opcode) + else: + self.handle_default_rhs( + node, opcodes_by_alt, is_loop=is_loop, is_gather=is_gather, is_leftrec=is_leftrec + ) + self.generate_opcodes(opcodes_by_alt) + + def generate_opcodes(self, opcodes_by_alt: Dict[Alt, List[Opcode]]) -> None: + *indexes, _ = accumulate( + map(lambda opcodes: sum(map(len, opcodes)), opcodes_by_alt.values()) + ) + indexes = [0, *indexes, -1] + self.print(f" {{{', '.join(map(str, indexes))}}},") + + self.print(" {") + with self.indent(): + for alt, opcodes in opcodes_by_alt.items(): + self.print(f"// {alt if str(alt) else ''}") + for opcode in opcodes: + oparg_text = str(opcode.oparg) + "," if opcode.oparg else "" + self.print(f"{opcode.opcode}, {oparg_text}") + self.print() + self.print(" },") + + def visit_Alt(self, node: Alt, is_loop: bool, is_loop1: bool, is_gather: bool) -> None: + for item in node.items: + self.visit(item) + + def group_helper(self, node: Rhs) -> None: + name = self.callmakervisitor.visit(node) + if name: + self.add_opcode("OP_RULE", self._get_rule_opcode(name)) + else: + self.visit(node.alts[0].items[0]) + + def visit_Opt(self, node: Opt) -> None: + if isinstance(node.node, Rhs): + self.group_helper(node.node) + else: + self.visit(node.node) + self.add_opcode("OP_OPTIONAL") + + def visit_Group(self, node: Group) -> None: + self.group_helper(node.rhs) + + def visit_Repeat0(self, node: Repeat0) -> None: + name = self.callmakervisitor.visit(node) + self.add_opcode("OP_RULE", self._get_rule_opcode(name)) + + def visit_Repeat1(self, node: Repeat1) -> None: + name = self.callmakervisitor.visit(node) + self.add_opcode("OP_RULE", self._get_rule_opcode(name)) + + def visit_Gather(self, node: Gather) -> None: + name = self.callmakervisitor.visit(node) + self.add_opcode("OP_RULE", self._get_rule_opcode(name)) + + +def main() -> None: + from pegen.build import build_parser + filename = "../../Grammar/python.gram" + if sys.argv[1:]: + filename = sys.argv[1] + grammar, parser, tokenizer = build_parser(filename, False, False) + p = VMParserGenerator(grammar) + p.generate("") + + +if __name__ == "__main__": + main()