Stefan Bischof wrote:
> Hi guys,
>
> I'm currently using a rewriting tree grammar (rewrite=true, filter=true)
> which means my parser is extending org.antlr.runtime.tree.TreeRewriter.
>
> I want to feed output of my program directly to another program with an
> unnamed pipe | on the command line. Unfortunately that's not possible
> now because the TreeRewriter shows every rewriting on stdout (like a ->
> b).
>
> So, is there a possibility to suppress this output (yes, it's using
> System.out.println)?
>   
Hmmm - I wonder if it is supposed to be doing that:

            if ( r!=null && !t.equals(r.getTree()) && r.getTree()!=null 
) { // show any transformations
                System.out.println(((CommonTree)t).toStringTree()+" -> "+
                                   
((CommonTree)r.getTree()).toStringTree());
            }


Anyway, tell ANTLR to use a superclass say AbstractMyTreeRewriter  
(options { superClass=AbstractMyTreeRewriter; } ) and in that class:

public abstract class AbstractMyTreeRewriter extends TreeRewriter {

    public TreeRewriter(TreeNodeStream input) {
       super(input);
    }
    public TreeRewriter(TreeNodeStream input, RecognizerSharedState state) {
        super(input, state);
    }

    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);
            
((CommonTreeNodeStream)input).setTokenStream(originalTokenStream);
            setBacktrackingLevel(1);
            TreeRuleReturnScope r = (TreeRuleReturnScope)whichRule.rule();
            setBacktrackingLevel(0);
            if ( failed() ) return t;

            // 
-------------------------------------------------------------------------
            // Commented out the output
            //if ( r!=null && !t.equals(r.getTree()) && 
r.getTree()!=null ) { // show any transformations
            //    System.out.println(((CommonTree)t).toStringTree()+" -> "+
            //                       
((CommonTree)r.getTree()).toStringTree());
            //}

            if ( r!=null && r.getTree()!=null ) return r.getTree();
            else return t;
        }
        catch (RecognitionException e) { ; }
        return t;
    }

}

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to