Skip to main content

Crate tabnas_jsonic

Crate tabnas_jsonic 

Source
Expand description

The jsonic relaxed-JSON grammar plugin for the tabnas parsing engine.

jsonic accepts standard JSON and then relaxes it for humans: unquoted keys, implicit objects and arrays, comments, trailing commas, single and backtick quoted strings, and path diving (a:b:1 is {"a":{"b":1}}).

The standard-JSON core (val / map / list / pair / elem) comes from the tabnas_json plugin; this crate installs that core and weaves the relaxed alternates and lifecycle actions around it, exactly as the canonical TypeScript grammar in ts/src/grammar.ts does.

let value = tabnas_jsonic::parse("a:1, b:[x,y,z]")?;
assert_eq!(value.to_string(), r#"{"a":1,"b":["x","y","z"]}"#);

TypeScript is canonical: ts/src/grammar.ts and ts/src/defaults.ts define behaviour, option defaults and the order of alternates. The shared fixtures in test/spec/*.tsv are the parity contract across TypeScript, Go and Rust.

Structs§

JsonicError
The error a failed parse produces, re-exported so callers need not depend on the engine crate directly. Mirrors the TypeScript export { TabnasError as JsonicError }.
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/jsonic.ts and const VERSION in go/jsonic.go.

Functions§

deep_merge
Recursively merge overlay into base: objects by key, arrays by index, everything else replaced by the overlay. The port of the deep() utility the TypeScript grammar merges duplicate keys with, over the engine’s native values, keeping the base’s container kind (a MapRef stays a MapRef with its metadata). The prototype pollution guard is the same one: __proto__, constructor and prototype keys of the overlay are skipped.
empty
A parser with the jsonic configuration but no grammar rules, for building a grammar from scratch. The counterpart of Jsonic.empty() and the Go Empty.
jsonic
Install jsonic on parser: the idiomatic engine plugin.
make
Build a relaxed-JSON parser with the default options. It declares lex.window, as make_with says.
make_json
Build a parser that accepts strict JSON only: the counterpart of Jsonic.make('json') and the Go MakeJSON.
make_with
Build a relaxed-JSON parser with caller options: the counterpart of Jsonic.make(options) and the Go Make(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 jsonic is read as and written from (tree), the root the render takes (any), 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. Its transduce names the transducer part, alchemy/transduce.alc, 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.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 jsonic source string with the shared default parser.
plugin
The plugin form of jsonic, for Tabnas::use_plugin. Installed this way the grammar is re-applied to derived instances, as every native plugin is.
register_jsonic_grammar
Register the relaxed-JSON grammar rules (val / map / list / pair / elem) on parser WITHOUT applying jsonic’s option branding, so other grammar plugins can layer their own syntax on the jsonic core while managing their own option set. The counterpart of the TypeScript registerJsonicGrammar export and the Go RegisterJsonicGrammar.
translate
Return jsonic’s immutable translation parts.