Skip to content

Toml Parser

Spice
import "std/text/toml-parser";

TomlParser struct

Recursive-descent parser for TOML v1.0.0.

Use parseToml for one-shot parsing; the struct is exposed mainly so the parser state (position, error message) can be inspected when needed.

Supported are comments, bare/quoted/dotted keys, basic and literal strings (single- and multi-line), decimal/hexadecimal/octal/binary integers, floats including inf and nan, booleans, date-times, arrays, inline tables, [table] headers and [[array of table]] headers.

The TomlValue data model lives in "std/text/toml/toml-value" and serialization in "std/text/toml/toml-serializer".

Constructors

ctor

Spice
public p TomlParser.ctor(const String& input)

Construct a TOML parser over the given input string

Parameters

Name Type Description
input const String& TOML text to parse

dtor

Spice
public p TomlParser.dtor()

Destruct the TOML parser, releasing the bookkeeping it built up while parsing

Methods

parse

Spice
public f<Result<TomlValue*>> TomlParser.parse()

Parse the input string into a TOML value tree

Returns: Result<TomlValue*> — Result holding the root table, or an error if the input is malformed

Functions

parseToml

Spice
public f<Result<TomlValue*>> parseToml(const String& input)

Parse a TOML document.

On success returns the root table, which the caller owns and releases again with deleteTomlValue from "std/text/toml/toml-value". On failure the partially built tree is released by the parser and an error describing the first problem encountered is returned.

Parameters

Name Type Description
input const String&

Returns: Result<TomlValue*>