use of mb.nabl2.spoofax.analysis.IScopeGraphUnit in project nabl by metaborg.
the class AnalysisPrimitive method call.
@Override
public Optional<? extends IStrategoTerm> call(IScopeGraphContext<?> context, IStrategoTerm sterm, List<IStrategoTerm> sterms, ITermFactory factory) throws InterpreterException {
if (sterms.size() < 1) {
throw new IllegalArgumentException("Expected as first term argument: analysis");
}
final IStrategoTerm analysisTerm = sterms.get(0);
final IScopeGraphUnit analysis;
final Optional<IScopeGraphUnit> maybeAnalysis = StrategoBlob.match(analysisTerm, IScopeGraphUnit.class);
if (maybeAnalysis.isPresent()) {
analysis = maybeAnalysis.get();
} else if (Tools.isTermAppl(analysisTerm) && Tools.hasConstructor((IStrategoAppl) analysisTerm, "AnalysisToken", 0)) {
// TODO Remove legacy case after bootstrapping
analysis = StrategoTermIndices.get(analysisTerm).map(idx -> context.unit(idx.getResource())).orElseThrow(() -> new IllegalArgumentException("Not a valid analysis term."));
} else {
throw new IllegalArgumentException("Not a valid analysis term.");
}
return call(analysis, sterm, sterms, factory);
}
use of mb.nabl2.spoofax.analysis.IScopeGraphUnit in project nabl by metaborg.
the class AnalysisPrimitive method call.
public Optional<? extends IStrategoTerm> call(IScopeGraphUnit unit, IStrategoTerm sterm, List<IStrategoTerm> sterms, ITermFactory factory) throws InterpreterException {
final StrategoTerms strategoTerms = new StrategoTerms(factory);
final List<ITerm> terms = sterms.stream().skip(1).map(strategoTerms::fromStratego).map(ConstraintTerms::specialize).collect(Collectors.toList());
final ITerm term = ConstraintTerms.specialize(strategoTerms.fromStratego(sterm));
Optional<? extends ITerm> result = call(unit, term, terms);
return result.map(ConstraintTerms::explicate).map(strategoTerms::toStratego);
}
use of mb.nabl2.spoofax.analysis.IScopeGraphUnit in project nabl by metaborg.
the class AnalysisNoTermPrimitive method call.
@Override
public Optional<? extends IStrategoTerm> call(IScopeGraphUnit unit, IStrategoTerm sterm, List<IStrategoTerm> sterms, ITermFactory factory) throws InterpreterException {
StrategoTerms strategoTerms = new StrategoTerms(factory);
Optional<? extends ITerm> result = call(unit);
return result.map(ConstraintTerms::explicate).map(strategoTerms::toStratego);
}
use of mb.nabl2.spoofax.analysis.IScopeGraphUnit 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.spoofax.analysis.IScopeGraphUnit in project nabl by metaborg.
the class SG_get_resource_analysis method call.
@Override
public Optional<? extends IStrategoTerm> call(IScopeGraphContext<?> context, IStrategoTerm sterm, List<IStrategoTerm> sterms, ITermFactory factory) throws InterpreterException {
if (!Tools.isTermString(sterm)) {
throw new InterpreterException("Expect a resource path.");
}
String resource = Tools.asJavaString(sterm);
final IScopeGraphUnit unit = context.unit(resource);
return Optional.of(new StrategoBlob(unit));
}
Aggregations