Search in sources :

Example 1 with OplGround

use of catdata.opl.OplExp.OplGround in project fql by CategoricalData.

the class OplOps method visit.

@Override
public OplObject visit(Program<OplExp> env, OplInst0 e) {
    OplObject zzz = ENV.get(e.P.S);
    if (!(zzz instanceof OplSchema)) {
        throw new RuntimeException("Not a SCHEMA: " + e.P.S);
    }
    for (Object k2 : e.imports) {
        String k = (String) k2;
        OplExp o = env.exps.get(k);
        OplInst0 a;
        if (o instanceof OplInst0) {
            a = (OplInst0) o;
        } else if (o instanceof OplGround) {
            a = ((OplGround) o).validate(((OplInst) ENV.get(k)).S);
        } else {
            throw new RuntimeException("Not an instance: " + k);
        }
        Util.putAllSafely(e.P.gens, a.P.gens);
        e.P.equations.addAll(a.P.equations);
        e.P.prec.putAll(a.P.prec);
    // Util.putAllSafely(e.P.prec, a.P.prec);
    }
    OplPres P = (OplPres) visit(env, e.P);
    OplInst ret = new OplInst(e.P.S, "?", "none");
    OplObject S0 = ENV.get(e.P.S);
    if (!(S0 instanceof OplSchema)) {
        throw new RuntimeException("Not a schema: " + e.P.S);
    }
    OplSchema S = (OplSchema) S0;
    ret.validate(S, P, null);
    return ret;
}
Also used : OplSchema(catdata.opl.OplExp.OplSchema) OplInst0(catdata.opl.OplExp.OplInst0) OplGround(catdata.opl.OplExp.OplGround) OplPres(catdata.opl.OplExp.OplPres) OplInst(catdata.opl.OplExp.OplInst)

Example 2 with OplGround

use of catdata.opl.OplExp.OplGround 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

OplGround (catdata.opl.OplExp.OplGround)2 Pair (catdata.Pair)1 OplInst (catdata.opl.OplExp.OplInst)1 OplInst0 (catdata.opl.OplExp.OplInst0)1 OplPres (catdata.opl.OplExp.OplPres)1 OplSchema (catdata.opl.OplExp.OplSchema)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Tuple3 (org.jparsec.functors.Tuple3)1 Tuple5 (org.jparsec.functors.Tuple5)1