You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
NT augassign -> aug_assign to match AST
This commit is contained in:
@@ -12,7 +12,7 @@ y ^= 1 # INPLACE_XOR
|
||||
|
||||
`y` # UNARY_CONVERT - No in Python 3.x
|
||||
|
||||
# Beef up augassign and STORE_SLICE+3
|
||||
# Beef up aug_assign and STORE_SLICE+3
|
||||
x = [1,2,3,4,5]
|
||||
x[0:1] = 1
|
||||
x[0:3] += 1, 2, 3
|
||||
|
@@ -10,7 +10,7 @@ y //= 1 # INPLACE_TRUE_DIVIDE
|
||||
y &= 1 # INPLACE_AND
|
||||
y ^= 1 # INPLACE_XOR
|
||||
|
||||
# Beef up augassign and STORE_SLICE+3
|
||||
# Beef up aug_assign and STORE_SLICE+3
|
||||
x = [1,2,3,4,5]
|
||||
x[0:1] = 1
|
||||
x[0:3] += 1, 2, 3
|
||||
|
@@ -26,11 +26,11 @@ l[1][2][3] = 7
|
||||
l[1][2][3] *= 3;
|
||||
|
||||
# Python 2.x
|
||||
# augassign1 ::= expr expr inplace_op ROT_TWO STORE_SLICE+0
|
||||
# aug_assign1 ::= expr expr inplace_op ROT_TWO STORE_SLICE+0
|
||||
l[:] += [9]; # print l
|
||||
|
||||
# Python 2.x
|
||||
# augassign1 ::= expr expr inplace_op ROT_THREE STORE_SLICE+2
|
||||
# aug_assign1 ::= expr expr inplace_op ROT_THREE STORE_SLICE+2
|
||||
l[:2] += [9]; # print l
|
||||
|
||||
|
||||
|
@@ -319,16 +319,17 @@ class PythonParser(GenericASTBuilder):
|
||||
|
||||
def p_augmented_assign(self, args):
|
||||
'''
|
||||
stmt ::= augassign1
|
||||
stmt ::= augassign2
|
||||
stmt ::= aug_assign1
|
||||
stmt ::= aug_assign2
|
||||
|
||||
# This is odd in that other augassign1's have only 3 slots
|
||||
# This is odd in that other aug_assign1's have only 3 slots
|
||||
# The store isn't used as that's supposed to be also
|
||||
# indicated in the first expr
|
||||
augassign1 ::= expr expr inplace_op store
|
||||
|
||||
augassign1 ::= expr expr inplace_op ROT_THREE STORE_SUBSCR
|
||||
augassign2 ::= expr DUP_TOP LOAD_ATTR expr
|
||||
aug_assign1 ::= expr expr
|
||||
inplace_op store
|
||||
aug_assign1 ::= expr expr
|
||||
inplace_op ROT_THREE STORE_SUBSCR
|
||||
aug_assign2 ::= expr DUP_TOP LOAD_ATTR expr
|
||||
inplace_op ROT_TWO STORE_ATTR
|
||||
|
||||
inplace_op ::= INPLACE_ADD
|
||||
|
@@ -200,10 +200,10 @@ class Python2Parser(PythonParser):
|
||||
store ::= expr expr STORE_SLICE+2
|
||||
store ::= expr expr expr STORE_SLICE+3
|
||||
|
||||
augassign1 ::= expr expr inplace_op ROT_FOUR STORE_SLICE+3
|
||||
augassign1 ::= expr expr inplace_op ROT_THREE STORE_SLICE+1
|
||||
augassign1 ::= expr expr inplace_op ROT_THREE STORE_SLICE+2
|
||||
augassign1 ::= expr expr inplace_op ROT_TWO STORE_SLICE+0
|
||||
aug_assign1 ::= expr expr inplace_op ROT_FOUR STORE_SLICE+3
|
||||
aug_assign1 ::= expr expr inplace_op ROT_THREE STORE_SLICE+1
|
||||
aug_assign1 ::= expr expr inplace_op ROT_THREE STORE_SLICE+2
|
||||
aug_assign1 ::= expr expr inplace_op ROT_TWO STORE_SLICE+0
|
||||
|
||||
slice0 ::= expr SLICE+0
|
||||
slice0 ::= expr DUP_TOP SLICE+0
|
||||
@@ -430,8 +430,8 @@ class Python2Parser(PythonParser):
|
||||
raise Exception('unknown customize token %s' % opname)
|
||||
self.add_unique_rule(rule, opname_base, v, customize)
|
||||
pass
|
||||
self.check_reduce['augassign1'] = 'AST'
|
||||
self.check_reduce['augassign2'] = 'AST'
|
||||
self.check_reduce['aug_assign1'] = 'AST'
|
||||
self.check_reduce['aug_assign2'] = 'AST'
|
||||
self.check_reduce['_stmts'] = 'AST'
|
||||
|
||||
# Dead code testing...
|
||||
@@ -447,7 +447,7 @@ class Python2Parser(PythonParser):
|
||||
# if lhs == 'while1elsestmt':
|
||||
# from trepan.api import debug; debug()
|
||||
|
||||
if lhs in ('augassign1', 'augassign2') and ast[0] and ast[0][0] == 'and':
|
||||
if lhs in ('aug_assign1', 'aug_assign2') and ast[0] and ast[0][0] == 'and':
|
||||
return True
|
||||
elif lhs == '_stmts':
|
||||
for i, stmt in enumerate(ast):
|
||||
|
@@ -972,8 +972,8 @@ class Python3Parser(PythonParser):
|
||||
self.add_unique_rule(rule, opname, token.attr, customize)
|
||||
elif opname_base == 'UNPACK_LIST':
|
||||
rule = 'unpack_list ::= ' + opname + ' store' * token.attr
|
||||
self.check_reduce['augassign1'] = 'AST'
|
||||
self.check_reduce['augassign2'] = 'AST'
|
||||
self.check_reduce['aug_assign1'] = 'AST'
|
||||
self.check_reduce['aug_assign2'] = 'AST'
|
||||
self.check_reduce['while1stmt'] = 'noAST'
|
||||
self.check_reduce['annotate_tuple'] = 'noAST'
|
||||
self.check_reduce['kwarg'] = 'noAST'
|
||||
@@ -983,7 +983,7 @@ class Python3Parser(PythonParser):
|
||||
|
||||
def reduce_is_invalid(self, rule, ast, tokens, first, last):
|
||||
lhs = rule[0]
|
||||
if lhs in ('augassign1', 'augassign2') and ast[0][0] == 'and':
|
||||
if lhs in ('aug_assign1', 'aug_assign2') and ast[0][0] == 'and':
|
||||
return True
|
||||
elif lhs == 'annotate_tuple':
|
||||
return not isinstance(tokens[first].attr, tuple)
|
||||
|
@@ -14,7 +14,7 @@ def checker(ast, in_loop, errors):
|
||||
in_loop = in_loop or ast.kind in ('while1stmt', 'whileTruestmt',
|
||||
'whilestmt', 'whileelsestmt', 'while1elsestmt',
|
||||
'for_block')
|
||||
if ast.kind in ('augassign1', 'augassign2') and ast[0][0] == 'and':
|
||||
if ast.kind in ('aug_assign1', 'aug_assign2') and ast[0][0] == 'and':
|
||||
text = str(ast)
|
||||
error_text = '\n# improper augmented assigment (e.g. +=, *=, ...):\n#\t' + '\n# '.join(text.split("\n")) + '\n'
|
||||
errors.append(error_text)
|
||||
|
@@ -176,9 +176,9 @@ TABLE_DIRECT = {
|
||||
# The 2nd parameter should have a = suffix.
|
||||
# There is a rule with a 4th parameter "store"
|
||||
# which we don't use here.
|
||||
'augassign1': ( '%|%c %c %c\n', 0, 2, 1),
|
||||
'aug_assign1': ( '%|%c %c %c\n', 0, 2, 1),
|
||||
|
||||
'augassign2': ( '%|%c.%[2]{pattr} %c %c\n', 0, -3, -4 ),
|
||||
'aug_assign2': ( '%|%c.%[2]{pattr} %c %c\n', 0, -3, -4 ),
|
||||
'designList': ( '%c = %c', 0, -1 ),
|
||||
'and': ( '%c and %c', 0, 2 ),
|
||||
'ret_and': ( '%c and %c', 0, 2 ),
|
||||
|
@@ -191,7 +191,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
|
||||
raise GenericASTTraversalPruningException
|
||||
|
||||
n_slice0 = n_slice1 = n_slice2 = n_slice3 = n_subscript = table_r_node
|
||||
n_augassign_1 = n_print_item = exec_stmt = print_to_item = del_stmt = table_r_node
|
||||
n_aug_assign_1 = n_print_item = exec_stmt = print_to_item = del_stmt = table_r_node
|
||||
n_classdefco1 = n_classdefco2 = except_cond1 = except_cond2 = table_r_node
|
||||
|
||||
def n_passtmt(self, node):
|
||||
|
Reference in New Issue
Block a user