Search in sources :

Example 1 with IListTerm

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());
}
Also used : IListTerm(mb.nabl2.terms.IListTerm) Scope(mb.nabl2.scopegraph.terms.Scope) ITerm(mb.nabl2.terms.ITerm)

Example 2 with IListTerm

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);
}
Also used : ITerm(mb.nabl2.terms.ITerm) Map(java.util.Map)

Example 3 with IListTerm

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;
}
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

IListTerm (mb.nabl2.terms.IListTerm)2 ITerm (mb.nabl2.terms.ITerm)2 ImmutableClassToInstanceMap (com.google.common.collect.ImmutableClassToInstanceMap)1 Map (java.util.Map)1 Scope (mb.nabl2.scopegraph.terms.Scope)1 IStrategoList (org.spoofax.interpreter.terms.IStrategoList)1 IStrategoTerm (org.spoofax.interpreter.terms.IStrategoTerm)1