mirror of
https://github.com/rwxrob/bonzai
synced 2024-11-16 21:25:44 +00:00
Rename Rng -> R
This commit is contained in:
parent
951c1ca048
commit
0414dbe7a2
@ -3,4 +3,4 @@ package z
|
||||
// keep only compound expressions here
|
||||
|
||||
var WS = In{' ', '\n', '\t', '\r'}
|
||||
var Digit = Rng{0, 9}
|
||||
var Digit = R{0, 9}
|
||||
|
@ -141,16 +141,16 @@ type C struct {
|
||||
This any
|
||||
}
|
||||
|
||||
// A is short for is.C{tk.ANY}. (Mnemonic: "any", "asterisk")
|
||||
// A is short for z.C{tk.ANY}. (Mnemonic: "any", "asterisk")
|
||||
type A struct {
|
||||
N int
|
||||
}
|
||||
|
||||
// Rng is a parameterized advancing expression that matches a single
|
||||
// Unicode code point (rune, uint32) from an inclusive consecutive set
|
||||
// from First to Last (First,Last). Use within is.It to disable
|
||||
// advancement.
|
||||
type Rng struct {
|
||||
// R ("range") is a parameterized advancing expression that matches
|
||||
// a single Unicode code point (rune, int32) from an inclusive
|
||||
// consecutive set from First to Last (First,Last). (Mnemonic: "range",
|
||||
// "rune")
|
||||
type R struct {
|
||||
First rune
|
||||
Last rune
|
||||
}
|
||||
|
@ -463,7 +463,7 @@ func (s *R) Expect(expr any) (*Cur, error) {
|
||||
s.Scan()
|
||||
return m, nil
|
||||
|
||||
case z.Rng: // ----------------------------------------------------
|
||||
case z.R: // ----------------------------------------------------
|
||||
if !(v.First <= s.Cur.Rune && s.Cur.Rune <= v.Last) {
|
||||
err := s.ErrorExpected(v)
|
||||
return nil, err
|
||||
@ -542,7 +542,7 @@ func (s *R) ErrorExpected(this any, args ...any) error {
|
||||
case z.C:
|
||||
str := `expected exactly %v of %q`
|
||||
msg = fmt.Sprintf(str, v.N, v.This)
|
||||
case z.Rng:
|
||||
case z.R:
|
||||
str := `expected range [%v-%v]`
|
||||
msg = fmt.Sprintf(str, string(v.First), string(v.Last))
|
||||
case z.Ti:
|
||||
|
@ -331,12 +331,12 @@ func ExampleExpect_in() {
|
||||
func ExampleExpect_avoid_Not_with_In() {
|
||||
s, _ := scan.New("some thing")
|
||||
s.Snap()
|
||||
c, _ := s.Expect(z.In{z.Not{'s'}, z.Rng{'a', 'z'}})
|
||||
c, _ := s.Expect(z.In{z.Not{'s'}, z.R{'a', 'z'}})
|
||||
c.Print() // unexpected success
|
||||
s.Print() // advanced to 'o'
|
||||
s.Back()
|
||||
// use z.X instead
|
||||
_, err := s.Expect(z.X{z.Not{'s'}, z.Rng{'a', 'z'}})
|
||||
_, err := s.Expect(z.X{z.Not{'s'}, z.R{'a', 'z'}})
|
||||
fmt.Println(err)
|
||||
s.Print() // not advanced
|
||||
// Output:
|
||||
@ -486,7 +486,7 @@ func ExampleExpect_c() {
|
||||
func ExampleExpect_rng() {
|
||||
s, _ := scan.New("some thing")
|
||||
s.Scan()
|
||||
c1, _ := s.Expect(z.Rng{'l', 'p'})
|
||||
c1, _ := s.Expect(z.R{'l', 'p'})
|
||||
c1.Print()
|
||||
s.Print()
|
||||
// Output:
|
||||
|
Loading…
Reference in New Issue
Block a user