diff --git a/test/simple_source/branching/10_if_else_ternary.py b/test/simple_source/branching/10_if_else_ternary.py index 7f1b02ea..b1753d9f 100644 --- a/test/simple_source/branching/10_if_else_ternary.py +++ b/test/simple_source/branching/10_if_else_ternary.py @@ -1,8 +1,8 @@ # Tests: # ret_expr_or_cond ::= ret_expr -# ret_cond ::= expr POP_JUMP_IF_FALSE expr RETURN_END_IF ret_expr_or_cond -# ret_expr_or_cond ::= ret_cond +# if_exp_ret ::= expr POP_JUMP_IF_FALSE expr RETURN_END_IF ret_expr_or_cond +# ret_expr_or_cond ::= if_exp_ret # ret_or ::= expr JUMP_IF_TRUE_OR_POP ret_expr_or_cond COME_FROM # See https://github.com/rocky/python-uncompyle6/issues/5 diff --git a/uncompyle6/parser.py b/uncompyle6/parser.py index fba35500..3f9217e4 100644 --- a/uncompyle6/parser.py +++ b/uncompyle6/parser.py @@ -577,7 +577,7 @@ class PythonParser(GenericASTBuilder): ret_expr ::= ret_or ret_expr_or_cond ::= ret_expr - ret_expr_or_cond ::= ret_cond + ret_expr_or_cond ::= if_exp_ret stmt ::= return_lambda diff --git a/uncompyle6/parsers/parse25.py b/uncompyle6/parsers/parse25.py index 378241e8..1f5ed48b 100644 --- a/uncompyle6/parsers/parse25.py +++ b/uncompyle6/parsers/parse25.py @@ -72,7 +72,7 @@ class Python25Parser(Python26Parser): classdefdeco1 ::= expr classdefdeco2 CALL_FUNCTION_1 classdefdeco2 ::= LOAD_CONST expr mkfunc CALL_FUNCTION_0 BUILD_CLASS kv3 ::= expr expr STORE_MAP - ret_cond ::= expr jmp_false_then expr RETURN_END_IF POP_TOP ret_expr_or_cond + if_exp_ret ::= expr jmp_false_then expr RETURN_END_IF POP_TOP ret_expr_or_cond return_if_lambda ::= RETURN_END_IF_LAMBDA POP_TOP return_if_stmt ::= ret_expr RETURN_END_IF POP_TOP return_if_stmts ::= return_if_stmt diff --git a/uncompyle6/parsers/parse26.py b/uncompyle6/parsers/parse26.py index 66aa9674..7a7f2271 100644 --- a/uncompyle6/parsers/parse26.py +++ b/uncompyle6/parsers/parse26.py @@ -262,8 +262,8 @@ class Python26Parser(Python2Parser): ''' ret_and ::= expr jmp_false ret_expr_or_cond COME_FROM ret_or ::= expr jmp_true ret_expr_or_cond COME_FROM - ret_cond ::= expr jmp_false_then expr RETURN_END_IF POP_TOP ret_expr_or_cond - ret_cond ::= expr jmp_false_then expr ret_expr_or_cond + if_exp_ret ::= expr jmp_false_then expr RETURN_END_IF POP_TOP ret_expr_or_cond + if_exp_ret ::= expr jmp_false_then expr ret_expr_or_cond return_if_stmt ::= ret_expr RETURN_END_IF POP_TOP return ::= ret_expr RETURN_VALUE POP_TOP diff --git a/uncompyle6/parsers/parse27.py b/uncompyle6/parsers/parse27.py index d41412b9..460086b7 100644 --- a/uncompyle6/parsers/parse27.py +++ b/uncompyle6/parsers/parse27.py @@ -97,9 +97,9 @@ class Python27Parser(Python2Parser): jmp_false ::= POP_JUMP_IF_FALSE jmp_true ::= POP_JUMP_IF_TRUE - ret_and ::= expr JUMP_IF_FALSE_OR_POP ret_expr_or_cond COME_FROM - ret_or ::= expr JUMP_IF_TRUE_OR_POP ret_expr_or_cond COME_FROM - ret_cond ::= expr POP_JUMP_IF_FALSE expr RETURN_END_IF COME_FROM ret_expr_or_cond + ret_and ::= expr JUMP_IF_FALSE_OR_POP ret_expr_or_cond COME_FROM + ret_or ::= expr JUMP_IF_TRUE_OR_POP ret_expr_or_cond COME_FROM + if_exp_ret ::= expr POP_JUMP_IF_FALSE expr RETURN_END_IF COME_FROM ret_expr_or_cond or ::= expr JUMP_IF_TRUE_OR_POP expr COME_FROM and ::= expr JUMP_IF_FALSE_OR_POP expr COME_FROM diff --git a/uncompyle6/parsers/parse3.py b/uncompyle6/parsers/parse3.py index f22f2a9c..2d601485 100644 --- a/uncompyle6/parsers/parse3.py +++ b/uncompyle6/parsers/parse3.py @@ -332,9 +332,9 @@ class Python3Parser(PythonParser): jmp_true ::= POP_JUMP_IF_TRUE # FIXME: Common with 2.7 - ret_and ::= expr JUMP_IF_FALSE_OR_POP ret_expr_or_cond COME_FROM - ret_or ::= expr JUMP_IF_TRUE_OR_POP ret_expr_or_cond COME_FROM - ret_cond ::= expr POP_JUMP_IF_FALSE expr RETURN_END_IF COME_FROM ret_expr_or_cond + ret_and ::= expr JUMP_IF_FALSE_OR_POP ret_expr_or_cond COME_FROM + ret_or ::= expr JUMP_IF_TRUE_OR_POP ret_expr_or_cond COME_FROM + if_exp_ret ::= expr POP_JUMP_IF_FALSE expr RETURN_END_IF COME_FROM ret_expr_or_cond or ::= expr JUMP_IF_TRUE_OR_POP expr COME_FROM or ::= expr jmp_true expr diff --git a/uncompyle6/parsers/parse30.py b/uncompyle6/parsers/parse30.py index e08f2771..3b1d0390 100644 --- a/uncompyle6/parsers/parse30.py +++ b/uncompyle6/parsers/parse30.py @@ -263,9 +263,9 @@ class Python30Parser(Python31Parser): compare_chained2 COME_FROM ret_or ::= expr JUMP_IF_TRUE_OR_POP ret_expr_or_cond COME_FROM ret_and ::= expr JUMP_IF_FALSE_OR_POP ret_expr_or_cond COME_FROM - ret_cond ::= expr POP_JUMP_IF_FALSE expr RETURN_END_IF + if_exp_ret ::= expr POP_JUMP_IF_FALSE expr RETURN_END_IF COME_FROM ret_expr_or_cond - ret_expr_or_cond ::= ret_cond + ret_expr_or_cond ::= if_exp_ret or ::= expr JUMP_IF_TRUE_OR_POP expr COME_FROM and ::= expr JUMP_IF_TRUE_OR_POP expr COME_FROM and ::= expr JUMP_IF_FALSE_OR_POP expr COME_FROM diff --git a/uncompyle6/parsers/parse37.py b/uncompyle6/parsers/parse37.py index e62bcdf2..14a0af42 100644 --- a/uncompyle6/parsers/parse37.py +++ b/uncompyle6/parsers/parse37.py @@ -193,7 +193,7 @@ class Python37Parser(Python37BaseParser): ret_expr ::= ret_or ret_expr_or_cond ::= ret_expr - ret_expr_or_cond ::= ret_cond + ret_expr_or_cond ::= if_exp_ret stmt ::= return_lambda @@ -921,9 +921,9 @@ class Python37Parser(Python37BaseParser): jmp_true ::= POP_JUMP_IF_TRUE # FIXME: Common with 2.7 - ret_and ::= expr JUMP_IF_FALSE_OR_POP ret_expr_or_cond COME_FROM - ret_or ::= expr JUMP_IF_TRUE_OR_POP ret_expr_or_cond COME_FROM - ret_cond ::= expr POP_JUMP_IF_FALSE expr RETURN_END_IF COME_FROM ret_expr_or_cond + ret_and ::= expr JUMP_IF_FALSE_OR_POP ret_expr_or_cond COME_FROM + ret_or ::= expr JUMP_IF_TRUE_OR_POP ret_expr_or_cond COME_FROM + if_exp_ret ::= expr POP_JUMP_IF_FALSE expr RETURN_END_IF COME_FROM ret_expr_or_cond jitop_come_from ::= JUMP_IF_TRUE_OR_POP come_froms jifop_come_from ::= JUMP_IF_FALSE_OR_POP come_froms diff --git a/uncompyle6/semantics/consts.py b/uncompyle6/semantics/consts.py index 13bfa5f0..a962f87b 100644 --- a/uncompyle6/semantics/consts.py +++ b/uncompyle6/semantics/consts.py @@ -61,7 +61,7 @@ PRECEDENCE = { 'if_exp_not_lamdba': 28, # Lambda expression 'if_exp_not': 28, 'if_exp_true': 28, - 'ret_cond': 28, + 'if_exp_ret': 28, 'or': 26, # Boolean OR 'ret_or': 26, @@ -313,7 +313,7 @@ TABLE_DIRECT = { 'if_exp_lambda': ( '%p if %c else %c', (2, 'expr', 27), (0, 'expr'), 4 ), 'if_exp_true': ( '%p if 1 else %c', (0, 'expr', 27), 2 ), - 'ret_cond': ( '%p if %p else %p', (2, 27), (0, 27), (-1, 27) ), + 'if_exp_ret': ( '%p if %p else %p', (2, 27), (0, 27), (-1, 27) ), 'if_exp_not': ( '%p if not %p else %p', (2, 27), (0, "expr", PRECEDENCE['unary_not']),