Skip to main content

Crate tabnas_zon

Crate tabnas_zon 

Source
Expand description

The Zig Object Notation (ZON) grammar plugin for the tabnas parsing engine.

ZON is the data format of Zig build.zig.zon manifests, built on Zig anonymous struct literals:

.{
    .name = "example",
    .version = "0.0.1",
    .dependencies = .{ .foo = .{ .url = "https://..." } },
    .paths = .{ "build.zig", "src" },
}

This is a jsonic plugin: it layers on the relaxed-JSON grammar of tabnas_jsonic and reshapes it into ZON, exactly as the canonical TypeScript plugin in ts/src/zon.ts does. It switches the jsonic extensions off (rule.exclude: jsonic,imp), remaps the fixed tokens (.{ opens both structs and tuples, } closes both, = separates a field from its value), adds six lex matchers for Zig syntax, and prepends the grammar alternates in zon-grammar.jsonic, which every runtime embeds.

let value = tabnas_zon::parse(".{ .name = \"Alice\", .age = 30 }")?;
assert_eq!(value.to_string(), r#"{"name":"Alice","age":30}"#);

TypeScript is canonical: ts/src/zon.ts defines behaviour and option defaults. The shared fixtures in test/spec/*.tsv and the two zig reference corpora are the parity contract across TypeScript, Go and Rust.

Structs§

TranslationPart
One optional alchemy translation source and its explicit entry point.
TranslationParts
The package-local structural translation interface.
ZonError
The error a failed parse produces, re-exported so callers need not depend on the engine crate directly.
ZonOptions
Plugin options. Default is the canonical Zon.defaults: character literals as one-character strings, enum literals as bare strings.

Constants§

BIG_KEY
The key of the object an integer literal becomes when no IEEE-754 double holds its exact value: { "$big": "<decimal digits>" }.
GRAMMAR_TEXT
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/zon.ts and const VERSION in go/zon.go.

Functions§

make
Build a ZON parser with the default options.
make_with
Build a ZON parser with the given options: the counterpart of the Go MakeJsonic(opts) and of the TypeScript make(opts), which is new Tabnas().use(jsonic).use(Zon, opts).
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 ZON is read as and written from (tree), the file that holds the render, and the sentences that say what the render does not keep. It also names the transducer part, alchemy/transduce.alc, the document’s JSON events from the grammar’s rule passes, 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 ZON source string with the shared default parser.
parse_with
Parse a ZON source string with the given options, on a dedicated instance built for the call: the Go Parse(src, opts). For many parses with the same options, build one parser with make_with.
plugin
The plugin form of zon, for Tabnas::use_plugin. Its defaults are ZonOptions::default, and the option bag a caller passes is merged over them by the engine, as UseDefaults merges them in Go.
render_text
ZON’s render, alchemy/render.alc, the file the manifest’s translate.render names: a library of alchemy definitions, with no export, whose entry point zon-render writes a tree’s events as one ZON document, a struct or tuple literal per container with every field name in the quoted identifier form. 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.
translate
Return ZON’s immutable translation parts.
zon
Install the ZON grammar on a jsonic-enabled instance, with typed options: the plugin function itself.