[antlr-interest] Help with discarding lexer tokens....

David-Sarah Hopwood david-sarah at jacaranda.org
Wed Jul 22 20:42:30 PDT 2009


Fredrik Ohrstrom wrote:
> I would like to ignore certain tokens found at the lexer level.
> For example: my example source code is sprinkled with tokens
> like [remove] and I want to prevent these to be seen by the parser.
[...]
> I did finally stumble upon a solution, but it is ugly.
> 
> grammar Test;
> cmd	:  (CMD suffix? )* ;
> suffix : LB CMD RB ;

  suffix : LB c=CMD RB
    { if ($c != null && $c.text.equals("remove")) $channel = HIDDEN; } ;

> CMD :	'a'..'z'+ ;

  LB : '[' ;

> RB : ']' ;
> WS :   (' '|'\t'|'\r'|'\n')+ { $channel=HIDDEN; } ;

-- 
David-Sarah Hopwood  ⚥  http://davidsarah.livejournal.com



More information about the antlr-interest mailing list