Search in sources :

Example 6 with Tuple4

use of org.jparsec.functors.Tuple4 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);
}
Also used : Agg(catdata.opl.OplQuery.Agg) LinkedHashMap(java.util.LinkedHashMap) Tuple4(org.jparsec.functors.Tuple4) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair) HashSet(java.util.HashSet)

Example 7 with Tuple4

use of org.jparsec.functors.Tuple4 in project fql by CategoricalData.

the class OplParser method fromBlock.

private static Block<String, String, String, String, String, String> fromBlock(Object o) {
    Tuple4<List, List, List, List> t = (Tuple4<List, List, List, List>) o;
    LinkedHashMap<String, String> from = new LinkedHashMap<>();
    Set<Pair<OplTerm<String, String>, OplTerm<String, String>>> where = new HashSet<>();
    Map<String, Chc<Agg<String, String, String, String, String, String>, OplTerm<String, String>>> attrs = new HashMap<>();
    Map<String, Pair<Object, Map<String, OplTerm<String, String>>>> edges = new HashMap<>();
    for (Object x : t.a) {
        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());
    }
    for (Object x : t.b) {
        Tuple3 l = (Tuple3) x;
        where.add(new Pair(toTerm(from.keySet(), null, l.a, true), toTerm(from.keySet(), null, l.c, true)));
    }
    for (Object x : t.c) {
        Tuple3 l = (Tuple3) x;
        if (attrs.containsKey(l.a.toString())) {
            throw new RuntimeException("Duplicate for: " + l.a);
        }
        if (l.c.toString().contains("agg") && l.c.toString().contains("{") && l.c.toString().contains("return") && l.c.toString().contains("}")) {
            attrs.put(l.a.toString(), Chc.inLeft(fromAgg(from.keySet(), null, l.c, true)));
        } else {
            attrs.put(l.a.toString(), Chc.inRight(toTerm(from.keySet(), null, l.c, true)));
        }
    }
    for (Object x : t.d) {
        Tuple5 l = (Tuple5) x;
        if (from.containsKey(l.a.toString())) {
            throw new RuntimeException("Duplicate for: " + l.a);
        }
        edges.put(l.a.toString(), new Pair(l.e.toString(), fromBlockHelper(from.keySet(), l.c)));
    }
    Block bl = new Block<>(from, where, attrs, edges);
    return bl;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) LinkedHashMap(java.util.LinkedHashMap) Tuple4(org.jparsec.functors.Tuple4) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) Block(catdata.opl.OplQuery.Block) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair) HashSet(java.util.HashSet) Chc(catdata.Chc)

Example 8 with Tuple4

use of org.jparsec.functors.Tuple4 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);
}
Also used : Tuple4(org.jparsec.functors.Tuple4) Optional(java.util.Optional) HashMap(java.util.HashMap) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List)

Example 9 with Tuple4

use of org.jparsec.functors.Tuple4 in project fql by CategoricalData.

the class CombinatorParser method instExpRaw.

private static Parser<InstExpRaw> instExpRaw() {
    Parser<List<catdata.Pair<LocStr, String>>> generators = Parsers.tuple(token("generators"), env(ident, ":")).map(x -> x.b);
    Parser<catdata.Pair<Integer, catdata.Pair<RawTerm, RawTerm>>> eq = Parsers.tuple(Parsers.INDEX, Parsers.tuple(term(), token("="), term())).map(x -> new catdata.Pair<>(x.a, new catdata.Pair<>(x.b.a, x.b.c)));
    Parser<List<catdata.Pair<Integer, catdata.Pair<RawTerm, RawTerm>>>> eqs = Parsers.tuple(token("equations"), eq.many()).map(x -> x.b);
    Parser<List<catdata.Pair<Integer, catdata.Pair<RawTerm, RawTerm>>>> table = Parsers.tuple(Parsers.INDEX, Parsers.tuple(ident, token("->"), token("{"), Parsers.tuple(term(), term()).sepBy(token(",")), token("}"))).map(x -> {
        List<catdata.Pair<Integer, catdata.Pair<RawTerm, RawTerm>>> ret = new LinkedList<>();
        for (Pair<RawTerm, RawTerm> y : x.b.d) {
            ret.add(new catdata.Pair<>(x.a, new catdata.Pair<>(new RawTerm(x.b.a, Util.singList(y.a)), y.b)));
        }
        return ret;
    });
    Parser<List<catdata.Pair<Integer, catdata.Pair<RawTerm, RawTerm>>>> tables = Parsers.tuple(token("multi_equations"), table.many()).map(x -> Util.concat(x.b));
    Parser<Tuple5<List<LocStr>, List<catdata.Pair<LocStr, String>>, List<catdata.Pair<Integer, catdata.Pair<RawTerm, RawTerm>>>, List<catdata.Pair<Integer, catdata.Pair<RawTerm, RawTerm>>>, List<catdata.Pair<String, String>>>> pa = Parsers.tuple(imports, generators.optional(), eqs.optional(), tables.optional(), options);
    Parser<Tuple4<Token, Token, SchExp<?, ?, ?, ?, ?>, Token>> l = Parsers.tuple(token("literal"), token(":"), sch_ref.lazy(), // .map(x -> x.c);
    token("{"));
    Parser<InstExpRaw> ret = Parsers.tuple(l, pa, token("}")).map(x -> new InstExpRaw(x.a.c, Util.newIfNull(x.b.a), Util.newIfNull(x.b.b), new LinkedList<>(Util.append(Util.newIfNull(x.b.c), Util.newIfNull(x.b.d))), x.b.e));
    return ret;
}
Also used : RawTerm(catdata.aql.RawTerm) LinkedList(java.util.LinkedList) Tuple4(org.jparsec.functors.Tuple4) Tuple5(org.jparsec.functors.Tuple5) List(java.util.List) LinkedList(java.util.LinkedList) Pair(org.jparsec.functors.Pair)

Example 10 with Tuple4

use of org.jparsec.functors.Tuple4 in project fql by CategoricalData.

the class CombinatorParser method colimSchExp.

@SuppressWarnings({ "rawtypes", "unchecked" })
private static void colimSchExp() {
    Parser<List<catdata.Pair<LocStr, SchExp<?, ?, ?, ?, ?>>>> nodes = Parsers.tuple(token("nodes"), env(sch_ref.lazy(), "->")).map(x -> x.b);
    Parser<List<catdata.Pair<LocStr, MapExp<?, ?, ?, ?, ?, ?, ?, ?>>>> edges = Parsers.tuple(token("edges"), env(map_ref.lazy(), "->")).map(x -> x.b);
    Parser<Tuple4<Object, List<catdata.Pair<LocStr, SchExp<?, ?, ?, ?, ?>>>, List<catdata.Pair<LocStr, MapExp<?, ?, ?, ?, ?, ?, ?, ?>>>, List<catdata.Pair<String, String>>>> pa = Parsers.tuple(Parsers.always(), nodes.optional(), edges.optional(), options);
    Parser<Tuple5<Token, GraphExp<?, ?>, Token, TyExp<?, ?>, Token>> l = Parsers.tuple(token("literal"), graph_ref.lazy(), token(":"), ty_ref.lazy(), token("{"));
    Parser<ColimSchExp<?>> ret = Parsers.tuple(l, pa, token("}")).map(x -> {
        // schema graph nodes edges options imports
        return new ColimSchExpRaw(x.a.b, x.a.d, Util.newIfNull(x.b.b), Util.newIfNull(x.b.c), x.b.d);
    });
    Parser<ColimSchExp<?>> ret2 = ident.map(x -> new ColimSchExpVar(x)), ret3 = Parsers.tuple(token("wrap"), colim_ref.lazy(), map_ref.lazy(), map_ref.lazy()).map(x -> new ColimSchExpWrap(x.b, x.c, x.d));
    Parser<ColimSchExp<?>> retX = Parsers.or(ret, ret2, ret3, colimExpModify(), colimSchExpQuotient(), parens(colim_ref));
    colim_ref.set(retX);
}
Also used : ColimSchExpRaw(catdata.aql.exp.ColimSchExp.ColimSchExpRaw) ColimSchExpVar(catdata.aql.exp.ColimSchExp.ColimSchExpVar) Tuple4(org.jparsec.functors.Tuple4) Tuple5(org.jparsec.functors.Tuple5) ColimSchExpWrap(catdata.aql.exp.ColimSchExp.ColimSchExpWrap) List(java.util.List) LinkedList(java.util.LinkedList) Pair(org.jparsec.functors.Pair)

Aggregations

Tuple4 (org.jparsec.functors.Tuple4)36 Pair (catdata.Pair)30 Tuple3 (org.jparsec.functors.Tuple3)30 List (java.util.List)25 LinkedList (java.util.LinkedList)24 Tuple5 (org.jparsec.functors.Tuple5)18 HashMap (java.util.HashMap)14 LinkedHashMap (java.util.LinkedHashMap)8 HashSet (java.util.HashSet)6 XPair (catdata.fpql.XExp.XPair)5 Map (java.util.Map)4 Triple (catdata.Triple)3 Pair (org.jparsec.functors.Pair)3 Chc (catdata.Chc)2 RawTerm (catdata.aql.RawTerm)2 ColimSchExpRaw (catdata.aql.exp.ColimSchExp.ColimSchExpRaw)2 Delta (catdata.fql.decl.FullQueryExp.Delta)2 Pi (catdata.fql.decl.FullQueryExp.Pi)2 Sigma (catdata.fql.decl.FullQueryExp.Sigma)2 External (catdata.fql.decl.InstExp.External)2