Beispiel #1
0
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())
Beispiel #2
0
 def replace(self, val, ctype):
     a = self(val.expr, EmptyType())
     self.reg.update(a)
     return ctype.splice(StringType())
Beispiel #3
0
 def ignore(self, val, ctype):
     a = self(val, EmptyType())
     if isinstance(a, InvalidType):
         return a
     self.reg.update(a)
     return ctype
Beispiel #4
0
 def top_splice(self, val, ctype):
     a = self(val, EmptyType())
     self.reg.update(ctype)
     return a.splice(ctype)
Beispiel #5
0
 def splice(self, val, ctype):
     a = self(val, EmptyType())
     self.reg.update(a)
     return ctype.splice(a)
Beispiel #6
0
 def append(self, val, ctype):
     a = self(val.expr, EmptyType())
     self.reg.update(a)
     return ctype.append(a, str(val.name))
Beispiel #7
0
 def top(self, val, ctype):
     a = self(val.expr, EmptyType())
     self.reg.update(ctype)
     return a.append(ctype, str(val.name))