Search in sources :

Example 1 with Pair

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

the class CombinatorParser method pragmaExp.

@SuppressWarnings({ "rawtypes", "unchecked" })
private static void pragmaExp() {
    Parser<Pair<List<String>, List<catdata.Pair<String, String>>>> p = Parsers.tuple(ident.many(), options).between(token("{"), token("}"));
    Parser<PragmaExp> var = ident.map(PragmaExpVar::new), csvInst = Parsers.tuple(token("export_csv_instance"), inst_ref.lazy(), ident, options.between(token("{"), token("}")).optional()).map(x -> new PragmaExpToCsvInst(x.b, x.c, x.d == null ? new LinkedList<>() : x.d)), csvTrans = Parsers.tuple(token("export_csv_transform"), trans_ref.lazy(), ident, options.between(token("{"), token("}")).optional(), options.between(token("{"), token("}")).optional()).map(x -> new PragmaExpToCsvTrans(x.b, x.c, x.d == null ? new LinkedList<>() : x.d, x.e == null ? new LinkedList<>() : x.e)), sql = Parsers.tuple(token("exec_jdbc"), ident, ident, p).map(x -> new PragmaExpSql(x.b, x.c, x.d.a, x.d.b)), js = Parsers.tuple(token("exec_js"), p).map(x -> new PragmaExpJs(x.b.a, x.b.b)), proc = Parsers.tuple(token("exec_cmdline"), p).map(x -> new PragmaExpProc(x.b.a, x.b.b)), jdbcInst = Parsers.tuple(Parsers.tuple(token("export_jdbc_instance"), inst_ref.lazy()), ident, ident, ident, options.between(token("{"), token("}")).optional()).map(x -> new PragmaExpToJdbcInst(x.a.b, x.b, x.c, x.d, x.e == null ? new LinkedList<>() : x.e)), jdbcQuery = Parsers.tuple(Parsers.tuple(token("export_jdbc_query"), query_ref.lazy()), Parsers.tuple(ident, ident, ident, ident), options.between(token("{"), token("}")).optional()).map(x -> new PragmaExpToJdbcQuery(x.a.b, x.b.a, x.b.b, x.b.c, x.b.d, x.c == null ? new LinkedList<>() : x.c)), jdbcTrans = Parsers.tuple(Parsers.tuple(token("export_jdbc_transform"), trans_ref.lazy()), ident, ident, ident, Parsers.tuple(options.between(token("{"), token("}")).optional(), options.between(token("{"), token("}")).optional())).map(x -> new PragmaExpToJdbcTrans(x.a.b, x.b, x.c, x.d, x.e.a == null ? new LinkedList<>() : x.e.a, x.e.b == null ? new LinkedList<>() : x.e.b)), match = Parsers.tuple(token("match"), ident.followedBy(token(":")), graph_ref.lazy().followedBy(token("->")), graph_ref.lazy(), options.between(token("{"), token("}")).optional()).map(x -> new PragmaExpMatch(x.b, x.c, x.d, x.e == null ? new LinkedList<>() : x.e)), load = Parsers.tuple(token("add_to_classpath"), token("{"), ident.many(), token("}")).map(x -> new PragmaExpLoadJars(x.c)), check = Parsers.tuple(token("check"), edsExp(), inst_ref.lazy()).map(x -> new PragmaExpCheck(x.c, x.b)), cons = Parsers.tuple(token("assert_consistent"), inst_ref.lazy()).map(x -> new PragmaExpConsistent(x.b)), ret = Parsers.or(jdbcQuery, check, csvInst, cons, csvTrans, var, sql, js, proc, jdbcInst, jdbcTrans, match, load, parens(pragma_ref));
    pragma_ref.set(ret);
}
Also used : PragmaExpLoadJars(catdata.aql.exp.PragmaExp.PragmaExpLoadJars) PragmaExpToJdbcInst(catdata.aql.exp.PragmaExp.PragmaExpToJdbcInst) PragmaExpVar(catdata.aql.exp.PragmaExp.PragmaExpVar) PragmaExpToJdbcQuery(catdata.aql.exp.PragmaExp.PragmaExpToJdbcQuery) PragmaExpSql(catdata.aql.exp.PragmaExp.PragmaExpSql) PragmaExpProc(catdata.aql.exp.PragmaExp.PragmaExpProc) PragmaExpCheck(catdata.aql.exp.PragmaExp.PragmaExpCheck) PragmaExpJs(catdata.aql.exp.PragmaExp.PragmaExpJs) PragmaExpToCsvTrans(catdata.aql.exp.PragmaExp.PragmaExpToCsvTrans) PragmaExpMatch(catdata.aql.exp.PragmaExp.PragmaExpMatch) PragmaExpToJdbcTrans(catdata.aql.exp.PragmaExp.PragmaExpToJdbcTrans) PragmaExpConsistent(catdata.aql.exp.PragmaExp.PragmaExpConsistent) PragmaExpToCsvInst(catdata.aql.exp.PragmaExp.PragmaExpToCsvInst) Pair(org.jparsec.functors.Pair)

Example 2 with Pair

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

the class CombinatorParser method instExpRaw.

private static Parser<InstExpRaw> instExpRaw() {
    Parser<List<catdata.Pair<LocStr, String>>> generators = Parsers.tuple(token("generators"), env(ident, ":")).map(x -> x.b);
    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<Tuple5<List<LocStr>, List<catdata.Pair<LocStr, String>>, List<catdata.Pair<Integer, catdata.Pair<RawTerm, RawTerm>>>, List<catdata.Pair<Integer, catdata.Pair<RawTerm, RawTerm>>>, List<catdata.Pair<String, String>>>> pa = Parsers.tuple(imports, generators.optional(), eqs.optional(), tables.optional(), options);
    Parser<Tuple4<Token, Token, SchExp<?, ?, ?, ?, ?>, Token>> l = Parsers.tuple(token("literal"), token(":"), sch_ref.lazy(), // .map(x -> x.c);
    token("{"));
    Parser<InstExpRaw> ret = Parsers.tuple(l, pa, token("}")).map(x -> new InstExpRaw(x.a.c, Util.newIfNull(x.b.a), Util.newIfNull(x.b.b), new LinkedList<>(Util.append(Util.newIfNull(x.b.c), Util.newIfNull(x.b.d))), x.b.e));
    return ret;
}
Also used : RawTerm(catdata.aql.RawTerm) LinkedList(java.util.LinkedList) Tuple4(org.jparsec.functors.Tuple4) Tuple5(org.jparsec.functors.Tuple5) List(java.util.List) LinkedList(java.util.LinkedList) Pair(org.jparsec.functors.Pair)

Example 3 with Pair

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

the class CombinatorParser method graphExpRaw.

private static Parser<GraphExpRaw> graphExpRaw() {
    Parser<List<LocStr>> nodes = Parsers.tuple(token("nodes"), locstr.many()).map(x -> x.b);
    Parser<Pair<Token, List<Tuple5<List<LocStr>, Token, String, Token, String>>>> edges = Parsers.tuple(token("edges"), Parsers.tuple(locstr.many1(), token(":"), ident, token("->"), ident).many());
    Parser<List<catdata.Pair<LocStr, catdata.Pair<String, String>>>> edges0 = edges.map(x -> {
        List<catdata.Pair<LocStr, catdata.Pair<String, String>>> ret = new LinkedList<>();
        for (Tuple5<List<LocStr>, Token, String, Token, String> a : x.b) {
            for (LocStr b : a.a) {
                ret.add(new catdata.Pair<>(b, new catdata.Pair<>(a.c, a.e)));
            }
        }
        return ret;
    });
    Parser<Tuple3<List<LocStr>, List<LocStr>, List<catdata.Pair<LocStr, catdata.Pair<String, String>>>>> pa = Parsers.tuple(imports, nodes.optional(), edges0.optional());
    Parser<GraphExpRaw> ret = pa.map(x -> new GraphExpRaw(Util.newIfNull(x.b), Util.newIfNull(x.c), x.a));
    return ret.between(token("literal").followedBy(token("{")), token("}"));
}
Also used : Token(org.jparsec.Token) LinkedList(java.util.LinkedList) GraphExpRaw(catdata.aql.exp.GraphExp.GraphExpRaw) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) Pair(org.jparsec.functors.Pair)

Example 4 with Pair

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

the class CombinatorParser method schExpRaw.

private static Parser<SchExpRaw> schExpRaw() {
    Parser<List<LocStr>> entities = Parsers.tuple(token("entities"), locstr.many()).map(x -> x.b);
    Parser<Pair<Token, List<Tuple5<List<LocStr>, Token, String, Token, String>>>> fks = Parsers.tuple(token("foreign_keys"), Parsers.tuple(locstr.many1(), token(":"), ident, token("->"), ident).many());
    Parser<List<catdata.Pair<LocStr, catdata.Pair<String, String>>>> fks0 = fks.map(x -> {
        List<catdata.Pair<LocStr, catdata.Pair<String, String>>> ret = new LinkedList<>();
        for (Tuple5<List<LocStr>, Token, String, Token, String> a : x.b) {
            for (LocStr b : a.a) {
                ret.add(new catdata.Pair<>(b, new catdata.Pair<>(a.c, a.e)));
            }
        }
        return ret;
    });
    Parser<Pair<Token, List<Tuple5<List<LocStr>, Token, String, Token, String>>>> atts = Parsers.tuple(token("attributes"), Parsers.tuple(locstr.many1(), token(":"), ident, token("->"), ident).many());
    Parser<List<catdata.Pair<LocStr, catdata.Pair<String, String>>>> atts0 = atts.map(x -> {
        List<catdata.Pair<LocStr, catdata.Pair<String, String>>> ret = new LinkedList<>();
        for (Tuple5<List<LocStr>, Token, String, Token, String> a : x.b) {
            for (LocStr b : a.a) {
                ret.add(new catdata.Pair<>(b, new catdata.Pair<>(a.c, a.e)));
            }
        }
        return ret;
    });
    Parser<catdata.Pair<Integer, catdata.Pair<List<String>, List<String>>>> p_eq = Parsers.tuple(Parsers.INDEX, Parsers.tuple(ident.sepBy(token(".")), token("="), ident.sepBy(token(".")))).map(x -> new catdata.Pair<>(x.a, new catdata.Pair<>(x.b.a, x.b.c)));
    Parser<Pair<Token, List<catdata.Pair<Integer, catdata.Pair<List<String>, List<String>>>>>> p_eqs = Parsers.tuple(token("path_equations"), p_eq.many());
    Parser<List<catdata.Pair<Integer, catdata.Pair<List<String>, List<String>>>>> p_eqs0 = p_eqs.map(x -> x.b);
    Parser<catdata.Pair<Integer, Quad<String, String, RawTerm, RawTerm>>> o_eq_from_p_eq = p_eq.map(x -> new catdata.Pair<>(x.first, new Quad<>("_x", null, RawTerm.fold(x.second.first, "_x"), RawTerm.fold(x.second.second, "_x"))));
    Parser<catdata.Pair<Integer, Quad<String, String, RawTerm, RawTerm>>> o_eq_old = Parsers.tuple(Parsers.INDEX, Parsers.tuple(token("forall"), ident, Parsers.tuple(token(":"), ident).optional().followedBy(token(".")), term().followedBy(token("=")), term())).map(x -> new catdata.Pair<>(x.a, new Quad<>(x.b.b, x.b.c == null ? null : x.b.c.b, x.b.d, x.b.e)));
    Parser<catdata.Pair<Integer, Quad<String, String, RawTerm, RawTerm>>> o_eq = Parsers.or(o_eq_old, o_eq_from_p_eq);
    Parser<Pair<Token, List<catdata.Pair<Integer, Quad<String, String, RawTerm, RawTerm>>>>> o_eqs = Parsers.tuple(token("observation_equations"), o_eq.many());
    Parser<List<catdata.Pair<Integer, Quad<String, String, RawTerm, RawTerm>>>> o_eqs0 = o_eqs.map(x -> x.b);
    Parser<Tuple4<List<LocStr>, List<LocStr>, List<catdata.Pair<LocStr, catdata.Pair<String, String>>>, List<catdata.Pair<Integer, catdata.Pair<List<String>, List<String>>>>>> pa = Parsers.tuple(imports, entities.optional(), fks0.optional(), p_eqs0.optional());
    Parser<Tuple3<List<catdata.Pair<LocStr, catdata.Pair<String, String>>>, List<catdata.Pair<Integer, Quad<String, String, RawTerm, RawTerm>>>, List<catdata.Pair<String, String>>>> pb = Parsers.tuple(atts0.optional(), o_eqs0.optional(), options);
    Parser<Tuple4<Token, Token, TyExp<?, ?>, Token>> l = Parsers.tuple(token("literal"), token(":"), ty_ref.lazy(), // .map(x -> x.c);
    token("{"));
    // needs tyexp
    Parser<SchExpRaw> ret = Parsers.tuple(l, pa, pb, token("}")).map(x -> new SchExpRaw((TyExp<Ty, Sym>) x.a.c, x.b.a, Util.newIfNull(x.b.b), Util.newIfNull(x.b.c), Util.newIfNull(x.b.d), Util.newIfNull(x.c.a), Util.newIfNull(x.c.b), x.c.c));
    return ret;
}
Also used : Quad(catdata.Quad) Token(org.jparsec.Token) List(java.util.List) LinkedList(java.util.LinkedList) Pair(org.jparsec.functors.Pair) RawTerm(catdata.aql.RawTerm) LinkedList(java.util.LinkedList) Tuple4(org.jparsec.functors.Tuple4) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) ColimSchExpRaw(catdata.aql.exp.ColimSchExp.ColimSchExpRaw)

Example 5 with Pair

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

the class CombinatorParser method trans.

private static Parser<Trans> trans() {
    Parser<List<catdata.Pair<LocStr, RawTerm>>> gens = env(term(), "->");
    // Parser<List<catdata.Pair<LocStr, RawTerm>>> gens2 =
    // env_backwards(term(), "<-");
    // Parser<List<catdata.Pair<LocStr, RawTerm>>> gens = Parsers.or(gens2,
    // gens1);
    Parser<Pair<List<catdata.Pair<LocStr, RawTerm>>, List<catdata.Pair<String, String>>>> pa = Parsers.tuple(gens.optional(), options);
    Parser<Trans> ret = Parsers.tuple(token("{"), pa, token("}")).map(x -> new Trans(Util.newIfNull(x.b.a), x.b.b));
    return ret;
}
Also used : List(java.util.List) LinkedList(java.util.LinkedList) RawTerm(catdata.aql.RawTerm) PragmaExpToJdbcTrans(catdata.aql.exp.PragmaExp.PragmaExpToJdbcTrans) Trans(catdata.aql.exp.QueryExpRaw.Trans) PragmaExpToCsvTrans(catdata.aql.exp.PragmaExp.PragmaExpToCsvTrans) Pair(org.jparsec.functors.Pair)

Aggregations

Pair (org.jparsec.functors.Pair)7 LinkedList (java.util.LinkedList)6 List (java.util.List)6 RawTerm (catdata.aql.RawTerm)5 Tuple3 (org.jparsec.functors.Tuple3)4 PragmaExpToCsvTrans (catdata.aql.exp.PragmaExp.PragmaExpToCsvTrans)3 PragmaExpToJdbcTrans (catdata.aql.exp.PragmaExp.PragmaExpToJdbcTrans)3 Tuple5 (org.jparsec.functors.Tuple5)3 Quad (catdata.Quad)2 ColimSchExpRaw (catdata.aql.exp.ColimSchExp.ColimSchExpRaw)2 GraphExpRaw (catdata.aql.exp.GraphExp.GraphExpRaw)2 Trans (catdata.aql.exp.QueryExpRaw.Trans)2 Token (org.jparsec.Token)2 Tuple4 (org.jparsec.functors.Tuple4)2 ParseException (catdata.ParseException)1 Program (catdata.Program)1 Triple (catdata.Triple)1 Util (catdata.Util)1 AqlOptions (catdata.aql.AqlOptions)1 ColimSchExpQuotient (catdata.aql.exp.ColimSchExp.ColimSchExpQuotient)1