Don't require so much Pos() when making messages
This commit is contained in:
+6
-6
@@ -70,14 +70,14 @@ func Regexp(pattern string) gigaparsec.Parser[byte, string] {
|
||||
}
|
||||
if idx == nil {
|
||||
if err == io.EOF {
|
||||
return gigaparsec.Fail[byte, string](false, gigaparsec.MessageEnd(input.Pos())), nil
|
||||
return gigaparsec.Fail[byte, string](false, input.MessageOK()), nil
|
||||
}
|
||||
got := make([]byte, r.Count())
|
||||
_, _, err = input.Read(got)
|
||||
if err != nil {
|
||||
return gigaparsec.Result[byte, string]{}, fmt.Errorf("Regexp: unexpected error: %w", err)
|
||||
}
|
||||
return gigaparsec.Fail[byte, string](false, gigaparsec.MakeMessage(input.Pos(), string(got), expected)), nil
|
||||
return gigaparsec.Fail[byte, string](false, input.Message(string(got), expected)), nil
|
||||
}
|
||||
// Alas, this is a little wasteful because a Regexp can only return indices
|
||||
// when searching a RuneReader.
|
||||
@@ -87,7 +87,7 @@ func Regexp(pattern string) gigaparsec.Parser[byte, string] {
|
||||
return gigaparsec.Result[byte, string]{}, fmt.Errorf("Regexp: unexpected error: %w", err)
|
||||
}
|
||||
next := input.At(input.Pos() + n)
|
||||
return gigaparsec.Succeed(true, string(dst), next, gigaparsec.MessageOK(input.Pos())), nil
|
||||
return gigaparsec.Succeed(true, string(dst), next, input.MessageOK()), nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,14 +98,14 @@ func MatchString(s string) gigaparsec.Parser[byte, string] {
|
||||
dst := make([]byte, len(s))
|
||||
_, next, err := input.Read(dst)
|
||||
if errors.Is(err, io.EOF) {
|
||||
return gigaparsec.Fail[byte, string](false, gigaparsec.MessageEnd(input.Pos(), expected)), nil
|
||||
return gigaparsec.Fail[byte, string](false, input.MessageEnd(expected)), nil
|
||||
}
|
||||
if err != nil {
|
||||
return gigaparsec.Result[byte, string]{}, fmt.Errorf("MatchString: %w", err)
|
||||
}
|
||||
if !bytes.Equal(dst, b) {
|
||||
return gigaparsec.Fail[byte, string](false, gigaparsec.MakeMessage(input.Pos(), string(dst), expected)), nil
|
||||
return gigaparsec.Fail[byte, string](false, input.Message(string(dst), expected)), nil
|
||||
}
|
||||
return gigaparsec.Succeed(true, s, next, gigaparsec.MessageOK(input.Pos())), nil
|
||||
return gigaparsec.Succeed(true, s, next, input.MessageOK()), nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user