def _compileTree(tree, prettyFlag): result = [u''] if prettyFlag: # Set options def optns(): pass optns = pretty.defaultOptions(optns) #optns.prettypCommentsBlockAdd = False result = pretty.prettyNode(tree, optns, result) else: result = Packer().serializeNode(tree, None, result, True) return u''.join(result)
def compile(node, opts, enableBreaks=False, enableVerbose=False): options = opts options.prettypIndentString = eval("'" + options.prettypIndentString + "'") options.prettypCommentsInlinePadding = eval( "'" + options.prettypCommentsInlinePadding + "'") # allow for escapes like "\t" # split trailing comment cols into an array if (options.prettypCommentsTrailingCommentCols and isinstance( options.prettypCommentsTrailingCommentCols, basestring)): options.prettypCommentsTrailingCommentCols = [ int(column.strip()) for column in options.prettypCommentsTrailingCommentCols.split(",") ] options.prettypCommentsTrailingCommentCols.sort( ) # make sure they are ascending! # or make sure it's a list of int's elif (isinstance(options.prettypCommentsTrailingCommentCols, list) and reduce(lambda y, z: y and z, [ isinstance(x, int) for x in options.prettypCommentsTrailingCommentCols ], True)): options.prettypCommentsTrailingCommentCols.sort( ) # make sure they are ascending! # or pass else: #raise TypeError, "Unsuitable type for option --pretty-print-comments-trailing-commentCols" pass result = [u""] if opts.prettyPrint: comment.fill(node) result = prettyM.prettyNode(node, opts, result) else: packer = Packer() result = packer.serializeNode(node, opts, result, enableBreaks) return u"".join(result)
def serializeCondensed(self, tree, format_=False): result = [u''] result = Packer().serializeNode(tree, None, result, format_) return u''.join(result)
def run_compile(fileName, fileContent, options, args): fileId = fileName tokens = tokenizer.Tokenizer().parseStream(fileContent, fileName) if not options.quiet: print(">>> Creating tree...") tree = treegenerator.createFileTree(tokens) tree = scopes.create_scopes(tree) # optimizing tree if len(options.variants) > 0: if not options.quiet: print(">>> Selecting variants...") varmap = {} for entry in options.variants: pos = entry.index(":") varmap[entry[0:pos]] = entry[pos + 1:] variantoptimizer.search(tree, varmap, fileId) if options.all or options.basecalls: if not options.quiet: print(">>> Optimizing basecalls...") basecalloptimizer.patch(tree) #if options.all or options.inline: # if not options.quiet: # print(">>> Optimizing inline...") # inlineoptimizer.patch(tree) if options.all or options.strings: if not options.quiet: print(">>> Optimizing strings...") _optimizeStrings(tree, fileId) if options.all or options.variables: if not options.quiet: print(">>> Optimizing variables...") variableoptimizer.search(tree) if options.all or options.globals: if not options.quiet: print(">>> Optimizing globals...") tree = globalsoptimizer.process(tree) if options.all or options.privates: if not options.quiet: print(">>> Optimizing privates...") privates = {} if options.cache: cache = Cache(options.cache, interruptRegistry=interruptRegistry) privates, _ = cache.read(options.privateskey) if privates == None: privates = {} privateoptimizer.patch(tree, fileId, privates) if options.cache: cache.write(options.privateskey, privates) if not options.quiet: print(">>> Compiling...") result = [u''] result = Packer().serializeNode(tree, None, result, True) result = u''.join(result) print(result.encode('utf-8')) return