Search in sources :

Example 1 with ListTerms

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;
}
Also used : IListTerm(mb.nabl2.terms.IListTerm) IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) ImmutableClassToInstanceMap(com.google.common.collect.ImmutableClassToInstanceMap) IStrategoList(org.spoofax.interpreter.terms.IStrategoList)

Aggregations

ImmutableClassToInstanceMap (com.google.common.collect.ImmutableClassToInstanceMap)1 IListTerm (mb.nabl2.terms.IListTerm)1 IStrategoList (org.spoofax.interpreter.terms.IStrategoList)1 IStrategoTerm (org.spoofax.interpreter.terms.IStrategoTerm)1