[antlr-interest] RewriteEmptyStreamException when changing from quoted string to token?

Mark Wright markwright at internode.on.net
Sat Jan 5 07:04:21 PST 2008


Hello Jon,

Here is an example stack trace of the exception:

Exception in thread "main" org.antlr.runtime.tree.RewriteEarlyExitException
        at tntdbo.dboc.TntdboParser.template_parameter_list(TntdboParser.java:15830)
        at tntdbo.dboc.TntdboParser.template_declaration(TntdboParser.java:15677)
        at tntdbo.dboc.TntdboParser.declaration(TntdboParser.java:5443)
        at tntdbo.dboc.TntdboParser.declaration_seq(TntdboParser.java:5327)
        at tntdbo.dboc.TntdboParser.namespace_body(TntdboParser.java:9378)
        at tntdbo.dboc.TntdboParser.original_namespace_definition(TntdboParser.java:9142)
        at tntdbo.dboc.TntdboParser.named_namespace_definition(TntdboParser.java:9053)
        at tntdbo.dboc.TntdboParser.namespace_definition(TntdboParser.java:8958)
        at tntdbo.dboc.TntdboParser.declaration(TntdboParser.java:5471)
        at tntdbo.dboc.TntdboParser.declaration_seq(TntdboParser.java:5327)
        at tntdbo.dboc.TntdboParser.translation_unit(TntdboParser.java:243)
        at tntdbo.dboc.Tntdboc.process(Tntdboc.java:99)
        at tntdbo.dboc.Tntdboc.<init>(Tntdboc.java:39)
        at tntdbo.dboc.Tntdboc.main(Tntdboc.java:65)

So I open up the 1.2 MB generated Java parser source file in emacs,
(as netbeans just hangs when trying to open it), and go to line 15830
from the stack trace above.  The relevant fragment is below.
Then I look above the line where the RewriteEarlyExitException
was thrown, to the comment that ANTLR helpfully generated for
me to let me know the line in my grammar where I screwed up.

// AST REWRITE
// elements: template_parameter
// token labels: 
// rule labels: retval
// token list labels: 
// rule list labels: 
retval.tree = root_0;
RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"token retval",retval!=null?retval.tree:null);

root_0 = (TntdboAST)adaptor.nil();
// 1175:17: -> ^( TEMPLATE_PARAM ( template_parameter )+ )
{
    // Tntdbo.g:1175:20: ^( TEMPLATE_PARAM ( template_parameter )+ )
    {
    TntdboAST root_1 = (TntdboAST)adaptor.nil();
    root_1 = (TntdboAST)adaptor.becomeRoot((TntdboAST)adaptor.create(TEMPLATE_PARAM, "TEMPLATE_PARAM"), root_1);

    if ( !(stream_template_parameter.hasNext()) ) {
        throw new RewriteEarlyExitException();          <=== line 15830
    }
    while ( stream_template_parameter.hasNext() ) {
        adaptor.addChild(root_1, stream_template_parameter.nextTree());

    }
    stream_template_parameter.reset();

    adaptor.addChild(root_0, root_1);
    }

}

I look at that line:

template_parameter_list
  :   template_parameter ( ',' template_parameter )*
          -> ^(TEMPLATE_PARAM template_parameter+)      <=== line 1175
  ;

and I guess it is wrong, it does not like the plus in the AST rewrite.
I tried changing it to:

template_parameter_list
  :   l+=template_parameter ( ',' l+=template_parameter )*
          -> ^(TEMPLATE_PARAM $l)      <=== line 1175
  ;

It then gets past the RewriteEarlyExitException (to another issue in my grammar).

I hope this gives some hints on how to debug it.

Regards, Mark

-- 


More information about the antlr-interest mailing list