[stringtemplate-interest] [ST4 Beta 2] Endless loop when loading invalid group file

Udo Borkowski ub at abego-software.de
Mon Jan 24 00:46:05 PST 2011


Did some more debugging (and generated the GroupLexer.java ;-) 

It looks like the problem is in Group.g ANONYMOUS_TEMPLATE:

        ...
        while ( lexer.subtemplateDepth>=1 || t.getType()!=STLexer.RCURLY ) {
            t = lexer.nextToken();
        }

One needs to check for the EOF_TYPE and raise an error if no closing brace is found.

Here the code I am now using to work around this issue:

while (lexer.subtemplateDepth >= 1 || t.getType() != STLexer.RCURLY) {
    t = lexer.nextToken();
    if (t.getType() == STLexer.EOF_TYPE) {
        throw new RuntimeException(
                String.format(
                        "Anonymous template starting at %d:%d of %s is not closed (missing '}')",
                        input.getLine(),
                        input.getCharPositionInLine(),
                        input.getSourceName()));
    }
}



Udo


Begin forwarded message:

> From: Udo Borkowski <ub at abego-software.de>
> Date: 24. Januar 2011 00:48:08 MEZ
> To: "stringtemplate-interest at antlr.org List" <stringtemplate-interest at antlr.org>
> Subject: [stringtemplate-interest] [ST4 Beta 2] Endless loop when loading invalid group file
> 
> Trying to load a group file with this content
> 
> "main(p) ::= {"
> 
> (without quotes)
> 
> results into an endless loop. I didn't debug in details because of missing source files but it looks like the problem is located in
> 
> 	GroupLexer.mANONYMOUS_TEMPLATE() line: 604	
> 
> 
> Udo
> 
> P.S.: You may wonder why I come up with these strange files. I am currently working on an interactive application and then these "invalid" groups are created as "intermediate steps" while editing.
> 
> 
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20110124/7bc0cc84/attachment.html 


More information about the stringtemplate-interest mailing list