Search in sources :

Example 1 with Inl

use of catdata.fql.decl.MapExp.Inl in project fql by CategoricalData.

the class FQLParser method toMapping.

@SuppressWarnings({ "rawtypes", "unchecked" })
private static MapExp toMapping(Object o) {
    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(toSchema(p2), toSchema(p3));
        } else if (p1.equals("snd")) {
            return new Snd(toSchema(p2), toSchema(p3));
        } else if (p1.equals("unit")) {
            return new TT(toSchema(p3), new HashSet<>((Collection<String>) p2));
        } else if (p1.equals("subschema")) {
            return new Sub(toSchema(p2), toSchema(p3));
        } else if (p1.equals("inl")) {
            return new Inl(toSchema(p2), toSchema(p3));
        } else if (p1.equals("inr")) {
            return new Inr(toSchema(p2), toSchema(p3));
        } else if (p1.equals("iso1")) {
            return new Iso(true, toSchema(p2), toSchema(p3));
        } else if (p1.equals("iso2")) {
            return new Iso(false, toSchema(p2), toSchema(p3));
        } else if (p1.equals("eval")) {
            return new Apply(toSchema(p2), toSchema(p3));
        } else if (p2.toString().equals("then")) {
            return new MapExp.Comp(toMapping(o1), toMapping(p3));
        } else if (p2.toString().equals("*")) {
            return new Prod(toMapping(o1), toMapping(p3));
        } else if (p2.toString().equals("+")) {
            return new Case(toMapping(o1), toMapping(p3));
        }
    } catch (RuntimeException re) {
    }
    if (o instanceof Tuple5) {
        Tuple5 p = (Tuple5) o;
        Object p2 = p.c;
        Object p3 = p.e;
        Object o1 = p.a;
        return toMapConst(o1, toSchema(p2), toSchema(p3));
    }
    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(toSchema(p2));
            case "curry":
                return new Curry(toMapping(p2));
            case "void":
                return new FF(toSchema(p2));
            case "opposite":
                return new Opposite(toMapping(p2));
            default:
                break;
        }
    } catch (RuntimeException re) {
    }
    if (o instanceof String) {
        return new MapExp.Var(o.toString());
    }
    throw new RuntimeException("Cannot parse " + o);
}
Also used : TT(catdata.fql.decl.MapExp.TT) TransCurry(catdata.fql.decl.TransExp.TransCurry) Curry(catdata.fql.decl.MapExp.Curry) FF(catdata.fql.decl.MapExp.FF) Inl(catdata.fql.decl.MapExp.Inl) Apply(catdata.fql.decl.MapExp.Apply) Var(catdata.fql.decl.FullQueryExp.Var) Snd(catdata.fql.decl.MapExp.Snd) Inr(catdata.fql.decl.MapExp.Inr) Case(catdata.fql.decl.MapExp.Case) Prod(catdata.fql.decl.MapExp.Prod) Pair(catdata.Pair) Opposite(catdata.fql.decl.MapExp.Opposite) Sub(catdata.fql.decl.MapExp.Sub) TransIso(catdata.fql.decl.TransExp.TransIso) Iso(catdata.fql.decl.MapExp.Iso) Fst(catdata.fql.decl.MapExp.Fst) MapExp(catdata.fql.decl.MapExp) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) Id(catdata.fql.decl.MapExp.Id)

Example 2 with Inl

use of catdata.fql.decl.MapExp.Inl 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)

Aggregations

Pair (catdata.Pair)2 Var (catdata.fql.decl.FullQueryExp.Var)2 Case (catdata.fql.decl.MapExp.Case)2 FF (catdata.fql.decl.MapExp.FF)2 Fst (catdata.fql.decl.MapExp.Fst)2 Id (catdata.fql.decl.MapExp.Id)2 Inl (catdata.fql.decl.MapExp.Inl)2 Inr (catdata.fql.decl.MapExp.Inr)2 Prod (catdata.fql.decl.MapExp.Prod)2 TransCurry (catdata.fql.decl.TransExp.TransCurry)2 TransIso (catdata.fql.decl.TransExp.TransIso)2 Tuple3 (org.jparsec.functors.Tuple3)2 Tuple5 (org.jparsec.functors.Tuple5)2 Delta (catdata.fql.decl.FullQueryExp.Delta)1 Pi (catdata.fql.decl.FullQueryExp.Pi)1 Sigma (catdata.fql.decl.FullQueryExp.Sigma)1 External (catdata.fql.decl.InstExp.External)1 FullSigma (catdata.fql.decl.InstExp.FullSigma)1 Relationalize (catdata.fql.decl.InstExp.Relationalize)1 MapExp (catdata.fql.decl.MapExp)1