use of mb.nabl2.terms.ITerm in project nabl by metaborg.
the class ScopeGraphComponent method solve.
private boolean solve(CGDirectEdge c) {
ITerm sourceScopeRep = unifier().findRecursive(c.getSourceScope());
if (!sourceScopeRep.isGround()) {
return false;
}
Scope sourceScope = Scope.matcher().match(sourceScopeRep, unifier()).orElseThrow(() -> new TypeException("Expected a scope but got " + sourceScopeRep));
return findScope(c.getTargetScope()).map(targetScope -> {
scopeGraph.addDirectEdge(sourceScope, c.getLabel(), targetScope);
return true;
}).orElseGet(() -> {
scopeGraph.addIncompleteDirectEdge(sourceScope, c.getLabel(), c.getTargetScope());
return true;
});
}
use of mb.nabl2.terms.ITerm in project nabl by metaborg.
the class Args method build.
public static ITerm build(Args args) {
List<ITerm> paramTerms = args.getParams();
ITerm paramsTerm;
if (paramTerms.size() == 1) {
paramsTerm = paramTerms.get(0);
} else {
paramsTerm = B.newTuple(paramTerms);
}
return args.getType().map(typeTerm -> B.newAppl(PARAMS_AND_TYPE, paramsTerm, typeTerm)).orElseGet(() -> B.newAppl(PARAMS, paramsTerm));
// @formatter:on
}
use of mb.nabl2.terms.ITerm 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.terms.ITerm in project nabl by metaborg.
the class ScopeGraphLogPrimitive method call.
@Override
public Optional<ITerm> call(IScopeGraphContext<?> context, ITerm term, List<ITerm> terms) throws InterpreterException {
final ITerm messageTerm = terms.get(0);
final String message = M.stringValue().match(messageTerm).orElseGet(() -> messageTerm.toString());
logger.log(level(context), "{}", message);
return fatal() ? Optional.empty() : Optional.of(term);
}
use of mb.nabl2.terms.ITerm in project nabl by metaborg.
the class StrategoTerms method toStratego.
// to
public IStrategoTerm toStratego(ITerm term) {
IStrategoTerm strategoTerm = term.match(Terms.cases(// @formatter:off
appl -> {
List<IStrategoTerm> args = appl.getArgs().stream().map(arg -> toStratego(arg)).collect(Collectors.toList());
IStrategoTerm[] argArray = args.toArray(new IStrategoTerm[args.size()]);
return appl.getOp().equals(Terms.TUPLE_OP) ? termFactory.makeTuple(argArray) : termFactory.makeAppl(termFactory.makeConstructor(appl.getOp(), appl.getArity()), argArray);
}, list -> toStrategoList(list), string -> termFactory.makeString(string.getValue()), integer -> termFactory.makeInt(integer.getValue()), blob -> new StrategoBlob(blob.getValue()), var -> {
throw new IllegalArgumentException("Cannot convert specialized terms to Stratego.");
}));
strategoTerm = putAttachments(strategoTerm, term.getAttachments());
return strategoTerm;
}
Aggregations