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/plugin/index.cjs
CHANGED
|
@@ -1729,7 +1729,9 @@ function tagRule(r, key) {
|
|
|
1729
1729
|
r._ruleName = key;
|
|
1730
1730
|
if (r._def.tag === "node" && r._def.type === void 0) r._def.type = key;
|
|
1731
1731
|
}
|
|
1732
|
-
function rules(
|
|
1732
|
+
function rules(a, b) {
|
|
1733
|
+
const factory = typeof a === "function" ? a : b;
|
|
1734
|
+
const options = typeof a === "function" ? b : a;
|
|
1733
1735
|
const cache = {};
|
|
1734
1736
|
const proxy = new Proxy(cache, {
|
|
1735
1737
|
get(target, key) {
|
|
@@ -1757,6 +1759,12 @@ function rules(factory) {
|
|
|
1757
1759
|
cache[key] = parser2;
|
|
1758
1760
|
}
|
|
1759
1761
|
}
|
|
1762
|
+
if (options?.trivia !== void 0) {
|
|
1763
|
+
for (const key of Object.keys(definitions)) {
|
|
1764
|
+
const rule = cache[key];
|
|
1765
|
+
if (rule && !rule._meta.isTrivia) rule._meta.grammarTrivia = options.trivia;
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1760
1768
|
for (const key of Object.keys(definitions)) {
|
|
1761
1769
|
markUnusedValues(cache[key]);
|
|
1762
1770
|
}
|
|
@@ -5351,6 +5359,7 @@ function ruleDependencies(ruleMap) {
|
|
|
5351
5359
|
}
|
|
5352
5360
|
function compile(combinator, mapFnSources) {
|
|
5353
5361
|
markUnusedValues(combinator);
|
|
5362
|
+
const grammarTrivia = combinator._meta.grammarTrivia;
|
|
5354
5363
|
const ctx = {
|
|
5355
5364
|
vars: 0,
|
|
5356
5365
|
indent: 1,
|
|
@@ -5369,7 +5378,8 @@ function compile(combinator, mapFnSources) {
|
|
|
5369
5378
|
triviaFnNames: /* @__PURE__ */ new Map(),
|
|
5370
5379
|
namedFnDecls: [],
|
|
5371
5380
|
capturing: hasNodeDef(combinator),
|
|
5372
|
-
lazyUsage: analyzeLazyUsage(combinator)
|
|
5381
|
+
lazyUsage: analyzeLazyUsage(combinator),
|
|
5382
|
+
...grammarTrivia ? { activeTrivia: grammarTrivia, triviaKindLabels: grammarTrivia._meta.triviaKindLabels } : {}
|
|
5373
5383
|
};
|
|
5374
5384
|
const r = emit(combinator, ctx, "_pos");
|
|
5375
5385
|
const namedPrelude = ctx.namedFnDecls.length > 0 ? [...namedFnPrelude(), ""] : [];
|
|
@@ -5445,8 +5455,9 @@ function publicRuleWrapperSource(rule, fnSource) {
|
|
|
5445
5455
|
if (labels === void 0) return fnSource;
|
|
5446
5456
|
return `Object.assign(${fnSource}, { _meta: { triviaKindLabels: ${JSON.stringify(labels)} } })`;
|
|
5447
5457
|
}
|
|
5448
|
-
function compileRuleMap(ruleMap) {
|
|
5458
|
+
function compileRuleMap(ruleMap, opts) {
|
|
5449
5459
|
for (const [, rule] of ruleMap) markUnusedValues(rule);
|
|
5460
|
+
const grammarTrivia = opts?.trivia;
|
|
5450
5461
|
const ctx = {
|
|
5451
5462
|
vars: 0,
|
|
5452
5463
|
indent: 1,
|
|
@@ -5465,7 +5476,8 @@ function compileRuleMap(ruleMap) {
|
|
|
5465
5476
|
triviaFnNames: /* @__PURE__ */ new Map(),
|
|
5466
5477
|
namedFnDecls: [],
|
|
5467
5478
|
capturing: ruleMap.some(([, rule]) => hasNodeDef(rule)),
|
|
5468
|
-
lazyUsage: analyzeLazyUsageMulti(ruleMap.map(([, rule]) => rule))
|
|
5479
|
+
lazyUsage: analyzeLazyUsageMulti(ruleMap.map(([, rule]) => rule)),
|
|
5480
|
+
...grammarTrivia ? { activeTrivia: grammarTrivia, triviaKindLabels: grammarTrivia._meta.triviaKindLabels } : {}
|
|
5469
5481
|
};
|
|
5470
5482
|
const seenNames = /* @__PURE__ */ new Map();
|
|
5471
5483
|
const ruleNames = /* @__PURE__ */ new Map();
|
|
@@ -5477,7 +5489,13 @@ function compileRuleMap(ruleMap) {
|
|
|
5477
5489
|
ruleNames.set(rule, n === 0 ? base : `${base}$${n}`);
|
|
5478
5490
|
}
|
|
5479
5491
|
ctx.ruleNames = ruleNames;
|
|
5480
|
-
const perEntry = ruleMap.map(([key, rule]) =>
|
|
5492
|
+
const perEntry = ruleMap.map(([key, rule]) => {
|
|
5493
|
+
const savedTrivia = ctx.activeTrivia;
|
|
5494
|
+
if (rule._meta.isTrivia) ctx.activeTrivia = void 0;
|
|
5495
|
+
const r = emit(rule, ctx, "_pos");
|
|
5496
|
+
ctx.activeTrivia = savedTrivia;
|
|
5497
|
+
return { key, rule, r };
|
|
5498
|
+
});
|
|
5481
5499
|
const derivedSrcs = ctx.mapFnSrcs.length === ctx.mapFns.length && ctx.mapFnSrcs.every((s) => s !== null) ? ctx.mapFnSrcs : void 0;
|
|
5482
5500
|
const buildCovered = ctx.buildFns.length === 0 || ctx.buildSrcs.every((s) => s !== null);
|
|
5483
5501
|
const buildSources = ctx.buildFns.length === 0 ? void 0 : ctx.buildSrcs;
|
|
@@ -6856,7 +6874,10 @@ function transformMacro(code, id, moduleAliases = /* @__PURE__ */ new Set([PARSE
|
|
|
6856
6874
|
};
|
|
6857
6875
|
const compileRulesFactory = (init, label2) => {
|
|
6858
6876
|
const args = init.arguments;
|
|
6859
|
-
const
|
|
6877
|
+
const arg0 = args[0];
|
|
6878
|
+
const arg1 = args[1];
|
|
6879
|
+
const optionsFirst = arg0?.type === "ObjectExpression";
|
|
6880
|
+
const factoryArg = optionsFirst ? arg1 : arg0;
|
|
6860
6881
|
if (!factoryArg) {
|
|
6861
6882
|
warn(init.start, `${label2}: rules() needs a factory argument`);
|
|
6862
6883
|
return null;
|
|
@@ -6866,7 +6887,12 @@ function transformMacro(code, id, moduleAliases = /* @__PURE__ */ new Set([PARSE
|
|
|
6866
6887
|
warn(init.start, `${label2}: rules(...) factory isn't statically evaluable`);
|
|
6867
6888
|
return null;
|
|
6868
6889
|
}
|
|
6869
|
-
const
|
|
6890
|
+
const optionsArg = optionsFirst ? arg0 : arg1;
|
|
6891
|
+
const triviaValue = optionsArg?.type === "ObjectExpression" ? (optionsArg.properties ?? []).find(
|
|
6892
|
+
(p) => p.key?.name === "trivia"
|
|
6893
|
+
)?.value : void 0;
|
|
6894
|
+
const gTrivia = triviaValue ? evaluateExpr(triviaValue, scope, code, []) : void 0;
|
|
6895
|
+
const compiled = compileRuleMap([...ruleMap], gTrivia ? { trivia: gTrivia } : void 0);
|
|
6870
6896
|
if (!compiled) {
|
|
6871
6897
|
warn(init.start, `${label2}: rule map couldn't be inlined`);
|
|
6872
6898
|
return null;
|