Search in sources :

Example 51 with Tuple3

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

the class PPParser method toCatFtrConst.

private static FunctorExp toCatFtrConst(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, CatExp> 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;
        CatExp l = toCat(u.c);
        nodesX.put(n, l);
    }
    Map<String, FunctorExp> 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;
        FunctorExp l = toFtr(u.c);
        arrowsX.put(n, l);
    }
    CatConst ret = new CatConst(toCat(y.c), nodesX, arrowsX);
    return ret;
}
Also used : HashMap(java.util.HashMap) CatConst(catdata.fqlpp.FunctorExp.CatConst) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair)

Example 52 with Tuple3

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

the class PPParser method toCatConst.

public static CatExp.Const toCatConst(Object y) {
    Set<String> nodes = new HashSet<>();
    Set<Triple<String, String, String>> arrows = new HashSet<>();
    Set<Pair<Pair<String, List<String>>, Pair<String, List<String>>>> eqs = new HashSet<>();
    Tuple3 s = (Tuple3) y;
    Tuple3 nodes0 = (Tuple3) s.a;
    Tuple3 arrows0 = (Tuple3) s.b;
    Tuple3 eqs0 = (Tuple3) s.c;
    List nodes1 = (List) nodes0.b;
    List arrows1 = (List) arrows0.b;
    List eqs1 = (List) eqs0.b;
    for (Object o : nodes1) {
        nodes.add((String) o);
    }
    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;
        List<String> l1 = (List<String>) x.a;
        List<String> l2 = (List<String>) x.c;
        String xxx = l1.remove(0);
        String yyy = l2.remove(0);
        eqs.add(new Pair<>(new Pair<>(xxx, l1), new Pair<>(yyy, l2)));
    }
    CatExp.Const c = new CatExp.Const(nodes, arrows, eqs);
    return c;
}
Also used : Const(catdata.fqlpp.FnExp.Const) CatConst(catdata.fqlpp.FunctorExp.CatConst) SetSetConst(catdata.fqlpp.FunctorExp.SetSetConst) InstConst(catdata.fqlpp.FunctorExp.InstConst) MapConst(catdata.fqlpp.FunctorExp.MapConst) FinalConst(catdata.fqlpp.FunctorExp.FinalConst) Triple(catdata.Triple) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet) Pair(catdata.Pair)

Example 53 with Tuple3

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

the class OplParser method toPragma.

private static OplExp toPragma(Object t) {
    Tuple3 tb = (Tuple3) t;
    List<Tuple3> l = (List<Tuple3>) tb.b;
    Map<String, String> map = new HashMap<>();
    for (Tuple3 x : l) {
        String k = (String) x.a;
        String v = (String) x.c;
        if (map.containsKey(k)) {
            throw new DoNotIgnore("Duplicate key: " + k);
        }
        map.put(k, v);
    }
    return new OplPragma(map);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) OplPragma(catdata.opl.OplExp.OplPragma)

Example 54 with Tuple3

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

the class OplParser method toFDM.

private static OplExp toFDM(Object c) {
    Tuple3 t = (Tuple3) c;
    String i = (String) t.b;
    String r = (String) t.c;
    if (t.a.toString().equals("delta")) {
        return new OplDelta(i, r);
    } else if (t.a.toString().equals("sigma")) {
        return new OplSigma(i, r);
    }
    throw new RuntimeException();
}
Also used : OplDelta(catdata.opl.OplExp.OplDelta) Tuple3(org.jparsec.functors.Tuple3) OplSigma(catdata.opl.OplExp.OplSigma)

Example 55 with Tuple3

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

the class OplParser method toTrans_2.

private static OplExp toTrans_2(Object c) {
    Tuple3 t = (Tuple3) c;
    if (!t.a.toString().equals("transpres")) {
        throw new RuntimeException();
    }
    Map<String, Map<String, OplTerm>> map = new HashMap<>();
    org.jparsec.functors.Pair q = (org.jparsec.functors.Pair) t.b;
    List<String> imports = q.a == null ? new LinkedList<>() : (List<String>) ((org.jparsec.functors.Pair) q.a).b;
    Tuple3 tb = (Tuple3) q.b;
    List<Tuple5> l = (List<Tuple5>) tb.b;
    for (Tuple5 x : l) {
        String name = (String) x.a;
        List<Tuple5> y = (List<Tuple5>) x.d;
        Map<String, OplTerm> m = new HashMap<>();
        for (Tuple5 z : y) {
            String xx = (String) z.b;
            // OplTerm yy = toTermNoVars(z.d);
            OplTerm yy = toTerm(new HashSet<>(), new HashSet<>(), z.d, false);
            if (m.containsKey(xx)) {
                throw new DoNotIgnore("Duplicate argument: " + xx);
            }
            m.put(xx, yy);
        }
        if (map.containsKey(name)) {
            throw new DoNotIgnore("Duplicate sort: " + name);
        }
        map.put(name, m);
    }
    Tuple4 tc = (Tuple4) t.c;
    OplPresTrans ret = new OplPresTrans(map, (String) tc.b, (String) tc.d);
    ret.imports = new HashSet<>(imports);
    return ret;
}
Also used : OplPresTrans(catdata.opl.OplExp.OplPresTrans) HashMap(java.util.HashMap) 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) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Pair(catdata.Pair)

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