use of org.jparsec.functors.Tuple5 in project fql by CategoricalData.
the class OplParser method fromBlocks.
private static Map<Object, Pair<String, Block<String, String, String, String, String, String>>> fromBlocks(List l) {
Map<Object, Pair<String, Block<String, String, String, String, String, String>>> ret = new HashMap<>();
for (Object o : l) {
Tuple5 t = (Tuple5) o;
Block<String, String, String, String, String, String> b = fromBlock(t.c);
ret.put(t.a.toString(), new Pair<>(t.e.toString(), b));
}
return ret;
}
use of org.jparsec.functors.Tuple5 in project fql by CategoricalData.
the class OplParser method toTerm.
private static OplTerm toTerm(Collection vars, Collection consts, Object a, boolean suppressError) {
if (a instanceof List) {
List<String> aa = (List<String>) a;
if (aa.isEmpty()) {
throw new RuntimeException();
}
OplTerm head = toTerm(vars, consts, aa.get(0), suppressError);
// List<String> bb = new LinkedList<>(aa); Collections.reverse(list)
for (int j = 1; j < aa.size(); j++) {
head = new OplTerm(aa.get(j), Util.singList(head));
}
return head;
}
if (a instanceof String) {
String a0 = (String) a;
try {
int i = Integer.parseInt(a0);
if (sugarForNat) {
return OplTerm.natToTerm(i);
}
} catch (Exception e) {
}
if (vars != null && vars.contains(a0)) {
return new OplTerm(a0);
} else if (vars != null && !vars.contains(a0) || consts != null && consts.contains(a0)) {
return new OplTerm(a0, new LinkedList<>());
} else if (consts == null || vars == null) {
return new OplTerm(a0);
} else if (suppressError) {
return new OplTerm(a0, new LinkedList<>());
}
throw new DoNotIgnore(a + " is neither a bound variable nor a (0-ary) constant ");
}
if (a instanceof Tuple5) {
Tuple5 t = (Tuple5) a;
String f = (String) t.c;
List<OplTerm> l0 = new LinkedList<>();
l0.add(toTerm(vars, consts, t.b, suppressError));
l0.add(toTerm(vars, consts, t.d, suppressError));
return new OplTerm(f, l0);
}
Tuple3 t = (Tuple3) a;
String f = (String) t.a;
List<Object> l = (List<Object>) t.c;
List<OplTerm> l0 = l.stream().map(x -> toTerm(vars, consts, x, suppressError)).collect(Collectors.toList());
return new OplTerm(f, l0);
}
use of org.jparsec.functors.Tuple5 in project fql by CategoricalData.
the class OplParser method toSCHEMA.
private static OplExp toSCHEMA(Object ox) {
Tuple4 oy = (Tuple4) ox;
String ts = (String) oy.d;
org.jparsec.functors.Pair newobj = (org.jparsec.functors.Pair) oy.b;
List<String> imports = newobj.a == null ? new LinkedList<>() : (List<String>) ((org.jparsec.functors.Pair) newobj.a).b;
Tuple5 t = (Tuple5) newobj.b;
Tuple3 a = (Tuple3) t.a;
Tuple3 b = (Tuple3) t.b;
Tuple3 c = (Tuple3) t.c;
Tuple3 d = (Tuple3) t.d;
Tuple3 e = (Tuple3) t.e;
Set<String> sorts = a == null ? new HashSet<>() : new HashSet<>((Collection<String>) a.b);
List<Tuple3> symbolsE0 = b == null ? new LinkedList<>() : (List<Tuple3>) b.b;
List<Tuple3> symbolsA0 = c == null ? new LinkedList<>() : (List<Tuple3>) c.b;
List<org.jparsec.functors.Pair> equationsE0 = c == null ? new LinkedList<>() : (List<org.jparsec.functors.Pair>) d.b;
List<org.jparsec.functors.Pair> equationsA0 = c == null ? new LinkedList<>() : (List<org.jparsec.functors.Pair>) e.b;
Map<String, Pair<List<String>, String>> symbolsE = new HashMap<>();
Map<String, Pair<List<String>, String>> symbolsA = new HashMap<>();
Map<String, Pair<List<String>, String>> symbolsEA = new HashMap<>();
Map<String, Integer> prec = new HashMap<>();
for (Tuple3 x : symbolsE0) {
String dom;
List<String> args;
if (x.c instanceof Tuple3) {
Tuple3 zzz = (Tuple3) x.c;
args = (List<String>) zzz.a;
dom = (String) zzz.c;
} else {
dom = (String) x.c;
args = new LinkedList<>();
}
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 (symbolsE.containsKey(name)) {
throw new DoNotIgnore("Duplicate symbol " + name);
}
symbolsE.put(name, new Pair<>(args, dom));
symbolsEA.put(name, new Pair<>(args, dom));
}
}
for (Tuple3 x : symbolsA0) {
String dom;
List<String> args;
if (x.c instanceof Tuple3) {
Tuple3 zzz = (Tuple3) x.c;
args = (List<String>) zzz.a;
dom = (String) zzz.c;
} else {
dom = (String) x.c;
args = new LinkedList<>();
}
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 (symbolsA.containsKey(name)) {
throw new DoNotIgnore("Duplicate symbol " + name);
}
symbolsA.put(name, new Pair<>(args, dom));
symbolsEA.put(name, new Pair<>(args, dom));
}
}
// /////////////
List<Triple<OplCtx<String, String>, OplTerm<String, String>, OplTerm<String, String>>> equationsE = new LinkedList<>();
List<Triple<OplCtx<String, String>, OplTerm<String, String>, OplTerm<String, String>>> equationsA = new LinkedList<>();
for (org.jparsec.functors.Pair<Tuple3, Tuple3> x : equationsE0) {
List<Tuple3> fa = x.a == null ? new LinkedList<>() : (List<Tuple3>) x.a.b;
OplCtx<String, String> ctx = toCtx(fa);
Tuple3 eq = x.b;
OplTerm lhs = toTerm(ctx.names(), consts(symbolsEA), eq.a, false);
OplTerm rhs = toTerm(ctx.names(), consts(symbolsEA), eq.c, false);
equationsE.add(new Triple<>(ctx, lhs, rhs));
}
for (org.jparsec.functors.Pair<Tuple3, Tuple3> x : equationsA0) {
List<Tuple3> fa = x.a == null ? new LinkedList<>() : (List<Tuple3>) x.a.b;
OplCtx<String, String> ctx = toCtx(fa);
Tuple3 eq = x.b;
OplTerm lhs = toTerm(ctx.names(), consts(symbolsEA), eq.a, false);
OplTerm rhs = toTerm(ctx.names(), consts(symbolsEA), eq.c, false);
equationsA.add(new Triple<>(ctx, lhs, rhs));
}
OplSCHEMA0 ret = new OplSCHEMA0(prec, sorts, symbolsE, symbolsA, equationsE, equationsA, ts);
ret.imports = new HashSet<>(imports);
return ret;
}
use of org.jparsec.functors.Tuple5 in project fql by CategoricalData.
the class OplParser method toTrans.
private static OplExp toTrans(Object c) {
Tuple3 t = (Tuple3) c;
if (!t.a.toString().equals("transform")) {
throw new RuntimeException();
}
Map<String, Map<String, String>> map = new HashMap<>();
Tuple3 tb = (Tuple3) t.b;
List<Tuple5> l = (List<Tuple5>) tb.b;
for (Tuple5 x : l) {
String name = (String) x.a;
List<Tuple5> y = (List<Tuple5>) x.d;
Map<String, String> m = new HashMap<>();
for (Tuple5 z : y) {
String xx = (String) z.b;
String yy = (String) z.d;
if (m.containsKey(xx)) {
throw new DoNotIgnore("Duplicate argument: " + xx);
}
m.put(xx, yy);
}
if (map.containsKey(name)) {
throw new DoNotIgnore("Duplicate sort: " + name);
}
map.put(name, m);
}
Tuple4 tc = (Tuple4) t.c;
return new OplSetTrans(map, (String) tc.b, (String) tc.d);
}
use of org.jparsec.functors.Tuple5 in project fql by CategoricalData.
the class OplParser method toModel.
private static OplExp toModel(Object o) {
if (!o.toString().contains("model")) {
throw new RuntimeException();
}
Tuple3 t = (Tuple3) o;
org.jparsec.functors.Pair b = (org.jparsec.functors.Pair) t.b;
org.jparsec.functors.Pair c = (org.jparsec.functors.Pair) t.c;
Tuple3 y = (Tuple3) b.a;
List<Tuple3> sorts = (List<Tuple3>) y.b;
Map<String, Set<String>> sorts0 = new HashMap<>();
for (Tuple3 x : sorts) {
String s = x.a.toString();
List<String> s0 = (List<String>) x.c;
if (sorts0.containsKey(s)) {
throw new DoNotIgnore("Duplicate sort: " + s);
}
Set<String> s1 = new HashSet<>(s0);
if (s1.size() != s0.size()) {
throw new DoNotIgnore("Duplicate member: " + s0);
}
sorts0.put(s, s1);
}
Map<String, Map<List<String>, String>> symbols0 = new HashMap<>();
Tuple3 z = (Tuple3) b.b;
List<Tuple3> q = (List<Tuple3>) z.b;
for (Tuple3 r : q) {
List<Tuple5> u = (List<Tuple5>) r.c;
String fname = (String) r.a;
if (symbols0.containsKey(fname)) {
throw new DoNotIgnore("Duplicte symbol " + fname);
}
Map<List<String>, String> toadd = new HashMap<>();
for (Tuple5 e : u) {
List<String> args = (List<String>) e.b;
String ret = (String) e.d;
if (toadd.containsKey(args)) {
throw new DoNotIgnore("Duplicate argument at " + args);
}
toadd.put(args, ret);
}
symbols0.put(fname, toadd);
}
return new OplSetInst(sorts0, symbols0, c.b.toString());
}
Aggregations