Search in sources :

Example 31 with Parser

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

the class XParser method superSoed.

private static Parser<?> superSoed() {
    Parser<?> es = Parsers.tuple(ident(), term(":"), ident().sepBy(term(",")), term("->"), ident());
    // bulb
    // bulb . path
    // path
    Parser bulb = Parsers.tuple(term("@"), ident(), Parsers.tuple(term("("), path().sepBy(term(",")), term(")")));
    Parser bulbpath = Parsers.tuple(bulb, term("."), path());
    Parser superPath = Parsers.or(new Parser[] { bulbpath, bulb, path() });
    Parser<?> x = Parsers.tuple(superPath, term("="), superPath);
    Parser<?> y = Parsers.tuple(x.sepBy(term(",")), term("->"), x.sepBy(term(",")));
    Parser<?> a = Parsers.tuple(term("forall"), Parsers.tuple(ident(), term(":"), ident()).sepBy(term(",")), term(","), y);
    Parser<?> foo = Parsers.tuple(term("exists"), es.sepBy(term(",")), term(";"), a.followedBy(term(";")).many());
    Parser<?> p = Parsers.between(term("supersoed").followedBy(term("{")), foo, term("}"));
    Parser<?> q = Parsers.tuple(term(":"), ident().followedBy(term("->")), ident().followedBy(term("on")), ident());
    return Parsers.tuple(p, q);
}
Also used : Parser(org.jparsec.Parser)

Example 32 with Parser

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

the class XParser method where.

private static Parser where() {
    Reference ref = Parser.newReference();
    Parser p1 = Parsers.tuple(term("("), ref.lazy(), term("and"), ref.lazy(), term(")"));
    Parser p2 = Parsers.tuple(term("("), ref.lazy(), term("or"), ref.lazy(), term(")"));
    Parser p3 = Parsers.tuple(path(), term("="), path());
    Parser p4 = Parsers.tuple(term("not"), ref.lazy());
    Parser p = Parsers.or(p1, p2, p3, p4, term("true"), term("false"));
    ref.set(p);
    return p;
}
Also used : Reference(org.jparsec.Parser.Reference) Parser(org.jparsec.Parser)

Example 33 with Parser

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

the class XParser method path.

/*
	
//	@SuppressWarnings("rawtypes")
	public static FunctorExp toInstConst(Object decl) {
		Tuple3 y = (Tuple3) decl;
		org.jparsec.functors.Pair x = (org.jparsec.functors.Pair) y.a;
		
		Tuple3 nodes = (Tuple3) x.a;
		Tuple3 arrows = (Tuple3) x.b;
		
		List nodes0 = (List) nodes.b;
		List arrows0 = (List) arrows.b;


		Map<String, SetExp> nodesX = new HashMap<>();
		for (Object o : nodes0) {
			if (nodesX.containsKey(o)) {
				throw new RuntimeException("Duplicate object: " + o + " in " + decl);
			}
			Tuple3 u = (Tuple3) o;
			String n = (String) u.a;
			SetExp l = toSet(u.c);
			nodesX.put(n, l);
		}
		
		Map<String, Chc<FnExp,SetExp>> arrowsX = new HashMap<>();
		for (Object o : arrows0) {
			if (arrowsX.containsKey(o)) {
				throw new RuntimeException("Duplicate arrow: " + o + " in " + decl);
			}
			Tuple3 u = (Tuple3) o;
			String n = (String) u.a;
			try {
				FnExp l = toFn(u.c);
				arrowsX.put(n, Chc.inLeft(l));
			} catch (Exception eee) {
				SetExp l = toSet(u.c);
				arrowsX.put(n, Chc.inRight(l));				
			}
		}
		InstConst ret = new InstConst(toCat(y.c), nodesX, arrowsX);
		return ret;
	}
	*/
/*
	public static FunctorExp toCatFtrConst(Object decl) {
		Tuple5 y = (Tuple5) decl;
		org.jparsec.functors.Pair x = (org.jparsec.functors.Pair) y.a;
		
		Tuple3 nodes = (Tuple3) x.a;
		Tuple3 arrows = (Tuple3) x.b;
		
		List nodes0 = (List) nodes.b;
		List arrows0 = (List) arrows.b;

		Map<String, CatExp> nodesX = new HashMap<>();
		for (Object o : nodes0) {
			if (nodesX.containsKey(o)) {
				throw new RuntimeException("Duplicate object: " + o + " in " + decl);
			}
			Tuple3 u = (Tuple3) o;
			String n = (String) u.a;
			CatExp l = toCat(u.c);
			nodesX.put(n, l);
		}

		Map<String, FunctorExp> arrowsX = new HashMap<>();
		for (Object o : arrows0) {
			if (arrowsX.containsKey(o)) {
				throw new RuntimeException("Duplicate arrow: " + o + " in " + decl);
			}
			Tuple3 u = (Tuple3) o;
			String n = (String) u.a;
			FunctorExp l = toFtr(u.c);
			arrowsX.put(n, l);
		}
		CatConst ret = new CatConst(toCat(y.c), nodesX, arrowsX);
		return ret;
	}
	*/
/*public static FunctorExp toMapConst(Object decl) {
		Tuple5 y = (Tuple5) decl;
		org.jparsec.functors.Pair x = (org.jparsec.functors.Pair) y.a;
		
		Tuple3 nodes = (Tuple3) x.a;
		Tuple3 arrows = (Tuple3) x.b;
		
		List nodes0 = (List) nodes.b;
		List arrows0 = (List) arrows.b;


		Map<String, String> nodesX = new HashMap<>();
		for (Object o : nodes0) {
			if (nodesX.containsKey(o)) {
				throw new RuntimeException("Duplicate object: " + o + " in " + decl);
			}
			Tuple3 u = (Tuple3) o;
			String n = (String) u.a;
			String l = u.c.toString();
			nodesX.put(n, l);
		}
		
		Map<String, Pair<String, List<String>>> arrowsX = new HashMap<>();
		for (Object o : arrows0) {
			if (arrowsX.containsKey(o)) {
				throw new RuntimeException("Duplicate arrow: " + o + " in " + decl);
			}
			Tuple3 u = (Tuple3) o;
			String n = (String) u.a;
			List<String> l = (List<String>) u.c;
			String ll = l.remove(0);
			arrowsX.put(n, new Pair<>(ll, l));
		}
		MapConst ret = new MapConst(toCat(y.c), toCat(y.e), nodesX, arrowsX);
		return ret;
	} */
public static List path(String s) {
    Parser p = Parsers.or(StringLiteral.PARSER, IntegerLiteral.PARSER, Identifier.PARSER);
    Parser e = Parsers.tuple(p, term(","), p);
    Parser q = Parsers.between(term("("), e, term(")"));
    Parser a = Parsers.or(q, p).sepBy1(term("."));
    List l = (List) a.from(TOKENIZER, IGNORED).parse(s);
    List ret = new LinkedList();
    for (Object o : l) {
        if (o instanceof Tuple3) {
            Tuple3 z = (Tuple3) o;
            ret.add(new Pair(z.a, z.c));
        } else {
            ret.add(o);
        }
    }
    return ret;
}
Also used : Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList) Parser(org.jparsec.Parser) Pair(catdata.Pair) XPair(catdata.fpql.XExp.XPair)

Example 34 with Parser

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

the class XRaToFpql method ed.

@SuppressWarnings({ "rawtypes", "unchecked" })
private static Parser<?> ed() {
    Parser tuple = Parsers.tuple(ident(), term("."), ident());
    Parser<?> from0 = Parsers.tuple(ident(), term("AS"), ident()).sepBy1(term(","));
    Parser<?> from1 = Parsers.tuple(term("FORALL"), from0);
    Parser<?> from2 = Parsers.tuple(term("EXISTS"), from0);
    Parser<?> where0 = Parsers.tuple(tuple, term("="), tuple.or(string())).sepBy(term("AND"));
    // Parser<?> where0 = Parsers.tuple(tuple, term("="), tuple).sepBy(term("AND"));
    Parser<?> where = Parsers.tuple(term("WHERE"), where0).optional();
    return Parsers.tuple(from1, where, from2, where);
}
Also used : Parser(org.jparsec.Parser)

Example 35 with Parser

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

the class XRaToFpql method flower.

@SuppressWarnings({ "rawtypes", "unchecked" })
private static Parser<?> flower() {
    Parser tuple = Parsers.tuple(ident(), term("."), ident());
    Parser<?> from0 = Parsers.tuple(ident(), term("AS"), ident()).sepBy(term(","));
    Parser<?> from = Parsers.tuple(term("FROM"), from0);
    Parser<?> where0 = Parsers.tuple(tuple, term("="), tuple.or(string())).sepBy(term("AND"));
    Parser<?> where = Parsers.tuple(term("WHERE"), where0);
    Parser<?> select0 = Parsers.tuple(tuple, term("AS"), ident()).sepBy1(term(","));
    Parser<?> select = Parsers.tuple(term("SELECT"), term("DISTINCT").optional(), select0);
    return Parsers.tuple(select, from, where);
}
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