From 0a1fe0821a1d8b8130e8e1c9d82c5ad96191341c Mon Sep 17 00:00:00 2001 From: Brandon Dyck Date: Mon, 2 Sep 2024 12:48:48 -0600 Subject: [PATCH] Now I understand how Try works --- gigaparsec.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gigaparsec.go b/gigaparsec.go index dde93a0..d6d223f 100644 --- a/gigaparsec.go +++ b/gigaparsec.go @@ -85,6 +85,11 @@ func Choose[In, Out any](p, q Parser[In, Out]) Parser[In, Out] { } } +// Try behaves identically to p, except that if p returns an error, +// Try will pretend that no input was consumed. This allows infinite +// lookahead: Since Choose only calls another parser when the previous +// parser consumed nothing, Try will allow backing out of a complex +// parser that did partially succeeded. func Try[In, Out any](p Parser[In, Out]) Parser[In, Out] { return func(input State[In]) (bool, Result[In, Out], error) { consumed, reply, err := p(input)