Boost logo

Boost Users :

From: Scott Lamb (slamb_at_[hidden])
Date: 2004-05-03 15:44:42


On May 3, 2004, at 3:15 PM, Eric Niebler wrote:

> John Maddock wrote:
>>> i think, "(one|two|three|)" style alternation (notice the empty
>>> string on
>>> the right) should be accepted and handled as "(one|two|three)?"
>>> now it throws bad_expression
>> I'm not sure about this one, Boost.regex has always deliberately
>> rejected
>> that, and although I realise that perl5 does accept this, perl6 will
>> regard
>> it as an error I believe.
>
> Indeed, this will be an error in perl 6. See "Null String Reform" at
> http://www.perl.com/pub/a/2002/06/04/apo5.html?page=10. You will have
> to write this as (one|two|three|<null>).
>
> I think it would be a horrible mistake for (one|two|three|) to be
> handled as (one|two|three). Either accept it for what it is or reject
> it, but don't try to second-guess what the programmer really meant.

Ugh, that'd be bad. I don't think anyone is looking for that; the
"(one|two|three)?" is like "(one|two|three|<null>)". [*] I bet you just
didn't notice the question mark? I didn't either on my first read.

I think one argument against <null> is that deviating from the normal
basis case would needlessly complicate algorithms that generate regexs
on-the-fly. (Requiring extra logic to avoid an arbitrarily-imposed
error.) But as I can't think of a good example where it'd come up,
maybe it's not so important.

[*] - except I think "(one|two|three)?" generates no capture group on
an empty match. but I assume he didn't mean the comparison to extend
that far.

Scott


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net