Search in sources :

Example 1 with Numeral

use of catdata.fqlpp.SetExp.Numeral in project fql by CategoricalData.

the class PPParser method toSet.

private static SetExp toSet(Object o) {
    try {
        Tuple5 t = (Tuple5) o;
        String f = t.b.toString();
        SetExp e = toSet(t.e);
        return new SetExp.Apply(f, e);
    } catch (Exception e) {
    }
    try {
        int i = Integer.parseInt(o.toString());
        return new Numeral(i);
    } catch (Exception e) {
    }
    try {
        Tuple3<?, ?, ?> t = (Tuple3<?, ?, ?>) o;
        String y = t.b.toString();
        if (y.equals("+")) {
            return new SetExp.Plus(toSet(t.a), toSet(t.c));
        } else if (y.equals("*")) {
            return new SetExp.Times(toSet(t.a), toSet(t.c));
        } else if (y.equals("^")) {
            return new SetExp.Exp(toSet(t.a), toSet(t.c));
        } else if (y.equals("union")) {
            return new SetExp.Union(toSet(t.a), toSet(t.c));
        } else if (y.equals("intersect")) {
            return new Intersect(toSet(t.a), toSet(t.c));
        } else if (t.a.toString().equals("{")) {
            List tb = (List) t.b;
            Set x = new HashSet();
            for (Object uu : tb) {
                x.add(toValue(uu));
            }
            return new SetExp.Const(x);
        }
    } catch (RuntimeException cce) {
    }
    try {
        org.jparsec.functors.Pair<?, ?> p = (org.jparsec.functors.Pair<?, ?>) o;
        if (p.a.toString().equals("dom")) {
            return new SetExp.Dom(toFn(p.b));
        } else if (p.a.toString().equals("cod")) {
            return new SetExp.Cod(toFn(p.b));
        } else if (p.a.toString().equals("range")) {
            return new Range(toFn(p.b));
        }
    } catch (RuntimeException cce) {
    }
    try {
        if (o.toString().equals("void")) {
            return new SetExp.Zero();
        } else if (o.toString().equals("unit")) {
            return new SetExp.One();
        } else if (o.toString().equals("prop")) {
            return new SetExp.Prop();
        }
        throw new RuntimeException();
    } catch (RuntimeException cce) {
    }
    return new SetExp.Var(o.toString());
}
Also used : Numeral(catdata.fqlpp.SetExp.Numeral) Set(java.util.Set) ToSet(catdata.fqlpp.TransExp.ToSet) HashSet(java.util.HashSet) SetSet(catdata.fqlpp.TransExp.SetSet) PeterApply(catdata.fqlpp.TransExp.PeterApply) Apply(catdata.fqlpp.FunctorExp.Apply) Var(catdata.fqlpp.FunctorExp.Var) Intersect(catdata.fqlpp.SetExp.Intersect) List(java.util.List) LinkedList(java.util.LinkedList) Plus(catdata.fqlpp.CatExp.Plus) HashSet(java.util.HashSet) Pair(catdata.Pair) Zero(catdata.fqlpp.FunctorExp.Zero) Dom(catdata.fqlpp.FunctorExp.Dom) Prop(catdata.fqlpp.FunctorExp.Prop) Range(catdata.fqlpp.SetExp.Range) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) Exp(catdata.fqlpp.FunctorExp.Exp)

Aggregations

Pair (catdata.Pair)1 Plus (catdata.fqlpp.CatExp.Plus)1 Apply (catdata.fqlpp.FunctorExp.Apply)1 Dom (catdata.fqlpp.FunctorExp.Dom)1 Exp (catdata.fqlpp.FunctorExp.Exp)1 Prop (catdata.fqlpp.FunctorExp.Prop)1 Var (catdata.fqlpp.FunctorExp.Var)1 Zero (catdata.fqlpp.FunctorExp.Zero)1 Intersect (catdata.fqlpp.SetExp.Intersect)1 Numeral (catdata.fqlpp.SetExp.Numeral)1 Range (catdata.fqlpp.SetExp.Range)1 PeterApply (catdata.fqlpp.TransExp.PeterApply)1 SetSet (catdata.fqlpp.TransExp.SetSet)1 ToSet (catdata.fqlpp.TransExp.ToSet)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Set (java.util.Set)1 Tuple3 (org.jparsec.functors.Tuple3)1 Tuple5 (org.jparsec.functors.Tuple5)1