You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
binary_expr -> bin_op to match Python AST
I know binary_expr is more natural, but as with things Python we sometimes sacrifice elegance and clarity for Python Fascism.
This commit is contained in:
@@ -504,7 +504,7 @@ class PythonParser(GenericASTBuilder):
|
||||
expr ::= LOAD_CONST
|
||||
expr ::= LOAD_GLOBAL
|
||||
expr ::= LOAD_DEREF
|
||||
expr ::= binary_expr
|
||||
expr ::= bin_op
|
||||
expr ::= list
|
||||
expr ::= compare
|
||||
expr ::= dict
|
||||
@@ -517,7 +517,8 @@ class PythonParser(GenericASTBuilder):
|
||||
expr ::= subscript2
|
||||
expr ::= yield
|
||||
|
||||
binary_expr ::= expr expr binary_op
|
||||
# bin_op (formerly "binary_expr") is the Python AST BinOp
|
||||
bin_op ::= expr expr binary_op
|
||||
binary_op ::= BINARY_ADD
|
||||
binary_op ::= BINARY_MULTIPLY
|
||||
binary_op ::= BINARY_AND
|
||||
|
@@ -139,7 +139,7 @@ class Python37Parser(Python37BaseParser):
|
||||
expr ::= LOAD_GLOBAL
|
||||
expr ::= LOAD_NAME
|
||||
expr ::= LOAD_STR
|
||||
expr ::= binary_expr
|
||||
expr ::= bin_op
|
||||
expr ::= list
|
||||
expr ::= compare
|
||||
expr ::= dict
|
||||
@@ -153,7 +153,8 @@ class Python37Parser(Python37BaseParser):
|
||||
expr ::= yield
|
||||
expr ::= generator_exp
|
||||
|
||||
binary_expr ::= expr expr binary_op
|
||||
# bin_op (formerly "binary_expr") is the Python AST BinOp
|
||||
bin_op ::= expr expr binary_op
|
||||
binary_op ::= BINARY_ADD
|
||||
binary_op ::= BINARY_MULTIPLY
|
||||
binary_op ::= BINARY_AND
|
||||
|
@@ -189,7 +189,9 @@ TABLE_DIRECT = {
|
||||
'INPLACE_AND': ( '&=' ,),
|
||||
'INPLACE_OR': ( '|=' ,),
|
||||
'INPLACE_XOR': ( '^=' ,),
|
||||
'binary_expr': ( '%c %c %c', 0,
|
||||
|
||||
# bin_op (formerly "binary_expr") is the Python AST BinOp
|
||||
'bin_op': ( '%c %c %c', 0,
|
||||
(-1, 'binary_op'),
|
||||
( 1, 'expr' ) ),
|
||||
|
||||
|
@@ -410,7 +410,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
|
||||
def n_expr(self, node):
|
||||
start = len(self.f.getvalue())
|
||||
p = self.prec
|
||||
if node[0].kind.startswith("binary_expr"):
|
||||
if node[0].kind.startswith("bin_op"):
|
||||
n = node[0][-1][0]
|
||||
else:
|
||||
n = node[0]
|
||||
@@ -444,13 +444,14 @@ class FragmentsWalker(pysource.SourceWalker, object):
|
||||
super(FragmentsWalker, self).n_ret_expr(node)
|
||||
self.set_pos_info(node, start, len(self.f.getvalue()))
|
||||
|
||||
def n_binary_expr(self, node):
|
||||
def n_bin_op(self, node):
|
||||
"""bin_op (formerly "binary_expr") is the Python AST BinOp"""
|
||||
start = len(self.f.getvalue())
|
||||
for n in node:
|
||||
n.parent = node
|
||||
self.last_finish = len(self.f.getvalue())
|
||||
try:
|
||||
super(FragmentsWalker, self).n_binary_expr(node)
|
||||
super(FragmentsWalker, self).n_bin_op(node)
|
||||
except GenericASTTraversalPruningException:
|
||||
pass
|
||||
self.set_pos_info(node, start, len(self.f.getvalue()))
|
||||
|
@@ -555,7 +555,7 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
|
||||
def n_expr(self, node):
|
||||
p = self.prec
|
||||
if node[0].kind.startswith("binary_expr"):
|
||||
if node[0].kind.startswith("bin_op"):
|
||||
n = node[0][-1][0]
|
||||
else:
|
||||
n = node[0]
|
||||
@@ -585,11 +585,13 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
|
||||
n_ret_expr_or_cond = n_expr
|
||||
|
||||
def n_binary_expr(self, node):
|
||||
def n_bin_op(self, node):
|
||||
"""bin_op (formerly "binary_expr") is the Python AST BinOp"""
|
||||
self.preorder(node[0])
|
||||
self.write(" ")
|
||||
self.preorder(node[-1])
|
||||
self.write(" ")
|
||||
# Try to avoid a trailing parentheses by lowering the priority a little
|
||||
self.prec -= 1
|
||||
self.preorder(node[1])
|
||||
self.prec += 1
|
||||
|
Reference in New Issue
Block a user