[antlr-interest] matchRange in parser?

Benjamin Niemann pink at odahoda.de
Tue Jul 24 06:47:31 PDT 2007


jrc at skylon.demon.co.uk wrote:

> Should the following work?
> ----------------------------------------------------------------------
> grammar Simple;
> line         : systemIdList NEWLINE ;
> systemIdList : systemId | systemId ',' systemIdList ;
> systemId     : '0'..'9' ;
> NEWLINE      : '\r'? '\n' ;
> ----------------------------------------------------------------------
> Here's what I get:
> ----------------------------------------------------------------------
> $ java org.antlr.Tool Simple.g
> ANTLR Parser Generator  Version 3.0 (May 17, 2007)  1989-2007
> $ javac *.java
> SimpleParser.java:119: cannot find symbol
> symbol  : method matchRange(char,char)
> location: class SimpleParser
>             matchRange('0','9');
>             ^
> 1 error
> ----------------------------------------------------------------------
> Swapping 'systemId' (parser rule) to 'SystemId' (lexer rule) causes
> matchRange() to be found ...

Ranges ('0'..'9') can only be used in lexer rules. The grammar parser should
complain about it, when used in parser rules.
This probably falls into the category of things to come, once ANTLR3 itself
is written in ANTLR3.

-- 
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://pink.odahoda.de/



More information about the antlr-interest mailing list