AW: [antlr-interest] Re: caseSensitive for one rule

Wirth. Michael M.Wirth at seeburger.de
Wed Jul 16 23:28:36 PDT 2003


I think this is a nice idea. Thanks.
But now I have found an other way.

I have found out that the token which I want to match case
insensitive is always standing behind another token. So I
match this token (the one before "end" in the example below)
than I catch the following word as an identifier. In a treeparser
I can now check this word however I want.

Thanks for the help. Sorry that I don't find out this solution before
asking in this list. But perhaps I can use your way in another project
or someoneelse use it.

Antlr is great!

> -----Ursprüngliche Nachricht-----
> Von: antlrlist [mailto:antlrlist at yahoo.com]
> Gesendet: Mittwoch, 16. Juli 2003 19:20
> An: antlr-interest at yahoogroups.com
> Betreff: [antlr-interest] Re: caseSensitive for one rule
> 
> 
> 
> Hello!
> 
> If you're trying to turn CaseSensitive *on some parser rules* I cannot
> help you - the AssertLowerCase solution is the best one I can 
> think of.
> 
> However, if you want to turn CaseSensitive on and off on some *tokens*
> you should modify the *Lexer*, not the *Parser*.
> 
> ( Sorry if I sound rude. Sometimes when I try to stress something it
> seems I'm angry - this is not the case :) )
> 
> Namely you should turn off CaseSensitive (or CaseSentiviteLiterals;
> that would be more efficient, but maybe not enough powerful) and then
> override testLiteralsTable in your lexer (I'll asume java mode):
> 
> <pre>
> options {
> caseSensitiveLiterals=false; // all literals are case-insensitive
> testLiterals=false; // Activate in IDENT
> }
> tokens{
>    END="end";     // case insensitive
>    START="start"; // case *sensitive*
>    FOO="foo";     // case *sensitive*
>    ...
> }
> 
> {
>     /** override testLiteralsTable **/
>     public int testLiteralsTable(String text, int oldtype)
>     {
>         int newtype = super.testLiteralsTable(text, oldtype);
>         switch(ttype)
>         {
>            // case sensitive tokens
>            case START : case FOO: case ... :
>               // return IDENT-or-whatever if is not
>               // completely lowercase (this could be more refined)
>               if(isLowerCase(text)) return oldtype;
>               return newtype;
>            // case insensitive tokens
>            default:
>               return newtype;
>         }
>     }
> }
> ...
> 
> // Surely you'll have an IDENT-like rule, where reserved words have to
> // be recognized. 
> IDENT
> :  options { testLiterals=true; }: 
>    LETTER (LETTER|DIGIT)*
> ;
> </pre>
> 
> I have not tried this out, but it should work fine. Please report!
> 
> Enrique.
> 
> PS: as a side note, I don't like using unnamed tokens - writing
> "start" in parser rules instead of START - with this solution you
> might not be able to use them.
> 
> 
> --- In antlr-interest at yahoogroups.com, "Wirth. Michael" <M.Wirth at s...>
> wrote:
> > Hi,
> > 
> > is there a way to set caseSensitive to false in one rule in 
> the parser?
> > Something like I wrote below.
> > I want that the "end", "End", "eNd", ... ist matched. Only 
> in this rule.
> > "start" should only be matched as "start", not as "Start".
> > 
> > 
> > ruleOne : "start" ruleTwo ;
> > 
> > ruleTwo :	
> >         options 
> >         {	
> >             caseSensitive = false;
> >         }:
> >         tok1:"end"
> >     ;
> > 
> > Is this possible?
> > 
> > 
> > Greetings,
> > 	Michael
 

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list