@tabnas/parser
v0.12.8
Published
A dynamic JSON parser that isn't strict and can be customized.
Maintainers
Readme
tabnas
A pluggable parsing engine. The runtime is a class (Tabnas) that
runs a rule-based parser over a configurable matcher-based lexer. The
package ships no grammar of its own: every grammar is a plugin
that you (or another package) supply.
npm install @tabnas/parserA tiny taste, a one-token grammar defined inline:
const { Tabnas } = require('@tabnas/parser')
const tn = new Tabnas({ plugins: [(tn) => {
tn.options({ fixed: { token: { '#HI': 'hello' } } })
tn.rule('val', (rs) => rs.open([
{ s: ['#HI'], a: (r) => { r.node = 'world' } },
]))
}] })
tn.parse('hello') // 'world'That grammar as a railroad/syntax diagram, generated from the live parser
with @tabnas/railroad:
A vertical ASCII version is in doc/taste.txt.
Documentation
- Tutorial. Build your first parser, step by step.
- How-to guides. Short recipes for common tasks.
- Writing plugins. Author a grammar or tooling plugin.
- API reference. Every public method, property, and export.
- Options reference. Every option field and its default.
- Concepts. How the TypeScript engine is put together, and why.
Shared design docs for both runtimes live at the top of the repo:
- Architecture. The engine model.
- Syntax. The relaxed-JSON syntax reference.
Explanation / design notes
- LSP feasibility. Language-server angles.
- GBNF feasibility. Llama.cpp grammar (constrained LLM decoding) angles.
Companion packages
Grammars and tooling ship as separate packages, not in this one:
@tabnas/abnf. Compiles ABNF into engine rules and addstn.bnf(src).@tabnas/debug. Tracing anddescribe()helpers.
The strict-JSON grammar used by the conformance tests lives as a test
fixture at test/json-plugin.ts: a worked
example of a non-trivial grammar plugin.
The Go port follows the same grammar-free design, with its strict-JSON grammar kept as a test fixture too.
License
MIT. Copyright (c) Richard Rodger.
