@tabnas/abnf 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 +21 -0
- package/README.md +50 -0
- package/bin/tabnas-abnf +2 -0
- package/dist/abnf.d.ts +6 -0
- package/dist/abnf.js +36 -0
- package/dist/abnf.js.map +1 -0
- package/dist/bin/tabnas-abnf-cli.d.ts +1 -0
- package/dist/bin/tabnas-abnf-cli.js +223 -0
- package/dist/bin/tabnas-abnf-cli.js.map +1 -0
- package/dist/compile.d.ts +26 -0
- package/dist/compile.js +341 -0
- package/dist/compile.js.map +1 -0
- package/dist/converter.d.ts +84 -0
- package/dist/converter.js +2106 -0
- package/dist/converter.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 jsonicjs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, 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,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# @tabnas/abnf
|
|
2
|
+
|
|
3
|
+
ABNF grammar compiler for the
|
|
4
|
+
[`tabnas`](https://github.com/rjrodger/tabnas) parser.
|
|
5
|
+
|
|
6
|
+
Takes ABNF source (the RFC 5234 dialect — `=` and `/`, not `::=`) and
|
|
7
|
+
emits a tabnas `GrammarSpec`. Installed on an engine, the spec parses
|
|
8
|
+
inputs in that grammar and builds a `{rule, src, kids}` AST. It can also
|
|
9
|
+
emit "pure-data" jsonic and supports user actions. Ships the
|
|
10
|
+
`tabnas-abnf` CLI.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @tabnas/parser @tabnas/abnf
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Use
|
|
19
|
+
|
|
20
|
+
```js
|
|
21
|
+
const { Tabnas } = require('@tabnas/parser')
|
|
22
|
+
const { abnf } = require('@tabnas/abnf')
|
|
23
|
+
|
|
24
|
+
const tn = new Tabnas({ plugins: [abnf] })
|
|
25
|
+
tn.abnf(`greet = "hi" / "hello"`)
|
|
26
|
+
|
|
27
|
+
tn.parse('hi') // => ({ rule: 'greet', src: 'hi', kids: [] })
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Documentation
|
|
31
|
+
|
|
32
|
+
Four-quadrant [Diátaxis](https://diataxis.fr) docs:
|
|
33
|
+
|
|
34
|
+
- [tutorial.md](doc/tutorial.md) — learning-oriented: zero to a working
|
|
35
|
+
parser, step by step.
|
|
36
|
+
- [guide.md](doc/guide.md) — task-oriented recipes for real problems.
|
|
37
|
+
- [reference.md](doc/reference.md) — the exact API surface and CLI flags.
|
|
38
|
+
- [concepts.md](doc/concepts.md) — how the compiler works and why.
|
|
39
|
+
|
|
40
|
+
## CLI
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
tabnas-abnf -f grammar.abnf
|
|
44
|
+
tabnas-abnf 'g = "a"' --parse 'a'
|
|
45
|
+
tabnas-abnf -C 'greet = "hi"' # compile to pure-data jsonic
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## License
|
|
49
|
+
|
|
50
|
+
MIT. Copyright (c) Richard Rodger.
|
package/bin/tabnas-abnf
ADDED
package/dist/abnf.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Plugin } from '@tabnas/parser';
|
|
2
|
+
import { abnf as abnfConvert, parseAbnf, emitGrammarSpec, eliminateLeftRecursion, abnfRules, AbnfParseError, AbnfConvertOptions } from './converter';
|
|
3
|
+
import { abnfCompile, toRecognitionSpec, toPureSpec, toJsonic, attachActions, attachActionSlots, markListing, AbnfCompileError, AbnfActionError, AbnfCompileOptions, ActionsMap } from './compile';
|
|
4
|
+
declare const abnf: Plugin;
|
|
5
|
+
export { abnf, abnfConvert, parseAbnf, emitGrammarSpec, eliminateLeftRecursion, abnfRules, AbnfParseError, abnfCompile, toRecognitionSpec, toPureSpec, toJsonic, attachActions, attachActionSlots, markListing, AbnfCompileError, AbnfActionError, };
|
|
6
|
+
export type { AbnfConvertOptions, AbnfCompileOptions, ActionsMap };
|
package/dist/abnf.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* Copyright (c) 2025-2026 Richard Rodger and other contributors, MIT License */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.AbnfActionError = exports.AbnfCompileError = exports.markListing = exports.attachActionSlots = exports.attachActions = exports.toJsonic = exports.toPureSpec = exports.toRecognitionSpec = exports.abnfCompile = exports.AbnfParseError = exports.abnfRules = exports.eliminateLeftRecursion = exports.emitGrammarSpec = exports.parseAbnf = exports.abnfConvert = exports.abnf = void 0;
|
|
5
|
+
const converter_1 = require("./converter");
|
|
6
|
+
Object.defineProperty(exports, "abnfConvert", { enumerable: true, get: function () { return converter_1.abnf; } });
|
|
7
|
+
Object.defineProperty(exports, "parseAbnf", { enumerable: true, get: function () { return converter_1.parseAbnf; } });
|
|
8
|
+
Object.defineProperty(exports, "emitGrammarSpec", { enumerable: true, get: function () { return converter_1.emitGrammarSpec; } });
|
|
9
|
+
Object.defineProperty(exports, "eliminateLeftRecursion", { enumerable: true, get: function () { return converter_1.eliminateLeftRecursion; } });
|
|
10
|
+
Object.defineProperty(exports, "abnfRules", { enumerable: true, get: function () { return converter_1.abnfRules; } });
|
|
11
|
+
Object.defineProperty(exports, "AbnfParseError", { enumerable: true, get: function () { return converter_1.AbnfParseError; } });
|
|
12
|
+
const compile_1 = require("./compile");
|
|
13
|
+
Object.defineProperty(exports, "abnfCompile", { enumerable: true, get: function () { return compile_1.abnfCompile; } });
|
|
14
|
+
Object.defineProperty(exports, "toRecognitionSpec", { enumerable: true, get: function () { return compile_1.toRecognitionSpec; } });
|
|
15
|
+
Object.defineProperty(exports, "toPureSpec", { enumerable: true, get: function () { return compile_1.toPureSpec; } });
|
|
16
|
+
Object.defineProperty(exports, "toJsonic", { enumerable: true, get: function () { return compile_1.toJsonic; } });
|
|
17
|
+
Object.defineProperty(exports, "attachActions", { enumerable: true, get: function () { return compile_1.attachActions; } });
|
|
18
|
+
Object.defineProperty(exports, "attachActionSlots", { enumerable: true, get: function () { return compile_1.attachActionSlots; } });
|
|
19
|
+
Object.defineProperty(exports, "markListing", { enumerable: true, get: function () { return compile_1.markListing; } });
|
|
20
|
+
Object.defineProperty(exports, "AbnfCompileError", { enumerable: true, get: function () { return compile_1.AbnfCompileError; } });
|
|
21
|
+
Object.defineProperty(exports, "AbnfActionError", { enumerable: true, get: function () { return compile_1.AbnfActionError; } });
|
|
22
|
+
const abnf = function abnf(tn, _options) {
|
|
23
|
+
const fn = ((src, opts) => {
|
|
24
|
+
// User actions wrap the compiler's closures, so convert in closure
|
|
25
|
+
// mode (never builtins) and request marks when actions are supplied.
|
|
26
|
+
const spec = (0, converter_1.abnf)(src, opts?.actions ? { ...opts, builtins: false, marks: true } : opts);
|
|
27
|
+
if (opts?.actions)
|
|
28
|
+
(0, compile_1.attachActions)(spec, opts.actions);
|
|
29
|
+
tn.grammar(spec);
|
|
30
|
+
return spec;
|
|
31
|
+
});
|
|
32
|
+
fn.toSpec = (src, opts) => (0, converter_1.abnf)(src, opts);
|
|
33
|
+
tn.abnf = fn;
|
|
34
|
+
};
|
|
35
|
+
exports.abnf = abnf;
|
|
36
|
+
//# sourceMappingURL=abnf.js.map
|
package/dist/abnf.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abnf.js","sourceRoot":"","sources":["../src/abnf.ts"],"names":[],"mappings":";AAAA,gFAAgF;;;AAiBhF,2CAQoB;AA0ClB,4FAjDQ,gBAAW,OAiDR;AACX,0FAjDA,qBAAS,OAiDA;AACT,gGAjDA,2BAAe,OAiDA;AACf,uGAjDA,kCAAsB,OAiDA;AACtB,0FAjDA,qBAAS,OAiDA;AACT,+FAjDA,0BAAc,OAiDA;AA7ChB,uCAYkB;AAkChB,4FA7CA,qBAAW,OA6CA;AACX,kGA7CA,2BAAiB,OA6CA;AACjB,2FA7CA,oBAAU,OA6CA;AACV,yFA7CA,kBAAQ,OA6CA;AACR,8FA7CA,uBAAa,OA6CA;AACb,kGA7CA,2BAAiB,OA6CA;AACjB,4FA7CA,qBAAW,OA6CA;AACX,iGA7CA,0BAAgB,OA6CA;AAChB,gGA7CA,yBAAe,OA6CA;AAlCjB,MAAM,IAAI,GAAW,SAAS,IAAI,CAAC,EAAU,EAAE,QAAc;IAC3D,MAAM,EAAE,GAAG,CAAC,CAAC,GAAW,EAAE,IAAwB,EAAe,EAAE;QACjE,mEAAmE;QACnE,qEAAqE;QACrE,MAAM,IAAI,GAAG,IAAA,gBAAW,EAAC,GAAG,EAC1B,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;QACnE,IAAI,IAAI,EAAE,OAAO;YAAE,IAAA,uBAAa,EAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAA;QACpD,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QAChB,OAAO,IAAI,CAAA;IACb,CAAC,CAEA,CAAA;IACD,EAAE,CAAC,MAAM,GAAG,CAAC,GAAW,EAAE,IAAyB,EAAe,EAAE,CAClE,IAAA,gBAAW,EAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IACxB,EAAE,CAAC,IAAI,GAAG,EAAE,CAAA;AACd,CAAC,CAAA;AAIC,oBAAI"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function run(argv: string[], console: Console): Promise<void>;
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* Copyright (c) 2025 Richard Rodger and other contributors, MIT License */
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.run = run;
|
|
8
|
+
/* tabnas-abnf-cli.ts
|
|
9
|
+
* CLI wrapper for the ABNF -> tabnas grammar spec converter.
|
|
10
|
+
*/
|
|
11
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
12
|
+
const abnf_1 = require("../abnf");
|
|
13
|
+
const parser_1 = require("@tabnas/parser");
|
|
14
|
+
async function run(argv, console) {
|
|
15
|
+
const args = {
|
|
16
|
+
help: false,
|
|
17
|
+
stdin: false,
|
|
18
|
+
files: [],
|
|
19
|
+
inline: [],
|
|
20
|
+
start: undefined,
|
|
21
|
+
tag: undefined,
|
|
22
|
+
space: 2,
|
|
23
|
+
// When set, convert and install the grammar, parse each sample,
|
|
24
|
+
// and report the tree (or an error) instead of the spec.
|
|
25
|
+
parse: [],
|
|
26
|
+
parseFiles: [],
|
|
27
|
+
// Compilation mode: emit a pure-data grammar as jsonic text.
|
|
28
|
+
compile: false,
|
|
29
|
+
// With --compile, emit the full AST grammar (tree builtins kept)
|
|
30
|
+
// instead of the recognition-only grammar.
|
|
31
|
+
full: false,
|
|
32
|
+
// List the marks the compiler assigns (for @rule:o|c:mark actions).
|
|
33
|
+
marks: false,
|
|
34
|
+
};
|
|
35
|
+
for (let aI = 2; aI < argv.length; aI++) {
|
|
36
|
+
const arg = argv[aI];
|
|
37
|
+
if ('-' === arg) {
|
|
38
|
+
args.stdin = true;
|
|
39
|
+
}
|
|
40
|
+
else if ('--help' === arg || '-h' === arg) {
|
|
41
|
+
args.help = true;
|
|
42
|
+
}
|
|
43
|
+
else if ('--file' === arg || '-f' === arg) {
|
|
44
|
+
args.files.push(argv[++aI]);
|
|
45
|
+
}
|
|
46
|
+
else if ('--start' === arg || '-s' === arg) {
|
|
47
|
+
args.start = argv[++aI];
|
|
48
|
+
}
|
|
49
|
+
else if ('--tag' === arg || '-t' === arg) {
|
|
50
|
+
args.tag = argv[++aI];
|
|
51
|
+
}
|
|
52
|
+
else if ('--compact' === arg || '-c' === arg) {
|
|
53
|
+
args.space = 0;
|
|
54
|
+
}
|
|
55
|
+
else if ('--compile' === arg || '-C' === arg) {
|
|
56
|
+
args.compile = true;
|
|
57
|
+
}
|
|
58
|
+
else if ('--full' === arg || '-F' === arg) {
|
|
59
|
+
args.compile = true;
|
|
60
|
+
args.full = true;
|
|
61
|
+
}
|
|
62
|
+
else if ('--marks' === arg || '-m' === arg) {
|
|
63
|
+
args.marks = true;
|
|
64
|
+
}
|
|
65
|
+
else if ('--parse' === arg || '-P' === arg) {
|
|
66
|
+
args.parse.push(argv[++aI]);
|
|
67
|
+
}
|
|
68
|
+
else if ('--parse-file' === arg) {
|
|
69
|
+
args.parseFiles.push(argv[++aI]);
|
|
70
|
+
}
|
|
71
|
+
else if (arg && !arg.startsWith('-')) {
|
|
72
|
+
args.inline.push(arg);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (args.help) {
|
|
76
|
+
return help(console);
|
|
77
|
+
}
|
|
78
|
+
let src = '';
|
|
79
|
+
for (const fp of args.files) {
|
|
80
|
+
if ('string' === typeof fp && '' !== fp) {
|
|
81
|
+
src += node_fs_1.default.readFileSync(fp).toString() + '\n';
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
for (const inline of args.inline) {
|
|
85
|
+
src += inline + '\n';
|
|
86
|
+
}
|
|
87
|
+
if ('' === src.trim() || args.stdin) {
|
|
88
|
+
src += await readStdin(console);
|
|
89
|
+
}
|
|
90
|
+
const spec = (0, abnf_1.abnfConvert)(src, { start: args.start, tag: args.tag });
|
|
91
|
+
// Marks mode: list the user-action marks the compiler assigns.
|
|
92
|
+
if (args.marks) {
|
|
93
|
+
console.log((0, abnf_1.markListing)((0, abnf_1.abnfConvert)(src, {
|
|
94
|
+
start: args.start, tag: args.tag, marks: true,
|
|
95
|
+
})));
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
// Compilation mode: emit a pure recognition grammar as jsonic text.
|
|
99
|
+
// No function references — recognition is fully structural. Grammars
|
|
100
|
+
// that need control functions (probe / unbounded lookahead) are
|
|
101
|
+
// refused until those ship as engine `$`-builtins.
|
|
102
|
+
if (args.compile) {
|
|
103
|
+
try {
|
|
104
|
+
console.log((0, abnf_1.abnfCompile)(src, {
|
|
105
|
+
start: args.start,
|
|
106
|
+
tag: args.tag,
|
|
107
|
+
indent: args.space || 2,
|
|
108
|
+
recognition: !args.full,
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
catch (e) {
|
|
112
|
+
if (e instanceof abnf_1.AbnfCompileError) {
|
|
113
|
+
console.error(e.message);
|
|
114
|
+
process.exitCode = 1;
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
throw e;
|
|
118
|
+
}
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
// Parse-mode: validate the grammar against one or more sample
|
|
122
|
+
// inputs and print their parse trees. Exits 1 if any sample fails.
|
|
123
|
+
if (args.parse.length > 0 || args.parseFiles.length > 0) {
|
|
124
|
+
const samples = [];
|
|
125
|
+
for (const fp of args.parseFiles) {
|
|
126
|
+
samples.push({
|
|
127
|
+
label: fp,
|
|
128
|
+
input: node_fs_1.default.readFileSync(fp).toString(),
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
for (const inp of args.parse) {
|
|
132
|
+
samples.push({ label: inp, input: inp });
|
|
133
|
+
}
|
|
134
|
+
// Bare engine: the ABNF spec we're about to install supplies the
|
|
135
|
+
// grammar, so we don't need any other plugin.
|
|
136
|
+
const j = new parser_1.Tabnas();
|
|
137
|
+
j.grammar(spec);
|
|
138
|
+
let failed = 0;
|
|
139
|
+
for (const { label, input } of samples) {
|
|
140
|
+
try {
|
|
141
|
+
const tree = j.parse(input);
|
|
142
|
+
console.log(`ok: ${JSON.stringify(label)} -> ` +
|
|
143
|
+
JSON.stringify(tree, null, args.space || undefined));
|
|
144
|
+
}
|
|
145
|
+
catch (e) {
|
|
146
|
+
failed++;
|
|
147
|
+
const msg = (e?.message || String(e)).split('\n')[0];
|
|
148
|
+
console.error(`fail: ${JSON.stringify(label)}: ${msg}`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (failed > 0) {
|
|
152
|
+
process.exitCode = 1;
|
|
153
|
+
}
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
console.log(JSON.stringify(spec, null, args.space || undefined));
|
|
157
|
+
}
|
|
158
|
+
async function readStdin(console) {
|
|
159
|
+
if ('string' === typeof console.test$) {
|
|
160
|
+
return console.test$;
|
|
161
|
+
}
|
|
162
|
+
if (process.stdin.isTTY)
|
|
163
|
+
return '';
|
|
164
|
+
let s = '';
|
|
165
|
+
process.stdin.setEncoding('utf8');
|
|
166
|
+
for await (const p of process.stdin)
|
|
167
|
+
s += p;
|
|
168
|
+
return s;
|
|
169
|
+
}
|
|
170
|
+
function help(console) {
|
|
171
|
+
console.log(`
|
|
172
|
+
tabnas-abnf: convert an ABNF grammar into a tabnas grammar spec.
|
|
173
|
+
|
|
174
|
+
Usage: tabnas-abnf <args> [<abnf-source>]*
|
|
175
|
+
|
|
176
|
+
Arguments:
|
|
177
|
+
- Read ABNF source from stdin.
|
|
178
|
+
--file <path> Read ABNF source from <path> (repeatable).
|
|
179
|
+
-f <path>
|
|
180
|
+
|
|
181
|
+
--start <name> Set the start rule (defaults to the first
|
|
182
|
+
-s <name> production).
|
|
183
|
+
|
|
184
|
+
--tag <name> Group tag applied to every emitted alt.
|
|
185
|
+
-t <name> Defaults to \`abnf\`.
|
|
186
|
+
|
|
187
|
+
--compact Emit single-line JSON (default indent is 2).
|
|
188
|
+
-c
|
|
189
|
+
|
|
190
|
+
--compile Compilation mode: emit a pure-data *recognition*
|
|
191
|
+
-C grammar as jsonic text (no closures; control
|
|
192
|
+
and tree building reference engine
|
|
193
|
+
\`$\`-builtins).
|
|
194
|
+
|
|
195
|
+
--full With compilation mode, emit the full AST
|
|
196
|
+
-F grammar (tree \`$\`-builtins retained) instead
|
|
197
|
+
of recognition-only. Still pure data.
|
|
198
|
+
|
|
199
|
+
--marks List the per-alt marks the compiler assigns,
|
|
200
|
+
-m usable as \`@<rule>:o|c:<mark>\` action refs.
|
|
201
|
+
|
|
202
|
+
--parse <input> Parse <input> against the generated grammar
|
|
203
|
+
-P <input> and print its parse tree. Repeatable.
|
|
204
|
+
Exits non-zero if any sample fails.
|
|
205
|
+
|
|
206
|
+
--parse-file <path> Parse the contents of <path> against the
|
|
207
|
+
generated grammar (repeatable).
|
|
208
|
+
|
|
209
|
+
--help Print this help message.
|
|
210
|
+
-h
|
|
211
|
+
|
|
212
|
+
Grammar dialect:
|
|
213
|
+
Rules are ABNF-style: \`name = element ...\`, with \`/\` for choice and
|
|
214
|
+
double-quoted literals. For example: \`greet = "hi" / "hello"\`.
|
|
215
|
+
|
|
216
|
+
Examples:
|
|
217
|
+
> tabnas-abnf 'greet = "hi" / "hello"'
|
|
218
|
+
> tabnas-abnf -f grammar.abnf
|
|
219
|
+
> echo 'g = "a"' | tabnas-abnf -
|
|
220
|
+
> tabnas-abnf -f grammar.abnf --parse 'hi'
|
|
221
|
+
`);
|
|
222
|
+
}
|
|
223
|
+
//# sourceMappingURL=tabnas-abnf-cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tabnas-abnf-cli.js","sourceRoot":"","sources":["../../src/bin/tabnas-abnf-cli.ts"],"names":[],"mappings":";AAAA,2EAA2E;;;;;AAY3E,kBA8IC;AAxJD;;GAEG;AAEH,sDAAwB;AAExB,kCAAiF;AACjF,2CAAuC;AAGhC,KAAK,UAAU,GAAG,CAAC,IAAc,EAAE,OAAgB;IACxD,MAAM,IAAI,GAAG;QACX,IAAI,EAAE,KAAK;QACX,KAAK,EAAE,KAAK;QACZ,KAAK,EAAE,EAAc;QACrB,MAAM,EAAE,EAAc;QACtB,KAAK,EAAE,SAA+B;QACtC,GAAG,EAAE,SAA+B;QACpC,KAAK,EAAE,CAAC;QACR,gEAAgE;QAChE,yDAAyD;QACzD,KAAK,EAAE,EAAc;QACrB,UAAU,EAAE,EAAc;QAC1B,6DAA6D;QAC7D,OAAO,EAAE,KAAK;QACd,iEAAiE;QACjE,2CAA2C;QAC3C,IAAI,EAAE,KAAK;QACX,oEAAoE;QACpE,KAAK,EAAE,KAAK;KACb,CAAA;IAED,KAAK,IAAI,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,EAAE,EAAE,EAAE,CAAC;QACxC,MAAM,GAAG,GAAG,IAAI,CAAC,EAAE,CAAC,CAAA;QACpB,IAAI,GAAG,KAAK,GAAG,EAAE,CAAC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AI,EAAE,IAAI,CAAC,KAAK,IAAI,SAAS,CAAC,CAAC,CAAA;AAClE,CAAC;AAGD,KAAK,UAAU,SAAS,CAAC,OAAgB;IACvC,IAAI,QAAQ,KAAK,OAAQ,OAAe,CAAC,KAAK,EAAE,CAAC;QAC/C,OAAQ,OAAe,CAAC,KAAK,CAAA;IAC/B,CAAC;IACD,IAAI,OAAO,CAAC,KAAK,CAAC,KAAK;QAAE,OAAO,EAAE,CAAA;IAClC,IAAI,CAAC,GAAG,EAAE,CAAA;IACV,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;IACjC,IAAI,KAAK,EAAE,MAAM,CAAC,IAAI,OAAO,CAAC,KAAK;QAAE,CAAC,IAAI,CAAC,CAAA;IAC3C,OAAO,CAAC,CAAA;AACV,CAAC;AAGD,SAAS,IAAI,CAAC,OAAgB;IAC5B,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkDb,CAAC,CAAA;AACF,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { GrammarSpec } from '@tabnas/parser';
|
|
2
|
+
import { AbnfConvertOptions } from './converter';
|
|
3
|
+
export declare class AbnfCompileError extends Error {
|
|
4
|
+
rules: string[];
|
|
5
|
+
constructor(message: string, rules: string[]);
|
|
6
|
+
}
|
|
7
|
+
export declare function toRecognitionSpec(spec: GrammarSpec): GrammarSpec;
|
|
8
|
+
export declare function toPureSpec(spec: GrammarSpec): GrammarSpec;
|
|
9
|
+
export type JsonicOptions = {
|
|
10
|
+
strict?: boolean;
|
|
11
|
+
indent?: number;
|
|
12
|
+
};
|
|
13
|
+
export declare function toJsonic(value: any, opts?: JsonicOptions): string;
|
|
14
|
+
export declare class AbnfActionError extends Error {
|
|
15
|
+
constructor(message: string);
|
|
16
|
+
}
|
|
17
|
+
type ActionFn = (r: any, ctx: any, alt: any) => any;
|
|
18
|
+
export type ActionsMap = Record<string, ActionFn | ActionFn[]>;
|
|
19
|
+
export declare function attachActions(spec: GrammarSpec, actions: ActionsMap): GrammarSpec;
|
|
20
|
+
export declare function attachActionSlots(spec: GrammarSpec, refNames: string[]): GrammarSpec;
|
|
21
|
+
export declare function markListing(spec: GrammarSpec): string;
|
|
22
|
+
export type AbnfCompileOptions = AbnfConvertOptions & JsonicOptions & {
|
|
23
|
+
recognition?: boolean;
|
|
24
|
+
};
|
|
25
|
+
export declare function abnfCompile(src: string, opts?: AbnfCompileOptions): string;
|
|
26
|
+
export {};
|