minitoml

package
v0.5.7 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package minitoml parses a restricted TOML subset into a flat intermediate key/value form. Arrays of tables are the one nested shape: a [[key]] array holds one sub-document per element, each itself flat.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Document

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

Document is a flat map of dotted hierarchical keys to intermediate values.

func NewDocument

func NewDocument() Document

NewDocument returns an empty intermediate document.

func Parse

func Parse(data []byte) (Document, error)

Parse parses restricted TOML bytes into an intermediate Document.

Allowed: standard tables, nested tables, dotted bare keys, bare keys only, scalar values, arrays of primitive scalars, and arrays of tables ([[key]]). Forbidden: quoted keys, inline tables, arrays of inline tables.

func ParseString

func ParseString(s string) (Document, error)

ParseString parses restricted TOML from a string.

func (Document) Clone

func (d Document) Clone() Document

Clone returns a shallow copy of the document map. Table-array elements are shared with the original, not copied.

func (Document) Get

func (d Document) Get(key string) (Value, bool)

Get returns the value for a dotted key path.

func (Document) Keys

func (d Document) Keys() []string

Keys returns sorted dotted key paths.

func (Document) Len

func (d Document) Len() int

Len returns the number of keys.

func (*Document) Set

func (d *Document) Set(key string, v Value)

Set stores a value under a dotted key path (used by the parser and tests).

type Kind

type Kind int

Kind classifies an intermediate value.

const (
	// KindString is a string scalar.
	KindString Kind = iota
	// KindBool is a boolean scalar.
	KindBool
	// KindInt is an integer scalar.
	KindInt
	// KindFloat is a floating-point scalar.
	KindFloat
	// KindArray is an array of primitive scalars.
	KindArray
	// KindTableArray is an array of tables written as repeated [[key]] headers.
	KindTableArray
)

type Value

type Value struct {
	Kind  Kind
	Str   string
	Bool  bool
	Int   int64
	Float float64
	Array []Value
	// Tables holds one Document per [[key]] element when Kind is KindTableArray.
	// Each element's keys are relative to the table-array key itself.
	Tables []Document
}

Value is one intermediate scalar, primitive array, or array of tables.

func (Value) AsBool

func (v Value) AsBool() (bool, error)

AsBool coerces a scalar value to bool.

func (Value) AsInt

func (v Value) AsInt() (int64, error)

AsInt coerces a scalar value to int64.

func (Value) AsString

func (v Value) AsString() (string, error)

AsString coerces a scalar value to string.

func (Value) AsStringSlice

func (v Value) AsStringSlice() ([]string, error)

AsStringSlice returns a primitive array as []string.

func (Value) AsTables added in v0.2.0

func (v Value) AsTables() ([]Document, error)

AsTables returns the per-element documents of an array of tables.

func (Value) KindName

func (v Value) KindName() string

KindName returns a human-readable kind name.

func (Value) String

func (v Value) String() string

String returns a display form of the value.

Directories

Path Synopsis
Package codegen emits reflection-free apply functions from intermediate minitoml.Document keys.
Package codegen emits reflection-free apply functions from intermediate minitoml.Document keys.

Jump to

Keyboard shortcuts

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