| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290 |
- # Copyright (c) 2016-2017, 2019-2020, 2022-2024 Rocky Bernstein
- """
- Python 3.7 base code. We keep non-custom-generated grammar rules out of this file.
- """
- from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
- from spark_parser.spark import rule2str
- from uncompyle6.parser import ParserError, PythonParser, nop_func
- from uncompyle6.parsers.reducecheck import (
- and_invalid,
- ifelsestmt,
- iflaststmt,
- ifstmt,
- ifstmts_jump,
- or_check,
- testtrue,
- tryelsestmtl3,
- while1elsestmt,
- while1stmt,
- )
- from uncompyle6.parsers.treenode import SyntaxTree
- class Python37BaseParser(PythonParser):
- def __init__(self, debug_parser=PARSER_DEFAULT_DEBUG):
- self.added_rules = set()
- super(Python37BaseParser, self).__init__(
- SyntaxTree, "stmts", debug=debug_parser
- )
- self.new_rules = set()
- @staticmethod
- def call_fn_name(token):
- """Customize CALL_FUNCTION to add the number of positional arguments"""
- if token.attr is not None:
- return "%s_%i" % (token.kind, token.attr)
- else:
- return "%s_0" % (token.kind)
- def add_make_function_rule(self, rule, opname, attr, customize):
- """Python 3.3 added a an additional LOAD_STR before MAKE_FUNCTION and
- this has an effect on many rules.
- """
- new_rule = rule % "LOAD_STR "
- self.add_unique_rule(new_rule, opname, attr, customize)
- def custom_build_class_rule(self, opname, i, token, tokens, customize):
- """
- # Should the first rule be somehow folded into the 2nd one?
- build_class ::= LOAD_BUILD_CLASS mkfunc
- LOAD_CLASSNAME {expr}^n-1 CALL_FUNCTION_n
- LOAD_CONST CALL_FUNCTION_n
- build_class ::= LOAD_BUILD_CLASS mkfunc
- expr
- call
- CALL_FUNCTION_3
- """
- # FIXME: I bet this can be simplified
- # look for next MAKE_FUNCTION
- for i in range(i + 1, len(tokens)):
- if tokens[i].kind.startswith("MAKE_FUNCTION"):
- break
- elif tokens[i].kind.startswith("MAKE_CLOSURE"):
- break
- pass
- assert i < len(
- tokens
- ), "build_class needs to find MAKE_FUNCTION or MAKE_CLOSURE"
- assert (
- tokens[i + 1].kind == "LOAD_STR"
- ), "build_class expecting CONST after MAKE_FUNCTION/MAKE_CLOSURE"
- call_fn_tok = None
- for i in range(i, len(tokens)):
- if tokens[i].kind.startswith("CALL_FUNCTION"):
- call_fn_tok = tokens[i]
- break
- if not call_fn_tok:
- raise RuntimeError(
- "build_class custom rule for %s needs to find CALL_FUNCTION" % opname
- )
- # customize build_class rule
- # FIXME: What's the deal with the two rules? Different Python versions?
- # Different situations? Note that the above rule is based on the CALL_FUNCTION
- # token found, while this one doesn't.
- # 3.6+ handling
- call_function = call_fn_tok.kind
- if call_function.startswith("CALL_FUNCTION_KW"):
- self.addRule("classdef ::= build_class_kw store", nop_func)
- rule = "build_class_kw ::= LOAD_BUILD_CLASS mkfunc %sLOAD_CONST %s" % (
- "expr " * (call_fn_tok.attr - 1),
- call_function,
- )
- else:
- call_function = self.call_fn_name(call_fn_tok)
- rule = "build_class ::= LOAD_BUILD_CLASS mkfunc %s%s" % (
- "expr " * (call_fn_tok.attr - 1),
- call_function,
- )
- self.addRule(rule, nop_func)
- return
- # FIXME FIXME FIXME: The below is an utter mess. Come up with a better
- # organization for this. For example, arrange organize by opcode base?
- def customize_grammar_rules(self, tokens, customize):
- is_pypy = False
- # For a rough break out on the first word. This may
- # include instructions that don't need customization,
- # but we'll do a finer check after the rough breakout.
- customize_instruction_basenames = frozenset(
- (
- "BEFORE",
- "BUILD",
- "CALL",
- "CONTINUE",
- "DELETE",
- "FORMAT",
- "GET",
- "JUMP",
- "LOAD",
- "LOOKUP",
- "MAKE",
- "RETURN",
- "RAISE",
- "SETUP",
- "UNPACK",
- "WITH",
- )
- )
- # Opcode names in the custom_ops_processed set have rules that get added
- # unconditionally and the rules are constant. So they need to be done
- # only once and if we see the opcode a second we don't have to consider
- # adding more rules.
- #
- # Note: BUILD_TUPLE_UNPACK_WITH_CALL gets considered by
- # default because it starts with BUILD. So we'll set to ignore it from
- # the start.
- custom_ops_processed = {"BUILD_TUPLE_UNPACK_WITH_CALL"}
- # A set of instruction operation names that exist in the token stream.
- # We use this customize the grammar that we create.
- # 2.6-compatible set comprehensions
- self.seen_ops = frozenset([t.kind for t in tokens])
- self.seen_op_basenames = frozenset(
- [opname[: opname.rfind("_")] for opname in self.seen_ops]
- )
- # Loop over instructions adding custom grammar rules based on
- # a specific instruction seen.
- if "PyPy" in customize:
- is_pypy = True
- self.addRule(
- """
- stmt ::= assign3_pypy
- stmt ::= assign2_pypy
- assign3_pypy ::= expr expr expr store store store
- assign2_pypy ::= expr expr store store
- stmt ::= if_exp_lambda
- stmt ::= if_exp_not_lambda
- if_exp_lambda ::= expr jmp_false expr return_if_lambda
- return_expr_lambda LAMBDA_MARKER
- if_exp_not_lambda ::= expr jmp_true expr return_if_lambda
- return_expr_lambda LAMBDA_MARKER
- """,
- nop_func,
- )
- n = len(tokens)
- # Determine if we have an iteration CALL_FUNCTION_1.
- has_get_iter_call_function1 = False
- for i, token in enumerate(tokens):
- if (
- token == "GET_ITER"
- and i < n - 2
- and self.call_fn_name(tokens[i + 1]) == "CALL_FUNCTION_1"
- ):
- has_get_iter_call_function1 = True
- for i, token in enumerate(tokens):
- opname = token.kind
- # Do a quick breakout before testing potentially
- # each of the dozen or so instruction in if elif.
- if (
- opname[: opname.find("_")] not in customize_instruction_basenames
- or opname in custom_ops_processed
- ):
- continue
- opname_base = opname[: opname.rfind("_")]
- # The order of opname listed is roughly sorted below
- if opname == "LOAD_ASSERT" and "PyPy" in customize:
- rules_str = """
- stmt ::= JUMP_IF_NOT_DEBUG stmts COME_FROM
- """
- self.add_unique_doc_rules(rules_str, customize)
- elif opname == "BEFORE_ASYNC_WITH":
- rules_str = """
- stmt ::= async_with_stmt
- stmt ::= async_with_as_stmt
- """
- if self.version < (3, 8):
- rules_str += """
- stmt ::= async_with_stmt SETUP_ASYNC_WITH
- c_stmt ::= c_async_with_stmt SETUP_ASYNC_WITH
- async_with_stmt ::= expr
- async_with_pre
- POP_TOP
- suite_stmts_opt
- POP_BLOCK LOAD_CONST
- async_with_post
- c_async_with_stmt ::= expr
- async_with_pre
- POP_TOP
- c_suite_stmts_opt
- POP_BLOCK LOAD_CONST
- async_with_post
- async_with_stmt ::= expr
- async_with_pre
- POP_TOP
- suite_stmts_opt
- async_with_post
- c_async_with_stmt ::= expr
- async_with_pre
- POP_TOP
- c_suite_stmts_opt
- async_with_post
- async_with_as_stmt ::= expr
- async_with_pre
- store
- suite_stmts_opt
- POP_BLOCK LOAD_CONST
- async_with_post
- c_async_with_as_stmt ::= expr
- async_with_pre
- store
- c_suite_stmts_opt
- POP_BLOCK LOAD_CONST
- async_with_post
- async_with_as_stmt ::= expr
- async_with_pre
- store
- suite_stmts_opt
- async_with_post
- c_async_with_as_stmt ::= expr
- async_with_pre
- store
- suite_stmts_opt
- async_with_post
- """
- else:
- rules_str += """
- async_with_pre ::= BEFORE_ASYNC_WITH GET_AWAITABLE LOAD_CONST YIELD_FROM SETUP_ASYNC_WITH
- async_with_post ::= BEGIN_FINALLY COME_FROM_ASYNC_WITH
- WITH_CLEANUP_START GET_AWAITABLE LOAD_CONST YIELD_FROM
- WITH_CLEANUP_FINISH END_FINALLY
- async_with_stmt ::= expr
- async_with_pre
- POP_TOP
- suite_stmts
- POP_TOP POP_BLOCK
- async_with_post
- c_async_with_stmt ::= expr
- async_with_pre
- POP_TOP
- c_suite_stmts
- POP_TOP POP_BLOCK
- async_with_post
- async_with_stmt ::= expr
- async_with_pre
- POP_TOP
- suite_stmts
- POP_BLOCK
- BEGIN_FINALLY
- WITH_CLEANUP_START GET_AWAITABLE LOAD_CONST YIELD_FROM
- WITH_CLEANUP_FINISH POP_FINALLY LOAD_CONST RETURN_VALUE
- COME_FROM_ASYNC_WITH
- WITH_CLEANUP_START GET_AWAITABLE LOAD_CONST YIELD_FROM
- WITH_CLEANUP_FINISH END_FINALLY
- c_async_with_stmt ::= expr
- async_with_pre
- POP_TOP
- c_suite_stmts
- POP_BLOCK
- BEGIN_FINALLY
- WITH_CLEANUP_START GET_AWAITABLE LOAD_CONST YIELD_FROM
- WITH_CLEANUP_FINISH POP_FINALLY LOAD_CONST RETURN_VALUE
- COME_FROM_ASYNC_WITH
- WITH_CLEANUP_START GET_AWAITABLE LOAD_CONST YIELD_FROM
- WITH_CLEANUP_FINISH END_FINALLY
- async_with_as_stmt ::= expr
- async_with_pre
- store suite_stmts
- POP_TOP POP_BLOCK
- async_with_post
- c_async_with_as_stmt ::= expr
- async_with_pre
- store suite_stmts
- POP_TOP POP_BLOCK
- async_with_post
- async_with_as_stmt ::= expr
- async_with_pre
- store suite_stmts
- POP_BLOCK async_with_post
- c_async_with_as_stmt ::= expr
- async_with_pre
- store suite_stmts
- POP_BLOCK async_with_post
- """
- self.addRule(rules_str, nop_func)
- elif opname in ("BUILD_CONST_LIST", "BUILD_CONST_DICT", "BUILD_CONST_SET"):
- if opname == "BUILD_CONST_DICT":
- rule = f"""
- add_consts ::= ADD_VALUE*
- const_list ::= COLLECTION_START add_consts {opname}
- dict ::= const_list
- expr ::= dict
- """
- else:
- rule = f"""
- add_consts ::= ADD_VALUE*
- const_list ::= COLLECTION_START add_consts {opname}
- expr ::= const_list
- """
- self.addRule(rule, nop_func)
- elif opname_base == "BUILD_CONST_KEY_MAP":
- kvlist_n = "expr " * (token.attr)
- rule = "dict ::= %sLOAD_CONST %s" % (kvlist_n, opname)
- self.addRule(rule, nop_func)
- elif opname.startswith("BUILD_LIST_UNPACK"):
- v = token.attr
- rule = "build_list_unpack ::= %s%s" % ("expr " * v, opname)
- self.addRule(rule, nop_func)
- rule = "expr ::= build_list_unpack"
- self.addRule(rule, nop_func)
- elif opname_base in ("BUILD_MAP", "BUILD_MAP_UNPACK"):
- if opname == "BUILD_MAP_UNPACK":
- self.addRule(
- """
- expr ::= dict_unpack
- dict_unpack ::= dict_comp BUILD_MAP_UNPACK
- """,
- nop_func,
- )
- pass
- elif opname.startswith("BUILD_MAP_UNPACK_WITH_CALL"):
- v = token.attr
- rule = "build_map_unpack_with_call ::= %s%s" % ("expr " * v, opname)
- self.addRule(rule, nop_func)
- kvlist_n = "kvlist_%s" % token.attr
- if opname == "BUILD_MAP_n":
- # PyPy sometimes has no count. Sigh.
- rule = (
- "dict_comp_func ::= BUILD_MAP_n LOAD_ARG for_iter store "
- "comp_iter JUMP_BACK RETURN_VALUE RETURN_LAST"
- )
- self.add_unique_rule(rule, "dict_comp_func", 1, customize)
- kvlist_n = "kvlist_n"
- rule = "kvlist_n ::= kvlist_n kv3"
- self.add_unique_rule(rule, "kvlist_n", 0, customize)
- rule = "kvlist_n ::="
- self.add_unique_rule(rule, "kvlist_n", 1, customize)
- rule = "dict ::= BUILD_MAP_n kvlist_n"
- if not opname.startswith("BUILD_MAP_WITH_CALL"):
- # FIXME: Use the attr
- # so this doesn't run into exponential parsing time.
- if opname.startswith("BUILD_MAP_UNPACK"):
- # FIXME: start here. The LHS should be dict_unpack, not dict.
- # FIXME: really we need a combination of dict_entry-like things.
- # It just so happens the most common case is not to mix
- # dictionary comphensions with dictionary, elements
- if "LOAD_DICTCOMP" in self.seen_ops:
- rule = "dict ::= %s%s" % ("dict_comp " * token.attr, opname)
- self.addRule(rule, nop_func)
- rule = """
- expr ::= dict_unpack
- dict_unpack ::= %s%s
- """ % (
- "expr " * token.attr,
- opname,
- )
- else:
- rule = "%s ::= %s %s" % (
- kvlist_n,
- "expr " * (token.attr * 2),
- opname,
- )
- self.add_unique_rule(rule, opname, token.attr, customize)
- rule = "dict ::= %s" % kvlist_n
- self.add_unique_rule(rule, opname, token.attr, customize)
- elif opname.startswith("BUILD_MAP_UNPACK_WITH_CALL"):
- v = token.attr
- rule = "build_map_unpack_with_call ::= %s%s" % ("expr " * v, opname)
- self.addRule(rule, nop_func)
- elif opname.startswith("BUILD_TUPLE_UNPACK_WITH_CALL"):
- v = token.attr
- rule = (
- "build_tuple_unpack_with_call ::= "
- + "expr1024 " * int(v // 1024)
- + "expr32 " * int((v // 32) % 32)
- + "expr " * (v % 32)
- + opname
- )
- self.addRule(rule, nop_func)
- rule = "starred ::= %s %s" % ("expr " * v, opname)
- self.addRule(rule, nop_func)
- elif opname_base in (
- "BUILD_LIST",
- "BUILD_SET",
- "BUILD_TUPLE",
- "BUILD_TUPLE_UNPACK",
- ):
- collection_size = token.attr
- is_LOAD_CLOSURE = False
- if opname_base == "BUILD_TUPLE":
- # If is part of a "load_closure", then it is not part of a
- # "list".
- is_LOAD_CLOSURE = True
- for j in range(collection_size):
- if tokens[i - j - 1].kind != "LOAD_CLOSURE":
- is_LOAD_CLOSURE = False
- break
- if is_LOAD_CLOSURE:
- rule = "load_closure ::= %s%s" % (
- ("LOAD_CLOSURE " * collection_size),
- opname,
- )
- self.add_unique_rule(rule, opname, token.attr, customize)
- if not is_LOAD_CLOSURE or collection_size == 0:
- # We do this complicated test to speed up parsing of
- # pathelogically long literals, especially those over 1024.
- thousands = collection_size // 1024
- thirty32s = (collection_size // 32) % 32
- if thirty32s > 0:
- rule = "expr32 ::=%s" % (" expr" * 32)
- self.add_unique_rule(
- rule, opname_base, collection_size, customize
- )
- pass
- if thousands > 0:
- self.add_unique_rule(
- "expr1024 ::=%s" % (" expr32" * 32),
- opname_base,
- collection_size,
- customize,
- )
- pass
- collection = opname_base[opname_base.find("_") + 1 :].lower()
- rule = (
- ("%s ::= " % collection)
- + "expr1024 " * thousands
- + "expr32 " * thirty32s
- + "expr " * (collection_size % 32)
- + opname
- )
- self.add_unique_rules(["expr ::= %s" % collection, rule], customize)
- continue
- continue
- elif opname_base == "BUILD_SLICE":
- if token.attr == 2:
- self.add_unique_rules(
- [
- "expr ::= slice2",
- "slice2 ::= expr expr BUILD_SLICE_2",
- ],
- customize,
- )
- else:
- assert token.attr == 3, (
- "BUILD_SLICE value must be 2 or 3; is %s" % token.attr
- )
- self.add_unique_rules(
- [
- "expr ::= slice3",
- "slice3 ::= expr expr expr BUILD_SLICE_3",
- ],
- customize,
- )
- elif opname.startswith("BUILD_STRING"):
- v = token.attr
- rules_str = """
- expr ::= joined_str
- joined_str ::= %sBUILD_STRING_%d
- """ % (
- "expr " * v,
- v,
- )
- self.add_unique_doc_rules(rules_str, customize)
- if "FORMAT_VALUE_ATTR" in self.seen_ops:
- rules_str = """
- formatted_value_attr ::= expr expr FORMAT_VALUE_ATTR expr BUILD_STRING
- expr ::= formatted_value_attr
- """
- self.add_unique_doc_rules(rules_str, customize)
- elif opname in frozenset(
- (
- "CALL_FUNCTION",
- "CALL_FUNCTION_EX",
- "CALL_FUNCTION_EX_KW",
- "CALL_FUNCTION_VAR",
- "CALL_FUNCTION_VAR_KW",
- )
- ) or opname.startswith("CALL_FUNCTION_KW"):
- if opname == "CALL_FUNCTION" and token.attr == 1:
- rule = """
- expr ::= dict_comp
- dict_comp ::= LOAD_DICTCOMP LOAD_STR MAKE_FUNCTION_0 expr
- GET_ITER CALL_FUNCTION_1
- classdefdeco1 ::= expr classdefdeco2 CALL_FUNCTION_1
- classdefdeco1 ::= expr classdefdeco1 CALL_FUNCTION_1
- """
- self.addRule(rule, nop_func)
- self.custom_classfunc_rule(opname, token, customize, tokens[i + 1])
- # Note: don't add to custom_ops_processed.
- elif opname_base == "CALL_METHOD":
- # PyPy and Python 3.7+ only - DRY with parse2
- args_pos, args_kw = self.get_pos_kw(token)
- if opname == "CALL_METHOD_KW":
- args_kw = token.attr
- rules_str = """
- expr ::= call_kw_pypy37
- pypy_kw_keys ::= LOAD_CONST
- """
- self.add_unique_doc_rules(rules_str, customize)
- rule = (
- "call_kw_pypy37 ::= expr "
- + ("expr " * args_kw)
- + " pypy_kw_keys "
- + opname
- )
- else:
- args_pos, args_kw = self.get_pos_kw(token)
- # number of apply equiv arguments:
- nak = (len(opname_base) - len("CALL_METHOD")) // 3
- rule = (
- "call ::= expr "
- + ("pos_arg " * args_pos)
- + ("kwarg " * args_kw)
- + "expr " * nak
- + opname
- )
- self.add_unique_rule(rule, opname, token.attr, customize)
- elif opname == "CONTINUE":
- self.addRule("continue ::= CONTINUE", nop_func)
- custom_ops_processed.add(opname)
- elif opname == "CONTINUE_LOOP":
- self.addRule("continue ::= CONTINUE_LOOP", nop_func)
- custom_ops_processed.add(opname)
- elif opname == "DELETE_ATTR":
- self.addRule("delete ::= expr DELETE_ATTR", nop_func)
- custom_ops_processed.add(opname)
- elif opname == "DELETE_DEREF":
- self.addRule(
- """
- stmt ::= del_deref_stmt
- del_deref_stmt ::= DELETE_DEREF
- """,
- nop_func,
- )
- custom_ops_processed.add(opname)
- elif opname == "DELETE_SUBSCR":
- self.addRule(
- """
- delete ::= delete_subscript
- delete_subscript ::= expr expr DELETE_SUBSCR
- """,
- nop_func,
- )
- custom_ops_processed.add(opname)
- elif opname == "FORMAT_VALUE":
- rules_str = """
- expr ::= formatted_value1
- formatted_value1 ::= expr FORMAT_VALUE
- """
- self.add_unique_doc_rules(rules_str, customize)
- elif opname == "GET_ANEXT":
- self.addRule(
- """
- func_async_prefix ::= _come_froms SETUP_FINALLY GET_ANEXT LOAD_CONST YIELD_FROM POP_BLOCK
- func_async_middle ::= JUMP_FORWARD COME_FROM_EXCEPT
- DUP_TOP LOAD_GLOBAL COMPARE_OP POP_JUMP_IF_TRUE
- list_afor2 ::= func_async_prefix
- store list_iter
- JUMP_BACK COME_FROM_FINALLY
- END_ASYNC_FOR
- """,
- nop_func,
- )
- custom_ops_processed.add(opname)
- elif opname == "FORMAT_VALUE_ATTR":
- rules_str = """
- expr ::= formatted_value2
- formatted_value2 ::= expr expr FORMAT_VALUE_ATTR
- """
- self.add_unique_doc_rules(rules_str, customize)
- elif opname == "GET_ITER":
- self.addRule(
- """
- expr ::= get_iter
- get_iter ::= expr GET_ITER
- """,
- nop_func,
- )
- custom_ops_processed.add(opname)
- elif opname == "GET_AITER":
- self.addRule(
- """
- expr ::= generator_exp_async
- generator_exp_async ::= load_genexpr LOAD_STR MAKE_FUNCTION_0 expr
- GET_AITER CALL_FUNCTION_1
- stmt ::= genexpr_func_async
- func_async_prefix ::= _come_froms SETUP_EXCEPT GET_ANEXT LOAD_CONST YIELD_FROM
- func_async_middle ::= POP_BLOCK JUMP_FORWARD COME_FROM_EXCEPT
- DUP_TOP LOAD_GLOBAL COMPARE_OP POP_JUMP_IF_TRUE
- END_FINALLY COME_FROM
- genexpr_func_async ::= LOAD_ARG func_async_prefix
- store func_async_middle comp_iter
- JUMP_BACK COME_FROM
- POP_TOP POP_TOP POP_TOP POP_EXCEPT POP_TOP
- expr ::= list_comp_async
- list_comp_async ::= LOAD_LISTCOMP LOAD_STR MAKE_FUNCTION_0
- expr GET_AITER CALL_FUNCTION_1
- GET_AWAITABLE LOAD_CONST
- YIELD_FROM
- expr ::= list_comp_async
- list_afor2 ::= func_async_prefix
- store func_async_middle list_iter
- JUMP_BACK COME_FROM
- POP_TOP POP_TOP POP_TOP POP_EXCEPT POP_TOP
- list_comp_async ::= BUILD_LIST_0 LOAD_ARG list_afor2
- get_aiter ::= expr GET_AITER
- list_afor ::= get_aiter list_afor2
- list_iter ::= list_afor
- """,
- nop_func,
- )
- elif opname == "JUMP_IF_NOT_DEBUG":
- v = token.attr
- self.addRule(
- """
- stmt ::= assert_pypy
- stmt ::= assert2_pypy", nop_func)
- assert_pypy ::= JUMP_IF_NOT_DEBUG expr jmp_true
- LOAD_ASSERT RAISE_VARARGS_1 COME_FROM
- assert2_pypy ::= JUMP_IF_NOT_DEBUG assert_expr jmp_true
- LOAD_ASSERT expr CALL_FUNCTION_1
- RAISE_VARARGS_1 COME_FROM
- assert2_pypy ::= JUMP_IF_NOT_DEBUG expr jmp_true
- LOAD_ASSERT expr CALL_FUNCTION_1
- RAISE_VARARGS_1 COME_FROM,
- """,
- nop_func,
- )
- custom_ops_processed.add(opname)
- elif opname == "LOAD_BUILD_CLASS":
- self.custom_build_class_rule(opname, i, token, tokens, customize)
- # Note: don't add to custom_ops_processed.
- elif opname == "LOAD_CLASSDEREF":
- # Python 3.4+
- self.addRule("expr ::= LOAD_CLASSDEREF", nop_func)
- custom_ops_processed.add(opname)
- elif opname == "LOAD_CLASSNAME":
- self.addRule("expr ::= LOAD_CLASSNAME", nop_func)
- custom_ops_processed.add(opname)
- elif opname == "LOAD_DICTCOMP":
- if has_get_iter_call_function1:
- rule_pat = (
- "dict_comp ::= LOAD_DICTCOMP %sMAKE_FUNCTION_0 expr "
- "GET_ITER CALL_FUNCTION_1"
- )
- self.add_make_function_rule(rule_pat, opname, token.attr, customize)
- pass
- custom_ops_processed.add(opname)
- elif opname == "LOAD_ATTR":
- self.addRule(
- """
- expr ::= attribute
- attribute ::= expr LOAD_ATTR
- """,
- nop_func,
- )
- custom_ops_processed.add(opname)
- elif opname == "LOAD_LISTCOMP":
- self.add_unique_rule(
- "expr ::= list_comp", opname, token.attr, customize
- )
- custom_ops_processed.add(opname)
- elif opname == "LOAD_NAME":
- if (
- token.attr == "__annotations__"
- and "SETUP_ANNOTATIONS" in self.seen_ops
- ):
- token.kind = "LOAD_ANNOTATION"
- self.addRule(
- """
- stmt ::= SETUP_ANNOTATIONS
- stmt ::= ann_assign
- ann_assign ::= expr LOAD_ANNOTATION LOAD_STR STORE_SUBSCR
- """,
- nop_func,
- )
- pass
- elif opname == "LOAD_SETCOMP":
- # Should this be generalized and put under MAKE_FUNCTION?
- if has_get_iter_call_function1:
- self.addRule("expr ::= set_comp", nop_func)
- rule_pat = (
- "set_comp ::= LOAD_SETCOMP %sMAKE_FUNCTION_0 expr "
- "GET_ITER CALL_FUNCTION_1"
- )
- self.add_make_function_rule(rule_pat, opname, token.attr, customize)
- pass
- custom_ops_processed.add(opname)
- elif opname == "LOOKUP_METHOD":
- # A PyPy speciality - DRY with parse3
- self.addRule(
- """
- expr ::= attribute
- attribute ::= expr LOOKUP_METHOD
- """,
- nop_func,
- )
- custom_ops_processed.add(opname)
- elif opname.startswith("MAKE_CLOSURE"):
- # DRY with MAKE_FUNCTION
- # Note: this probably doesn't handle kwargs proprerly
- if opname == "MAKE_CLOSURE_0" and "LOAD_DICTCOMP" in self.seen_ops:
- # Is there something general going on here?
- # Note that 3.6+ doesn't do this, but we'll remove
- # this rule in parse36.py
- rule = """
- dict_comp ::= load_closure LOAD_DICTCOMP LOAD_STR
- MAKE_CLOSURE_0 expr
- GET_ITER CALL_FUNCTION_1
- """
- self.addRule(rule, nop_func)
- args_pos, args_kw, annotate_args = token.attr
- # FIXME: Fold test into add_make_function_rule
- j = 2
- if is_pypy or (i >= j and tokens[i - j] == "LOAD_LAMBDA"):
- rule_pat = "lambda_body ::= %sload_closure LOAD_LAMBDA %%s%s" % (
- "pos_arg " * args_pos,
- opname,
- )
- self.add_make_function_rule(rule_pat, opname, token.attr, customize)
- if has_get_iter_call_function1:
- rule_pat = (
- "generator_exp ::= %sload_closure load_genexpr %%s%s expr "
- "GET_ITER CALL_FUNCTION_1" % ("pos_arg " * args_pos, opname)
- )
- self.add_make_function_rule(rule_pat, opname, token.attr, customize)
- if has_get_iter_call_function1:
- if is_pypy or (i >= j and tokens[i - j] == "LOAD_LISTCOMP"):
- # In the tokens we saw:
- # LOAD_LISTCOMP LOAD_CONST MAKE_FUNCTION (>= 3.3) or
- # LOAD_LISTCOMP MAKE_FUNCTION (< 3.3) or
- # and have GET_ITER CALL_FUNCTION_1
- # Todo: For Pypy we need to modify this slightly
- rule_pat = (
- "list_comp ::= %sload_closure LOAD_LISTCOMP %%s%s expr "
- "GET_ITER CALL_FUNCTION_1"
- % ("pos_arg " * args_pos, opname)
- )
- self.add_make_function_rule(
- rule_pat, opname, token.attr, customize
- )
- if is_pypy or (i >= j and tokens[i - j] == "LOAD_SETCOMP"):
- rule_pat = (
- "set_comp ::= %sload_closure LOAD_SETCOMP %%s%s expr "
- "GET_ITER CALL_FUNCTION_1"
- % ("pos_arg " * args_pos, opname)
- )
- self.add_make_function_rule(
- rule_pat, opname, token.attr, customize
- )
- if is_pypy or (i >= j and tokens[i - j] == "LOAD_DICTCOMP"):
- self.add_unique_rule(
- "dict_comp ::= %sload_closure LOAD_DICTCOMP %s "
- "expr GET_ITER CALL_FUNCTION_1"
- % ("pos_arg " * args_pos, opname),
- opname,
- token.attr,
- customize,
- )
- if args_kw > 0:
- kwargs_str = "kwargs "
- else:
- kwargs_str = ""
- rule = "mkfunc ::= %s%s%s load_closure LOAD_CODE LOAD_STR %s" % (
- "expr " * args_pos,
- kwargs_str,
- "expr " * annotate_args,
- opname,
- )
- self.add_unique_rule(rule, opname, token.attr, customize)
- if args_kw == 0:
- rule = "mkfunc ::= %sload_closure load_genexpr %s" % (
- "pos_arg " * args_pos,
- opname,
- )
- self.add_unique_rule(rule, opname, token.attr, customize)
- pass
- elif opname_base.startswith("MAKE_FUNCTION"):
- args_pos, args_kw, annotate_args, closure = token.attr
- stack_count = args_pos + args_kw + annotate_args
- if closure:
- if args_pos:
- rule = "lambda_body ::= %s%s%s%s" % (
- "expr " * stack_count,
- "load_closure " * closure,
- "BUILD_TUPLE_1 LOAD_LAMBDA LOAD_STR ",
- opname,
- )
- else:
- rule = "lambda_body ::= %s%s%s" % (
- "load_closure " * closure,
- "LOAD_LAMBDA LOAD_STR ",
- opname,
- )
- self.add_unique_rule(rule, opname, token.attr, customize)
- else:
- rule = "lambda_body ::= %sLOAD_LAMBDA LOAD_STR %s" % (
- ("expr " * stack_count),
- opname,
- )
- self.add_unique_rule(rule, opname, token.attr, customize)
- rule = "mkfunc ::= %s%s%s%s" % (
- "expr " * stack_count,
- "load_closure " * closure,
- "LOAD_CODE LOAD_STR ",
- opname,
- )
- self.add_unique_rule(rule, opname, token.attr, customize)
- if has_get_iter_call_function1:
- rule_pat = (
- "generator_exp ::= %sload_genexpr %%s%s expr "
- "GET_ITER CALL_FUNCTION_1" % ("pos_arg " * args_pos, opname)
- )
- self.add_make_function_rule(rule_pat, opname, token.attr, customize)
- rule_pat = (
- "generator_exp ::= %sload_closure load_genexpr %%s%s expr "
- "GET_ITER CALL_FUNCTION_1" % ("pos_arg " * args_pos, opname)
- )
- self.add_make_function_rule(rule_pat, opname, token.attr, customize)
- if is_pypy or (i >= 2 and tokens[i - 2] == "LOAD_LISTCOMP"):
- # 3.6+ sometimes bundles all of the
- # 'exprs' in the rule above into a
- # tuple.
- rule_pat = (
- "list_comp ::= load_closure LOAD_LISTCOMP %%s%s "
- "expr GET_ITER CALL_FUNCTION_1" % (opname,)
- )
- self.add_make_function_rule(
- rule_pat, opname, token.attr, customize
- )
- rule_pat = (
- "list_comp ::= %sLOAD_LISTCOMP %%s%s expr "
- "GET_ITER CALL_FUNCTION_1" % ("expr " * args_pos, opname)
- )
- self.add_make_function_rule(
- rule_pat, opname, token.attr, customize
- )
- if is_pypy or (i >= 2 and tokens[i - 2] == "LOAD_LAMBDA"):
- rule_pat = "lambda_body ::= %s%sLOAD_LAMBDA %%s%s" % (
- ("pos_arg " * args_pos),
- ("kwarg " * args_kw),
- opname,
- )
- self.add_make_function_rule(rule_pat, opname, token.attr, customize)
- continue
- args_pos, args_kw, annotate_args, closure = token.attr
- j = 2
- if has_get_iter_call_function1:
- rule_pat = (
- "generator_exp ::= %sload_genexpr %%s%s expr "
- "GET_ITER CALL_FUNCTION_1" % ("pos_arg " * args_pos, opname)
- )
- self.add_make_function_rule(rule_pat, opname, token.attr, customize)
- if is_pypy or (i >= j and tokens[i - j] == "LOAD_LISTCOMP"):
- # In the tokens we saw:
- # LOAD_LISTCOMP LOAD_CONST MAKE_FUNCTION (>= 3.3) or
- # LOAD_LISTCOMP MAKE_FUNCTION (< 3.3) or
- # and have GET_ITER CALL_FUNCTION_1
- # Todo: For Pypy we need to modify this slightly
- rule_pat = (
- "list_comp ::= %sLOAD_LISTCOMP %%s%s expr "
- "GET_ITER CALL_FUNCTION_1" % ("expr " * args_pos, opname)
- )
- self.add_make_function_rule(
- rule_pat, opname, token.attr, customize
- )
- # FIXME: Fold test into add_make_function_rule
- if is_pypy or (i >= j and tokens[i - j] == "LOAD_LAMBDA"):
- rule_pat = "lambda_body ::= %s%sLOAD_LAMBDA %%s%s" % (
- ("pos_arg " * args_pos),
- ("kwarg " * args_kw),
- opname,
- )
- self.add_make_function_rule(rule_pat, opname, token.attr, customize)
- if args_kw == 0:
- kwargs = "no_kwargs"
- self.add_unique_rule("no_kwargs ::=", opname, token.attr, customize)
- else:
- kwargs = "kwargs"
- # positional args before keyword args
- rule = "mkfunc ::= %s%s %s%s" % (
- "pos_arg " * args_pos,
- kwargs,
- "LOAD_CODE LOAD_STR ",
- opname,
- )
- self.add_unique_rule(rule, opname, token.attr, customize)
- elif opname == "MAKE_FUNCTION_CLOSURE":
- if "LOAD_DICTCOMP" in self.seen_ops:
- # Is there something general going on here?
- rule = """
- dict_comp ::= load_closure LOAD_DICTCOMP LOAD_STR
- MAKE_FUNCTION_CLOSURE expr
- GET_ITER CALL_FUNCTION_1
- """
- self.addRule(rule, nop_func)
- elif "LOAD_SETCOMP" in self.seen_ops:
- rule = """
- set_comp ::= load_closure LOAD_SETCOMP LOAD_STR
- MAKE_FUNCTION_CLOSURE expr
- GET_ITER CALL_FUNCTION_1
- """
- self.addRule(rule, nop_func)
- elif opname == "RETURN_VALUE_LAMBDA":
- self.addRule(
- """
- return_expr_lambda ::= return_expr RETURN_VALUE_LAMBDA
- """,
- nop_func,
- )
- custom_ops_processed.add(opname)
- elif opname == "RAISE_VARARGS_0":
- self.addRule(
- """
- stmt ::= raise_stmt0
- raise_stmt0 ::= RAISE_VARARGS_0
- """,
- nop_func,
- )
- custom_ops_processed.add(opname)
- elif opname == "RAISE_VARARGS_1":
- self.addRule(
- """
- stmt ::= raise_stmt1
- raise_stmt1 ::= expr RAISE_VARARGS_1
- """,
- nop_func,
- )
- custom_ops_processed.add(opname)
- elif opname == "RAISE_VARARGS_2":
- self.addRule(
- """
- stmt ::= raise_stmt2
- raise_stmt2 ::= expr expr RAISE_VARARGS_2
- """,
- nop_func,
- )
- custom_ops_processed.add(opname)
- elif opname == "SETUP_EXCEPT":
- self.addRule(
- """
- try_except ::= SETUP_EXCEPT suite_stmts_opt POP_BLOCK
- except_handler opt_come_from_except
- tryelsestmt ::= SETUP_EXCEPT suite_stmts_opt POP_BLOCK
- except_handler else_suite come_from_except_clauses
- tryelsestmt ::= SETUP_EXCEPT suite_stmts_opt POP_BLOCK
- except_handler else_suite come_froms
- tryelsestmtl ::= SETUP_EXCEPT suite_stmts_opt POP_BLOCK
- except_handler else_suitel come_from_except_clauses
- stmt ::= tryelsestmtl3
- tryelsestmtl3 ::= SETUP_EXCEPT suite_stmts_opt POP_BLOCK
- except_handler COME_FROM else_suitel
- opt_come_from_except
- """,
- nop_func,
- )
- custom_ops_processed.add(opname)
- elif opname == "WITH_CLEANUP_START":
- rules_str = """
- stmt ::= with_null
- with_null ::= with_suffix
- with_suffix ::= WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
- """
- self.addRule(rules_str, nop_func)
- elif opname == "SETUP_WITH":
- rules_str = """
- stmt ::= with
- stmt ::= with_as
- with ::= expr
- SETUP_WITH POP_TOP
- suite_stmts_opt
- COME_FROM_WITH
- with_suffix
- with_as ::= expr SETUP_WITH store suite_stmts_opt COME_FROM_WITH
- with_suffix
- with ::= expr
- SETUP_WITH POP_TOP
- suite_stmts_opt
- POP_BLOCK LOAD_CONST COME_FROM_WITH
- with_suffix
- with_as ::= expr
- SETUP_WITH store suite_stmts_opt
- POP_BLOCK LOAD_CONST COME_FROM_WITH
- with_suffix
- with ::= expr
- SETUP_WITH POP_TOP suite_stmts_opt
- POP_BLOCK LOAD_CONST COME_FROM_WITH
- with_suffix
- with_as ::= expr
- SETUP_WITH store suite_stmts_opt
- POP_BLOCK LOAD_CONST COME_FROM_WITH
- with_suffix
- """
- if self.version < (3, 8):
- rules_str += """
- with ::= expr SETUP_WITH POP_TOP suite_stmts_opt POP_BLOCK
- LOAD_CONST
- with_suffix
- """
- else:
- rules_str += """
- with ::= expr
- SETUP_WITH POP_TOP suite_stmts_opt
- POP_BLOCK LOAD_CONST COME_FROM_WITH
- with_suffix
- with ::= expr SETUP_WITH POP_TOP suite_stmts_opt POP_BLOCK
- BEGIN_FINALLY COME_FROM_WITH
- with_suffix
- with_as ::= expr
- SETUP_WITH store suite_stmts_opt
- POP_BLOCK LOAD_CONST COME_FROM_WITH
- with_as ::= expr
- SETUP_WITH store suite_stmts
- POP_BLOCK BEGIN_FINALLY COME_FROM_WITH with_suffix
- """
- self.addRule(rules_str, nop_func)
- elif opname_base in ("UNPACK_EX",):
- before_count, after_count = token.attr
- rule = (
- "unpack ::= " + opname + " store" * (before_count + after_count + 1)
- )
- self.addRule(rule, nop_func)
- elif opname_base in ("UNPACK_TUPLE", "UNPACK_SEQUENCE"):
- rule = "unpack ::= " + opname + " store" * token.attr
- self.addRule(rule, nop_func)
- elif opname_base == "UNPACK_LIST":
- rule = "unpack_list ::= " + opname + " store" * token.attr
- self.addRule(rule, nop_func)
- custom_ops_processed.add(opname)
- pass
- pass
- self.reduce_check_table = {
- "_ifstmts_jump": ifstmts_jump,
- "and": and_invalid,
- "ifelsestmt": ifelsestmt,
- "ifelsestmtl": ifelsestmt,
- "iflaststmt": iflaststmt,
- "iflaststmtl": iflaststmt,
- "ifstmt": ifstmt,
- "ifstmtl": ifstmt,
- "or": or_check,
- "testtrue": testtrue,
- "testfalsel": testtrue,
- "while1elsestmt": while1elsestmt,
- "while1stmt": while1stmt,
- "try_elsestmtl38": tryelsestmtl3,
- }
- self.check_reduce["and"] = "AST"
- self.check_reduce["annotate_tuple"] = "noAST"
- self.check_reduce["aug_assign1"] = "AST"
- self.check_reduce["aug_assign2"] = "AST"
- self.check_reduce["while1stmt"] = "noAST"
- self.check_reduce["while1elsestmt"] = "noAST"
- self.check_reduce["_ifstmts_jump"] = "AST"
- self.check_reduce["import_as37"] = "tokens"
- self.check_reduce["import_from_as37"] = "tokens"
- self.check_reduce["import_from_as37"] = "tokens"
- self.check_reduce["ifelsestmt"] = "AST"
- self.check_reduce["ifelsestmtl"] = "AST"
- self.check_reduce["iflaststmt"] = "AST"
- self.check_reduce["iflaststmtl"] = "AST"
- self.check_reduce["ifstmt"] = "AST"
- self.check_reduce["ifstmtl"] = "AST"
- self.check_reduce["import_from37"] = "AST"
- self.check_reduce["or"] = "AST"
- self.check_reduce["testtrue"] = "tokens"
- self.check_reduce["testfalsel"] = "tokens"
- return
- def custom_classfunc_rule(self, opname, token, customize, next_token):
- """
- call ::= expr {expr}^n CALL_FUNCTION_n
- call ::= expr {expr}^n CALL_FUNCTION_VAR_n
- call ::= expr {expr}^n CALL_FUNCTION_VAR_KW_n
- call ::= expr {expr}^n CALL_FUNCTION_KW_n
- classdefdeco2 ::= LOAD_BUILD_CLASS mkfunc {expr}^n-1 CALL_FUNCTION_n
- """
- args_pos, args_kw = self.get_pos_kw(token)
- # Additional exprs for * and ** args:
- # 0 if neither
- # 1 for CALL_FUNCTION_VAR or CALL_FUNCTION_KW
- # 2 for * and ** args (CALL_FUNCTION_VAR_KW).
- # Yes, this computation based on instruction name is a little bit hoaky.
- nak = (len(opname) - len("CALL_FUNCTION")) // 3
- uniq_param = args_kw + args_pos
- if frozenset(("GET_AWAITABLE", "YIELD_FROM")).issubset(self.seen_ops):
- rule = (
- "async_call ::= expr "
- + ("pos_arg " * args_pos)
- + ("kwarg " * args_kw)
- + "expr " * nak
- + token.kind
- + " GET_AWAITABLE LOAD_CONST YIELD_FROM"
- )
- self.add_unique_rule(rule, token.kind, uniq_param, customize)
- self.add_unique_rule(
- "expr ::= async_call", token.kind, uniq_param, customize
- )
- if opname.startswith("CALL_FUNCTION_VAR"):
- token.kind = self.call_fn_name(token)
- if opname.endswith("KW"):
- kw = "expr "
- else:
- kw = ""
- rule = (
- "call ::= expr expr "
- + ("pos_arg " * args_pos)
- + ("kwarg " * args_kw)
- + kw
- + token.kind
- )
- # Note: Semantic actions make use of whether or not "args_pos"
- # is zero when creating a template rule.
- self.add_unique_rule(rule, token.kind, args_pos, customize)
- else:
- token.kind = self.call_fn_name(token)
- uniq_param = args_kw + args_pos
- # Note: 3.5+ have subclassed this method; so we don't handle
- # 'CALL_FUNCTION_VAR' or 'CALL_FUNCTION_EX' here.
- rule = (
- "call ::= expr "
- + ("pos_arg " * args_pos)
- + ("kwarg " * args_kw)
- + "expr " * nak
- + token.kind
- )
- self.add_unique_rule(rule, token.kind, uniq_param, customize)
- if "LOAD_BUILD_CLASS" in self.seen_ops:
- if (
- next_token == "CALL_FUNCTION"
- and next_token.attr == 1
- and args_pos > 1
- ):
- rule = "classdefdeco2 ::= LOAD_BUILD_CLASS mkfunc %s%s_%d" % (
- ("expr " * (args_pos - 1)),
- opname,
- args_pos,
- )
- self.add_unique_rule(rule, token.kind, uniq_param, customize)
- def reduce_is_invalid(self, rule, ast, tokens, first, last):
- lhs = rule[0]
- n = len(tokens)
- last = min(last, n - 1)
- fn = self.reduce_check_table.get(lhs, None)
- try:
- if fn:
- return fn(self, lhs, n, rule, ast, tokens, first, last)
- except Exception:
- import sys
- import traceback
- print(
- f"Exception in {fn.__name__} {sys.exc_info()[1]}\n"
- + f"rule: {rule2str(rule)}\n"
- + f"offsets {tokens[first].offset} .. {tokens[last].offset}"
- )
- print(traceback.print_tb(sys.exc_info()[2], -1))
- raise ParserError(tokens[last], tokens[last].off2int(), self.debug["rules"])
- if lhs in ("aug_assign1", "aug_assign2") and ast[0][0] == "and":
- return True
- elif lhs == "annotate_tuple":
- return not isinstance(tokens[first].attr, tuple)
- elif lhs == "import_from37":
- importlist37 = ast[3]
- alias37 = importlist37[0]
- if importlist37 == "importlist37" and alias37 == "alias37":
- store = alias37[1]
- assert store == "store"
- return alias37[0].attr != store[0].attr
- return False
- elif lhs == "import_as37":
- return tokens[first + 1].pattr is not None
- elif lhs == "import_from_as37":
- return tokens[first + 1].pattr is None
- return False
|