Search in sources :

Example 6 with AStrategoTermVisitor

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

the class TracingService method toTermsWithin.

private Iterable<IStrategoTerm> toTermsWithin(IStrategoTerm ast, final ISourceRegion region) {
    if (ast == 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 = location(term);
            if (location != null && region.contains(location.region())) {
                parsed.add(term);
                // no need to check the children, as this term is already within the given region
                return false;
            }
            return true;
        }
    };
    StrategoTermVisitee.topdown(visitor, ast);
    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 7 with AStrategoTermVisitor

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

the class TracingService method toTerms.

private Iterable<IStrategoTerm> toTerms(IStrategoTerm ast, final ISourceRegion region) {
    if (ast == 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 = location(term);
            if (location != null && location.region().contains(region)) {
                parsed.add(term);
                return false;
            }
            return true;
        }
    };
    StrategoTermVisitee.bottomup(visitor, ast);
    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)

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