minitoml

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package minitoml parses a restricted TOML subset into a flat intermediate key/value form.

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, and arrays of primitive scalars. Forbidden: quoted keys, inline tables, arrays of 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.

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
)

type Value

type Value struct {
	Kind  Kind
	Str   string
	Bool  bool
	Int   int64
	Float float64
	Array []Value
}

Value is one intermediate scalar or primitive array.

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) 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