1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | Index: lib/mako/_ast_util.py =================================================================== --- lib/mako/_ast_util.py (revision 359) +++ lib/mako/_ast_util.py (working copy) @@ -33,10 +33,11 @@ import array jython = True ast_list = array.ArrayType + op_type = lambda x: x else: ast_list = list + op_type = type - BOOLOP_SYMBOLS = { And: 'and', Or: 'or' @@ -435,7 +436,7 @@ def visit_AugAssign(self, node): self.newline() self.visit(node.target) - self.write(BINOP_SYMBOLS[type(node.op)] + '=') + self.write(BINOP_SYMBOLS[op_type(node.op)] + '=') self.visit(node.value) def visit_ImportFrom(self, node): @@ -711,7 +712,7 @@ def visit_BinOp(self, node): self.write('(') self.visit(node.left) - self.write(' %s ' % BINOP_SYMBOLS[type(node.op)]) + self.write(' %s ' % BINOP_SYMBOLS[op_type(node.op)]) self.visit(node.right) self.write(')') @@ -719,7 +720,7 @@ self.write('(') for idx, value in enumerate(node.values): if idx: - self.write(' %s ' % BOOLOP_SYMBOLS[type(node.op)]) + self.write(' %s ' % BOOLOP_SYMBOLS[op_type(node.op)]) self.visit(value) self.write(')') @@ -727,13 +728,13 @@ self.write('(') self.visit(node.left) for op, right in zip(node.ops, node.comparators): - self.write(' %s ' % CMPOP_SYMBOLS[type(op)]) + self.write(' %s ' % CMPOP_SYMBOLS[op_type(op)]) self.visit(right) self.write(')') def visit_UnaryOp(self, node): self.write('(') - op = UNARYOP_SYMBOLS[type(node.op)] + op = UNARYOP_SYMBOLS[op_type(node.op)] self.write(op) if op == 'not': self.write(' ') |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | Index: lib/mako/_ast_util.py =================================================================== --- lib/mako/_ast_util.py (revision 359) +++ lib/mako/_ast_util.py (working copy) @@ -435,7 +435,7 @@ def visit_AugAssign(self, node): self.newline() self.visit(node.target) - self.write(BINOP_SYMBOLS[type(node.op)] + '=') + self.write(BINOP_SYMBOLS[node.op] + '=') self.visit(node.value) def visit_ImportFrom(self, node): @@ -711,7 +711,7 @@ def visit_BinOp(self, node): self.write('(') self.visit(node.left) - self.write(' %s ' % BINOP_SYMBOLS[type(node.op)]) + self.write(' %s ' % BINOP_SYMBOLS[node.op]) self.visit(node.right) self.write(')') @@ -719,7 +719,7 @@ self.write('(') for idx, value in enumerate(node.values): if idx: - self.write(' %s ' % BOOLOP_SYMBOLS[type(node.op)]) + self.write(' %s ' % BOOLOP_SYMBOLS[node.op]) self.visit(value) self.write(')') @@ -727,13 +727,13 @@ self.write('(') self.visit(node.left) for op, right in zip(node.ops, node.comparators): - self.write(' %s ' % CMPOP_SYMBOLS[type(op)]) + self.write(' %s ' % CMPOP_SYMBOLS[op]) self.visit(right) self.write(')') def visit_UnaryOp(self, node): self.write('(') - op = UNARYOP_SYMBOLS[type(node.op)] + op = UNARYOP_SYMBOLS[node.op] self.write(op) if op == 'not': self.write(' ') |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | Index: lib/mako/_ast_util.py =================================================================== --- lib/mako/_ast_util.py (revision 359) +++ lib/mako/_ast_util.py (working copy) @@ -435,7 +435,7 @@ def visit_AugAssign(self, node): self.newline() self.visit(node.target) - self.write(BINOP_SYMBOLS[type(node.op)] + '=') + self.write(BINOP_SYMBOLS[str(node.op)] + '=') self.visit(node.value) def visit_ImportFrom(self, node): @@ -711,7 +711,7 @@ def visit_BinOp(self, node): self.write('(') self.visit(node.left) - self.write(' %s ' % BINOP_SYMBOLS[type(node.op)]) + self.write(' %s ' % BINOP_SYMBOLS[node.op]) self.visit(node.right) self.write(')') @@ -719,7 +719,7 @@ self.write('(') for idx, value in enumerate(node.values): if idx: - self.write(' %s ' % BOOLOP_SYMBOLS[type(node.op)]) + self.write(' %s ' % BOOLOP_SYMBOLS[node.op]) self.visit(value) self.write(')') @@ -727,13 +727,13 @@ self.write('(') self.visit(node.left) for op, right in zip(node.ops, node.comparators): - self.write(' %s ' % CMPOP_SYMBOLS[type(op)]) + self.write(' %s ' % CMPOP_SYMBOLS[op]) self.visit(right) self.write(')') def visit_UnaryOp(self, node): self.write('(') - op = UNARYOP_SYMBOLS[type(node.op)] + op = UNARYOP_SYMBOLS[node.op] self.write(op) if op == 'not': self.write(' ') |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | def get_class_name(t): result = t.__class__.__name__ if os.name.startswith('java'): if result in ("org.python.antlr.ast.expr_contextType", "org.python.antlr.ast.boolopType", "org.python.antlr.ast.unaryopType", "org.python.antlr.ast.cmpopType", "org.python.antlr.ast.operatorType"): result = str(t) else: result = result.split(".")[-1] if result.endswith("Type"): result = result[:-4] return result |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | t7.py:
from __future__ import with_statement
with f:
pass
C:\workspace\jython\sandbox\ast>python astlib.py t7.py jython23.bat
---------- ouput -------------
py: ('Module',
('body',
('ImportFrom',
('module', '__future__'),
('names', ('alias', ('name', 'with_statement'), ('asname', None))),
('level', 0)),
('With',
('context_expr', ('Name', ('id', 'f'), ('ctx', ('Load',)))),
('optional_vars', None),
('body', ('Pass',)))))
jy: ('Module',
('body',
('With',
('context_expr', ('Name', ('id', 'f'), ('ctx', ('Load',)))),
('optional_vars', ('Name', ('id', 'f'), ('ctx', ('Load',)))),
('body', ('Pass',)))))
---------- DIFF -------------
('Module',
('body',
- ('ImportFrom',
- ('module', '__future__'),
- ('names', ('alias', ('name', 'with_statement'), ('asname', None))),
- ('level', 0)),
('With',
('context_expr', ('Name', ('id', 'f'), ('ctx', ('Load',)))),
- ('optional_vars', None),
+ ('optional_vars', ('Name', ('id', 'f'), ('ctx', ('Load',)))),
('body', ('Pass',)))))
|