kdl

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package kdl reads a KDL v2 document into a small tree of its own.

It wraps github.com/calico32/kdl-go, whose public API is 0.x and documented as unstable, and pins the parser to version 2. The format is v2, so there is nothing to detect: with auto-detection a genuine v2 syntax error late in a document can be reported as a bogus error on the first `#true` far earlier.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Kind

type Kind int

Kind is the type of a KDL value.

const (
	KindNull Kind = iota
	KindString
	KindInt
	KindFloat
	KindBool
)

Value kinds.

func (Kind) String

func (kind Kind) String() string

String names the kind, for diagnostics.

type Node

type Node struct {
	File     string
	Name     string
	Line     int
	Args     []Value
	Children []*Node
	// contains filtered or unexported fields
}

Node is one node of the document.

func Parse

func Parse(reader io.Reader, name string) ([]*Node, error)

Parse reads a KDL v2 document.

func ParseFile

func ParseFile(path string) ([]*Node, error)

ParseFile reads a KDL v2 document from a file.

func ParseString

func ParseString(src, name string) ([]*Node, error)

ParseString reads a KDL v2 document from a string.

func (*Node) Child

func (node *Node) Child(name string) *Node

Child returns the first child of a given name, or nil.

func (*Node) ChildrenNamed

func (node *Node) ChildrenNamed(name string) []*Node

Children of a given name, in document order.

func (*Node) Parent

func (node *Node) Parent() *Node

Parent returns the enclosing node, or nil at the top level.

func (*Node) Path

func (node *Node) Path() string

Path renders the node's position in the tree, for diagnostics.

func (*Node) Prop

func (node *Node) Prop(key string) (Value, bool)

Prop returns a named property.

func (*Node) PropNames

func (node *Node) PropNames() []string

PropNames lists the properties in document order.

type Value

type Value struct {
	Kind  Kind
	Str   string
	Int   *big.Int
	Float float64
	Bool  bool
	Line  int
}

Value is one KDL argument or property value.

func (Value) Number

func (value Value) Number() (float64, bool)

Number returns the value as a float, and whether it was numeric.

func (Value) Text

func (value Value) Text() (string, bool)

Text returns the value's string content, and whether it was a string.

Jump to

Keyboard shortcuts

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