Search in sources :

Example 1 with Tuple4

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

the class PPParser method toCat.

private static CatExp toCat(Object o) {
    if (o.toString().equals("Set")) {
        return new Named("Set");
    }
    if (o.toString().equals("Cat")) {
        return new Named("Cat");
    }
    if (o instanceof Tuple4) {
        Tuple4 t = (Tuple4) o;
        return new Kleisli(t.b.toString(), t.c.toString(), t.d.toString(), t.a.toString().equals("cokleisli"));
    }
    try {
        Tuple3<?, ?, ?> t = (Tuple3<?, ?, ?>) o;
        String y = t.b.toString();
        if (y.equals("+")) {
            return new Plus(toCat(t.a), toCat(t.c));
        } else if (y.equals("*")) {
            return new Times(toCat(t.a), toCat(t.c));
        } else if (y.equals("^")) {
            return new CatExp.Exp(toCat(t.a), toCat(t.c));
        } else if (t.a.toString().equals("union")) {
            return new Union(toCat(t.b), toCat(t.c));
        } else {
            return toCatConst(o);
        }
    } catch (RuntimeException cce) {
    }
    try {
        org.jparsec.functors.Pair<?, ?> p = (org.jparsec.functors.Pair<?, ?>) o;
        if (p.a.toString().equals("dom")) {
            return new CatExp.Dom(toFtr(p.b));
        } else if (p.a.toString().equals("cod")) {
            return new Cod(toFtr(p.b));
        } else if (p.a.toString().equals("colim")) {
            return new Colim((String) p.b);
        }
    } catch (RuntimeException cce) {
    }
    try {
        if (o.toString().equals("void")) {
            return new CatExp.Zero();
        } else if (o.toString().equals("unit")) {
            return new CatExp.One();
        }
    } catch (RuntimeException cce) {
    }
    return new CatExp.Var(o.toString());
}
Also used : Colim(catdata.fqlpp.CatExp.Colim) Named(catdata.fqlpp.CatExp.Named) Zero(catdata.fqlpp.FunctorExp.Zero) Dom(catdata.fqlpp.FunctorExp.Dom) Var(catdata.fqlpp.FunctorExp.Var) Union(catdata.fqlpp.CatExp.Union) Tuple4(org.jparsec.functors.Tuple4) Kleisli(catdata.fqlpp.CatExp.Kleisli) Tuple3(org.jparsec.functors.Tuple3) Times(catdata.fqlpp.CatExp.Times) Cod(catdata.fqlpp.CatExp.Cod) Plus(catdata.fqlpp.CatExp.Plus) Exp(catdata.fqlpp.FunctorExp.Exp) Pair(catdata.Pair)

Example 2 with Tuple4

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

the class OplParser method toSchema.

private static OplExp toSchema(Object o) {
    Tuple4 t = (Tuple4) o;
    org.jparsec.functors.Pair e = (org.jparsec.functors.Pair) t.b;
    String yyy = (String) t.d;
    List<String> symbols0 = (List<String>) e.b;
    return new OplSchema<String, String, String>(yyy, new HashSet<>(symbols0));
}
Also used : Tuple4(org.jparsec.functors.Tuple4) OplSchema(catdata.opl.OplExp.OplSchema) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair)

Example 3 with Tuple4

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

the class OplParser method toChase.

private static OplExp toChase(Tuple5 t) {
    // Parser<?> chase = Parsers.tuple(term("chase"), ident(), Parsers.tuple(term("with"), term("{"), ident().sepBy(term(","), term("}")), term("max"), ident()));
    String I = (String) t.b;
    // t.c is (with { ... })
    Integer i0 = Integer.parseInt((String) t.e);
    Tuple4 x = (Tuple4) t.c;
    List<String> l = (List<String>) x.c;
    return new OplChaseExp(i0, I, new LinkedList<>(l));
}
Also used : Tuple4(org.jparsec.functors.Tuple4) OplChaseExp(catdata.opl.OplExp.OplChaseExp) List(java.util.List) LinkedList(java.util.LinkedList)

Example 4 with Tuple4

use of org.jparsec.functors.Tuple4 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 5 with Tuple4

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

the class OplParser method fromBlocks2.

private static Map<Object, Pair<String, Block<String, String, String, String, String, String>>> fromBlocks2(List l) {
    Map<Object, Pair<String, Block<String, String, String, String, String, String>>> ret = new HashMap<>();
    for (Object o : l) {
        Tuple4 t = (Tuple4) o;
        Block<String, String, String, String, String, String> b = fromBlock2(t.d);
        ret.put(t.c.toString(), new Pair<>(t.c.toString(), b));
    }
    return ret;
}
Also used : Tuple4(org.jparsec.functors.Tuple4) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Pair(catdata.Pair)

Aggregations

Tuple4 (org.jparsec.functors.Tuple4)36 Pair (catdata.Pair)30 Tuple3 (org.jparsec.functors.Tuple3)30 List (java.util.List)25 LinkedList (java.util.LinkedList)24 Tuple5 (org.jparsec.functors.Tuple5)18 HashMap (java.util.HashMap)14 LinkedHashMap (java.util.LinkedHashMap)8 HashSet (java.util.HashSet)6 XPair (catdata.fpql.XExp.XPair)5 Map (java.util.Map)4 Triple (catdata.Triple)3 Pair (org.jparsec.functors.Pair)3 Chc (catdata.Chc)2 RawTerm (catdata.aql.RawTerm)2 ColimSchExpRaw (catdata.aql.exp.ColimSchExp.ColimSchExpRaw)2 Delta (catdata.fql.decl.FullQueryExp.Delta)2 Pi (catdata.fql.decl.FullQueryExp.Pi)2 Sigma (catdata.fql.decl.FullQueryExp.Sigma)2 External (catdata.fql.decl.InstExp.External)2