[antlr-interest] wildcard isn't?

Randall R Schulz rschulz at sonic.net
Thu Aug 2 09:36:21 PDT 2007


On Thursday 02 August 2007 09:26, Jack Tanner wrote:
> 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?

If the grammar you showed in your email is really what you're using, 
then the problem is that these are _parser_ rules and the '.' wildcard 
is a _token_ wildcard, not a character wildcard as it would be a lexer 
rule.

Lexer rules must be named with their first letter upper case.


Randall Schulz


More information about the antlr-interest mailing list