Search in sources :

Example 86 with Tuple3

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

the class XRaToFpql method toFlower.

@SuppressWarnings({ "rawtypes", "unchecked" })
private static EFlower toFlower(Object decl) {
    Map<String, Pair<String, String>> select = new LinkedHashMap<>();
    Map<String, String> from = new LinkedHashMap<>();
    List<Pair<Pair<String, String>, Pair<String, String>>> where = new LinkedList<>();
    Tuple3 o = (Tuple3) decl;
    Tuple3 select0 = (Tuple3) o.a;
    org.jparsec.functors.Pair from0 = (org.jparsec.functors.Pair) o.b;
    org.jparsec.functors.Pair where0 = (org.jparsec.functors.Pair) o.c;
    boolean distinct;
    distinct = select0.b != null;
    List<Tuple3> select1 = (List<Tuple3>) select0.c;
    for (Tuple3 k : select1) {
        Tuple3 a = (Tuple3) k.a;
        String b = k.c.toString();
        select.put(b, new Pair<>(a.a.toString(), a.c.toString()));
    }
    List<Tuple3> from1 = (List<Tuple3>) from0.b;
    for (Tuple3 k : from1) {
        from.put(k.c.toString(), k.a.toString());
    }
    if (where0 != null) {
        List<Tuple3> where1 = (List<Tuple3>) where0.b;
        for (Tuple3 k : where1) {
            Tuple3 l = (Tuple3) k.a;
            if (k.c instanceof Tuple3) {
                Tuple3 r = (Tuple3) k.c;
                where.add(new Pair<>(new Pair<>(l.a.toString(), l.c.toString()), new Pair<>(r.a.toString(), r.c.toString())));
            } else {
                String r = (String) k.c;
                where.add(new Pair<>(new Pair<>(l.a.toString(), l.c.toString()), new Pair<>(r, null)));
            }
        }
    }
    return new EFlower(select, from, where, distinct);
}
Also used : Tuple3(org.jparsec.functors.Tuple3) Pair(catdata.Pair)

Example 87 with Tuple3

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

the class XSqlToFql method toEInsertValues.

@SuppressWarnings({ "rawtypes", "unchecked" })
private static EInsertValues toEInsertValues(Object decl) {
    Tuple5 t = (Tuple5) decl;
    String target = t.b.toString();
    List<Tuple3> x = (List<Tuple3>) t.d;
    List<List<String>> values = new LinkedList<>();
    for (Tuple3 y : x) {
        List<String> l = (List<String>) y.b;
        values.add(l);
    }
    return new EInsertValues(target, values);
}
Also used : Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) LinkedList(java.util.LinkedList) List(java.util.List) LinkedList(java.util.LinkedList)

Example 88 with Tuple3

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

the class XSqlToFql method program.

@SuppressWarnings({ "unchecked", "rawtypes" })
private static List<EExternal> program(String s) {
    List<EExternal> ret = new LinkedList<>();
    List<Tuple3> decls = (List<Tuple3>) program.parse(s);
    for (Tuple3 decl : decls) {
        if (decl.a.toString().equals("CREATE")) {
            ret.add(toECreateTable(decl));
        } else if (decl.toString().startsWith("((INSERT")) {
            ret.add(toEInsertValues(decl));
        } else {
            throw new RuntimeException(decl.toString());
        }
    }
    return ret;
}
Also used : Tuple3(org.jparsec.functors.Tuple3) LinkedList(java.util.LinkedList) List(java.util.List) LinkedList(java.util.LinkedList)

Example 89 with Tuple3

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

the class CombinatorParser method mapExpRaw.

// TODO: aql reverse order on arguments env
private static Parser<MapExpRaw> mapExpRaw() {
    Parser<List<catdata.Pair<LocStr, List<String>>>> fks = Parsers.tuple(token("foreign_keys"), env(ident.sepBy1(token(".")), "->")).map(x -> x.b);
    Parser<Tuple5<Token, String, Pair<Token, String>, Token, RawTerm>> lp0 = Parsers.tuple(token("lambda"), ident, Parsers.tuple(token(":"), ident).optional(), token("."), term());
    Parser<Tuple5<Token, String, Pair<Token, String>, Token, RawTerm>> lq = ident.sepBy1(token(".")).map(x -> {
        // TODO aql
        RawTerm term = RawTerm.fold(x, "_x");
        return new Tuple5<>(null, "_x", new Pair<>(null, null), null, term);
    });
    Parser<Tuple5<Token, String, Pair<Token, String>, Token, RawTerm>> lp = Parsers.or(lp0, lq);
    Parser<List<catdata.Pair<LocStr, Triple<String, String, RawTerm>>>> envp = env(lp.map(x -> new Triple<>(x.b, x.c == null ? null : x.c.b, x.e)), "->");
    Parser<List<catdata.Pair<LocStr, Triple<String, String, RawTerm>>>> atts = Parsers.tuple(token("attributes"), envp).map(x -> x.b);
    // List<Pair<LocStr, Triple<String, List<Pair<LocStr, List<String>>>,
    // List<Pair<LocStr, Triple<String, String, RawTerm>>>>>> list,
    Parser<List<catdata.Pair<LocStr, String>>> ens = Parsers.tuple(token("entities"), env(ident, "->")).map(x -> x.b);
    Parser<Tuple3<List<LocStr>, List<catdata.Pair<LocStr, Triple<String, List<catdata.Pair<LocStr, List<String>>>, List<catdata.Pair<LocStr, Triple<String, String, RawTerm>>>>>>, List<catdata.Pair<String, String>>>> pa = Parsers.tuple(imports, Parsers.tuple(token("entity"), locstr.followedBy(token("->")), ident, fks.optional(), atts.optional()).map(x -> new catdata.Pair<>(x.b, new Triple<>(x.c, Util.newIfNull(x.d), Util.newIfNull(x.e)))).many(), options);
    Parser<Tuple5<Token, Token, SchExp<?, ?, ?, ?, ?>, SchExp<?, ?, ?, ?, ?>, Token>> l = Parsers.tuple(token("literal"), token(":"), sch_ref.lazy().followedBy(token("->")), sch_ref.lazy(), token("{"));
    // List<Pair<LocStr, Triple<String, List<Pair<LocStr, List<String>>>,
    // List<Pair<LocStr, Triple<String, String, RawTerm>>>>>> list,
    Parser<MapExpRaw> ret = Parsers.tuple(l, pa, token("}")).map(x -> new MapExpRaw(x.a.c, x.a.d, x.b.a, x.b.b, x.b.c));
    return ret;
}
Also used : AqlOptions(catdata.aql.AqlOptions) PragmaExpProc(catdata.aql.exp.PragmaExp.PragmaExpProc) Scanners(org.jparsec.Scanners) InstExpDelta(catdata.aql.exp.InstExp.InstExpDelta) GraphExpVar(catdata.aql.exp.GraphExp.GraphExpVar) GraphExpRaw(catdata.aql.exp.GraphExp.GraphExpRaw) StringLiteral(org.jparsec.Terminals.StringLiteral) EdsExpVar(catdata.aql.exp.EdsExp.EdsExpVar) SchExpInst(catdata.aql.exp.SchExp.SchExpInst) Pair(org.jparsec.functors.Pair) TransExpSigmaDeltaCounit(catdata.aql.exp.TransExp.TransExpSigmaDeltaCounit) QueryExpCompose(catdata.aql.exp.QueryExp.QueryExpCompose) PragmaExpConsistent(catdata.aql.exp.PragmaExp.PragmaExpConsistent) ParseException(catdata.ParseException) Quad(catdata.Quad) PragmaExpSql(catdata.aql.exp.PragmaExp.PragmaExpSql) SchExpVar(catdata.aql.exp.SchExp.SchExpVar) Parser(org.jparsec.Parser) InstExpColim(catdata.aql.exp.InstExp.InstExpColim) QueryExpDeltaCoEval(catdata.aql.exp.QueryExp.QueryExpDeltaCoEval) IntegerLiteral(org.jparsec.Terminals.IntegerLiteral) Program(catdata.Program) Triple(catdata.Triple) PragmaExpJs(catdata.aql.exp.PragmaExp.PragmaExpJs) PragmaExpCheck(catdata.aql.exp.PragmaExp.PragmaExpCheck) Ty(catdata.aql.exp.TyExpRaw.Ty) Terminals(org.jparsec.Terminals) PragmaExpMatch(catdata.aql.exp.PragmaExp.PragmaExpMatch) MapExpVar(catdata.aql.exp.MapExp.MapExpVar) TransExpDistinct(catdata.aql.exp.TransExp.TransExpDistinct) TyExpEmpty(catdata.aql.exp.TyExp.TyExpEmpty) TransExpVar(catdata.aql.exp.TransExp.TransExpVar) ColimSchExpQuotient(catdata.aql.exp.ColimSchExp.ColimSchExpQuotient) Token(org.jparsec.Token) PragmaExpToCsvInst(catdata.aql.exp.PragmaExp.PragmaExpToCsvInst) MapExpComp(catdata.aql.exp.MapExp.MapExpComp) InstExpCoEq(catdata.aql.exp.InstExp.InstExpCoEq) InstExpCod(catdata.aql.exp.InstExp.InstExpCod) InstExpCoProdFull(catdata.aql.exp.InstExp.InstExpCoProdFull) Att(catdata.aql.exp.SchExpRaw.Att) TransExpCoEvalEvalCoUnit(catdata.aql.exp.TransExp.TransExpCoEvalEvalCoUnit) TransExpDelta(catdata.aql.exp.TransExp.TransExpDelta) SchExpEmpty(catdata.aql.exp.SchExp.SchExpEmpty) ParserException(org.jparsec.error.ParserException) PragmaExpToJdbcTrans(catdata.aql.exp.PragmaExp.PragmaExpToJdbcTrans) Trans(catdata.aql.exp.QueryExpRaw.Trans) SchExpCod(catdata.aql.exp.SchExp.SchExpCod) InstExpChase(catdata.aql.exp.InstExp.InstExpChase) PragmaExpToJdbcQuery(catdata.aql.exp.PragmaExp.PragmaExpToJdbcQuery) InstExpFrozen(catdata.aql.exp.InstExp.InstExpFrozen) Sym(catdata.aql.exp.TyExpRaw.Sym) Tuple3(org.jparsec.functors.Tuple3) PragmaExpVar(catdata.aql.exp.PragmaExp.PragmaExpVar) Tuple4(org.jparsec.functors.Tuple4) Tuple5(org.jparsec.functors.Tuple5) InstExpAnonymize(catdata.aql.exp.InstExp.InstExpAnonymize) InstExpSigma(catdata.aql.exp.InstExp.InstExpSigma) TransExpEval(catdata.aql.exp.TransExp.TransExpEval) InstExpCoProdSigma(catdata.aql.exp.InstExp.InstExpCoProdSigma) InstExpVar(catdata.aql.exp.InstExp.InstExpVar) PreBlock(catdata.aql.exp.QueryExpRaw.PreBlock) TransExpSigmaDeltaUnit(catdata.aql.exp.TransExp.TransExpSigmaDeltaUnit) EdExpRaw(catdata.aql.exp.EdsExpRaw.EdExpRaw) Collectors(java.util.stream.Collectors) List(java.util.List) InstExpDom(catdata.aql.exp.InstExp.InstExpDom) Parsers(org.jparsec.Parsers) InstExpCoEval(catdata.aql.exp.InstExp.InstExpCoEval) TransExpSigma(catdata.aql.exp.TransExp.TransExpSigma) TransExpId(catdata.aql.exp.TransExp.TransExpId) MapExpId(catdata.aql.exp.MapExp.MapExpId) RawTerm(catdata.aql.RawTerm) En(catdata.aql.exp.SchExpRaw.En) InstExpSigmaChase(catdata.aql.exp.InstExp.InstExpSigmaChase) HashMap(java.util.HashMap) QueryExpDeltaEval(catdata.aql.exp.QueryExp.QueryExpDeltaEval) InstExpPi(catdata.aql.exp.InstExp.InstExpPi) ColimSchExpVar(catdata.aql.exp.ColimSchExp.ColimSchExpVar) ColimSchExpRaw(catdata.aql.exp.ColimSchExp.ColimSchExpRaw) PragmaExpLoadJars(catdata.aql.exp.PragmaExp.PragmaExpLoadJars) LinkedList(java.util.LinkedList) PragmaExpToCsvTrans(catdata.aql.exp.PragmaExp.PragmaExpToCsvTrans) Fk(catdata.aql.exp.SchExpRaw.Fk) TyExpSch(catdata.aql.exp.TyExp.TyExpSch) Reference(org.jparsec.Parser.Reference) ColimSchExpWrap(catdata.aql.exp.ColimSchExp.ColimSchExpWrap) Util(catdata.Util) QueryExpId(catdata.aql.exp.QueryExp.QueryExpId) QueryExpVar(catdata.aql.exp.QueryExp.QueryExpVar) InstExpEval(catdata.aql.exp.InstExp.InstExpEval) TransExpCoEval(catdata.aql.exp.TransExp.TransExpCoEval) TyExpVar(catdata.aql.exp.TyExp.TyExpVar) Identifier(org.jparsec.Terminals.Identifier) InstExpDistinct(catdata.aql.exp.InstExp.InstExpDistinct) PragmaExpToJdbcInst(catdata.aql.exp.PragmaExp.PragmaExpToJdbcInst) TransExpCoEvalEvalUnit(catdata.aql.exp.TransExp.TransExpCoEvalEvalUnit) Collections(java.util.Collections) InstExpEmpty(catdata.aql.exp.InstExp.InstExpEmpty) Token(org.jparsec.Token) RawTerm(catdata.aql.RawTerm) Triple(catdata.Triple) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) Pair(org.jparsec.functors.Pair)

Example 90 with Tuple3

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

the class CombinatorParser method instExpQuotient.

private static Parser<InstExpQuotient<?, ?>> instExpQuotient() {
    Parser<catdata.Pair<Integer, catdata.Pair<RawTerm, RawTerm>>> eq = Parsers.tuple(Parsers.INDEX, Parsers.tuple(term(), token("="), term())).map(x -> new catdata.Pair<>(x.a, new catdata.Pair<>(x.b.a, x.b.c)));
    Parser<List<catdata.Pair<Integer, catdata.Pair<RawTerm, RawTerm>>>> eqs = Parsers.tuple(token("equations"), eq.many()).map(x -> x.b);
    Parser<List<catdata.Pair<Integer, catdata.Pair<RawTerm, RawTerm>>>> table = Parsers.tuple(Parsers.INDEX, Parsers.tuple(ident, token("->"), token("{"), Parsers.tuple(term(), term()).sepBy(token(",")), token("}"))).map(x -> {
        List<catdata.Pair<Integer, catdata.Pair<RawTerm, RawTerm>>> ret = new LinkedList<>();
        for (Pair<RawTerm, RawTerm> y : x.b.d) {
            ret.add(new catdata.Pair<>(x.a, new catdata.Pair<>(new RawTerm(x.b.a, Util.singList(y.a)), y.b)));
        }
        return ret;
    });
    Parser<List<catdata.Pair<Integer, catdata.Pair<RawTerm, RawTerm>>>> tables = Parsers.tuple(token("multi_equations"), table.many()).map(x -> Util.concat(x.b));
    Parser<Tuple3<List<catdata.Pair<Integer, catdata.Pair<RawTerm, RawTerm>>>, List<catdata.Pair<Integer, catdata.Pair<RawTerm, RawTerm>>>, List<catdata.Pair<String, String>>>> pa = Parsers.tuple(eqs.optional(), tables.optional(), options);
    Parser<Tuple3<Token, InstExp<?, ?, ?, ?, ?, ?, ?, ?, ?>, Token>> l = Parsers.tuple(token("quotient"), inst_ref.lazy(), // .map(x -> x.c);
    token("{"));
    Parser<InstExpQuotient<?, ?>> ret = Parsers.tuple(l, pa, token("}")).map(x -> new InstExpQuotient(x.a.b, new LinkedList<>(Util.append(Util.newIfNull(x.b.a), Util.newIfNull(x.b.b))), x.b.c));
    return ret;
}
Also used : RawTerm(catdata.aql.RawTerm) LinkedList(java.util.LinkedList) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) Pair(org.jparsec.functors.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