Add "testtrue" reduction rule...

only for 3.7 for now.
This commit is contained in:
rocky
2020-01-10 10:26:40 -05:00
parent 07f16fa040
commit 505946d747
5 changed files with 16 additions and 3 deletions

View File

@@ -29,7 +29,7 @@ that a later phase can turn into a sequence of ASCII text.
import re
from uncompyle6.scanners.tok import Token
from uncompyle6.parser import PythonParser, PythonParserSingle, nop_func
from uncompyle6.parsers.reducecheck import except_handler_else
from uncompyle6.parsers.reducecheck import except_handler_else, testtrue
from uncompyle6.parsers.treenode import SyntaxTree
from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
from xdis import PYTHON3
@@ -317,6 +317,7 @@ class Python3Parser(PythonParser):
ret_cond ::= 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
and ::= expr JUMP_IF_FALSE_OR_POP expr COME_FROM
# compare_chained1 is used exclusively in chained_compare
@@ -1464,6 +1465,7 @@ class Python3Parser(PythonParser):
self.check_reduce["ifstmt"] = "AST"
self.check_reduce["annotate_tuple"] = "noAST"
self.check_reduce["except_handler_else"] = "tokens"
self.check_reduce["testtrue"] = "tokens"
if not PYTHON3:
self.check_reduce["kwarg"] = "noAST"
if self.version < 3.6:
@@ -1504,6 +1506,8 @@ class Python3Parser(PythonParser):
last -= 1
jump_forward_else = ast[2]
return tokens[first].off2int() <= jump_forward_else[0].attr < tokens[last].off2int()
elif lhs == "testtrue":
return testtrue(self, lhs, n, rule, ast, tokens, first, last)
elif lhs == "while1stmt":
# If there is a fall through to the COME_FROM_LOOP, then this is

View File

@@ -14,6 +14,7 @@ from uncompyle6.parsers.reducecheck import (
ifstmt,
ifstmts_jump,
or_check,
testtrue,
while1stmt,
while1elsestmt,
)
@@ -1001,6 +1002,7 @@ class Python37BaseParser(PythonParser):
self.check_reduce["ifstmtl"] = "AST"
self.check_reduce["import_from37"] = "AST"
self.check_reduce["or"] = "AST"
self.check_reduce["testtrue"] = "tokens"
return
def custom_classfunc_rule(self, opname, token, customize, next_token):
@@ -1112,6 +1114,8 @@ class Python37BaseParser(PythonParser):
return or_check(self, lhs, n, rule, ast, tokens, first, last)
elif lhs == "while1elsestmt":
return while1elsestmt(self, lhs, n, rule, ast, tokens, first, last)
elif lhs == "testtrue":
return testtrue(self, lhs, n, rule, ast, tokens, first, last)
elif lhs == "while1stmt":
return while1stmt(self, lhs, n, rule, ast, tokens, first, last)

View File

@@ -5,6 +5,7 @@ from uncompyle6.parsers.reducecheck.iflaststmt import *
from uncompyle6.parsers.reducecheck.ifstmt import *
from uncompyle6.parsers.reducecheck.ifstmts_jump import *
from uncompyle6.parsers.reducecheck.or_check import *
from uncompyle6.parsers.reducecheck.testtrue import *
from uncompyle6.parsers.reducecheck.tryelsestmt import *
from uncompyle6.parsers.reducecheck.while1elsestmt import *
from uncompyle6.parsers.reducecheck.while1stmt import *