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("}"));
}
Aggregations