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);
}