@thi.ng/parse 2.4.42 → 2.4.44

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-05-08T18:24:31Z
3
+ - **Last updated**: 2024-06-29T09:28:36Z
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.
@@ -9,6 +9,13 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ### [2.4.43](https://github.com/thi-ng/umbrella/tree/@thi.ng/parse@2.4.43) (2024-06-21)
13
+
14
+ #### ♻️ Refactoring
15
+
16
+ - rename various rest args to be more semantically meaningful ([8088a56](https://github.com/thi-ng/umbrella/commit/8088a56))
17
+ - enforce uniform naming convention of internal functions ([56992b2](https://github.com/thi-ng/umbrella/commit/56992b2))
18
+
12
19
  ### [2.4.5](https://github.com/thi-ng/umbrella/tree/@thi.ng/parse@2.4.5) (2023-11-09)
13
20
 
14
21
  #### ♻️ Refactoring
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)](https://mastodon.thi.ng/@toxi)
8
8
 
9
9
  > [!NOTE]
10
- > This is one of 192 standalone projects, maintained as part
10
+ > This is one of 189 standalone projects, maintained as part
11
11
  > of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
12
12
  > and anti-framework.
13
13
  >
@@ -73,7 +73,6 @@ grammars](https://makertube.net/w/ursFuQNJQQskmejx1ydL7q)
73
73
 
74
74
  ## Related packages
75
75
 
76
- - [@thi.ng/fsm](https://github.com/thi-ng/umbrella/tree/develop/packages/fsm) - Composable primitives for building declarative, transducer based Finite-State Machines & matchers for arbitrary data streams
77
76
  - [@thi.ng/transducers-fsm](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers-fsm) - Transducer-based Finite State Machine transformer
78
77
 
79
78
  ## Installation
@@ -102,7 +101,7 @@ For Node.js REPL:
102
101
  const parse = await import("@thi.ng/parse");
103
102
  ```
104
103
 
105
- Package sizes (brotli'd, pre-treeshake): ESM: 5.22 KB
104
+ Package sizes (brotli'd, pre-treeshake): ESM: 5.21 KB
106
105
 
107
106
  ## Dependencies
108
107
 
@@ -1,16 +1,17 @@
1
1
  import type { DynamicParser } from "../api.js";
2
2
  /**
3
- * Returns a parser function placeholder, whose implementation can be
4
- * set at a later stage via calling `.set()`.
3
+ * Returns a parser function placeholder, whose implementation can be set at a
4
+ * later stage via calling `.set()`. The parser always fails until set, after
5
+ * which it then delegates to the chosen impl.
5
6
  *
6
7
  * @examples
7
- * ```ts
8
- * import { defContext, dynamic } from "@thi.ng/parse";
8
+ * ```ts tangle:../../export/dynamic.ts
9
+ * import { defContext, dynamic,lit } from "@thi.ng/parse";
9
10
  *
10
11
  * const parser = dynamic<string>();
11
12
  * parser.set(lit("a"));
12
13
  *
13
- * parser(defContext("a"));
14
+ * console.log(parser(defContext("a")));
14
15
  * // true
15
16
  * ```
16
17
  */
@@ -25,8 +25,8 @@ import type { Parser } from "../api.js";
25
25
  * behavior and not a bug.
26
26
  *
27
27
  * @example
28
- * ```ts
29
- * import { defContext, lookahead, oneOf, stringD } from "@thi.ng/parse";
28
+ * ```ts tangle:../../export/lookahead.ts
29
+ * import { defContext, join, lookahead, oneOf, stringD } from "@thi.ng/parse";
30
30
  *
31
31
  * const ctx = defContext("ababaaabbabba");
32
32
  *
@@ -34,30 +34,34 @@ import type { Parser } from "../api.js";
34
34
  * // note the use of `stringD()` to discard lookahead result
35
35
  *
36
36
  * // non-capturing lookahead
37
- * join(lookahead(oneOf("ab"), stringD("abba")))(ctx)
37
+ * console.log(
38
+ * join(lookahead(oneOf("ab"), stringD("abba")))(ctx)
39
+ * );
38
40
  * // true
39
41
  *
40
- * ctx.result
42
+ * console.log(ctx.result);
41
43
  * // "ababaa"
42
44
  *
43
- * ctx.state
45
+ * console.log(ctx.state);
44
46
  * // { p: 6, l: 1, c: 7, done: false, last: 'a' }
45
47
  * ```
46
48
  *
47
49
  * @example
48
- * ```ts
49
- * import { defContext, lookahead, oneOf, string } from "@thi.ng/parse";
50
+ * ```ts tangle:../../export/lookahead-2.ts
51
+ * import { defContext, join, lookahead, oneOf, string } from "@thi.ng/parse";
50
52
  *
51
53
  * const ctx = defContext("ababaaabbabba");
52
54
  *
53
55
  * // capturing lookahead
54
- * join(lookahead(oneOf("ab"), string("abba"), true))(ctx)
56
+ * console.log(
57
+ * join(lookahead(oneOf("ab"), string("abba"), true))(ctx)
58
+ * );
55
59
  * // true
56
60
  *
57
- * ctx.result
61
+ * console.log(ctx.result);
58
62
  * // "ababaaabba"
59
63
  *
60
- * ctx.state
64
+ * console.log(ctx.state);
61
65
  * // { p: 10, l: 1, c: 11, done: false, last: 'a' }
62
66
  * ```
63
67
  *
package/context.js CHANGED
@@ -3,7 +3,7 @@ import { isString } from "@thi.ng/checks/is-string";
3
3
  import { parseError } from "./error.js";
4
4
  import { defArrayReader } from "./readers/array-reader.js";
5
5
  import { defStringReader } from "./readers/string-reader.js";
6
- import { indent } from "./utils.js";
6
+ import { __indent } from "./utils.js";
7
7
  class ParseContext {
8
8
  constructor(reader, opts) {
9
9
  this.reader = reader;
@@ -46,7 +46,7 @@ class ParseContext {
46
46
  scopes.push(scope);
47
47
  this._peakDepth = Math.max(this._peakDepth, scopes.length);
48
48
  this._debug && console.log(
49
- `${indent(scopes.length)}start: ${id} (${scope.state.p})`
49
+ `${__indent(scopes.length)}start: ${id} (${scope.state.p})`
50
50
  );
51
51
  return this._curr = scope;
52
52
  }
@@ -54,7 +54,7 @@ class ParseContext {
54
54
  const scopes = this._scopes;
55
55
  const child = scopes.pop();
56
56
  this._curr = scopes[scopes.length - 1];
57
- this._debug && console.log(`${indent(scopes.length + 1)}discard: ${child.id}`);
57
+ this._debug && console.log(`${__indent(scopes.length + 1)}discard: ${child.id}`);
58
58
  return false;
59
59
  }
60
60
  end() {
@@ -64,7 +64,7 @@ class ParseContext {
64
64
  const cstate = child.state;
65
65
  let pstate;
66
66
  this._debug && console.log(
67
- `${indent(scopes.length + 1)}end: ${child.id} (${cstate.p})`
67
+ `${__indent(scopes.length + 1)}end: ${child.id} (${cstate.p})`
68
68
  );
69
69
  child.state = this._retain ? (pstate = parent.state, { p: pstate.p, l: pstate.l, c: pstate.c }) : null;
70
70
  parent.state = cstate;
@@ -83,7 +83,7 @@ class ParseContext {
83
83
  result
84
84
  };
85
85
  this._debug && console.log(
86
- `${indent(this._scopes.length + 1)}addChild: ${id} (${cstate.p})`
86
+ `${__indent(this._scopes.length + 1)}addChild: ${id} (${cstate.p})`
87
87
  );
88
88
  const children = curr.children;
89
89
  children ? children.push(child) : curr.children = [child];
package/grammar.js CHANGED
@@ -43,8 +43,8 @@ import { print, xfPrint } from "./xform/print.js";
43
43
  import { xfReplace } from "./xform/replace.js";
44
44
  import { xfTrim } from "./xform/trim.js";
45
45
  import { withID } from "./xform/with-id.js";
46
- const apos = litD("'");
47
- const dash = litD("-");
46
+ const APOS = litD("'");
47
+ const DASH = litD("-");
48
48
  const REPEAT = maybe(
49
49
  alt([
50
50
  oneOf("?*+", "repeat"),
@@ -58,7 +58,7 @@ const REPEAT = maybe(
58
58
  );
59
59
  const DISCARD = maybe(lit("!"), void 0, "discard");
60
60
  const CHAR_OR_ESC = alt([UNICODE, ESC, always()]);
61
- const CHAR_RANGE = seq([CHAR_OR_ESC, dash, CHAR_OR_ESC], "charRange");
61
+ const CHAR_RANGE = seq([CHAR_OR_ESC, DASH, CHAR_OR_ESC], "charRange");
62
62
  const CHAR_SEL = seq(
63
63
  [
64
64
  litD("["),
@@ -69,7 +69,7 @@ const CHAR_SEL = seq(
69
69
  "charSel"
70
70
  );
71
71
  const ANY = lit(".", "any");
72
- const LIT = hoistResult(seq([apos, CHAR_OR_ESC, apos], "char"));
72
+ const LIT = hoistResult(seq([APOS, CHAR_OR_ESC, APOS], "char"));
73
73
  const SYM = join(oneOrMore(alt([ALPHA_NUM, oneOf(".-_$")]), "sym"));
74
74
  const RULE_REF = seq([litD("<"), SYM, litD(">")], "ref");
75
75
  const TERM_BODY = alt([RULE_REF, ANY, LIT, STRING, CHAR_SEL]);
@@ -119,9 +119,9 @@ const RULE = seq(
119
119
  );
120
120
  const COMMENT = seqD([WS0, litD("#"), lookahead(always(), DNL)]);
121
121
  const GRAMMAR = zeroOrMore(alt([RULE, COMMENT]), "rules");
122
- const first = ($) => $.children[0];
123
- const nth = ($, n) => $.children[n];
124
- const compile = defmulti(
122
+ const __first = ($) => $.children[0];
123
+ const __nth = ($, n) => $.children[n];
124
+ const __compile = defmulti(
125
125
  (scope) => scope.id,
126
126
  {
127
127
  unicode: "char"
@@ -129,15 +129,15 @@ const compile = defmulti(
129
129
  {
130
130
  [DEFAULT]: ($) => unsupported(`unknown op: ${$.id}`),
131
131
  root: ($, lang, opts, flags) => {
132
- const rules = first($).children;
132
+ const rules = __first($).children;
133
133
  rules.reduce(
134
- (acc, r) => (acc[first(r).result] = dynamic(), acc),
134
+ (acc, r) => (acc[__first(r).result] = dynamic(), acc),
135
135
  lang.rules
136
136
  );
137
137
  for (let r of rules) {
138
- const id = first(r).result;
138
+ const id = __first(r).result;
139
139
  lang.rules[id].set(
140
- compile(r, lang, opts, flags)
140
+ __compile(r, lang, opts, flags)
141
141
  );
142
142
  }
143
143
  return lang;
@@ -147,7 +147,7 @@ const compile = defmulti(
147
147
  opts.debug && console.log(`rule: ${id.result}`, xf);
148
148
  const acc = [];
149
149
  for (let b of body.children) {
150
- const c = compile(b, lang, opts, flags);
150
+ const c = __compile(b, lang, opts, flags);
151
151
  c && acc.push(c);
152
152
  }
153
153
  let parser = acc.length > 1 ? seq(acc, id.result) : withID(id.result, acc[0]);
@@ -156,7 +156,7 @@ const compile = defmulti(
156
156
  if (!$xf) illegalArgs(`missing xform: ${xf.result}`);
157
157
  parser = xform(parser, $xf);
158
158
  } else if (xf.id === "ref") {
159
- const $id = first(xf).result;
159
+ const $id = __first(xf).result;
160
160
  if ($id === id) illegalArgs(`self-referential: ${$id}`);
161
161
  const $xf = lang.rules[$id];
162
162
  if (!$xf) illegalArgs(`missing xform rule: ${$id}`);
@@ -167,7 +167,7 @@ const compile = defmulti(
167
167
  return parser;
168
168
  },
169
169
  ref: ($, lang, opts, flags) => {
170
- const id = first($).result;
170
+ const id = __first($).result;
171
171
  opts.debug && console.log(`ref: ${id}`, flags);
172
172
  const ref = lang.rules[id];
173
173
  return ref ? flags.discard ? discard(ref) : ref : illegalArgs(`invalid rule ref: ${id}`);
@@ -175,8 +175,8 @@ const compile = defmulti(
175
175
  term: ($, lang, opts, flags) => {
176
176
  const [term, repeat2, discard2, lookahead2] = $.children;
177
177
  opts.debug && console.log(`term: ${term.id}`, flags);
178
- return compileRDL(
179
- (discard3) => compile(term, lang, opts, { ...flags, discard: discard3 }),
178
+ return __compileRDL(
179
+ (discard3) => __compile(term, lang, opts, { ...flags, discard: discard3 }),
180
180
  repeat2,
181
181
  discard2,
182
182
  lookahead2,
@@ -187,8 +187,8 @@ const compile = defmulti(
187
187
  lhterm: ($, lang, opts, flags) => {
188
188
  const [term, repeat2, discard2] = $.children;
189
189
  opts.debug && console.log(`lhterm: ${term.id}`);
190
- return compileRD(
191
- (discard3) => compile(term, lang, opts, { ...flags, discard: discard3 }),
190
+ return __compileRD(
191
+ (discard3) => __compile(term, lang, opts, { ...flags, discard: discard3 }),
192
192
  repeat2,
193
193
  discard2,
194
194
  opts
@@ -197,13 +197,13 @@ const compile = defmulti(
197
197
  alt: ($, lang, opts, flags) => {
198
198
  opts.debug && console.log(`alt: ${$.id}`, flags);
199
199
  const [term0, { children: terms }, repeat2, disc, lookahead2] = $.children;
200
- const acc = [compile(term0, lang, opts, flags)];
200
+ const acc = [__compile(term0, lang, opts, flags)];
201
201
  if (terms) {
202
202
  for (let c of terms) {
203
- acc.push(compile(first(c), lang, opts, flags));
203
+ acc.push(__compile(__first(c), lang, opts, flags));
204
204
  }
205
205
  }
206
- return compileRDL(
206
+ return __compileRDL(
207
207
  (optimize) => optimize || flags.discard ? acc.length > 1 ? altD(acc) : discard(acc[0]) : acc.length > 1 ? alt(acc) : acc[0],
208
208
  repeat2,
209
209
  disc,
@@ -233,17 +233,17 @@ const compile = defmulti(
233
233
  },
234
234
  charSel: ($, lang, opts, flags) => {
235
235
  opts.debug && console.log("charSel", flags);
236
- const choices = nth($, 1).children.map(
237
- (c) => compile(c, lang, opts, flags)
236
+ const choices = __nth($, 1).children.map(
237
+ (c) => __compile(c, lang, opts, flags)
238
238
  );
239
- const invert = first($).result;
239
+ const invert = __first($).result;
240
240
  const parser = choices.length > 1 ? alt(choices) : choices[0];
241
241
  opts.debug && console.log(`invert: ${invert}`);
242
242
  return invert ? not(parser, flags.discard ? alwaysD() : always()) : parser;
243
243
  }
244
244
  }
245
245
  );
246
- const compileRepeat = (parser, rspec, opts) => {
246
+ const __compileRepeat = (parser, rspec, opts) => {
247
247
  opts.debug && console.log(`repeat: ${rspec.id}`);
248
248
  if (rspec.id === "repeat") {
249
249
  switch (rspec.result) {
@@ -262,24 +262,29 @@ const compileRepeat = (parser, rspec, opts) => {
262
262
  }
263
263
  return parser;
264
264
  };
265
- const compileDiscard = (parser, dspec, opts) => {
265
+ const __compileDiscard = (parser, dspec, opts) => {
266
266
  opts.debug && console.log(`discard:`, dspec.result);
267
267
  return dspec.result === "!" ? discard(parser) : parser;
268
268
  };
269
- const compileLookahead = (parser, spec, lang, opts) => {
269
+ const __compileLookahead = (parser, spec, lang, opts) => {
270
270
  opts.debug && console.log(`lookahead:`, spec.id);
271
271
  return spec.id === "lhspec" ? lookahead(
272
272
  parser,
273
- compile(nth(spec, 1), lang, opts, {}),
274
- first(spec).result === "+"
273
+ __compile(__nth(spec, 1), lang, opts, {}),
274
+ __first(spec).result === "+"
275
275
  ) : parser;
276
276
  };
277
- const compileRD = (parser, rspec, dspec, opts) => dspec.result != null && rspec.result == null ? parser(true) : compileDiscard(
278
- compileRepeat(parser(false), rspec, opts),
277
+ const __compileRD = (parser, rspec, dspec, opts) => dspec.result != null && rspec.result == null ? parser(true) : __compileDiscard(
278
+ __compileRepeat(parser(false), rspec, opts),
279
279
  dspec,
280
280
  opts
281
281
  );
282
- const compileRDL = (parser, rspec, dspec, lhspec, lang, opts) => compileLookahead(compileRD(parser, rspec, dspec, opts), lhspec, lang, opts);
282
+ const __compileRDL = (parser, rspec, dspec, lhspec, lang, opts) => __compileLookahead(
283
+ __compileRD(parser, rspec, dspec, opts),
284
+ lhspec,
285
+ lang,
286
+ opts
287
+ );
283
288
  const defGrammar = (rules, env, opts) => {
284
289
  opts = { debug: false, optimize: true, ...opts };
285
290
  env = {
@@ -301,7 +306,7 @@ const defGrammar = (rules, env, opts) => {
301
306
  const ctx = defContext(rules);
302
307
  const result = (opts.debug ? print(GRAMMAR) : GRAMMAR)(ctx);
303
308
  if (result) {
304
- return compile(
309
+ return __compile(
305
310
  ctx.root,
306
311
  {
307
312
  env,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/parse",
3
- "version": "2.4.42",
3
+ "version": "2.4.44",
4
4
  "description": "Purely functional parser combinators & AST generation for generic inputs",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -10,7 +10,7 @@
10
10
  "type": "git",
11
11
  "url": "https://github.com/thi-ng/umbrella.git"
12
12
  },
13
- "homepage": "https://github.com/thi-ng/umbrella/tree/develop/packages/parse#readme",
13
+ "homepage": "https://thi.ng/parse",
14
14
  "funding": [
15
15
  {
16
16
  "type": "github",
@@ -36,17 +36,17 @@
36
36
  "tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
37
37
  },
38
38
  "dependencies": {
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"
39
+ "@thi.ng/api": "^8.11.4",
40
+ "@thi.ng/checks": "^3.6.6",
41
+ "@thi.ng/defmulti": "^3.0.41",
42
+ "@thi.ng/errors": "^2.5.9",
43
+ "@thi.ng/strings": "^3.7.35"
44
44
  },
45
45
  "devDependencies": {
46
- "@microsoft/api-extractor": "^7.43.2",
47
- "esbuild": "^0.21.1",
46
+ "@microsoft/api-extractor": "^7.47.0",
47
+ "esbuild": "^0.21.5",
48
48
  "typedoc": "^0.25.13",
49
- "typescript": "^5.4.5"
49
+ "typescript": "^5.5.2"
50
50
  },
51
51
  "keywords": [
52
52
  "ast",
@@ -241,5 +241,5 @@
241
241
  ],
242
242
  "year": 2020
243
243
  },
244
- "gitHead": "df34b4a9e650cc7323575356de207d78933bdcf3\n"
244
+ "gitHead": "7b950c112fba0b2e7c450765b15624c3382f1354\n"
245
245
  }
package/presets/string.js CHANGED
@@ -5,9 +5,9 @@ import { litD } from "../prims/lit.js";
5
5
  import { noneOf } from "../prims/none-of.js";
6
6
  import { join } from "../xform/join.js";
7
7
  import { ESC, UNICODE } from "./escape.js";
8
- const quote = litD('"');
8
+ const QUOTE = litD('"');
9
9
  const STRING = join(
10
- seq([quote, zeroOrMore(alt([UNICODE, ESC, noneOf('"')])), quote], "string")
10
+ seq([QUOTE, zeroOrMore(alt([UNICODE, ESC, noneOf('"')])), QUOTE], "string")
11
11
  );
12
12
  export {
13
13
  STRING
package/prims/skip.d.ts CHANGED
@@ -7,16 +7,17 @@ import type { Parser } from "../api.js";
7
7
  * of the input is reached, this parser will return true.
8
8
  *
9
9
  * @example
10
- * ```ts
11
- * import { defContext, litD, noneOfP, seqD, skipWhile } from "@thi.ng/parse";
10
+ * ```ts tangle:../../export/skip-while.ts
11
+ * import { defContext, litD, NL, noneOfP, seqD, skipWhile } from "@thi.ng/parse";
12
12
  *
13
13
  * const comment = seqD([litD("#"), skipWhile(noneOfP("\n")), NL]);
14
14
  *
15
15
  * const ctx = defContext("# ignore more!\n");
16
- * comment(ctx);
16
+ *
17
+ * console.log(comment(ctx));
17
18
  * // true
18
19
  *
19
- * ctx.state
20
+ * console.log(ctx.state);
20
21
  * // { p: 15, l: 2, c: 1, done: true, last: '\n' }
21
22
  * ```
22
23
  *
package/utils.d.ts CHANGED
@@ -5,5 +5,5 @@
5
5
  *
6
6
  * @internal
7
7
  */
8
- export declare const indent: (x: number) => string;
8
+ export declare const __indent: (x: number) => string;
9
9
  //# sourceMappingURL=utils.d.ts.map
package/utils.js CHANGED
@@ -1,5 +1,5 @@
1
- const cache = [];
2
- const indent = (x) => cache[x] = " ".repeat(x);
1
+ const CACHE = [];
2
+ const __indent = (x) => CACHE[x] = " ".repeat(x);
3
3
  export {
4
- indent
4
+ __indent
5
5
  };
package/xform/comp.d.ts CHANGED
@@ -3,7 +3,7 @@ import type { ScopeTransform } from "../api.js";
3
3
  * Takes any number of {@link ScopeTransform}s and composes them into
4
4
  * new xform w/ left to right order of execution.
5
5
  *
6
- * @param xs -
6
+ * @param xforms -
7
7
  */
8
- export declare const comp: <T>(...xs: ScopeTransform<T>[]) => ScopeTransform<T>;
8
+ export declare const comp: <T>(...xforms: ScopeTransform<T>[]) => ScopeTransform<T>;
9
9
  //# sourceMappingURL=comp.d.ts.map
package/xform/comp.js CHANGED
@@ -1,6 +1,6 @@
1
- const comp = (...xs) => {
2
- const [a, b, c, d] = xs;
3
- switch (xs.length) {
1
+ const comp = (...xforms) => {
2
+ const [a, b, c, d] = xforms;
3
+ switch (xforms.length) {
4
4
  case 0:
5
5
  return (x) => x;
6
6
  case 1:
@@ -12,7 +12,7 @@ const comp = (...xs) => {
12
12
  case 4:
13
13
  return (scope, ctx, user) => d(c(b(a(scope, ctx, user), ctx, user), ctx, user), ctx, user);
14
14
  default:
15
- return (scope, ctx, user) => xs.reduce((scope2, x) => x(scope2, ctx, user), scope);
15
+ return (scope, ctx, user) => xforms.reduce((scope2, x) => x(scope2, ctx, user), scope);
16
16
  }
17
17
  };
18
18
  export {
package/xform/print.d.ts CHANGED
@@ -18,16 +18,16 @@ export declare const xfPrint: (fn?: Fn<string, void>) => ScopeTransform<any>;
18
18
  * Syntax sugar for `xform(parser, xfPrint)`.
19
19
  *
20
20
  * @example
21
- * ```ts
22
- * import { defContext, lit, oneOrMore, seq, ALPHA } from "@thi.ng/parse";
21
+ * ```ts tangle:../../export/print.ts
22
+ * import { ALPHA, defContext, lit, oneOrMore, print, seq } from "@thi.ng/parse";
23
23
  *
24
- * print(seq([lit("["), oneOrMore(ALPHA), lit("]")]))(defContext("[abc]"))
24
+ * print(seq([lit("["), oneOrMore(ALPHA), lit("]")]))(defContext("[abc]"));
25
25
  * // seq: null
26
26
  * // lit: "["
27
27
  * // repeat1: null
28
- * // lit: "a"
29
- * // lit: "b"
30
- * // lit: "c"
28
+ * // oneOf: "a"
29
+ * // oneOf: "b"
30
+ * // oneOf: "c"
31
31
  * // lit: "]"
32
32
  * ```
33
33
  *
package/xform/print.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { xform } from "../combinators/xform.js";
2
- import { indent } from "../utils.js";
2
+ import { __indent } from "../utils.js";
3
3
  const xfPrint = (fn = console.log) => {
4
4
  const $print = (scope, _, level = 0) => {
5
5
  if (!scope) return;
6
- const prefix = indent(level);
6
+ const prefix = __indent(level);
7
7
  const state = scope.state;
8
8
  const info = state ? ` (${state.l}:${state.c})` : "";
9
9
  fn(`${prefix}${scope.id}${info}: ${JSON.stringify(scope.result)}`);