use of mb.nabl2.terms.matching.Transform.T 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);
}
use of mb.nabl2.terms.matching.Transform.T in project nabl by metaborg.
the class TermIndexTest method testSerializeSpecialized.
@Test
public void testSerializeSpecialized() throws Exception {
ITerm t = ImmutableTermIndex.of("Hello, world!", 42);
byte[] b1 = serialize(t);
byte[] b2 = serialize(deserialize(b1));
assertTrue(Arrays.equals(b1, b2));
}
use of mb.nabl2.terms.matching.Transform.T in project nabl by metaborg.
the class HashcodeAndEqualsTest method testSerializeGeneric.
@Test
public void testSerializeGeneric() throws Exception {
ITerm t = B.newAppl(SpecializedAppl.OP, B.newString("Hello, world!"), B.newInt(42));
byte[] b1 = serialize(t);
byte[] b2 = serialize(deserialize(b1));
assertTrue(Arrays.equals(b1, b2));
}
use of mb.nabl2.terms.matching.Transform.T 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());
});
}
use of mb.nabl2.terms.matching.Transform.T in project nabl by metaborg.
the class VarMultimap method update.
public boolean update(final ITermVar var, IUnifier unifier) {
final Collection<T> values = map.removeAll(var);
final Set<ITermVar> reps = unifier.getVars(var);
boolean change = false;
for (ITermVar rep : reps) {
change |= map.putAll(rep, values);
}
return change;
}
Aggregations