Search in sources :

Example 6 with Tuple3

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

the class PPParser method toFinalConst.

private static FunctorExp toFinalConst(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, FunctorExp> 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;
        FunctorExp l = toFtr(u.c);
        nodesX.put(n, l);
    }
    Map<String, TransExp> 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;
        TransExp l = toTrans(u.c);
        arrowsX.put(n, l);
    }
    FinalConst ret = new FinalConst(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) FinalConst(catdata.fqlpp.FunctorExp.FinalConst) Pair(catdata.Pair)

Example 7 with Tuple3

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

the class OplParser method toPresentation.

private static OplPres toPresentation(Object o) {
    Tuple4 t = (Tuple4) o;
    Tuple3 e = (Tuple3) t.b;
    // List<String> imports = e.a == null ? new LinkedList<>() : (List<String>) ((Tuple3)e.a).b;
    String yyy = (String) t.d;
    org.jparsec.functors.Pair b = (org.jparsec.functors.Pair) e.b;
    org.jparsec.functors.Pair c = (org.jparsec.functors.Pair) e.c;
    List<Tuple3> symbols0 = (List<Tuple3>) b.b;
    List<Tuple4> equations0 = (List<Tuple4>) c.b;
    Map<String, String> symbols = new HashMap<>();
    Map<String, Integer> prec = new HashMap<>();
    for (Tuple3 x : symbols0) {
        String dom = (String) x.c;
        List<org.jparsec.functors.Pair> name0s = (List<org.jparsec.functors.Pair>) x.a;
        for (org.jparsec.functors.Pair name0 : name0s) {
            String name = (String) name0.a;
            if (name0.b != null) {
                org.jparsec.functors.Pair zzz = (org.jparsec.functors.Pair) name0.b;
                Integer i = (Integer) zzz.b;
                prec.put(name, i);
            }
            if (symbols.containsKey(name)) {
                throw new DoNotIgnore("Duplicate symbol " + name);
            }
            symbols.put(name, dom);
        }
    }
    List<Pair<OplTerm<Chc<String, String>, String>, OplTerm<Chc<String, String>, String>>> equations = new LinkedList<>();
    for (org.jparsec.functors.Pair<Tuple3, Tuple3> x : equations0) {
        if (x.a != null) {
            throw new DoNotIgnore("Cannot have universally quantified equations in presentations");
        }
        List<Tuple3> fa = new LinkedList<>();
        OplCtx<String, String> ctx = toCtx(fa);
        Tuple3 eq = x.b;
        OplTerm lhs = toTerm(ctx.names(), symbols.keySet(), eq.a, true);
        OplTerm rhs = toTerm(ctx.names(), symbols.keySet(), eq.c, true);
        equations.add(new Pair<>(lhs, rhs));
    }
    OplPres ret = new OplPres<>(prec, yyy, null, symbols, equations);
    return ret;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) OplPres(catdata.opl.OplExp.OplPres) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair) LinkedList(java.util.LinkedList) Tuple4(org.jparsec.functors.Tuple4) Tuple3(org.jparsec.functors.Tuple3) Chc(catdata.Chc)

Example 8 with Tuple3

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

the class OplParser method toTheory.

private static OplExp toTheory(Object o) {
    Tuple5 t = (Tuple5) o;
    List<String> imports = t.a == null ? new LinkedList<>() : (List<String>) ((org.jparsec.functors.Pair) t.a).b;
    Tuple3 a = (Tuple3) t.b;
    Tuple3 b = (Tuple3) t.c;
    Tuple3 c = (Tuple3) t.d;
    Tuple3 d = (Tuple3) t.e;
    Set<String> sorts = a == null ? new HashSet<>() : new HashSet<>((Collection<String>) a.b);
    List<Tuple3> symbols0 = b == null ? new LinkedList<>() : (List<Tuple3>) b.b;
    List<org.jparsec.functors.Pair> equations0 = c == null ? new LinkedList<>() : (List<org.jparsec.functors.Pair>) c.b;
    List<org.jparsec.functors.Pair> implications0 = new LinkedList<>();
    if (d != null) {
        implications0 = (List<org.jparsec.functors.Pair>) d.b;
    }
    Map<String, Pair<List<String>, String>> symbols = new HashMap<>();
    Map<String, Integer> prec = new HashMap<>();
    for (Tuple3 x : symbols0) {
        String dom;
        List<String> args;
        if (x.c instanceof Tuple3) {
            Tuple3 zzz = (Tuple3) x.c;
            args = (List<String>) zzz.a;
            dom = (String) zzz.c;
        } else {
            dom = (String) x.c;
            args = new LinkedList<>();
        }
        List<org.jparsec.functors.Pair> name0s = (List<org.jparsec.functors.Pair>) x.a;
        for (org.jparsec.functors.Pair name0 : name0s) {
            // org.jparsec.functors.Pair name0 =
            // (org.jparsec.functors.Pair) x.a;
            String name = (String) name0.a;
            if (name0.b != null) {
                org.jparsec.functors.Pair zzz = (org.jparsec.functors.Pair) name0.b;
                Integer i = (Integer) zzz.b;
                prec.put(name, i);
            }
            if (symbols.containsKey(name)) {
                throw new DoNotIgnore("Duplicate symbol " + name);
            }
            symbols.put(name, new Pair<>(args, dom));
        }
    }
    if (sorts.contains("Nat") && symbols.keySet().contains("zero") && symbols.keySet().contains("succ") && DefunctGlobalOptions.debug.opl.opl_desugar_nat) {
        sugarForNat = true;
    }
    List<Triple<OplCtx<String, String>, OplTerm<String, String>, OplTerm<String, String>>> equations = new LinkedList<>();
    for (org.jparsec.functors.Pair<Tuple3, Tuple3> x : equations0) {
        List<Tuple3> fa = x.a == null ? new LinkedList<>() : (List<Tuple3>) x.a.b;
        OplCtx<String, String> ctx = toCtx(fa);
        Tuple3 eq = x.b;
        OplTerm lhs = toTerm(ctx.names(), consts(symbols), eq.a, false);
        OplTerm rhs = toTerm(ctx.names(), consts(symbols), eq.c, false);
        equations.add(new Triple<>(ctx, lhs, rhs));
    }
    List<Triple<OplCtx<String, String>, List<Pair<OplTerm<String, String>, OplTerm<String, String>>>, List<Pair<OplTerm<String, String>, OplTerm<String, String>>>>> implications = new LinkedList<>();
    for (org.jparsec.functors.Pair<Tuple3, Tuple3> x : implications0) {
        List<Tuple3> fa = x.a == null ? new LinkedList<>() : (List<Tuple3>) x.a.b;
        OplCtx<String, String> ctx = toCtx(fa);
        Tuple3 eq = x.b;
        List<Tuple3> lhs0 = (List<Tuple3>) eq.a;
        List<Tuple3> rhs0 = (List<Tuple3>) eq.c;
        List<Pair<OplTerm<String, String>, OplTerm<String, String>>> lhs = new LinkedList<>();
        List<Pair<OplTerm<String, String>, OplTerm<String, String>>> rhs = new LinkedList<>();
        for (Tuple3 obj : lhs0) {
            OplTerm lhsX = toTerm(ctx.names(), consts(symbols), obj.a, false);
            OplTerm rhsX = toTerm(ctx.names(), consts(symbols), obj.c, false);
            lhs.add(new Pair<>(lhsX, rhsX));
        }
        for (Tuple3 obj : rhs0) {
            OplTerm lhsX = toTerm(ctx.names(), consts(symbols), obj.a, false);
            OplTerm rhsX = toTerm(ctx.names(), consts(symbols), obj.c, false);
            rhs.add(new Pair<>(lhsX, rhsX));
        }
        implications.add(new Triple<>(ctx, lhs, rhs));
    }
    OplSig ret = new OplSig<>(new VIt(), prec, sorts, symbols, equations, implications);
    ret.imports = new HashSet<>(imports);
    return ret;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair) OplSig(catdata.opl.OplExp.OplSig) LinkedList(java.util.LinkedList) Triple(catdata.Triple) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) Collection(java.util.Collection)

Example 9 with Tuple3

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

the class OplParser method toEval.

private static OplExp toEval(Object c) {
    Tuple3 t = (Tuple3) c;
    if (!t.a.toString().equals("eval")) {
        throw new RuntimeException();
    }
    String i = (String) t.b;
    OplTerm r = toTerm(null, null, t.c, false);
    return new OplEval(i, r);
}
Also used : Tuple3(org.jparsec.functors.Tuple3) OplEval(catdata.opl.OplExp.OplEval)

Example 10 with Tuple3

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

the class OplParser method fromAgg.

@SuppressWarnings("unused")
private static Agg<String, String, String, String, String, String> fromAgg(Collection vars, Collection consts, Object o, boolean suppressError) {
    Tuple5<Tuple4<?, String, String, ?>, List<Tuple3<String, ?, String>>, List<Tuple3<?, ?, ?>>, org.jparsec.functors.Pair<?, ?>, ?> t = (Tuple5<Tuple4<?, String, String, ?>, List<Tuple3<String, ?, String>>, List<Tuple3<?, ?, ?>>, org.jparsec.functors.Pair<?, ?>, ?>) o;
    LinkedHashMap<String, String> from = new LinkedHashMap<>();
    Set<Pair<OplTerm<String, String>, OplTerm<String, String>>> where = new HashSet<>();
    for (Object x : t.b) {
        Tuple3 l = (Tuple3) x;
        if (from.containsKey(l.a.toString())) {
            throw new RuntimeException("Duplicate for: " + l.a);
        }
        from.put(l.a.toString(), l.c.toString());
    }
    Set<String> allVars = new HashSet<>();
    allVars.addAll(vars);
    allVars.addAll(from.keySet());
    for (Object x : t.c) {
        Tuple3 l = (Tuple3) x;
        where.add(new Pair(toTerm(allVars, null, l.a, true), toTerm(allVars, null, l.c, true)));
    }
    OplTerm<String, String> att = toTerm(allVars, null, t.d.b, true);
    return new Agg<>(t.a.b, t.a.c, from, where, att);
}
Also used : Agg(catdata.opl.OplQuery.Agg) LinkedHashMap(java.util.LinkedHashMap) Tuple4(org.jparsec.functors.Tuple4) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair) HashSet(java.util.HashSet)

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