At 10:24 14/09/2008, Olya Krachina wrote:
>LONG_STRINGLITERAL
> :
> ('"') (~('"'|'\n'|'\r'))* ('"')
> {
> String wholeStr;
> int strLen, maxStrLen = 80;
> wholeStr = getText().toString();
> strLen = wholeStr.length();
> if ( strLen > maxStrLen )
> {
> {$setType(STRINGLITERAL))};
> }
> }
> ;
>
>It looks like this might work, only now i have to declare
>STRINGLITERAL somehow, i would have to write ANOTHER RULE for
>stringliteral, and i don't know what i could write where the
>prefix does not match the LONGSTRINGLITERAL rule;
You can declare it as a protected rule. That will define it as a
possible token type without making it a top-level candidate; if
you don't call it yourself elsewhere in the grammar then its
precise contents are irrelevant.
But as I said before I wouldn't do it this way. I'd just make a
STRINGLITERAL rule that tolerates string literals of any length,
and then do the length validation in the parser. It's much easier
to generate meaningful error messages in the parser than it is in
the lexer.
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
-~----------~----~----~----~------~----~------~--~---