Search in sources :

Example 11 with Label

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;
            });
        });
    });
}
Also used : Scope(mb.nabl2.scopegraph.terms.Scope) Label(mb.nabl2.scopegraph.terms.Label) ITerm(mb.nabl2.terms.ITerm) Occurrence(mb.nabl2.scopegraph.terms.Occurrence)

Example 12 with Label

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

Aggregations

ITerm (mb.nabl2.terms.ITerm)12 Label (mb.nabl2.scopegraph.terms.Label)11 Scope (mb.nabl2.scopegraph.terms.Scope)11 Occurrence (mb.nabl2.scopegraph.terms.Occurrence)10 Map (java.util.Map)7 ISolution (mb.nabl2.solver.ISolution)6 SolveResult (mb.nabl2.solver.ISolver.SolveResult)6 IUnifier (mb.nabl2.terms.unification.IUnifier)6 IEsopNameResolution (mb.nabl2.scopegraph.esop.IEsopNameResolution)5 Optional (java.util.Optional)4 NaBL2DebugConfig (mb.nabl2.config.NaBL2DebugConfig)4 IConstraint (mb.nabl2.constraints.IConstraint)4 IEsopScopeGraph (mb.nabl2.scopegraph.esop.IEsopScopeGraph)4 IResolutionPath (mb.nabl2.scopegraph.path.IResolutionPath)4 ISolver (mb.nabl2.solver.ISolver)4 ImmutableSolution (mb.nabl2.solver.ImmutableSolution)4 SolverConfig (mb.nabl2.solver.SolverConfig)4 SolverCore (mb.nabl2.solver.SolverCore)4 SolverException (mb.nabl2.solver.SolverException)4 BaseComponent (mb.nabl2.solver.components.BaseComponent)4