use of org.jparsec.functors.Tuple5 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.Tuple5 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;
}
use of org.jparsec.functors.Tuple5 in project fql by CategoricalData.
the class XNeo4jToFQL method fromEdges.
/* Parser<?> n = ident().between(term("("), term(")"));
Parser<?> e = Parsers.tuple(term("["), term(":"), ident(), term("]"));
Parser<?> p = Parsers.tuple(n, term("-"), e, term("->"), n);
return Parsers.tuple(term("CREATE"), p.sepBy(term(","))); */
@SuppressWarnings({ "rawtypes", "unchecked" })
private static Map<String, Set<Pair<String, String>>> fromEdges(Object oo) {
Map<String, Set<Pair<String, String>>> ret = new HashMap<>();
org.jparsec.functors.Pair o = (org.jparsec.functors.Pair) oo;
List<Tuple5> xx = (List<Tuple5>) o.b;
for (Tuple5 tt : xx) {
String s = (String) tt.a;
String t = (String) tt.e;
Tuple4 e0 = (Tuple4) tt.c;
String e = (String) e0.c;
Set<Pair<String, String>> set = ret.computeIfAbsent(e, k -> new HashSet<>());
set.add(new Pair<>(s, t));
}
return ret;
}
use of org.jparsec.functors.Tuple5 in project fql by CategoricalData.
the class XParser method fromBlocks.
private static Map<Object, Pair<String, Block<String, String>>> fromBlocks(List l) {
Map<Object, Pair<String, Block<String, String>>> ret = new HashMap<>();
for (Object o : l) {
Tuple5 t = (Tuple5) o;
Block<String, String> b = fromBlock(t.c);
ret.put(t.a.toString(), new Pair<>(t.e.toString(), b));
}
return ret;
}
use of org.jparsec.functors.Tuple5 in project fql by CategoricalData.
the class XParser method toTrans.
private static XTransConst toTrans(Object decl) {
Tuple5 y = (Tuple5) decl;
// org.jparsec.functors.Pair x = (org.jparsec.functors.Pair) y.a;
Tuple3 nodes = (Tuple3) y.a;
// Tuple3 arrows = (Tuple3) x.b;
List nodes0 = (List) nodes.b;
// List arrows0 = (List) arrows.b;
List<Pair<Pair<String, String>, List<String>>> eqsX = new LinkedList<>();
for (Object o : nodes0) {
Tuple3 u = (Tuple3) o;
List<String> m = (List<String>) u.c;
if (u.a instanceof Tuple3) {
Tuple3 n = (Tuple3) u.a;
eqsX.add(new Pair<>(new Pair<>(n.a.toString(), n.c.toString()), m));
} else {
String n = (String) u.a;
eqsX.add(new Pair<>(new Pair<>(n, null), m));
}
}
XTransConst ret = new XTransConst(toExp(y.c), toExp(y.e), eqsX);
return ret;
}
Aggregations