Search in sources :

Example 1 with Opposite

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

Aggregations

Pair (catdata.Pair)1 Var (catdata.fql.decl.FullQueryExp.Var)1 MapExp (catdata.fql.decl.MapExp)1 Apply (catdata.fql.decl.MapExp.Apply)1 Case (catdata.fql.decl.MapExp.Case)1 Curry (catdata.fql.decl.MapExp.Curry)1 FF (catdata.fql.decl.MapExp.FF)1 Fst (catdata.fql.decl.MapExp.Fst)1 Id (catdata.fql.decl.MapExp.Id)1 Inl (catdata.fql.decl.MapExp.Inl)1 Inr (catdata.fql.decl.MapExp.Inr)1 Iso (catdata.fql.decl.MapExp.Iso)1 Opposite (catdata.fql.decl.MapExp.Opposite)1 Prod (catdata.fql.decl.MapExp.Prod)1 Snd (catdata.fql.decl.MapExp.Snd)1 Sub (catdata.fql.decl.MapExp.Sub)1 TT (catdata.fql.decl.MapExp.TT)1 TransCurry (catdata.fql.decl.TransExp.TransCurry)1 TransIso (catdata.fql.decl.TransExp.TransIso)1 Tuple3 (org.jparsec.functors.Tuple3)1