@tabnas/parser
v0.2.0
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
- BNF feasibility — turning BNF / ABNF into engine rules.
- LSP feasibility — language-server 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.
