Consume entire input in sexp parser
This commit is contained in:
parent
2d3c8748be
commit
c770c1ca8b
@ -147,7 +147,12 @@ func parseList(input gigaparsec.State[byte]) (gigaparsec.Result[byte, Sexp], err
|
||||
}
|
||||
|
||||
func Parse(data []byte) (Sexp, error) {
|
||||
result, err := parseSexp(gigaparsec.MakeState(cursor.NewSlice(data)))
|
||||
parser := gigaparsec.Seq2(
|
||||
parseSexp,
|
||||
gigaparsec.End[byte](),
|
||||
func(s Sexp, _ struct{}) Sexp { return s },
|
||||
)
|
||||
result, err := parser(gigaparsec.MakeState(cursor.NewSlice(data)))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("csexp.Parse: %w", err)
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
|
||||
"git.codemonkeysoftware.net/b/peachy-go/csexp"
|
||||
"git.codemonkeysoftware.net/b/peachy-go/csexp/gen"
|
||||
"github.com/shoenig/test"
|
||||
"github.com/shoenig/test/must"
|
||||
"pgregory.net/rapid"
|
||||
)
|
||||
@ -33,6 +34,19 @@ func TestStringAndParseEqual(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestParseFails(t *testing.T) {
|
||||
t.Run("with extra input", rapid.MakeCheck(func(t *rapid.T) {
|
||||
sexp := gen.Sexp().Draw(t, "sexp")
|
||||
b := []byte(sexp.String())
|
||||
extra := rapid.SliceOfN(rapid.Byte(), 1, -1).Draw(t, "extra")
|
||||
b = append(b, extra...)
|
||||
parsed, err := csexp.Parse(b)
|
||||
test.Error(t, err)
|
||||
test.Nil(t, parsed)
|
||||
}))
|
||||
t.Run("with too little input", rapid.MakeCheck(func(t *rapid.T) {}))
|
||||
}
|
||||
|
||||
func TestCloneEqual(t *testing.T) {
|
||||
rapid.Check(t, func(t *rapid.T) {
|
||||
sexp := gen.Sexp().Draw(t, "sexp")
|
||||
|
Loading…
Reference in New Issue
Block a user