sourcepos

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package sourcepos provides source-location-aware parsing for YAML files. It maps logical paths (e.g., "spec.resolvers.appName.resolve.with[0].inputs.value") to source positions (line, column, file) in the original YAML document.

This enables tools like lint, validation, and MCP diagnostics to report precise source locations alongside logical paths.

Usage:

sm, err := sourcepos.BuildSourceMap(yamlBytes, "solution.yaml")
if err != nil { ... }
if pos, ok := sm.Get("spec.resolvers.appName.resolve.with[0]"); ok {
    fmt.Printf("line %d, column %d\n", pos.Line, pos.Column)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Position

type Position struct {
	// Line is the 1-based line number in the source file.
	Line int `json:"line" yaml:"line" doc:"1-based line number in source file" maximum:"1000000" example:"42"`

	// Column is the 1-based column number in the source file.
	Column int `json:"column" yaml:"column" doc:"1-based column number in source file" maximum:"10000" example:"5"`

	// File is the source file path. This is important for compose scenarios
	// where multiple files contribute to a single solution.
	File string `` /* 130-byte string literal not displayed */
}

Position represents a location in a YAML source file.

func (Position) IsZero

func (p Position) IsZero() bool

IsZero returns true if the position has no meaningful location.

func (Position) String

func (p Position) String() string

String returns a human-readable representation of the position.

type SourceMap

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

SourceMap maps logical YAML paths to source positions. It is built by walking a yaml.Node tree and recording each node's Line/Column.

func BuildSourceMap

func BuildSourceMap(data []byte, file string) (*SourceMap, error)

BuildSourceMap parses the YAML data and builds a SourceMap by walking the yaml.Node tree. The file parameter is recorded in each Position for multi-file (compose) scenarios.

func NewSourceMap

func NewSourceMap() *SourceMap

NewSourceMap creates a new empty SourceMap.

func (*SourceMap) Get

func (sm *SourceMap) Get(path string) (Position, bool)

Get returns the Position for the given logical path, if known.

func (*SourceMap) Len

func (sm *SourceMap) Len() int

Len returns the number of recorded positions.

func (*SourceMap) Merge

func (sm *SourceMap) Merge(other *SourceMap)

Merge incorporates all positions from another SourceMap. If both maps have the same key, the other map's position wins.

func (*SourceMap) Paths

func (sm *SourceMap) Paths() []string

Paths returns all recorded logical paths.

func (*SourceMap) Set

func (sm *SourceMap) Set(path string, pos Position)

Set records a position for the given logical path.

Jump to

Keyboard shortcuts

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