package np
import "src.elv.sh/pkg/parse/np"
Package np provides utilities for working with node paths from a leaf of a parse tree to the root.
Index ¶
- Variables
- type Matcher
- func SimpleExpr(data *SimpleExprData, ev *eval.Evaler) Matcher
- func Store[T parse.Node](p *T) Matcher
- func Typed[T parse.Node]() Matcher
- type Path
- func Find(root parse.Node, p int) Path
- func FindLeft(root parse.Node, p int) Path
- func (p Path) Match(ms ...Matcher) bool
- type SimpleExprData
Variables ¶
var ( Chunk = Typed[*parse.Chunk]() Pipeline = Typed[*parse.Pipeline]() Array = Typed[*parse.Array]() Redir = Typed[*parse.Redir]() Sep = Typed[*parse.Sep]() )
Commonly used Typed matchers.
Types ¶
type Matcher ¶
type Matcher interface { // Match takes a slice of nodes and returns the remaining nodes and whether // the match succeeded. Match([]parse.Node) ([]parse.Node, bool) }
Matcher wraps the Match method.
func SimpleExpr ¶
func SimpleExpr(data *SimpleExprData, ev *eval.Evaler) Matcher
SimpleExpr returns a Matcher matching a "simple expression", which consists of 3 nodes from the leaf upwards (Primary, Indexing and Compound) and where the Compound expression can be evaluated statically using ev.
func Store ¶
Store returns a Matcher matching one node of a given type, and stores it if a match succeeds.
func Typed ¶
Typed returns a Matcher matching one node of a given type.
type Path ¶
Path is a path from a leaf in a parse tree to the root.
func Find ¶
Find finds the path of nodes from the leaf at position p to the root.
func FindLeft ¶
FindLeft finds the path of nodes from the leaf at position p to the root. If p points to the start of one node (p == x.From), FindLeft finds the node to the left instead (y s.t. p == y.To).
func (Path) Match ¶
Match matches against matchers, and returns whether all matches have succeeded.
type SimpleExprData ¶
type SimpleExprData struct { Value string Compound *parse.Compound PrimarType parse.PrimaryType }
SimpleExprData contains useful data written by the SimpleExpr matcher.
Source Files ¶
np.go
- Version
- v0.21.0 (latest)
- Published
- Aug 13, 2024
- Platform
- linux/amd64
- Imports
- 2 packages
- Last checked
- 1 day ago –
Tools for package owners.