internal

package
v3.11.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(w io.Writer, doc *Document, opts GenerateOptions) error

Generate writes a Document to the given writer as KDL.

func GenerateString

func GenerateString(doc *Document, opts GenerateOptions) (string, error)

GenerateString returns a KDL string for the document.

Types

type Document

type Document struct {
	Nodes []*Node
}

Document represents a KDL document.

func Parse

func Parse(input string) (*Document, error)

Parse parses the given KDL input and returns a Document.

type GenerateOptions

type GenerateOptions struct {
	Indent  string
	Compact bool
	Version Version // Output version. Defaults to Version2.
}

GenerateOptions controls the output format.

func DefaultGenerateOptions

func DefaultGenerateOptions() GenerateOptions

DefaultGenerateOptions returns sensible defaults.

type Node

type Node struct {
	Name       string
	Type       string // type annotation, empty if none
	Arguments  []*Value
	Properties []*Property // ordered
	Children   []*Node
}

Node represents a KDL node.

type Parser

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

Parser parses KDL tokens into a Document.

type Property

type Property struct {
	Key   string
	Value *Value
}

Property represents a KDL property (key=value pair on a node).

type Token

type Token struct {
	Type  TokenType
	Value string
	Line  int
	Col   int
}

Token represents a single KDL token.

type TokenType

type TokenType int

TokenType represents the type of a KDL token.

const (
	TokenEOF TokenType = iota
	TokenNewline
	TokenIdentifier
	TokenQuotedString
	TokenRawString
	TokenMultiLineString
	TokenInteger
	TokenFloat
	TokenHexInt
	TokenOctalInt
	TokenBinaryInt
	TokenTrue
	TokenFalse
	TokenNull
	TokenInf
	TokenNegInf
	TokenNaN
	TokenOpenBrace
	TokenCloseBrace
	TokenOpenParen
	TokenCloseParen
	TokenEquals
	TokenSemicolon
	TokenSlashDash
)

type Tokenizer

type Tokenizer struct {
	Version Version
	// contains filtered or unexported fields
}

Tokenizer is a KDL tokenizer supporting both v1 and v2.

func NewTokenizer

func NewTokenizer(input string) *Tokenizer

NewTokenizer creates a new tokenizer for the given input.

func (*Tokenizer) NextToken

func (t *Tokenizer) NextToken() (Token, error)

NextToken returns the next token from the input.

func (*Tokenizer) PeekToken

func (t *Tokenizer) PeekToken() (Token, error)

PeekToken returns the next token without consuming it.

type Value

type Value struct {
	Type  string      // type annotation, empty if none
	Value interface{} // string, int64, float64, bool, or nil
}

Value represents a KDL value with optional type annotation.

type Version

type Version int

Version represents the KDL specification version.

const (
	VersionUnknown Version = 0
	Version1       Version = 1
	Version2       Version = 2
)

Jump to

Keyboard shortcuts

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