Search in sources :

Example 21 with Tuple5

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

the class FQLParser method toTransConst.

@SuppressWarnings({ "rawtypes" })
private static TransExp toTransConst(Object decl, String t1, String t2) {
    List<Pair<String, List<Pair<Object, Object>>>> objs = new LinkedList<>();
    Tuple3 a0 = (Tuple3) decl;
    List b0 = (List) a0.b;
    for (Object o : b0) {
        Tuple3 z = (Tuple3) o;
        String p = (String) z.a;
        List<?> q = (List<?>) z.c;
        List<Pair<Object, Object>> l = new LinkedList<>();
        for (Object q0 : q) {
            Tuple5 q1 = (Tuple5) q0;
            l.add(new Pair<>(q1.b, q1.d));
        }
        objs.add(new Pair<>(p, l));
    }
    return new TransExp.Const(objs, t1, t2);
}
Also used : Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) Const(catdata.fql.decl.SigExp.Const) Pair(catdata.Pair)

Example 22 with Tuple5

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

the class FQLParser method toTrans.

@SuppressWarnings("rawtypes")
private static TransExp toTrans(Object o) {
    try {
        Tuple4 p = (Tuple4) o;
        String src = p.b.toString();
        String dst = p.c.toString();
        TransExp h = toTrans(p.d);
        String kind = p.a.toString();
        switch(kind) {
            case "delta":
                return new TransExp.Delta(h, src, dst);
            case "pi":
                return new TransExp.Pi(h, src, dst);
            case "sigma":
                return new TransExp.Sigma(h, src, dst);
            case "relationalize":
                return new TransExp.Relationalize(h, src, dst);
            default:
                throw new RuntimeException(o.toString());
        }
    } catch (RuntimeException ex) {
    }
    try {
        Tuple4 p = (Tuple4) o;
        String src = p.b.toString();
        String dst = p.c.toString();
        String name = p.d.toString();
        String kind = p.a.toString();
        switch(kind) {
            case "external":
                return new TransExp.External(src, dst, name);
            case "SIGMA":
                return new TransExp.FullSigma(name, src, dst);
            default:
                throw new RuntimeException(o.toString());
        }
    } catch (RuntimeException ex) {
    }
    try {
        Tuple4 p = (Tuple4) o;
        String obj = p.a.toString();
        String dst = p.d.toString();
        if (p.c.toString().equals("void")) {
            return new TransExp.FF(obj, dst);
        } else if (p.c.toString().equals("unit")) {
            return new TransExp.TT(obj, dst);
        } else if (p.c.toString().equals("curry")) {
            return new TransCurry(obj, dst);
        } else if (p.c.toString().equals("true")) {
            return new Bool(true, dst, obj);
        } else if (p.c.toString().equals("false")) {
            return new Bool(false, dst, obj);
        } else if (p.c.toString().equals("char")) {
            return new Chi(obj, dst);
        }
    } catch (RuntimeException re) {
    }
    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("iso1")) {
            return new TransIso(true, p2.toString(), p3.toString());
        } else if (p1.equals("iso2")) {
            return new TransIso(false, p2.toString(), p3.toString());
        } else if (p3.toString().equals("fst")) {
            return new TransExp.Fst(p1);
        } else if (p3.toString().equals("not")) {
            return new Not(p1);
        } else if (p3.toString().equals("and")) {
            return new And(p1);
        } else if (p3.toString().equals("or")) {
            return new Or(p1);
        } else if (p3.toString().equals("implies")) {
            return new Implies(p1);
        } else if (p3.toString().equals("eval")) {
            return new TransEval(p1);
        } else if (p3.toString().equals("relationalize")) {
            return new Squash(p1);
        } else if (p3.toString().equals("snd")) {
            return new TransExp.Snd(p1);
        } else if (p3.toString().equals("return")) {
            return new Return(p1);
        } else if (p3.toString().equals("coreturn")) {
            return new Coreturn(p1);
        } else if (p3.toString().equals("inl")) {
            return new TransExp.Inl(p1);
        } else if (p3.toString().equals("kernel")) {
            return new UnChi(p1);
        } else if (p3.toString().equals("inr")) {
            return new TransExp.Inr(p1);
        } else if (p2.toString().equals("then")) {
            return new TransExp.Comp(toTrans(o1), toTrans(p3));
        } else if (p3 instanceof Tuple3) {
            Tuple3 y = (Tuple3) p3;
            String x = y.b.toString();
            switch(x) {
                case "+":
                    return new TransExp.Case(p1, toTrans(y.a), toTrans(y.c));
                case "*":
                    return new TransExp.Prod(p1, toTrans(y.a), toTrans(y.c));
                // return new TransExp.(p1, toTrans(y.a), toTrans(y.c));
                default:
                    throw new RuntimeException("foo");
            }
        }
    } catch (RuntimeException re) {
    }
    try {
        Tuple5 p = (Tuple5) o;
        Object p2 = p.c;
        Object p3 = p.e;
        Object o1 = p.a;
        return toTransConst(o1, p2.toString(), p3.toString());
    } catch (RuntimeException re) {
    }
    try {
        org.jparsec.functors.Pair p = (org.jparsec.functors.Pair) o;
        String p1 = p.a.toString();
        Object p2 = p.b;
        if (p1.equals("id")) {
            return new TransExp.Id(p2.toString());
        }
    } catch (RuntimeException re) {
    }
    if (o instanceof String) {
        return new TransExp.Var(o.toString());
    }
    throw new RuntimeException();
}
Also used : FF(catdata.fql.decl.MapExp.FF) Or(catdata.fql.decl.TransExp.Or) Chi(catdata.fql.decl.TransExp.Chi) UnChi(catdata.fql.decl.TransExp.UnChi) Inl(catdata.fql.decl.MapExp.Inl) Var(catdata.fql.decl.FullQueryExp.Var) TransExp(catdata.fql.decl.TransExp) Sigma(catdata.fql.decl.FullQueryExp.Sigma) FullSigma(catdata.fql.decl.InstExp.FullSigma) UnChi(catdata.fql.decl.TransExp.UnChi) Inr(catdata.fql.decl.MapExp.Inr) Squash(catdata.fql.decl.TransExp.Squash) Case(catdata.fql.decl.MapExp.Case) Prod(catdata.fql.decl.MapExp.Prod) Implies(catdata.fql.decl.TransExp.Implies) Bool(catdata.fql.decl.TransExp.Bool) Pi(catdata.fql.decl.FullQueryExp.Pi) Pair(catdata.Pair) Relationalize(catdata.fql.decl.InstExp.Relationalize) Return(catdata.fql.decl.TransExp.Return) TransEval(catdata.fql.decl.TransExp.TransEval) Fst(catdata.fql.decl.MapExp.Fst) TransCurry(catdata.fql.decl.TransExp.TransCurry) Coreturn(catdata.fql.decl.TransExp.Coreturn) TransIso(catdata.fql.decl.TransExp.TransIso) Tuple4(org.jparsec.functors.Tuple4) Tuple5(org.jparsec.functors.Tuple5) Not(catdata.fql.decl.TransExp.Not) Delta(catdata.fql.decl.FullQueryExp.Delta) And(catdata.fql.decl.TransExp.And) Tuple3(org.jparsec.functors.Tuple3) External(catdata.fql.decl.InstExp.External) FullSigma(catdata.fql.decl.InstExp.FullSigma) Id(catdata.fql.decl.MapExp.Id)

Example 23 with Tuple5

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

the class PPParser method toTrans.

// : ** notation
private static TransExp toTrans(Object o) {
    try {
        Tuple5 t = (Tuple5) o;
        if (t.a.toString().equals("apply")) {
            FunctorExp f = toFtr(t.b);
            if (t.d.toString().equals("arrow")) {
                TransExp e = toTrans(t.e);
                return new TransExp.Apply(f, e);
            } else {
                Tuple3 t3 = (Tuple3) t.e;
                List<String> l = (List<String>) t3.a;
                return new ApplyPath(f, l.remove(0), l, toCat(t3.c));
            }
        }
        Tuple5 a = (Tuple5) t.c;
        Tuple5 b = (Tuple5) t.e;
        if (a.c.toString().equals("Set") && a.e.toString().equals("Set") && b.c.toString().equals("Set") && b.e.toString().equals("Set")) {
            Tuple3 z = (Tuple3) ((org.jparsec.functors.Pair) t.a).b;
            FunctorExp src = toFtr(a.a);
            FunctorExp dst = toFtr(b.a);
            String ob = z.a.toString();
            FnExp fun = toFn(z.c);
            return new SetSet(ob, fun, src, dst);
        } else if (a.e.toString().equals("Set") && b.e.toString().equals("Set")) {
            FunctorExp src = toFtr(a.a);
            FunctorExp dst = toFtr(b.a);
            List<Object> ob = (List<Object>) ((org.jparsec.functors.Pair) t.a).b;
            Map<String, Chc<FnExp, SetExp>> fun = new HashMap<>();
            for (Object ttt : ob) {
                if (fun.containsKey(o)) {
                    throw new RuntimeException("Duplicate arrow: " + ttt + " in " + o);
                }
                Tuple3 u = (Tuple3) ttt;
                String n = (String) u.a;
                try {
                    fun.put(n, Chc.inLeft(toFn(u.c)));
                } catch (Exception yyy) {
                    fun.put(n, Chc.inRight(toSet(u.c)));
                }
            }
            return new ToSet(fun, src, dst);
        } else if (a.e.toString().equals("Cat") && b.e.toString().equals("Cat")) {
            FunctorExp src = toFtr(a.a);
            FunctorExp dst = toFtr(b.a);
            List<Object> ob = (List<Object>) ((org.jparsec.functors.Pair) t.a).b;
            Map<String, FunctorExp> fun = new HashMap<>();
            for (Object ttt : ob) {
                if (fun.containsKey(o)) {
                    throw new RuntimeException("Duplicate arrow: " + ttt + " in " + o);
                }
                Tuple3 u = (Tuple3) ttt;
                String n = (String) u.a;
                fun.put(n, toFtr(u.c));
            }
            return new ToCat(fun, src, dst);
        } else {
            try {
                FunctorExp src = toFtr(a.a);
                FunctorExp dst = toFtr(b.a);
                List<Object> ob = (List<Object>) ((org.jparsec.functors.Pair) t.a).b;
                Map<String, TransExp> fun = new HashMap<>();
                for (Object ttt : ob) {
                    if (fun.containsKey(o)) {
                        throw new RuntimeException("Duplicate arrow: " + ttt + " in " + o);
                    }
                    Tuple3 u = (Tuple3) ttt;
                    String n = (String) u.a;
                    fun.put(n, toTrans(u.c));
                }
                return new ToInst(fun, src, dst);
            } catch (Exception ex) {
            }
            FunctorExp src = toFtr(a.a);
            FunctorExp dst = toFtr(b.a);
            List<Object> ob = (List<Object>) ((org.jparsec.functors.Pair) t.a).b;
            Map<String, Pair<String, List<String>>> fun = new HashMap<>();
            for (Object ttt : ob) {
                if (fun.containsKey(o)) {
                    throw new RuntimeException("Duplicate arrow: " + ttt + " in " + o);
                }
                Tuple3 u = (Tuple3) ttt;
                String n = (String) u.a;
                List<String> l = (List<String>) u.c;
                String ll = l.remove(0);
                fun.put(n, new Pair<>(ll, l));
            }
            return new ToMap(fun, src, dst, toCat(a.c), toCat(a.e));
        }
    } catch (Exception re) {
    }
    try {
        Tuple4 t = (Tuple4) o;
        if (t.a.toString().equals("return") || t.a.toString().equals("coreturn")) {
            return new Adj(t.a.toString(), t.b.toString(), t.c.toString(), toFtr(t.d));
        } else if (t.a.toString().equals("left")) {
            return new Whisker(true, toFtr(t.c), toTrans(t.d));
        } else if (t.a.toString().equals("right")) {
            return new Whisker(false, toFtr(t.c), toTrans(t.d));
        } else if (t.a.toString().equals("APPLY")) {
            return new PeterApply(t.d.toString(), toTrans(t.b));
        } else {
            return new ApplyTrans(toTrans(t.b), toFtr(t.d));
        }
    } catch (Exception re) {
    }
    try {
        Tuple3 p = (Tuple3) o;
        Object p2 = p.b;
        Object p3 = p.c;
        Object o1 = p.a;
        if (p2.toString().equals(";")) {
            return new TransExp.Comp(toTrans(o1), toTrans(p3));
        } else if (o1.toString().equals("fst")) {
            return new Proj(toFtr(p2), toFtr(p3), true);
        } else if (o1.toString().equals("snd")) {
            return new Proj(toFtr(p2), toFtr(p3), false);
        } else if (o1.toString().equals("inl")) {
            return new Inj(toFtr(p2), toFtr(p3), true);
        } else if (o1.toString().equals("inr")) {
            return new Inj(toFtr(p2), toFtr(p3), false);
        } else if (o1.toString().equals("eval")) {
            return new TransExp.Eval(toFtr(p2), toFtr(p3));
        } else if (p2.toString().equals("*")) {
            return new TransExp.Prod(toTrans(o1), toTrans(p3));
        } else if (p2.toString().equals("+")) {
            return new CoProd(toTrans(o1), toTrans(p3));
        } else if (o1.toString().equals("iso1")) {
            return new TransExp.Iso(true, toFtr(p2), toFtr(p3));
        } else if (o1.toString().equals("iso2")) {
            return new TransExp.Iso(false, toFtr(p2), toFtr(p3));
        }
    } 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 TransExp.Id(toFtr(p2));
            case "tt":
                return new TransExp.One(toFtr(p2));
            case "ff":
                return new TransExp.Zero(toFtr(p2));
            case "curry":
                return new TransExp.Curry(toTrans(p2), true);
            case "CURRY":
                return new TransExp.Curry(toTrans(p2), false);
            case "true":
                return new Bool(true, toCat(p2));
            case "false":
                return new Bool(false, toCat(p2));
            case "char":
                return new Chr(toTrans(p2));
            case "kernel":
                return new Ker(toTrans(p2));
            case "not":
            case "and":
            case "implies":
            case "or":
                return new AndOrNotImplies(p1, toCat(p2));
            default:
                break;
        }
    } catch (RuntimeException re) {
    }
    if (o instanceof String) {
        return new TransExp.Var(o.toString());
    }
    throw new RuntimeException("Could not create transform from " + o);
}
Also used : Curry(catdata.fqlpp.FunctorExp.Curry) HashMap(java.util.HashMap) PeterApply(catdata.fqlpp.TransExp.PeterApply) Apply(catdata.fqlpp.FunctorExp.Apply) Adj(catdata.fqlpp.TransExp.Adj) Var(catdata.fqlpp.FunctorExp.Var) Chr(catdata.fqlpp.TransExp.Chr) AndOrNotImplies(catdata.fqlpp.TransExp.AndOrNotImplies) Comp(catdata.fqlpp.FunctorExp.Comp) ToMap(catdata.fqlpp.TransExp.ToMap) ToSet(catdata.fqlpp.TransExp.ToSet) CoProd(catdata.fqlpp.TransExp.CoProd) Bool(catdata.fqlpp.TransExp.Bool) ToInst(catdata.fqlpp.TransExp.ToInst) List(java.util.List) LinkedList(java.util.LinkedList) SetSet(catdata.fqlpp.TransExp.SetSet) ApplyPath(catdata.fqlpp.TransExp.ApplyPath) Whisker(catdata.fqlpp.TransExp.Whisker) Ker(catdata.fqlpp.TransExp.Ker) Id(catdata.fqlpp.FunctorExp.Id) Map(java.util.Map) ToMap(catdata.fqlpp.TransExp.ToMap) HashMap(java.util.HashMap) PeterApply(catdata.fqlpp.TransExp.PeterApply) Inj(catdata.fqlpp.TransExp.Inj) One(catdata.fqlpp.FunctorExp.One) Prod(catdata.fqlpp.FunctorExp.Prod) CoProd(catdata.fqlpp.TransExp.CoProd) Proj(catdata.fqlpp.TransExp.Proj) Pair(catdata.Pair) Zero(catdata.fqlpp.FunctorExp.Zero) Iso(catdata.fqlpp.FunctorExp.Iso) ToCat(catdata.fqlpp.TransExp.ToCat) Tuple4(org.jparsec.functors.Tuple4) ApplyTrans(catdata.fqlpp.TransExp.ApplyTrans) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3)

Example 24 with Tuple5

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

the class PPParser method toMapConst.

private static FunctorExp toMapConst(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, String> 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;
        String l = u.c.toString();
        nodesX.put(n, l);
    }
    Map<String, Pair<String, List<String>>> 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;
        List<String> l = (List<String>) u.c;
        String ll = l.remove(0);
        arrowsX.put(n, new Pair<>(ll, l));
    }
    MapConst ret = new MapConst(toCat(y.c), toCat(y.e), nodesX, arrowsX);
    return ret;
}
Also used : HashMap(java.util.HashMap) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) MapConst(catdata.fqlpp.FunctorExp.MapConst) Pair(catdata.Pair)

Example 25 with Tuple5

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

the class PPParser method toSetSet.

private static FunctorExp toSetSet(Object decl) {
    Tuple3 y = (Tuple3) decl;
    org.jparsec.functors.Pair x = (org.jparsec.functors.Pair) y.a;
    Tuple3 nodes = (Tuple3) x.a;
    Tuple3 arrows = (Tuple3) x.b;
    Tuple3 nodes0 = (Tuple3) nodes.b;
    Tuple3 arrows0 = (Tuple3) arrows.b;
    Tuple5 arrows1 = (Tuple5) arrows0.a;
    SetSetConst ret = new SetSetConst(nodes0.a.toString(), toSet(nodes0.c), arrows1.a.toString(), arrows1.c.toString(), arrows1.e.toString(), toFn(arrows0.c));
    return ret;
}
Also used : Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) SetSetConst(catdata.fqlpp.FunctorExp.SetSetConst) 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