use of catdata.fql.decl.FQLProgram.NewDecl in project fql by CategoricalData.
the class FQLParser method program.
@SuppressWarnings({ "rawtypes", "unchecked" })
public static FQLProgram 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();
}
if (decl instanceof org.jparsec.functors.Pair) {
org.jparsec.functors.Pair p = (org.jparsec.functors.Pair) decl;
if (p.a.toString().equals("drop")) {
ret.add(NewDecl.dropDecl((List<String>) p.b));
continue;
}
}
Tuple3 t = (Tuple3) decl;
String kind = t.a.toString();
switch(kind) {
case "enum":
Tuple4 tte = (Tuple4) decl;
String name = (String) tte.b;
List<String> values = (List<String>) tte.d;
ret.add(NewDecl.typeDecl(name, values, idx));
break;
case "query":
Tuple4 tta = (Tuple4) decl;
name = (String) tta.b;
ret.add(NewDecl.queryDecl(name, idx, toQuery(tta.d)));
break;
case "QUERY":
tta = (Tuple4) decl;
name = (String) tta.b;
ret.add(NewDecl.fullQuery(name, toFullQuery(tta.d), idx));
break;
case "schema":
Tuple4 tt = (Tuple4) decl;
name = (String) tt.b;
ret.add(NewDecl.sigDecl(name, idx, toSchema(tt.d)));
break;
case "instance":
Tuple4 tt0 = (Tuple4) decl;
name = (String) t.b;
NewDecl toAdd = NewDecl.instDecl(name, idx, toInst(tt0.d));
ret.add(toAdd);
break;
case "mapping":
Tuple4 t0 = (Tuple4) decl;
name = (String) t.b;
ret.add(NewDecl.mapDecl(name, idx, toMapping(t0.d)));
break;
case "transform":
Tuple4 tx = (Tuple4) decl;
name = (String) tx.b;
ret.add(NewDecl.transDecl(name, idx, toTrans(tx.d)));
break;
default:
throw new RuntimeException("Unknown decl: " + kind);
}
}
return new FQLProgram(ret);
}
Aggregations