use of mb.nabl2.terms.IListTerm in project nabl by metaborg.
the class InterpreterTerms method scopeEntries.
private static ITerm scopeEntries(IScopeGraph<Scope, Label, Occurrence> scopeGraph) {
Map<ITerm, ITerm> entries = Maps.newHashMap();
for (Scope scope : scopeGraph.getAllScopes()) {
IListTerm decls = B.newList(scopeGraph.getDecls().inverse().get(scope));
IListTerm refs = B.newList(scopeGraph.getRefs().inverse().get(scope));
IListTerm edges = multimap(scopeGraph.getDirectEdges().get(scope));
IListTerm imports = multimap(scopeGraph.getImportEdges().get(scope));
ITerm entry = B.newAppl("SE", decls, refs, edges, imports);
entries.put(scope, entry);
}
return map(entries.entrySet());
}
use of mb.nabl2.terms.IListTerm in project nabl by metaborg.
the class InterpreterTerms method multimap.
private static IListTerm multimap(Iterable<? extends Map.Entry<? extends ITerm, ? extends ITerm>> entries) {
Multimap<ITerm, ITerm> grouped = HashMultimap.create();
for (Map.Entry<? extends ITerm, ? extends ITerm> entry : entries) {
grouped.put(entry.getKey(), entry.getValue());
}
List<ITerm> entryterms = Lists.newArrayList();
for (ITerm key : grouped.keySet()) {
entryterms.add(B.newTuple(key, B.newList(grouped.get(key))));
}
return B.newList(entryterms);
}
use of mb.nabl2.terms.IListTerm in project nabl by metaborg.
the class StrategoTerms method toStrategoList.
// NB. This function does not preserve locks, it depends on toStratego for that.
private IStrategoTerm toStrategoList(IListTerm list) {
final LinkedList<IStrategoTerm> terms = Lists.newLinkedList();
final LinkedList<ImmutableClassToInstanceMap<Object>> attachments = Lists.newLinkedList();
while (list != null) {
attachments.push(list.getAttachments());
list = list.match(ListTerms.<IListTerm>cases(// @formatter:off
cons -> {
terms.push(toStratego(cons.getHead()));
return cons.getTail();
}, nil -> {
return null;
}, var -> {
throw new IllegalArgumentException("Cannot convert specialized terms to Stratego.");
}));
}
IStrategoList strategoList = termFactory.makeList();
putAttachments(strategoList, attachments.pop());
while (!terms.isEmpty()) {
strategoList = termFactory.makeListCons(terms.pop(), strategoList);
putAttachments(strategoList, attachments.pop());
}
return strategoList;
}
Aggregations