def generate_codestr(self, language, symbols, symbols_to_load=None): codestr = '' # first we generate code to load whichever variables # can be resolved (all dependencies met) if symbols_to_load is None: symbols_to_load = symbols new_symbols_to_load = {} for name, sym in symbols_to_load.items(): deps = sym.depends if set(deps).issubset(set(self.resolved)): codestr += indent_string(sym.load, self.tabs) else: new_symbols_to_load[name] = sym # now we generate the content (recursively) for item in self.content: itemstr = None if isinstance(item, str): itemstr = indent_string(item, self.tabs) if isinstance(item, Statement): itemstr = item.convert_to(language, symbols) itemstr = indent_string(itemstr, self.tabs) if isinstance(item, CodeBlock): itemstr = item.generate_codestr(language, symbols, new_symbols_to_load) if itemstr is None: raise TypeError("Unknown code block item type") codestr = codestr+itemstr return codestr
def generate_codestr(self, language, symbols, symbols_to_load=None): codestr = '' # first we generate code to load whichever variables # can be resolved (all dependencies met) if symbols_to_load is None: symbols_to_load = symbols new_symbols_to_load = {} for name, sym in symbols_to_load.items(): deps = sym.depends if set(deps).issubset(set(self.resolved)): codestr += indent_string(sym.load, self.tabs) else: new_symbols_to_load[name] = sym # now we generate the content (recursively) for item in self.content: itemstr = None if isinstance(item, str): itemstr = indent_string(item, self.tabs) if isinstance(item, Statement): itemstr = item.convert_to(language, symbols) itemstr = indent_string(itemstr, self.tabs) if isinstance(item, CodeBlock): itemstr = item.generate_codestr(language, symbols, new_symbols_to_load) if itemstr is None: raise TypeError("Unknown code block item type") codestr = codestr + itemstr return codestr
def __str__(self): s = '' for c in self.content: if isinstance(c, Statement): c = indent_string(str(c), self.tabs) elif isinstance(c, str): c = indent_string(c, self.tabs) else: c = str(c)+'\n' s = s+c return s
def __str__(self): s = '' for c in self.content: if isinstance(c, Statement): c = indent_string(str(c), self.tabs) elif isinstance(c, str): c = indent_string(c, self.tabs) else: c = str(c) + '\n' s = s + c return s