[antlr-interest] wildcard isn't?

Jim Idle jimi at temporal-wave.com
Thu Aug 2 09:36:40 PDT 2007


Wildcard in a parser rule (that starts with lower case) means "Any
defined token", but you don't have any token defined for '/'. A LEXER
rule starts with an Upper Case letter and there, '.' also means anything
in your character set, hence . means any character.

So you want something like:

COMMENT: '#' ~('\n'|'\r')*

Then you can use the COMMENT token in your parser rule.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Jack Tanner
> Sent: Thursday, August 02, 2007 9:26 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] wildcard isn't?
> 
> I have the following grammar:
> 
> line	:	comment? EOL ;
> comment	:	'#' .* ;
> EOL	:	'\r' | '\n' | '\r\n' ;
> 
> It fails on this input:
> 
> # foo/bar
> 
> The error relates to the slash between foo and bar. I can modify the
> grammar as
> follows:
> 
> comment	:	'#' ( . | '/')* ;
> 
> It works fine then, but it seems bizarre that the . wildcard doesn't
> consume the
> slash. Is that a bug, or am I misunderstanding the wildcard?
> 



More information about the antlr-interest mailing list