[antlr-interest] Lexer Rule matching member variable (Java)

Daniels, Troy (US SSA) troy.daniels at baesystems.com
Mon Aug 23 07:56:57 PDT 2010


Is there a reason this won't work?

TEXT:
   ( {lxstate == State.NORMAL && input.LA(1) != curspecial}?=>. )+

This should cause the predicate to be evaluated inside the loop, rather than outside, and consumes each character that passes.  While the generated code should be more or less the same, this version decreases the language specific code, might let ANLTR do better lookahead (especially if you reduce the text that can match) and won't be as sensitive to changes in the API.

Troy
 

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org 
> [mailto:antlr-interest-bounces at antlr.org] On Behalf Of 
> Frederic Beister
> Sent: Sunday, August 22, 2010 9:22 AM
> To: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] Lexer Rule matching member 
> variable (Java)
> 
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Hi,
> 
> just for the archives: This worked with small one small 
> modification regarding the EOF-Token:
> 
> TEXT:
>   {lxstate == State.NORMAL && input.LA(1) != curspecial}?=>.
> {
>  while (input.LA(1) != curspecial && input.LA(1) != CharStream.EOF) {
>   input.consume();
>  }
> }
> ;
> 
> Thanks again
> Frederic
> 
> 
> 
> 
> Am 20.08.2010 18:15, schrieb Jim Idle:
> > You just need to not use ANY. Once the predicate matches, 
> your rule is 
> > selected and it will do whatever you tell it. So, don't use 
> ANY+ just 
> > put some code in to consume until you get to some point 
> that you don't 
> > want to consume any more:
> > 
> > TEXT: { lxstate==State.NORMAL && input.LA(1)!=curspecial} ?=> .
> > {
> >   while (input.LA(1) != curspecial) { input.consume(); } } ;
> > 
> > It is often instructive to look at the generated code and 
> steal from 
> > it to get where you need to.
> > 
> > Jim
> > 
> >> -----Original Message-----
> >> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest- 
> >> bounces at antlr.org] On Behalf Of Frederic Beister
> >> Sent: Friday, August 20, 2010 12:34 AM
> >> To: antlr-interest at antlr.org
> >> Subject: Re: [antlr-interest] Lexer Rule matching member variable 
> >> (Java)
> >>
> >>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address
> 
> > List: http://www.antlr.org/mailman/listinfo/antlr-interest
> > Unsubscribe: 
> > 
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> 
> 
> - --
> PGP Fingerprint = 782C 2BE7 0972 D632 8BDF 4A23 3811 174A 
> 1530 64ED -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
> 
> iEYEARECAAYFAkxxJIIACgkQOBEXShUwZO10xQCfZtRkA0b9yyfQJze4IsogkdaK
> 5xMAnjnIEqtmMPhGsNRKUSvyXotxf0rz
> =bq0d
> -----END PGP SIGNATURE-----
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: 
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> 


More information about the antlr-interest mailing list