use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.
the class PPParser method toCatFtrConst.
private static FunctorExp toCatFtrConst(Object decl) {
Tuple5 y = (Tuple5) decl;
org.jparsec.functors.Pair x = (org.jparsec.functors.Pair) y.a;
Tuple3 nodes = (Tuple3) x.a;
Tuple3 arrows = (Tuple3) x.b;
List nodes0 = (List) nodes.b;
List arrows0 = (List) arrows.b;
Map<String, CatExp> nodesX = new HashMap<>();
for (Object o : nodes0) {
if (nodesX.containsKey(o)) {
throw new RuntimeException("Duplicate object: " + o + " in " + decl);
}
Tuple3 u = (Tuple3) o;
String n = (String) u.a;
CatExp l = toCat(u.c);
nodesX.put(n, l);
}
Map<String, FunctorExp> arrowsX = new HashMap<>();
for (Object o : arrows0) {
if (arrowsX.containsKey(o)) {
throw new RuntimeException("Duplicate arrow: " + o + " in " + decl);
}
Tuple3 u = (Tuple3) o;
String n = (String) u.a;
FunctorExp l = toFtr(u.c);
arrowsX.put(n, l);
}
CatConst ret = new CatConst(toCat(y.c), nodesX, arrowsX);
return ret;
}
use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.
the class PPParser method toCatConst.
public static CatExp.Const toCatConst(Object y) {
Set<String> nodes = new HashSet<>();
Set<Triple<String, String, String>> arrows = new HashSet<>();
Set<Pair<Pair<String, List<String>>, Pair<String, List<String>>>> eqs = new HashSet<>();
Tuple3 s = (Tuple3) y;
Tuple3 nodes0 = (Tuple3) s.a;
Tuple3 arrows0 = (Tuple3) s.b;
Tuple3 eqs0 = (Tuple3) s.c;
List nodes1 = (List) nodes0.b;
List arrows1 = (List) arrows0.b;
List eqs1 = (List) eqs0.b;
for (Object o : nodes1) {
nodes.add((String) o);
}
for (Object o : arrows1) {
Tuple5 x = (Tuple5) o;
arrows.add(new Triple<>((String) x.a, (String) x.c, (String) x.e));
}
for (Object o : eqs1) {
Tuple3 x = (Tuple3) o;
List<String> l1 = (List<String>) x.a;
List<String> l2 = (List<String>) x.c;
String xxx = l1.remove(0);
String yyy = l2.remove(0);
eqs.add(new Pair<>(new Pair<>(xxx, l1), new Pair<>(yyy, l2)));
}
CatExp.Const c = new CatExp.Const(nodes, arrows, eqs);
return c;
}
use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.
the class OplParser method toPragma.
private static OplExp toPragma(Object t) {
Tuple3 tb = (Tuple3) t;
List<Tuple3> l = (List<Tuple3>) tb.b;
Map<String, String> map = new HashMap<>();
for (Tuple3 x : l) {
String k = (String) x.a;
String v = (String) x.c;
if (map.containsKey(k)) {
throw new DoNotIgnore("Duplicate key: " + k);
}
map.put(k, v);
}
return new OplPragma(map);
}
use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.
the class OplParser method toFDM.
private static OplExp toFDM(Object c) {
Tuple3 t = (Tuple3) c;
String i = (String) t.b;
String r = (String) t.c;
if (t.a.toString().equals("delta")) {
return new OplDelta(i, r);
} else if (t.a.toString().equals("sigma")) {
return new OplSigma(i, r);
}
throw new RuntimeException();
}
use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.
the class OplParser method toTrans_2.
private static OplExp toTrans_2(Object c) {
Tuple3 t = (Tuple3) c;
if (!t.a.toString().equals("transpres")) {
throw new RuntimeException();
}
Map<String, Map<String, OplTerm>> map = new HashMap<>();
org.jparsec.functors.Pair q = (org.jparsec.functors.Pair) t.b;
List<String> imports = q.a == null ? new LinkedList<>() : (List<String>) ((org.jparsec.functors.Pair) q.a).b;
Tuple3 tb = (Tuple3) q.b;
List<Tuple5> l = (List<Tuple5>) tb.b;
for (Tuple5 x : l) {
String name = (String) x.a;
List<Tuple5> y = (List<Tuple5>) x.d;
Map<String, OplTerm> m = new HashMap<>();
for (Tuple5 z : y) {
String xx = (String) z.b;
// OplTerm yy = toTermNoVars(z.d);
OplTerm yy = toTerm(new HashSet<>(), new HashSet<>(), z.d, false);
if (m.containsKey(xx)) {
throw new DoNotIgnore("Duplicate argument: " + xx);
}
m.put(xx, yy);
}
if (map.containsKey(name)) {
throw new DoNotIgnore("Duplicate sort: " + name);
}
map.put(name, m);
}
Tuple4 tc = (Tuple4) t.c;
OplPresTrans ret = new OplPresTrans(map, (String) tc.b, (String) tc.d);
ret.imports = new HashSet<>(imports);
return ret;
}
Aggregations