[antlr-interest] Comments in Tcl - Lexer

dmp dmp0x7c5 at gmail.com
Sat Jun 11 17:07:07 PDT 2011


Hello,

I'm working with Antlr to provide syntax highlight for Tcl (in
Netbeans). I have a problem with COMMENT token.
Basic version for one line comment looks like this:

COMMENT :
     '#' (options {greedy=false;} : .)* NEWLINE
;

But comment in Tcl starts only at the beginning of a line with
optional whitespace or after ";" also with optional whitespace.
How can I handle this using antlr grammar and lexer?

I've already allowed to use '#' in IDs:
ID :
     ('a'..'z'|'A'..'Z'|'0'..'9'|'_'|'#')+
;

It's difficult to find simple solution because char stream provided
from Netbeans it's not full source but only parts displayed/edited. I
followed some tips from this mailing list for example:
http://wklej.org/id/544171/ but It doesn't solve my problem.

I would be grateful if someone could give me some advices.

Thanks,
dmp


More information about the antlr-interest mailing list