Skip to main content

Crate tabnas_toml

Crate tabnas_toml 

Source
Expand description

The TOML grammar plugin for the tabnas parsing engine.

It parses TOML into plain values: bare, quoted and dotted keys, [table] headers, [[array-of-tables]], inline tables, arrays, basic, literal and multi-line strings, integers and floats including inf and nan, booleans, and date and time values.

It is not standalone. It layers on the relaxed-JSON base grammar from tabnas_jsonic (the val / map / list / pair / elem rules), sets rule.start to toml and excludes the jsonic alternates, then adds the TOML rules, a custom string matcher and context-aware date and time matchers on top.

let value = tabnas_toml::parse("title = \"TOML\"\n[owner]\nname = \"Tom\"")?;
assert_eq!(
    value.to_string(),
    r#"{"title":"TOML","owner":{"name":"Tom"}}"#
);

TypeScript is canonical: ts/src/toml.ts defines behaviour, and the grammar itself is authored once in toml-grammar.jsonic and embedded into every runtime. The shared fixtures in test/spec/*.tsv are the parity contract across TypeScript, Go and Rust.

Structs§

TomlError
TomlOptions
Parser options. Reserved for future use, as TomlOptions is in both other ports.
TomlTime
A TOML date, time or date-time, as this port carries it.
TranslationPart
One optional alchemy translation source and its explicit entry point.
TranslationParts
The package-local structural translation interface.

Constants§

DEPTH_GUARD
The name the depth check is installed under, as a parse guard, and the name Tabnas::remove_parse_guard takes to lift it.
DEPTH_LIMIT
How many levels a document may nest before the parse is refused, with the engine’s cancel code: 127 levels parse, the 128th is refused.
LOCAL_DATE
See OFFSET_DATE_TIME.
LOCAL_DATE_TIME
See OFFSET_DATE_TIME.
LOCAL_TIME
See OFFSET_DATE_TIME.
OFFSET_DATE_TIME
The four TOML date and time kinds, in the spelling the TypeScript port attaches to a JavaScript Date as __toml__.kind and the Go port stores in TomlTime.Kind.
VERSION
This crate’s version. It MUST equal ts/package.json “version”: the release orchestrator rewrites both, and tests/version_test.rs fails the build if they drift. Mirrors VERSION in ts/src/toml.ts and const VERSION in go/toml.go.

Functions§

make
Build a TOML parser: a jsonic instance with this plugin installed, the counterpart of the TypeScript make() and the Go MakeJsonic(), with lex.window declared, so that Tabnas::parse_reader reads a reader a window at a time rather than whole (admin ADR-30).
make_with
Build a TOML parser with plugin options. TomlOptions carries nothing yet, in every port; the entry point exists so that adding one is not a breaking change.
manifest_text
The plugin’s manifest, tabnas.plugin.json, as the repository carries it. Its translate object is what a host that translates reads: the shape TOML is read as and written from (tree), the file that holds the render, the sentences that say what the render does not keep, and the file that holds the transducer part (transduce), the document’s JSON events from the grammar’s rule passes under its default options, through which a host that reads parser events reads a document. The crate embeds its own copies, translate/manifest.json and translate/transduce.alc, since a packaged crate holds nothing outside rs/; tests/translate_test.rs holds each copy to its file.
parse
Parse a TOML document with a shared default parser.
plugin
The plugin form of toml, for Tabnas::use_plugin. Installed this way the grammar is re-applied to derived instances, as every native plugin is.
render_text
TOML’s render, alchemy/render.alc, the file the manifest’s translate.render names: a library of alchemy definitions, with no export, whose entry point toml-render writes a tree’s events as one TOML document. A host links it with its own program. The crate embeds its own copy, translate/render.alc, held to the file as the manifest’s is.
toml
Install the TOML grammar on an instance that already carries the jsonic base grammar.
toml_time
Read a TomlTime back off a parsed value, or None when the value is not one. The kind is checked against the four constants, so an ordinary Text from some other plugin is not mistaken for a date.
translate
Return TOML’s immutable translation parts.