use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.
the class FQLParser method toMapConst.
@SuppressWarnings({ "rawtypes", "unchecked" })
private static MapExp toMapConst(Object decl, SigExp t1, SigExp t2) {
Tuple3 x = (Tuple3) decl;
List<Pair<String, String>> objs = new LinkedList<>();
List<Pair<String, String>> attrs = new LinkedList<>();
List<Pair<String, List<String>>> arrows = new LinkedList<>();
Tuple3 a = (Tuple3) x.a;
Tuple3 b = (Tuple3) x.b;
Tuple3 c = (Tuple3) x.c;
List a0 = (List) a.b;
for (Object o : a0) {
Tuple3 z = (Tuple3) o;
String p = (String) z.a;
String q = (String) z.c;
objs.add(new Pair<>(p, q));
}
if (b.b.toString().equals("ASWRITTEN")) {
for (Pair<String, String> k : objs) {
attrs.add(new Pair<>(k.first + "_att", k.second + "_att"));
}
} else {
List b0 = (List) b.b;
for (Object o : b0) {
Tuple3 z = (Tuple3) o;
String p = (String) z.a;
String q = (String) z.c;
attrs.add(new Pair<>(p, q));
}
}
List c0 = (List) c.b;
for (Object o : c0) {
Tuple3 z = (Tuple3) o;
String p = (String) z.a;
List<String> q = (List<String>) z.c;
arrows.add(new Pair<>(p, q));
}
try {
MapExp.Const ret = new MapExp.Const(objs, attrs, arrows, t1, t2);
return ret;
} catch (Exception ex) {
ex.printStackTrace();
throw ex;
}
}
use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.
the class FQLParser method toMatch.
@SuppressWarnings({ "unchecked", "rawtypes" })
private static Set<Pair<String, String>> toMatch(Object b) {
List<Tuple3> l = (List<Tuple3>) b;
Set<Pair<String, String>> ret = new HashSet<>();
for (Tuple3 k : l) {
ret.add(new Pair<>(k.a.toString(), k.c.toString()));
}
return ret;
}
use of org.jparsec.functors.Tuple3 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 org.jparsec.functors.Tuple3 in project fql by CategoricalData.
the class FQLParser method toInstConst.
@SuppressWarnings("rawtypes")
private static InstExp toInstConst(Object decl) {
Tuple3 y = (Tuple3) decl;
Tuple3 x = (Tuple3) y.a;
// List<Pair<String, List<Pair<Object, Object>>>> data = new
// LinkedList<>();
Tuple3 nodes = (Tuple3) x.a;
Tuple3 arrows = (Tuple3) x.c;
Tuple3 attrs = (Tuple3) x.b;
List nodes0 = (List) nodes.b;
List arrows0 = (List) arrows.b;
// List<Object> seen = new LinkedList<>();
List<Pair<String, List<Pair<Object, Object>>>> nodesX = new LinkedList<>();
for (Object o : nodes0) {
Tuple3 u = (Tuple3) o;
String n = (String) u.a;
List m = (List) u.c;
List<Pair<Object, Object>> l = new LinkedList<>();
for (Object h : m) {
l.add(new Pair<>(h, h));
}
// if (seen.contains(n)) {
// throw new RuntimeException("duplicate field: " + o);
// }
// seen.add(n);
nodesX.add(new Pair<>(n, l));
}
// RuntimeException toThrow = null;
List<Pair<String, List<Pair<Object, Object>>>> attrsX = new LinkedList<>();
if (attrs.b.toString().equals("ASWRITTEN")) {
for (Pair<String, List<Pair<Object, Object>>> k : nodesX) {
attrsX.add(new Pair<>(k.first + "_att", k.second));
}
} else {
List attrs0 = (List) attrs.b;
for (Object o : attrs0) {
Tuple3 u = (Tuple3) o;
String n = (String) u.a;
List m = (List) u.c;
List<Pair<Object, Object>> l = new LinkedList<>();
for (Object h : m) {
Tuple3 k = (Tuple3) h;
l.add(new Pair<>(k.a, k.c));
}
// if (seen.contains(n)) {
// toThrow = new RuntimeException("duplicate field: " + n );
// throw toThrow;
// }
// seen.add(n);
attrsX.add(new Pair<>(n, l));
}
}
List<Pair<String, List<Pair<Object, Object>>>> arrowsX = new LinkedList<>();
for (Object o : arrows0) {
Tuple3 u = (Tuple3) o;
String n = (String) u.a;
List m = (List) u.c;
List<Pair<Object, Object>> l = new LinkedList<>();
for (Object h : m) {
Tuple3 k = (Tuple3) h;
l.add(new Pair<>(k.a, k.c));
}
// if (seen.contains(n)) {
// throw new RuntimeException("duplicate field: " + o);
// }
// seen.add(n);
arrowsX.add(new Pair<>(n, l));
}
InstExp.Const ret = new InstExp.Const(nodesX, attrsX, arrowsX, toSchema(y.c));
return ret;
}
use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.
the class FQLParser method toSchema.
@SuppressWarnings({ "rawtypes", "unchecked" })
private static SigExp toSchema(Object o) {
try {
Tuple3<?, ?, ?> t = (Tuple3<?, ?, ?>) o;
Token z = (Token) t.b;
String y = z.toString();
switch(y) {
case "+":
return new SigExp.Plus(toSchema(t.a), toSchema(t.c));
case "*":
return new SigExp.Times(toSchema(t.a), toSchema(t.c));
case "^":
return new SigExp.Exp(toSchema(t.a), toSchema(t.c));
case "union":
return new Union(toSchema(t.a), toSchema(t.c));
default:
break;
}
} catch (RuntimeException cce) {
}
try {
org.jparsec.functors.Pair p = (org.jparsec.functors.Pair) o;
if (p.a.toString().equals("unit")) {
return new SigExp.One(new HashSet<>((Collection<String>) p.b));
} else if (p.a.toString().equals("opposite")) {
return new SigExp.Opposite(toSchema(p.b));
}
} catch (RuntimeException cce) {
}
try {
if (o.toString().equals("void")) {
return new SigExp.Zero();
} else if (o.toString().equals("?")) {
return new Unknown("?" + unknown_idx++);
}
throw new RuntimeException();
} catch (RuntimeException cce) {
}
try {
return toSchemaConst(o);
} catch (RuntimeException cce) {
}
return new SigExp.Var(o.toString());
}
Aggregations