[antlr-interest] Unterminated html comments

Steve Bennett stevagewp at gmail.com
Sun Feb 17 20:45:56 PST 2008


Can anyone think how to lex both terminated and unterminated HTML
comments? That is:

<!-- this should all be one token -->

<!-- this should all be one token <EOF>

I have this:

HTML_COMMENT:
    (('<!--') => '<!--' .* ('-->' | EOF) { $channel=HIDDEN; })
    | '<' { $type=LT; };

But it doesn't work. On a line like: <!-- foo -->, the "<!-- f" gets
lost (doesn't form a token in ANTLRworks).

If I remove the "| EOF", it matches normal comments fine, but not
unterminated ones.

Thanks all,
Steve


More information about the antlr-interest mailing list