Track "or" grammar changes...

Remove re deprecation warning
This commit is contained in:
rocky
2020-04-16 15:25:42 -04:00
parent f117feb585
commit badfe5456f
4 changed files with 16 additions and 10 deletions

View File

@@ -635,6 +635,10 @@ class Python37Parser(Python37BaseParser):
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

View File

@@ -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"])

View File

@@ -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

View File

@@ -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)",