@@ -20,18 +20,18 @@ type Path struct {
2020 q * spec.PathQuery
2121}
2222
23- // New creates and returns a new Path consisting of q.
23+ // New creates and returns a new [ Path] consisting of q.
2424func New (q * spec.PathQuery ) * Path {
2525 return & Path {q : q }
2626}
2727
28- // Parse parses path, a JSONPath query string, into a Path. Returns an
29- // ErrPathParse on parse failure.
28+ // Parse parses path, a JSONPath query string, into a [ Path] . Returns an
29+ // [ ErrPathParse] on parse failure.
3030func Parse (path string ) (* Path , error ) {
3131 return NewParser ().Parse (path )
3232}
3333
34- // MustParse parses path into a Path. Panics with an ErrPathParse on parse
34+ // MustParse parses path into a [ Path] . Panics with an [ ErrPathParse] on parse
3535// failure.
3636func MustParse (path string ) * Path {
3737 return NewParser ().MustParse (path )
@@ -42,20 +42,21 @@ func (p *Path) String() string {
4242 return p .q .String ()
4343}
4444
45- // Query returns p's root Query .
45+ // Query returns p's root [spec.PathQuery] .
4646func (p * Path ) Query () * spec.PathQuery {
4747 return p .q
4848}
4949
50- // Select returns the values that JSONPath query p selects from input.
50+ // Select returns the nodes that JSONPath query p selects from input.
5151func (p * Path ) Select (input any ) NodeList {
5252 return p .q .Select (nil , input )
5353}
5454
55- // SelectLocated returns the values that JSONPath query p selects from input
56- // as [spec.LocatedNode] values that pair the values with the [normalized
57- // paths] that identify them. Unless you have a specific need for the unique
58- // normalized path for each value, you probably want to use [Path.Select].
55+ // SelectLocated returns the nodes that JSONPath query p selects from input as
56+ // [spec.LocatedNode] values that pair the nodes with the [normalized paths]
57+ // that identify them. Unless you have a specific need for the unique
58+ // [spec.NormalizedPath] for each value, you probably want to use
59+ // [Path.Select].
5960//
6061// [normalized paths]: https://www.rfc-editor.org/rfc/rfc9535#section-2.7
6162func (p * Path ) SelectLocated (input any ) LocatedNodeList {
@@ -70,13 +71,13 @@ type Parser struct {
7071// Option defines a parser option.
7172type Option func (* Parser )
7273
73- // WithRegistry configures a Parser with a function Registry, which may
74- // contain function extensions. See [Parser] for an example.
74+ // WithRegistry configures a [ Parser] with a [registry. Registry] , which may
75+ // contain function extensions.
7576func WithRegistry (reg * registry.Registry ) Option {
7677 return func (p * Parser ) { p .reg = reg }
7778}
7879
79- // NewParser creates a new Parser configured by opt.
80+ // NewParser creates a new [ Parser] configured by opt.
8081func NewParser (opt ... Option ) * Parser {
8182 p := & Parser {}
8283 for _ , o := range opt {
@@ -90,20 +91,19 @@ func NewParser(opt ...Option) *Parser {
9091 return p
9192}
9293
93- // Parse parses path, a JSON Path query string, into a Path. Returns an
94- // ErrPathParse on parse failure.
95- //
96- //nolint:wrapcheck
94+ // Parse parses path, a JSONPath query string, into a [Path]. Returns an
95+ // [ErrPathParse] on parse failure.
9796func (c * Parser ) Parse (path string ) (* Path , error ) {
9897 q , err := parser .Parse (c .reg , path )
9998 if err != nil {
99+ //nolint:wrapcheck
100100 return nil , err
101101 }
102102 return New (q ), nil
103103}
104104
105- // MustParse parses path, a JSON Path query string, into a Path. Panics with
106- // an ErrPathParse on parse failure.
105+ // MustParse parses path, a JSONPath query string, into a [ Path] . Panics with
106+ // an [ ErrPathParse] on parse failure.
107107func (c * Parser ) MustParse (path string ) * Path {
108108 q , err := parser .Parse (c .reg , path )
109109 if err != nil {
@@ -131,7 +131,7 @@ func (list NodeList) All() iter.Seq[any] {
131131}
132132
133133// LocatedNodeList is a list of nodes selected by a JSONPath query, along with
134- // their locations. Returned by [Path.SelectLocated].
134+ // their [NormalizedPath] locations. Returned by [Path.SelectLocated].
135135type LocatedNodeList []* spec.LocatedNode
136136
137137// All returns an iterator over all the nodes in list.
@@ -147,8 +147,8 @@ func (list LocatedNodeList) All() iter.Seq[*spec.LocatedNode] {
147147 }
148148}
149149
150- // Nodes returns an iterator over all the nodes in list. This is effectively
151- // the same data a returned by [Path.Select].
150+ // Nodes returns an iterator over all the nodes in list. This is the same data
151+ // as returned by [Path.Select].
152152func (list LocatedNodeList ) Nodes () iter.Seq [any ] {
153153 return func (yield func (any ) bool ) {
154154 for _ , v := range list {
@@ -159,7 +159,7 @@ func (list LocatedNodeList) Nodes() iter.Seq[any] {
159159 }
160160}
161161
162- // Paths returns an iterator over all the normalized paths in list.
162+ // Paths returns an iterator over all the [NormalizedPath] values in list.
163163func (list LocatedNodeList ) Paths () iter.Seq [spec.NormalizedPath ] {
164164 return func (yield func (spec.NormalizedPath ) bool ) {
165165 for _ , v := range list {
@@ -170,10 +170,10 @@ func (list LocatedNodeList) Paths() iter.Seq[spec.NormalizedPath] {
170170 }
171171}
172172
173- // Deduplicate deduplicates the nodes in list based on their normalized paths,
174- // modifying the contents of list. It returns the modified list, which may
175- // have a smaller length, and zeroes the elements between the new length and
176- // the original length.
173+ // Deduplicate deduplicates the nodes in list based on their [NormalizedPath]
174+ // values, modifying the contents of list. It returns the modified list, which
175+ // may have a shorter length, and zeroes the elements between the new length
176+ // and the original length.
177177func (list LocatedNodeList ) Deduplicate () LocatedNodeList {
178178 if len (list ) <= 1 {
179179 return list
@@ -192,7 +192,7 @@ func (list LocatedNodeList) Deduplicate() LocatedNodeList {
192192 return slices .Clip (uniq )
193193}
194194
195- // Sort sorts list by the normalized path of each node.
195+ // Sort sorts list by the [NormalizedPath] of each node.
196196func (list LocatedNodeList ) Sort () {
197197 slices .SortFunc (list , func (a , b * spec.LocatedNode ) int {
198198 return a .Path .Compare (b .Path )
0 commit comments