source

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package source reads a SpecArch YAML file into a node tree that keeps the line of every value, and into the plain value the JSON Schema check needs.

Index

Constants

View Source
const MarkPrefix = "# specarch-problem:"

MarkPrefix starts every line SpecArch writes into a YAML file to mark a problem at the entry below it (ADR-065, ADR-066). A line that starts with it after its indentation is SpecArch's own; no other line is.

Variables

This section is empty.

Functions

func Child

func Child(n *yaml.Node, token string) *yaml.Node

Child returns the value under key in a mapping, or the item at an index in a sequence, following aliases; nil when there is none.

func Deref

func Deref(n *yaml.Node) *yaml.Node

Deref follows an alias.

func EscapeToken

func EscapeToken(s string) string

EscapeToken escapes one JSON pointer token.

func IsMark added in v0.6.0

func IsMark(line string) bool

IsMark tells whether a line of a file is a problem mark.

func IsScalar

func IsScalar(n *yaml.Node) bool

IsScalar reports whether n is a scalar.

func Items

func Items(n *yaml.Node) []*yaml.Node

Items lists a sequence's items; nil for anything else.

func Key

func Key(n *yaml.Node, key string) *yaml.Node

Key returns the key node for key in a mapping, or nil.

func Pointer

func Pointer(tokens ...string) string

Pointer joins tokens into a JSON pointer, "/" for none.

func Resolve

func Resolve(n *yaml.Node, tokens []string) (*yaml.Node, bool)

Resolve follows a pointer's tokens from n. It returns the deepest node it reached and whether it reached the end. For a mapping key it returns the value node.

func Str

func Str(n *yaml.Node) string

Str returns a scalar's text, or "" for anything else.

func StripMarks added in v0.6.0

func StripMarks(data []byte) []byte

StripMarks is a file's text without its problem marks: what the author wrote, which the marks of a run do not change.

func UnescapeToken

func UnescapeToken(s string) string

UnescapeToken reverses EscapeToken.

func ValueOf

func ValueOf(n *yaml.Node) any

ValueOf converts a node tree into plain JSON values, reporting nothing: a repeated key keeps its first value, and a date is its text.

Types

type Doc

type Doc struct {
	Root     *yaml.Node // the top-level mapping, nil when nothing of the file could be read
	Value    any        // the same content as JSON values
	Problems []Problem
	Held     []string // the pointers of the entries that did not parse, kept by their names only or left out
}

Doc is one parsed file.

func Parse

func Parse(data []byte) *Doc

Parse reads one YAML document. A file that does not parse keeps what can be read of it (see readable); when nothing can, the syntax error is returned as a Problem, with Root left nil.

type Pair

type Pair struct {
	Key   *yaml.Node
	Value *yaml.Node
}

Pair is one key and value of a mapping.

func Pairs

func Pairs(n *yaml.Node) []Pair

Pairs lists a mapping's entries in document order; nil for anything else.

type Problem

type Problem struct {
	Line    int
	Path    string
	Rule    string
	Message string
}

Problem is something wrong with the YAML itself, found while reading.

Jump to

Keyboard shortcuts

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