[antlr-interest] Token stream filter

Ric Klaren klaren at cs.utwente.nl
Wed Jun 2 08:46:03 PDT 2004


On Wed, Jun 02, 2004 at 03:37:15PM +0100, Anthony Youngman wrote:
> If I don't want to eat up the newline at the end, is the following
> likely to be a good/sensible parser rule?
> 
> commentst : REMARK ( (LA(1) != newline) => . )* ;
> 
> in other words, having found a REMARK, eat everything up to but not
> including the next newline. Or is LA a lexer-only thing as well?

That one is a bit inefficient due to an exception per character:

This is a dirty one but it works:

comment: REMARK ( { if( LA(1) == NEWLINE ) break; } : . )* ;

Tip: read the generated code.

Cheers,

Ric
-- 
-----+++++*****************************************************+++++++++-------
    ---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893755  ----
-----+++++*****************************************************+++++++++-------
 'And this 'rebooting' business? Give it a good kicking, do you?' 'Oh, no,
  of course, we ... that is ... well, yes, in fact,' said Ponder. 'Adrian
    goes round the back and ... er ... prods it with his foot. But in a
     technical way,' he added. --- From: Hogfather by Terry Pratchett.



 
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