use of org.jparsec.Parser in project fql by CategoricalData.
the class NraViewer method inst.
private static Parser<?> inst() {
Reference ref = Parser.newReference();
Parser rcd = Parsers.tuple(term("("), Parsers.tuple(ident(), term(":"), ref.lazy()).sepBy(term(",")), term(")"));
Parser set = Parsers.tuple(term("{"), rcd.sepBy(term(",")), term("}"));
Parser p = Parsers.or(string(), rcd, set);
ref.set(p);
return p;
}
use of org.jparsec.Parser in project fql by CategoricalData.
the class CombinatorParser method instExpCoProd.
@SuppressWarnings({ "rawtypes", "unchecked" })
private static Parser<InstExpCoProdSigma> instExpCoProd() {
Parser<catdata.Pair<MapExp, InstExp>> p = Parsers.tuple(map_ref.lazy(), inst_ref.lazy()).map(x -> new catdata.Pair<>(x.a, x.b));
Parser<InstExpCoProdSigma> ret = Parsers.tuple(token("coproduct_sigma"), p.many(), token(":"), sch_ref.lazy(), options.between(token("{"), token("}")).optional()).map(x -> new InstExpCoProdSigma(x.b, x.d, Util.newIfNull(x.e)));
//
Parser<InstExpCoProdSigma> ret2 = Parsers.tuple(token("union"), inst_ref.lazy().sepBy(token("+")), token(":"), sch_ref.lazy(), options.between(token("{"), token("}")).optional()).map(x -> new InstExpCoProdSigma(x.b.stream().map(y -> new catdata.Pair<>(new MapExpId(x.d), y)).collect(Collectors.toList()), x.d, Util.newIfNull(x.e)));
return Parsers.or(ret, ret2);
}
use of org.jparsec.Parser in project fql by CategoricalData.
the class CombinatorParser method edExpRaw.
private static Parser<EdExpRaw> edExpRaw() {
Parser<List<catdata.Pair<LocStr, String>>> as = Parsers.tuple(token("forall"), env(ident, ":")).map(x -> x.b).optional();
Parser<catdata.Pair<List<catdata.Pair<LocStr, String>>, Boolean>> es = Parsers.tuple(token("exists"), token("unique").optional(), env(ident, ":")).map(x -> new catdata.Pair<>(x.c, x.b != null)).optional();
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, x.c))).map(x -> new catdata.Pair<>(x.a, x.b));
Parser<List<catdata.Pair<Integer, catdata.Pair<RawTerm, RawTerm>>>> eqs = Parsers.tuple(token("where"), eq.many()).map(x -> x.b).optional();
Parser<EdExpRaw> ret = Parsers.tuple(as, eqs, token("->"), es, eqs).map(x -> new EdExpRaw(Util.newIfNull(x.a), Util.newIfNull(x.b), x.d == null ? new LinkedList<>() : x.d.first, Util.newIfNull(x.e), x.d == null ? false : x.d.second));
return ret;
}
use of org.jparsec.Parser in project fql by CategoricalData.
the class XParser method instance.
/* public static final Parser<?> query(Reference ref) {
Parser<?> xxx = ref.lazy().between(term("pi"), term(";"));
Parser<?> yyy = ref.lazy().between(term("delta"), term(";"));
Parser<?> zzz = ref.lazy().between(term("sigma"), term(";"));
Parser p = Parsers.tuple(xxx, yyy, zzz);
Parser<?> ret = Parsers.tuple(term("query"), p.between(term("{"), term("}")));
return ret;
} */
private static Parser<?> instance(Reference ref) {
Parser<?> node = Parsers.tuple(ident().many1(), term(":"), ident());
Parser<?> p3 = Parsers.tuple(path(), term("="), path());
Parser<?> xxx = Parsers.tuple(section("variables", node), section("equations", p3));
Parser kkk = ((Parser) term("INSTANCE")).or(term("instance"));
Parser<?> constant = Parsers.tuple(kkk, xxx.between(term("{"), term("}")), term(":"), ref.lazy());
return constant;
}
use of org.jparsec.Parser in project fql by CategoricalData.
the class XParser method decl.
private static Parser<?> decl() {
// Parser e = Parsers.or(new Parser[] { exp(), type(), fn(), constx(), assume() });
Parser p0 = Parsers.tuple(Parsers.tuple(ident(), term(":"), ident()).between(term("("), term(")")), term("="), exp());
Parser p1 = Parsers.tuple(ident(), term("="), exp());
Parser p3 = Parsers.tuple(ident().many1(), term(":"), Parsers.tuple(ident(), term("->"), ident()));
Parser p4 = Parsers.tuple(ident().many1(), term(":"), term("type"));
Parser p5 = Parsers.tuple(ident(), term(":"), Parsers.tuple(path(), term("="), path()));
Parser p2 = Parsers.tuple(ident().many1(), term(":"), ident());
return Parsers.or(new Parser[] { p0, p1, p3, p4, p5, p2 });
// return Parsers.tuple(ident(), Parsers.or(term("="), term(":")), e);
}
Aggregations