@thi.ng/parse 2.4.40 → 2.4.42
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/CHANGELOG.md +1 -1
- package/README.md +4 -2
- package/combinators/alt.js +1 -2
- package/combinators/check.js +1 -2
- package/combinators/lookahead.js +2 -4
- package/combinators/not.js +1 -2
- package/combinators/seq.js +1 -2
- package/grammar.js +3 -6
- package/package.json +12 -13
- package/prims/satisfy.js +2 -4
- package/prims/skip.js +1 -2
- package/prims/string.js +5 -10
- package/readers/array-reader.js +1 -2
- package/readers/string-reader.js +1 -2
- package/xform/join.js +2 -4
- package/xform/nest.js +1 -2
- package/xform/print.js +1 -2
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -47,7 +47,9 @@
|
|
|
47
47
|
|
|
48
48
|
Purely functional parser combinators & AST generation for generic inputs.
|
|
49
49
|
|
|
50
|
-
There's a 2h 45m long video tutorial (live stream) introducing this package:
|
|
50
|
+
There's a 2h 45m long video tutorial (live stream) introducing this package:
|
|
51
|
+
[Building a web editor for creating/testing parse
|
|
52
|
+
grammars](https://makertube.net/w/ursFuQNJQQskmejx1ydL7q)
|
|
51
53
|
|
|
52
54
|
### Features
|
|
53
55
|
|
|
@@ -100,7 +102,7 @@ For Node.js REPL:
|
|
|
100
102
|
const parse = await import("@thi.ng/parse");
|
|
101
103
|
```
|
|
102
104
|
|
|
103
|
-
Package sizes (brotli'd, pre-treeshake): ESM: 5.
|
|
105
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 5.22 KB
|
|
104
106
|
|
|
105
107
|
## Dependencies
|
|
106
108
|
|
package/combinators/alt.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { string } from "../prims/string.js";
|
|
2
2
|
import { discard } from "../xform/discard.js";
|
|
3
3
|
const alt = (parsers) => (ctx) => {
|
|
4
|
-
if (ctx.done)
|
|
5
|
-
return false;
|
|
4
|
+
if (ctx.done) return false;
|
|
6
5
|
for (let i = 0, n = parsers.length; i < n; i++) {
|
|
7
6
|
if (parsers[i](ctx)) {
|
|
8
7
|
return true;
|
package/combinators/check.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { parseError } from "../error.js";
|
|
2
2
|
import { xform } from "./xform.js";
|
|
3
3
|
const check = (parser, pred, msg = "check failed") => xform(parser, (scope, ctx) => {
|
|
4
|
-
if (!pred(scope))
|
|
5
|
-
parseError(ctx, msg);
|
|
4
|
+
if (!pred(scope)) parseError(ctx, msg);
|
|
6
5
|
return scope;
|
|
7
6
|
});
|
|
8
7
|
export {
|
package/combinators/lookahead.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const lookahead = (parser, ahead, capture = false, id = "lookahead") => (ctx) => {
|
|
2
|
-
if (ctx.done)
|
|
3
|
-
return false;
|
|
2
|
+
if (ctx.done) return false;
|
|
4
3
|
ctx.start(id);
|
|
5
4
|
let pass = false;
|
|
6
5
|
while (true) {
|
|
@@ -9,8 +8,7 @@ const lookahead = (parser, ahead, capture = false, id = "lookahead") => (ctx) =>
|
|
|
9
8
|
!capture && (ctx.state = state);
|
|
10
9
|
return pass ? ctx.end() : ctx.discard();
|
|
11
10
|
}
|
|
12
|
-
if (!parser(ctx))
|
|
13
|
-
return ctx.discard();
|
|
11
|
+
if (!parser(ctx)) return ctx.discard();
|
|
14
12
|
pass = true;
|
|
15
13
|
}
|
|
16
14
|
};
|
package/combinators/not.js
CHANGED
package/combinators/seq.js
CHANGED
package/grammar.js
CHANGED
|
@@ -153,16 +153,13 @@ const compile = defmulti(
|
|
|
153
153
|
let parser = acc.length > 1 ? seq(acc, id.result) : withID(id.result, acc[0]);
|
|
154
154
|
if (xf.id === "sym") {
|
|
155
155
|
const $xf = lang.env[xf.result];
|
|
156
|
-
if (!$xf)
|
|
157
|
-
illegalArgs(`missing xform: ${xf.result}`);
|
|
156
|
+
if (!$xf) illegalArgs(`missing xform: ${xf.result}`);
|
|
158
157
|
parser = xform(parser, $xf);
|
|
159
158
|
} else if (xf.id === "ref") {
|
|
160
159
|
const $id = first(xf).result;
|
|
161
|
-
if ($id === id)
|
|
162
|
-
illegalArgs(`self-referential: ${$id}`);
|
|
160
|
+
if ($id === id) illegalArgs(`self-referential: ${$id}`);
|
|
163
161
|
const $xf = lang.rules[$id];
|
|
164
|
-
if (!$xf)
|
|
165
|
-
illegalArgs(`missing xform rule: ${$id}`);
|
|
162
|
+
if (!$xf) illegalArgs(`missing xform rule: ${$id}`);
|
|
166
163
|
parser = nest(parser, $xf);
|
|
167
164
|
} else if (xf.id === "string") {
|
|
168
165
|
parser = xform(parser, xfReplace(xf.result));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/parse",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.42",
|
|
4
4
|
"description": "Purely functional parser combinators & AST generation for generic inputs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"build": "yarn build:esbuild && yarn build:decl",
|
|
28
28
|
"build:decl": "tsc --declaration --emitDeclarationOnly",
|
|
29
29
|
"build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
|
|
30
|
-
"clean": "
|
|
30
|
+
"clean": "bun ../../tools/src/clean-package.ts combinators presets prims readers xform",
|
|
31
31
|
"doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
|
|
32
32
|
"doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
|
|
33
33
|
"doc:readme": "bun ../../tools/src/module-stats.ts && bun ../../tools/src/readme.ts",
|
|
@@ -36,18 +36,17 @@
|
|
|
36
36
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@thi.ng/api": "^8.11.
|
|
40
|
-
"@thi.ng/checks": "^3.6.
|
|
41
|
-
"@thi.ng/defmulti": "^3.0.
|
|
42
|
-
"@thi.ng/errors": "^2.5.
|
|
43
|
-
"@thi.ng/strings": "^3.7.
|
|
39
|
+
"@thi.ng/api": "^8.11.2",
|
|
40
|
+
"@thi.ng/checks": "^3.6.4",
|
|
41
|
+
"@thi.ng/defmulti": "^3.0.39",
|
|
42
|
+
"@thi.ng/errors": "^2.5.7",
|
|
43
|
+
"@thi.ng/strings": "^3.7.33"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@microsoft/api-extractor": "^7.43.
|
|
47
|
-
"esbuild": "^0.
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"typescript": "^5.4.3"
|
|
46
|
+
"@microsoft/api-extractor": "^7.43.2",
|
|
47
|
+
"esbuild": "^0.21.1",
|
|
48
|
+
"typedoc": "^0.25.13",
|
|
49
|
+
"typescript": "^5.4.5"
|
|
51
50
|
},
|
|
52
51
|
"keywords": [
|
|
53
52
|
"ast",
|
|
@@ -242,5 +241,5 @@
|
|
|
242
241
|
],
|
|
243
242
|
"year": 2020
|
|
244
243
|
},
|
|
245
|
-
"gitHead": "
|
|
244
|
+
"gitHead": "df34b4a9e650cc7323575356de207d78933bdcf3\n"
|
|
246
245
|
}
|
package/prims/satisfy.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
const satisfy = (pred, id = "satisfy") => (ctx) => {
|
|
2
|
-
if (ctx.done)
|
|
3
|
-
return false;
|
|
2
|
+
if (ctx.done) return false;
|
|
4
3
|
const r = ctx.reader.read(ctx.state);
|
|
5
4
|
return pred(r) ? ctx.addChild(id, r, true) : false;
|
|
6
5
|
};
|
|
7
6
|
const satisfyD = (pred) => (ctx) => {
|
|
8
|
-
if (ctx.done)
|
|
9
|
-
return false;
|
|
7
|
+
if (ctx.done) return false;
|
|
10
8
|
const state = ctx.state;
|
|
11
9
|
const reader = ctx.reader;
|
|
12
10
|
return pred(reader.read(state)) ? (reader.next(state), true) : false;
|
package/prims/skip.js
CHANGED
package/prims/string.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
const string = (str, id = "string") => (ctx) => {
|
|
2
|
-
if (ctx.done)
|
|
3
|
-
return false;
|
|
2
|
+
if (ctx.done) return false;
|
|
4
3
|
const scope = ctx.start(id);
|
|
5
4
|
const state = scope.state;
|
|
6
5
|
const reader = ctx.reader;
|
|
7
6
|
for (let i = 0, n = str.length; i < n; i++) {
|
|
8
|
-
if (state.done)
|
|
9
|
-
return false;
|
|
7
|
+
if (state.done) return false;
|
|
10
8
|
const r = reader.read(state);
|
|
11
9
|
if (r !== str[i]) {
|
|
12
10
|
return ctx.discard();
|
|
@@ -17,13 +15,11 @@ const string = (str, id = "string") => (ctx) => {
|
|
|
17
15
|
return ctx.end();
|
|
18
16
|
};
|
|
19
17
|
const stringD = (str) => (ctx) => {
|
|
20
|
-
if (ctx.done)
|
|
21
|
-
return false;
|
|
18
|
+
if (ctx.done) return false;
|
|
22
19
|
const state = { ...ctx.state };
|
|
23
20
|
const reader = ctx.reader;
|
|
24
21
|
for (let i = 0, n = str.length; i < n; i++) {
|
|
25
|
-
if (state.done)
|
|
26
|
-
return false;
|
|
22
|
+
if (state.done) return false;
|
|
27
23
|
const r = reader.read(state);
|
|
28
24
|
if (r !== str[i]) {
|
|
29
25
|
return false;
|
|
@@ -39,8 +35,7 @@ const stringOf = (pred, id = "string", reduce = (x) => x.join("")) => (ctx) => {
|
|
|
39
35
|
let acc = [];
|
|
40
36
|
while (!state.done) {
|
|
41
37
|
const r = reader.read(state);
|
|
42
|
-
if (!pred(r))
|
|
43
|
-
break;
|
|
38
|
+
if (!pred(r)) break;
|
|
44
39
|
acc.push(r);
|
|
45
40
|
reader.next(state);
|
|
46
41
|
}
|
package/readers/array-reader.js
CHANGED
package/readers/string-reader.js
CHANGED
package/xform/join.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { xform } from "../combinators/xform.js";
|
|
2
2
|
const xfJoin = (scope) => {
|
|
3
|
-
if (!scope || !scope.children)
|
|
4
|
-
return null;
|
|
3
|
+
if (!scope || !scope.children) return null;
|
|
5
4
|
const res = [];
|
|
6
5
|
for (let c of scope.children) {
|
|
7
6
|
xfJoin(c);
|
|
8
|
-
if (c.result)
|
|
9
|
-
res.push(c.result);
|
|
7
|
+
if (c.result) res.push(c.result);
|
|
10
8
|
}
|
|
11
9
|
scope.result = res.join("");
|
|
12
10
|
scope.children = null;
|
package/xform/nest.js
CHANGED
|
@@ -2,8 +2,7 @@ import { xform } from "../combinators/xform.js";
|
|
|
2
2
|
import { defContext } from "../context.js";
|
|
3
3
|
import { xfJoin } from "./join.js";
|
|
4
4
|
const xfNest = (parser) => (scope, ctx) => {
|
|
5
|
-
if (!scope)
|
|
6
|
-
return;
|
|
5
|
+
if (!scope) return;
|
|
7
6
|
const src = scope.result || xfJoin({ ...scope }).result;
|
|
8
7
|
const inner = defContext(src, ctx.opts);
|
|
9
8
|
const state = scope.state;
|
package/xform/print.js
CHANGED
|
@@ -2,8 +2,7 @@ import { xform } from "../combinators/xform.js";
|
|
|
2
2
|
import { indent } from "../utils.js";
|
|
3
3
|
const xfPrint = (fn = console.log) => {
|
|
4
4
|
const $print = (scope, _, level = 0) => {
|
|
5
|
-
if (!scope)
|
|
6
|
-
return;
|
|
5
|
+
if (!scope) return;
|
|
7
6
|
const prefix = indent(level);
|
|
8
7
|
const state = scope.state;
|
|
9
8
|
const info = state ? ` (${state.l}:${state.c})` : "";
|