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.
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 ¶
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 (*SourceMap) Merge ¶
Merge incorporates all positions from another SourceMap. If both maps have the same key, the other map's position wins.