You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-02 16:44:46 +08:00
Grammar reduction
This commit is contained in:
@@ -415,10 +415,6 @@ class PythonParser(GenericASTBuilder):
|
||||
|
||||
def p_setcomp(self, args):
|
||||
"""
|
||||
expr ::= setcomp
|
||||
|
||||
setcomp ::= LOAD_SETCOMP MAKE_FUNCTION_0 expr GET_ITER CALL_FUNCTION_1
|
||||
|
||||
comp_iter ::= comp_if
|
||||
comp_iter ::= comp_for
|
||||
comp_iter ::= comp_body
|
||||
@@ -512,8 +508,6 @@ class PythonParser(GenericASTBuilder):
|
||||
compare_chained ::= expr compare_chained1 ROT_TWO POP_TOP _come_from
|
||||
compare_chained2 ::= expr COMPARE_OP JUMP_FORWARD
|
||||
|
||||
mapexpr ::= BUILD_MAP kvlist
|
||||
|
||||
# Non-null kvlist items are broken out in the indiviual grammars
|
||||
kvlist ::=
|
||||
|
||||
|
@@ -100,6 +100,12 @@ class Python2Parser(PythonParser):
|
||||
_mklambda ::= load_closure mklambda
|
||||
kwarg ::= LOAD_CONST expr
|
||||
|
||||
kvlist ::= kvlist kv3
|
||||
kv3 ::= expr expr STORE_MAP
|
||||
|
||||
mapexpr ::= BUILD_MAP kvlist
|
||||
|
||||
|
||||
classdef ::= buildclass designator
|
||||
|
||||
buildclass ::= LOAD_CONST expr mkfunc
|
||||
@@ -355,6 +361,12 @@ class Python2Parser(PythonParser):
|
||||
"LOAD_ASSERT expr CALL_FUNCTION_1 RAISE_VARARGS_1 COME_FROM",
|
||||
], customize)
|
||||
continue
|
||||
elif opname == 'LOAD_SETCOMP':
|
||||
self.add_unique_rules([
|
||||
"expr ::= setcomp",
|
||||
"setcomp ::= LOAD_SETCOMP MAKE_FUNCTION_0 expr GET_ITER CALL_FUNCTION_1"
|
||||
], customize)
|
||||
continue
|
||||
elif opname == 'LOOKUP_METHOD':
|
||||
# A PyPy speciality - DRY with parse3
|
||||
self.add_unique_rule("load_attr ::= expr LOOKUP_METHOD",
|
||||
@@ -392,6 +404,7 @@ class Python2Parser(PythonParser):
|
||||
('expr '*v, opname))], customize)
|
||||
elif prev_tok == 'LOAD_SETCOMP':
|
||||
self.add_unique_rules([
|
||||
"expr ::= setcomp",
|
||||
('setcomp ::= %s load_closure LOAD_SETCOMP %s expr'
|
||||
' GET_ITER CALL_FUNCTION_1' %
|
||||
('expr '*v, opname))
|
||||
|
@@ -142,7 +142,6 @@ class Python26Parser(Python2Parser):
|
||||
|
||||
whilestmt ::= SETUP_LOOP testexpr l_stmts_opt jb_pop POP_BLOCK _come_from
|
||||
whilestmt ::= SETUP_LOOP testexpr l_stmts_opt jb_cf_pop bp_come_from
|
||||
whilestmt ::= SETUP_LOOP testexpr return_stmts come_froms POP_TOP bp_come_from
|
||||
whilestmt ::= SETUP_LOOP testexpr return_stmts POP_BLOCK COME_FROM
|
||||
|
||||
whileelsestmt ::= SETUP_LOOP testexpr l_stmts_opt jb_pop POP_BLOCK
|
||||
@@ -253,8 +252,6 @@ class Python26Parser(Python2Parser):
|
||||
return_if_lambda ::= RETURN_END_IF_LAMBDA POP_TOP
|
||||
conditional_lambda ::= expr jmp_false_then expr return_if_lambda
|
||||
return_stmt_lambda LAMBDA_MARKER
|
||||
kvlist ::= kvlist kv3
|
||||
kv3 ::= expr expr STORE_MAP
|
||||
"""
|
||||
|
||||
def add_custom_rules(self, tokens, customize):
|
||||
|
@@ -113,7 +113,6 @@ class Python27Parser(Python2Parser):
|
||||
return_if_lambda ::= RETURN_END_IF_LAMBDA COME_FROM
|
||||
conditional_lambda ::= expr jmp_false expr return_if_lambda
|
||||
return_stmt_lambda LAMBDA_MARKER
|
||||
kvlist ::= kvlist kv3
|
||||
kv3 ::= expr expr STORE_MAP
|
||||
"""
|
||||
|
||||
|
@@ -809,6 +809,8 @@ class Python3Parser(PythonParser):
|
||||
seen_LOAD_SETCOMP = True
|
||||
# Should this be generalized and put under MAKE_FUNCTION?
|
||||
if has_get_iter_call_function1:
|
||||
self.add_unique_rule("expr ::= setcomp",
|
||||
opname, token.attr, customize)
|
||||
rule_pat = ("setcomp ::= LOAD_SETCOMP %sMAKE_FUNCTION_0 expr "
|
||||
"GET_ITER CALL_FUNCTION_1")
|
||||
self.add_make_function_rule(rule_pat, opname, token.attr, customize)
|
||||
|
@@ -260,6 +260,8 @@ class Scanner2(Scanner):
|
||||
customize[op_name] = 0
|
||||
elif op == self.opc.CONTINUE_LOOP:
|
||||
customize[op_name] = 0
|
||||
elif op_name == 'LOAD_SETCOMP':
|
||||
customize[op_name] = 0
|
||||
elif op == self.opc.JUMP_ABSOLUTE:
|
||||
# Further classify JUMP_ABSOLUTE into backward jumps
|
||||
# which are used in loops, and "CONTINUE" jumps which
|
||||
|
Reference in New Issue
Block a user