From 68f54e7f18d782abb4a71a7b5219b27eb8f98f9c Mon Sep 17 00:00:00 2001 From: rwxrob Date: Fri, 4 Mar 2022 16:49:11 -0500 Subject: [PATCH] Rename Not -> N, N -> Nd --- scan/is/is.go | 28 +++++++++++++++------------- scan/scan.go | 4 ++-- scan/scan_test.go | 16 ++++++++-------- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/scan/is/is.go b/scan/is/is.go index aa9a7d0..0e855d2 100644 --- a/scan/is/is.go +++ b/scan/is/is.go @@ -11,10 +11,12 @@ easily generate the other. Nodes and Expressions -Nodes (z.N) indicate something to be captured as a part of the resulting +Nodes (z.Nd) indicate something to be captured as a part of the resulting abstract syntax tree. They are functionally equivalent to parenthesis in regular expressions but with the obvious advantage of capturing a rooted -node tree instead of an array. Expressions (z.X) indicate a sequence to be scanned but not captured unless the expression itself is within a node (z.N). +node tree instead of an array. Expressions (z.X) indicate a sequence to +be scanned but not captured unless the expression itself is within +a node (z.Nd). Tokens @@ -59,16 +61,16 @@ package z // ------------------------------- core ------------------------------- -// N ("node") is a named sequence of expressions that will be captured +// Nd ("node") is a named sequence of expressions that will be captured // into a node. The first string must always be the name which can be // any valid Go string. If any expression fails to match the scan fails. // Otherwise, a new tree.Node is added under the current node and the // scan proceeds. Nodes must either contain other nodes or no nodes at // all. If the first item in the sequence after the name is not also -// a node (z.N) then the node is marked as "edge" (or "leaf") and any +// a node (z.Nd) then the node is marked as "edge" (or "leaf") and any // nodes detected further in the sequence will cause the scan to fail // with a syntax error. -type N []any +type Nd []any // X ("expression") is a sequence of expressions. If any are not the // scan fails. (Equal to (?foo) in regular expressions.) @@ -76,20 +78,20 @@ type X []any // ------------------------------- sets ------------------------------- -// It (the slice) is a set of positive lookahead expressions. If any are +// It ("is it") is a set of positive lookahead expressions. If any are // seen at the current cursor position the scan will proceed without // consuming them (unlike is.O and is.In). If none are found the scan // fails. This is useful when everything from one expression is wanted // except for a few positive exceptions. (Equal to ampersand (&) in -// PEGN.) Also see the tk.IS token. +// PEGN.) type It []any -// Not (the slice) is a set of negative lookahead expressions. If any -// are seen at the current cursor position the scan will fail and the -// scan is never advanced. This is useful when everything from one -// expression is wanted except for a few negative exceptions. (Equal to -// exclamation point (!) in PEGN.) Also see the tk.NOT token. -type Not []any +// N ("not") is a set of negative lookahead expressions. If any are seen +// at the current cursor position the scan will fail and the scan is +// never advanced. This is useful when everything from one expression is +// wanted except for a few negative exceptions. (Equal to exclamation +// point (!) in PEGN.) +type N []any // In is a set of advancing expressions. If any expression in the slice // is found the scan advances to the end of that expression and diff --git a/scan/scan.go b/scan/scan.go index 6132c84..630467a 100644 --- a/scan/scan.go +++ b/scan/scan.go @@ -367,7 +367,7 @@ func (s *R) Expect(expr any) (*Cur, error) { s.Jump(b) return b, nil - case z.Not: // ---------------------------------------------------- + case z.N: // ---------------------------------------------------- m := s.Mark() for _, i := range v { if c, _ := s.Expect(i); c != nil { @@ -517,7 +517,7 @@ func (s *R) ErrorExpected(this any, args ...any) error { } else { msg = fmt.Sprintf(`expected %q`, v[0]) } - case z.Not: + case z.N: msg = fmt.Sprintf(`unexpected %q`, args[0]) case z.In: str := `expected one of %q` diff --git a/scan/scan_test.go b/scan/scan_test.go index 8f9b612..da9f51e 100644 --- a/scan/scan_test.go +++ b/scan/scan_test.go @@ -266,7 +266,7 @@ func ExampleExpect_it_Fail_X() { func ExampleExpect_not_Success() { s, _ := scan.New("some thing") - c, _ := s.Expect(z.Not{"foo"}) + c, _ := s.Expect(z.N{"foo"}) c.Print() // not advanced, but also not s.Print() // not advanced at all // Output: @@ -276,7 +276,7 @@ func ExampleExpect_not_Success() { func ExampleExpect_not_Fail() { s, _ := scan.New("some thing") - _, err := s.Expect(z.Not{"some"}) + _, err := s.Expect(z.N{"some"}) fmt.Println(err) s.Print() // not advanced at all // Output: @@ -286,7 +286,7 @@ func ExampleExpect_not_Fail() { func ExampleExpect_not_X_Fail() { s, _ := scan.New("some thing wonderful") - _, err := s.Expect(z.X{z.Not{'s'}, 'o'}) + _, err := s.Expect(z.X{z.N{'s'}, 'o'}) fmt.Println(err) // sees the s so fails s.Print() // not advanced // Output: @@ -296,7 +296,7 @@ func ExampleExpect_not_X_Fail() { func ExampleExpect_not_X_Success() { s, _ := scan.New("some thing wonderful") - c, _ := s.Expect(z.X{z.Not{`n`}, z.In{`som`}}) + c, _ := s.Expect(z.X{z.N{`n`}, z.In{`som`}}) c.Print() // pointing to last in match 'm' s.Print() // advanced to next after match 'e' // Output: @@ -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.R{'a', 'z'}}) + c, _ := s.Expect(z.In{z.N{'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.R{'a', 'z'}}) + _, err := s.Expect(z.X{z.N{'s'}, z.R{'a', 'z'}}) fmt.Println(err) s.Print() // not advanced // Output: @@ -368,7 +368,7 @@ func ExampleExpect_seq_Fail() { func ExampleExpect_seq_Not_Success() { s, _ := scan.New("some thing") - c, _ := s.Expect(z.X{"some", ` `, z.Not{`T`}, "thin"}) + c, _ := s.Expect(z.X{"some", ` `, z.N{`T`}, "thin"}) c.Print() // same as "some thin" s.Print() // advanced to next after ('g') // Output: @@ -378,7 +378,7 @@ func ExampleExpect_seq_Not_Success() { func ExampleExpect_seq_Not_Fail() { s, _ := scan.New("some Thing") - _, err := s.Expect(z.X{"some", ' ', z.Not{`T`}, "ignored"}) + _, err := s.Expect(z.X{"some", ' ', z.N{`T`}, "ignored"}) fmt.Println(err) s.Print() // not advanced at all // Output: