From b06454a4bc8c712db49b8246a269fcf9ce7cdc47 Mon Sep 17 00:00:00 2001 From: Brandon Dyck Date: Mon, 2 Sep 2024 21:20:13 -0600 Subject: [PATCH] Get rid of binary Choose --- gigaparsec.go | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) 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))