[antlr-interest] Re: Regular expression "repetition"
peg_ericsson
per.geil at ericsson.com
Tue May 18 00:34:06 PDT 2004
Thanks Mark,
I think your approach is right: "write the grammar to accept any
number at all ,and then generate an error for the user if the limits
are exceeded or not met."
My original problem was that I wanted an easy way to translate the
following piece of protocol syntax presented in ABNF:
AuthData = "0x" 24*64(HEXDIG)
domainName = (...) *63(ALPHA / DIGIT / "-" / ".") (...)
to ANTLR syntax. I will just write it like:
AuthData : "0x" (HEXDIG)+;
and then check if the string length is within 24..64.
Thanks,
Per
--- In antlr-interest at yahoogroups.com, Mark Lentczner <markl at g...>
wrote:
>
> I have found that it is often much more useful, both for the
grammar
> and for the user to express size limits (on characters in
identifiers,
> in number of digits for numbers, or repeats of some rule) as
semantic
> constraints: Write the grammar to accept any number at all, and
then
> generate an error for the user if the limits are exceeded or not
met.
> Consider:
>
> ID: LETTER{1,8} ;
> protected LETTER: 'a'..'z' ;
>
> Does anyone expect "subtotals" to parse as two IDs?
>
> In your case, have you considered what a run of 64 r structures
should
> be? It is just an error, or is really a structure of 63 r.s
followed
> by 1 r?
>
> - Mark
>
> Mark Lentczner
> markl at w...
> http://www.wheatfarm.org/
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/antlr-interest/
<*> To unsubscribe from this group, send an email to:
antlr-interest-unsubscribe at yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list