node

package
v0.0.0-...-e4c065d Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Traverse

func Traverse(n Node, f func(Node) bool)

func Validate

func Validate(expression string, start Node) error

Types

type Alternation

type Alternation interface {
	Node

	GetVariants() []Node

	VisitAlternation(
		scanner Scanner,
		input Input,
		from, to int,
		match AlternationCallback,
	)

	CopyAlternation() Alternation
}

func NewAlternation

func NewAlternation(variants []Node) Alternation

type AlternationCallback

type AlternationCallback func(x Node, from int, to int, empty bool) (stop bool)

type Callback

type Callback func(x Node, from int, to int, empty bool)

type Container

type Container interface {
	Node

	GetValue() Node
}

type Input

type Input interface {
	ReadAt(int) rune
	Size() int
	Position() int
}

type Node

type Node interface {
	GetKey() string
	GetExpressions() structs.Set[string]
	AddExpression(string)
	GetNestedNodes() map[string]Node
	IsLeaf() bool

	Visit(Scanner, Input, int, int, Callback)

	// TODO : trie have few size / heights (leafs)
	// TODO : node with different sizes must have chain value instead trie to simpliy this moment
	Size() (int, bool)

	Copy() Node
}

func NewAtomicGroup

func NewAtomicGroup(alt Alternation) Node

func NewClass

func NewClass(table Table) Node

func NewComment

func NewComment(text string) Node

func NewCondition

func NewCondition(cond *Predicate, yes Node, no Node) Node

func NewDot

func NewDot() Node

func NewEndOfLine

func NewEndOfLine() Node

func NewEndOfString

func NewEndOfString() Node

func NewEndOfStringAndNewLine

func NewEndOfStringAndNewLine() Node

func NewForNameReference

func NewForNameReference(name string) Node

func NewGroup

func NewGroup(alt Alternation) Node

func NewGuard

func NewGuard(cond *Predicate, yes Node) Node

func NewKeep

func NewKeep() Node

func NewLookAhead

func NewLookAhead(alt Alternation) Node

func NewLookBehind

func NewLookBehind(alt Alternation) (Node, error)

func NewNamedGroup

func NewNamedGroup(name string, alt Alternation) Node

func NewNegativeClass

func NewNegativeClass(table Table) Node

func NewNegativeLookAhead

func NewNegativeLookAhead(alt Alternation) Node

func NewNegativeLookBehind

func NewNegativeLookBehind(alt Alternation) (Node, error)

func NewNonWordBoundary

func NewNonWordBoundary() Node

func NewNotCapturedGroup

func NewNotCapturedGroup(alt Alternation) Node

func NewOptionsSwitcher

func NewOptionsSwitcher(enable []ScanOption, disable []ScanOption) Node

func NewQuantifier

func NewQuantifier(q *quantity.Quantity, value Node) Node

func NewStartOfLine

func NewStartOfLine() Node

func NewStartOfString

func NewStartOfString() Node

func NewWordBoundary

func NewWordBoundary() Node

func NodeForReference

func NodeForReference(index int) Node

func Unify

func Unify(start Node) []Node

type Output

type Output interface {
	Yield(
		n Node,
		subString string,
		sp quantity.Interface,
		groups []quantity.Interface,
		namedGroups map[string]quantity.Interface,
	)

	LastPosOf(n Node) (int, bool)
	String() string
}

type Predicate

type Predicate struct {
	// contains filtered or unexported fields
}

func NewPredicate

func NewPredicate(key string, f func(scanner Scanner) bool) *Predicate

type ScanOption

type ScanOption uint
const (
	ScanOptionCaseInsensetive    ScanOption = 1
	ScanOptionMultiline          ScanOption = 2
	ScanOptionDisableNamedGroups ScanOption = 3
)

type Scanner

type Scanner interface {
	Position() int
	Rewind(pos int)

	MatchGroup(from int, to int)
	GroupsPosition() int
	GetGroup(idx int) (quantity.Interface, bool)
	RewindGroups(pos int)

	MatchNamedGroup(name string, from int, to int)
	NamedGroupsPosition() int
	GetNamedGroup(name string) (quantity.Interface, bool)
	RewindNamedGroups(pos int)

	MarkAsHole(from int, to int)
	HolesPosition() int
	RewindHoles(pos int)

	OptionsInclude(opt ScanOption) bool
	OptionsEnable(opt ScanOption)
	OptionsDisable(opt ScanOption)
	OptionsPosition() int
	RewindOptions(pos int)
}

type Table

type Table interface {
	Include(rune) bool
	Invert(rune) Table
	Empty() bool
	String() string
}

Jump to

Keyboard shortcuts

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