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§
- Json5
Error - 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. - Json5
Options - The plugin options: a strict JSON5 configuration by default, with the
relaxations jsonic offers beyond the specification opt-in. The
TypeScript
Json5Optionsand the GoDefaults()map. - Translation
Part - One optional alchemy source and the entry point a host calls.
- Translation
Parts - The package-local structural translation interface.
Constants§
- 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/json5.tsandconst VERSIONingo/json5.go.
Functions§
- json5
- Install JSON5 on
parser, which must already carry the jsonic grammar (fromtabnas_jsonic::make, ortabnas_jsonic::jsonicon a bare engine). The counterpart of the TypeScriptJson5plugin function and the GoJson5(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 byUseDefaults(Json5, Defaults(), opts)in Go, ornew Tabnas().use(jsonic).use(Json5, opts)in TypeScript. - manifest_
text - The plugin’s manifest,
tabnas.plugin.json, as the repository carries it. Itstranslateobject is what a host that translates reads: the shape JSON5 is read as and written from (tree), the render that writes it, which is thejsonrender 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 outsiders/;tests/translate_test.rsholds 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 theparsethe TypeScript plugin wraps. - plugin
- The plugin form of
json5, forTabnas::use_plugin. Its defaults areJson5Options::default, and the bag it receives is read withJson5Options::from_value, so a caller passes only the keys to change: - translate
- Return JSON5’s immutable translation parts.