DRY Python 2 reduction check code a little

This commit is contained in:
rocky
2020-01-12 04:42:13 -05:00
parent 316bf7f0e0
commit ac0b0ff7b6
2 changed files with 16 additions and 5 deletions

View File

@@ -78,13 +78,17 @@ case $PYVERSION in
[test_pep352.py]=1 # Investigate
[test_pyclbr.py]=1 # Investigate
[test_pwd.py]=1 # Long test - might work? Control flow?
[test test_select.py]=1 # test takes too long to run: 11 seconds
[test_socket.py]=1 # test takes too long to run: 12 seconds
[test_trace.py]=1 # Line numbers are expected to be different
[test_urllib2_localnet.py]=1 # test takes too long to run: 12 seconds
[test_urllib2net.py]=1 # test takes too long to run: 11 seconds
[test_zipfile64.py]=1 # Skip Long test
[test_zlib.py]=1 #
# .pyenv/versions/2.6.9/lib/python2.6/lib2to3/refactor.pyc
# .pyenv/versions/2.6.9/lib/python2.6/pyclbr.pyc
)
# About 308 unit-test files, run in about 15 minutes
# About 308 unit-test files, run in about 14 minutes
if (( batch )) ; then
# Fails in crontab environment?
# Figure out what's up here

View File

@@ -640,6 +640,13 @@ class Python2Parser(PythonParser):
self.addRule(rule, nop_func)
pass
self.reduce_check_table = {
# "and": and_check,
"except_handler_else": except_handler_else,
# "or": or_check,
"try_elsestmt": tryelsestmt,
"try_elsestmtl": tryelsestmt,
}
self.check_reduce["and"] = "AST"
self.check_reduce["except_handler_else"] = "tokens"
self.check_reduce["raise_stmt1"] = "tokens"
@@ -661,6 +668,10 @@ class Python2Parser(PythonParser):
lhs = rule[0]
n = len(tokens)
fn = self.reduce_check_table.get(lhs, None)
if fn:
return fn(self, lhs, n, rule, ast, tokens, first, last)
if rule == ("and", ("expr", "jmp_false", "expr", "\\e_come_from_opt")):
# If the instruction after the instructions forming the "and" is an "YIELD_VALUE"
# then this is probably an "if" inside a comprehension.
@@ -698,8 +709,6 @@ class Python2Parser(PythonParser):
jmp_false = ast[1]
jump_target = jmp_false[0].attr
return jump_target > tokens[last].off2int()
elif lhs == "except_handler_else":
return except_handler_else(self, lhs, n, rule, ast, tokens, first, last)
elif lhs in ("raise_stmt1",):
# We will assume 'LOAD_ASSERT' will be handled by an assert grammar rule
return tokens[first] == "LOAD_ASSERT" and (last >= len(tokens))
@@ -709,8 +718,6 @@ class Python2Parser(PythonParser):
elif lhs in ("delete_subscript", "del_expr"):
op = ast[0][0]
return op.kind in ("and", "or")
elif lhs in ("tryelsestmt", "tryelsestmtl"):
return tryelsestmt(self, lhs, n, rule, ast, tokens, first, last)
return False