use of catdata.fql.decl.MapExp.Inl in project fql by CategoricalData.
the class FQLParser method toMapping.
@SuppressWarnings({ "rawtypes", "unchecked" })
private static MapExp toMapping(Object o) {
try {
Tuple3 p = (Tuple3) o;
Object p2 = p.b;
Object p3 = p.c;
Object o1 = p.a;
String p1 = p.a.toString();
if (p1.equals("fst")) {
return new Fst(toSchema(p2), toSchema(p3));
} else if (p1.equals("snd")) {
return new Snd(toSchema(p2), toSchema(p3));
} else if (p1.equals("unit")) {
return new TT(toSchema(p3), new HashSet<>((Collection<String>) p2));
} else if (p1.equals("subschema")) {
return new Sub(toSchema(p2), toSchema(p3));
} else if (p1.equals("inl")) {
return new Inl(toSchema(p2), toSchema(p3));
} else if (p1.equals("inr")) {
return new Inr(toSchema(p2), toSchema(p3));
} else if (p1.equals("iso1")) {
return new Iso(true, toSchema(p2), toSchema(p3));
} else if (p1.equals("iso2")) {
return new Iso(false, toSchema(p2), toSchema(p3));
} else if (p1.equals("eval")) {
return new Apply(toSchema(p2), toSchema(p3));
} else if (p2.toString().equals("then")) {
return new MapExp.Comp(toMapping(o1), toMapping(p3));
} else if (p2.toString().equals("*")) {
return new Prod(toMapping(o1), toMapping(p3));
} else if (p2.toString().equals("+")) {
return new Case(toMapping(o1), toMapping(p3));
}
} catch (RuntimeException re) {
}
if (o instanceof Tuple5) {
Tuple5 p = (Tuple5) o;
Object p2 = p.c;
Object p3 = p.e;
Object o1 = p.a;
return toMapConst(o1, toSchema(p2), toSchema(p3));
}
try {
org.jparsec.functors.Pair p = (org.jparsec.functors.Pair) o;
String p1 = p.a.toString();
Object p2 = p.b;
switch(p1) {
case "id":
return new Id(toSchema(p2));
case "curry":
return new Curry(toMapping(p2));
case "void":
return new FF(toSchema(p2));
case "opposite":
return new Opposite(toMapping(p2));
default:
break;
}
} catch (RuntimeException re) {
}
if (o instanceof String) {
return new MapExp.Var(o.toString());
}
throw new RuntimeException("Cannot parse " + o);
}
use of catdata.fql.decl.MapExp.Inl in project fql by CategoricalData.
the class FQLParser method toTrans.
@SuppressWarnings("rawtypes")
private static TransExp toTrans(Object o) {
try {
Tuple4 p = (Tuple4) o;
String src = p.b.toString();
String dst = p.c.toString();
TransExp h = toTrans(p.d);
String kind = p.a.toString();
switch(kind) {
case "delta":
return new TransExp.Delta(h, src, dst);
case "pi":
return new TransExp.Pi(h, src, dst);
case "sigma":
return new TransExp.Sigma(h, src, dst);
case "relationalize":
return new TransExp.Relationalize(h, src, dst);
default:
throw new RuntimeException(o.toString());
}
} catch (RuntimeException ex) {
}
try {
Tuple4 p = (Tuple4) o;
String src = p.b.toString();
String dst = p.c.toString();
String name = p.d.toString();
String kind = p.a.toString();
switch(kind) {
case "external":
return new TransExp.External(src, dst, name);
case "SIGMA":
return new TransExp.FullSigma(name, src, dst);
default:
throw new RuntimeException(o.toString());
}
} catch (RuntimeException ex) {
}
try {
Tuple4 p = (Tuple4) o;
String obj = p.a.toString();
String dst = p.d.toString();
if (p.c.toString().equals("void")) {
return new TransExp.FF(obj, dst);
} else if (p.c.toString().equals("unit")) {
return new TransExp.TT(obj, dst);
} else if (p.c.toString().equals("curry")) {
return new TransCurry(obj, dst);
} else if (p.c.toString().equals("true")) {
return new Bool(true, dst, obj);
} else if (p.c.toString().equals("false")) {
return new Bool(false, dst, obj);
} else if (p.c.toString().equals("char")) {
return new Chi(obj, dst);
}
} catch (RuntimeException re) {
}
try {
Tuple3 p = (Tuple3) o;
Object p2 = p.b;
Object p3 = p.c;
Object o1 = p.a;
String p1 = p.a.toString();
if (p1.equals("iso1")) {
return new TransIso(true, p2.toString(), p3.toString());
} else if (p1.equals("iso2")) {
return new TransIso(false, p2.toString(), p3.toString());
} else if (p3.toString().equals("fst")) {
return new TransExp.Fst(p1);
} else if (p3.toString().equals("not")) {
return new Not(p1);
} else if (p3.toString().equals("and")) {
return new And(p1);
} else if (p3.toString().equals("or")) {
return new Or(p1);
} else if (p3.toString().equals("implies")) {
return new Implies(p1);
} else if (p3.toString().equals("eval")) {
return new TransEval(p1);
} else if (p3.toString().equals("relationalize")) {
return new Squash(p1);
} else if (p3.toString().equals("snd")) {
return new TransExp.Snd(p1);
} else if (p3.toString().equals("return")) {
return new Return(p1);
} else if (p3.toString().equals("coreturn")) {
return new Coreturn(p1);
} else if (p3.toString().equals("inl")) {
return new TransExp.Inl(p1);
} else if (p3.toString().equals("kernel")) {
return new UnChi(p1);
} else if (p3.toString().equals("inr")) {
return new TransExp.Inr(p1);
} else if (p2.toString().equals("then")) {
return new TransExp.Comp(toTrans(o1), toTrans(p3));
} else if (p3 instanceof Tuple3) {
Tuple3 y = (Tuple3) p3;
String x = y.b.toString();
switch(x) {
case "+":
return new TransExp.Case(p1, toTrans(y.a), toTrans(y.c));
case "*":
return new TransExp.Prod(p1, toTrans(y.a), toTrans(y.c));
// return new TransExp.(p1, toTrans(y.a), toTrans(y.c));
default:
throw new RuntimeException("foo");
}
}
} catch (RuntimeException re) {
}
try {
Tuple5 p = (Tuple5) o;
Object p2 = p.c;
Object p3 = p.e;
Object o1 = p.a;
return toTransConst(o1, p2.toString(), p3.toString());
} catch (RuntimeException re) {
}
try {
org.jparsec.functors.Pair p = (org.jparsec.functors.Pair) o;
String p1 = p.a.toString();
Object p2 = p.b;
if (p1.equals("id")) {
return new TransExp.Id(p2.toString());
}
} catch (RuntimeException re) {
}
if (o instanceof String) {
return new TransExp.Var(o.toString());
}
throw new RuntimeException();
}
Aggregations