Search in sources :

Example 1 with NewDecl

use of catdata.fqlpp.FQLPPProgram.NewDecl in project fql by CategoricalData.

the class PPParser method program.

public static FQLPPProgram program(String s) {
    List<NewDecl> ret = new LinkedList<>();
    List decls = (List) program.parse(s);
    for (Object d : decls) {
        org.jparsec.functors.Pair pr = (org.jparsec.functors.Pair) d;
        Object decl = pr.b;
        String txt = pr.a.toString();
        int idx = s.indexOf(txt);
        if (idx < 0) {
            throw new RuntimeException();
        }
        Tuple3 t = (Tuple3) decl;
        String kind = t.a.toString();
        String name = t.b.toString();
        switch(kind) {
            case "set":
                Tuple4 tt = (Tuple4) decl;
                // name = (String) t.b;
                ret.add(NewDecl.setDecl(name, idx, toSet(tt.d)));
                break;
            case "function":
                Tuple4 t0 = (Tuple4) decl;
                // name = (String) t.b;
                ret.add(NewDecl.fnDecl(name, idx, toFn(t0.d)));
                break;
            case "functor":
                Tuple4 ti = (Tuple4) decl;
                // name = (String) t.b;
                ret.add(NewDecl.ftrDecl(name, idx, toFtr(ti.d)));
                break;
            case "category":
                Tuple4 tx = (Tuple4) decl;
                // name = (String) t.b;
                ret.add(NewDecl.catDecl(name, idx, toCat(tx.d)));
                break;
            case "transform":
                Tuple4 te = (Tuple4) decl;
                // name = (String) t.b;
                ret.add(NewDecl.transDecl(name, idx, toTrans(te.d)));
                break;
            default:
                throw new RuntimeException("Unknown decl: " + kind);
        }
    }
    return new FQLPPProgram(ret);
}
Also used : NewDecl(catdata.fqlpp.FQLPPProgram.NewDecl) LinkedList(java.util.LinkedList) Tuple4(org.jparsec.functors.Tuple4) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair)

Aggregations

Pair (catdata.Pair)1 NewDecl (catdata.fqlpp.FQLPPProgram.NewDecl)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Tuple3 (org.jparsec.functors.Tuple3)1 Tuple4 (org.jparsec.functors.Tuple4)1