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§
- Toml
Error - Toml
Options - Parser options. Reserved for future use, as
TomlOptionsis in both other ports. - Toml
Time - A TOML date, time or date-time, as this port carries it.
- Translation
Part - One optional alchemy translation source and its explicit entry point.
- Translation
Parts - 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_guardtakes to lift it. - DEPTH_
LIMIT - How many levels a document may nest before the parse is refused, with
the engine’s
cancelcode: 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
Dateas__toml__.kindand the Go port stores inTomlTime.Kind. - VERSION
- This crate’s version. It MUST equal
ts/package.json“version”: the release orchestrator rewrites both, andtests/version_test.rsfails the build if they drift. MirrorsVERSIONints/src/toml.tsandconst VERSIONingo/toml.go.
Functions§
- make
- Build a TOML parser: a jsonic instance with this plugin installed, the
counterpart of the TypeScript
make()and the GoMakeJsonic(), withlex.windowdeclared, so thatTabnas::parse_readerreads a reader a window at a time rather than whole (admin ADR-30). - make_
with - Build a TOML parser with plugin options.
TomlOptionscarries 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. Itstranslateobject 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.jsonandtranslate/transduce.alc, since a packaged crate holds nothing outsiders/;tests/translate_test.rsholds each copy to its file. - parse
- Parse a TOML document with a shared default parser.
- plugin
- The plugin form of
toml, forTabnas::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’stranslate.rendernames: a library of alchemy definitions, with noexport, whose entry pointtoml-renderwrites 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
TomlTimeback off a parsed value, orNonewhen the value is not one. The kind is checked against the four constants, so an ordinaryTextfrom some other plugin is not mistaken for a date. - translate
- Return TOML’s immutable translation parts.