np

package
v0.20.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 14, 2024 License: BSD-2-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package np provides utilities for working with node paths from a leaf of a parse tree to the root.

Index

Constants

This section is empty.

Variables

View Source
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.

Functions

This section is empty.

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

func Store[T parse.Node](p *T) Matcher

Store returns a Matcher matching one node of a given type, and stores it if a match succeeds.

func Typed

func Typed[T parse.Node]() Matcher

Typed returns a Matcher matching one node of a given type.

type Path

type Path []parse.Node

Path is a path from a leaf in a parse tree to the root.

func Find

func Find(root parse.Node, p int) Path

Find finds the path of nodes from the leaf at position p to the root.

func FindLeft

func FindLeft(root parse.Node, p int) Path

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

func (p Path) Match(ms ...Matcher) bool

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL