[Haskell-cafe] ReadP question

Tom Phoenix rootbeer at redcat.com
Wed Aug 30 19:25:35 EDT 2006


On 8/30/06, Chris Kuklewicz <haskell at list.mightyreason.com> wrote:

> > -- Simulate "(a?|b+|c*)*d" regular expression

> But 'go' seems to not terminate with the leading 'star'

Unless I'm missing something... The part of the pattern inside the
parentheses should successfully match at least the empty string at the
beginning of the string. Since it's regulated by the second (outer)
'star', it will keep matching as long as it keeps succeeding; since it
keeps matching the empty string, it keeps matching forever in the same
spot.

To solve this problem, your implementation of 'star' could perhaps be
changed to answer "no more matches" rather than "infinitely many
matches" once the body fails to consume any characters.

Hope this helps!

--Tom Phoenix


More information about the Haskell-Cafe mailing list