Search in sources :

Example 56 with Tuple3

use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.

the class OplParser method program.

public static Program<OplExp> program(String s) {
    List<Triple<String, Integer, OplExp>> ret = new LinkedList<>();
    List decls = (List) program.parse(s);
    sugarForNat = false;
    for (Object d : decls) {
        org.jparsec.functors.Pair pr = (org.jparsec.functors.Pair) d;
        Tuple3 decl = (Tuple3) pr.b;
        toProgHelper(pr.a.toString(), s, ret, decl);
    }
    sugarForNat = false;
    return new Program<>(ret, null);
}
Also used : Triple(catdata.Triple) Program(catdata.Program) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList) Pair(catdata.Pair)

Example 57 with Tuple3

use of org.jparsec.functors.Tuple3 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;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair) HashSet(java.util.HashSet) LinkedList(java.util.LinkedList) Tuple4(org.jparsec.functors.Tuple4) Tuple3(org.jparsec.functors.Tuple3) OplMapping(catdata.opl.OplExp.OplMapping)

Example 58 with Tuple3

use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.

the class OplParser method toModel2.

private static OplExp toModel2(Object o) {
    if (!o.toString().contains("tables")) {
        throw new RuntimeException();
    }
    Tuple3 t = (Tuple3) o;
    Tuple3 b = (Tuple3) 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, List<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);
        }
        sorts0.put(s, s0);
    }
    Map<String, Map<String, String>> symbols0 = new HashMap<>();
    Tuple3 z = (Tuple3) b.b;
    List<Tuple3> q = (List<Tuple3>) z.b;
    Tuple3 z0 = (Tuple3) b.c;
    q.addAll((Collection<? extends Tuple3>) z0.b);
    for (Tuple3 r : q) {
        List<Tuple5> u = (List<Tuple5>) r.c;
        String fname = (String) r.a;
        if (symbols0.containsKey(fname)) {
            throw new DoNotIgnore("Duplicate symbol " + fname);
        }
        Map<String, String> toadd = new HashMap<>();
        for (Tuple5 e : u) {
            String args = (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 OplGround(sorts0, symbols0, c.b.toString());
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) OplGround(catdata.opl.OplExp.OplGround) List(java.util.List) LinkedList(java.util.LinkedList) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Pair(catdata.Pair)

Example 59 with Tuple3

use of org.jparsec.functors.Tuple3 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);
}
Also used : OplPres(catdata.opl.OplExp.OplPres) Scanners(org.jparsec.Scanners) Tuple3(org.jparsec.functors.Tuple3) Tuple4(org.jparsec.functors.Tuple4) Tuple5(org.jparsec.functors.Tuple5) StringLiteral(org.jparsec.Terminals.StringLiteral) OplGround(catdata.opl.OplExp.OplGround) OplPushoutSch(catdata.opl.OplExp.OplPushoutSch) Map(java.util.Map) OplSchema(catdata.opl.OplExp.OplSchema) OplColim(catdata.opl.OplExp.OplColim) OplPushout(catdata.opl.OplExp.OplPushout) OplSetInst(catdata.opl.OplExp.OplSetInst) Pair(catdata.Pair) OplPushoutBen(catdata.opl.OplExp.OplPushoutBen) Collection(java.util.Collection) OplInst(catdata.opl.OplExp.OplInst) Set(java.util.Set) Collectors(java.util.stream.Collectors) Parser(org.jparsec.Parser) OplChaseExp(catdata.opl.OplExp.OplChaseExp) OplDelta(catdata.opl.OplExp.OplDelta) List(java.util.List) IntegerLiteral(org.jparsec.Terminals.IntegerLiteral) OplUnion(catdata.opl.OplExp.OplUnion) Parsers(org.jparsec.Parsers) Program(catdata.Program) OplId(catdata.opl.OplExp.OplId) XSchema(catdata.fpql.XExp.XSchema) Triple(catdata.Triple) OplSat(catdata.opl.OplExp.OplSat) DefunctGlobalOptions(catdata.ide.DefunctGlobalOptions) Terminals(org.jparsec.Terminals) OplJavaInst(catdata.opl.OplExp.OplJavaInst) OplDelta0(catdata.opl.OplExp.OplDelta0) Chc(catdata.Chc) HashMap(java.util.HashMap) OplApply(catdata.opl.OplExp.OplApply) OplDistinct(catdata.opl.OplExp.OplDistinct) OplUberSat(catdata.opl.OplExp.OplUberSat) OplSig(catdata.opl.OplExp.OplSig) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) OplFlower(catdata.opl.OplExp.OplFlower) OplPragma(catdata.opl.OplExp.OplPragma) OplPresTrans(catdata.opl.OplExp.OplPresTrans) OplSetTrans(catdata.opl.OplExp.OplSetTrans) LinkedList(java.util.LinkedList) Block(catdata.opl.OplQuery.Block) Iterator(java.util.Iterator) Reference(org.jparsec.Parser.Reference) Util(catdata.Util) OplSCHEMA0(catdata.opl.OplExp.OplSCHEMA0) OplEval(catdata.opl.OplExp.OplEval) OplPivot(catdata.opl.OplExp.OplPivot) OplSchemaProj(catdata.opl.OplExp.OplSchemaProj) Agg(catdata.opl.OplQuery.Agg) Identifier(org.jparsec.Terminals.Identifier) OplGraph(catdata.opl.OplExp.OplGraph) OplUnSat(catdata.opl.OplExp.OplUnSat) OplInst0(catdata.opl.OplExp.OplInst0) OplSigma(catdata.opl.OplExp.OplSigma) OplVar(catdata.opl.OplExp.OplVar) OplMapping(catdata.opl.OplExp.OplMapping) LinkedList(java.util.LinkedList) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList)

Example 60 with Tuple3

use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.

the class OplParser method toCtx.

private static OplCtx<String, String> toCtx(List<Tuple3> fa) {
    List<Pair<String, String>> ret = new LinkedList<>();
    if (fa == null) {
        return new OplCtx<>();
    }
    for (Object tt : fa) {
        if (tt instanceof Tuple3) {
            Tuple3 t = (Tuple3) tt;
            ret.add(new Pair<>(t.a.toString(), t.c.toString()));
        } else {
            ret.add(new Pair<>((String) tt, null));
        }
    }
    return new OplCtx<>(ret);
}
Also used : Tuple3(org.jparsec.functors.Tuple3) LinkedList(java.util.LinkedList) Pair(catdata.Pair)

Aggregations

Tuple3 (org.jparsec.functors.Tuple3)90 Pair (catdata.Pair)69 List (java.util.List)57 LinkedList (java.util.LinkedList)56 Tuple5 (org.jparsec.functors.Tuple5)41 HashMap (java.util.HashMap)33 Tuple4 (org.jparsec.functors.Tuple4)32 LinkedHashMap (java.util.LinkedHashMap)17 Triple (catdata.Triple)15 HashSet (java.util.HashSet)15 XPair (catdata.fpql.XExp.XPair)11 Map (java.util.Map)10 Set (java.util.Set)6 Chc (catdata.Chc)5 Var (catdata.fqlpp.FunctorExp.Var)5 Program (catdata.Program)4 Const (catdata.fql.decl.SigExp.Const)4 Plus (catdata.fqlpp.CatExp.Plus)4 Apply (catdata.fqlpp.FunctorExp.Apply)4 Zero (catdata.fqlpp.FunctorExp.Zero)4