Search in sources :

Example 41 with Tuple3

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

the class FQLParser method toSchemaConst.

@SuppressWarnings({ "rawtypes", "unchecked" })
private static SigExp toSchemaConst(Object y) {
    List<String> nodes = new LinkedList<>();
    List<Triple<String, String, String>> attrs = new LinkedList<>();
    List<Triple<String, String, String>> arrows = new LinkedList<>();
    List<Pair<List<String>, List<String>>> eqs = new LinkedList<>();
    Tuple4 s = (Tuple4) y;
    Tuple3 nodes0 = (Tuple3) s.a;
    Tuple3 attrs0 = (Tuple3) s.b;
    Tuple3 arrows0 = (Tuple3) s.c;
    Tuple3 eqs0 = (Tuple3) s.d;
    List nodes1 = (List) nodes0.b;
    List arrows1 = (List) arrows0.b;
    List eqs1 = (List) eqs0.b;
    for (Object o : nodes1) {
        nodes.add((String) o);
    }
    if (attrs0.b.toString().equals("ASWRITTEN")) {
        for (String k : nodes) {
            attrs.add(new Triple<>(k + "_att", k, "string"));
        }
    } else {
        List attrs1 = (List) attrs0.b;
        for (Object o : attrs1) {
            Tuple5 x = (Tuple5) o;
            attrs.add(new Triple<>((String) x.a, (String) x.c, (String) x.e));
        }
    }
    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;
        eqs.add(new Pair<>((List<String>) x.a, (List<String>) x.c));
    }
    Const c = new Const(nodes, attrs, arrows, eqs);
    return c;
}
Also used : Const(catdata.fql.decl.SigExp.Const) Triple(catdata.Triple) Tuple4(org.jparsec.functors.Tuple4) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) Pair(catdata.Pair)

Example 42 with Tuple3

use of org.jparsec.functors.Tuple3 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 43 with Tuple3

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

the class FQLParser method program.

@SuppressWarnings({ "rawtypes", "unchecked" })
public static FQLProgram program(String s) {
    List<NewDecl> ret = new LinkedList<>();
    List decls = (List) program.parse(s);
    for (Object d : decls) {
        org.jparsec.functors.Pair pr = (org.jparsec.functors.Pair) d;
        Object decl = pr.b;
        String txt = pr.a.toString();
        int idx = s.indexOf(txt);
        if (idx < 0) {
            throw new RuntimeException();
        }
        if (decl instanceof org.jparsec.functors.Pair) {
            org.jparsec.functors.Pair p = (org.jparsec.functors.Pair) decl;
            if (p.a.toString().equals("drop")) {
                ret.add(NewDecl.dropDecl((List<String>) p.b));
                continue;
            }
        }
        Tuple3 t = (Tuple3) decl;
        String kind = t.a.toString();
        switch(kind) {
            case "enum":
                Tuple4 tte = (Tuple4) decl;
                String name = (String) tte.b;
                List<String> values = (List<String>) tte.d;
                ret.add(NewDecl.typeDecl(name, values, idx));
                break;
            case "query":
                Tuple4 tta = (Tuple4) decl;
                name = (String) tta.b;
                ret.add(NewDecl.queryDecl(name, idx, toQuery(tta.d)));
                break;
            case "QUERY":
                tta = (Tuple4) decl;
                name = (String) tta.b;
                ret.add(NewDecl.fullQuery(name, toFullQuery(tta.d), idx));
                break;
            case "schema":
                Tuple4 tt = (Tuple4) decl;
                name = (String) tt.b;
                ret.add(NewDecl.sigDecl(name, idx, toSchema(tt.d)));
                break;
            case "instance":
                Tuple4 tt0 = (Tuple4) decl;
                name = (String) t.b;
                NewDecl toAdd = NewDecl.instDecl(name, idx, toInst(tt0.d));
                ret.add(toAdd);
                break;
            case "mapping":
                Tuple4 t0 = (Tuple4) decl;
                name = (String) t.b;
                ret.add(NewDecl.mapDecl(name, idx, toMapping(t0.d)));
                break;
            case "transform":
                Tuple4 tx = (Tuple4) decl;
                name = (String) tx.b;
                ret.add(NewDecl.transDecl(name, idx, toTrans(tx.d)));
                break;
            default:
                throw new RuntimeException("Unknown decl: " + kind);
        }
    }
    return new FQLProgram(ret);
}
Also used : NewDecl(catdata.fql.decl.FQLProgram.NewDecl) Tuple4(org.jparsec.functors.Tuple4) Tuple3(org.jparsec.functors.Tuple3) FQLProgram(catdata.fql.decl.FQLProgram) Pair(catdata.Pair)

Example 44 with Tuple3

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

the class FQLParser method toInst.

@SuppressWarnings("rawtypes")
private static InstExp toInst(Object o) {
    try {
        Tuple4 t = (Tuple4) o;
        Token z = (Token) t.a;
        String y = z.toString();
        if (y.equals("step")) {
            return new Step(t.d.toString(), toMapping(t.b), toMapping(t.c));
        }
    } catch (RuntimeException cce) {
    }
    try {
        Tuple3 t = (Tuple3) o;
        Token z = (Token) t.a;
        String y = z.toString();
        switch(y) {
            case "delta":
                return new InstExp.Delta(toMapping(t.b), t.c.toString());
            case "sigma":
                return new InstExp.Sigma(toMapping(t.b), t.c.toString());
            case "SIGMA":
                return new FullSigma(toMapping(t.b), t.c.toString());
            case "pi":
                return new InstExp.Pi(toMapping(t.b), t.c.toString());
            case "external":
                return new External(toSchema(t.b), t.c.toString());
            case "eval":
                return new Eval(toQuery(t.b), t.c.toString());
            case "EVAL":
                return new FullEval(toFullQuery(t.b), t.c.toString());
            default:
                break;
        }
    } catch (RuntimeException cce) {
    }
    try {
        Tuple3 t = (Tuple3) o;
        Token z = (Token) t.b;
        String y = z.toString();
        if (y.equals("+")) {
            return new Plus(t.a.toString(), t.c.toString());
        } else if (y.equals("*")) {
            return new Times(t.a.toString(), t.c.toString());
        }
        if (y.equals("^")) {
            return new Exp(t.a.toString(), (t.c).toString());
        }
    } catch (RuntimeException cce) {
    }
    try {
        org.jparsec.functors.Pair pr = (org.jparsec.functors.Pair) o;
        if (pr.a.toString().equals("unit")) {
            return new One(toSchema(pr.b));
        } else if (pr.a.toString().equals("void")) {
            return new Zero(toSchema(pr.b));
        } else if (pr.a.toString().equals("prop")) {
            return new Two(toSchema(pr.b));
        } else if (pr.a.toString().equals("relationalize")) {
            return new Relationalize(pr.b.toString());
        } else if (pr.a.toString().equals("kernel")) {
            return new Kernel(pr.b.toString());
        }
        throw new RuntimeException();
    } catch (RuntimeException cce) {
    }
    return toInstConst(o);
}
Also used : FullEval(catdata.fql.decl.InstExp.FullEval) Sigma(catdata.fql.decl.FullQueryExp.Sigma) FullSigma(catdata.fql.decl.InstExp.FullSigma) One(catdata.fql.decl.InstExp.One) Token(org.jparsec.Token) Step(catdata.fql.decl.InstExp.Step) Pi(catdata.fql.decl.FullQueryExp.Pi) Plus(catdata.fql.decl.InstExp.Plus) TransEval(catdata.fql.decl.TransExp.TransEval) FullEval(catdata.fql.decl.InstExp.FullEval) Eval(catdata.fql.decl.InstExp.Eval) Kernel(catdata.fql.decl.InstExp.Kernel) Pair(catdata.Pair) Relationalize(catdata.fql.decl.InstExp.Relationalize) Zero(catdata.fql.decl.InstExp.Zero) Two(catdata.fql.decl.InstExp.Two) Tuple4(org.jparsec.functors.Tuple4) Delta(catdata.fql.decl.FullQueryExp.Delta) Tuple3(org.jparsec.functors.Tuple3) Times(catdata.fql.decl.InstExp.Times) External(catdata.fql.decl.InstExp.External) FullSigma(catdata.fql.decl.InstExp.FullSigma) FullQueryExp(catdata.fql.decl.FullQueryExp) Exp(catdata.fql.decl.InstExp.Exp) MapExp(catdata.fql.decl.MapExp) TransExp(catdata.fql.decl.TransExp) QueryExp(catdata.fql.decl.QueryExp) SigExp(catdata.fql.decl.SigExp) InstExp(catdata.fql.decl.InstExp)

Example 45 with Tuple3

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

Tuple3 (org.jparsec.functors.Tuple3)90 Pair (catdata.Pair)69 List (java.util.List)57 LinkedList (java.util.LinkedList)56 Tuple5 (org.jparsec.functors.Tuple5)41 HashMap (java.util.HashMap)33 Tuple4 (org.jparsec.functors.Tuple4)32 LinkedHashMap (java.util.LinkedHashMap)17 Triple (catdata.Triple)15 HashSet (java.util.HashSet)15 XPair (catdata.fpql.XExp.XPair)11 Map (java.util.Map)10 Set (java.util.Set)6 Chc (catdata.Chc)5 Var (catdata.fqlpp.FunctorExp.Var)5 Program (catdata.Program)4 Const (catdata.fql.decl.SigExp.Const)4 Plus (catdata.fqlpp.CatExp.Plus)4 Apply (catdata.fqlpp.FunctorExp.Apply)4 Zero (catdata.fqlpp.FunctorExp.Zero)4