[antlr-interest] Separating text from comment in a source file
Mark Venbrux
mark.venbrux at gmail.com
Tue May 15 08:12:12 PDT 2007
Hi,
I would like to separate text from comment in a source file. In the end I
would like to keep the source code as is, and to process the comments. I
tried the following grammar, but it doesn't work as expected.
Warning: [17:01:59] warning(201): d:\temp\antlr.g:26:40: The following
alternatives are unreachable: 1
This is about the TEXT rule.
Comments are picked up, but text is skipped. What is wrong here?
Cheers,
Mark
grammar antlr;
options {filter=true;}
@header {
package test;
}
@lexer::header {package test;}
@members {
}
file: (
COMMENT {System.out.println("CO: "+$COMMENT.text);}
| TEXT {System.out.println("TE: "+$TEXT.text);}
)*
;
COMMENT
: '/*' (options {greedy=false;} : . )* '*/'
;
TEXT
: (options {greedy=false;} : . )+
;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070515/5bcd738c/attachment.html
More information about the antlr-interest
mailing list