'RulePredicate': RulePredicate, 'RuleExpression': RuleExpression, 'Rule': Rule }.get(o['class'])() instance.__dict__ = o['data'] return instance if __name__ == '__main__': import json import astprint import astnode as ast Node._verbose_desc = True bp = astprint.BracePrinter() root = ast.Node() root.add_child( ast.Constant(ident=ast.Id(ident="foo"), arg=ast.Value(value=1))) bp.visit(root) s = json.dumps(root, default=ast.node_encoder, indent=2) print print s print tree = json.loads(s, object_hook=ast.node_decoder) bp.visit(tree)
def p_constdef(self, p): """constdef : DEFINE identifier EQ argument""" constdef = ast.Constant(ident=p[2], arg=p[4], debug_info=self.debug_info(p, 1)) p[0] = constdef
}.get(o['class'])() instance.__dict__ = o['data'] return instance if __name__ == '__main__': import json import astprint import astnode as ast Node._verbose_desc = True bp = astprint.BracePrinter() root = ast.Node() root.add_child(ast.Constant(ident=ast.Id(ident="foo"), arg=ast.Value(value=1))) bp.visit(root) s = json.dumps(root, default=ast.node_encoder, indent=2) print print s print tree = json.loads(s, object_hook=ast.node_decoder) bp.visit(tree)