diff --git a/gigaparsec.go b/gigaparsec.go index 594eeb0..46afbd4 100644 --- a/gigaparsec.go +++ b/gigaparsec.go @@ -82,25 +82,7 @@ func Bind[In, A, B any](p Parser[In, A], f func(A) Parser[In, B]) Parser[In, B] } } -// TODO Add error propagation -func Choose[In, Out any](p, q Parser[In, Out]) Parser[In, Out] { - return func(input State[In]) (bool, Result[In, Out], error) { - consumedP, replyP, errP := p(input) - if consumedP { - return consumedP, replyP, errP - } - if errP != nil { - return q(input) - } - consumedQ, replyQ, errQ := q(input) - if consumedQ { - return consumedQ, replyQ, errQ - } - return consumedP, replyP, errP - } -} - -func ChooseMany[In, Out any](p Parser[In, Out], ps ...Parser[In, Out]) Parser[In, Out] { +func Choose[In, Out any](p Parser[In, Out], ps ...Parser[In, Out]) Parser[In, Out] { all := append([]Parser[In, Out]{p}, ps...) return func(input State[In]) (bool, Result[In, Out], error) { expecteds := make([][]string, 0, len(all))