Skip to main content

Crate tabnas_json5

Crate tabnas_json5 

Source
Expand description

The JSON5 grammar plugin for the tabnas parsing engine.

JSON5 is JSON plus comments, unquoted keys, trailing commas, single quotes, hex numbers, Infinity and NaN, leading and trailing decimal points, explicit + signs, and string line continuations. The plugin layers on the relaxed-JSON base grammar of tabnas_jsonic and then TIGHTENS it toward the JSON5 specification: no implicit top-level a:1 or 1,2, no auto-close at the end of the source, no unquoted text at a value position, and only ECMAScript 5.1 IdentifierNames as unquoted keys.

let value = tabnas_json5::parse("{ a: 1, b: [2, 3,], }")?;
assert_eq!(value.to_string(), r#"{"a":1,"b":[2,3]}"#);

TypeScript is canonical: ts/src/json5.ts and the shared json5-grammar.jsonic define behaviour and option defaults. The shared fixtures in test/spec/*.tsv and the vendored test/json5-tests corpus are the parity contract across TypeScript, Go and Rust.

Structs§

Json5Error
The error a failed parse produces, re-exported so callers need not depend on the engine crate directly. The Go port returns the same *jsonic.JsonicError.
Json5Options
The plugin options: a strict JSON5 configuration by default, with the relaxations jsonic offers beyond the specification opt-in. The TypeScript Json5Options and the Go Defaults() map.
TranslationPart
One optional alchemy source and the entry point a host calls.
TranslationParts
The package-local structural translation interface.

Constants§

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/json5.ts and const VERSION in go/json5.go.

Functions§

json5
Install JSON5 on parser, which must already carry the jsonic grammar (from tabnas_jsonic::make, or tabnas_jsonic::jsonic on a bare engine). The counterpart of the TypeScript Json5 plugin function and the Go Json5(j, opts).
make
Build a JSON5 parser with the default (strict JSON5) options.
make_with
Build a JSON5 parser with caller options: jsonic.Make() followed by UseDefaults(Json5, Defaults(), opts) in Go, or new Tabnas().use(jsonic).use(Json5, opts) in TypeScript.
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 JSON5 is read as and written from (tree), the render that writes it, which is the json render alchemy carries rather than a file of this repository’s, and the sentences that say what that render does not keep. The crate embeds its own copy, translate/manifest.json, since a packaged crate holds nothing outside rs/; tests/translate_test.rs holds the copy to the file.
parse
Parse a JSON5 source string with the shared default parser.
parse_with
Parse a JSON5 source with a parser that carries the plugin: the counterpart of the Go Parse(j, src) and of the parse the TypeScript plugin wraps.
plugin
The plugin form of json5, for Tabnas::use_plugin. Its defaults are Json5Options::default, and the bag it receives is read with Json5Options::from_value, so a caller passes only the keys to change:
translate
Return JSON5’s immutable translation parts.