Search in sources :

Example 6 with Token

use of org.jparsec.Token in project fql by CategoricalData.

the class FQLParser method toInst.

@SuppressWarnings("rawtypes")
private static InstExp toInst(Object o) {
    try {
        Tuple4 t = (Tuple4) o;
        Token z = (Token) t.a;
        String y = z.toString();
        if (y.equals("step")) {
            return new Step(t.d.toString(), toMapping(t.b), toMapping(t.c));
        }
    } catch (RuntimeException cce) {
    }
    try {
        Tuple3 t = (Tuple3) o;
        Token z = (Token) t.a;
        String y = z.toString();
        switch(y) {
            case "delta":
                return new InstExp.Delta(toMapping(t.b), t.c.toString());
            case "sigma":
                return new InstExp.Sigma(toMapping(t.b), t.c.toString());
            case "SIGMA":
                return new FullSigma(toMapping(t.b), t.c.toString());
            case "pi":
                return new InstExp.Pi(toMapping(t.b), t.c.toString());
            case "external":
                return new External(toSchema(t.b), t.c.toString());
            case "eval":
                return new Eval(toQuery(t.b), t.c.toString());
            case "EVAL":
                return new FullEval(toFullQuery(t.b), t.c.toString());
            default:
                break;
        }
    } catch (RuntimeException cce) {
    }
    try {
        Tuple3 t = (Tuple3) o;
        Token z = (Token) t.b;
        String y = z.toString();
        if (y.equals("+")) {
            return new Plus(t.a.toString(), t.c.toString());
        } else if (y.equals("*")) {
            return new Times(t.a.toString(), t.c.toString());
        }
        if (y.equals("^")) {
            return new Exp(t.a.toString(), (t.c).toString());
        }
    } catch (RuntimeException cce) {
    }
    try {
        org.jparsec.functors.Pair pr = (org.jparsec.functors.Pair) o;
        if (pr.a.toString().equals("unit")) {
            return new One(toSchema(pr.b));
        } else if (pr.a.toString().equals("void")) {
            return new Zero(toSchema(pr.b));
        } else if (pr.a.toString().equals("prop")) {
            return new Two(toSchema(pr.b));
        } else if (pr.a.toString().equals("relationalize")) {
            return new Relationalize(pr.b.toString());
        } else if (pr.a.toString().equals("kernel")) {
            return new Kernel(pr.b.toString());
        }
        throw new RuntimeException();
    } catch (RuntimeException cce) {
    }
    return toInstConst(o);
}
Also used : FullEval(catdata.fql.decl.InstExp.FullEval) Sigma(catdata.fql.decl.FullQueryExp.Sigma) FullSigma(catdata.fql.decl.InstExp.FullSigma) One(catdata.fql.decl.InstExp.One) Token(org.jparsec.Token) Step(catdata.fql.decl.InstExp.Step) Pi(catdata.fql.decl.FullQueryExp.Pi) Plus(catdata.fql.decl.InstExp.Plus) TransEval(catdata.fql.decl.TransExp.TransEval) FullEval(catdata.fql.decl.InstExp.FullEval) Eval(catdata.fql.decl.InstExp.Eval) Kernel(catdata.fql.decl.InstExp.Kernel) Pair(catdata.Pair) Relationalize(catdata.fql.decl.InstExp.Relationalize) Zero(catdata.fql.decl.InstExp.Zero) Two(catdata.fql.decl.InstExp.Two) Tuple4(org.jparsec.functors.Tuple4) Delta(catdata.fql.decl.FullQueryExp.Delta) Tuple3(org.jparsec.functors.Tuple3) Times(catdata.fql.decl.InstExp.Times) External(catdata.fql.decl.InstExp.External) FullSigma(catdata.fql.decl.InstExp.FullSigma) FullQueryExp(catdata.fql.decl.FullQueryExp) Exp(catdata.fql.decl.InstExp.Exp) MapExp(catdata.fql.decl.MapExp) TransExp(catdata.fql.decl.TransExp) QueryExp(catdata.fql.decl.QueryExp) SigExp(catdata.fql.decl.SigExp) InstExp(catdata.fql.decl.InstExp)

Example 7 with Token

use of org.jparsec.Token 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)

Aggregations

Token (org.jparsec.Token)7 Tuple3 (org.jparsec.functors.Tuple3)7 Tuple4 (org.jparsec.functors.Tuple4)5 Quad (catdata.Quad)4 RawTerm (catdata.aql.RawTerm)4 ColimSchExpRaw (catdata.aql.exp.ColimSchExp.ColimSchExpRaw)4 GraphExpRaw (catdata.aql.exp.GraphExp.GraphExpRaw)4 LinkedList (java.util.LinkedList)4 List (java.util.List)4 Pair (org.jparsec.functors.Pair)4 Tuple5 (org.jparsec.functors.Tuple5)4 ParseException (catdata.ParseException)3 Program (catdata.Program)3 Triple (catdata.Triple)3 Util (catdata.Util)3 AqlOptions (catdata.aql.AqlOptions)3 ColimSchExpQuotient (catdata.aql.exp.ColimSchExp.ColimSchExpQuotient)3 ColimSchExpVar (catdata.aql.exp.ColimSchExp.ColimSchExpVar)3 ColimSchExpWrap (catdata.aql.exp.ColimSchExp.ColimSchExpWrap)3 EdsExpVar (catdata.aql.exp.EdsExp.EdsExpVar)3