[antlr-interest] Can subrules be set to 'n-to-m'?
Scott Stanchfield
scott at javadude.com
Fri Mar 25 19:21:34 PST 2005
I think these examples strengthen my point about how ugly the "+" is in
there...
In every regex language that I've seen that allows min/max cardinality, it's
something like
foo{n,m}
foo+
foo*
But not
foo+{n,m}
And they allow (but don't require) parens if you're matching a single
element.
C'mon -- let's be STANDARD about this. People have been using regex's for
years that work this way, so let's be similar.
(And to be clear, I understand the diff between parsing grammars and regexs
-- but there's no reason to have a different syntax if it's not necessary.)
<g>
-- Scott
> -----Original Message-----
> From: antlr-interest-bounces at antlr.org
> [mailto:antlr-interest-bounces at antlr.org] On Behalf Of John
> D. Mitchell
> Sent: Friday, March 25, 2005 5:13 PM
> To: Martin Probst
> Cc: 'antlr-interest Interest'
> Subject: RE: [antlr-interest] Can subrules be set to 'n-to-m'?
>
> >>>>> "Martin" == Martin Probst <mail at martin-probst.com> writes:
> [...]
>
> >> (...)+[n,m]
>
> >> with the ,m part optional.
>
> > Uh, better make only the "m" optional, e.g.
> >> (...)+[n,]
> > Otherwise it might be mistaken as "exactly n times". Maybe
> this should
> > indeed be the case for (...)+[n].
>
> Yes, I meant that to mean 'exactly". To be clear...
>
> (XYZ)+[n,m] means XYZ must occur anywhere from n through m
> times (inclusive on both ends).
>
> (XYZ)+[n] means XYZ must occur exactly n times.
>
> (XYZ)+[0,n] should be an error telling people that they
> should b using:
>
> (XYZ)*[0,n] means 0..n occurrences.
>
> (XYZ)*[n,m] means 0, or n..m occurrences.
>
> (XYZ)*[n] means 0 or exactly n occurrences.
>
> [Though, personally, I'm not sure that the last three cases
> are justifiable to include in the Antlr core. I'd like them
> for completeness and consistency and would actually be using
> them but I know that I'm a wacko. :-)]
>
> > Also (...)[1,] looks at least understandable for me - maybe as an
> > alias for (...)+.
>
> Naw, if you're going to support an "at least" construct then
> you've gotta make it more clearly distinct than that. Something like:
>
> (XYZ)+[n...] or
> (XYZ)+[n,...] or
> (XYZ)+[n,+]
>
> Hope this helps,
> John
More information about the antlr-interest
mailing list