[antlr-interest] Tree pattern matching and delegate grammars (imported grammars) incompatible?

Søren Boisen sboisen at mail.dk
Tue Jan 24 06:49:50 PST 2012


Hi there,
I'm trying to build a tree pattern matcher that rewrites my AST. Right
now, I'm trying to define a shared grammar for some common rules and
use it in my tree pattern matchers by importing it.
My problem is that the input TreeNodeStream doesn't seem to be shared
between the root grammar and the delegate. I've been looking hard at
the code involved, and it seems to me that this excerpt from
TreeRewriter is the culprit:

    public Object applyOnce(Object t, fptr whichRule) {
        if ( t==null ) return null;
        try {
            // share TreeParser object but not parsing-related state
            state = new RecognizerSharedState();
            input = new CommonTreeNodeStream(originalAdaptor, t);
        ...
    }

So my question becomes: is tree pattern matching (and rewriting)
simply incompatible with grammar inheritance/delegation? Is there a
workaround?
It would be nice if such limitations were documented on the wiki, I
couldn't find any info on it at all.

Best regards
Søren


More information about the antlr-interest mailing list