use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.
the class PPParser method toFinalConst.
private static FunctorExp toFinalConst(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, FunctorExp> 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;
FunctorExp l = toFtr(u.c);
nodesX.put(n, l);
}
Map<String, TransExp> 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;
TransExp l = toTrans(u.c);
arrowsX.put(n, l);
}
FinalConst ret = new FinalConst(toCat(y.c), toCat(y.e), nodesX, arrowsX);
return ret;
}
use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.
the class OplParser method toPresentation.
private static OplPres toPresentation(Object o) {
Tuple4 t = (Tuple4) o;
Tuple3 e = (Tuple3) t.b;
// List<String> imports = e.a == null ? new LinkedList<>() : (List<String>) ((Tuple3)e.a).b;
String yyy = (String) t.d;
org.jparsec.functors.Pair b = (org.jparsec.functors.Pair) e.b;
org.jparsec.functors.Pair c = (org.jparsec.functors.Pair) e.c;
List<Tuple3> symbols0 = (List<Tuple3>) b.b;
List<Tuple4> equations0 = (List<Tuple4>) c.b;
Map<String, String> symbols = new HashMap<>();
Map<String, Integer> prec = new HashMap<>();
for (Tuple3 x : symbols0) {
String dom = (String) x.c;
List<org.jparsec.functors.Pair> name0s = (List<org.jparsec.functors.Pair>) x.a;
for (org.jparsec.functors.Pair name0 : name0s) {
String name = (String) name0.a;
if (name0.b != null) {
org.jparsec.functors.Pair zzz = (org.jparsec.functors.Pair) name0.b;
Integer i = (Integer) zzz.b;
prec.put(name, i);
}
if (symbols.containsKey(name)) {
throw new DoNotIgnore("Duplicate symbol " + name);
}
symbols.put(name, dom);
}
}
List<Pair<OplTerm<Chc<String, String>, String>, OplTerm<Chc<String, String>, String>>> equations = new LinkedList<>();
for (org.jparsec.functors.Pair<Tuple3, Tuple3> x : equations0) {
if (x.a != null) {
throw new DoNotIgnore("Cannot have universally quantified equations in presentations");
}
List<Tuple3> fa = new LinkedList<>();
OplCtx<String, String> ctx = toCtx(fa);
Tuple3 eq = x.b;
OplTerm lhs = toTerm(ctx.names(), symbols.keySet(), eq.a, true);
OplTerm rhs = toTerm(ctx.names(), symbols.keySet(), eq.c, true);
equations.add(new Pair<>(lhs, rhs));
}
OplPres ret = new OplPres<>(prec, yyy, null, symbols, equations);
return ret;
}
use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.
the class OplParser method toTheory.
private static OplExp toTheory(Object o) {
Tuple5 t = (Tuple5) o;
List<String> imports = t.a == null ? new LinkedList<>() : (List<String>) ((org.jparsec.functors.Pair) t.a).b;
Tuple3 a = (Tuple3) t.b;
Tuple3 b = (Tuple3) t.c;
Tuple3 c = (Tuple3) t.d;
Tuple3 d = (Tuple3) t.e;
Set<String> sorts = a == null ? new HashSet<>() : new HashSet<>((Collection<String>) a.b);
List<Tuple3> symbols0 = b == null ? new LinkedList<>() : (List<Tuple3>) b.b;
List<org.jparsec.functors.Pair> equations0 = c == null ? new LinkedList<>() : (List<org.jparsec.functors.Pair>) c.b;
List<org.jparsec.functors.Pair> implications0 = new LinkedList<>();
if (d != null) {
implications0 = (List<org.jparsec.functors.Pair>) d.b;
}
Map<String, Pair<List<String>, String>> symbols = new HashMap<>();
Map<String, Integer> prec = new HashMap<>();
for (Tuple3 x : symbols0) {
String dom;
List<String> args;
if (x.c instanceof Tuple3) {
Tuple3 zzz = (Tuple3) x.c;
args = (List<String>) zzz.a;
dom = (String) zzz.c;
} else {
dom = (String) x.c;
args = new LinkedList<>();
}
List<org.jparsec.functors.Pair> name0s = (List<org.jparsec.functors.Pair>) x.a;
for (org.jparsec.functors.Pair name0 : name0s) {
// org.jparsec.functors.Pair name0 =
// (org.jparsec.functors.Pair) x.a;
String name = (String) name0.a;
if (name0.b != null) {
org.jparsec.functors.Pair zzz = (org.jparsec.functors.Pair) name0.b;
Integer i = (Integer) zzz.b;
prec.put(name, i);
}
if (symbols.containsKey(name)) {
throw new DoNotIgnore("Duplicate symbol " + name);
}
symbols.put(name, new Pair<>(args, dom));
}
}
if (sorts.contains("Nat") && symbols.keySet().contains("zero") && symbols.keySet().contains("succ") && DefunctGlobalOptions.debug.opl.opl_desugar_nat) {
sugarForNat = true;
}
List<Triple<OplCtx<String, String>, OplTerm<String, String>, OplTerm<String, String>>> equations = new LinkedList<>();
for (org.jparsec.functors.Pair<Tuple3, Tuple3> x : equations0) {
List<Tuple3> fa = x.a == null ? new LinkedList<>() : (List<Tuple3>) x.a.b;
OplCtx<String, String> ctx = toCtx(fa);
Tuple3 eq = x.b;
OplTerm lhs = toTerm(ctx.names(), consts(symbols), eq.a, false);
OplTerm rhs = toTerm(ctx.names(), consts(symbols), eq.c, false);
equations.add(new Triple<>(ctx, lhs, rhs));
}
List<Triple<OplCtx<String, String>, List<Pair<OplTerm<String, String>, OplTerm<String, String>>>, List<Pair<OplTerm<String, String>, OplTerm<String, String>>>>> implications = new LinkedList<>();
for (org.jparsec.functors.Pair<Tuple3, Tuple3> x : implications0) {
List<Tuple3> fa = x.a == null ? new LinkedList<>() : (List<Tuple3>) x.a.b;
OplCtx<String, String> ctx = toCtx(fa);
Tuple3 eq = x.b;
List<Tuple3> lhs0 = (List<Tuple3>) eq.a;
List<Tuple3> rhs0 = (List<Tuple3>) eq.c;
List<Pair<OplTerm<String, String>, OplTerm<String, String>>> lhs = new LinkedList<>();
List<Pair<OplTerm<String, String>, OplTerm<String, String>>> rhs = new LinkedList<>();
for (Tuple3 obj : lhs0) {
OplTerm lhsX = toTerm(ctx.names(), consts(symbols), obj.a, false);
OplTerm rhsX = toTerm(ctx.names(), consts(symbols), obj.c, false);
lhs.add(new Pair<>(lhsX, rhsX));
}
for (Tuple3 obj : rhs0) {
OplTerm lhsX = toTerm(ctx.names(), consts(symbols), obj.a, false);
OplTerm rhsX = toTerm(ctx.names(), consts(symbols), obj.c, false);
rhs.add(new Pair<>(lhsX, rhsX));
}
implications.add(new Triple<>(ctx, lhs, rhs));
}
OplSig ret = new OplSig<>(new VIt(), prec, sorts, symbols, equations, implications);
ret.imports = new HashSet<>(imports);
return ret;
}
use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.
the class OplParser method toEval.
private static OplExp toEval(Object c) {
Tuple3 t = (Tuple3) c;
if (!t.a.toString().equals("eval")) {
throw new RuntimeException();
}
String i = (String) t.b;
OplTerm r = toTerm(null, null, t.c, false);
return new OplEval(i, r);
}
use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.
the class OplParser method fromAgg.
@SuppressWarnings("unused")
private static Agg<String, String, String, String, String, String> fromAgg(Collection vars, Collection consts, Object o, boolean suppressError) {
Tuple5<Tuple4<?, String, String, ?>, List<Tuple3<String, ?, String>>, List<Tuple3<?, ?, ?>>, org.jparsec.functors.Pair<?, ?>, ?> t = (Tuple5<Tuple4<?, String, String, ?>, List<Tuple3<String, ?, String>>, List<Tuple3<?, ?, ?>>, org.jparsec.functors.Pair<?, ?>, ?>) o;
LinkedHashMap<String, String> from = new LinkedHashMap<>();
Set<Pair<OplTerm<String, String>, OplTerm<String, String>>> where = new HashSet<>();
for (Object x : t.b) {
Tuple3 l = (Tuple3) x;
if (from.containsKey(l.a.toString())) {
throw new RuntimeException("Duplicate for: " + l.a);
}
from.put(l.a.toString(), l.c.toString());
}
Set<String> allVars = new HashSet<>();
allVars.addAll(vars);
allVars.addAll(from.keySet());
for (Object x : t.c) {
Tuple3 l = (Tuple3) x;
where.add(new Pair(toTerm(allVars, null, l.a, true), toTerm(allVars, null, l.c, true)));
}
OplTerm<String, String> att = toTerm(allVars, null, t.d.b, true);
return new Agg<>(t.a.b, t.a.c, from, where, att);
}
Aggregations