diff --git a/TODO.txt b/TODO.txt index aad8838..081cdda 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,4 +1,3 @@ -Result should be Failed by default Test RuneReader Test Regexp Add SPDX tags diff --git a/gigaparsec.go b/gigaparsec.go index 2f181e6..e07bd31 100644 --- a/gigaparsec.go +++ b/gigaparsec.go @@ -10,23 +10,23 @@ import ( ) type Result[In, Out any] struct { - consumed, failed bool - value Out - next State[In] - message Message + consumed, succeeded bool + value Out + next State[In] + message Message } func Fail[In, Out any](consumed bool, msg Message) Result[In, Out] { return Result[In, Out]{ - consumed: consumed, - failed: true, - message: msg, + consumed: consumed, + succeeded: false, + message: msg, } } -func (r Result[In, Out]) Failed() (ok, consumed bool, msg Message) { - ok = r.failed - if ok { +func (r Result[In, Out]) Failed() (failed, consumed bool, msg Message) { + failed = !r.succeeded + if failed { consumed = r.consumed msg = r.message } @@ -35,17 +35,17 @@ func (r Result[In, Out]) Failed() (ok, consumed bool, msg Message) { func Succeed[In, Out any](consumed bool, value Out, next State[In], msg Message) Result[In, Out] { return Result[In, Out]{ - failed: false, - value: value, - consumed: consumed, - next: next, - message: msg, + succeeded: true, + value: value, + consumed: consumed, + next: next, + message: msg, } } -func (r Result[In, Out]) Succeeded() (ok, consumed bool, value Out, next State[In], msg Message) { - ok = !r.failed - if ok { +func (r Result[In, Out]) Succeeded() (succeeded, consumed bool, value Out, next State[In], msg Message) { + succeeded = r.succeeded + if succeeded { consumed = r.consumed value = r.value next = r.next diff --git a/parser_test.go b/parser_test.go index 9f8464c..94be345 100644 --- a/parser_test.go +++ b/parser_test.go @@ -56,8 +56,10 @@ func TestSlice(t *testing.T) { r := ptest.ErrReaderAt(expectedErr) c := cursor.NewReaderAt(r) s := rapid.SliceOfN(rapid.Byte(), 0, 100).Draw(t, "s") - _, err := gigaparsec.Slice(s)(gigaparsec.MakeState(c)) + result, err := gigaparsec.Slice(s)(gigaparsec.MakeState(c)) + failed, _, _ := result.Failed() test.ErrorIs(t, err, expectedErr) + test.True(t, failed) })) t.Run("succeeds when contents match", rapid.MakeCheck(func(t *rapid.T) { input := rapid.SliceOfN(rapid.Byte(), 1, -1).Draw(t, "input")