Rename Toi -> Ti, Min -> M

pull/53/head
rwxrob 2 years ago
parent 52bb09eacb
commit 0bdb9536ef
No known key found for this signature in database
GPG Key ID: 2B9111F33082AE77

@ -108,24 +108,24 @@ type O []any
// boundary.
type To []any
// Toi is an inclusive version of is.To returning a cursor that points
// to the last rune of the boundary itself.
type Toi []any
// Ti ("to inclusive") is an inclusive version of is.To returning
// a cursor that points to the last rune of the boundary itself.
type Ti []any
// --------------------------- parameterized --------------------------
// MM is a parameterized advancing expression that matches an inclusive
// minimum and maximum count of the given expression (This).
// MM ("minmax") is a parameterized advancing expression that matches an
// inclusive minimum and maximum count of the given expression (This).
type MM struct {
Min int
Max int
This any
}
// Min is a parameterized advancing expression that matches an inclusive
// minimum number of the given expression item (This). Use within is.It
// to disable advancement.
type Min struct {
// M ("min") is a parameterized advancing expression that matches an
// inclusive minimum number of the given expression item (This). Use
// within is.It to disable advancement.
type M struct {
Min int
This any
}

@ -320,7 +320,7 @@ func (s *R) Expect(expr any) (*Cur, error) {
}
}
case z.Toi: // -----------------------------------------------------
case z.Ti: // -----------------------------------------------------
back := s.Mark()
for s.Cur.Rune != tk.EOD {
for _, i := range v {
@ -420,14 +420,14 @@ func (s *R) Expect(expr any) (*Cur, error) {
case z.Mn1: // ----------------------------------------------------
m := s.Mark()
c, err := s.Expect(z.Min{1, v.This})
c, err := s.Expect(z.M{1, v.This})
if err != nil {
s.Jump(m)
return nil, s.ErrorExpected(v)
}
return c, nil
case z.Min: // ----------------------------------------------------
case z.M: // ----------------------------------------------------
c := 0
last := s.Mark()
var err error
@ -533,7 +533,7 @@ func (s *R) ErrorExpected(this any, args ...any) error {
case z.Mn1:
str := `expected one or more %q`
msg = fmt.Sprintf(str, v.This)
case z.Min:
case z.M:
str := `expected min %v of %q`
msg = fmt.Sprintf(str, v.Min, v.This)
case z.MM:
@ -545,7 +545,7 @@ func (s *R) ErrorExpected(this any, args ...any) error {
case z.Rng:
str := `expected range [%v-%v]`
msg = fmt.Sprintf(str, string(v.First), string(v.Last))
case z.Toi:
case z.Ti:
str := `%q not found`
if len(v) > 1 {
str = `none of %q found`

@ -435,9 +435,9 @@ func ExampleExpect_mn1() {
// U+006F 'o' 1,2-2 (2-2)
}
func ExampleExpect_min() {
func ExampleExpect_minimum() {
s, _ := scan.New("sssoommme thing")
c, _ := s.Expect(z.Min{2, 's'})
c, _ := s.Expect(z.M{2, 's'})
c.Print() // needs 2, but will consume all three to last 's'
s.Print() // advances to next after ('o')
// Output:
@ -539,9 +539,9 @@ func ExampleExpect_to_Success() {
// U+0065 'e' 1,4-4 (4-4)
}
func ExampleExpect_toi() {
func ExampleExpect_to_Inclusive() {
s, _ := scan.New("some thing")
c, _ := s.Expect(z.Toi{'e'})
c, _ := s.Expect(z.Ti{'e'})
c.Print() // same as "some", points to 'e'
s.Print() // scanned next after (' ')
// Output:

Loading…
Cancel
Save