Search in sources :

Example 16 with Parser

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

the class FQLParser method fullQuery.

// add identity query
@SuppressWarnings({ "rawtypes", "unchecked" })
private static Parser<?> fullQuery() {
    Reference ref = Parser.newReference();
    Parser p1 = Parsers.tuple(term("delta"), mapping());
    Parser p2 = Parsers.tuple(term("pi"), mapping());
    Parser p3 = Parsers.tuple(term("SIGMA"), mapping());
    Parser comp = Parsers.tuple(term("("), ref.lazy(), term("then"), ref.lazy(), term(")"));
    Parser zzz = Parsers.tuple(ident(), term(","), ident());
    Parser yyy = Parsers.between(term("("), zzz, term(")"));
    Parser xxx = Parsers.between(term("{"), yyy.sepBy(term(",")), term("}"));
    Parser mtch = Parsers.tuple(term("match"), xxx, schema(), schema(), StringLiteral.PARSER);
    Parser ret = Parsers.or(p1, p2, p3, comp, ident(), mtch);
    ref.set(ret);
    return ret;
}
Also used : Reference(org.jparsec.Parser.Reference) Parser(org.jparsec.Parser)

Example 17 with Parser

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

the class FQLParser method transform.

@SuppressWarnings({ "rawtypes", "unchecked" })
private static Parser<?> transform() {
    Reference ref = Parser.newReference();
    Parser plusTy = Parsers.tuple(ident(), term("."), Parsers.between(term("("), Parsers.tuple(ref.lazy(), term("+"), ref.lazy()), term(")")));
    Parser prodTy = Parsers.tuple(ident(), term("."), Parsers.between(term("("), Parsers.tuple(ref.lazy(), term("*"), ref.lazy()), term(")")));
    Parser compTy = Parsers.between(term("("), Parsers.tuple(ref.lazy(), term("then"), ref.lazy()), term(")"));
    Parser a = Parsers.or(Parsers.tuple(term("external"), ident(), ident(), ident()), Parsers.tuple(ident(), term("."), term("char"), ident()), Parsers.tuple(ident(), term("."), term("kernel")), Parsers.tuple(ident(), term("."), term("unit"), ident()), Parsers.tuple(ident(), term("."), term("void"), ident()), Parsers.tuple(ident(), term("."), term("curry"), ident()), Parsers.tuple(ident(), term("."), term("fst")), Parsers.tuple(ident(), term("."), term("not")), Parsers.tuple(ident(), term("."), term("and")), Parsers.tuple(ident(), term("."), term("or")), Parsers.tuple(ident(), term("."), term("implies")), Parsers.tuple(ident(), term("."), term("return")), Parsers.tuple(ident(), term("."), term("coreturn")), Parsers.tuple(ident(), term("."), term("snd")), Parsers.tuple(ident(), term("."), term("eval")), Parsers.tuple(ident(), term("."), term("true"), ident()), Parsers.tuple(ident(), term("."), term("false"), ident()), Parsers.tuple(ident(), term("."), term("inl")), Parsers.tuple(ident(), term("."), term("inr")), Parsers.tuple(term("iso1"), ident(), ident()), Parsers.tuple(term("iso2"), ident(), ident()), Parsers.tuple(ident(), term("."), term("relationalize")), Parsers.tuple(term("delta"), ident(), ident(), ref.lazy()), Parsers.tuple(term("sigma"), ident(), ident(), ref.lazy()), Parsers.tuple(term("SIGMA"), ident(), ident(), ident()), Parsers.tuple(term("pi"), ident(), ident(), ref.lazy()), Parsers.tuple(term("relationalize"), ident(), ident(), ref.lazy()), // Parsers.tuple(term("eq"), sig()),
    Parsers.tuple(term("id"), ident()), // Parsers.tuple(term("dist2"), sig(), sig(), sig()), compTy,
    compTy, plusTy, prodTy, ident(), transConst());
    ref.set(a);
    return a;
}
Also used : Reference(org.jparsec.Parser.Reference) Parser(org.jparsec.Parser)

Example 18 with Parser

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

the class PPParser method trans.

private static Parser<?> trans() {
    Reference ref = Parser.newReference();
    Parser compTy = Parsers.between(term("("), Parsers.tuple(ref.lazy(), term(";"), ref.lazy()), term(")"));
    Parser prodTy = Parsers.between(term("("), Parsers.tuple(ref.lazy(), term("*"), ref.lazy()), term(")"));
    Parser sumTy = Parsers.between(term("("), Parsers.tuple(ref.lazy(), term("+"), ref.lazy()), term(")"));
    // ////
    Parser<?> node = Parsers.tuple(ident(), term("->"), fn());
    Parser s2 = Parsers.tuple(ftr(), term(":"), term("Set"), term("->"), term("Set"));
    Parser s1 = Parsers.between(term("("), s2, term(")"));
    Parser<?> setset = Parsers.tuple(Parsers.between(term("{"), section2("objects", node), term("}")), term(":"), s1, term("->"), s1);
    // ///
    Parser<?> node2 = Parsers.tuple(ident(), term("->"), fn().or(setOfPairs()));
    Parser x2 = Parsers.tuple(ftr(), term(":"), cat(), term("->"), term("Set"));
    Parser x1 = Parsers.between(term("("), x2, term(")"));
    Parser<?> toset = Parsers.tuple(Parsers.between(term("{"), section("objects", node2), term("}")), term(":"), x1, term("->"), x1);
    // ///
    Parser nd = Parsers.tuple(ident(), term("->"), ftr());
    Parser t2 = Parsers.tuple(ftr(), term(":"), cat(), term("->"), term("Cat"));
    Parser t1 = Parsers.between(term("("), t2, term(")"));
    Parser<?> tocat = Parsers.tuple(Parsers.between(term("{"), section("objects", nd), term("}")), term(":"), t1, term("->"), t1);
    // ///
    Parser edX = Parsers.tuple(ident(), term("->"), ref.lazy());
    Parser uip = term("Cat");
    Parser piu = term("Set");
    Parser u2X = Parsers.tuple(ftr(), term(":"), cat(), term("->"), Parsers.between(term("("), Parsers.tuple(uip.or(piu), term("^"), cat()), term(")")));
    Parser u1X = Parsers.between(term("("), u2X, term(")"));
    Parser<?> tofinal = Parsers.tuple(Parsers.between(term("{"), section("objects", edX), term("}")), term(":"), u1X, term("->"), u1X);
    // ///
    Parser ed = Parsers.tuple(ident(), term("->"), path());
    Parser u2 = Parsers.tuple(ftr(), term(":"), cat(), term("->"), cat());
    Parser u1 = Parsers.between(term("("), u2, term(")"));
    Parser<?> tomap = Parsers.tuple(Parsers.between(term("{"), section("objects", ed), term("}")), term(":"), u1, term("->"), u1);
    Parser a = Parsers.or(ident(), Parsers.tuple(term("id"), ftr()), tofinal, compTy, setset, toset, tocat, tomap, Parsers.tuple(term("tt"), ref.lazy()), Parsers.tuple(term("not"), cat()), Parsers.tuple(term("and"), cat()), Parsers.tuple(term("or"), cat()), Parsers.tuple(term("implies"), cat()), Parsers.tuple(term("char"), ref.lazy()), Parsers.tuple(term("kernel"), ref.lazy()), Parsers.tuple(term("fst"), ftr(), ftr()), Parsers.tuple(term("snd"), ftr(), ftr()), Parsers.tuple(term("ff"), ref.lazy()), Parsers.tuple(term("curry"), ref.lazy()), Parsers.tuple(term("CURRY"), ref.lazy()), Parsers.tuple(term("return"), term("sigma"), term("delta"), ftr()), Parsers.tuple(term("coreturn"), term("sigma"), term("delta"), ftr()), Parsers.tuple(term("return"), term("delta"), term("pi"), ftr()), Parsers.tuple(term("coreturn"), term("delta"), term("pi"), ftr()), Parsers.tuple(term("apply"), ftr(), term("on"), term("arrow"), ref.lazy()), Parsers.tuple(term("apply"), ftr(), term("on"), term("path"), Parsers.tuple(path(), term("in"), cat())), Parsers.tuple(term("APPLY"), ref.lazy(), term("on"), ident()), Parsers.tuple(term("apply"), ref.lazy(), term("on"), ftr()), Parsers.tuple(term("left"), term("whisker"), ftr(), ref.lazy()), Parsers.tuple(term("right"), term("whisker"), ftr(), ref.lazy()), Parsers.tuple(term("inl"), ftr(), ftr()), Parsers.tuple(term("inr"), ftr(), ftr()), Parsers.tuple(term("eval"), ftr(), ftr()), Parsers.tuple(term("iso1"), ftr(), ftr()), Parsers.tuple(term("iso2"), ftr(), ftr()), Parsers.tuple(term("true"), cat()), Parsers.tuple(term("false"), cat()), prodTy, sumTy);
    ref.set(a);
    return a;
}
Also used : Reference(org.jparsec.Parser.Reference) Parser(org.jparsec.Parser)

Example 19 with Parser

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

the class PPParser method fn.

private static Parser<?> fn() {
    Reference ref = Parser.newReference();
    Parser plusTy = Parsers.between(term("("), Parsers.tuple(ref.lazy(), term("+"), ref.lazy()), term(")"));
    Parser prodTy = Parsers.between(term("("), Parsers.tuple(ref.lazy(), term("*"), ref.lazy()), term(")"));
    Parser compTy = Parsers.between(term("("), Parsers.tuple(ref.lazy(), term(";"), ref.lazy()), term(")"));
    Parser<?> app2 = Parsers.tuple(term("apply"), ident(), set());
    Parser<?> app = Parsers.tuple(term("apply"), ident(), term("on"), term("arrow"), ref.lazy());
    Parser a = Parsers.or(term("true"), term("false"), term("and"), term("or"), term("not"), term("implies"), Parsers.tuple(term("tt"), set()), Parsers.tuple(term("ff"), set()), Parsers.tuple(term("iso1"), set(), set()), Parsers.tuple(term("iso2"), set(), set()), Parsers.tuple(term("fst"), set(), set()), Parsers.tuple(term("snd"), set(), set()), Parsers.tuple(term("inl"), set(), set()), Parsers.tuple(term("inr"), set(), set()), Parsers.tuple(term("eval"), set(), set()), Parsers.tuple(term("curry"), ref.lazy()), Parsers.tuple(term("char"), ref.lazy()), Parsers.tuple(term("kernel"), ref.lazy()), Parsers.tuple(term("id"), set()), compTy, plusTy, prodTy, ident(), fnConst(), app, app2);
    ref.set(a);
    return a;
}
Also used : Reference(org.jparsec.Parser.Reference) Parser(org.jparsec.Parser)

Example 20 with Parser

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

the class OplParser method oplSequent.

private static Parser<?> oplSequent() {
    Parser<?> p1 = Parsers.tuple(ident(), term(":"), ident());
    Parser<?> z = Parsers.longest(p1, ident());
    Parser<?> p = z.sepBy(term(","));
    Parser a = Parsers.tuple(term("forall"), p, term("."));
    Parser retX = Parsers.tuple(a.optional(), oplTerm());
    return retX;
}
Also used : Parser(org.jparsec.Parser)

Aggregations

Parser (org.jparsec.Parser)38 Reference (org.jparsec.Parser.Reference)15 InstExpAnonymize (catdata.aql.exp.InstExp.InstExpAnonymize)4 InstExpChase (catdata.aql.exp.InstExp.InstExpChase)4 InstExpCoEval (catdata.aql.exp.InstExp.InstExpCoEval)4 InstExpCoProdFull (catdata.aql.exp.InstExp.InstExpCoProdFull)4 InstExpCod (catdata.aql.exp.InstExp.InstExpCod)4 InstExpDelta (catdata.aql.exp.InstExp.InstExpDelta)4 InstExpDistinct (catdata.aql.exp.InstExp.InstExpDistinct)4 InstExpDom (catdata.aql.exp.InstExp.InstExpDom)4 InstExpEval (catdata.aql.exp.InstExp.InstExpEval)4 InstExpFrozen (catdata.aql.exp.InstExp.InstExpFrozen)4 InstExpPi (catdata.aql.exp.InstExp.InstExpPi)4 InstExpSigma (catdata.aql.exp.InstExp.InstExpSigma)4 InstExpSigmaChase (catdata.aql.exp.InstExp.InstExpSigmaChase)4 InstExpVar (catdata.aql.exp.InstExp.InstExpVar)4 ParseException (catdata.ParseException)3 Program (catdata.Program)3 Quad (catdata.Quad)3 Triple (catdata.Triple)3