func (p *Path) FilterNode(node ast.Node) (ast.Node, error) {
	n, err := p.node.filter(node)
	if err != nil {
		return nil, errors.Wrapf(err, "failed to filter node by path ( %s )", p.node)
	}
	return n, nil
}
FilterNode filter from node by YAMLPath.
package yaml
import (
	"bytes"
	"fmt"
	"io"
	"strconv"
	"strings"
	"github.com/goccy/go-yaml/ast"
	"github.com/goccy/go-yaml/internal/errors"
	"github.com/goccy/go-yaml/parser"
	"github.com/goccy/go-yaml/printer"
)
func PathString(s string) (*Path, error) {
	buf := []rune(s)
	length := len(buf)
	cursor := 0
	builder := &PathBuilder{}
	for cursor < length {
		c := buf[cursor]
		switch c {
		case '$':
			builder = builder.Root()
			cursor++
		case '.':
			b, buf, c, err := parsePathDot(builder, buf, cursor)
			if err != nil {
				return nil, errors.Wrapf(err, "failed to parse path of dot")
			}
			length = len(buf)
			builder = b
			cursor = c
		case '[':
			b, buf, c, err := parsePathIndex(builder, buf, cursor)
			if err != nil {
				return nil, errors.Wrapf(err, "failed to parse path of index")
			}
			length = len(buf)
			builder = b
			cursor = c
		default:
			return nil, errors.Wrapf(ErrInvalidPathString, "invalid path at %d", cursor)
		}
	}
	return builder.Build(), nil
}
func parsePathRecursive(b *PathBuilder, buf []rune, cursor int) (*PathBuilder, []rune, int, error) {
	length := len(buf)
	cursor += 2  
	start := cursor
	for ; cursor < length; cursor++ {
		c := buf[cursor]
		switch c {
		case '$':
			return nil, nil, 0, errors.Wrapf(ErrInvalidPathString, "specified '$' after '..' character")
		case '*':
			return nil, nil, 0, errors.Wrapf(ErrInvalidPathString, "specified '*' after '..' character")
		case '.', '[':
			goto end
		case ']':
			return nil, nil, 0, errors.Wrapf(ErrInvalidPathString, "specified ']' after '..' character")
		}
	}
end:
	if start == cursor {
		return nil, nil, 0, errors.Wrapf(ErrInvalidPathString, "not found recursive selector")
	}
	return b.Recursive(string(buf[start:cursor])), buf, cursor, nil
}
func parsePathDot(b *PathBuilder, buf []rune, cursor int) (*PathBuilder, []rune, int, error) {
	length := len(buf)
	if cursor+1 < length && buf[cursor+1] == '.' {
		b, buf, c, err := parsePathRecursive(b, buf, cursor)
		if err != nil {
			return nil, nil, 0, errors.Wrapf(err, "failed to parse path of recursive")
		}
		return b, buf, c, nil
	}
	cursor++  
	start := cursor
	if cursor < length && buf[cursor] == '\'' {
		return parseQuotedKey(b, buf, cursor)
	}
	for ; cursor < length; cursor++ {
		c := buf[cursor]
		switch c {
		case '$':
			return nil, nil, 0, errors.Wrapf(ErrInvalidPathString, "specified '$' after '.' character")
		case '*':
			return nil, nil, 0, errors.Wrapf(ErrInvalidPathString, "specified '*' after '.' character")
		case '.', '[':
			goto end
		case ']':
			return nil, nil, 0, errors.Wrapf(ErrInvalidPathString, "specified ']' after '.' character")
		}
	}
end:
	if start == cursor {
		return nil, nil, 0, errors.Wrapf(ErrInvalidPathString, "cloud not find by empty key")
	}
	return b.child(string(buf[start:cursor])), buf, cursor, nil
}
func parseQuotedKey(b *PathBuilder, buf []rune, cursor int) (*PathBuilder, []rune, int, error) {
	cursor++  
	start := cursor
	length := len(buf)
	var foundEndDelim bool
	for ; cursor < length; cursor++ {
		switch buf[cursor] {
		case '\\':
			buf = append(append([]rune{}, buf[:cursor]...), buf[cursor+1:]...)
			length = len(buf)
		case '\'':
			foundEndDelim = true
			goto end
		}
	}
end:
	if !foundEndDelim {
		return nil, nil, 0, errors.Wrapf(ErrInvalidPathString, "could not find end delimiter for key")
	}
	if start == cursor {
		return nil, nil, 0, errors.Wrapf(ErrInvalidPathString, "could not find by empty key")
	}
	selector := buf[start:cursor]
	cursor++
	if cursor < length {
		switch buf[cursor] {
		case '$':
			return nil, nil, 0, errors.Wrapf(ErrInvalidPathString, "specified '$' after '.' character")
		case '*':
			return nil, nil, 0, errors.Wrapf(ErrInvalidPathString, "specified '*' after '.' character")
		case ']':
			return nil, nil, 0, errors.Wrapf(ErrInvalidPathString, "specified ']' after '.' character")
		}
	}
	return b.child(string(selector)), buf, cursor, nil
}
func parsePathIndex(b *PathBuilder, buf []rune, cursor int) (*PathBuilder, []rune, int, error) {
	length := len(buf)
	cursor++  
	if length <= cursor {
		return nil, nil, 0, errors.Wrapf(ErrInvalidPathString, "unexpected end of YAML Path")
	}
	c := buf[cursor]
	switch c {
	case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '*':
		start := cursor
		cursor++
		for ; cursor < length; cursor++ {
			c := buf[cursor]
			switch c {
			case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
				continue
			}
			break
		}
		if buf[cursor] != ']' {
			return nil, nil, 0, errors.Wrapf(ErrInvalidPathString, "invalid character %s at %d", string(buf[cursor]), cursor)
		}
		numOrAll := string(buf[start:cursor])
		if numOrAll == "*" {
			return b.IndexAll(), buf, cursor + 1, nil
		}
		num, err := strconv.ParseInt(numOrAll, 10, 64)
		if err != nil {
			return nil, nil, 0, errors.Wrapf(err, "failed to parse number")
		}
		return b.Index(uint(num)), buf, cursor + 1, nil
	}
	return nil, nil, 0, errors.Wrapf(ErrInvalidPathString, "invalid character %s at %d", c, cursor)
}
type Path struct {
	node pathNode
}
func (p *Path) String() string {
	return p.node.String()
}
func (p *Path) Read(r io.Reader, v interface{}) error {
	node, err := p.ReadNode(r)
	if err != nil {
		return errors.Wrapf(err, "failed to read node")
	}
	if err := Unmarshal([]byte(node.String()), v); err != nil {
		return errors.Wrapf(err, "failed to unmarshal")
	}
	return nil
}
func (p *Path) ReadNode(r io.Reader) (ast.Node, error) {
	if p.node == nil {
		return nil, ErrInvalidPath
	}
	var buf bytes.Buffer
	if _, err := io.Copy(&buf, r); err != nil {
		return nil, errors.Wrapf(err, "failed to copy from reader")
	}
	f, err := parser.ParseBytes(buf.Bytes(), 0)
	if err != nil {
		return nil, errors.Wrapf(err, "failed to parse yaml")
	}
	node, err := p.FilterFile(f)
	if err != nil {
		return nil, errors.Wrapf(err, "failed to filter from ast.File")
	}
	return node, nil
}
func (p *Path) Filter(target, v interface{}) error {
	b, err := Marshal(target)
	if err != nil {
		return errors.Wrapf(err, "failed to marshal target value")
	}
	if err := p.Read(bytes.NewBuffer(b), v); err != nil {
		return errors.Wrapf(err, "failed to read")
	}
	return nil
}
func (p *Path) FilterFile(f *ast.File) (ast.Node, error) {
	for _, doc := range f.Docs {
		node, err := p.FilterNode(doc.Body)
		if err != nil {
			return nil, errors.Wrapf(err, "failed to filter node by path ( %s )", p.node)
		}
		if node != nil {
			return node, nil
		}
	}
	return nil, errors.Wrapf(ErrNotFoundNode, "failed to find path ( %s )", p.node)
}