def n_return_if_stmt(self, node): if self.__params['isLambda']: self.preorder(node[0]) self.prune() else: self.write(self.indent, 'return') if self.return_none or node != AST( 'return_stmt', [AST('ret_expr', [NONE]), Token('RETURN_END_IF')]): self.write(' ') self.preorder(node[0]) self.print_() self.prune() # stop recursing
def n_yield(self, node): self.write('yield') if node != AST('yield', [NONE, Token('YIELD_VALUE')]): self.write(' ') self.preorder(node[0]) self.prune() # stop recursing
import sys, re, cStringIO from types import ListType, TupleType, DictType, \ EllipsisType, IntType, CodeType from spark import GenericASTTraversal import parser from parser import AST from scanner import Token, Code minint = -sys.maxint - 1 # Some ASTs used for comparing code fragments (like 'return None' at # the end of functions). RETURN_LOCALS = AST('return_stmt', [ AST('ret_expr', [AST('expr', [Token('LOAD_LOCALS')])]), Token('RETURN_VALUE') ]) NONE = AST('expr', [Token('LOAD_CONST', pattr=None)]) RETURN_NONE = AST('stmt', [AST('return_stmt', [NONE, Token('RETURN_VALUE')])]) PASS = AST('stmts', [AST('sstmt', [AST('stmt', [AST('passstmt', [])])])]) ASSIGN_DOC_STRING = lambda doc_string: \ AST('stmt', [ AST('assign', [ AST('expr', [ Token('LOAD_CONST', pattr=doc_string) ]), AST('designator', [ Token('STORE_NAME', pattr='__doc__')]) ])])