use of org.jparsec.functors.Tuple4 in project fql by CategoricalData.
the class PPParser method toCat.
private static CatExp toCat(Object o) {
if (o.toString().equals("Set")) {
return new Named("Set");
}
if (o.toString().equals("Cat")) {
return new Named("Cat");
}
if (o instanceof Tuple4) {
Tuple4 t = (Tuple4) o;
return new Kleisli(t.b.toString(), t.c.toString(), t.d.toString(), t.a.toString().equals("cokleisli"));
}
try {
Tuple3<?, ?, ?> t = (Tuple3<?, ?, ?>) o;
String y = t.b.toString();
if (y.equals("+")) {
return new Plus(toCat(t.a), toCat(t.c));
} else if (y.equals("*")) {
return new Times(toCat(t.a), toCat(t.c));
} else if (y.equals("^")) {
return new CatExp.Exp(toCat(t.a), toCat(t.c));
} else if (t.a.toString().equals("union")) {
return new Union(toCat(t.b), toCat(t.c));
} else {
return toCatConst(o);
}
} catch (RuntimeException cce) {
}
try {
org.jparsec.functors.Pair<?, ?> p = (org.jparsec.functors.Pair<?, ?>) o;
if (p.a.toString().equals("dom")) {
return new CatExp.Dom(toFtr(p.b));
} else if (p.a.toString().equals("cod")) {
return new Cod(toFtr(p.b));
} else if (p.a.toString().equals("colim")) {
return new Colim((String) p.b);
}
} catch (RuntimeException cce) {
}
try {
if (o.toString().equals("void")) {
return new CatExp.Zero();
} else if (o.toString().equals("unit")) {
return new CatExp.One();
}
} catch (RuntimeException cce) {
}
return new CatExp.Var(o.toString());
}
use of org.jparsec.functors.Tuple4 in project fql by CategoricalData.
the class OplParser method toSchema.
private static OplExp toSchema(Object o) {
Tuple4 t = (Tuple4) o;
org.jparsec.functors.Pair e = (org.jparsec.functors.Pair) t.b;
String yyy = (String) t.d;
List<String> symbols0 = (List<String>) e.b;
return new OplSchema<String, String, String>(yyy, new HashSet<>(symbols0));
}
use of org.jparsec.functors.Tuple4 in project fql by CategoricalData.
the class OplParser method toChase.
private static OplExp toChase(Tuple5 t) {
// Parser<?> chase = Parsers.tuple(term("chase"), ident(), Parsers.tuple(term("with"), term("{"), ident().sepBy(term(","), term("}")), term("max"), ident()));
String I = (String) t.b;
// t.c is (with { ... })
Integer i0 = Integer.parseInt((String) t.e);
Tuple4 x = (Tuple4) t.c;
List<String> l = (List<String>) x.c;
return new OplChaseExp(i0, I, new LinkedList<>(l));
}
use of org.jparsec.functors.Tuple4 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.Tuple4 in project fql by CategoricalData.
the class OplParser method fromBlocks2.
private static Map<Object, Pair<String, Block<String, String, String, String, String, String>>> fromBlocks2(List l) {
Map<Object, Pair<String, Block<String, String, String, String, String, String>>> ret = new HashMap<>();
for (Object o : l) {
Tuple4 t = (Tuple4) o;
Block<String, String, String, String, String, String> b = fromBlock2(t.d);
ret.put(t.c.toString(), new Pair<>(t.c.toString(), b));
}
return ret;
}
Aggregations