Search in sources :

Example 1 with StrategoConstructor

use of org.spoofax.terms.StrategoConstructor in project spoofax by metaborg.

the class JSGLRCompletionService method calculateDirectCompletionProposals.

private Collection<IStrategoTerm> calculateDirectCompletionProposals(IStrategoTerm nestedCompletionTerm, ITermFactory termFactory, IStrategoTerm completionAst, String languageName, HybridInterpreter runtime) throws MetaborgException {
    Collection<IStrategoTerm> inputsStratego = Lists.newLinkedList();
    Collection<IStrategoTerm> completionTerms = findCompletionTermInsideNested((StrategoTerm) nestedCompletionTerm);
    for (IStrategoTerm completionTerm : completionTerms) {
        final StrategoTerm topMostCompletionTerm = findTopMostCompletionNode((StrategoTerm) completionTerm);
        final StrategoTerm topMostAmb = findTopMostAmbNode(topMostCompletionTerm);
        IStrategoTerm parenthesized = parenthesizeTerm(topMostCompletionTerm, termFactory);
        final IStrategoTerm inputStratego = termFactory.makeTuple(termFactory.makeString(ImploderAttachment.getElementSort(parenthesized)), completionAst, completionTerm, topMostAmb, parenthesized);
        final IStrategoTerm proposalTerm = strategoCommon.invoke(runtime, inputStratego, "get-proposals-incorrect-programs-" + languageName);
        if (proposalTerm == null) {
            logger.error("Getting proposals for {} failed", inputStratego);
            continue;
        }
        final IStrategoTerm replaceTermText = termFactory.makeAppl(new StrategoConstructor("REPLACE_TERM_TEXT", 2), topMostAmb, proposalTerm.getSubterm(1));
        IStrategoTerm parenthesizedNested = parenthesizeTerm(nestedCompletionTerm, termFactory);
        final IStrategoTerm inputStrategoNested = termFactory.makeTuple(termFactory.makeString(ImploderAttachment.getElementSort(parenthesizedNested)), completionAst, nestedCompletionTerm, proposalTerm.getSubterm(0), replaceTermText, parenthesizedNested);
        inputsStratego.add(inputStrategoNested);
    }
    return inputsStratego;
}
Also used : IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) StrategoTerm(org.spoofax.terms.StrategoTerm) StrategoConstructor(org.spoofax.terms.StrategoConstructor)

Example 2 with StrategoConstructor

use of org.spoofax.terms.StrategoConstructor in project spoofax by metaborg.

the class JSGLRCompletionService method calculateNestedCompletionProposals.

private Collection<IStrategoTerm> calculateNestedCompletionProposals(IStrategoTerm mainNestedCompletionTerm, IStrategoTerm nestedCompletionTerm, ITermFactory termFactory, IStrategoTerm completionAst, String languageName, HybridInterpreter runtime) throws MetaborgException {
    Collection<IStrategoTerm> inputsStratego = Lists.newLinkedList();
    Collection<IStrategoTerm> nestedCompletionTerms = findNestedCompletionTerm((StrategoTerm) nestedCompletionTerm, true);
    for (IStrategoTerm innerNestedCompletionTerm : nestedCompletionTerms) {
        Collection<IStrategoTerm> inputsStrategoInnerNested = calculateNestedCompletionProposals(nestedCompletionTerm, innerNestedCompletionTerm, termFactory, completionAst, languageName, runtime);
        for (IStrategoTerm inputStrategoNested : inputsStrategoInnerNested) {
            final IStrategoTerm proposalTermNested = strategoCommon.invoke(runtime, inputStrategoNested, "get-proposals-incorrect-programs-nested-" + languageName);
            if (proposalTermNested == null) {
                logger.error("Getting proposals for {} failed", inputStrategoNested);
                continue;
            }
            final StrategoTerm topMostAmb = findTopMostAmbNode((StrategoTerm) nestedCompletionTerm);
            final IStrategoTerm replaceTermText = termFactory.makeAppl(new StrategoConstructor("REPLACE_TERM_TEXT", 2), topMostAmb, proposalTermNested.getSubterm(1));
            IStrategoTerm parenthesized = parenthesizeTerm(mainNestedCompletionTerm, termFactory);
            final IStrategoTerm inputStrategoInnerNested = termFactory.makeTuple(termFactory.makeString(ImploderAttachment.getElementSort(parenthesized)), completionAst, mainNestedCompletionTerm, proposalTermNested.getSubterm(0), replaceTermText, parenthesized);
            inputsStratego.add(inputStrategoInnerNested);
        }
    }
    Collection<IStrategoTerm> inputsStrategoInner = calculateDirectCompletionProposals(nestedCompletionTerm, termFactory, completionAst, languageName, runtime);
    for (IStrategoTerm inputStrategoNested : inputsStrategoInner) {
        final IStrategoTerm proposalTermNested = strategoCommon.invoke(runtime, inputStrategoNested, "get-proposals-incorrect-programs-nested-" + languageName);
        if (proposalTermNested == null) {
            logger.error("Getting proposals for {} failed", inputStrategoNested);
            continue;
        }
        final StrategoTerm topMostAmb = findTopMostAmbNode((StrategoTerm) nestedCompletionTerm);
        final IStrategoTerm replaceTermText = termFactory.makeAppl(new StrategoConstructor("REPLACE_TERM_TEXT", 2), topMostAmb, proposalTermNested.getSubterm(1));
        IStrategoTerm parenthesized = parenthesizeTerm(mainNestedCompletionTerm, termFactory);
        final IStrategoTerm inputStrategoInnerNested = termFactory.makeTuple(termFactory.makeString(ImploderAttachment.getElementSort(parenthesized)), completionAst, mainNestedCompletionTerm, proposalTermNested.getSubterm(0), replaceTermText, parenthesized);
        inputsStratego.add(inputStrategoInnerNested);
    }
    return inputsStratego;
}
Also used : IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) StrategoTerm(org.spoofax.terms.StrategoTerm) StrategoConstructor(org.spoofax.terms.StrategoConstructor)

Aggregations

IStrategoTerm (org.spoofax.interpreter.terms.IStrategoTerm)2 StrategoConstructor (org.spoofax.terms.StrategoConstructor)2 StrategoTerm (org.spoofax.terms.StrategoTerm)2