Search in sources :

Example 26 with Tuple5

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

the class PPParser method toFtr.

private static FunctorExp toFtr(Object o) {
    try {
        Tuple5 p = (Tuple5) o;
        if (p.a.toString().equals("apply")) {
            FunctorExp f = toFtr(p.b);
            FunctorExp e = toFtr(p.e);
            return new Apply(f, e);
        }
        if (p.e.toString().equals("Set")) {
            return p.c.toString().equals("Set") ? toSetSet(o) : toInstConst(o);
        } else if (p.e.toString().equals("Cat")) {
            return toCatFtrConst(o);
        } else {
            if (p.e instanceof Tuple3) {
                Tuple3 t = (Tuple3) p.e;
                if ((t.a.toString().equals("Cat") || t.a.toString().equals("Set")) && t.b.toString().equals("^")) {
                    return toFinalConst(o);
                } else {
                    throw new RuntimeException();
                }
            }
            return toMapConst(o);
        }
    } catch (Exception e) {
    }
    try {
        Tuple3 p = (Tuple3) o;
        Object p2 = p.b;
        Object p3 = p.c;
        Object o1 = p.a;
        String p1 = p.a.toString();
        if (p1.equals("fst")) {
            return new Fst(toCat(p2), toCat(p3));
        } else if (p1.equals("snd")) {
            return new Snd(toCat(p2), toCat(p3));
        } else if (p1.equals("inl")) {
            return new Inl(toCat(p2), toCat(p3));
        } else if (p1.equals("inr")) {
            return new Inr(toCat(p2), toCat(p3));
        } else if (p1.equals("iso1")) {
            return new Iso(true, toCat(p2), toCat(p3));
        } else if (p1.equals("iso2")) {
            return new Iso(false, toCat(p2), toCat(p3));
        } else if (p1.equals("eval")) {
            return new Eval(toCat(p2), toCat(p3));
        } else if (p2.toString().equals(";")) {
            return new Comp(toFtr(o1), toFtr(p3));
        } else if (p2.toString().equals("*")) {
            return new Prod(toFtr(o1), toFtr(p3));
        } else if (p2.toString().equals("+")) {
            return new Case(toFtr(o1), toFtr(p3));
        } else if (p2.toString().equals("^")) {
            return new Exp(toFtr(o1), toFtr(p3));
        } else if (p1.equals("unit")) {
            return new One(toCat(p.b), toCat(p.c));
        } else if (p1.equals("void")) {
            return new Zero(toCat(p.b), toCat(p.c));
        } else if (p1.equals("pushout")) {
            return new Pushout(p.b.toString(), p.c.toString());
        }
    } catch (RuntimeException re) {
    }
    try {
        org.jparsec.functors.Pair p = (org.jparsec.functors.Pair) o;
        String p1 = p.a.toString();
        Object p2 = p.b;
        switch(p1) {
            case "id":
                return new Id(toCat(p2));
            case "prop":
                return new Prop(toCat(p2));
            case "curry":
                return new Curry(toFtr(p2));
            case "uncurry":
                return new Uncurry(toFtr(p2));
            case "delta":
            case "sigma":
            case "pi":
                return new Migrate(toFtr(p2), p1);
            case "ff":
                return new FF(toCat(p2));
            case "tt":
                return new TT(toCat(p2));
            case "dom":
                return new Dom(p2.toString(), true);
            case "cod":
                return new Dom(p2.toString(), false);
            case "pivot":
                return new Pivot(toFtr(p2), true);
            case "unpivot":
                return new Pivot(toFtr(p2), false);
            default:
                break;
        }
    } catch (RuntimeException re) {
    }
    if (o instanceof String) {
        return new Var(o.toString());
    }
    throw new RuntimeException("Bad: " + o);
}
Also used : Curry(catdata.fqlpp.FunctorExp.Curry) FF(catdata.fqlpp.FunctorExp.FF) TT(catdata.fqlpp.FunctorExp.TT) PeterApply(catdata.fqlpp.TransExp.PeterApply) Apply(catdata.fqlpp.FunctorExp.Apply) Inl(catdata.fqlpp.FunctorExp.Inl) Migrate(catdata.fqlpp.FunctorExp.Migrate) Var(catdata.fqlpp.FunctorExp.Var) One(catdata.fqlpp.FunctorExp.One) Snd(catdata.fqlpp.FunctorExp.Snd) Pushout(catdata.fqlpp.FunctorExp.Pushout) Inr(catdata.fqlpp.FunctorExp.Inr) Comp(catdata.fqlpp.FunctorExp.Comp) Case(catdata.fqlpp.FunctorExp.Case) Prod(catdata.fqlpp.FunctorExp.Prod) CoProd(catdata.fqlpp.TransExp.CoProd) Eval(catdata.fqlpp.FunctorExp.Eval) Pair(catdata.Pair) Zero(catdata.fqlpp.FunctorExp.Zero) Dom(catdata.fqlpp.FunctorExp.Dom) Iso(catdata.fqlpp.FunctorExp.Iso) Prop(catdata.fqlpp.FunctorExp.Prop) Fst(catdata.fqlpp.FunctorExp.Fst) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) Pivot(catdata.fqlpp.FunctorExp.Pivot) Id(catdata.fqlpp.FunctorExp.Id) Exp(catdata.fqlpp.FunctorExp.Exp) Uncurry(catdata.fqlpp.FunctorExp.Uncurry)

Example 27 with Tuple5

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

the class PPParser method toCatFtrConst.

private static FunctorExp toCatFtrConst(Object decl) {
    Tuple5 y = (Tuple5) decl;
    org.jparsec.functors.Pair x = (org.jparsec.functors.Pair) y.a;
    Tuple3 nodes = (Tuple3) x.a;
    Tuple3 arrows = (Tuple3) x.b;
    List nodes0 = (List) nodes.b;
    List arrows0 = (List) arrows.b;
    Map<String, CatExp> nodesX = new HashMap<>();
    for (Object o : nodes0) {
        if (nodesX.containsKey(o)) {
            throw new RuntimeException("Duplicate object: " + o + " in " + decl);
        }
        Tuple3 u = (Tuple3) o;
        String n = (String) u.a;
        CatExp l = toCat(u.c);
        nodesX.put(n, l);
    }
    Map<String, FunctorExp> arrowsX = new HashMap<>();
    for (Object o : arrows0) {
        if (arrowsX.containsKey(o)) {
            throw new RuntimeException("Duplicate arrow: " + o + " in " + decl);
        }
        Tuple3 u = (Tuple3) o;
        String n = (String) u.a;
        FunctorExp l = toFtr(u.c);
        arrowsX.put(n, l);
    }
    CatConst ret = new CatConst(toCat(y.c), nodesX, arrowsX);
    return ret;
}
Also used : HashMap(java.util.HashMap) CatConst(catdata.fqlpp.FunctorExp.CatConst) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair)

Example 28 with Tuple5

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

the class PPParser method toCatConst.

public static CatExp.Const toCatConst(Object y) {
    Set<String> nodes = new HashSet<>();
    Set<Triple<String, String, String>> arrows = new HashSet<>();
    Set<Pair<Pair<String, List<String>>, Pair<String, List<String>>>> eqs = new HashSet<>();
    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;
        String xxx = l1.remove(0);
        String yyy = l2.remove(0);
        eqs.add(new Pair<>(new Pair<>(xxx, l1), new Pair<>(yyy, l2)));
    }
    CatExp.Const c = new CatExp.Const(nodes, arrows, eqs);
    return c;
}
Also used : Const(catdata.fqlpp.FnExp.Const) CatConst(catdata.fqlpp.FunctorExp.CatConst) SetSetConst(catdata.fqlpp.FunctorExp.SetSetConst) InstConst(catdata.fqlpp.FunctorExp.InstConst) MapConst(catdata.fqlpp.FunctorExp.MapConst) FinalConst(catdata.fqlpp.FunctorExp.FinalConst) Triple(catdata.Triple) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet) Pair(catdata.Pair)

Example 29 with Tuple5

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

the class OplParser method toTrans_2.

private static OplExp toTrans_2(Object c) {
    Tuple3 t = (Tuple3) c;
    if (!t.a.toString().equals("transpres")) {
        throw new RuntimeException();
    }
    Map<String, Map<String, OplTerm>> map = new HashMap<>();
    org.jparsec.functors.Pair q = (org.jparsec.functors.Pair) t.b;
    List<String> imports = q.a == null ? new LinkedList<>() : (List<String>) ((org.jparsec.functors.Pair) q.a).b;
    Tuple3 tb = (Tuple3) q.b;
    List<Tuple5> l = (List<Tuple5>) tb.b;
    for (Tuple5 x : l) {
        String name = (String) x.a;
        List<Tuple5> y = (List<Tuple5>) x.d;
        Map<String, OplTerm> m = new HashMap<>();
        for (Tuple5 z : y) {
            String xx = (String) z.b;
            // OplTerm yy = toTermNoVars(z.d);
            OplTerm yy = toTerm(new HashSet<>(), new HashSet<>(), z.d, false);
            if (m.containsKey(xx)) {
                throw new DoNotIgnore("Duplicate argument: " + xx);
            }
            m.put(xx, yy);
        }
        if (map.containsKey(name)) {
            throw new DoNotIgnore("Duplicate sort: " + name);
        }
        map.put(name, m);
    }
    Tuple4 tc = (Tuple4) t.c;
    OplPresTrans ret = new OplPresTrans(map, (String) tc.b, (String) tc.d);
    ret.imports = new HashSet<>(imports);
    return ret;
}
Also used : OplPresTrans(catdata.opl.OplExp.OplPresTrans) HashMap(java.util.HashMap) 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) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Pair(catdata.Pair)

Example 30 with Tuple5

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

the class OplParser method toModel2.

private static OplExp toModel2(Object o) {
    if (!o.toString().contains("tables")) {
        throw new RuntimeException();
    }
    Tuple3 t = (Tuple3) o;
    Tuple3 b = (Tuple3) t.b;
    org.jparsec.functors.Pair c = (org.jparsec.functors.Pair) t.c;
    Tuple3 y = (Tuple3) b.a;
    List<Tuple3> sorts = (List<Tuple3>) y.b;
    Map<String, List<String>> sorts0 = new HashMap<>();
    for (Tuple3 x : sorts) {
        String s = x.a.toString();
        List<String> s0 = (List<String>) x.c;
        if (sorts0.containsKey(s)) {
            throw new DoNotIgnore("Duplicate sort: " + s);
        }
        sorts0.put(s, s0);
    }
    Map<String, Map<String, String>> symbols0 = new HashMap<>();
    Tuple3 z = (Tuple3) b.b;
    List<Tuple3> q = (List<Tuple3>) z.b;
    Tuple3 z0 = (Tuple3) b.c;
    q.addAll((Collection<? extends Tuple3>) z0.b);
    for (Tuple3 r : q) {
        List<Tuple5> u = (List<Tuple5>) r.c;
        String fname = (String) r.a;
        if (symbols0.containsKey(fname)) {
            throw new DoNotIgnore("Duplicate symbol " + fname);
        }
        Map<String, String> toadd = new HashMap<>();
        for (Tuple5 e : u) {
            String args = (String) e.b;
            String ret = (String) e.d;
            if (toadd.containsKey(args)) {
                throw new DoNotIgnore("Duplicate argument at " + args);
            }
            toadd.put(args, ret);
        }
        symbols0.put(fname, toadd);
    }
    return new OplGround(sorts0, symbols0, c.b.toString());
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) OplGround(catdata.opl.OplExp.OplGround) List(java.util.List) LinkedList(java.util.LinkedList) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Pair(catdata.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