Documentation
¶
Overview ¶
Package jsonl is a JSON Lines (JSONL, also known as NDJSON) grammar plugin for the tabnas parsing engine (github.com/tabnas/parser/go).
JSON Lines (https://jsonlines.org) is a text format where each line is one complete, standard-JSON value, and the newline is the record separator. A document parses to a slice of the per-line values.
{"name":"alice","age":30}
{"name":"bob","age":25}
=> []any{map[...]{name:alice, age:30}, map[...]{name:bob, age:25}}
This plugin is a deliberately small demonstration of the engine's extensible-grammar model: it adds NO lexer matchers and re-uses the entire strict-JSON rule set (val / map / list / pair / elem) from github.com/tabnas/json/go untouched. All of JSONL is expressed as
- one lexer semantic change — the newline token stops being ignorable and becomes a meaningful token the grammar can match;
- two new rules — jsonl (the document) and record (one line).
Point 1 does more work than it appears to. Once #LN is no longer in the IGNORE token set, a newline inside a record is no longer invisible to the parser, so a value SPLIT ACROSS LINES stops parsing — which is exactly the JSON Lines requirement that each record occupy one line. That rule is not written down anywhere below; it falls out of making the separator significant.
This is the Go port; the TypeScript package (ts/src/jsonl.ts) is canonical. The two are held together by the shared test/spec/*.tsv fixtures, which both runtimes discover and run.
Index ¶
Constants ¶
const VERSION = "0.1.12"
VERSION is this module's version. It MUST equal ts/package.json "version": the release orchestrator rewrites both, and TestVersionMatchesPackageJSON fails the build if they drift.
Variables ¶
This section is empty.
Functions ¶
func Jsonl ¶
Jsonl is the standard plugin form. Install it on an engine that ALREADY has the strict-JSON grammar:
j := tabnas.Make() tabnasjson.Json(j, nil) tabnasjsonl.Jsonl(j, nil)
Order matters, and not only by convention: the json plugin sets rule.Include "json", which would filter this plugin's alternates straight back out if it were applied afterwards. Applying the json plugin here when it is absent would silently accept the wrong order, so instead the missing-grammar case is reported.
func Make ¶
Make builds a JSON Lines parser instance: a tabnas engine with the strict-JSON grammar and this plugin installed, in that order. Extra options are applied after the grammar exists, mirroring the TS make().
func Parse ¶
Parse parses a JSON Lines source string and returns the slice of per-line values, or a *tabnas.TabnasError on failure. The error's Row is the line of the offending record.
func RegisterJsonlGrammar ¶
RegisterJsonlGrammar installs the JSONL document rules on j via the engine's declarative grammar spec — the same shape as the TypeScript registerJsonlGrammar. Exposed separately from the options (the same split github.com/tabnas/json/go makes) so a plugin layering on JSONL can re-use the rules without re-declaring them.
The value tree is built entirely by the engine's native-value $-builtins, so this grammar is function-free and serializable:
@array$ — allocate an empty array into the node (the document). @push$ — append the just-built child value to that array.
Types ¶
type JsonlError ¶
type JsonlError = tabnas.TabnasError
JsonlError is the error type returned by a failed parse — an alias of the engine's *tabnas.TabnasError (with Code / Row / Col / Hint fields and a formatted Error() report). Mirrors the TS re-export `export { TabnasError as JsonlError }`; reach it with `errors.As(err, &je)` where je is a *tabnasjsonl.JsonlError.
type TranslationPart ¶ added in v0.1.11
TranslationPart is one optional alchemy source and the entry point a host calls.
type TranslationParts ¶ added in v0.1.11
type TranslationParts struct {
Manifest string
Lift *TranslationPart
Render *TranslationPart
}
TranslationParts is the package-local structural translation interface.
func Translate ¶ added in v0.1.11
func Translate() *TranslationParts
Translate returns JSON Lines' immutable translation parts.