Add is.Digit to scan

pull/53/head
rwxrob 3 years ago
parent fb9eec2d5b
commit f2033baee8
No known key found for this signature in database
GPG Key ID: 2B9111F33082AE77

@ -49,10 +49,10 @@ type Min struct {
This any
}
// X scannable struct represents exactly X number of the given scannable
// N scannable struct represents exactly X number of the given scannable
// items (This).
type X struct {
X int
type N struct {
N int
This any
}
@ -67,3 +67,4 @@ type Rng struct {
// (keep most common to the left)
var WS = In{' ', '\n', '\t', '\r'}
var Digit = Rng{0, 9}

@ -359,8 +359,8 @@ func (s *Scanner) Expect(scannables ...any) (*Cur, error) {
}
end = last
case is.X: // ------------------------------------------------------
m, err := s.Expect(is.MMx{v.X, v.X, v.This})
case is.N: // ------------------------------------------------------
m, err := s.Expect(is.MMx{v.N, v.N, v.This})
if err != nil {
s.Jump(beg)
return nil, s.ErrorExpected(v)
@ -420,9 +420,9 @@ func (s *Scanner) ErrorExpected(this any, args ...any) error {
case is.MMx:
str := `expected min %v, max %v of %q`
msg = fmt.Sprintf(str, v.Min, v.Max, v.This)
case is.X:
case is.N:
str := `expected exactly %v of %q`
msg = fmt.Sprintf(str, v.X, v.This)
msg = fmt.Sprintf(str, v.N, v.This)
case is.Rng:
str := `expected range [%v-%v]`
msg = fmt.Sprintf(str, string(v.First), string(v.Last))

Loading…
Cancel
Save