nodeindex

package
v0.153.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package nodeindex derives, from a YAML node tree and the text it was parsed from, the two things the parser does not report: where the block headed by a node ends, and which key an anchor was defined under.

The first half is interim. https://github.com/yaml/go-yaml/pull/391 records end positions on the node, which is where they belong and which they are exact at; this derives them instead, and agrees on 99.98% of blocks.

The import is the yaml fork this module already depends on rather than the stock package, whose Node is the same type: nothing here needs the fork, and the switch to stock yaml belongs to the change that removes the fork.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Index

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

Index answers where the block headed by a key ends.

The parser reports where every node starts and nothing about where it stops, so the end is derived, in two passes over the tree.

measure takes the largest line among a node's descendants. Reading that off the tree rather than from indentation is what makes a sequence item work: a parameter's key location is the item's first key, at the same column as the keys following it, so no column comparison can tell the end of the item from the start of its own second field.

extend then grows that over lines belonging to the block that carry no node, which is the body of a block scalar. Together they agree with a parser's own end positions on 99.98% of blocks across a 4,240-file corpus; measure alone agrees on 99.60%, the difference being blocks that end in a `description: |`.

Trailing blank and comment lines fall outside.

func New

func New(root *yaml.Node, data []byte) *Index

New indexes data's node tree. Ends are derived per file: a $ref into another document is decoded separately, against its own text.

func (*Index) AnchorKey

func (ix *Index) AnchorKey(anchored *yaml.Node) (*yaml.Node, bool)

AnchorKey returns the key the anchored node was defined under.

func (*Index) EndOf

func (ix *Index) EndOf(node *yaml.Node) (int, int)

EndOf returns the last line and column of the block node occupies.

func (*Index) Has

func (ix *Index) Has(node *yaml.Node) bool

Has reports whether node is part of the tree this index was built from.

Jump to

Keyboard shortcuts

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