[stringtemplate-interest] [ST4 Beta-3] Endless loop when template comment is not closed.

Udo Borkowski ub at abego-software.de
Thu Feb 3 10:22:09 PST 2011


A template comment that is not closed, e.g.

t() ::= <<
<!bad comment>
...
>>

leads to an endless loop.


I changed STLexer#COMMENT to work around this issue:

    void COMMENT() {
        match('!');
        while ( !(c=='!' && input.LA(2)==delimiterStopChar) ) {
        	if (c==EOF) {
				RecognitionException re =
					new MismatchedTokenException((int)'!', input);
				re.line = input.getLine();
				re.charPositionInLine = input.getCharPositionInLine();
				errMgr.lexerError(input.getSourceName(), "Comment not closed. '!"+delimiterStopChar+"' missing", templateToken, re);
				break;        		
        	}
        	consume();
        }
        consume(); consume(); // kill !>
    }


This fix works. However I guess it would be better if the error message could refer to the opening "<!", but I am not sure how to write this.

Udo



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20110203/dd498596/attachment-0001.html 


More information about the stringtemplate-interest mailing list