From badfe5456f695ecaebdc4e4a852a8454c852a74e Mon Sep 17 00:00:00 2001 From: rocky Date: Thu, 16 Apr 2020 15:25:42 -0400 Subject: [PATCH] Track "or" grammar changes... Remove re deprecation warning --- uncompyle6/parsers/parse37.py | 12 ++++++++---- uncompyle6/parsers/parse37base.py | 6 +++--- uncompyle6/parsers/reducecheck/or_check.py | 6 ++++-- uncompyle6/semantics/customize37.py | 2 +- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/uncompyle6/parsers/parse37.py b/uncompyle6/parsers/parse37.py index 40e53227..b5d1c2dd 100644 --- a/uncompyle6/parsers/parse37.py +++ b/uncompyle6/parsers/parse37.py @@ -632,9 +632,13 @@ class Python37Parser(Python37BaseParser): def p_37conditionals(self, args): """ expr ::= if_exp37 - if_exp37 ::= expr expr jf_cfs expr COME_FROM + if_exp37 ::= expr expr jf_cfs expr COME_FROM jf_cfs ::= JUMP_FORWARD _come_froms ifelsestmt ::= testexpr c_stmts_opt jf_cfs else_suite opt_come_from_except + expr_pjit ::= expr POP_JUMP_IF_TRUE + expr_jit ::= expr JUMP_IF_TRUE + expr_jt ::= expr jmp_true + expr_jitop ::= expr JUMP_IF_TRUE_OR_POP jmp_false37 ::= POP_JUMP_IF_FALSE COME_FROM list_if ::= expr jmp_false37 list_iter @@ -929,8 +933,8 @@ class Python37Parser(Python37BaseParser): jifop_come_from ::= JUMP_IF_FALSE_OR_POP come_froms or ::= and jitop_come_from expr COME_FROM or ::= expr JUMP_IF_TRUE_OR_POP expr COME_FROM - or ::= expr JUMP_IF_TRUE expr COME_FROM - or ::= expr POP_JUMP_IF_TRUE expr POP_JUMP_IF_FALSE COME_FROM + or ::= expr_jit expr COME_FROM + or ::= expr_pjit expr POP_JUMP_IF_FALSE COME_FROM testfalse_not_or ::= expr jmp_false expr jmp_false COME_FROM testfalse_not_and ::= and jmp_true come_froms @@ -946,7 +950,7 @@ class Python37Parser(Python37BaseParser): testexprl ::= testfalsel testfalsel ::= expr jmp_true - or ::= expr jmp_true expr + or ::= expr_jt expr and ::= expr JUMP_IF_FALSE_OR_POP expr come_from_opt and ::= expr jifop_come_from expr diff --git a/uncompyle6/parsers/parse37base.py b/uncompyle6/parsers/parse37base.py index 3bff043d..ddaac563 100644 --- a/uncompyle6/parsers/parse37base.py +++ b/uncompyle6/parsers/parse37base.py @@ -3,7 +3,7 @@ Python 3.7 base code. We keep non-custom-generated grammar rules out of this file. """ from uncompyle6.scanners.tok import Token -from uncompyle6.parser import PythonParser, PythonParserSingle, nop_func +from uncompyle6.parser import ParserError, PythonParser, PythonParserSingle, nop_func from uncompyle6.parsers.treenode import SyntaxTree from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG @@ -1191,8 +1191,8 @@ class Python37BaseParser(PythonParser): import sys, traceback print("Exception in %s %s\n" + "rule: %s\n" + - "offsets %s .. %s", - (fn.__name__, sys.exc_info()[1], rule2str(rule), tokens[first].offset, otokens[last].offset)) + "offsets %s .. %s" % + (fn.__name__, sys.exc_info()[1], rule, 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"]) diff --git a/uncompyle6/parsers/reducecheck/or_check.py b/uncompyle6/parsers/reducecheck/or_check.py index c9af5be8..2a35adf3 100644 --- a/uncompyle6/parsers/reducecheck/or_check.py +++ b/uncompyle6/parsers/reducecheck/or_check.py @@ -2,7 +2,7 @@ ASSERT_OPS = frozenset(["LOAD_ASSERT", "RAISE_VARARGS_1"]) def or_check(self, lhs, n, rule, ast, tokens, first, last): - if rule == ("or", ("expr", "jmp_true", "expr")): + if rule == ("or", ("expr_jt", "expr")): if tokens[last] in ASSERT_OPS or tokens[last-1] in ASSERT_OPS: return True @@ -18,7 +18,9 @@ def or_check(self, lhs, n, rule, ast, tokens, first, last): return True first_offset = tokens[first].off2int() - jmp_true_target = ast[1][0].attr + jmp_true_target = ast[0][1][0].attr + jmp_true_target < first_offset + if jmp_true_target < first_offset: return False diff --git a/uncompyle6/semantics/customize37.py b/uncompyle6/semantics/customize37.py index da432bdb..0fdd35e4 100644 --- a/uncompyle6/semantics/customize37.py +++ b/uncompyle6/semantics/customize37.py @@ -262,7 +262,7 @@ def customize_for_version37(self, version): elif ( opname.startswith("CALL_FUNCTION_1") and opname == "CALL_FUNCTION_1" - or not re.match("\d", opname[-1]) + or not re.match(r"\d", opname[-1]) ): self.template_engine( ("%c(%p)",