Search in sources :

Example 1 with IStrategoTermVisitor

use of org.spoofax.terms.visitor.IStrategoTermVisitor in project spoofax by metaborg.

the class JSGLRCompletionService method findPlaceholderTerms.

private Collection<IStrategoTerm> findPlaceholderTerms(IStrategoTerm ast) {
    final Collection<IStrategoTerm> placeholderTerms = Lists.newLinkedList();
    final IStrategoTermVisitor visitor = new AStrategoTermVisitor() {

        @Override
        public boolean visit(IStrategoTerm term) {
            if (term instanceof IStrategoAppl) {
                IStrategoAppl appl = (IStrategoAppl) term;
                if (appl.getConstructor().getName().contains("-Plhdr") && appl.getSubtermCount() > 0) {
                    placeholderTerms.add(appl);
                    return false;
                }
            }
            return true;
        }
    };
    StrategoTermVisitee.topdown(visitor, ast);
    return placeholderTerms;
}
Also used : IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) AStrategoTermVisitor(org.spoofax.terms.visitor.AStrategoTermVisitor) IStrategoAppl(org.spoofax.interpreter.terms.IStrategoAppl) IStrategoTermVisitor(org.spoofax.terms.visitor.IStrategoTermVisitor)

Example 2 with IStrategoTermVisitor

use of org.spoofax.terms.visitor.IStrategoTermVisitor in project spoofax by metaborg.

the class JSGLRCompletionService method findNestedCompletionTerm.

private Collection<IStrategoTerm> findNestedCompletionTerm(final StrategoTerm ast, final boolean excludeIdTerm) {
    final Collection<IStrategoTerm> completionTerms = Lists.newLinkedList();
    final IStrategoTermVisitor visitor = new AStrategoTermVisitor() {

        @Override
        public boolean visit(IStrategoTerm term) {
            ImploderAttachment ia = term.getAttachment(ImploderAttachment.TYPE);
            if (excludeIdTerm && term.equals(ast)) {
                return true;
            }
            if (ia.isNestedCompletion()) {
                completionTerms.add(term);
                return false;
            }
            return true;
        }
    };
    StrategoTermVisitee.topdown(visitor, ast);
    return completionTerms;
}
Also used : IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) AStrategoTermVisitor(org.spoofax.terms.visitor.AStrategoTermVisitor) IStrategoTermVisitor(org.spoofax.terms.visitor.IStrategoTermVisitor) ImploderAttachment(org.spoofax.jsglr.client.imploder.ImploderAttachment) ListImploderAttachment(org.spoofax.jsglr.client.imploder.ListImploderAttachment)

Example 3 with IStrategoTermVisitor

use of org.spoofax.terms.visitor.IStrategoTermVisitor in project spoofax by metaborg.

the class JSGLRCompletionService method findCompletionTerm.

private Collection<IStrategoTerm> findCompletionTerm(StrategoTerm ast) {
    final Collection<IStrategoTerm> completionTerms = Lists.newLinkedList();
    final IStrategoTermVisitor visitor = new AStrategoTermVisitor() {

        @Override
        public boolean visit(IStrategoTerm term) {
            ImploderAttachment ia = term.getAttachment(ImploderAttachment.TYPE);
            if (ia.isNestedCompletion()) {
                return false;
            }
            if (ia.isCompletion()) {
                completionTerms.add(term);
                return false;
            }
            return true;
        }
    };
    StrategoTermVisitee.topdown(visitor, ast);
    return completionTerms;
}
Also used : IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) AStrategoTermVisitor(org.spoofax.terms.visitor.AStrategoTermVisitor) IStrategoTermVisitor(org.spoofax.terms.visitor.IStrategoTermVisitor) ImploderAttachment(org.spoofax.jsglr.client.imploder.ImploderAttachment) ListImploderAttachment(org.spoofax.jsglr.client.imploder.ListImploderAttachment)

Example 4 with IStrategoTermVisitor

use of org.spoofax.terms.visitor.IStrategoTermVisitor in project spoofax by metaborg.

the class JSGLRCompletionService method tracingTermsCompletions.

private Iterable<IStrategoTerm> tracingTermsCompletions(final int position, Object result, final ISourceRegion region, final HybridInterpreter runtime, final ITermFactory termFactory, final String languageName, final Map<IStrategoTerm, Boolean> leftRecursiveTerms, final Map<IStrategoTerm, Boolean> rightRecursiveTerms) {
    if (result == null || region == null) {
        return Iterables2.empty();
    }
    final Collection<IStrategoTerm> parsed = Lists.newLinkedList();
    final IStrategoTermVisitor visitor = new AStrategoTermVisitor() {

        @Override
        public boolean visit(IStrategoTerm term) {
            final ISourceLocation location = fromTokens(term, runtime, termFactory, position, languageName, leftRecursiveTerms, rightRecursiveTerms);
            if (location != null && location.region().contains(region)) {
                parsed.add(term);
                return false;
            }
            return true;
        }
    };
    StrategoTermVisitee.bottomup(visitor, (IStrategoTerm) result);
    return parsed;
}
Also used : IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) AStrategoTermVisitor(org.spoofax.terms.visitor.AStrategoTermVisitor) IStrategoTermVisitor(org.spoofax.terms.visitor.IStrategoTermVisitor) ISourceLocation(org.metaborg.core.source.ISourceLocation)

Example 5 with IStrategoTermVisitor

use of org.spoofax.terms.visitor.IStrategoTermVisitor in project spoofax by metaborg.

the class JSGLRCompletionService method findCompletionTermInsideNested.

private Collection<IStrategoTerm> findCompletionTermInsideNested(final StrategoTerm ast) {
    final Collection<IStrategoTerm> completionTerms = Lists.newLinkedList();
    final IStrategoTermVisitor visitor = new AStrategoTermVisitor() {

        @Override
        public boolean visit(IStrategoTerm term) {
            ImploderAttachment ia = term.getAttachment(ImploderAttachment.TYPE);
            if (ia.isNestedCompletion() && !term.equals(ast)) {
                return false;
            }
            if (ia.isCompletion()) {
                completionTerms.add(term);
                return false;
            }
            return true;
        }
    };
    StrategoTermVisitee.topdown(visitor, ast);
    return completionTerms;
}
Also used : IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) AStrategoTermVisitor(org.spoofax.terms.visitor.AStrategoTermVisitor) IStrategoTermVisitor(org.spoofax.terms.visitor.IStrategoTermVisitor) ImploderAttachment(org.spoofax.jsglr.client.imploder.ImploderAttachment) ListImploderAttachment(org.spoofax.jsglr.client.imploder.ListImploderAttachment)

Aggregations

IStrategoTerm (org.spoofax.interpreter.terms.IStrategoTerm)7 AStrategoTermVisitor (org.spoofax.terms.visitor.AStrategoTermVisitor)7 IStrategoTermVisitor (org.spoofax.terms.visitor.IStrategoTermVisitor)7 ISourceLocation (org.metaborg.core.source.ISourceLocation)3 ImploderAttachment (org.spoofax.jsglr.client.imploder.ImploderAttachment)3 ListImploderAttachment (org.spoofax.jsglr.client.imploder.ListImploderAttachment)3 IStrategoAppl (org.spoofax.interpreter.terms.IStrategoAppl)1