@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2024-04-20T14:42:45Z
3
+ - **Last updated**: 2024-05-08T18:24:31Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
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: [Building a web editor for creating/testing parse grammars](https://www.youtube.com/watch?v=mXp92s_VP40)
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.21 KB
105
+ Package sizes (brotli'd, pre-treeshake): ESM: 5.22 KB
104
106
 
105
107
  ## Dependencies
106
108
 
@@ -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;
@@ -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 {
@@ -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
  };
@@ -1,7 +1,6 @@
1
1
  import { always } from "../prims/always.js";
2
2
  const not = (parser, fail = always()) => (ctx) => {
3
- if (ctx.done)
4
- return false;
3
+ if (ctx.done) return false;
5
4
  ctx.start("");
6
5
  const res = parser(ctx);
7
6
  ctx.discard();
@@ -1,7 +1,6 @@
1
1
  import { discard } from "../xform/discard.js";
2
2
  const seq = (parsers, id = "seq") => (ctx) => {
3
- if (ctx.done)
4
- return false;
3
+ if (ctx.done) return false;
5
4
  ctx.start(id);
6
5
  for (let i = 0, n = parsers.length; i < n; i++) {
7
6
  if (!parsers[i](ctx)) {
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.40",
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": "rimraf --glob '*.js' '*.d.ts' '*.map' doc combinators presets prims readers xform",
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.0",
40
- "@thi.ng/checks": "^3.6.2",
41
- "@thi.ng/defmulti": "^3.0.37",
42
- "@thi.ng/errors": "^2.5.5",
43
- "@thi.ng/strings": "^3.7.31"
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.0",
47
- "esbuild": "^0.20.2",
48
- "rimraf": "^5.0.5",
49
- "typedoc": "^0.25.12",
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": "8339d05ecc857e529c7325a9839c0063b89e728d\n"
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
@@ -2,8 +2,7 @@ const skipWhile = (pred) => (ctx) => {
2
2
  const state = { ...ctx.state };
3
3
  const reader = ctx.reader;
4
4
  while (!state.done) {
5
- if (!pred(reader.read(state)))
6
- break;
5
+ if (!pred(reader.read(state))) break;
7
6
  reader.next(state);
8
7
  }
9
8
  ctx.state = state;
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
  }
@@ -6,8 +6,7 @@ class ArrayReader {
6
6
  return this._src[state.p];
7
7
  }
8
8
  next(state) {
9
- if (state.done)
10
- return;
9
+ if (state.done) return;
11
10
  state.last = this._src[state.p];
12
11
  state.done = ++state.p >= this._src.length;
13
12
  }
@@ -6,8 +6,7 @@ class StringReader {
6
6
  return this._src[state.p];
7
7
  }
8
8
  next(state) {
9
- if (state.done)
10
- return;
9
+ if (state.done) return;
11
10
  state.last = this._src[state.p];
12
11
  if (state.last === "\n") {
13
12
  state.l++;
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})` : "";