@tabnas/parser 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +75 -0
- package/dist/builtins.d.ts +4 -0
- package/dist/builtins.js +202 -0
- package/dist/builtins.js.map +1 -0
- package/dist/context.d.ts +64 -0
- package/dist/context.js +138 -0
- package/dist/context.js.map +1 -0
- package/dist/defaults.d.ts +3 -0
- package/dist/defaults.js +301 -0
- package/dist/defaults.js.map +1 -0
- package/dist/error.d.ts +51 -0
- package/dist/error.js +362 -0
- package/dist/error.js.map +1 -0
- package/dist/lexer.d.ts +85 -0
- package/dist/lexer.js +1202 -0
- package/dist/lexer.js.map +1 -0
- package/dist/parser.d.ts +15 -0
- package/dist/parser.js +141 -0
- package/dist/parser.js.map +1 -0
- package/dist/rules.d.ts +100 -0
- package/dist/rules.js +923 -0
- package/dist/rules.js.map +1 -0
- package/dist/tabnas.d.ts +103 -0
- package/dist/tabnas.js +387 -0
- package/dist/tabnas.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types.d.ts +527 -0
- package/dist/types.js +24 -0
- package/dist/types.js.map +1 -0
- package/dist/utility.d.ts +80 -0
- package/dist/utility.js +868 -0
- package/dist/utility.js.map +1 -0
- package/package.json +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2013-2026 Richard Rodger
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# tabnas
|
|
2
|
+
|
|
3
|
+
A pluggable parsing engine. The runtime is a class — `Tabnas` — that
|
|
4
|
+
runs a rule-based parser over a configurable matcher-based lexer. The
|
|
5
|
+
package ships **no grammar** of its own: every grammar is a plugin
|
|
6
|
+
that you (or another package) supply.
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install @tabnas/parser
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
A tiny taste — a one-token grammar defined inline:
|
|
13
|
+
|
|
14
|
+
```js
|
|
15
|
+
const { Tabnas } = require('@tabnas/parser')
|
|
16
|
+
|
|
17
|
+
const tn = new Tabnas({ plugins: [(tn) => {
|
|
18
|
+
tn.options({ fixed: { token: { '#HI': 'hello' } } })
|
|
19
|
+
tn.rule('val', (rs) => rs.open([
|
|
20
|
+
{ s: ['#HI'], a: (r) => { r.node = 'world' } },
|
|
21
|
+
]))
|
|
22
|
+
}] })
|
|
23
|
+
|
|
24
|
+
tn.parse('hello') // 'world'
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
That grammar as a railroad/syntax diagram, generated from the live parser
|
|
28
|
+
with [`@tabnas/railroad`](https://github.com/tabnas/railroad):
|
|
29
|
+
|
|
30
|
+

|
|
31
|
+
|
|
32
|
+
A vertical ASCII version is in [`doc/taste.txt`](doc/taste.txt).
|
|
33
|
+
|
|
34
|
+
## Documentation
|
|
35
|
+
|
|
36
|
+
- [Tutorial](doc/tutorial.md) — build your first parser, step by step.
|
|
37
|
+
- [How-to guides](doc/guide.md) — short recipes for common tasks.
|
|
38
|
+
- [Writing plugins](doc/plugins.md) — author a grammar or tooling
|
|
39
|
+
plugin.
|
|
40
|
+
- [API reference](doc/api.md) — every public method, property, and
|
|
41
|
+
export.
|
|
42
|
+
- [Options reference](doc/options.md) — every option field and its
|
|
43
|
+
default.
|
|
44
|
+
- [Concepts](doc/concepts.md) — how the TypeScript engine is put
|
|
45
|
+
together, and why.
|
|
46
|
+
|
|
47
|
+
Shared design docs for both runtimes live at the top of the repo:
|
|
48
|
+
|
|
49
|
+
- [Architecture](../doc/architecture.md) — the engine model.
|
|
50
|
+
- [Syntax](../doc/syntax.md) — the relaxed-JSON syntax reference.
|
|
51
|
+
|
|
52
|
+
### Explanation / design notes
|
|
53
|
+
|
|
54
|
+
- [BNF feasibility](doc/bnf-to-tabnas-feasibility.md) — turning
|
|
55
|
+
BNF / ABNF into engine rules.
|
|
56
|
+
- [LSP feasibility](doc/lsp-feasibility.md) — language-server angles.
|
|
57
|
+
|
|
58
|
+
## Companion packages
|
|
59
|
+
|
|
60
|
+
Grammars and tooling ship as separate packages, not in this one:
|
|
61
|
+
|
|
62
|
+
- `@tabnas/abnf` — compiles ABNF into engine rules and adds
|
|
63
|
+
`tn.bnf(src)`.
|
|
64
|
+
- `@tabnas/debug` — tracing and `describe()` helpers.
|
|
65
|
+
|
|
66
|
+
The strict-JSON grammar used by the conformance tests lives as a test
|
|
67
|
+
fixture at [`test/json-plugin.ts`](test/json-plugin.ts) — a worked
|
|
68
|
+
example of a non-trivial grammar plugin.
|
|
69
|
+
|
|
70
|
+
The [Go port](../go/) follows the same grammar-free design, with its
|
|
71
|
+
strict-JSON grammar kept as a test fixture too.
|
|
72
|
+
|
|
73
|
+
## License
|
|
74
|
+
|
|
75
|
+
MIT. Copyright (c) Richard Rodger.
|
package/dist/builtins.js
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* Copyright (c) 2026 Richard Rodger and other contributors, MIT License */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.BUILTIN_REFS = exports.BUILTIN_SCHEMA_VERSION = void 0;
|
|
5
|
+
// The config-schema version implemented by these builtins. A serialized
|
|
6
|
+
// grammar that declares `GrammarSpec.v` greater than this is refused at
|
|
7
|
+
// load (see Tabnas.grammar). Absent ⇒ treated as version 1.
|
|
8
|
+
exports.BUILTIN_SCHEMA_VERSION = 2;
|
|
9
|
+
const defprop = Object.defineProperty;
|
|
10
|
+
// Attach the engine's info marker as a hidden (non-enumerable) property on
|
|
11
|
+
// a node, so a grammar running with `info` on can introspect a container's
|
|
12
|
+
// origin (implicit flag, meta bag) or a string's quote without the marker
|
|
13
|
+
// leaking into JSON output. The TS info carrier (the marker property) is
|
|
14
|
+
// the counterpart of Go's MapRef/ListRef/Text wrapper structs.
|
|
15
|
+
function markNode(node, marker, data) {
|
|
16
|
+
if (node != null && 'object' === typeof node) {
|
|
17
|
+
defprop(node, marker, { value: data, writable: true });
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function mkNode(rule, kind) {
|
|
21
|
+
return 'user' === kind ? { rule, src: '', kids: [] } : { src: '', kids: [] };
|
|
22
|
+
}
|
|
23
|
+
// ---- Tree builders (config in `alt.k.<name>`) ---------------------
|
|
24
|
+
// These mirror @tabnas/abnf's emitter closures so a serialized,
|
|
25
|
+
// function-free grammar builds the identical `{rule,src,kids}` tree.
|
|
26
|
+
// Allocate (when `init`) and/or accumulate matched terminals' src.
|
|
27
|
+
const node$ = (r, _ctx, alt) => {
|
|
28
|
+
const cfg = (alt && alt.k && alt.k.node$) || {};
|
|
29
|
+
if (cfg.init)
|
|
30
|
+
r.node = mkNode(cfg.rule, cfg.kind);
|
|
31
|
+
const n = r.node;
|
|
32
|
+
const nterms = cfg.nterms || 0;
|
|
33
|
+
for (let i = 0; i < nterms; i++)
|
|
34
|
+
n.src += r.o[i].src;
|
|
35
|
+
};
|
|
36
|
+
// Merge the just-returned child node into the current node. Tagged
|
|
37
|
+
// children push into `kids`; untagged ones flatten (src concatenates,
|
|
38
|
+
// kids extend).
|
|
39
|
+
const capture$ = (r, _ctx, alt) => {
|
|
40
|
+
const cfg = (alt && alt.k && alt.k.capture$) || {};
|
|
41
|
+
if (null == r.node)
|
|
42
|
+
r.node = mkNode(cfg.rule, cfg.kind);
|
|
43
|
+
const n = r.node;
|
|
44
|
+
const c = r.child && r.child.node;
|
|
45
|
+
if (null == c)
|
|
46
|
+
return;
|
|
47
|
+
if ('object' !== typeof c || !('src' in c)) {
|
|
48
|
+
n.kids.push(c);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (c === n)
|
|
52
|
+
return;
|
|
53
|
+
n.src += c.src;
|
|
54
|
+
if (c.rule)
|
|
55
|
+
n.kids.push(c);
|
|
56
|
+
else if (Array.isArray(c.kids))
|
|
57
|
+
n.kids.push(...c.kids);
|
|
58
|
+
};
|
|
59
|
+
// Lift the committed child's node straight up (no merge).
|
|
60
|
+
const bubble$ = (r) => {
|
|
61
|
+
if (r.child && r.child.node !== undefined)
|
|
62
|
+
r.node = r.child.node;
|
|
63
|
+
};
|
|
64
|
+
// ---- Probe + phase-retry dispatch ---------------------------------
|
|
65
|
+
// Phase-0 open action: mark the token position and reset phase.
|
|
66
|
+
const probeInit$ = (r, ctx) => {
|
|
67
|
+
r.k.pd_phase = 0;
|
|
68
|
+
r.k.pd_mark = ctx.mark();
|
|
69
|
+
};
|
|
70
|
+
// Phase-0 close action: peek the first token the probe did not consume,
|
|
71
|
+
// rewind to the mark, and commit to phase 1 (disambiguator present) or
|
|
72
|
+
// phase 2 (absent). The probe never fails, so `ctx.t[0]` always reflects
|
|
73
|
+
// a real position (the compiler emits a phase-0 close that consumes
|
|
74
|
+
// nothing — that contract is required for this builtin to be correct).
|
|
75
|
+
const probeDecide$ = (r, ctx) => {
|
|
76
|
+
// The phase-0 close must follow a phase-0 open (`@probeInit$`), which
|
|
77
|
+
// records `pd_mark`. Guard against a malformed grammar that runs the
|
|
78
|
+
// decision without it: `ctx.rewind(undefined)` would silently corrupt
|
|
79
|
+
// the rewind window (NaN), breaking every later mark/rewind.
|
|
80
|
+
if (null == r.k.pd_mark) {
|
|
81
|
+
throw new Error('@probeDecide$: no pd_mark — phase-0 @probeInit$ did not run');
|
|
82
|
+
}
|
|
83
|
+
const peek = ctx.t[0];
|
|
84
|
+
ctx.rewind(r.k.pd_mark);
|
|
85
|
+
r.k.pd_phase = peek && peek.name === r.k.pd_d ? 1 : 2;
|
|
86
|
+
};
|
|
87
|
+
// Phase-guard conditions.
|
|
88
|
+
const probePhase0$ = (r) => !r.k.pd_phase;
|
|
89
|
+
const probePhase1$ = (r) => 1 === r.k.pd_phase;
|
|
90
|
+
const probePhase2$ = (r) => 2 === r.k.pd_phase;
|
|
91
|
+
// ---- Native-value builders (config in `alt.k.<name>`) -------------
|
|
92
|
+
// Build NATIVE JSON values (objects/arrays/scalars), as opposed to the
|
|
93
|
+
// `{rule,src,kids}` syntax tree of the tree builders above. A grammar
|
|
94
|
+
// whose rules thread a node from parent to child (the engine seeds a
|
|
95
|
+
// pushed child's node from the parent — see makeRule) can assemble plain
|
|
96
|
+
// objects/arrays with these as alt actions. Schema family v2.
|
|
97
|
+
//
|
|
98
|
+
// These are INFO-AWARE: with `cfg.info` off they emit PLAIN nodes
|
|
99
|
+
// (byte-identical to v1); with `cfg.info.{map,list,text}` on they attach
|
|
100
|
+
// the engine's introspection marker (origin/quote metadata) — the same
|
|
101
|
+
// info model the Go engine carries via MapRef/ListRef/Text. The info
|
|
102
|
+
// logic lives here, in the engine, instead of each JSON-family plugin
|
|
103
|
+
// re-hand-writing it. See doc/value-builtins.md.
|
|
104
|
+
// Allocate a fresh empty object into r.node (no prototype, like JSON).
|
|
105
|
+
// When info.map is on, attach the marker with the static `implicit` flag.
|
|
106
|
+
const object$ = (r, ctx, alt) => {
|
|
107
|
+
const node = Object.create(null);
|
|
108
|
+
r.node = node;
|
|
109
|
+
if (ctx.cfg.info.map) {
|
|
110
|
+
const cfg = (alt && alt.k && alt.k.object$) || {};
|
|
111
|
+
markNode(node, ctx.cfg.info.marker, { implicit: !!cfg.implicit, meta: {} });
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
// Allocate a fresh empty array into r.node. When info.list is on, attach
|
|
115
|
+
// the marker with the static `implicit` flag.
|
|
116
|
+
const array$ = (r, ctx, alt) => {
|
|
117
|
+
const node = [];
|
|
118
|
+
r.node = node;
|
|
119
|
+
if (ctx.cfg.info.list) {
|
|
120
|
+
const cfg = (alt && alt.k && alt.k.array$) || {};
|
|
121
|
+
markNode(node, ctx.cfg.info.marker, { implicit: !!cfg.implicit, meta: {} });
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
// Clear r.node back to "no value" — undoes the parent-seeded node so a
|
|
125
|
+
// scalar value (or fresh container) doesn't inherit the parent container.
|
|
126
|
+
const reset$ = (r) => {
|
|
127
|
+
r.node = undefined;
|
|
128
|
+
};
|
|
129
|
+
// Capture the matched key token's value into a (non-propagated) r.u slot,
|
|
130
|
+
// for a later @setval$ on the same rule to consume.
|
|
131
|
+
const key$ = (r, _ctx, alt) => {
|
|
132
|
+
const cfg = (alt && alt.k && alt.k.key$) || {};
|
|
133
|
+
r.u[cfg.slot || 'key'] = r.o[cfg.from || 0]?.val;
|
|
134
|
+
};
|
|
135
|
+
// Assign the just-returned child node under the captured key: the object-
|
|
136
|
+
// property set. No-op if r.node isn't an object. When info.map is on, a
|
|
137
|
+
// key that collides with the marker is dropped (the marker rides as a
|
|
138
|
+
// hidden property, so a literal `"__info__"` key must not overwrite it) —
|
|
139
|
+
// this guard is TS-only; Go's field-based metadata has no key collision.
|
|
140
|
+
const setval$ = (r, ctx, alt) => {
|
|
141
|
+
const cfg = (alt && alt.k && alt.k.setval$) || {};
|
|
142
|
+
const n = r.node;
|
|
143
|
+
if (null != n && 'object' === typeof n) {
|
|
144
|
+
const key = r.u[cfg.slot || 'key'];
|
|
145
|
+
if (ctx.cfg.info.map && key === ctx.cfg.info.marker)
|
|
146
|
+
return;
|
|
147
|
+
n[key] = r.child.node;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
// Append the just-returned child node to the array (skips the no-value
|
|
151
|
+
// child). No-op if r.node isn't an array.
|
|
152
|
+
const push$ = (r) => {
|
|
153
|
+
if (undefined !== r.child.node && Array.isArray(r.node)) {
|
|
154
|
+
r.node.push(r.child.node);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
// Coalesce a value: a built child node wins; otherwise resolve the
|
|
158
|
+
// matched scalar token. When info.text is on and the resolved scalar is a
|
|
159
|
+
// string from a string/text token, box it as a `String` carrying the
|
|
160
|
+
// quote char (the leaf whose output type changes under info — it has no
|
|
161
|
+
// container to hang the marker on). The Go counterpart wraps in a `Text`.
|
|
162
|
+
const value$ = (r, ctx, alt) => {
|
|
163
|
+
if (undefined !== r.child.node) {
|
|
164
|
+
r.node = r.child.node;
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const cfg = (alt && alt.k && alt.k.value$) || {};
|
|
168
|
+
const tok = r.o[cfg.from || 0];
|
|
169
|
+
let val = tok ? tok.resolveVal(r, ctx) : undefined;
|
|
170
|
+
const info = ctx.cfg.info;
|
|
171
|
+
if (info.text &&
|
|
172
|
+
'string' === typeof val &&
|
|
173
|
+
tok &&
|
|
174
|
+
(tok.tin === ctx.cfg.t.ST || tok.tin === ctx.cfg.t.TX)) {
|
|
175
|
+
const quote = tok.tin === ctx.cfg.t.ST && tok.src.length > 0 ? tok.src[0] : '';
|
|
176
|
+
const sv = new String(val);
|
|
177
|
+
markNode(sv, info.marker, { quote });
|
|
178
|
+
val = sv;
|
|
179
|
+
}
|
|
180
|
+
r.node = val;
|
|
181
|
+
};
|
|
182
|
+
// The standard builtin library, frozen so a grammar that (illegally)
|
|
183
|
+
// overrides a `$` ref cannot mutate the shared map for other instances.
|
|
184
|
+
exports.BUILTIN_REFS = Object.freeze({
|
|
185
|
+
'@node$': node$,
|
|
186
|
+
'@capture$': capture$,
|
|
187
|
+
'@bubble$': bubble$,
|
|
188
|
+
'@probeInit$': probeInit$,
|
|
189
|
+
'@probeDecide$': probeDecide$,
|
|
190
|
+
'@probePhase0$': probePhase0$,
|
|
191
|
+
'@probePhase1$': probePhase1$,
|
|
192
|
+
'@probePhase2$': probePhase2$,
|
|
193
|
+
// Native-value builders (schema v2).
|
|
194
|
+
'@object$': object$,
|
|
195
|
+
'@array$': array$,
|
|
196
|
+
'@reset$': reset$,
|
|
197
|
+
'@key$': key$,
|
|
198
|
+
'@setval$': setval$,
|
|
199
|
+
'@push$': push$,
|
|
200
|
+
'@value$': value$,
|
|
201
|
+
});
|
|
202
|
+
//# sourceMappingURL=builtins.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builtins.js","sourceRoot":"","sources":["../src/builtins.ts"],"names":[],"mappings":";AAAA,2EAA2E;;;AAyC3E,wEAAwE;AACxE,wEAAwE;AACxE,4DAA4D;AAC/C,QAAA,sBAAsB,GAAG,CAAC,CAAA;AAGvC,MAAM,OAAO,GAAG,MAAM,CAAC,cAAc,CAAA;AAErC,2EAA2E;AAC3E,2EAA2E;AAC3E,0EAA0E;AAC1E,yEAAyE;AACzE,+DAA+D;AAC/D,SAAS,QAAQ,CAAC,IAAS,EAAE,MAAc,EAAE,IAAS;IACpD,IAAI,IAAI,IAAI,IAAI,IAAI,QAAQ,KAAK,OAAO,IAAI,EAAE,CAAC;QAC7C,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,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AAC,EAAE,IAAI,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;QAC9E,MAAM,EAAE,GAAG,IAAI,MAAM,CAAC,GAAG,CAAC,CAAA;QAC1B,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;QACpC,GAAG,GAAG,EAAS,CAAA;IACjB,CAAC;IACD,CAAC,CAAC,IAAI,GAAG,GAAG,CAAA;AACd,CAAC,CAAA;AAGD,qEAAqE;AACrE,wEAAwE;AAC3D,QAAA,YAAY,GAAyC,MAAM,CAAC,MAAM,CAAC;IAC9E,QAAQ,EAAE,KAAK;IACf,WAAW,EAAE,QAAQ;IACrB,UAAU,EAAE,OAAO;IACnB,aAAa,EAAE,UAAU;IACzB,eAAe,EAAE,YAAY;IAC7B,eAAe,EAAE,YAAY;IAC7B,eAAe,EAAE,YAAY;IAC7B,eAAe,EAAE,YAAY;IAE7B,qCAAqC;IACrC,UAAU,EAAE,OAAO;IACnB,SAAS,EAAE,MAAM;IACjB,SAAS,EAAE,MAAM;IACjB,OAAO,EAAE,IAAI;IACb,UAAU,EAAE,OAAO;IACnB,QAAQ,EAAE,KAAK;IACf,SAAS,EAAE,MAAM;CAClB,CAAC,CAAA"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Tabnas, Config, LexSub, TabnasOptions, Plugin, Rule, RuleSpec, RuleSub, Tin, Token } from './types';
|
|
2
|
+
export type ContextInit = {
|
|
3
|
+
opts: TabnasOptions;
|
|
4
|
+
cfg: Config;
|
|
5
|
+
meta: Record<string, any>;
|
|
6
|
+
src: () => string;
|
|
7
|
+
root: () => any;
|
|
8
|
+
plgn: () => Plugin[];
|
|
9
|
+
inst: () => Tabnas;
|
|
10
|
+
sub: {
|
|
11
|
+
lex?: LexSub[];
|
|
12
|
+
rule?: RuleSub[];
|
|
13
|
+
};
|
|
14
|
+
rsm: {
|
|
15
|
+
[name: string]: RuleSpec;
|
|
16
|
+
};
|
|
17
|
+
F: (s: any) => string;
|
|
18
|
+
NOTOKEN: Token;
|
|
19
|
+
NORULE: Rule;
|
|
20
|
+
};
|
|
21
|
+
export declare class Context {
|
|
22
|
+
[key: string]: any;
|
|
23
|
+
uI: number;
|
|
24
|
+
opts: TabnasOptions;
|
|
25
|
+
cfg: Config;
|
|
26
|
+
meta: Record<string, any>;
|
|
27
|
+
src: () => string;
|
|
28
|
+
root: () => any;
|
|
29
|
+
plgn: () => Plugin[];
|
|
30
|
+
inst: () => Tabnas;
|
|
31
|
+
rule: Rule;
|
|
32
|
+
sub: {
|
|
33
|
+
lex?: LexSub[];
|
|
34
|
+
rule?: RuleSub[];
|
|
35
|
+
};
|
|
36
|
+
xs: Tin;
|
|
37
|
+
v: Token[];
|
|
38
|
+
vAbs: number;
|
|
39
|
+
t: Token[];
|
|
40
|
+
tC: number;
|
|
41
|
+
kI: number;
|
|
42
|
+
rs: Rule[];
|
|
43
|
+
rsI: number;
|
|
44
|
+
rsm: {
|
|
45
|
+
[name: string]: RuleSpec;
|
|
46
|
+
};
|
|
47
|
+
log?: (...rest: any) => void;
|
|
48
|
+
F: (s: any) => string;
|
|
49
|
+
u: Record<string, any>;
|
|
50
|
+
NOTOKEN: Token;
|
|
51
|
+
NORULE: Rule;
|
|
52
|
+
lex?: any;
|
|
53
|
+
constructor(init: ContextInit);
|
|
54
|
+
get t0(): Token;
|
|
55
|
+
set t0(tkn: Token);
|
|
56
|
+
get t1(): Token;
|
|
57
|
+
set t1(tkn: Token);
|
|
58
|
+
get v1(): Token;
|
|
59
|
+
set v1(tkn: Token);
|
|
60
|
+
get v2(): Token;
|
|
61
|
+
set v2(tkn: Token);
|
|
62
|
+
mark(): number;
|
|
63
|
+
rewind(mark: number): void;
|
|
64
|
+
}
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* Copyright (c) 2013-2026 Richard Rodger, MIT License */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.Context = void 0;
|
|
5
|
+
// Per-parse state object passed to every rule action and lex matcher.
|
|
6
|
+
class Context {
|
|
7
|
+
constructor(init) {
|
|
8
|
+
this.uI = 0; // Rule index.
|
|
9
|
+
this.xs = -1; // Lex state tin.
|
|
10
|
+
// Consumed-token history; v1 / v2 (below) read from the top of this stack.
|
|
11
|
+
this.v = [];
|
|
12
|
+
// Absolute count of pushed-not-rewound tokens since parse start; mark()
|
|
13
|
+
// returns it so ring-buffer eviction of old entries doesn't invalidate marks.
|
|
14
|
+
this.vAbs = 0;
|
|
15
|
+
this.tC = -2; // Prepare count for lookahead (two seeded slots).
|
|
16
|
+
this.kI = -1; // Parser rule iteration count.
|
|
17
|
+
this.rs = []; // Rule stack.
|
|
18
|
+
this.rsI = 0; // Rule stack index.
|
|
19
|
+
this.u = {}; // Custom meta data (for use by plugins).
|
|
20
|
+
this.opts = init.opts;
|
|
21
|
+
this.cfg = init.cfg;
|
|
22
|
+
this.meta = init.meta;
|
|
23
|
+
this.src = init.src;
|
|
24
|
+
this.root = init.root;
|
|
25
|
+
this.plgn = init.plgn;
|
|
26
|
+
this.inst = init.inst;
|
|
27
|
+
this.sub = init.sub;
|
|
28
|
+
this.rsm = init.rsm;
|
|
29
|
+
this.F = init.F;
|
|
30
|
+
this.NOTOKEN = init.NOTOKEN;
|
|
31
|
+
this.NORULE = init.NORULE;
|
|
32
|
+
this.rule = init.NORULE; // overwritten by parser.start once the
|
|
33
|
+
// root rule is built; safe placeholder.
|
|
34
|
+
this.t = [init.NOTOKEN, init.NOTOKEN];
|
|
35
|
+
}
|
|
36
|
+
// Legacy aliases for the first two slots of the lookahead buffer.
|
|
37
|
+
// Reading an unfetched slot yields NOTOKEN; writing seeds the slot.
|
|
38
|
+
// @deprecated Use t[0] / t[1] directly in new grammar code.
|
|
39
|
+
get t0() {
|
|
40
|
+
return this.t[0] ?? this.NOTOKEN;
|
|
41
|
+
}
|
|
42
|
+
set t0(tkn) {
|
|
43
|
+
this.t[0] = tkn;
|
|
44
|
+
}
|
|
45
|
+
get t1() {
|
|
46
|
+
return this.t[1] ?? this.NOTOKEN;
|
|
47
|
+
}
|
|
48
|
+
set t1(tkn) {
|
|
49
|
+
this.t[1] = tkn;
|
|
50
|
+
}
|
|
51
|
+
// Most-recently-consumed token (top of the v stack).
|
|
52
|
+
// Setting v1 with an empty stack pushes; otherwise replaces top.
|
|
53
|
+
get v1() {
|
|
54
|
+
return this.v[this.v.length - 1] ?? this.NOTOKEN;
|
|
55
|
+
}
|
|
56
|
+
set v1(tkn) {
|
|
57
|
+
if (0 < this.v.length)
|
|
58
|
+
this.v[this.v.length - 1] = tkn;
|
|
59
|
+
else
|
|
60
|
+
this.v.push(tkn);
|
|
61
|
+
}
|
|
62
|
+
// Token before the previous one (one below the top).
|
|
63
|
+
get v2() {
|
|
64
|
+
return this.v[this.v.length - 2] ?? this.NOTOKEN;
|
|
65
|
+
}
|
|
66
|
+
set v2(tkn) {
|
|
67
|
+
const L = this.v.length;
|
|
68
|
+
if (1 < L)
|
|
69
|
+
this.v[L - 2] = tkn;
|
|
70
|
+
else if (1 === L)
|
|
71
|
+
this.v.unshift(tkn);
|
|
72
|
+
else
|
|
73
|
+
this.v.push(tkn);
|
|
74
|
+
}
|
|
75
|
+
// Save a rewind mark at the current parse position. The returned
|
|
76
|
+
// value can be passed to rewind() to replay the tokens consumed
|
|
77
|
+
// since the mark was taken, re-feeding them through the lexer's
|
|
78
|
+
// pending-token queue.
|
|
79
|
+
mark() {
|
|
80
|
+
return this.vAbs;
|
|
81
|
+
}
|
|
82
|
+
// Replay the tokens consumed since the given mark.
|
|
83
|
+
//
|
|
84
|
+
// Marks are absolute rather than array-relative so the ring-buffer
|
|
85
|
+
// cap (options.rewind.history) can evict old tokens from the front
|
|
86
|
+
// of v without invalidating mark values held by in-flight rule
|
|
87
|
+
// actions. A rewind whose target has been evicted throws — the
|
|
88
|
+
// caller's retained-history budget was too small for the grammar.
|
|
89
|
+
rewind(mark) {
|
|
90
|
+
const k = this.vAbs - mark;
|
|
91
|
+
if (k <= 0)
|
|
92
|
+
return;
|
|
93
|
+
if (k > this.v.length) {
|
|
94
|
+
throw new Error(`tabnas: ctx.rewind target ${mark} is outside the retained ` +
|
|
95
|
+
`history window (oldest mark available is ${this.vAbs - this.v.length}, ` +
|
|
96
|
+
`current is ${this.vAbs}); increase options.rewind.history.`);
|
|
97
|
+
}
|
|
98
|
+
const queue = this.lex.pnt.token;
|
|
99
|
+
const NOTOKEN = this.NOTOKEN;
|
|
100
|
+
// The lookahead buffer (this.t) holds tokens the lexer has already
|
|
101
|
+
// produced past the current consumed position but that haven't
|
|
102
|
+
// been committed to this.v yet. They advanced the lexer's sI — so
|
|
103
|
+
// if we just invalidated the buffer, those source chars would be
|
|
104
|
+
// lost. Preserve them by splicing into the front of the pending
|
|
105
|
+
// queue in the order the lexer produced them, BEHIND the rewound
|
|
106
|
+
// consumed tokens that come next.
|
|
107
|
+
const pendingLookahead = [];
|
|
108
|
+
for (let i = 0; i < this.t.length; i++) {
|
|
109
|
+
const tkn = this.t[i];
|
|
110
|
+
if (tkn && tkn !== NOTOKEN)
|
|
111
|
+
pendingLookahead.push(tkn);
|
|
112
|
+
this.t[i] = NOTOKEN;
|
|
113
|
+
}
|
|
114
|
+
// Un-shift pre-lexed lookahead (oldest-first order at the queue
|
|
115
|
+
// head), so the next lex.next() serves them in the same order
|
|
116
|
+
// they were originally produced.
|
|
117
|
+
for (let i = pendingLookahead.length - 1; i >= 0; i--) {
|
|
118
|
+
queue.unshift(pendingLookahead[i]);
|
|
119
|
+
}
|
|
120
|
+
// Then unshift the rewound consumed tokens — they go in FRONT of
|
|
121
|
+
// the lookahead, so the next lex.next() serves the oldest rewound
|
|
122
|
+
// consumed token first, then the rest in order.
|
|
123
|
+
for (let i = 0; i < k; i++) {
|
|
124
|
+
// Pop newest-first, unshift in that order — the first unshift
|
|
125
|
+
// lands the newest at the queue's head; the next unshift slides
|
|
126
|
+
// older tokens in front of it, so the queue reads oldest-first.
|
|
127
|
+
queue.unshift(this.v.pop());
|
|
128
|
+
}
|
|
129
|
+
this.vAbs -= k;
|
|
130
|
+
// Clear the lexer's cached end-of-source token so lex.next serves
|
|
131
|
+
// from the newly-replenished queue rather than short-circuiting
|
|
132
|
+
// to #ZZ. (Once the lexer has produced the end token it pins it
|
|
133
|
+
// to pnt.end; the rewound tokens would otherwise be unreachable.)
|
|
134
|
+
this.lex.pnt.end = undefined;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
exports.Context = Context;
|
|
138
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAyCzD,sEAAsE;AACtE,MAAa,OAAO;IAwClB,YAAY,IAAiB;QApC7B,OAAE,GAAG,CAAC,CAAA,CAAuC,cAAc;QAY3D,OAAE,GAAQ,CAAC,CAAQ,CAAA,CAA0B,iBAAiB;QAE9D,2EAA2E;QAC3E,MAAC,GAAY,EAAE,CAAA;QACf,wEAAwE;QACxE,8EAA8E;QAC9E,SAAI,GAAG,CAAC,CAAA;QAKR,OAAE,GAAG,CAAC,CAAC,CAAA,CAAsC,kDAAkD;QAC/F,OAAE,GAAG,CAAC,CAAC,CAAA,CAAsC,+BAA+B;QAC5E,OAAE,GAAW,EAAE,CAAA,CAA8B,cAAc;QAC3D,QAAG,GAAG,CAAC,CAAA,CAAsC,oBAAoB;QAIjE,MAAC,GAAwB,EAAE,CAAA,CAAkB,yCAAyC;QAOpF,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;QACrB,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAA;QACnB,IAAI,CAAC,IAAI,GAAG,IAAI,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