Search in sources :

Example 1 with GraphExpRaw

use of catdata.aql.exp.GraphExp.GraphExpRaw in project fql by CategoricalData.

the class CombinatorParser method graphExpRaw.

private static Parser<GraphExpRaw> graphExpRaw() {
    Parser<List<LocStr>> nodes = Parsers.tuple(token("nodes"), locstr.many()).map(x -> x.b);
    Parser<Pair<Token, List<Tuple5<List<LocStr>, Token, String, Token, String>>>> edges = Parsers.tuple(token("edges"), Parsers.tuple(locstr.many1(), token(":"), ident, token("->"), ident).many());
    Parser<List<catdata.Pair<LocStr, catdata.Pair<String, String>>>> edges0 = edges.map(x -> {
        List<catdata.Pair<LocStr, catdata.Pair<String, String>>> ret = new LinkedList<>();
        for (Tuple5<List<LocStr>, Token, String, Token, String> a : x.b) {
            for (LocStr b : a.a) {
                ret.add(new catdata.Pair<>(b, new catdata.Pair<>(a.c, a.e)));
            }
        }
        return ret;
    });
    Parser<Tuple3<List<LocStr>, List<LocStr>, List<catdata.Pair<LocStr, catdata.Pair<String, String>>>>> pa = Parsers.tuple(imports, nodes.optional(), edges0.optional());
    Parser<GraphExpRaw> ret = pa.map(x -> new GraphExpRaw(Util.newIfNull(x.b), Util.newIfNull(x.c), x.a));
    return ret.between(token("literal").followedBy(token("{")), token("}"));
}
Also used : Token(org.jparsec.Token) LinkedList(java.util.LinkedList) GraphExpRaw(catdata.aql.exp.GraphExp.GraphExpRaw) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) Pair(org.jparsec.functors.Pair)

Aggregations

GraphExpRaw (catdata.aql.exp.GraphExp.GraphExpRaw)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Token (org.jparsec.Token)1 Pair (org.jparsec.functors.Pair)1 Tuple3 (org.jparsec.functors.Tuple3)1 Tuple5 (org.jparsec.functors.Tuple5)1