parseman 0.21.0 → 0.22.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/dist/combinators/grammar.d.ts.map +1 -1
- package/dist/combinators/parser.d.ts +12 -0
- package/dist/combinators/parser.d.ts.map +1 -1
- package/dist/compiler/codegen.d.ts +3 -1
- package/dist/compiler/codegen.d.ts.map +1 -1
- package/dist/functional/run.d.ts.map +1 -1
- package/dist/index.cjs +16 -2
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +16 -2
- package/dist/index.js.map +2 -2
- package/dist/plugin/index.cjs +33 -7
- package/dist/plugin/index.cjs.map +2 -2
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +33 -7
- package/dist/plugin/index.js.map +2 -2
- package/dist/types.d.ts +10 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1690,7 +1690,9 @@ function tagRule(r, key) {
|
|
|
1690
1690
|
r._ruleName = key;
|
|
1691
1691
|
if (r._def.tag === "node" && r._def.type === void 0) r._def.type = key;
|
|
1692
1692
|
}
|
|
1693
|
-
function rules(
|
|
1693
|
+
function rules(a, b) {
|
|
1694
|
+
const factory = typeof a === "function" ? a : b;
|
|
1695
|
+
const options = typeof a === "function" ? b : a;
|
|
1694
1696
|
const cache = {};
|
|
1695
1697
|
const proxy = new Proxy(cache, {
|
|
1696
1698
|
get(target, key) {
|
|
@@ -1718,6 +1720,12 @@ function rules(factory) {
|
|
|
1718
1720
|
cache[key] = parser2;
|
|
1719
1721
|
}
|
|
1720
1722
|
}
|
|
1723
|
+
if (options?.trivia !== void 0) {
|
|
1724
|
+
for (const key of Object.keys(definitions)) {
|
|
1725
|
+
const rule = cache[key];
|
|
1726
|
+
if (rule && !rule._meta.isTrivia) rule._meta.grammarTrivia = options.trivia;
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1721
1729
|
for (const key of Object.keys(definitions)) {
|
|
1722
1730
|
markUnusedValues(cache[key]);
|
|
1723
1731
|
}
|
|
@@ -2060,8 +2068,10 @@ function parse(combinator, input, opts = {}) {
|
|
|
2060
2068
|
const trackLines = opts.trackLines ?? false;
|
|
2061
2069
|
const _errors = opts.recover ? [] : void 0;
|
|
2062
2070
|
const _probe = opts.recover ? { offset: input.length, best: null } : void 0;
|
|
2071
|
+
const grammarTrivia = combinator._meta.grammarTrivia;
|
|
2063
2072
|
const ctx = {
|
|
2064
2073
|
trackLines,
|
|
2074
|
+
...grammarTrivia !== void 0 ? { trivia: grammarTrivia, ...grammarTrivia._meta.triviaKindLabels ? { triviaKindLabels: grammarTrivia._meta.triviaKindLabels } : {} } : {},
|
|
2065
2075
|
..._errors !== void 0 ? { _errors } : {},
|
|
2066
2076
|
..._probe !== void 0 ? { _probe } : {}
|
|
2067
2077
|
};
|
|
@@ -5327,6 +5337,7 @@ function ruleDependencies(ruleMap) {
|
|
|
5327
5337
|
}
|
|
5328
5338
|
function compile(combinator, mapFnSources) {
|
|
5329
5339
|
markUnusedValues(combinator);
|
|
5340
|
+
const grammarTrivia = combinator._meta.grammarTrivia;
|
|
5330
5341
|
const ctx = {
|
|
5331
5342
|
vars: 0,
|
|
5332
5343
|
indent: 1,
|
|
@@ -5345,7 +5356,8 @@ function compile(combinator, mapFnSources) {
|
|
|
5345
5356
|
triviaFnNames: /* @__PURE__ */ new Map(),
|
|
5346
5357
|
namedFnDecls: [],
|
|
5347
5358
|
capturing: hasNodeDef(combinator),
|
|
5348
|
-
lazyUsage: analyzeLazyUsage(combinator)
|
|
5359
|
+
lazyUsage: analyzeLazyUsage(combinator),
|
|
5360
|
+
...grammarTrivia ? { activeTrivia: grammarTrivia, triviaKindLabels: grammarTrivia._meta.triviaKindLabels } : {}
|
|
5349
5361
|
};
|
|
5350
5362
|
const r = emit(combinator, ctx, "_pos");
|
|
5351
5363
|
const namedPrelude = ctx.namedFnDecls.length > 0 ? [...namedFnPrelude(), ""] : [];
|
|
@@ -6203,12 +6215,14 @@ function run(entry, input, options = {}) {
|
|
|
6203
6215
|
}
|
|
6204
6216
|
const triviaLog = [];
|
|
6205
6217
|
const errors = [];
|
|
6218
|
+
const grammarTrivia = typeof entry !== "function" ? entry._meta.grammarTrivia : void 0;
|
|
6206
6219
|
const ctx = {
|
|
6207
6220
|
trackLines: false,
|
|
6208
6221
|
_triviaLog: triviaLog,
|
|
6209
6222
|
_errors: errors,
|
|
6210
6223
|
build: options.build,
|
|
6211
6224
|
state: options.state,
|
|
6225
|
+
...grammarTrivia !== void 0 ? { trivia: grammarTrivia, ...grammarTrivia._meta.triviaKindLabels ? { triviaKindLabels: grammarTrivia._meta.triviaKindLabels } : {} } : {},
|
|
6212
6226
|
...options.triviaCaptureMask !== void 0 ? { _triviaCaptureMask: options.triviaCaptureMask } : {}
|
|
6213
6227
|
};
|
|
6214
6228
|
const r = invoke(entry, input, 0, ctx);
|