tree

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package tree defines the configuration tree shared by all pipeline stages. Each Node stores raw text, its matched schema definition, captured fields, a source line, an optional raw block body, and a remediation operation. OpNone is the zero value so ordinary nodes have no remediation operation.

A remediation Change can refer to nodes in caller-owned source trees. These references are read-only. Mutation helpers support transforms and folds. CloneValue copies value state but clears the source line.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Walk

func Walk(c *Config, fn func(*Node))

Walk visits every real node (excludes the sentinel root) in pre-order.

Types

type Config

type Config struct {
	Schema *schema.Schema
	Root   *Node
}

Config contains a sentinel root and the schema used to parse it.

func NewConfig

func NewConfig(s *schema.Schema) *Config

NewConfig returns an empty Config bound to s.

type Node

type Node struct {
	Text       string
	Def        *schema.Node      // The matched schema node, or nil when unknown.
	Fields     map[string]string // Captured argument values; live, not a copy.
	RealIndent int               // Raw parsed indentation column.
	Line       int               // A 1-based source line, or zero when absent.
	Op         Op                // The remediation operation.
	Block      []string          // Raw block body lines, or nil for ordinary nodes.

	// Parent and Children are maintained by AddChild, ReplaceChild, and InsertChildBefore.
	Parent   *Node
	Children []*Node
}

Node stores one parsed configuration line and its children.

func NewNode

func NewNode(text string) *Node

NewNode creates an unmatched node with the given text.

func (*Node) AddChild

func (n *Node) AddChild(c *Node) *Node

AddChild attaches c under n and panics if c already has a parent.

func (*Node) CloneValue

func (n *Node) CloneValue() *Node

CloneValue deep-copies value state into an unparented node without children, operation, indentation, or source line.

func (*Node) InsertChildBefore

func (n *Node) InsertChildBefore(ref, c *Node)

InsertChildBefore inserts parentless c before child ref and retains ref.

func (*Node) Path

func (n *Node) Path() string

Path joins ancestor texts with " / ", excluding the sentinel root.

func (*Node) ReplaceChild

func (n *Node) ReplaceChild(old *Node, repl ...*Node)

ReplaceChild replaces old with zero or more parentless nodes.

func (*Node) SetValueFrom

func (n *Node) SetValueFrom(src *Node)

SetValueFrom deep-copies src value state while preserving this node's tree position and children.

func (*Node) Walk

func (n *Node) Walk(fn func(*Node))

Walk visits n and its descendants in pre-order.

type Op

type Op int

Op identifies a node's remediation role; OpNone must remain the zero value for ordinary parsed nodes.

const (
	OpNone    Op = iota // A normal node outside remediation.
	OpSection           // A retained section header with changed children.
	OpAdd               // A line present only in intended.
	OpRemove            // A line present only in running and rendered as negation.
	OpModify            // An idempotent slot rendered with its new value.
)

func (Op) String

func (o Op) String() string

Jump to

Keyboard shortcuts

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