toml

The toml module provides routines for parsing and validating TOML documents. It implements version 1.0.0 of the TOML specification.

This top-level module contains the data-structures of a parsed TOML document and some basic utilities to operate on them. See the toml::parse submodule for functions that parse documents, and toml::sift for some utilities that can help you validate documents.

A table can be created using functions in toml::parse, and can be deinitialized with finish.

All values should be considered immutable. You can read from them, but this library isn't made to accomodate modifications to structured TOML data.

Submodules

Index

Types

type array = struct {
	items: []value,
	parent: container,
	ctx: valuectx,
};
type pair = struct {
	key: str,
	value: value,
};
type table = struct {
	pairs: []pair,
	parent: container,
	ctx: valuectx,
};
type value = (*array | *table | str | i64 | f64 | bool | date::virtual | void);

// Undocumented types:
type container = (*array | *table | void);
type valuectx = enum {
	TABLE_PART, // In "[a.b.c]", this is "a" and "b" but not "c".
	KEY, // In "a.b.c = 2", this is "a" and "b".
	// In "[[a.b.c]]", this is "c" (which is an array). Each item inside is
	// a TABLE.
	ARRAY_OF_TABLES,
	TABLE, // In "[a.b.c]", this is "c".
	VALUE, // In "a.b.c = {}", this is "c".
};

Functions

fn arraylen(a: *array) size;
fn at_index(a: *array, index: size) value;
fn at_key(t: *table, key: str) value;
fn compare(a: value, b: value) bool;
fn finish(t: *table) void;
fn tablelen(t: *table) size;

Types

type array[link]

type array = struct {
	items: []value,
	parent: container,
	ctx: valuectx,
};

An array of values.

type pair[link]

type pair = struct {
	key: str,
	value: value,
};

A single key-value pair in a table.

type table[link]

type table = struct {
	pairs: []pair,
	parent: container,
	ctx: valuectx,
};

A table in a TOML document.

type value[link]

type value = (*array | *table | str | i64 | f64 | bool | date::virtual | void);

A single value in a TOML document.

type container[link]

Show undocumented member
type container = (*array | *table | void);

type valuectx[link]

Show undocumented member
type valuectx = enum {
	TABLE_PART, // In "[a.b.c]", this is "a" and "b" but not "c".
	KEY, // In "a.b.c = 2", this is "a" and "b".
	// In "[[a.b.c]]", this is "c" (which is an array). Each item inside is
	// a TABLE.
	ARRAY_OF_TABLES,
	TABLE, // In "[a.b.c]", this is "c".
	VALUE, // In "a.b.c = {}", this is "c".
};

Functions

fn arraylen[link]

fn arraylen(a: *array) size;

Gets the length of an array.

fn at_index[link]

fn at_index(a: *array, index: size) value;

Gets the value at an index of an array. Returns the value if it exists, and void otherwise.

fn at_key[link]

fn at_key(t: *table, key: str) value;

Gets the value for a key in a table. Returns the value if it exists, and void otherwise.

fn compare[link]

fn compare(a: value, b: value) bool;

Compares two values. This ignores the parent and ctx fields of tables and arrays.

fn finish[link]

fn finish(t: *table) void;

Frees table resources.

fn tablelen[link]

fn tablelen(t: *table) size;

Gets the number of keys in a table.