
How to use parsec to match optional things. Lets consider regex style matching of greedy a?b, lazy a??b, and possessive a?+b. And consider greedy a*b, lazy a*?b, and possessive a*+b. Then I think these examples (cribbed from my module) will work: -- Building blocks greedyOpt p contFail contSuccess = try (p >> contSuccess) <|> contFail lazyOpt p contFail contSuccess = try contFail <|> (p >> contSuccess) possessiveOpt p contFail contSuccess = ((try p) >> contSuccess) <|> contFail -- Match p*cont p*?cont p*+cont greedyStar p cont = fix (greedyOpt p cont) lazyStar p cont = fix (lazyOpt p cont) possessiveStar p cont = fix (possessiveOpt p cont) -- Match p?cont p??cont p?+cont greedyQuest p cont = greedyOpt p cont cont lazyQuest p cont = lazyOpt p cont cont possessiveQuest p cont = possessiveOpt p cont cont Altering p to return a useful value is left to the user.