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§
- Translation
Part - One optional alchemy translation source and its explicit entry point.
- Translation
Parts - 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.
Defaultis the canonicalZon.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, andtests/version_test.rsfails the build if they drift. MirrorsVERSIONints/src/zon.tsandconst VERSIONingo/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 TypeScriptmake(opts), which isnew Tabnas().use(jsonic).use(Zon, opts). - manifest_
text - The plugin’s manifest,
tabnas.plugin.json, as the repository carries it. Itstranslateobject 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.jsonandtranslate/transduce.alc, since a packaged crate holds nothing outsiders/;tests/translate_test.rsholds 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 withmake_with. - plugin
- The plugin form of
zon, forTabnas::use_plugin. Its defaults areZonOptions::default, and the option bag a caller passes is merged over them by the engine, asUseDefaultsmerges them in Go. - render_
text - ZON’s render,
alchemy/render.alc, the file the manifest’stranslate.rendernames: a library of alchemy definitions, with noexport, whose entry pointzon-renderwrites 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.