def infer_types(gram): start = list(gram)[0] reg = Registry() inf = infer(gram, [start], EmptyType(), reg=reg) top = inf[start].get((EmptyType(),), ()) if isinstance(top, InvalidType): return None reg.update(top) return list(reg.types.values())
def replace(self, val, ctype): a = self(val.expr, EmptyType()) self.reg.update(a) return ctype.splice(StringType())
def ignore(self, val, ctype): a = self(val, EmptyType()) if isinstance(a, InvalidType): return a self.reg.update(a) return ctype
def top_splice(self, val, ctype): a = self(val, EmptyType()) self.reg.update(ctype) return a.splice(ctype)
def splice(self, val, ctype): a = self(val, EmptyType()) self.reg.update(a) return ctype.splice(a)
def append(self, val, ctype): a = self(val.expr, EmptyType()) self.reg.update(a) return ctype.append(a, str(val.name))
def top(self, val, ctype): a = self(val.expr, EmptyType()) self.reg.update(ctype) return a.append(ctype, str(val.name))