Search in sources :

Example 1 with Strategy

use of org.spoofax.interpreter.stratego.Strategy in project nabl by metaborg.

the class ScopeGraphContextPrimitive method call.

@Override
public final boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars) throws InterpreterException {
    final Object contextObj = env.contextObject();
    if (contextObj == null) {
        logger.warn("Context is null.");
        return false;
    }
    if (!(contextObj instanceof IScopeGraphContext)) {
        throw new InterpreterException("Context does not implement IScopeGraphContext");
    }
    final IScopeGraphContext<?> context = (IScopeGraphContext<?>) env.contextObject();
    List<IStrategoTerm> termArgs = Arrays.asList(tvars);
    Optional<? extends IStrategoTerm> result;
    try (IClosableLock lock = context.guard()) {
        result = call(context, env.current(), termArgs, env.getFactory());
    }
    return result.map(t -> {
        env.setCurrent(t);
        return true;
    }).orElse(false);
}
Also used : Arrays(java.util.Arrays) ITerm(mb.nabl2.terms.ITerm) StrategoTerms(mb.nabl2.stratego.StrategoTerms) ITermFactory(org.spoofax.interpreter.terms.ITermFactory) IScopeGraphContext(mb.nabl2.spoofax.analysis.IScopeGraphContext) Collectors(java.util.stream.Collectors) IContext(org.spoofax.interpreter.core.IContext) List(java.util.List) Strategy(org.spoofax.interpreter.stratego.Strategy) InterpreterException(org.spoofax.interpreter.core.InterpreterException) ConstraintTerms(mb.nabl2.stratego.ConstraintTerms) Optional(java.util.Optional) LoggerUtils(org.metaborg.util.log.LoggerUtils) AbstractPrimitive(org.spoofax.interpreter.library.AbstractPrimitive) IClosableLock(org.metaborg.util.concurrent.IClosableLock) ILogger(org.metaborg.util.log.ILogger) IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) IScopeGraphContext(mb.nabl2.spoofax.analysis.IScopeGraphContext) IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) InterpreterException(org.spoofax.interpreter.core.InterpreterException) IClosableLock(org.metaborg.util.concurrent.IClosableLock)

Aggregations

Arrays (java.util.Arrays)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 IScopeGraphContext (mb.nabl2.spoofax.analysis.IScopeGraphContext)1 ConstraintTerms (mb.nabl2.stratego.ConstraintTerms)1 StrategoTerms (mb.nabl2.stratego.StrategoTerms)1 ITerm (mb.nabl2.terms.ITerm)1 IClosableLock (org.metaborg.util.concurrent.IClosableLock)1 ILogger (org.metaborg.util.log.ILogger)1 LoggerUtils (org.metaborg.util.log.LoggerUtils)1 IContext (org.spoofax.interpreter.core.IContext)1 InterpreterException (org.spoofax.interpreter.core.InterpreterException)1 AbstractPrimitive (org.spoofax.interpreter.library.AbstractPrimitive)1 Strategy (org.spoofax.interpreter.stratego.Strategy)1 IStrategoTerm (org.spoofax.interpreter.terms.IStrategoTerm)1 ITermFactory (org.spoofax.interpreter.terms.ITermFactory)1