Compare commits

..

2 Commits

Author SHA1 Message Date
4e157f7a0e Regexp: succeed on empty match at end of input 2025-04-02 14:06:12 -06:00
1892a97070 Add some TODOs 2025-04-02 13:27:16 -06:00
3 changed files with 12 additions and 2 deletions

View File

@ -4,4 +4,6 @@ Rename Seq2 to Seq
Document Seq
Should MakeState be private now that there's Run?
What's Megaparsec got that we ain't got?
Add and benchmark naïve Seq
Add and benchmark naïve Seq
chainl
whitespace handling

View File

@ -80,7 +80,7 @@ func Regexp(pattern string) gigaparsec.Parser[byte, string] {
// when searching a RuneReader.
dst := make([]byte, idx[1]-idx[0])
n, _, err := input.Read(dst)
if err != nil {
if err != nil && (!errors.Is(err, io.EOF) || n < uint64(len(dst))) {
return gigaparsec.Result[byte, string]{}, fmt.Errorf("Regexp: unexpected error: %w", err)
}
next := input.At(input.Pos() + n)

View File

@ -61,6 +61,14 @@ func TestRegexp(t *testing.T) {
must.NoError(t, err)
test.StrContains(t, result.Message().Got(), "hella")
})
t.Run("succeeds on empty matches", func(t *testing.T) {
p := pbytes.Regexp(".*")
result, err := p(gigaparsec.MakeState(strings.NewReader("")))
succeeded, value, _ := result.Status()
must.NoError(t, err)
must.True(t, succeeded)
must.EqOp(t, "", value)
})
}
func TestRuneReader(t *testing.T) {