use of org.jparsec.functors.Tuple4 in project fql by CategoricalData.
the class OplParser method toTrans_2.
private static OplExp toTrans_2(Object c) {
Tuple3 t = (Tuple3) c;
if (!t.a.toString().equals("transpres")) {
throw new RuntimeException();
}
Map<String, Map<String, OplTerm>> map = new HashMap<>();
org.jparsec.functors.Pair q = (org.jparsec.functors.Pair) t.b;
List<String> imports = q.a == null ? new LinkedList<>() : (List<String>) ((org.jparsec.functors.Pair) q.a).b;
Tuple3 tb = (Tuple3) q.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, OplTerm> m = new HashMap<>();
for (Tuple5 z : y) {
String xx = (String) z.b;
// OplTerm yy = toTermNoVars(z.d);
OplTerm yy = toTerm(new HashSet<>(), new HashSet<>(), z.d, false);
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;
OplPresTrans ret = new OplPresTrans(map, (String) tc.b, (String) tc.d);
ret.imports = new HashSet<>(imports);
return ret;
}
use of org.jparsec.functors.Tuple4 in project fql by CategoricalData.
the class OplParser method toMapping.
private static OplExp toMapping(Object c) {
Tuple3 t = (Tuple3) c;
Tuple3 aa = (Tuple3) t.b;
Tuple3 a = (Tuple3) aa.b;
Tuple3 b = (Tuple3) aa.c;
// Tuple3 b = (Tuple3) t.c;
List<String> imports = aa.a == null ? new LinkedList<>() : (List<String>) ((org.jparsec.functors.Pair) aa.a).b;
List<Tuple3> sorts = (List<Tuple3>) a.b;
List<Tuple3> symbols = (List<Tuple3>) b.b;
Map<String, String> sorts0 = new HashMap<>();
Map<String, Pair<OplCtx<String, String>, OplTerm<String, String>>> symbols0 = new HashMap<>();
for (Tuple3 z : sorts) {
String p = (String) z.a;
if (sorts0.containsKey(p)) {
throw new DoNotIgnore("Duplicate sort: " + p);
}
String q = (String) z.c;
sorts0.put(p, q);
}
for (Tuple3 z : symbols) {
String p = (String) z.a;
if (sorts0.containsKey(p)) {
throw new DoNotIgnore("Duplicate symbol: " + p);
}
org.jparsec.functors.Pair ppp = (org.jparsec.functors.Pair) z.c;
Tuple3 q = (Tuple3) ppp.a;
List<Tuple3> ctx = q == null ? new LinkedList<>() : (List<Tuple3>) q.b;
List<Pair<String, String>> ctx0 = new LinkedList<>();
Set<String> seen = new HashSet<>();
for (Object uu : ctx) {
String name;
String type = null;
if (uu instanceof Tuple3) {
Tuple3 u = (Tuple3) uu;
name = (String) u.a;
type = (String) u.c;
} else {
name = (String) uu;
}
if (seen.contains(name)) {
throw new DoNotIgnore("Duplicate var: " + name);
}
seen.add(name);
ctx0.add(new Pair<>(name, type));
}
OplCtx ccc = new OplCtx<>(ctx0);
symbols0.put(p, new Pair<>(ccc, toTerm(ccc.names(), null, ppp.b, false)));
}
Tuple4 x = (Tuple4) t.c;
String src0 = (String) x.b;
String dst0 = (String) x.d;
OplMapping ret = new OplMapping(sorts0, symbols0, src0, dst0);
ret.imports = new HashSet<>(imports);
return ret;
}
use of org.jparsec.functors.Tuple4 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.Tuple4 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.Tuple4 in project fql by CategoricalData.
the class OplParser method toINSTANCE.
private static OplExp toINSTANCE(Object o) {
if (!o.toString().contains("INSTANCE")) {
throw new RuntimeException();
}
OplPres ex = toPresentation(o);
OplInst0 ret = new OplInst0(ex);
Tuple4 t = (Tuple4) o;
Tuple3 e = (Tuple3) t.b;
List<String> imports = e.a == null ? new LinkedList<>() : (List<String>) ((org.jparsec.functors.Pair) e.a).b;
ret.imports = new HashSet<>(imports);
return ret;
}
Aggregations