Documentation
¶
Overview ¶
Package json is a standard JSON grammar plugin for the tabnas parsing engine (github.com/tabnas/parser/go).
The engine ships no grammar of its own; this package supplies the strict, standard-JSON one. The rule set (val / map / list / pair / elem) is jsonic's "Plain JSON" grammar — the pure-JSON core jsonic defines before extending it for the relaxed jsonic format. Here that core is installed on its own, with the lexer restricted to strict JSON and none of jsonic's extended grammar (comments, unquoted keys, implicit objects/arrays, trailing commas, single/backtick strings, path diving). It mirrors encoding/json: quoted-string keys only, double-quoted strings, plain decimal numbers, true/false/null.
This plugin is intended to be the foundation other tabnas grammar plugins build on: Use it first, then layer rules on the shared val / map / list / pair / elem rules.
Index ¶
Constants ¶
const Version = "0.2.0"
Version is the current version of the module.
Variables ¶
This section is empty.
Functions ¶
func Json ¶
Json is the standard plugin form: apply the strict JSON options, then register the JSON grammar. Use it on a bare engine, or call Make.
func Make ¶
Make builds a standard-JSON parser instance, optionally layering extra options (e.g. info.Map/List/Text) over the base strict configuration.
func Parse ¶
Parse parses a JSON source string with a default standard-JSON parser and returns the resulting value, or a *tabnas.TabnasError on failure.
func RegisterJSONGrammar ¶
RegisterJSONGrammar installs the standard JSON rule set (val / map / list / pair / elem) on j via the engine's declarative grammar spec — the same shape as the TypeScript registerJsonGrammar. Exposed separately from the options so other grammar plugins can layer on the JSON core.
The value tree is built ENTIRELY by the engine's native-value `$`-builtins (object/array/reset/key/setval/push/value); there are NO grammar-local closures. The builders are info-aware, so when the MapRef / ListRef / TextInfo options are enabled they allocate the engine's info carriers (MapRef / ListRef / Text) and perform the container/quote annotation themselves — the json plugin used to hand-write that as @map-bc / @list-bc / @val-bc state hooks. Strict JSON containers are always explicit, so @object$/@array$ take the default implicit:false (no `K` config needed).
The builtin actions used below, one line each:
@reset$ — clear the parent-seeded node (so a value doesn't inherit the parent container). @object$ — allocate an empty object into the node (a MapRef under info.Map). @array$ — allocate an empty array into the node (a ListRef under info.List). @key$ — capture the matched key token into a scratch slot for the pending @setval$. @setval$ — assign the just-built child value into the object under the captured key. @push$ — append the just-built child value to the array. @value$ — resolve the rule's value: a built child wins, else the scalar token (a Text under info.Text).
Types ¶
This section is empty.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
tabnas-json
command
Command tabnas-json is a tiny command-line front end: read JSON from the arguments or from stdin, parse it (strict, standard JSON), and print the canonical re-serialized form.
|
Command tabnas-json is a tiny command-line front end: read JSON from the arguments or from stdin, parse it (strict, standard JSON), and print the canonical re-serialized form. |