def pp(self, packed=False): _ob = ppr.IOpenBlock() _cb = ppr.ICloseBlock() _case = ppr.IWord('case') _of = ppr.IWord('of') _esac = ppr.IWord('esac') pp_expr = self.expr.pp(packed) alternatives = self.pp_alternatives(self.alts, packed) pp_alts = ppr.sequence(_ob, alternatives, _cb) return ppr.sequence(_ob, _case, pp_expr, _of, pp_alts, _esac, _cb)
def pp(self, packed=False): _tag = self.tag.pp(packed) _arity = self.arity.pp(packed) _pack = ppr.IStr(' Pack') _lbrace = ppr.IStr('{') _rbrace = ppr.IStr('}') _comma = ppr.IStr(', ') return ppr.sequence(_pack, _lbrace, _tag, _comma, _arity, _rbrace)
def pp(self, packed=False): _ob = ppr.IOpenBlock() _cb = ppr.ICloseBlock() _nl = ppr.INewline() _let = ppr.IWord('letrec') if self.isRec else ppr.IWord('let') _in = ppr.IWord('in') _definitions = self.pp_definitions(self.deflist, packed) pp_expr = self.expr.pp(packed) return ppr.sequence(_ob, _let, _ob, _definitions, _cb, _in, pp_expr, _cb)
def pp(self, packed=False): pre = ppr.IStr('(') if packed else ppr.INil() post = ppr.IStr(')') if packed else ppr.INil() return ppr.sequence(pre, self.fun.pp(False), self.arg.pp(True), post)
def pp(self, packed=False): _name = self.name.pp(packed) _eq = ppr.IWord('=') _val = self.val.pp(packed) return ppr.sequence(_name, _eq, _val)
def pp(self, packed=False): if len(self.pars) == 0: return ppr.IWord(self.name) else: parlist = [ppr.IWord(par) for par in self.pars] return ppr.sequence(ppr.IWord(self.name), ppr.ISequence(parlist))
def pp(self, packed=False): return ppr.sequence(self.lhs.pp(), ppr.IWord('='), self.expr.pp())
def pp(self, packed=False): combinator_list = [combinator.pp() for combinator in self.supercombinators] _seq = ppr.ISequence(combinator_list) _nl = ppr.sequence(ppr.IStr(';'), ppr.INewline()) return _seq.join(_nl)
def pp(self, packed=False): tag = ppr.sequence(ppr.IStr('<'), self.tag.pp(packed), ppr.IStr('> ')) varlist = [var.pp(packed) for var in self.vars] expr = self.expr.pp(packed) return ppr.sequence(tag, ppr.ISequence(varlist), ppr.IWord('->'), expr)
def pp(self, packed=False): _lambda = ppr.IStr('\\') _dot = ppr.IStr('.') _par = self.par.pp(packed) _body = self.body.pp(packed) return ppr.sequence(_lambda, _par, _dot, _body)
def pp_alternatives(self, alternatives, packed): alts = ppr.ISequence([alt.pp(packed) for alt in alternatives]) nl = ppr.sequence(ppr.IStr(';'), ppr.INewline()) return alts.join(nl)
def pp_definitions(self, definitions, packed): _nl = ppr.sequence(ppr.IStr(';'), ppr.INewline()) defs = ppr.ISequence([definition.pp(packed) for definition in definitions]) return defs.join(_nl)
from prettyprinter import IStr, IWord, IAppend, INewline, IOpenBlock, ICloseBlock, PrintContext, append, sequence ctx = PrintContext(False, 0) s1 = IStr('s1') s2 = IStr('s2') w1 = IWord('w1') w2 = IWord('w2') a1 = IAppend(s1, s2) a2 = IAppend(w1, w2) a3 = append(s1, w1, w2, s2) nl = INewline() ob = IOpenBlock() cb = ICloseBlock() seq1 = sequence(w1, s1, s2, w2) seq2 = sequence(w1, w2, w1, w2) seq3 = sequence(w1, s1, w2, s2) seq4 = sequence(s1, w1, w2, s2) seq5 = sequence(s1, nl, s2, ob, s1, nl, s2, ob, s1, nl, s2, cb, s1, cb, s2) seq6 = sequence(w1, nl, w2, ob, w1, nl, w2, ob, w1, nl, w2, cb, w1, cb, w2) def flt(iseq): return iseq.flatten([], ctx) print(flt(seq6))