[antlr-interest] Syntactic predicates don't work in lexer grammar

Farr, John john.farr at medtronic.com
Mon Jul 30 07:36:09 PDT 2007


I have a situation where (I think) I need a syntactic predicate in my
lexer grammar. I have to deal with a section of input that contains
arbitrary text terminated by a keyword. This is similar to the
multi-line comment case, but differs in that the keyword is case
insensitive. Here's the relevant part of the grammar...


lexer grammar example;

fragment SOME_TEXT_BEGIN
    : ('S'|'s') ('O'|'o') ('M'|'m') ('E'|'e')
      '_' ('T'|'t') ('E'|'e') ('X'|'x') ('T'|'t')
    ;

fragment SOME_TEXT_END
    : ('S'|'s') ('O'|'o') ('M'|'m') ('E'|'e')
      '_' ('T'|'t') ('E'|'e') ('X'|'x') ('T'|'t')
      '_' ('E'|'e') ('N'|'n') ('D'|'d')
    ;

SOME_TEXT
    : SOME_TEXT_BEGIN
      ( options {greedy = false;} . )*
      ( SOME_TEXT_END ) => SOME_TEXT_END
    ;


In the generated code there is the expected call to synpred1(), but the
problem is that no synpred1() function is generated!

I've had to resort to the following definition for SOME_TEXT...


SOME_TEXT
    : SOME_TEXT_BEGIN
      ( options {greedy = false;} . )*
      ( 'SOME_TEXT_END' | 'some_text_end' | 'Some_Text_End' )
    ;


As you can see, providing explicit alternatives for each combination of
upper/lower case letters would be less than desirable.

Is this a bug in ANTLR or am I missing something?
Is there some other way to deal with a situation like this?

Thanks,
John

___________________________________________________________________________________________________
CONFIDENTIALITY AND PRIVACY NOTICE
Information transmitted by this email is proprietary to Medtronic and is intended for use only by the individual or entity to which it is addressed, and may contain information that is private, privileged, confidential or exempt from disclosure under applicable law. If you are not the intended recipient or it appears that this mail has been forwarded to you without proper authority, you are notified that any use or dissemination of this information in any manner is strictly prohibited. In such cases, please delete this mail from your records.

To view this notice in other languages you can either select the following link or manually copy and paste the link into the address bar of a web browser: http://emaildisclaimer.medtronic.com


More information about the antlr-interest mailing list