[antlr-interest] Can subrules be set to 'n-to-m'?

Richard Matthias richard at exaflop.org
Thu Mar 24 14:47:49 PST 2005


>> Ter,
>>  I think you should put this in 3.0 only if it is widely 
>useful, which 
>> it doesn't seem to be.
>> For special cases like this, people can use the code like 
>its provided 
>> above.
>> 
>
>
>Actually I think (...)+[n,m] comes up often enough to make it 
>a useful feature of the ANTLR grammar. Using the action code 
>is unwieldy and messy, but if there are no other options, then 
>it's the only way. 

Yes, I hate putting checks in action code for something so simple and it does
come up often enough when you are trying to covert rules from a 'lex' type
scanner. I'm pulling my hair out now with trying to get the sample CSS
grammar to work with antlr (pretty close to giving up and using the Apache
Batik project's hand-coded parser). That has a rule for unicode escapes.

H : '0'..'9' | 'a'..'f';
UNICODE : '\\' (H)+		// one to six hex characters
           { some action code here to check the length;}
        ;

I suppose another way to do it would be

UNICODE : '\\' H ( H ( H ( H ( H ( H )? )? )? )? )? ;

Not pretty though!

richard



More information about the antlr-interest mailing list