use of mb.nabl2.scopegraph.terms.Label in project nabl by metaborg.
the class SG_get_ref_resolution method call.
@Override
public Optional<? extends ITerm> call(IScopeGraphUnit unit, ITerm term, List<ITerm> terms) throws InterpreterException {
return unit.solution().flatMap(s -> {
return Occurrence.matcher().match(term, s.unifier()).<ITerm>flatMap(ref -> {
return s.nameResolution().resolve(ref).map(paths -> {
List<ITerm> pathTerms = Lists.newArrayListWithExpectedSize(paths.size());
for (IResolutionPath<Scope, Label, Occurrence> path : paths) {
pathTerms.add(B.newTuple(path.getDeclaration(), Paths.toTerm(path)));
}
ITerm result = B.newList(pathTerms);
return result;
});
});
});
}
use of mb.nabl2.scopegraph.terms.Label 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());
});
}
Aggregations