
Chris Kuklewicz wrote:
I just tried to mimic regular expression matching with ReadP and got what seems like a non-terminating program. Is there another way to use ReadP to do this?
-- Simulate "(a?|b+|c*)*d" regular expression test = star (choice [quest (c 'a') ,plus (c 'b') ,star (c 'c')]) +> c 'd'
Indeed, this cannot work. ReadP delivers parses in order of increasing length, and your expression produces infinitely many parses of the empty string, you never get to the interesting matches. I'd say, the best solution is to use an equivalent regex which does not contain something of the form 'many (return x)':
-- Simulate "(a?|b+|c*)*d" regular expression test' = star (choice [(c 'a') ,plus (c 'b') ,plus (c 'c')]) +> c 'd'
Udo. -- f u cn rd ths, u cn gt a gd jb n cmptr prgrmmng.