Search in sources :

Example 6 with IScopeGraphUnit

use of mb.nabl2.spoofax.analysis.IScopeGraphUnit 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());
    });
}
Also used : Label(mb.nabl2.scopegraph.terms.Label) ITerm(mb.nabl2.terms.ITerm) Map(java.util.Map)

Aggregations

ITerm (mb.nabl2.terms.ITerm)4 StrategoTerms (mb.nabl2.stratego.StrategoTerms)3 Label (mb.nabl2.scopegraph.terms.Label)2 IScopeGraphUnit (mb.nabl2.spoofax.analysis.IScopeGraphUnit)2 StrategoBlob (mb.nabl2.stratego.StrategoBlob)2 InterpreterException (org.spoofax.interpreter.core.InterpreterException)2 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Occurrence (mb.nabl2.scopegraph.terms.Occurrence)1 Scope (mb.nabl2.scopegraph.terms.Scope)1 IScopeGraphContext (mb.nabl2.spoofax.analysis.IScopeGraphContext)1 ConstraintTerms (mb.nabl2.stratego.ConstraintTerms)1 StrategoTermIndices (mb.nabl2.stratego.StrategoTermIndices)1 Tools (org.spoofax.interpreter.core.Tools)1 IStrategoAppl (org.spoofax.interpreter.terms.IStrategoAppl)1 IStrategoTerm (org.spoofax.interpreter.terms.IStrategoTerm)1 ITermFactory (org.spoofax.interpreter.terms.ITermFactory)1 NotImplementedException (org.spoofax.terms.util.NotImplementedException)1