use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.
the class NraViewer method toTy.
private static NRel toTy(Object o) {
Tuple4 e = (Tuple4) o;
List l = (List) e.c;
Map<String, Optional<NRel>> m = new HashMap();
for (Object x : l) {
Tuple3 u = (Tuple3) x;
if (u.c.toString().equals("string")) {
m.put(u.a.toString(), Optional.empty());
} else {
m.put(u.a.toString(), Optional.of(toTy(u.c)));
}
}
return new NRel(m);
}
use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.
the class NraViewer method toInst.
private static Object toInst(Object o) {
if (o instanceof String) {
return o;
}
Tuple3 t = (Tuple3) o;
List l = (List) t.b;
if (t.a.toString().equals("(")) {
Map<String, Object> m = new HashMap();
for (Object lx : l) {
Tuple3 u = (Tuple3) lx;
m.put(u.a.toString(), toInst(u.c));
}
return m;
} else {
Set m = new HashSet<>();
for (Object lx : l) {
m.add(toInst(lx));
}
return m;
}
}
use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.
the class CfgToOpl method toCfg.
@SuppressWarnings({ "unchecked", "rawtypes" })
private static OplExp toCfg(Object o) {
Map<String, List<List<String>>> ret = new HashMap<>();
List<Tuple3> l = (List<Tuple3>) o;
for (Tuple3 p : l) {
String x = (String) p.a;
if (ret.containsKey(x)) {
throw new RuntimeException("Duplicate production name: " + x);
}
ret.put(x, (List<List<String>>) p.c);
}
Map<String, Pair<List<String>, String>> symbols = new HashMap<>();
int i = 0;
for (String k : ret.keySet()) {
List<List<String>> v = ret.get(k);
for (List<String> u : v) {
List<String> pre = new LinkedList<>();
List<String> tys = new LinkedList<>();
for (String z : u) {
if (ret.keySet().contains(z)) {
tys.add(z);
} else {
pre.add(z);
}
}
String name0 = Util.sep(pre, "_");
String xxx = symbols.keySet().contains(name0) ? "_" + (i++) : "";
String name = "\"" + name0 + xxx + "\"";
symbols.put(name, new Pair<>(tys, k));
i++;
}
}
return new OplSig(null, new HashMap<>(), ret.keySet(), symbols, new LinkedList<>());
}
use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.
the class CombinatorParser method graphExpRaw.
private static Parser<GraphExpRaw> graphExpRaw() {
Parser<List<LocStr>> nodes = Parsers.tuple(token("nodes"), locstr.many()).map(x -> x.b);
Parser<Pair<Token, List<Tuple5<List<LocStr>, Token, String, Token, String>>>> edges = Parsers.tuple(token("edges"), Parsers.tuple(locstr.many1(), token(":"), ident, token("->"), ident).many());
Parser<List<catdata.Pair<LocStr, catdata.Pair<String, String>>>> edges0 = edges.map(x -> {
List<catdata.Pair<LocStr, catdata.Pair<String, String>>> ret = new LinkedList<>();
for (Tuple5<List<LocStr>, Token, String, Token, String> a : x.b) {
for (LocStr b : a.a) {
ret.add(new catdata.Pair<>(b, new catdata.Pair<>(a.c, a.e)));
}
}
return ret;
});
Parser<Tuple3<List<LocStr>, List<LocStr>, List<catdata.Pair<LocStr, catdata.Pair<String, String>>>>> pa = Parsers.tuple(imports, nodes.optional(), edges0.optional());
Parser<GraphExpRaw> ret = pa.map(x -> new GraphExpRaw(Util.newIfNull(x.b), Util.newIfNull(x.c), x.a));
return ret.between(token("literal").followedBy(token("{")), token("}"));
}
use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.
the class CombinatorParser method schExpRaw.
private static Parser<SchExpRaw> schExpRaw() {
Parser<List<LocStr>> entities = Parsers.tuple(token("entities"), locstr.many()).map(x -> x.b);
Parser<Pair<Token, List<Tuple5<List<LocStr>, Token, String, Token, String>>>> fks = Parsers.tuple(token("foreign_keys"), Parsers.tuple(locstr.many1(), token(":"), ident, token("->"), ident).many());
Parser<List<catdata.Pair<LocStr, catdata.Pair<String, String>>>> fks0 = fks.map(x -> {
List<catdata.Pair<LocStr, catdata.Pair<String, String>>> ret = new LinkedList<>();
for (Tuple5<List<LocStr>, Token, String, Token, String> a : x.b) {
for (LocStr b : a.a) {
ret.add(new catdata.Pair<>(b, new catdata.Pair<>(a.c, a.e)));
}
}
return ret;
});
Parser<Pair<Token, List<Tuple5<List<LocStr>, Token, String, Token, String>>>> atts = Parsers.tuple(token("attributes"), Parsers.tuple(locstr.many1(), token(":"), ident, token("->"), ident).many());
Parser<List<catdata.Pair<LocStr, catdata.Pair<String, String>>>> atts0 = atts.map(x -> {
List<catdata.Pair<LocStr, catdata.Pair<String, String>>> ret = new LinkedList<>();
for (Tuple5<List<LocStr>, Token, String, Token, String> a : x.b) {
for (LocStr b : a.a) {
ret.add(new catdata.Pair<>(b, new catdata.Pair<>(a.c, a.e)));
}
}
return ret;
});
Parser<catdata.Pair<Integer, catdata.Pair<List<String>, List<String>>>> p_eq = Parsers.tuple(Parsers.INDEX, Parsers.tuple(ident.sepBy(token(".")), token("="), ident.sepBy(token(".")))).map(x -> new catdata.Pair<>(x.a, new catdata.Pair<>(x.b.a, x.b.c)));
Parser<Pair<Token, List<catdata.Pair<Integer, catdata.Pair<List<String>, List<String>>>>>> p_eqs = Parsers.tuple(token("path_equations"), p_eq.many());
Parser<List<catdata.Pair<Integer, catdata.Pair<List<String>, List<String>>>>> p_eqs0 = p_eqs.map(x -> x.b);
Parser<catdata.Pair<Integer, Quad<String, String, RawTerm, RawTerm>>> o_eq_from_p_eq = p_eq.map(x -> new catdata.Pair<>(x.first, new Quad<>("_x", null, RawTerm.fold(x.second.first, "_x"), RawTerm.fold(x.second.second, "_x"))));
Parser<catdata.Pair<Integer, Quad<String, String, RawTerm, RawTerm>>> o_eq_old = Parsers.tuple(Parsers.INDEX, Parsers.tuple(token("forall"), ident, Parsers.tuple(token(":"), ident).optional().followedBy(token(".")), term().followedBy(token("=")), term())).map(x -> new catdata.Pair<>(x.a, new Quad<>(x.b.b, x.b.c == null ? null : x.b.c.b, x.b.d, x.b.e)));
Parser<catdata.Pair<Integer, Quad<String, String, RawTerm, RawTerm>>> o_eq = Parsers.or(o_eq_old, o_eq_from_p_eq);
Parser<Pair<Token, List<catdata.Pair<Integer, Quad<String, String, RawTerm, RawTerm>>>>> o_eqs = Parsers.tuple(token("observation_equations"), o_eq.many());
Parser<List<catdata.Pair<Integer, Quad<String, String, RawTerm, RawTerm>>>> o_eqs0 = o_eqs.map(x -> x.b);
Parser<Tuple4<List<LocStr>, List<LocStr>, List<catdata.Pair<LocStr, catdata.Pair<String, String>>>, List<catdata.Pair<Integer, catdata.Pair<List<String>, List<String>>>>>> pa = Parsers.tuple(imports, entities.optional(), fks0.optional(), p_eqs0.optional());
Parser<Tuple3<List<catdata.Pair<LocStr, catdata.Pair<String, String>>>, List<catdata.Pair<Integer, Quad<String, String, RawTerm, RawTerm>>>, List<catdata.Pair<String, String>>>> pb = Parsers.tuple(atts0.optional(), o_eqs0.optional(), options);
Parser<Tuple4<Token, Token, TyExp<?, ?>, Token>> l = Parsers.tuple(token("literal"), token(":"), ty_ref.lazy(), // .map(x -> x.c);
token("{"));
// needs tyexp
Parser<SchExpRaw> ret = Parsers.tuple(l, pa, pb, token("}")).map(x -> new SchExpRaw((TyExp<Ty, Sym>) x.a.c, x.b.a, Util.newIfNull(x.b.b), Util.newIfNull(x.b.c), Util.newIfNull(x.b.d), Util.newIfNull(x.c.a), Util.newIfNull(x.c.b), x.c.c));
return ret;
}
Aggregations