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§
- Jsonic
Error - 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 }. - 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/jsonic.tsandconst VERSIONingo/jsonic.go.
Functions§
- deep_
merge - Recursively merge
overlayintobase: objects by key, arrays by index, everything else replaced by the overlay. The port of thedeep()utility the TypeScript grammar merges duplicate keys with, over the engine’s native values, keeping the base’s container kind (aMapRefstays aMapRefwith its metadata). The prototype pollution guard is the same one:__proto__,constructorandprototypekeys 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 GoEmpty. - jsonic
- Install jsonic on
parser: the idiomatic engine plugin. - make
- Build a relaxed-JSON parser with the default options. It declares
lex.window, asmake_withsays. - make_
json - Build a parser that accepts strict JSON only: the counterpart of
Jsonic.make('json')and the GoMakeJSON. - make_
with - Build a relaxed-JSON parser with caller options: the counterpart of
Jsonic.make(options)and the GoMake(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 jsonic is read as and written from (tree), the root the render takes (any), 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. Itstransducenames 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.jsonandtranslate/transduce.alc, since a packaged crate holds nothing outsiders/;tests/translate_test.rsholds each copy to its file. - parse
- Parse a jsonic source string with the shared default parser.
- plugin
- The plugin form of
jsonic, forTabnas::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) onparserWITHOUT 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 TypeScriptregisterJsonicGrammarexport and the GoRegisterJsonicGrammar. - translate
- Return jsonic’s immutable translation parts.