[antlr-interest] Re: Lookbehind and other regex features

thrutchy eric_mahurin at yahoo.com
Wed Jul 14 10:53:48 PDT 2004


--- In antlr-interest at yahoogroups.com, Monty Zukowski <monty at c...> wrote:
> \On Jul 14, 2004, at 5:08 AM, Eric Mahurin wrote:
> 
> > Is there any way to accomplish lookbehind in the lexer or parser? This
> > is the main thing that I don't immediately see how to do in ANTLR that
> > I could in Perl's regex's.
> 
> You could implement this with your own actions in ANTLR if you wanted 
> to.  Override match() to keep a lookbehind buffer.  Then just check 
> against that with semantic predicates.
> 
> I'm not familiar with lookbehind, can you point to some examples of its 
> usefulness?  I believe using lexer states serves a similar purpose for 
> lexers.
> 
> Monty

Yep, that sounds like a solution.  Semantic predicates seem to cover a
lot.

Actually, I think the usefulness is probably limited.  Even with
regex's the lookbehind wasn't introduced until recently.  I think the
main uses would be in the lexer, but I haven't thought about it too
much.  A prime example would be for finding the beginning of a line -
last character was newline or beginning of file.  But, I know this can
be done now with the column variable in a semantic predicate.

I'm doing a good job convincing, am I?  I just noticed it as a missing
feature and pointed it out.  I was just thinking that it would be nice
if the lookahead buffer extended in the other direction so that you
could access say LA(-1), LA(-2), etc.  No syntax changes to the ANTLR
language for now - other than having a new option for the lookbehind
depth (defaulting to zero).

Do you know of a place for feature requests?  Or is it here?





 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

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



More information about the antlr-interest mailing list