Search in sources :

Example 6 with Tuple5

use of org.jparsec.functors.Tuple5 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 Tuple5

use of org.jparsec.functors.Tuple5 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 Tuple5

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

the class OplParser method toCatConst.

public static XSchema toCatConst(Object y) {
    List<String> nodes = new LinkedList<>();
    List<Triple<String, String, String>> arrows = new LinkedList<>();
    List<Pair<List<String>, List<String>>> eqs = new LinkedList<>();
    Tuple3 s = (Tuple3) y;
    Tuple3 nodes0 = (Tuple3) s.a;
    Tuple3 arrows0 = (Tuple3) s.b;
    Tuple3 eqs0 = (Tuple3) s.c;
    List nodes1 = (List) nodes0.b;
    List arrows1 = (List) arrows0.b;
    List eqs1 = (List) eqs0.b;
    for (Object o : nodes1) {
        nodes.add((String) o);
    }
    for (Object o : arrows1) {
        Tuple5 x = (Tuple5) o;
        arrows.add(new Triple<>((String) x.a, (String) x.c, (String) x.e));
    }
    for (Object o : eqs1) {
        Tuple3 x = (Tuple3) o;
        List<String> l1 = (List<String>) x.a;
        List<String> l2 = (List<String>) x.c;
        eqs.add(new Pair<>(l1, l2));
    }
    XSchema c = new XSchema(nodes, arrows, eqs);
    return c;
}
Also used : LinkedList(java.util.LinkedList) Triple(catdata.Triple) Tuple5(org.jparsec.functors.Tuple5) XSchema(catdata.fpql.XExp.XSchema) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair)

Example 9 with Tuple5

use of org.jparsec.functors.Tuple5 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 Tuple5

use of org.jparsec.functors.Tuple5 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

Tuple5 (org.jparsec.functors.Tuple5)47 Tuple3 (org.jparsec.functors.Tuple3)41 Pair (catdata.Pair)36 LinkedList (java.util.LinkedList)36 List (java.util.List)36 HashMap (java.util.HashMap)21 Tuple4 (org.jparsec.functors.Tuple4)20 Triple (catdata.Triple)10 HashSet (java.util.HashSet)10 LinkedHashMap (java.util.LinkedHashMap)10 XPair (catdata.fpql.XExp.XPair)9 Map (java.util.Map)8 Set (java.util.Set)5 Apply (catdata.fqlpp.FunctorExp.Apply)4 Var (catdata.fqlpp.FunctorExp.Var)4 PeterApply (catdata.fqlpp.TransExp.PeterApply)4 Pair (org.jparsec.functors.Pair)4 XSchema (catdata.fpql.XExp.XSchema)3 Plus (catdata.fqlpp.CatExp.Plus)3 Program (catdata.Program)2