MULTI_COMMENT
: '/*'
{
$channel=HIDDEN;
}
( ~('/'|'*')
| ('/' ~'*') => '/'
| ('*' ~'/') => '*'
| MULTI_COMMENT
)*
'*/'
;
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of micha
Sent: Wednesday, December 03, 2008 4:18 AM
To: [EMAIL PROTECTED]
Subject: [antlr-interest] lexing nested comments
Hi,
I don't get the lexer rules correct to lex my nested comments.
As a workaround I use the following, see below. What are the right rules
for
this ?
thanks
Michael
------------------------------------------
one lexer rule:
MULTI_COMMENT: '/*' { nestedComment(0); skip(); }
and in the @members section (my STRINGs don't allow escapes):
private final void nestedComment(int nest) throws
RecognitionException {
System.err.println("reading Comment nesting level " +
nest);
while (true) {
int la = input.LA(1);
if (la == '/') {
input.consume();
la = input.LA(1);
if (la == '*') {input.consume();
nestedComment(nest+1);}
}
else if (la == '*') {
input.consume();
la = input.LA(1);
if (la == '/') {input.consume();
return;}
}
else if (la == '"') {
mSTRING();
} else
input.consume();
}
}
List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-addr
ess
List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---