use of mb.nabl2.terms.ListTerms 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