You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
Revert augassign change but..
Make note of what's going on and add grammar test for bad situations we have in Python 2.6 (and perhaps others)
This commit is contained in:
@@ -265,10 +265,14 @@ class PythonParser(GenericASTBuilder):
|
|||||||
|
|
||||||
def p_augmented_assign(self, args):
|
def p_augmented_assign(self, args):
|
||||||
'''
|
'''
|
||||||
stmt ::= augassign0
|
|
||||||
stmt ::= augassign1
|
stmt ::= augassign1
|
||||||
stmt ::= augassign2
|
stmt ::= augassign2
|
||||||
augassign0 ::= expr expr inplace_op designator
|
|
||||||
|
# This is odd in that other augassign1's have only 3 slots
|
||||||
|
# The designator isn't used as that's supposed to be also
|
||||||
|
# indicated in the first expr
|
||||||
|
augassign1 ::= expr expr inplace_op designator
|
||||||
|
|
||||||
augassign1 ::= expr expr inplace_op ROT_THREE STORE_SUBSCR
|
augassign1 ::= expr expr inplace_op ROT_THREE STORE_SUBSCR
|
||||||
augassign2 ::= expr DUP_TOP LOAD_ATTR expr
|
augassign2 ::= expr DUP_TOP LOAD_ATTR expr
|
||||||
inplace_op ROT_TWO STORE_ATTR
|
inplace_op ROT_TWO STORE_ATTR
|
||||||
|
@@ -12,6 +12,11 @@ def checker(ast, in_loop, errors):
|
|||||||
in_loop = in_loop or ast.type in ('while1stmt', 'whileTruestmt',
|
in_loop = in_loop or ast.type in ('while1stmt', 'whileTruestmt',
|
||||||
'whilestmt', 'whileelsestmt',
|
'whilestmt', 'whileelsestmt',
|
||||||
'for_block')
|
'for_block')
|
||||||
|
if ast.type == 'augassign1' and ast[0][0] == 'and':
|
||||||
|
text = str(ast[0])
|
||||||
|
error_text = '\n# improper augmented assigment:\n#\t' + '\n# '.join(text.split("\n"))
|
||||||
|
errors.append(error_text)
|
||||||
|
|
||||||
for node in ast:
|
for node in ast:
|
||||||
if not in_loop and node.type in ('continue_stmt', 'break_stmt'):
|
if not in_loop and node.type in ('continue_stmt', 'break_stmt'):
|
||||||
text = str(node)
|
text = str(node)
|
||||||
|
@@ -1772,7 +1772,7 @@ def deparse_code(version, co, out=StringIO(), showasm=False, showast=False,
|
|||||||
|
|
||||||
if deparsed.ast_errors:
|
if deparsed.ast_errors:
|
||||||
deparsed.write("# NOTE: have decompilation errors.\n")
|
deparsed.write("# NOTE: have decompilation errors.\n")
|
||||||
deparsed.write("# Use -t option to show context of errors.")
|
deparsed.write("# Use -t option to show full of errors.")
|
||||||
for err in deparsed.ast_errors:
|
for err in deparsed.ast_errors:
|
||||||
deparsed.write(err)
|
deparsed.write(err)
|
||||||
deparsed.ERROR = True
|
deparsed.ERROR = True
|
||||||
|
@@ -239,8 +239,12 @@ TABLE_DIRECT = {
|
|||||||
'dict_comp_body': ( '%c:%c', 1, 0 ),
|
'dict_comp_body': ( '%c:%c', 1, 0 ),
|
||||||
|
|
||||||
'assign': ( '%|%c = %p\n', -1, (0, 200) ),
|
'assign': ( '%|%c = %p\n', -1, (0, 200) ),
|
||||||
'augassign0': ( '%|%c = %c %c %c\n', 3, 0, 2, 1),
|
|
||||||
|
# The 2nd parameter should have a = suffix.
|
||||||
|
# There is a rule with a 4th parameter "designator"
|
||||||
|
# which we don't use here.
|
||||||
'augassign1': ( '%|%c %c %c\n', 0, 2, 1),
|
'augassign1': ( '%|%c %c %c\n', 0, 2, 1),
|
||||||
|
|
||||||
'augassign2': ( '%|%c.%[2]{pattr} %c %c\n', 0, -3, -4),
|
'augassign2': ( '%|%c.%[2]{pattr} %c %c\n', 0, -3, -4),
|
||||||
'designList': ( '%c = %c', 0, -1 ),
|
'designList': ( '%c = %c', 0, -1 ),
|
||||||
'and': ( '%c and %c', 0, 2 ),
|
'and': ( '%c and %c', 0, 2 ),
|
||||||
@@ -2318,7 +2322,7 @@ def deparse_code(version, co, out=sys.stdout, showasm=None, showast=False,
|
|||||||
|
|
||||||
if deparsed.ast_errors:
|
if deparsed.ast_errors:
|
||||||
deparsed.write("# NOTE: have decompilation errors.\n")
|
deparsed.write("# NOTE: have decompilation errors.\n")
|
||||||
deparsed.write("# Use -t option to show context of errors.")
|
deparsed.write("# Use -t option to full context of errors.")
|
||||||
for err in deparsed.ast_errors:
|
for err in deparsed.ast_errors:
|
||||||
deparsed.write(err)
|
deparsed.write(err)
|
||||||
raise SourceWalkerError("Deparsing hit an internal grammar-rule bug")
|
raise SourceWalkerError("Deparsing hit an internal grammar-rule bug")
|
||||||
|
Reference in New Issue
Block a user