use of mb.nabl2.terms.matching.TermMatch.IMatcher in project nabl by metaborg.
the class ScopeGraphEdgePrimitive method call.
@Override
public Optional<ITerm> call(IScopeGraphUnit unit, ITerm term, List<ITerm> terms) throws InterpreterException {
return unit.solution().flatMap(sol -> {
final IRelation3<S, Label, ? extends ITerm> edges = getEdges(sol.scopeGraph());
final IMatcher<S> sourceMatcher = getSourceMatcher();
return M.<ITerm>cases(// @formatter:off
M.term(sourceMatcher, (t, source) -> {
List<ITerm> edgeTerms = Lists.newArrayList();
for (Map.Entry<Label, ? extends ITerm> edge : edges.get(source)) {
edgeTerms.add(B.newTuple(edge.getKey(), edge.getValue()));
}
return B.newList(edgeTerms);
}), M.tuple2(sourceMatcher, Label.matcher(), (t, source, label) -> {
List<ITerm> targetTerms = Lists.newArrayList();
for (ITerm target : edges.get(source, label)) {
targetTerms.add(target);
}
return B.newList(targetTerms);
})).match(term, sol.unifier());
});
}