parseman 0.60.3 → 0.60.5
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/analysis/commitment.d.ts.map +1 -1
- package/dist/analysis/diagnostics.js +1 -1
- package/dist/cli/index.js +420 -420
- package/dist/cli/index.js.map +3 -3
- package/dist/combinators/parser.d.ts +34 -3
- package/dist/combinators/parser.d.ts.map +1 -1
- package/dist/compiler/compile-linkable-table.d.ts.map +1 -1
- package/dist/compiler/ir-serialize.d.ts +3 -1
- package/dist/compiler/ir-serialize.d.ts.map +1 -1
- package/dist/compiler/linker.d.ts +21 -3
- package/dist/compiler/linker.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +90 -35
- package/dist/index.js.map +1 -1
- package/dist/plugin/evaluator.d.ts +11 -1
- package/dist/plugin/evaluator.d.ts.map +1 -1
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +162 -73
- package/dist/plugin/index.js.map +2 -2
- package/dist/spec/index.js +3 -1
- package/dist/spec/index.js.map +1 -1
- package/dist/spec/model.d.ts.map +1 -1
- package/dist/table/index.js +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/analysis/commitment.ts +3 -1
- package/src/combinators/parser.ts +82 -9
- package/src/compiler/compile-linkable-table.ts +4 -1
- package/src/compiler/ir-serialize.ts +24 -7
- package/src/compiler/linker.ts +50 -24
- package/src/index.ts +1 -0
- package/src/plugin/evaluator.ts +27 -5
- package/src/plugin/index.ts +41 -100
- package/src/spec/model.ts +3 -1
- package/src/version.ts +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -4167,6 +4167,336 @@ function scalarRootOf(combinator) {
|
|
|
4167
4167
|
return scalar !== void 0 && def.tag === "grammar" && scalarTree(def.parser, /* @__PURE__ */ new Set()) ? scalar : void 0;
|
|
4168
4168
|
}
|
|
4169
4169
|
|
|
4170
|
+
// src/combinators/ref.ts
|
|
4171
|
+
function withRuleTrivia(trivia2, ctx, run) {
|
|
4172
|
+
const savedLabels = ctx.triviaKindLabels;
|
|
4173
|
+
ctx.trivia = trivia2;
|
|
4174
|
+
ctx.triviaKindLabels = trivia2._meta.triviaKindLabels;
|
|
4175
|
+
try {
|
|
4176
|
+
return run();
|
|
4177
|
+
} finally {
|
|
4178
|
+
ctx.trivia = void 0;
|
|
4179
|
+
ctx.triviaKindLabels = savedLabels;
|
|
4180
|
+
}
|
|
4181
|
+
}
|
|
4182
|
+
var UNDEFINED_REF = new Error("ref<T>() used before .define() was called");
|
|
4183
|
+
function ref() {
|
|
4184
|
+
let resolved = null;
|
|
4185
|
+
let resolvedScalar = null;
|
|
4186
|
+
let ownBoundary = false;
|
|
4187
|
+
const meta = {
|
|
4188
|
+
firstSet: any(),
|
|
4189
|
+
canMatchNewline: true,
|
|
4190
|
+
isTrivia: false
|
|
4191
|
+
};
|
|
4192
|
+
const slot = {
|
|
4193
|
+
_tag: "lazy",
|
|
4194
|
+
_meta: meta,
|
|
4195
|
+
_def: {
|
|
4196
|
+
tag: "lazy",
|
|
4197
|
+
thunk: () => {
|
|
4198
|
+
if (!resolved) throw UNDEFINED_REF;
|
|
4199
|
+
return resolved;
|
|
4200
|
+
}
|
|
4201
|
+
},
|
|
4202
|
+
_parseScalar(input, pos, ctx) {
|
|
4203
|
+
const scalar = resolvedScalar;
|
|
4204
|
+
if (!scalar) throw new Error("ref<T>() used before .define() was called");
|
|
4205
|
+
const gt = meta.grammarTrivia;
|
|
4206
|
+
if (gt !== void 0 && ownBoundary && ctx.trivia === void 0) {
|
|
4207
|
+
return withRuleTrivia(gt, ctx, () => scalar(input, pos, ctx));
|
|
4208
|
+
}
|
|
4209
|
+
return scalar(input, pos, ctx);
|
|
4210
|
+
},
|
|
4211
|
+
parse(input, pos, ctx) {
|
|
4212
|
+
const parser2 = resolved;
|
|
4213
|
+
if (!parser2) throw new Error("ref<T>() used before .define() was called");
|
|
4214
|
+
const gt = meta.grammarTrivia;
|
|
4215
|
+
if (gt !== void 0 && ownBoundary && ctx.trivia === void 0) {
|
|
4216
|
+
return withRuleTrivia(gt, ctx, () => parser2.parse(input, pos, ctx));
|
|
4217
|
+
}
|
|
4218
|
+
return parser2.parse(input, pos, ctx);
|
|
4219
|
+
},
|
|
4220
|
+
define(p) {
|
|
4221
|
+
if (resolved) throw new Error("ref<T>() already defined");
|
|
4222
|
+
resolved = p;
|
|
4223
|
+
resolvedScalar = scalarOf(p);
|
|
4224
|
+
ownBoundary = hasOwnTriviaBoundary(p);
|
|
4225
|
+
meta.firstSet = p._meta.firstSet;
|
|
4226
|
+
meta.canMatchNewline = p._meta.canMatchNewline;
|
|
4227
|
+
meta.isTrivia = p._meta.isTrivia;
|
|
4228
|
+
if (p._meta.triviaKindLabels !== void 0) meta.triviaKindLabels = p._meta.triviaKindLabels;
|
|
4229
|
+
else delete meta.triviaKindLabels;
|
|
4230
|
+
if (p._meta.disjoint !== void 0) meta.disjoint = p._meta.disjoint;
|
|
4231
|
+
else delete meta.disjoint;
|
|
4232
|
+
}
|
|
4233
|
+
};
|
|
4234
|
+
return slot;
|
|
4235
|
+
}
|
|
4236
|
+
|
|
4237
|
+
// src/compiler/value-usage.ts
|
|
4238
|
+
function markUnusedValues(root) {
|
|
4239
|
+
const seenConsumed = /* @__PURE__ */ new WeakSet();
|
|
4240
|
+
const seenUnconsumed = /* @__PURE__ */ new WeakSet();
|
|
4241
|
+
const mark = (def, consumed) => {
|
|
4242
|
+
if (consumed) def.valueUnused = false;
|
|
4243
|
+
else if (def.valueUnused !== false) def.valueUnused = true;
|
|
4244
|
+
};
|
|
4245
|
+
const visit = (c, consumed) => {
|
|
4246
|
+
const seen = consumed ? seenConsumed : seenUnconsumed;
|
|
4247
|
+
if (seen.has(c)) return;
|
|
4248
|
+
seen.add(c);
|
|
4249
|
+
const def = c._def;
|
|
4250
|
+
switch (def.tag) {
|
|
4251
|
+
case "many":
|
|
4252
|
+
case "oneOrMore":
|
|
4253
|
+
mark(def, consumed);
|
|
4254
|
+
visit(def.parser, consumed);
|
|
4255
|
+
return;
|
|
4256
|
+
case "optional":
|
|
4257
|
+
visit(def.parser, consumed);
|
|
4258
|
+
return;
|
|
4259
|
+
case "sequence":
|
|
4260
|
+
mark(def, consumed);
|
|
4261
|
+
for (const p of def.parsers) visit(p, consumed);
|
|
4262
|
+
return;
|
|
4263
|
+
case "choice":
|
|
4264
|
+
for (const p of def.parsers) visit(p, consumed);
|
|
4265
|
+
return;
|
|
4266
|
+
case "dispatch":
|
|
4267
|
+
visit(def.selector, consumed);
|
|
4268
|
+
for (const entry of def.cases) visit(entry.parser, consumed);
|
|
4269
|
+
if (def.matchers) for (const entry of def.matchers) visit(entry.parser, consumed);
|
|
4270
|
+
if (def.otherwise) visit(def.otherwise, consumed);
|
|
4271
|
+
return;
|
|
4272
|
+
case "node":
|
|
4273
|
+
visit(def.parser, false);
|
|
4274
|
+
return;
|
|
4275
|
+
case "transform":
|
|
4276
|
+
visit(def.parser, true);
|
|
4277
|
+
return;
|
|
4278
|
+
case "field":
|
|
4279
|
+
visit(def.parser, true);
|
|
4280
|
+
return;
|
|
4281
|
+
case "sepBy":
|
|
4282
|
+
visit(def.parser, true);
|
|
4283
|
+
visit(def.separator, false);
|
|
4284
|
+
return;
|
|
4285
|
+
case "not":
|
|
4286
|
+
case "peek":
|
|
4287
|
+
visit(def.parser, false);
|
|
4288
|
+
return;
|
|
4289
|
+
case "grammar":
|
|
4290
|
+
visit(def.parser, consumed);
|
|
4291
|
+
if (def.triviaParser) visit(def.triviaParser, false);
|
|
4292
|
+
return;
|
|
4293
|
+
case "recover":
|
|
4294
|
+
visit(def.parser, consumed);
|
|
4295
|
+
visit(def.sentinel, false);
|
|
4296
|
+
return;
|
|
4297
|
+
case "token":
|
|
4298
|
+
visit(def.parser, false);
|
|
4299
|
+
return;
|
|
4300
|
+
case "label":
|
|
4301
|
+
case "trivia":
|
|
4302
|
+
case "attempt":
|
|
4303
|
+
case "withCtx":
|
|
4304
|
+
case "expect":
|
|
4305
|
+
visit(def.parser, consumed);
|
|
4306
|
+
return;
|
|
4307
|
+
case "leaf":
|
|
4308
|
+
visit(def.parser, true);
|
|
4309
|
+
return;
|
|
4310
|
+
case "lazy":
|
|
4311
|
+
return;
|
|
4312
|
+
default:
|
|
4313
|
+
return;
|
|
4314
|
+
}
|
|
4315
|
+
};
|
|
4316
|
+
const resolveRoot = (c) => {
|
|
4317
|
+
const guard = /* @__PURE__ */ new Set();
|
|
4318
|
+
let cur = c;
|
|
4319
|
+
while (!guard.has(cur)) {
|
|
4320
|
+
const d = cur._def;
|
|
4321
|
+
if (d.tag === "grammar") {
|
|
4322
|
+
guard.add(cur);
|
|
4323
|
+
cur = d.parser;
|
|
4324
|
+
continue;
|
|
4325
|
+
}
|
|
4326
|
+
if (d.tag !== "lazy") return cur;
|
|
4327
|
+
guard.add(cur);
|
|
4328
|
+
try {
|
|
4329
|
+
cur = d.thunk();
|
|
4330
|
+
} catch {
|
|
4331
|
+
return c;
|
|
4332
|
+
}
|
|
4333
|
+
}
|
|
4334
|
+
return cur;
|
|
4335
|
+
};
|
|
4336
|
+
visit(resolveRoot(root), true);
|
|
4337
|
+
}
|
|
4338
|
+
|
|
4339
|
+
// src/cst/root-trivia-scope.ts
|
|
4340
|
+
var ROOT_TRIVIA_SCOPE_REFUSAL = "parser(): selected root trivia requires classifiedTrivia() for every local trivia scope, or rootCapture: 'opaque'.";
|
|
4341
|
+
function refuseUnclassifiedRootScope(strict) {
|
|
4342
|
+
if (strict === true) throw new TypeError(ROOT_TRIVIA_SCOPE_REFUSAL);
|
|
4343
|
+
}
|
|
4344
|
+
|
|
4345
|
+
// src/combinators/grammar.ts
|
|
4346
|
+
function annotateResultLines(result, index) {
|
|
4347
|
+
const annotated = { ...result, span: annotateSpan(result.span, index) };
|
|
4348
|
+
const errors = annotated.errors;
|
|
4349
|
+
if (errors) {
|
|
4350
|
+
;
|
|
4351
|
+
annotated.errors = errors.map((error) => ({
|
|
4352
|
+
...error,
|
|
4353
|
+
span: annotateSpan(error.span, index)
|
|
4354
|
+
}));
|
|
4355
|
+
}
|
|
4356
|
+
return annotated;
|
|
4357
|
+
}
|
|
4358
|
+
function createParseLineContext(input, pos) {
|
|
4359
|
+
const lineIndex = createLineIndex();
|
|
4360
|
+
if (pos > 0) recordLineRange(lineIndex, input, 0, pos);
|
|
4361
|
+
return { lineIndex, lineScannedTo: pos };
|
|
4362
|
+
}
|
|
4363
|
+
var TRACK_LINES_ON = () => true;
|
|
4364
|
+
var TRACK_LINES_OFF = () => false;
|
|
4365
|
+
var TRACK_LINES_INHERIT = (ctx) => ctx?.trackLines === true;
|
|
4366
|
+
function parser(opts, root) {
|
|
4367
|
+
const clearTrivia = opts.trivia === null;
|
|
4368
|
+
const opaqueRootCapture = opts.rootCapture === "opaque";
|
|
4369
|
+
if (opaqueRootCapture && opts.trivia === void 0) {
|
|
4370
|
+
throw new TypeError("parser({ rootCapture: 'opaque' }) requires an explicit trivia scope.");
|
|
4371
|
+
}
|
|
4372
|
+
const scopeTrivia = clearTrivia ? void 0 : opts.trivia ?? void 0;
|
|
4373
|
+
const scopeLabels = scopeTrivia?._meta?.triviaKindLabels;
|
|
4374
|
+
const refuseUnclassified = scopeTrivia !== void 0 && !scopeTrivia._meta?.rootTriviaClassified && !opaqueRootCapture;
|
|
4375
|
+
const forceCaptureTrivia = opts.captureTrivia === true;
|
|
4376
|
+
const trackLinesPolicy = opts.trackLines === true ? "on" : opts.trackLines === false ? "off" : "inherit";
|
|
4377
|
+
const trackLinesOf = trackLinesPolicy === "on" ? TRACK_LINES_ON : trackLinesPolicy === "off" ? TRACK_LINES_OFF : TRACK_LINES_INHERIT;
|
|
4378
|
+
const captureKinds = clearTrivia ? void 0 : opts.captureTriviaKinds;
|
|
4379
|
+
const ownCaptureMask = captureKinds === void 0 ? void 0 : scopeLabels !== void 0 ? triviaKindMask(scopeLabels, captureKinds) : void 0;
|
|
4380
|
+
const inheritCaptureMask = captureKinds !== void 0 && scopeLabels === void 0;
|
|
4381
|
+
const rootScalar = scalarOf(root);
|
|
4382
|
+
const scalarEligible = opts.trackLines !== true && opts.recover !== true && !opaqueRootCapture && !forceCaptureTrivia && captureKinds === void 0;
|
|
4383
|
+
const parseScalar = scalarEligible ? (input, pos, ctx) => {
|
|
4384
|
+
const savedTrivia = ctx.trivia;
|
|
4385
|
+
const savedLabels = ctx.triviaKindLabels;
|
|
4386
|
+
if (clearTrivia) {
|
|
4387
|
+
ctx.trivia = void 0;
|
|
4388
|
+
ctx.triviaKindLabels = void 0;
|
|
4389
|
+
} else if (scopeTrivia !== void 0) {
|
|
4390
|
+
ctx.trivia = scopeTrivia;
|
|
4391
|
+
ctx.triviaKindLabels = scopeLabels;
|
|
4392
|
+
}
|
|
4393
|
+
const end = rootScalar(input, pos, ctx);
|
|
4394
|
+
ctx.trivia = savedTrivia;
|
|
4395
|
+
ctx.triviaKindLabels = savedLabels;
|
|
4396
|
+
return end;
|
|
4397
|
+
} : void 0;
|
|
4398
|
+
let publicScalar;
|
|
4399
|
+
const grammar = {
|
|
4400
|
+
_tag: "grammar",
|
|
4401
|
+
_meta: {
|
|
4402
|
+
...root._meta,
|
|
4403
|
+
// Trivia classification describes this grammar's own active trivia
|
|
4404
|
+
// scope. A directly nested grammar may have classified trivia of its
|
|
4405
|
+
// own, but that must not advertise classification for this wrapper.
|
|
4406
|
+
triviaKindLabels: void 0,
|
|
4407
|
+
rootTriviaClassified: void 0,
|
|
4408
|
+
...opts.trivia?._meta?.triviaKindLabels ? { triviaKindLabels: opts.trivia._meta.triviaKindLabels } : {},
|
|
4409
|
+
...opts.trivia?._meta?.rootTriviaClassified ? { rootTriviaClassified: true } : {}
|
|
4410
|
+
},
|
|
4411
|
+
_def: {
|
|
4412
|
+
tag: "grammar",
|
|
4413
|
+
parser: root,
|
|
4414
|
+
triviaParser: scopeTrivia,
|
|
4415
|
+
clearTrivia,
|
|
4416
|
+
...opaqueRootCapture ? { rootCapture: "opaque" } : {},
|
|
4417
|
+
...opts.captureTrivia ? { captureTrivia: true } : {},
|
|
4418
|
+
trackLines: opts.trackLines ?? false,
|
|
4419
|
+
constructionTrackLines: trackLinesPolicy,
|
|
4420
|
+
...captureKinds === void 0 ? {} : { constructionCaptureTriviaKinds: captureKinds }
|
|
4421
|
+
},
|
|
4422
|
+
_parseScalar: parseScalar,
|
|
4423
|
+
parse(input, pos, _ctx) {
|
|
4424
|
+
if (pos === void 0 && _ctx === void 0) {
|
|
4425
|
+
publicScalar ??= scalarRootOf(grammar) ?? null;
|
|
4426
|
+
if (publicScalar) {
|
|
4427
|
+
const ctx2 = createParseContext();
|
|
4428
|
+
const end = publicScalar(input, 0, ctx2);
|
|
4429
|
+
if (end < 0) {
|
|
4430
|
+
const at = ~end;
|
|
4431
|
+
return { ok: false, expected: ctx2._fx ?? [], span: { start: at, end: at } };
|
|
4432
|
+
}
|
|
4433
|
+
return { ok: true, value: ctx2._sv, span: { start: 0, end } };
|
|
4434
|
+
}
|
|
4435
|
+
}
|
|
4436
|
+
if (refuseUnclassified) refuseUnclassifiedRootScope(_ctx?._rootTriviaStrictScopes);
|
|
4437
|
+
const trackLines = trackLinesOf(_ctx);
|
|
4438
|
+
const lineContext = trackLines && _ctx?._lineIndex === void 0 && _ctx?._lineStarts === void 0 ? createParseLineContext(input, pos ?? 0) : void 0;
|
|
4439
|
+
const lineIndex = trackLines ? _ctx?._lineIndex ?? (_ctx?._lineStarts ? { lineStarts: _ctx._lineStarts } : lineContext.lineIndex) : void 0;
|
|
4440
|
+
const ctx = _ctx === void 0 ? createParseContext() : { ..._ctx };
|
|
4441
|
+
ctx.trackLines = trackLines;
|
|
4442
|
+
if (lineIndex) ctx._lineIndex = lineIndex;
|
|
4443
|
+
if (lineContext) ctx._lineScannedTo = lineContext.lineScannedTo;
|
|
4444
|
+
if (clearTrivia) {
|
|
4445
|
+
ctx.trivia = void 0;
|
|
4446
|
+
ctx.triviaKindLabels = void 0;
|
|
4447
|
+
} else if (scopeTrivia !== void 0) {
|
|
4448
|
+
ctx.trivia = scopeTrivia;
|
|
4449
|
+
if (scopeLabels) ctx.triviaKindLabels = scopeLabels;
|
|
4450
|
+
}
|
|
4451
|
+
if (forceCaptureTrivia || _ctx?.captureTrivia) ctx.captureTrivia = true;
|
|
4452
|
+
if (ownCaptureMask !== void 0) ctx._triviaCaptureMask = ownCaptureMask;
|
|
4453
|
+
else if (inheritCaptureMask) ctx._triviaCaptureMask = triviaKindMask(_ctx?.triviaKindLabels, captureKinds);
|
|
4454
|
+
if (opaqueRootCapture) ctx._rootTriviaCapture = false;
|
|
4455
|
+
const result = root.parse(input, pos ?? 0, ctx);
|
|
4456
|
+
if (trackLines && _ctx && ctx._lineScannedTo !== void 0) {
|
|
4457
|
+
_ctx._lineScannedTo = Math.max(_ctx._lineScannedTo ?? 0, ctx._lineScannedTo);
|
|
4458
|
+
}
|
|
4459
|
+
return lineIndex ? annotateResultLines(result, normalizeLineIndex(lineIndex)) : result;
|
|
4460
|
+
}
|
|
4461
|
+
};
|
|
4462
|
+
return grammar;
|
|
4463
|
+
}
|
|
4464
|
+
function noTrivia(root) {
|
|
4465
|
+
return parser({ trivia: null }, root);
|
|
4466
|
+
}
|
|
4467
|
+
var _analyzed = /* @__PURE__ */ new WeakSet();
|
|
4468
|
+
function parse(combinator, input, opts = {}) {
|
|
4469
|
+
if (!_analyzed.has(combinator)) {
|
|
4470
|
+
_analyzed.add(combinator);
|
|
4471
|
+
markUnusedValues(combinator);
|
|
4472
|
+
}
|
|
4473
|
+
if (!opts.trackLines && !opts.recover && combinator._def.tag === "grammar" && combinator._meta.grammarScanSkip === void 0) {
|
|
4474
|
+
return combinator.parse(input);
|
|
4475
|
+
}
|
|
4476
|
+
const trackLines = opts.trackLines ?? combinator._meta.grammarTrackLines ?? false;
|
|
4477
|
+
const lineContext = trackLines ? createParseLineContext(input, 0) : void 0;
|
|
4478
|
+
const lineIndex = lineContext?.lineIndex;
|
|
4479
|
+
const _errors = opts.recover ? [] : void 0;
|
|
4480
|
+
const _probe = opts.recover ? { offset: input.length, best: null } : void 0;
|
|
4481
|
+
const grammarTrivia = combinator._meta.grammarTrivia;
|
|
4482
|
+
const grammarScanSkip = combinator._meta.grammarScanSkip;
|
|
4483
|
+
const ctx = createParseContext();
|
|
4484
|
+
ctx.trackLines = trackLines;
|
|
4485
|
+
if (lineIndex) ctx._lineIndex = lineIndex;
|
|
4486
|
+
if (lineContext) ctx._lineScannedTo = lineContext.lineScannedTo;
|
|
4487
|
+
if (grammarTrivia !== void 0) {
|
|
4488
|
+
ctx.trivia = grammarTrivia;
|
|
4489
|
+
if (grammarTrivia._meta.triviaKindLabels) ctx.triviaKindLabels = grammarTrivia._meta.triviaKindLabels;
|
|
4490
|
+
}
|
|
4491
|
+
if (grammarScanSkip !== void 0) ctx.scanSkip = grammarScanSkip;
|
|
4492
|
+
if (_errors !== void 0) ctx._errors = _errors;
|
|
4493
|
+
if (_probe !== void 0) ctx._probe = _probe;
|
|
4494
|
+
const result = combinator.parse(input, 0, ctx);
|
|
4495
|
+
if (!result.ok) return lineIndex ? annotateResultLines(result, normalizeLineIndex(lineIndex)) : result;
|
|
4496
|
+
const withErrors = _errors !== void 0 ? { ...result, errors: _errors, furthestFail: _probe?.best ?? null } : result;
|
|
4497
|
+
return lineIndex ? annotateResultLines(withErrors, normalizeLineIndex(lineIndex)) : withErrors;
|
|
4498
|
+
}
|
|
4499
|
+
|
|
4170
4500
|
// src/combinators/choice.ts
|
|
4171
4501
|
function choice(...args) {
|
|
4172
4502
|
const parsers = args.map((a) => "gate" in a ? a.combinator : a);
|
|
@@ -6464,369 +6794,106 @@ function token(root) {
|
|
|
6464
6794
|
firstSet: root._meta.firstSet,
|
|
6465
6795
|
canMatchNewline: root._meta.canMatchNewline,
|
|
6466
6796
|
isTrivia: false
|
|
6467
|
-
};
|
|
6468
|
-
return {
|
|
6469
|
-
_tag: "token",
|
|
6470
|
-
_meta: meta,
|
|
6471
|
-
_def: { tag: "token", parser: root },
|
|
6472
|
-
parse(input, pos, ctx) {
|
|
6473
|
-
const savedTrivia = ctx.trivia;
|
|
6474
|
-
const savedKinds = ctx.triviaKindLabels;
|
|
6475
|
-
const savedBuf = ctx._cstBuf;
|
|
6476
|
-
const savedChildren = ctx._cstChildren;
|
|
6477
|
-
const savedLeaves = ctx._cstLeaves;
|
|
6478
|
-
const savedRaw = ctx._cstRawChildren;
|
|
6479
|
-
const savedTriviaLog = ctx._cstTriviaLog;
|
|
6480
|
-
const savedOuterTriviaLog = ctx._triviaLog;
|
|
6481
|
-
const savedRootTriviaLog = ctx._rootTriviaLog;
|
|
6482
|
-
const wasCapturing = cstCaptureActive(ctx);
|
|
6483
|
-
ctx.trivia = void 0;
|
|
6484
|
-
ctx.triviaKindLabels = void 0;
|
|
6485
|
-
ctx._cstBuf = void 0;
|
|
6486
|
-
ctx._cstChildren = void 0;
|
|
6487
|
-
ctx._cstLeaves = void 0;
|
|
6488
|
-
ctx._cstRawChildren = void 0;
|
|
6489
|
-
ctx._cstTriviaLog = void 0;
|
|
6490
|
-
ctx._triviaLog = void 0;
|
|
6491
|
-
ctx._rootTriviaLog = void 0;
|
|
6492
|
-
let result;
|
|
6493
|
-
try {
|
|
6494
|
-
result = root.parse(input, pos, ctx);
|
|
6495
|
-
} finally {
|
|
6496
|
-
ctx.trivia = savedTrivia;
|
|
6497
|
-
ctx.triviaKindLabels = savedKinds;
|
|
6498
|
-
ctx._cstBuf = savedBuf;
|
|
6499
|
-
ctx._cstChildren = savedChildren;
|
|
6500
|
-
ctx._cstLeaves = savedLeaves;
|
|
6501
|
-
ctx._cstRawChildren = savedRaw;
|
|
6502
|
-
ctx._cstTriviaLog = savedTriviaLog;
|
|
6503
|
-
ctx._triviaLog = savedOuterTriviaLog;
|
|
6504
|
-
ctx._rootTriviaLog = savedRootTriviaLog;
|
|
6505
|
-
}
|
|
6506
|
-
if (!result.ok) return result;
|
|
6507
|
-
const span = result.span;
|
|
6508
|
-
const value = input.slice(pos, span.end);
|
|
6509
|
-
if (wasCapturing) pushCstLeaf(ctx, new PlainLeaf6(value, span));
|
|
6510
|
-
return { ok: true, value, span };
|
|
6511
|
-
}
|
|
6512
|
-
};
|
|
6513
|
-
}
|
|
6514
|
-
function makeLeaf(root, fn, sourceCstValue) {
|
|
6515
|
-
const cstValue = sourceCstValue ? sourceLeafValue : semanticLeafValue;
|
|
6516
|
-
const meta = {
|
|
6517
|
-
firstSet: root._meta.firstSet,
|
|
6518
|
-
canMatchNewline: root._meta.canMatchNewline,
|
|
6519
|
-
isTrivia: false
|
|
6520
|
-
};
|
|
6521
|
-
return {
|
|
6522
|
-
_tag: "leaf",
|
|
6523
|
-
_meta: meta,
|
|
6524
|
-
_def: {
|
|
6525
|
-
tag: "leaf",
|
|
6526
|
-
parser: root,
|
|
6527
|
-
fn,
|
|
6528
|
-
...sourceCstValue ? { cstValue: "source" } : {}
|
|
6529
|
-
},
|
|
6530
|
-
parse(input, pos, ctx) {
|
|
6531
|
-
const savedBuf = ctx._cstBuf;
|
|
6532
|
-
const savedChildren = ctx._cstChildren;
|
|
6533
|
-
const savedLeaves = ctx._cstLeaves;
|
|
6534
|
-
const savedRaw = ctx._cstRawChildren;
|
|
6535
|
-
const savedTriviaLog = ctx._cstTriviaLog;
|
|
6536
|
-
const savedOuterTriviaLog = ctx._triviaLog;
|
|
6537
|
-
const wasCapturing = cstCaptureActive(ctx);
|
|
6538
|
-
ctx._cstBuf = void 0;
|
|
6539
|
-
ctx._cstChildren = void 0;
|
|
6540
|
-
ctx._cstLeaves = void 0;
|
|
6541
|
-
ctx._cstRawChildren = void 0;
|
|
6542
|
-
ctx._cstTriviaLog = void 0;
|
|
6543
|
-
ctx._triviaLog = void 0;
|
|
6544
|
-
let result;
|
|
6545
|
-
try {
|
|
6546
|
-
result = root.parse(input, pos, ctx);
|
|
6547
|
-
} finally {
|
|
6548
|
-
ctx._cstBuf = savedBuf;
|
|
6549
|
-
ctx._cstChildren = savedChildren;
|
|
6550
|
-
ctx._cstLeaves = savedLeaves;
|
|
6551
|
-
ctx._cstRawChildren = savedRaw;
|
|
6552
|
-
ctx._cstTriviaLog = savedTriviaLog;
|
|
6553
|
-
ctx._triviaLog = savedOuterTriviaLog;
|
|
6554
|
-
}
|
|
6555
|
-
if (!result.ok) return result;
|
|
6556
|
-
const value = fn(result.value, result.span);
|
|
6557
|
-
if (wasCapturing) pushCstLeaf(ctx, new PlainLeaf6(cstValue(ctx, input, pos, result.span.end, value), result.span));
|
|
6558
|
-
return { ok: true, value, span: result.span };
|
|
6559
|
-
}
|
|
6560
|
-
};
|
|
6561
|
-
}
|
|
6562
|
-
function leaf(root, fn) {
|
|
6563
|
-
return makeLeaf(root, fn, false);
|
|
6564
|
-
}
|
|
6565
|
-
function sourceLeaf(root, fn) {
|
|
6566
|
-
return makeLeaf(root, fn, true);
|
|
6567
|
-
}
|
|
6568
|
-
|
|
6569
|
-
// src/compiler/value-usage.ts
|
|
6570
|
-
function markUnusedValues(root) {
|
|
6571
|
-
const seenConsumed = /* @__PURE__ */ new WeakSet();
|
|
6572
|
-
const seenUnconsumed = /* @__PURE__ */ new WeakSet();
|
|
6573
|
-
const mark = (def, consumed) => {
|
|
6574
|
-
if (consumed) def.valueUnused = false;
|
|
6575
|
-
else if (def.valueUnused !== false) def.valueUnused = true;
|
|
6576
|
-
};
|
|
6577
|
-
const visit = (c, consumed) => {
|
|
6578
|
-
const seen = consumed ? seenConsumed : seenUnconsumed;
|
|
6579
|
-
if (seen.has(c)) return;
|
|
6580
|
-
seen.add(c);
|
|
6581
|
-
const def = c._def;
|
|
6582
|
-
switch (def.tag) {
|
|
6583
|
-
case "many":
|
|
6584
|
-
case "oneOrMore":
|
|
6585
|
-
mark(def, consumed);
|
|
6586
|
-
visit(def.parser, consumed);
|
|
6587
|
-
return;
|
|
6588
|
-
case "optional":
|
|
6589
|
-
visit(def.parser, consumed);
|
|
6590
|
-
return;
|
|
6591
|
-
case "sequence":
|
|
6592
|
-
mark(def, consumed);
|
|
6593
|
-
for (const p of def.parsers) visit(p, consumed);
|
|
6594
|
-
return;
|
|
6595
|
-
case "choice":
|
|
6596
|
-
for (const p of def.parsers) visit(p, consumed);
|
|
6597
|
-
return;
|
|
6598
|
-
case "dispatch":
|
|
6599
|
-
visit(def.selector, consumed);
|
|
6600
|
-
for (const entry of def.cases) visit(entry.parser, consumed);
|
|
6601
|
-
if (def.matchers) for (const entry of def.matchers) visit(entry.parser, consumed);
|
|
6602
|
-
if (def.otherwise) visit(def.otherwise, consumed);
|
|
6603
|
-
return;
|
|
6604
|
-
case "node":
|
|
6605
|
-
visit(def.parser, false);
|
|
6606
|
-
return;
|
|
6607
|
-
case "transform":
|
|
6608
|
-
visit(def.parser, true);
|
|
6609
|
-
return;
|
|
6610
|
-
case "field":
|
|
6611
|
-
visit(def.parser, true);
|
|
6612
|
-
return;
|
|
6613
|
-
case "sepBy":
|
|
6614
|
-
visit(def.parser, true);
|
|
6615
|
-
visit(def.separator, false);
|
|
6616
|
-
return;
|
|
6617
|
-
case "not":
|
|
6618
|
-
case "peek":
|
|
6619
|
-
visit(def.parser, false);
|
|
6620
|
-
return;
|
|
6621
|
-
case "grammar":
|
|
6622
|
-
visit(def.parser, consumed);
|
|
6623
|
-
if (def.triviaParser) visit(def.triviaParser, false);
|
|
6624
|
-
return;
|
|
6625
|
-
case "recover":
|
|
6626
|
-
visit(def.parser, consumed);
|
|
6627
|
-
visit(def.sentinel, false);
|
|
6628
|
-
return;
|
|
6629
|
-
case "token":
|
|
6630
|
-
visit(def.parser, false);
|
|
6631
|
-
return;
|
|
6632
|
-
case "label":
|
|
6633
|
-
case "trivia":
|
|
6634
|
-
case "attempt":
|
|
6635
|
-
case "withCtx":
|
|
6636
|
-
case "expect":
|
|
6637
|
-
visit(def.parser, consumed);
|
|
6638
|
-
return;
|
|
6639
|
-
case "leaf":
|
|
6640
|
-
visit(def.parser, true);
|
|
6641
|
-
return;
|
|
6642
|
-
case "lazy":
|
|
6643
|
-
return;
|
|
6644
|
-
default:
|
|
6645
|
-
return;
|
|
6646
|
-
}
|
|
6647
|
-
};
|
|
6648
|
-
const resolveRoot = (c) => {
|
|
6649
|
-
const guard = /* @__PURE__ */ new Set();
|
|
6650
|
-
let cur = c;
|
|
6651
|
-
while (!guard.has(cur)) {
|
|
6652
|
-
const d = cur._def;
|
|
6653
|
-
if (d.tag === "grammar") {
|
|
6654
|
-
guard.add(cur);
|
|
6655
|
-
cur = d.parser;
|
|
6656
|
-
continue;
|
|
6657
|
-
}
|
|
6658
|
-
if (d.tag !== "lazy") return cur;
|
|
6659
|
-
guard.add(cur);
|
|
6660
|
-
try {
|
|
6661
|
-
cur = d.thunk();
|
|
6662
|
-
} catch {
|
|
6663
|
-
return c;
|
|
6664
|
-
}
|
|
6665
|
-
}
|
|
6666
|
-
return cur;
|
|
6667
|
-
};
|
|
6668
|
-
visit(resolveRoot(root), true);
|
|
6669
|
-
}
|
|
6670
|
-
|
|
6671
|
-
// src/cst/root-trivia-scope.ts
|
|
6672
|
-
var ROOT_TRIVIA_SCOPE_REFUSAL = "parser(): selected root trivia requires classifiedTrivia() for every local trivia scope, or rootCapture: 'opaque'.";
|
|
6673
|
-
function refuseUnclassifiedRootScope(strict) {
|
|
6674
|
-
if (strict === true) throw new TypeError(ROOT_TRIVIA_SCOPE_REFUSAL);
|
|
6675
|
-
}
|
|
6676
|
-
|
|
6677
|
-
// src/combinators/grammar.ts
|
|
6678
|
-
function annotateResultLines(result, index) {
|
|
6679
|
-
const annotated = { ...result, span: annotateSpan(result.span, index) };
|
|
6680
|
-
const errors = annotated.errors;
|
|
6681
|
-
if (errors) {
|
|
6682
|
-
;
|
|
6683
|
-
annotated.errors = errors.map((error) => ({
|
|
6684
|
-
...error,
|
|
6685
|
-
span: annotateSpan(error.span, index)
|
|
6686
|
-
}));
|
|
6687
|
-
}
|
|
6688
|
-
return annotated;
|
|
6689
|
-
}
|
|
6690
|
-
function createParseLineContext(input, pos) {
|
|
6691
|
-
const lineIndex = createLineIndex();
|
|
6692
|
-
if (pos > 0) recordLineRange(lineIndex, input, 0, pos);
|
|
6693
|
-
return { lineIndex, lineScannedTo: pos };
|
|
6694
|
-
}
|
|
6695
|
-
var TRACK_LINES_ON = () => true;
|
|
6696
|
-
var TRACK_LINES_OFF = () => false;
|
|
6697
|
-
var TRACK_LINES_INHERIT = (ctx) => ctx?.trackLines === true;
|
|
6698
|
-
function parser(opts, root) {
|
|
6699
|
-
const clearTrivia = opts.trivia === null;
|
|
6700
|
-
const opaqueRootCapture = opts.rootCapture === "opaque";
|
|
6701
|
-
if (opaqueRootCapture && opts.trivia === void 0) {
|
|
6702
|
-
throw new TypeError("parser({ rootCapture: 'opaque' }) requires an explicit trivia scope.");
|
|
6703
|
-
}
|
|
6704
|
-
const scopeTrivia = clearTrivia ? void 0 : opts.trivia ?? void 0;
|
|
6705
|
-
const scopeLabels = scopeTrivia?._meta?.triviaKindLabels;
|
|
6706
|
-
const refuseUnclassified = scopeTrivia !== void 0 && !scopeTrivia._meta?.rootTriviaClassified && !opaqueRootCapture;
|
|
6707
|
-
const forceCaptureTrivia = opts.captureTrivia === true;
|
|
6708
|
-
const trackLinesPolicy = opts.trackLines === true ? "on" : opts.trackLines === false ? "off" : "inherit";
|
|
6709
|
-
const trackLinesOf = trackLinesPolicy === "on" ? TRACK_LINES_ON : trackLinesPolicy === "off" ? TRACK_LINES_OFF : TRACK_LINES_INHERIT;
|
|
6710
|
-
const captureKinds = clearTrivia ? void 0 : opts.captureTriviaKinds;
|
|
6711
|
-
const ownCaptureMask = captureKinds === void 0 ? void 0 : scopeLabels !== void 0 ? triviaKindMask(scopeLabels, captureKinds) : void 0;
|
|
6712
|
-
const inheritCaptureMask = captureKinds !== void 0 && scopeLabels === void 0;
|
|
6713
|
-
const rootScalar = scalarOf(root);
|
|
6714
|
-
const scalarEligible = opts.trackLines !== true && opts.recover !== true && !opaqueRootCapture && !forceCaptureTrivia && captureKinds === void 0;
|
|
6715
|
-
const parseScalar = scalarEligible ? (input, pos, ctx) => {
|
|
6716
|
-
const savedTrivia = ctx.trivia;
|
|
6717
|
-
const savedLabels = ctx.triviaKindLabels;
|
|
6718
|
-
if (clearTrivia) {
|
|
6797
|
+
};
|
|
6798
|
+
return {
|
|
6799
|
+
_tag: "token",
|
|
6800
|
+
_meta: meta,
|
|
6801
|
+
_def: { tag: "token", parser: root },
|
|
6802
|
+
parse(input, pos, ctx) {
|
|
6803
|
+
const savedTrivia = ctx.trivia;
|
|
6804
|
+
const savedKinds = ctx.triviaKindLabels;
|
|
6805
|
+
const savedBuf = ctx._cstBuf;
|
|
6806
|
+
const savedChildren = ctx._cstChildren;
|
|
6807
|
+
const savedLeaves = ctx._cstLeaves;
|
|
6808
|
+
const savedRaw = ctx._cstRawChildren;
|
|
6809
|
+
const savedTriviaLog = ctx._cstTriviaLog;
|
|
6810
|
+
const savedOuterTriviaLog = ctx._triviaLog;
|
|
6811
|
+
const savedRootTriviaLog = ctx._rootTriviaLog;
|
|
6812
|
+
const wasCapturing = cstCaptureActive(ctx);
|
|
6719
6813
|
ctx.trivia = void 0;
|
|
6720
6814
|
ctx.triviaKindLabels = void 0;
|
|
6721
|
-
|
|
6722
|
-
ctx.
|
|
6723
|
-
ctx.
|
|
6815
|
+
ctx._cstBuf = void 0;
|
|
6816
|
+
ctx._cstChildren = void 0;
|
|
6817
|
+
ctx._cstLeaves = void 0;
|
|
6818
|
+
ctx._cstRawChildren = void 0;
|
|
6819
|
+
ctx._cstTriviaLog = void 0;
|
|
6820
|
+
ctx._triviaLog = void 0;
|
|
6821
|
+
ctx._rootTriviaLog = void 0;
|
|
6822
|
+
let result;
|
|
6823
|
+
try {
|
|
6824
|
+
result = root.parse(input, pos, ctx);
|
|
6825
|
+
} finally {
|
|
6826
|
+
ctx.trivia = savedTrivia;
|
|
6827
|
+
ctx.triviaKindLabels = savedKinds;
|
|
6828
|
+
ctx._cstBuf = savedBuf;
|
|
6829
|
+
ctx._cstChildren = savedChildren;
|
|
6830
|
+
ctx._cstLeaves = savedLeaves;
|
|
6831
|
+
ctx._cstRawChildren = savedRaw;
|
|
6832
|
+
ctx._cstTriviaLog = savedTriviaLog;
|
|
6833
|
+
ctx._triviaLog = savedOuterTriviaLog;
|
|
6834
|
+
ctx._rootTriviaLog = savedRootTriviaLog;
|
|
6835
|
+
}
|
|
6836
|
+
if (!result.ok) return result;
|
|
6837
|
+
const span = result.span;
|
|
6838
|
+
const value = input.slice(pos, span.end);
|
|
6839
|
+
if (wasCapturing) pushCstLeaf(ctx, new PlainLeaf6(value, span));
|
|
6840
|
+
return { ok: true, value, span };
|
|
6724
6841
|
}
|
|
6725
|
-
|
|
6726
|
-
|
|
6727
|
-
|
|
6728
|
-
|
|
6729
|
-
|
|
6730
|
-
|
|
6731
|
-
|
|
6732
|
-
|
|
6733
|
-
|
|
6734
|
-
|
|
6735
|
-
|
|
6736
|
-
|
|
6737
|
-
// own, but that must not advertise classification for this wrapper.
|
|
6738
|
-
triviaKindLabels: void 0,
|
|
6739
|
-
rootTriviaClassified: void 0,
|
|
6740
|
-
...opts.trivia?._meta?.triviaKindLabels ? { triviaKindLabels: opts.trivia._meta.triviaKindLabels } : {},
|
|
6741
|
-
...opts.trivia?._meta?.rootTriviaClassified ? { rootTriviaClassified: true } : {}
|
|
6742
|
-
},
|
|
6842
|
+
};
|
|
6843
|
+
}
|
|
6844
|
+
function makeLeaf(root, fn, sourceCstValue) {
|
|
6845
|
+
const cstValue = sourceCstValue ? sourceLeafValue : semanticLeafValue;
|
|
6846
|
+
const meta = {
|
|
6847
|
+
firstSet: root._meta.firstSet,
|
|
6848
|
+
canMatchNewline: root._meta.canMatchNewline,
|
|
6849
|
+
isTrivia: false
|
|
6850
|
+
};
|
|
6851
|
+
return {
|
|
6852
|
+
_tag: "leaf",
|
|
6853
|
+
_meta: meta,
|
|
6743
6854
|
_def: {
|
|
6744
|
-
tag: "
|
|
6855
|
+
tag: "leaf",
|
|
6745
6856
|
parser: root,
|
|
6746
|
-
|
|
6747
|
-
|
|
6748
|
-
...opaqueRootCapture ? { rootCapture: "opaque" } : {},
|
|
6749
|
-
...opts.captureTrivia ? { captureTrivia: true } : {},
|
|
6750
|
-
trackLines: opts.trackLines ?? false,
|
|
6751
|
-
constructionTrackLines: trackLinesPolicy,
|
|
6752
|
-
...captureKinds === void 0 ? {} : { constructionCaptureTriviaKinds: captureKinds }
|
|
6857
|
+
fn,
|
|
6858
|
+
...sourceCstValue ? { cstValue: "source" } : {}
|
|
6753
6859
|
},
|
|
6754
|
-
|
|
6755
|
-
|
|
6756
|
-
|
|
6757
|
-
|
|
6758
|
-
|
|
6759
|
-
|
|
6760
|
-
|
|
6761
|
-
|
|
6762
|
-
|
|
6763
|
-
|
|
6764
|
-
|
|
6765
|
-
|
|
6766
|
-
|
|
6767
|
-
|
|
6768
|
-
|
|
6769
|
-
|
|
6770
|
-
|
|
6771
|
-
|
|
6772
|
-
|
|
6773
|
-
|
|
6774
|
-
|
|
6775
|
-
|
|
6776
|
-
|
|
6777
|
-
ctx.
|
|
6778
|
-
ctx.triviaKindLabels = void 0;
|
|
6779
|
-
} else if (scopeTrivia !== void 0) {
|
|
6780
|
-
ctx.trivia = scopeTrivia;
|
|
6781
|
-
if (scopeLabels) ctx.triviaKindLabels = scopeLabels;
|
|
6782
|
-
}
|
|
6783
|
-
if (forceCaptureTrivia || _ctx?.captureTrivia) ctx.captureTrivia = true;
|
|
6784
|
-
if (ownCaptureMask !== void 0) ctx._triviaCaptureMask = ownCaptureMask;
|
|
6785
|
-
else if (inheritCaptureMask) ctx._triviaCaptureMask = triviaKindMask(_ctx?.triviaKindLabels, captureKinds);
|
|
6786
|
-
if (opaqueRootCapture) ctx._rootTriviaCapture = false;
|
|
6787
|
-
const result = root.parse(input, pos ?? 0, ctx);
|
|
6788
|
-
if (trackLines && _ctx && ctx._lineScannedTo !== void 0) {
|
|
6789
|
-
_ctx._lineScannedTo = Math.max(_ctx._lineScannedTo ?? 0, ctx._lineScannedTo);
|
|
6860
|
+
parse(input, pos, ctx) {
|
|
6861
|
+
const savedBuf = ctx._cstBuf;
|
|
6862
|
+
const savedChildren = ctx._cstChildren;
|
|
6863
|
+
const savedLeaves = ctx._cstLeaves;
|
|
6864
|
+
const savedRaw = ctx._cstRawChildren;
|
|
6865
|
+
const savedTriviaLog = ctx._cstTriviaLog;
|
|
6866
|
+
const savedOuterTriviaLog = ctx._triviaLog;
|
|
6867
|
+
const wasCapturing = cstCaptureActive(ctx);
|
|
6868
|
+
ctx._cstBuf = void 0;
|
|
6869
|
+
ctx._cstChildren = void 0;
|
|
6870
|
+
ctx._cstLeaves = void 0;
|
|
6871
|
+
ctx._cstRawChildren = void 0;
|
|
6872
|
+
ctx._cstTriviaLog = void 0;
|
|
6873
|
+
ctx._triviaLog = void 0;
|
|
6874
|
+
let result;
|
|
6875
|
+
try {
|
|
6876
|
+
result = root.parse(input, pos, ctx);
|
|
6877
|
+
} finally {
|
|
6878
|
+
ctx._cstBuf = savedBuf;
|
|
6879
|
+
ctx._cstChildren = savedChildren;
|
|
6880
|
+
ctx._cstLeaves = savedLeaves;
|
|
6881
|
+
ctx._cstRawChildren = savedRaw;
|
|
6882
|
+
ctx._cstTriviaLog = savedTriviaLog;
|
|
6883
|
+
ctx._triviaLog = savedOuterTriviaLog;
|
|
6790
6884
|
}
|
|
6791
|
-
|
|
6885
|
+
if (!result.ok) return result;
|
|
6886
|
+
const value = fn(result.value, result.span);
|
|
6887
|
+
if (wasCapturing) pushCstLeaf(ctx, new PlainLeaf6(cstValue(ctx, input, pos, result.span.end, value), result.span));
|
|
6888
|
+
return { ok: true, value, span: result.span };
|
|
6792
6889
|
}
|
|
6793
6890
|
};
|
|
6794
|
-
return grammar;
|
|
6795
6891
|
}
|
|
6796
|
-
function
|
|
6797
|
-
return
|
|
6892
|
+
function leaf(root, fn) {
|
|
6893
|
+
return makeLeaf(root, fn, false);
|
|
6798
6894
|
}
|
|
6799
|
-
|
|
6800
|
-
|
|
6801
|
-
if (!_analyzed.has(combinator)) {
|
|
6802
|
-
_analyzed.add(combinator);
|
|
6803
|
-
markUnusedValues(combinator);
|
|
6804
|
-
}
|
|
6805
|
-
if (!opts.trackLines && !opts.recover && combinator._def.tag === "grammar" && combinator._meta.grammarScanSkip === void 0) {
|
|
6806
|
-
return combinator.parse(input);
|
|
6807
|
-
}
|
|
6808
|
-
const trackLines = opts.trackLines ?? combinator._meta.grammarTrackLines ?? false;
|
|
6809
|
-
const lineContext = trackLines ? createParseLineContext(input, 0) : void 0;
|
|
6810
|
-
const lineIndex = lineContext?.lineIndex;
|
|
6811
|
-
const _errors = opts.recover ? [] : void 0;
|
|
6812
|
-
const _probe = opts.recover ? { offset: input.length, best: null } : void 0;
|
|
6813
|
-
const grammarTrivia = combinator._meta.grammarTrivia;
|
|
6814
|
-
const grammarScanSkip = combinator._meta.grammarScanSkip;
|
|
6815
|
-
const ctx = createParseContext();
|
|
6816
|
-
ctx.trackLines = trackLines;
|
|
6817
|
-
if (lineIndex) ctx._lineIndex = lineIndex;
|
|
6818
|
-
if (lineContext) ctx._lineScannedTo = lineContext.lineScannedTo;
|
|
6819
|
-
if (grammarTrivia !== void 0) {
|
|
6820
|
-
ctx.trivia = grammarTrivia;
|
|
6821
|
-
if (grammarTrivia._meta.triviaKindLabels) ctx.triviaKindLabels = grammarTrivia._meta.triviaKindLabels;
|
|
6822
|
-
}
|
|
6823
|
-
if (grammarScanSkip !== void 0) ctx.scanSkip = grammarScanSkip;
|
|
6824
|
-
if (_errors !== void 0) ctx._errors = _errors;
|
|
6825
|
-
if (_probe !== void 0) ctx._probe = _probe;
|
|
6826
|
-
const result = combinator.parse(input, 0, ctx);
|
|
6827
|
-
if (!result.ok) return lineIndex ? annotateResultLines(result, normalizeLineIndex(lineIndex)) : result;
|
|
6828
|
-
const withErrors = _errors !== void 0 ? { ...result, errors: _errors, furthestFail: _probe?.best ?? null } : result;
|
|
6829
|
-
return lineIndex ? annotateResultLines(withErrors, normalizeLineIndex(lineIndex)) : withErrors;
|
|
6895
|
+
function sourceLeaf(root, fn) {
|
|
6896
|
+
return makeLeaf(root, fn, true);
|
|
6830
6897
|
}
|
|
6831
6898
|
|
|
6832
6899
|
// src/combinators/attempt.ts
|
|
@@ -13029,73 +13096,6 @@ function literal(value, opts = {}) {
|
|
|
13029
13096
|
};
|
|
13030
13097
|
}
|
|
13031
13098
|
|
|
13032
|
-
// src/combinators/ref.ts
|
|
13033
|
-
function withRuleTrivia(trivia2, ctx, run) {
|
|
13034
|
-
const savedLabels = ctx.triviaKindLabels;
|
|
13035
|
-
ctx.trivia = trivia2;
|
|
13036
|
-
ctx.triviaKindLabels = trivia2._meta.triviaKindLabels;
|
|
13037
|
-
try {
|
|
13038
|
-
return run();
|
|
13039
|
-
} finally {
|
|
13040
|
-
ctx.trivia = void 0;
|
|
13041
|
-
ctx.triviaKindLabels = savedLabels;
|
|
13042
|
-
}
|
|
13043
|
-
}
|
|
13044
|
-
var UNDEFINED_REF = new Error("ref<T>() used before .define() was called");
|
|
13045
|
-
function ref() {
|
|
13046
|
-
let resolved = null;
|
|
13047
|
-
let resolvedScalar = null;
|
|
13048
|
-
let ownBoundary = false;
|
|
13049
|
-
const meta = {
|
|
13050
|
-
firstSet: any(),
|
|
13051
|
-
canMatchNewline: true,
|
|
13052
|
-
isTrivia: false
|
|
13053
|
-
};
|
|
13054
|
-
const slot = {
|
|
13055
|
-
_tag: "lazy",
|
|
13056
|
-
_meta: meta,
|
|
13057
|
-
_def: {
|
|
13058
|
-
tag: "lazy",
|
|
13059
|
-
thunk: () => {
|
|
13060
|
-
if (!resolved) throw UNDEFINED_REF;
|
|
13061
|
-
return resolved;
|
|
13062
|
-
}
|
|
13063
|
-
},
|
|
13064
|
-
_parseScalar(input, pos, ctx) {
|
|
13065
|
-
const scalar = resolvedScalar;
|
|
13066
|
-
if (!scalar) throw new Error("ref<T>() used before .define() was called");
|
|
13067
|
-
const gt = meta.grammarTrivia;
|
|
13068
|
-
if (gt !== void 0 && ownBoundary && ctx.trivia === void 0) {
|
|
13069
|
-
return withRuleTrivia(gt, ctx, () => scalar(input, pos, ctx));
|
|
13070
|
-
}
|
|
13071
|
-
return scalar(input, pos, ctx);
|
|
13072
|
-
},
|
|
13073
|
-
parse(input, pos, ctx) {
|
|
13074
|
-
const parser2 = resolved;
|
|
13075
|
-
if (!parser2) throw new Error("ref<T>() used before .define() was called");
|
|
13076
|
-
const gt = meta.grammarTrivia;
|
|
13077
|
-
if (gt !== void 0 && ownBoundary && ctx.trivia === void 0) {
|
|
13078
|
-
return withRuleTrivia(gt, ctx, () => parser2.parse(input, pos, ctx));
|
|
13079
|
-
}
|
|
13080
|
-
return parser2.parse(input, pos, ctx);
|
|
13081
|
-
},
|
|
13082
|
-
define(p) {
|
|
13083
|
-
if (resolved) throw new Error("ref<T>() already defined");
|
|
13084
|
-
resolved = p;
|
|
13085
|
-
resolvedScalar = scalarOf(p);
|
|
13086
|
-
ownBoundary = hasOwnTriviaBoundary(p);
|
|
13087
|
-
meta.firstSet = p._meta.firstSet;
|
|
13088
|
-
meta.canMatchNewline = p._meta.canMatchNewline;
|
|
13089
|
-
meta.isTrivia = p._meta.isTrivia;
|
|
13090
|
-
if (p._meta.triviaKindLabels !== void 0) meta.triviaKindLabels = p._meta.triviaKindLabels;
|
|
13091
|
-
else delete meta.triviaKindLabels;
|
|
13092
|
-
if (p._meta.disjoint !== void 0) meta.disjoint = p._meta.disjoint;
|
|
13093
|
-
else delete meta.disjoint;
|
|
13094
|
-
}
|
|
13095
|
-
};
|
|
13096
|
-
return slot;
|
|
13097
|
-
}
|
|
13098
|
-
|
|
13099
13099
|
// src/combinators/scanTo.ts
|
|
13100
13100
|
import { PlainLeaf as PlainLeaf8, PlainSpan as PlainSpan9 } from "../cst/plain.js";
|
|
13101
13101
|
function resolveScanSkip(explicitSkip, raw, ctx) {
|
|
@@ -13415,7 +13415,7 @@ function clearOf(ranges, input, from, to) {
|
|
|
13415
13415
|
}
|
|
13416
13416
|
|
|
13417
13417
|
// src/version.ts
|
|
13418
|
-
var PARSEMAN_VERSION = "0.60.
|
|
13418
|
+
var PARSEMAN_VERSION = "0.60.5";
|
|
13419
13419
|
|
|
13420
13420
|
// src/table/assemble.ts
|
|
13421
13421
|
import { PlainBuf as PlainBuf2, PlainField, PlainLeaf as PlainLeaf9, PlainNode as PlainNode2, PlainSpan as PlainSpan10 } from "../cst/plain.js";
|