Search in sources :

Example 11 with Reference

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

the class FQLParser method instance.

@SuppressWarnings({ "rawtypes", "unchecked" })
private static Parser<?> instance() {
    Reference ref = Parser.newReference();
    Parser plusTy = Parsers.between(term("("), Parsers.tuple(ident(), term("+"), ident()), term(")"));
    Parser prodTy = Parsers.between(term("("), Parsers.tuple(ident(), term("*"), ident()), term(")"));
    Parser expTy = Parsers.between(term("("), Parsers.tuple(ident(), term("^"), ident()), term(")"));
    Parser<?> external = Parsers.tuple(term("external"), ident(), schema());
    Parser<?> delta = Parsers.tuple(term("delta"), mapping(), ident());
    Parser<?> sigma = Parsers.tuple(term("sigma"), mapping(), ident());
    Parser<?> pi = Parsers.tuple(term("pi"), mapping(), ident());
    Parser<?> SIGMA = Parsers.tuple(term("SIGMA"), mapping(), ident());
    Parser<?> relationalize = Parsers.tuple(term("relationalize"), ident());
    Parser<?> eval = Parsers.tuple(term("eval"), query(), ident());
    Parser<?> fullEval = Parsers.tuple(term("EVAL"), fullQuery(), ident());
    Parser<?> step = Parsers.tuple(term("step"), mapping(), mapping(), ident());
    Parser a = Parsers.or(Parsers.tuple(term("kernel"), ident()), Parsers.tuple(term("prop"), schema()), Parsers.tuple(term("void"), schema()), Parsers.tuple(term("unit"), schema()), plusTy, prodTy, expTy, /* ident(), */
    instanceConst(), delta, sigma, pi, SIGMA, external, relationalize, eval, fullEval, step);
    ref.set(a);
    return a;
}
Also used : Reference(org.jparsec.Parser.Reference) Parser(org.jparsec.Parser)

Example 12 with Reference

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

the class FQLParser method schema.

@SuppressWarnings({ "unchecked", "rawtypes" })
private static Parser<?> schema() {
    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<?> expTy = Parsers.between(term("("), Parsers.tuple(ref.lazy(), term("^"), ref.lazy()), term(")"));
    Parser<?> unionTy = Parsers.between(term("("), Parsers.tuple(ref.lazy(), term("union"), ref.lazy()), term(")"));
    Parser<?> xxx = ident().sepBy(term(",")).between(term("{"), term("}"));
    Parser<?> op = Parsers.tuple(term("opposite"), ref.lazy());
    Parser<?> a = Parsers.or(term("void"), Parsers.tuple(term("unit"), xxx), plusTy, prodTy, expTy, unionTy, ident(), schemaConst(), op, term("?"));
    ref.set(a);
    return a;
}
Also used : Reference(org.jparsec.Parser.Reference)

Example 13 with Reference

use of org.jparsec.Parser.Reference 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 14 with Reference

use of org.jparsec.Parser.Reference 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 15 with Reference

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

Aggregations

Reference (org.jparsec.Parser.Reference)21 Parser (org.jparsec.Parser)12