Skip to content

Commit

Permalink
Simpilfy grammar via ending_return
Browse files Browse the repository at this point in the history
  • Loading branch information
rocky committed Aug 13, 2023
1 parent b3ddf95 commit c0957d9
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 38 deletions.
3 changes: 3 additions & 0 deletions uncompyle6/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@ def p_stmt(self, args):
c_stmts ::= lastc_stmt
c_stmts ::= continues
ending_return ::= RETURN_VALUE RETURN_LAST
ending_return ::= RETURN_VALUE_LAMBDA LAMBDA_MARKER
lastc_stmt ::= iflaststmt
lastc_stmt ::= forelselaststmt
lastc_stmt ::= ifelsestmtc
Expand Down
8 changes: 2 additions & 6 deletions uncompyle6/parsers/parse27.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,10 @@ def p_comprehension27(self, args):
stmt ::= dict_comp_func
dict_comp_func ::= BUILD_MAP_0 LOAD_FAST FOR_ITER store
comp_iter JUMP_BACK RETURN_VALUE RETURN_LAST
dict_comp_func ::= BUILD_MAP_0 LOAD_FAST FOR_ITER store
comp_iter JUMP_BACK RETURN_VALUE_LAMBDA LAMBDA_MARKER
comp_iter JUMP_BACK ending_return
set_comp_func ::= BUILD_SET_0 LOAD_FAST FOR_ITER store comp_iter
JUMP_BACK RETURN_VALUE RETURN_LAST
set_comp_func ::= BUILD_SET_0 LOAD_FAST FOR_ITER store comp_iter
JUMP_BACK RETURN_VALUE_LAMBDA LAMBDA_MARKER
JUMP_BACK ending_return
comp_iter ::= comp_if_not
comp_if_not ::= expr jmp_true comp_iter
Expand Down
14 changes: 4 additions & 10 deletions uncompyle6/parsers/parse3.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,13 @@ def p_comprehension3(self, args):
stmt ::= set_comp_func
# TODO this can be simplified
set_comp_func ::= BUILD_SET_0 LOAD_ARG FOR_ITER store comp_iter
JUMP_BACK RETURN_VALUE RETURN_LAST
set_comp_func ::= BUILD_SET_0 LOAD_ARG FOR_ITER store comp_iter
JUMP_BACK RETURN_VALUE_LAMBDA LAMBDA_MARKER
set_comp_func ::= BUILD_SET_0 LOAD_FAST FOR_ITER store comp_iter
JUMP_BACK RETURN_VALUE RETURN_LAST
JUMP_BACK ending_return
set_comp_func ::= BUILD_SET_0 LOAD_FAST FOR_ITER store comp_iter
JUMP_BACK RETURN_VALUE_LAMBDA LAMBDA_MARKER
set_comp_func ::= BUILD_SET_0 LOAD_ARG FOR_ITER store comp_iter
COME_FROM JUMP_BACK RETURN_VALUE RETURN_LAST
JUMP_BACK ending_return
set_comp_func ::= BUILD_SET_0 LOAD_ARG FOR_ITER store comp_iter
COME_FROM JUMP_BACK RETURN_VALUE_LAMBDA LAMBDA_MARKER
COME_FROM JUMP_BACK ending_return
comp_body ::= dict_comp_body
comp_body ::= set_comp_body
Expand Down
12 changes: 2 additions & 10 deletions uncompyle6/parsers/parse30.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,8 @@ def p_30(self, args):
set_comp_func ::= set_comp_header
LOAD_ARG FOR_ITER store comp_iter
JUMP_BACK
JUMP_BACK ending_return
RETURN_VALUE RETURN_LAST
set_comp_func ::= set_comp_header
LOAD_ARG FOR_ITER store comp_iter
JUMP_BACK
RETURN_VALUE_LAMBDA LAMBDA_MARKER
list_comp_header ::= BUILD_LIST_0 DUP_TOP STORE_FAST
list_comp ::= list_comp_header
Expand Down Expand Up @@ -112,11 +108,7 @@ def p_30(self, args):
dict_comp_func ::= BUILD_MAP_0
DUP_TOP STORE_FAST
LOAD_ARG FOR_ITER store
dict_comp_iter JUMP_BACK RETURN_VALUE RETURN_LAST
dict_comp_func ::= BUILD_MAP_0
DUP_TOP STORE_FAST
LOAD_ARG FOR_ITER store
dict_comp_iter JUMP_BACK RETURN_VALUE_LAMBDA LAMBDA_MARKER
dict_comp_iter JUMP_BACK ending_return
stmt ::= try_except30
try_except30 ::= SETUP_EXCEPT suite_stmts_opt
Expand Down
17 changes: 7 additions & 10 deletions uncompyle6/parsers/parse37.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ def p_stmt(self, args):
c_stmts ::= lastc_stmt
c_stmts ::= continues
ending_return ::= RETURN_VALUE RETURN_LAST
ending_return ::= RETURN_VALUE_LAMBDA LAMBDA_MARKER
lastc_stmt ::= iflaststmt
lastc_stmt ::= forelselaststmt
lastc_stmt ::= ifelsestmtc
Expand Down Expand Up @@ -739,15 +742,11 @@ def p_comprehension3(self, args):
stmt ::= set_comp_func
# TODO: simplify this
set_comp_func ::= BUILD_SET_0 LOAD_ARG for_iter store comp_iter
JUMP_BACK RETURN_VALUE RETURN_LAST
JUMP_BACK ending_return
set_comp_func ::= BUILD_SET_0 LOAD_ARG for_iter store comp_iter
JUMP_BACK RETURN_VALUE_LAMBDA LAMBDA_MARKER
set_comp_func ::= BUILD_SET_0 LOAD_ARG for_iter store comp_iter
COME_FROM JUMP_BACK RETURN_VALUE RETURN_LAST
set_comp_func ::= BUILD_SET_0 LOAD_ARG for_iter store comp_iter
COME_FROM JUMP_BACK RETURN_VALUE_LAMBDA LAMBDA_MARKER
COME_FROM JUMP_BACK ending_return
comp_body ::= dict_comp_body
comp_body ::= set_comp_body
Expand All @@ -763,9 +762,7 @@ def p_dict_comp3(self, args):
stmt ::= dict_comp_func
dict_comp_func ::= BUILD_MAP_0 LOAD_ARG for_iter store
comp_iter JUMP_BACK RETURN_VALUE RETURN_LAST
dict_comp_func ::= BUILD_MAP_0 LOAD_ARG for_iter store
comp_iter JUMP_BACK RETURN_VALUE_LAMBDA LAMBDA_MARKER
comp_iter JUMP_BACK ending_return
comp_iter ::= comp_if
comp_iter ::= comp_if_not
Expand Down
6 changes: 4 additions & 2 deletions uncompyle6/parsers/parse38.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ def p_38_stmt(self, args):
for38 ::= expr get_for_iter store for_block
forelsestmt38 ::= expr get_for_iter store for_block POP_BLOCK else_suite
forelsestmt38 ::= expr get_for_iter store for_block JUMP_BACK _come_froms else_suite
forelsestmt38 ::= expr get_for_iter store for_block JUMP_BACK _come_froms
else_suite
forelselaststmt38 ::= expr get_for_iter store for_block POP_BLOCK else_suitec
forelselaststmtl38 ::= expr get_for_iter store for_block POP_BLOCK else_suitel
Expand All @@ -130,7 +131,8 @@ def p_38_stmt(self, args):
except_return_value ::= POP_BLOCK return
except_return_value ::= expr POP_BLOCK RETURN_VALUE
whilestmt38 ::= _come_froms testexpr l_stmts_opt COME_FROM JUMP_BACK POP_BLOCK
whilestmt38 ::= _come_froms testexpr l_stmts_opt COME_FROM JUMP_BACK
POP_BLOCK
whilestmt38 ::= _come_froms testexpr l_stmts_opt JUMP_BACK POP_BLOCK
whilestmt38 ::= _come_froms testexpr l_stmts_opt JUMP_BACK come_froms
whilestmt38 ::= _come_froms testexpr returns POP_BLOCK
Expand Down

0 comments on commit c0957d9

Please sign in to comment.