ohm-js 18.0.0-beta.7 → 18.0.0-beta.9
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/index.js +29 -42
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -120,7 +120,6 @@ const CstNodeType = {
|
|
|
120
120
|
SEQ: 4
|
|
121
121
|
};
|
|
122
122
|
const EMPTY_CHILDREN = Object.freeze([]);
|
|
123
|
-
const compileOptions = { builtins: ["js-string"] };
|
|
124
123
|
const UnicodeCategoryNames = [
|
|
125
124
|
"Cn",
|
|
126
125
|
"Lu",
|
|
@@ -211,30 +210,27 @@ var Grammar = class Grammar {
|
|
|
211
210
|
printI32(val) {
|
|
212
211
|
console.log(val);
|
|
213
212
|
},
|
|
214
|
-
isRuleSyntactic: (ruleId) => {
|
|
215
|
-
const name = this._ruleNames[ruleId];
|
|
216
|
-
assert(!!name);
|
|
217
|
-
return name[0] === name[0].toUpperCase();
|
|
218
|
-
},
|
|
219
213
|
fillInputBuffer: this._fillInputBuffer.bind(this),
|
|
220
214
|
matchUnicodeChar: (catBitmap) => {
|
|
221
|
-
const {
|
|
215
|
+
const { pos } = this._instance.exports;
|
|
222
216
|
const re = regexFromCategoryBitmap(catBitmap);
|
|
223
217
|
re.lastIndex = pos;
|
|
224
|
-
const arr = re.exec(
|
|
218
|
+
const arr = re.exec(this._input);
|
|
225
219
|
if (arr) pos.value += arr[0].length;
|
|
226
220
|
return !!arr;
|
|
227
|
-
}
|
|
228
|
-
},
|
|
229
|
-
"wasm:js-string": {
|
|
230
|
-
length(str) {
|
|
231
|
-
return str.length;
|
|
232
221
|
},
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
222
|
+
matchCaseInsensitive: (() => {
|
|
223
|
+
const cache = [];
|
|
224
|
+
return (stringIdx) => {
|
|
225
|
+
const { pos } = this._instance.exports;
|
|
226
|
+
let re = cache[stringIdx];
|
|
227
|
+
if (!re) re = cache[stringIdx] = new RegExp(this._strings[stringIdx], "iy");
|
|
228
|
+
re.lastIndex = pos.value;
|
|
229
|
+
const arr = re.exec(this._input);
|
|
230
|
+
if (arr) pos.value += arr[0].length;
|
|
231
|
+
return !!arr;
|
|
232
|
+
};
|
|
233
|
+
})()
|
|
238
234
|
}
|
|
239
235
|
};
|
|
240
236
|
/** @internal */
|
|
@@ -244,7 +240,7 @@ var Grammar = class Grammar {
|
|
|
244
240
|
/** @internal */
|
|
245
241
|
_input = "";
|
|
246
242
|
/** @internal */
|
|
247
|
-
|
|
243
|
+
_strings = [];
|
|
248
244
|
/** @internal */
|
|
249
245
|
_resultStack = [];
|
|
250
246
|
/**
|
|
@@ -255,7 +251,7 @@ var Grammar = class Grammar {
|
|
|
255
251
|
*/
|
|
256
252
|
constructor(bytes) {
|
|
257
253
|
if (bytes) {
|
|
258
|
-
const mod = new WebAssembly.Module(bytes
|
|
254
|
+
const mod = new WebAssembly.Module(bytes);
|
|
259
255
|
this._init(mod, new WebAssembly.Instance(mod, this._imports));
|
|
260
256
|
}
|
|
261
257
|
}
|
|
@@ -263,18 +259,10 @@ var Grammar = class Grammar {
|
|
|
263
259
|
_init(module, instance) {
|
|
264
260
|
this._instance = instance;
|
|
265
261
|
this._extractStrings(module);
|
|
266
|
-
this._initMemoConfig(module);
|
|
267
262
|
this.name = this._getGrammarName(module);
|
|
268
263
|
return this;
|
|
269
264
|
}
|
|
270
265
|
/** @internal */
|
|
271
|
-
_initMemoConfig(module) {
|
|
272
|
-
const sections = WebAssembly.Module.customSections(module, "memoizedRuleCount");
|
|
273
|
-
assert(sections.length === 1, "Expected one memoizedRuleCount section");
|
|
274
|
-
const count = new DataView(sections[0]).getUint32(0, true);
|
|
275
|
-
this._instance.exports.setNumMemoizedRules(count);
|
|
276
|
-
}
|
|
277
|
-
/** @internal */
|
|
278
266
|
_manage(result) {
|
|
279
267
|
result._managed = true;
|
|
280
268
|
}
|
|
@@ -297,7 +285,7 @@ var Grammar = class Grammar {
|
|
|
297
285
|
const { module, instance } = await WebAssembly.instantiate(source, {
|
|
298
286
|
...this._imports,
|
|
299
287
|
debug: debugImports
|
|
300
|
-
}
|
|
288
|
+
});
|
|
301
289
|
return this._init(module, instance);
|
|
302
290
|
}
|
|
303
291
|
/** @internal */
|
|
@@ -305,7 +293,7 @@ var Grammar = class Grammar {
|
|
|
305
293
|
const { module, instance } = await WebAssembly.instantiateStreaming(source, {
|
|
306
294
|
...this._imports,
|
|
307
295
|
debug: debugImports
|
|
308
|
-
}
|
|
296
|
+
});
|
|
309
297
|
return this._init(module, instance);
|
|
310
298
|
}
|
|
311
299
|
/** @internal */
|
|
@@ -323,7 +311,7 @@ var Grammar = class Grammar {
|
|
|
323
311
|
this._ruleIds.set(ruleName, this._ruleIds.size);
|
|
324
312
|
this._ruleNames.push(ruleName);
|
|
325
313
|
}
|
|
326
|
-
for (const str of parseStringTable(module, "
|
|
314
|
+
for (const str of parseStringTable(module, "strings")) this._strings.push(str);
|
|
327
315
|
}
|
|
328
316
|
match(input, ruleName) {
|
|
329
317
|
assert(this._resultStack.every((r) => r._managed), "Cannot match while there are unmanaged MatchResults. Use `using` or `.use()` to manage the MatchResult lifecycle.");
|
|
@@ -332,13 +320,13 @@ var Grammar = class Grammar {
|
|
|
332
320
|
const exports = this._instance.exports;
|
|
333
321
|
const ruleId = checkNotNull(this._ruleIds.get(ruleName || this._ruleNames[0]), `unknown rule: '${ruleName}'`);
|
|
334
322
|
const heapWatermark = exports.__offset.value;
|
|
335
|
-
const succeeded = exports.match(input, ruleId);
|
|
323
|
+
const succeeded = exports.match(input.length, ruleId);
|
|
336
324
|
const buffer = exports.memory.buffer;
|
|
337
325
|
for (const r of this._resultStack) if (r._ctx.view.buffer !== buffer) r._ctx.view = new DataView(buffer);
|
|
338
326
|
const ctx = {
|
|
339
327
|
ruleNames: this._ruleNames,
|
|
340
328
|
view: new DataView(buffer),
|
|
341
|
-
input
|
|
329
|
+
input
|
|
342
330
|
};
|
|
343
331
|
const result = createMatchResult(this, ruleName || this._ruleNames[0], ctx, !!succeeded);
|
|
344
332
|
result._heapWatermark = heapWatermark;
|
|
@@ -349,13 +337,13 @@ var Grammar = class Grammar {
|
|
|
349
337
|
/** @internal */
|
|
350
338
|
recordFailures() {
|
|
351
339
|
const { exports } = this._instance;
|
|
352
|
-
exports.recordFailures(this._ruleIds.get(this._ruleNames[0]));
|
|
340
|
+
exports.recordFailures(this._input.length, this._ruleIds.get(this._ruleNames[0]));
|
|
353
341
|
const ans = [];
|
|
354
342
|
for (let i = 0; i < exports.getRecordedFailuresLength(); i++) if (!exports.isFluffy(i)) ans.push(exports.recordedFailuresAt(i));
|
|
355
343
|
return [...new Set(ans)];
|
|
356
344
|
}
|
|
357
345
|
getFailureDescription(id) {
|
|
358
|
-
return this.
|
|
346
|
+
return this._strings[id];
|
|
359
347
|
}
|
|
360
348
|
getMemorySizeBytes() {
|
|
361
349
|
return this._instance.exports.memory.buffer.byteLength;
|
|
@@ -377,7 +365,7 @@ var Grammar = class Grammar {
|
|
|
377
365
|
ctx ??= {
|
|
378
366
|
ruleNames: this._ruleNames,
|
|
379
367
|
view: new DataView(exports.memory.buffer),
|
|
380
|
-
input:
|
|
368
|
+
input: this._input
|
|
381
369
|
};
|
|
382
370
|
const firstNode = new CstNodeImpl(ctx, exports.bindingsAt(0), 0);
|
|
383
371
|
assert(firstNode.isNonterminal());
|
|
@@ -390,12 +378,10 @@ var Grammar = class Grammar {
|
|
|
390
378
|
}
|
|
391
379
|
/** @internal */
|
|
392
380
|
_fillInputBuffer(ptr, length) {
|
|
393
|
-
const encoder = new TextEncoder();
|
|
394
381
|
const { memory } = this._instance.exports;
|
|
395
|
-
const buf = new
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
return written;
|
|
382
|
+
const buf = new Uint16Array(memory.buffer, ptr, length);
|
|
383
|
+
for (let i = 0; i < length; i++) buf[i] = this._input.charCodeAt(i);
|
|
384
|
+
return length;
|
|
399
385
|
}
|
|
400
386
|
getRightmostFailurePosition() {
|
|
401
387
|
return this._instance.exports.rightmostFailurePos.value;
|
|
@@ -708,7 +694,8 @@ var FailedMatchResult = class extends MatchResult {
|
|
|
708
694
|
const { exports } = this.grammar._instance;
|
|
709
695
|
const ruleIds = this.grammar._ruleIds;
|
|
710
696
|
const ruleNames = this.grammar._ruleNames;
|
|
711
|
-
|
|
697
|
+
const inputLength = this.grammar._input.length;
|
|
698
|
+
exports.recordFailures(inputLength, ruleIds.get(ruleNames[0]));
|
|
712
699
|
const failureMap = /* @__PURE__ */ new Map();
|
|
713
700
|
const len = exports.getRecordedFailuresLength();
|
|
714
701
|
for (let i = 0; i < len; i++) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/assert.ts","../src/extras.ts","../src/miniohm.ts"],"sourcesContent":["export function assert(cond: boolean, message = 'Assertion failed'): asserts cond {\n if (!cond) throw new Error(message);\n}\n\nexport function checkNotNull<T>(x: T, msg = 'unexpected null value'): NonNullable<T> {\n assert(x != null, msg);\n return x as NonNullable<T>;\n}\n","// Self-contained copies of getLineAndColumn / getLineAndColumnMessage,\n// originally from packages/ohm-js/src/util.js. Inlined here so the runtime\n// package has zero dependency on the legacy engine.\n\nfunction repeatStr(str: string, n: number): string {\n return new Array(n + 1).join(str);\n}\n\nfunction padLeft(str: string, len: number, ch = ' '): string {\n if (str.length < len) {\n return repeatStr(ch, len - str.length) + str;\n }\n return str;\n}\n\nfunction padNumbersToEqualLength(arr: number[]): string[] {\n let maxLen = 0;\n const strings = arr.map(n => {\n const str = n.toString();\n maxLen = Math.max(maxLen, str.length);\n return str;\n });\n return strings.map(s => padLeft(s, maxLen));\n}\n\nfunction strcpy(dest: string, src: string, offset: number): string {\n const origDestLen = dest.length;\n const start = dest.slice(0, offset);\n const end = dest.slice(offset + src.length);\n return (start + src + end).substr(0, origDestLen);\n}\n\ninterface LineAndColumnInfo {\n offset: number;\n lineNum: number;\n colNum: number;\n line: string;\n prevLine: string | null;\n nextLine: string | null;\n toString(...ranges: [number, number][]): string;\n}\n\nfunction lineAndColumnToMessage(\n this: LineAndColumnInfo,\n ...ranges: [number, number][]\n): string {\n const lineAndCol = this;\n const {offset} = lineAndCol;\n\n let result = '';\n result += 'Line ' + lineAndCol.lineNum + ', col ' + lineAndCol.colNum + ':\\n';\n\n const lineNumbers = padNumbersToEqualLength([\n lineAndCol.prevLine == null ? 0 : lineAndCol.lineNum - 1,\n lineAndCol.lineNum,\n lineAndCol.nextLine == null ? 0 : lineAndCol.lineNum + 1,\n ]);\n\n const appendLine = (num: number, content: string, prefix: string) => {\n result += prefix + lineNumbers[num] + ' | ' + content + '\\n';\n };\n\n if (lineAndCol.prevLine != null) {\n appendLine(0, lineAndCol.prevLine, ' ');\n }\n appendLine(1, lineAndCol.line, '> ');\n\n const lineLen = lineAndCol.line.length;\n let indicationLine = repeatStr(' ', lineLen + 1);\n for (let i = 0; i < ranges.length; ++i) {\n let startIdx = ranges[i][0];\n let endIdx = ranges[i][1];\n if (!(startIdx >= 0 && startIdx <= endIdx)) {\n throw new Error('range start must be >= 0 and <= end');\n }\n\n const lineStartOffset = offset - lineAndCol.colNum + 1;\n startIdx = Math.max(0, startIdx - lineStartOffset);\n endIdx = Math.min(endIdx - lineStartOffset, lineLen);\n\n indicationLine = strcpy(indicationLine, repeatStr('~', endIdx - startIdx), startIdx);\n }\n const gutterWidth = 2 + lineNumbers[1].length + 3;\n result += repeatStr(' ', gutterWidth);\n indicationLine = strcpy(indicationLine, '^', lineAndCol.colNum - 1);\n result += indicationLine.replace(/ +$/, '') + '\\n';\n\n if (lineAndCol.nextLine != null) {\n appendLine(2, lineAndCol.nextLine, ' ');\n }\n return result;\n}\n\nexport function getLineAndColumn(str: string, offset: number): LineAndColumnInfo {\n let lineNum = 1;\n let colNum = 1;\n\n let currOffset = 0;\n let lineStartOffset = 0;\n\n let nextLine: string | null = null;\n let prevLine: string | null = null;\n let prevLineStartOffset = -1;\n\n while (currOffset < offset) {\n const c = str.charAt(currOffset++);\n if (c === '\\n') {\n lineNum++;\n colNum = 1;\n prevLineStartOffset = lineStartOffset;\n lineStartOffset = currOffset;\n } else if (c !== '\\r') {\n colNum++;\n }\n }\n\n // Find the end of the target line.\n let lineEndOffset = str.indexOf('\\n', lineStartOffset);\n if (lineEndOffset === -1) {\n lineEndOffset = str.length;\n } else {\n // Get the next line.\n const nextLineEndOffset = str.indexOf('\\n', lineEndOffset + 1);\n nextLine =\n nextLineEndOffset === -1\n ? str.slice(lineEndOffset)\n : str.slice(lineEndOffset, nextLineEndOffset);\n // Strip leading and trailing EOL char(s).\n nextLine = nextLine.replace(/^\\r?\\n/, '').replace(/\\r$/, '');\n }\n\n // Get the previous line.\n if (prevLineStartOffset >= 0) {\n // Strip trailing EOL char(s).\n prevLine = str.slice(prevLineStartOffset, lineStartOffset).replace(/\\r?\\n$/, '');\n }\n\n // Get the target line, stripping a trailing carriage return if necessary.\n const line = str.slice(lineStartOffset, lineEndOffset).replace(/\\r$/, '');\n\n return {\n offset,\n lineNum,\n colNum,\n line,\n prevLine,\n nextLine,\n toString: lineAndColumnToMessage,\n };\n}\n\nexport function getLineAndColumnMessage(\n str: string,\n offset: number,\n ...ranges: [number, number][]\n): string {\n return getLineAndColumn(str, offset).toString(...ranges);\n}\n","import {assert, checkNotNull} from './assert.ts';\nimport {getLineAndColumn, getLineAndColumnMessage} from './extras.ts';\n\nconst MATCH_RECORD_TYPE_MASK = 0b11;\n\n// A MatchRecord is the representation of a CstNode in Wasm linear memory.\nconst MatchRecordType = {\n NONTERMINAL: 0,\n TERMINAL: 1,\n ITER_FLAG: 2,\n OPTIONAL: 3,\n} as const;\n\n// A _CST node_ is the user-facing representation, built from a match record.\nexport const CstNodeType = {\n NONTERMINAL: 0,\n TERMINAL: 1,\n LIST: 2,\n OPT: 3,\n SEQ: 4,\n} as const;\n\n// Define types with the same name as the values above. This gives us roughly the\n// same functionality as a TypeScript enum, but works with erasableSyntaxOnly.\ntype MatchRecordType = (typeof MatchRecordType)[keyof typeof MatchRecordType];\nexport type CstNodeType = (typeof CstNodeType)[keyof typeof CstNodeType];\n\nconst EMPTY_CHILDREN: ReadonlyArray<CstNode> = Object.freeze([]);\n\nconst compileOptions = {\n builtins: ['js-string'],\n};\n\n// Bit flags for Unicode categories, based on the order that they appear in\n// https://www.unicode.org/Public/16.0.0/ucd/extracted/DerivedGeneralCategory.txt\n\nconst UnicodeCategoryNames = [\n 'Cn', // Unassigned\n 'Lu', // Uppercase_Letter\n 'Ll', // Lowercase_Letter\n 'Lt', // Titlecase_Letter\n 'Lm', // Modifier_Letter\n 'Lo', // Other_Letter\n];\n\nconst utf8 = new TextDecoder('utf-8');\nconst utf16le = new TextDecoder('utf-16le');\n\n// Minimal implementation of Interval (for FailedMatchResult)\nexport class Interval {\n startIdx: number;\n endIdx: number;\n /** @internal */\n private _sourceString: string;\n\n constructor(sourceString: string, startIdx: number, endIdx: number) {\n this._sourceString = sourceString;\n this.startIdx = startIdx;\n this.endIdx = endIdx;\n }\n\n get sourceString(): string {\n return this._sourceString;\n }\n\n get contents(): string {\n return this._sourceString.slice(this.startIdx, this.endIdx);\n }\n}\n\nexport class Failure {\n /** @internal */\n private _description: string;\n /** @internal */\n private _fluffy: boolean;\n\n constructor(description: string, fluffy: boolean) {\n this._description = description;\n this._fluffy = fluffy;\n }\n\n isFluffy(): boolean {\n return this._fluffy;\n }\n\n toString(): string {\n return this._description;\n }\n}\n\nfunction regexFromCategoryBitmap(bitmap: number): RegExp {\n const cats: string[] = [];\n for (let i = 0; i < 32; i++) {\n const mask = 1 << i;\n if (bitmap & mask) cats.push(UnicodeCategoryNames[i]);\n }\n return new RegExp(\n cats.map(cat => `\\\\p{${cat}}`).join('|'),\n 'uy' // u: unicode, y: sticky\n );\n}\n\nfunction parseStringTable(module: WebAssembly.Module, sectionName: string): string[] {\n const sections = WebAssembly.Module.customSections(module, sectionName);\n assert(\n sections.length === 1,\n `Expected one ${sectionName} section, found ${sections.length}`\n );\n\n const data = new Uint8Array(sections[0]);\n const dataView = new DataView(data.buffer);\n let offset = 0;\n\n const parseU32 = (): number => {\n // Quick 'n dirty ULeb128 parsing, assuming no more than 2 bytes.\n const b1 = dataView.getUint8(offset++);\n let value = b1 & 0x7f;\n if (b1 & 0x80) {\n const b2 = dataView.getUint8(offset++);\n assert((b2 & 0x80) === 0, 'Expected max two bytes');\n value |= (b2 & 0x7f) << 7;\n }\n return value;\n };\n\n const numEntries = parseU32();\n const ans: string[] = [];\n for (let i = 0; i < numEntries; i++) {\n const stringLen = parseU32();\n const bytes = data.slice(offset, offset + stringLen);\n offset += stringLen;\n const name = utf8.decode(bytes);\n ans.push(name);\n }\n return ans;\n}\n\nexport class Grammar {\n name = '';\n\n /** @internal */\n private _instance?: WebAssembly.Instance = undefined;\n /** @internal */\n private _imports = {\n // System-level AssemblyScript imports.\n env: {\n abort: (msgPtr: number, filePtr: number, line: number, column: number) => {\n const msg = this._readASString(msgPtr);\n const file = this._readASString(filePtr);\n throw new Error(`Wasm abort: ${msg} at ${file}:${line}:${column}`);\n },\n },\n // For imports from ohmRuntime.ts.\n ohmRuntime: {\n printI32(val: number) {\n // eslint-disable-next-line no-console\n console.log(val);\n },\n isRuleSyntactic: (ruleId: number) => {\n // TODO: Precompute this for all rules, and encode it in the module?\n const name = this._ruleNames[ruleId];\n assert(!!name);\n return name[0] === name[0].toUpperCase();\n },\n fillInputBuffer: this._fillInputBuffer.bind(this),\n matchUnicodeChar: (catBitmap: number) => {\n const {input, pos} = (this._instance as any).exports;\n const re = regexFromCategoryBitmap(catBitmap);\n re.lastIndex = pos;\n const arr = re.exec(input.value);\n if (arr) {\n pos.value += arr[0].length;\n }\n return !!arr;\n },\n },\n // Include a polyfill for js-string builtins for engines that don't\n // support that feature (e.g., Safari).\n 'wasm:js-string': {\n length(str: string): number {\n return str.length;\n },\n charCodeAt(str: string, idx: number): number {\n // NOTE: `index` is interpreted as a signed 32-bit integer when converted to\n // a JS value using standard conversions. Reinterpret as unsigned here.\n idx >>>= 0;\n assert(idx < str.length, 'string index out of bounds');\n return str.charCodeAt(idx);\n },\n },\n };\n /** @internal */\n private _ruleIds = new Map<string, number>();\n /** @internal */\n private _ruleNames: string[] = [];\n /** @internal */\n private _input = '';\n\n /** @internal */\n public _failureDescriptions: string[] = [];\n\n /*\n * Wasm heap memory management\n * ===========================\n *\n * The Wasm module uses a bump-pointer allocator (AssemblyScript's \"stub\"\n * runtime). Each match() call allocates a memo table and CST nodes on\n * the Wasm heap. There is no way to free individual allocations — you\n * can only reset the bump pointer.\n *\n * To allow incremental freeing, we exploit two facts:\n *\n * 1. MatchResult disposal is LIFO — you must dispose the most recent\n * result first (enforced by an assert in _dispose).\n *\n * 2. Allocations for match N are always contiguous and sit above\n * match N-1's allocations on the heap.\n *\n * Before each match, we snapshot the bump pointer (`exports.__offset`)\n * as a \"watermark\" and store it on the MatchResult. On dispose, we\n * reset the bump pointer to that watermark, freeing exactly that\n * match's allocations while keeping earlier results intact.\n *\n * When the last result is disposed, its watermark equals the initial\n * heap offset, so the entire heap is reclaimed — equivalent to the\n * old resetHeap() approach, but without the all-or-nothing limitation.\n */\n\n /** @internal */\n private _resultStack: MatchResult[] = [];\n\n /**\n * Create a new Grammar object.\n * If `bytes` is specified, the WebAssembly module will be synchronously\n * compiled and instantiated. Use `instantiate` or `instantiateStreaming`\n * to instantiate asynchronously.\n */\n constructor(bytes?: BufferSource) {\n if (bytes) {\n // @ts-expect-error: TS2554: Expected 1 arguments, but got 2.\n const mod = new WebAssembly.Module(bytes, compileOptions);\n this._init(mod, new WebAssembly.Instance(mod, this._imports));\n }\n }\n\n /** @internal */\n private _init(module: WebAssembly.Module, instance: WebAssembly.Instance) {\n this._instance = instance;\n this._extractStrings(module);\n this._initMemoConfig(module);\n this.name = this._getGrammarName(module);\n return this;\n }\n\n /** @internal */\n private _initMemoConfig(module: WebAssembly.Module) {\n const sections = WebAssembly.Module.customSections(module, 'memoizedRuleCount');\n assert(sections.length === 1, 'Expected one memoizedRuleCount section');\n const view = new DataView(sections[0]);\n const count = view.getUint32(0, true); // little-endian\n (this._instance as any).exports.setNumMemoizedRules(count);\n }\n\n /** @internal */\n _manage(result: MatchResult): void {\n result._managed = true;\n }\n\n /** @internal */\n _dispose(result: MatchResult): void {\n assert(\n this._resultStack.at(-1) === result,\n `You can only dispose() the most recent MatchResult`\n );\n this._resultStack.pop();\n // Reset the bump-pointer allocator to the watermark recorded before this\n // match. Because disposal is LIFO, this frees exactly this match's\n // allocations (memo table + CST nodes) while keeping earlier ones intact.\n (this._instance as any).exports.__offset.value = result._heapWatermark;\n result._attached = false;\n result._ctx.view = new DataView(new ArrayBuffer(0));\n }\n\n static async instantiate(source: BufferSource): Promise<Grammar> {\n return new Grammar()._instantiate(source);\n }\n\n static async instantiateStreaming(source: Response | Promise<Response>): Promise<Grammar> {\n return new Grammar()._instantiateStreaming(source);\n }\n\n /** @internal */\n async _instantiate(source: BufferSource, debugImports: any = {}): Promise<Grammar> {\n const {module, instance} = await WebAssembly.instantiate(\n source,\n {\n ...this._imports,\n debug: debugImports,\n },\n // @ts-expect-error: Expected 1-2 arguments, but got 3.\n compileOptions\n );\n return this._init(module, instance);\n }\n\n /** @internal */\n async _instantiateStreaming(\n source: Response | Promise<Response>,\n debugImports: any = {}\n ): Promise<Grammar> {\n const {module, instance} = await WebAssembly.instantiateStreaming(\n source,\n {\n ...this._imports,\n debug: debugImports,\n },\n // @ts-expect-error: TS2554: Expected 1-2 arguments, but got 3.\n compileOptions\n );\n return this._init(module, instance);\n }\n\n /** @internal */\n private _getGrammarName(module: WebAssembly.Module): string {\n const sections = WebAssembly.Module.customSections(module, 'name');\n assert(sections.length === 1, `Expected one name section, found ${sections.length}`);\n const data = new Uint8Array(sections[0]);\n return utf8.decode(data);\n }\n\n /** @internal */\n private _extractStrings(module: WebAssembly.Module): void {\n assert(this._ruleNames.length === 0);\n assert(this._ruleIds.size === 0);\n for (const ruleName of parseStringTable(module, 'ruleNames')) {\n this._ruleIds.set(ruleName, this._ruleIds.size);\n this._ruleNames.push(ruleName);\n }\n for (const str of parseStringTable(module, 'failureDescriptions')) {\n this._failureDescriptions.push(str);\n }\n }\n\n match<T>(input: string, ruleName?: string): MatchResult {\n assert(\n this._resultStack.every(r => r._managed),\n 'Cannot match while there are unmanaged MatchResults. ' +\n 'Use `using` or `.use()` to manage the MatchResult lifecycle.'\n );\n this._input = input;\n if (typeof process !== 'undefined' && process.env.OHM_DEBUG === '1') debugger; // eslint-disable-line no-debugger\n const exports = (this._instance as any).exports;\n const ruleId = checkNotNull(\n this._ruleIds.get(ruleName || this._ruleNames[0]),\n `unknown rule: '${ruleName}'`\n );\n const heapWatermark = exports.__offset.value;\n const succeeded = exports.match(input, ruleId);\n const buffer = exports.memory.buffer;\n\n // If the Wasm match triggered memory.grow() (e.g. for the memo table or\n // CST nodes), the old ArrayBuffer is detached. Refresh the DataView in\n // all existing match contexts so that their CstNodes can still read data.\n for (const r of this._resultStack) {\n if (r._ctx.view.buffer !== buffer) {\n r._ctx.view = new DataView(buffer);\n }\n }\n\n const ctx: MatchContext = {\n ruleNames: this._ruleNames,\n view: new DataView(buffer),\n input: exports.input.value,\n };\n const result = createMatchResult(this, ruleName || this._ruleNames[0], ctx, !!succeeded);\n result._heapWatermark = heapWatermark;\n result.dispose = this._dispose.bind(this, result);\n this._resultStack.push(result);\n return result;\n }\n\n /** @internal */\n recordFailures(): number[] {\n const {exports} = this._instance as any;\n exports.recordFailures(this._ruleIds.get(this._ruleNames[0]));\n const ans: number[] = [];\n for (let i = 0; i < exports.getRecordedFailuresLength(); i++) {\n if (!exports.isFluffy(i)) {\n // Filter out fluffy failures\n ans.push(exports.recordedFailuresAt(i));\n }\n }\n // Deduplicate\n return [...new Set(ans)];\n }\n\n getFailureDescription(id: number): string {\n return this._failureDescriptions[id];\n }\n\n getMemorySizeBytes(): number {\n return (this._instance as any).exports.memory.buffer.byteLength;\n }\n\n /** @internal Read an AssemblyScript string from Wasm linear memory. */\n private _readASString(ptr: number): string {\n if (!ptr || !this._instance) return '(unknown)';\n try {\n const buffer = (this._instance as any).exports.memory.buffer;\n // AS managed object layout: rtSize (byte length) is at ptr - 4.\n const byteLen = new DataView(buffer).getUint32(ptr - 4, true);\n return utf16le.decode(new Uint8Array(buffer, ptr, byteLen));\n } catch {\n return `(ptr=${ptr})`;\n }\n }\n\n /** @internal */\n _getCstRoot(ctx?: MatchContext): CstNode {\n const {exports} = this._instance as any;\n ctx ??= {\n ruleNames: this._ruleNames,\n view: new DataView(exports.memory.buffer),\n input: exports.input.value,\n };\n const firstNode = new CstNodeImpl(ctx, exports.bindingsAt(0), 0);\n assert(firstNode.isNonterminal());\n if (firstNode.ctorName !== '$spaces') {\n return firstNode;\n }\n assert(exports.getBindingsLength() > 1 && firstNode.ctorName === '$spaces');\n const nextAddr = exports.bindingsAt(1);\n const root = new CstNodeImpl(ctx, nextAddr, firstNode.matchLength);\n root.leadingSpaces = firstNode;\n return root as CstNode;\n }\n\n /** @internal */\n private _fillInputBuffer(ptr: number, length: number): number {\n const encoder = new TextEncoder();\n const {memory} = (this._instance as any).exports;\n const buf = new Uint8Array(memory.buffer, ptr, length);\n const {read, written} = encoder.encodeInto(this._input, buf);\n assert(read === this._input.length, 'Input was not fully read');\n return written;\n }\n\n getRightmostFailurePosition(): number {\n return (this._instance as any).exports.rightmostFailurePos.value;\n }\n}\n\ninterface MatchContext {\n ruleNames: string[];\n view: DataView;\n input: string;\n}\n\nexport type CstNode = NonterminalNode | TerminalNode | ListNode | OptNode | SeqNode;\nexport type CstNodeChildren = readonly CstNode[];\n\nexport interface CstNodeBase {\n ctorName: string;\n source: {startIdx: number; endIdx: number};\n sourceString: string;\n matchLength: number;\n\n isNonterminal(): this is NonterminalNode;\n isTerminal(): this is TerminalNode;\n isOptional(): this is OptNode;\n isSeq(): this is SeqNode;\n isList(): this is ListNode;\n}\n\nexport interface NonterminalNode<TChildren extends CstNodeChildren = CstNodeChildren>\n extends CstNodeBase {\n type: typeof CstNodeType.NONTERMINAL;\n ctorName: string;\n leadingSpaces?: NonterminalNode;\n children: TChildren;\n\n isSyntactic(): boolean;\n isLexical(): boolean;\n}\n\nexport interface TerminalNode extends CstNodeBase {\n type: typeof CstNodeType.TERMINAL;\n ctorName: '_terminal';\n leadingSpaces?: NonterminalNode;\n children: readonly [];\n value: string;\n}\n\nexport interface ListNode<TNode extends CstNode = CstNode> extends CstNodeBase {\n type: typeof CstNodeType.LIST;\n ctorName: '_list';\n children: readonly TNode[];\n collect: <R>(cb: (...children: CstNode[]) => R) => R[];\n}\n\nexport interface OptNode<TChild extends CstNode = CstNode> extends CstNodeBase {\n type: typeof CstNodeType.OPT;\n ctorName: '_opt';\n children: [] | [TChild];\n\n // If the child is a SeqNode, the `consume` callback receives its unpacked children.\n // Otherwise, it receives the child node itself.\n ifPresent<R>(\n consume: TChild extends SeqNode<infer T> ? (...children: T) => R : (child: TChild) => R,\n orElse?: () => R\n ): R;\n ifPresent<R>(\n consume: TChild extends SeqNode<infer T> ? (...children: T) => R : (child: TChild) => R\n ): R | undefined;\n isPresent(): boolean;\n isEmpty(): boolean;\n}\n\nexport interface SeqNode<TChildren extends CstNodeChildren = CstNodeChildren>\n extends CstNodeBase {\n type: typeof CstNodeType.SEQ;\n ctorName: '_seq';\n children: TChildren;\n unpack: <R>(cb: (...children: TChildren) => R) => R;\n}\n\nclass CstNodeImpl implements CstNodeBase {\n _ctx!: MatchContext;\n _children?: CstNodeChildren = undefined;\n _base: number;\n startIdx: number;\n leadingSpaces?: NonterminalNode = undefined;\n source: {startIdx: number; endIdx: number};\n\n constructor(ctx: MatchContext, ptr: number, startIdx: number) {\n // Non-enumerable properties\n Object.defineProperties(this, {\n _ctx: {value: ctx},\n _children: {writable: true},\n });\n this._base = ptr;\n this.startIdx = startIdx;\n this.source = {\n startIdx,\n endIdx: startIdx + this.sourceString.length,\n };\n if (this.matchRecordType === MatchRecordType.TERMINAL || this.count === 0) {\n this._children = EMPTY_CHILDREN;\n }\n }\n\n get type(): CstNodeType {\n switch (this._typeAndDetails & MATCH_RECORD_TYPE_MASK) {\n case MatchRecordType.NONTERMINAL:\n return CstNodeType.NONTERMINAL;\n case MatchRecordType.TERMINAL:\n return CstNodeType.TERMINAL;\n case MatchRecordType.ITER_FLAG:\n return CstNodeType.LIST;\n default:\n throw new Error('unreachable');\n }\n }\n\n private get matchRecordType(): MatchRecordType {\n return (this._typeAndDetails & MATCH_RECORD_TYPE_MASK) as MatchRecordType;\n }\n\n isNonterminal(): this is NonterminalNode {\n return this.type === CstNodeType.NONTERMINAL;\n }\n\n isTerminal(): this is TerminalNode {\n return this.type === CstNodeType.TERMINAL;\n }\n\n isList(): this is ListNode {\n return this.type === CstNodeType.LIST;\n }\n\n isOptional(): this is OptNode {\n return this.type === CstNodeType.OPT;\n }\n\n isSeq(): this is SeqNode {\n return this.type === CstNodeType.SEQ;\n }\n\n get ctorName(): string {\n switch (this.type) {\n case CstNodeType.NONTERMINAL: {\n const {ruleNames, view} = this._ctx;\n const ruleId = view.getInt32(this._base + 8, true) >>> 2;\n return ruleNames[ruleId].split('<')[0];\n }\n case CstNodeType.TERMINAL:\n return '_terminal';\n case CstNodeType.LIST:\n return '_list';\n case CstNodeType.OPT:\n return '_opt';\n case CstNodeType.SEQ:\n return '_seq';\n }\n }\n\n get count(): number {\n return this._ctx.view.getUint32(this._base, true);\n }\n\n get matchLength(): number {\n return this._ctx.view.getUint32(this._base + 4, true);\n }\n\n get _typeAndDetails(): number {\n return this._ctx.view.getInt32(this._base + 8, true);\n }\n\n get arity(): number {\n return this._typeAndDetails >>> 2;\n }\n\n get children(): CstNodeChildren {\n if (!this._children) {\n this._children = this._computeChildren().map((n): CstNode => {\n const {matchRecordType} = n;\n if (matchRecordType === MatchRecordType.OPTIONAL) {\n const child: CstNode | undefined =\n n.children.length <= 1\n ? n.children[0]\n : new SeqNodeImpl(n.children, n.source, n.sourceString);\n return new OptNodeImpl(child, n.source, n.sourceString);\n } else if (matchRecordType === MatchRecordType.ITER_FLAG) {\n if (n.arity <= 1) {\n return new ListNodeImpl(n.children, n.source, n.sourceString);\n }\n const arr: CstNode[] = [];\n let startIdx = n.startIdx;\n for (let i = 0; i < n.children.length; i += n.arity) {\n // FIXME: We don't need any of this nonsense if we actually build the SeqNodes at parse time.\n const seqChildren = n.children.slice(i, i + n.arity);\n const endIdx = checkNotNull(seqChildren.at(-1)).source.endIdx;\n const sourceString = n._ctx.input.slice(startIdx, endIdx);\n arr.push(new SeqNodeImpl(seqChildren, {startIdx, endIdx}, sourceString));\n startIdx = endIdx;\n }\n assert(startIdx === n.source.endIdx);\n return new ListNodeImpl(arr, n.source, n.sourceString);\n }\n return n as CstNode; // FIXME\n });\n }\n return this._children;\n }\n\n _computeChildren(): CstNodeImpl[] {\n const children: CstNodeImpl[] = [];\n const {ruleNames, view, input} = this._ctx;\n let spaces: NonterminalNode | undefined;\n let {startIdx} = this;\n for (let i = 0; i < this.count; i++) {\n const slotOffset = this._base + 16 + i * 4;\n const ptr = view.getUint32(slotOffset, true);\n // TODO: Avoid allocating $spaces nodes altogether?\n const node = new CstNodeImpl(this._ctx, ptr, startIdx);\n if (\n node.matchRecordType === MatchRecordType.NONTERMINAL &&\n node.ctorName === '$spaces'\n ) {\n assert(!spaces, 'Multiple $spaces nodes found');\n spaces = node as NonterminalNode; // FIXME\n } else {\n if (spaces) {\n node.leadingSpaces = spaces;\n spaces = undefined;\n }\n children.push(node);\n }\n startIdx += node.matchLength;\n }\n assert(spaces === undefined, 'Unclaimed $spaces!');\n return children;\n }\n\n get sourceString(): string {\n return this._ctx.input.slice(this.startIdx, this.startIdx + this.matchLength);\n }\n\n isSyntactic(): boolean {\n assert(this.isNonterminal(), 'Not a nonterminal');\n const firstChar = this.ctorName[0];\n return firstChar === firstChar.toUpperCase();\n }\n\n isLexical(): boolean {\n assert(this.isNonterminal(), 'Not a nonterminal');\n return !this.isSyntactic();\n }\n\n toString(): string {\n const ctorName = this.isTerminal() ? '_terminal' : this.isSeq() ? '_iter' : this.ctorName;\n const {sourceString, startIdx} = this;\n return `CstNode {ctorName: ${ctorName}, sourceString: ${sourceString}, startIdx: ${startIdx} }`;\n }\n}\n\nabstract class WrapperNode implements CstNodeBase {\n abstract ctorName: string;\n source: {startIdx: number; endIdx: number};\n sourceString: string;\n\n constructor(source: {startIdx: number; endIdx: number}, sourceString: string) {\n this.source = source;\n this.sourceString = sourceString;\n }\n\n get matchLength(): number {\n return this.sourceString.length;\n }\n\n isNonterminal(): this is NonterminalNode {\n return false;\n }\n isTerminal(): this is TerminalNode {\n return false;\n }\n isOptional(): this is OptNode {\n return false;\n }\n isSeq(): this is SeqNode {\n return false;\n }\n isList(): this is ListNode {\n return false;\n }\n}\n\nclass SeqNodeImpl<TChildren extends CstNodeChildren = CstNodeChildren>\n extends WrapperNode\n implements SeqNode<TChildren>\n{\n type: typeof CstNodeType.SEQ = CstNodeType.SEQ;\n ctorName = '_seq' as const;\n children: TChildren;\n\n constructor(\n children: TChildren,\n source: {startIdx: number; endIdx: number},\n sourceString: string\n ) {\n super(source, sourceString);\n this.children = children;\n }\n\n override isSeq(): this is SeqNode {\n return true;\n }\n\n unpack<R>(cb: (...args: TChildren) => R): R {\n assert(\n cb.length === this.children.length,\n `bad arity: expected ${this.children.length}, got ${cb.length}`\n );\n return cb.call(null, ...this.children); // FIXME\n }\n}\n\nclass ListNodeImpl<TNode extends CstNode = CstNode>\n extends WrapperNode\n implements ListNode<TNode>\n{\n type: typeof CstNodeType.LIST = CstNodeType.LIST;\n ctorName = '_list' as const;\n children: readonly TNode[];\n\n constructor(\n children: readonly TNode[],\n source: {startIdx: number; endIdx: number},\n sourceString: string\n ) {\n super(source, sourceString);\n this.children = children;\n }\n\n override isList(): this is ListNode {\n return true;\n }\n\n collect<R>(cb: (...args: CstNode[]) => R): R[] {\n return this.children.map(c => {\n return c?.isSeq() ? c.unpack(cb) : cb(c);\n });\n }\n}\n\nclass OptNodeImpl<TNode extends CstNode = CstNode>\n extends WrapperNode\n implements OptNode<TNode>\n{\n type: typeof CstNodeType.OPT = CstNodeType.OPT;\n ctorName = '_opt' as const;\n children: [] | [TNode];\n\n constructor(\n child: TNode | undefined,\n source: {startIdx: number; endIdx: number},\n sourceString: string\n ) {\n super(source, sourceString);\n this.children = child ? [child] : [];\n }\n\n override isOptional(): this is OptNode {\n return true;\n }\n\n ifPresent<R>(\n consume: TNode extends SeqNode<infer T> ? (...children: T) => R : (child: TNode) => R,\n orElse?: () => R\n ): R | undefined {\n const child = this.children[0];\n if (child) {\n return child.isSeq()\n ? child.unpack(consume as (...children: any[]) => R)\n : (consume as (child: TNode) => R)(child);\n }\n if (orElse) return orElse();\n }\n\n isPresent(): boolean {\n return this.children.length > 0;\n }\n\n isEmpty(): boolean {\n return this.children.length === 0;\n }\n}\n\nexport abstract class MatchResult {\n // Note: This is different from the JS implementation, which has:\n // matcher: Matcher;\n // …instead.\n grammar: Grammar;\n startExpr: string;\n /** @internal */\n _ctx: MatchContext;\n /** @internal */\n _succeeded: boolean;\n /** @internal */\n _attached = true;\n /** @internal */\n _managed = false;\n /** @internal */\n _heapWatermark = 0;\n\n /** @internal */\n protected constructor(\n grammar: Grammar,\n startExpr: string,\n ctx: MatchContext,\n succeeded: boolean\n ) {\n this.grammar = grammar;\n this.startExpr = startExpr;\n this._ctx = ctx;\n this._succeeded = succeeded;\n }\n\n get input(): string {\n return (this.grammar as any)._input;\n }\n\n // `using` accesses [Symbol.dispose] at declaration time to get the\n // disposal method. We use this as the signal that the result is managed.\n get [Symbol.dispose](): () => void {\n this.grammar._manage(this);\n return () => this.dispose();\n }\n\n dispose(): void {\n throw new Error('MatchResult is not attached to any grammar');\n }\n\n succeeded(): this is SucceededMatchResult {\n return this._succeeded;\n }\n\n failed(): this is FailedMatchResult {\n return !this._succeeded;\n }\n\n toString(): string {\n return this.failed()\n ? '[match failed at position ' + this.getRightmostFailurePosition() + ']'\n : '[match succeeded]';\n }\n\n use<T>(cb: (r: this) => T): T {\n this.grammar._manage(this);\n try {\n return cb(this);\n } finally {\n this.dispose();\n }\n }\n}\n\nfunction createMatchResult(\n grammar: Grammar,\n startExpr: string,\n ctx: MatchContext,\n succeeded: boolean\n): MatchResult {\n return succeeded\n ? new SucceededMatchResult(grammar, startExpr, ctx, succeeded)\n : new FailedMatchResult(\n grammar,\n startExpr,\n ctx,\n succeeded,\n grammar.getRightmostFailurePosition()\n );\n}\n\nexport class SucceededMatchResult extends MatchResult {\n /** @internal */\n _cst: CstNode;\n\n /** @internal */\n protected constructor(\n grammar: Grammar,\n startExpr: string,\n ctx: MatchContext,\n succeeded: boolean\n ) {\n super(grammar, startExpr, ctx, succeeded);\n this._cst = grammar._getCstRoot(ctx);\n }\n\n getCstRoot(): CstNode {\n return this._cst;\n }\n}\n\nexport class FailedMatchResult extends MatchResult {\n /** @internal */\n _rightmostFailurePosition: number;\n /** @internal */\n private _rightmostFailures: Failure[] | null = null;\n /** @internal */\n private _failureDescriptions: string[] | null = null;\n\n /** @internal */\n protected constructor(\n grammar: Grammar,\n startExpr: string,\n ctx: MatchContext,\n succeeded: boolean,\n rightmostFailurePosition: number\n ) {\n super(grammar, startExpr, ctx, succeeded);\n this._rightmostFailurePosition = rightmostFailurePosition;\n }\n\n /** @internal */\n private _assertAttached(property: string) {\n if (!this._attached) {\n throw new Error(\n `Cannot access '${property}' after MatchResult has been disposed. ` +\n `Access failure information before calling dispose(), or use result.use().`\n );\n }\n }\n\n getRightmostFailurePosition(): number {\n return this._rightmostFailurePosition;\n }\n\n getRightmostFailures(): Failure[] {\n if (this._rightmostFailures === null) {\n this._assertAttached('getRightmostFailures()');\n const {exports} = (this.grammar as any)._instance;\n const ruleIds = (this.grammar as any)._ruleIds;\n const ruleNames = (this.grammar as any)._ruleNames;\n exports.recordFailures(ruleIds.get(ruleNames[0]));\n\n // Use a Map to deduplicate by description while preserving fluffy status.\n // A failure is only fluffy if ALL occurrences are fluffy.\n const failureMap = new Map<string, boolean>();\n const len = exports.getRecordedFailuresLength();\n for (let i = 0; i < len; i++) {\n const id = exports.recordedFailuresAt(i);\n const desc = this.grammar.getFailureDescription(id);\n const fluffy = exports.isFluffy(i);\n if (failureMap.has(desc)) {\n // Only keep fluffy=true if both are fluffy\n failureMap.set(desc, failureMap.get(desc)! && fluffy);\n } else {\n failureMap.set(desc, fluffy);\n }\n }\n\n this._rightmostFailures = Array.from(failureMap.entries()).map(\n ([desc, fluffy]) => new Failure(desc, fluffy)\n );\n }\n return this._rightmostFailures;\n }\n\n // Get the non-fluffy failure descriptions.\n /** @internal */\n private _getFailureDescriptions(): string[] {\n if (this._failureDescriptions === null) {\n this._failureDescriptions = this.getRightmostFailures()\n .filter(f => !f.isFluffy())\n .map(f => f.toString());\n }\n return this._failureDescriptions;\n }\n\n // Return a string summarizing the expected contents of the input stream when\n // the match failure occurred.\n getExpectedText(): string {\n assert(!this._succeeded, 'cannot get expected text of a successful MatchResult');\n const descriptions = this._getFailureDescriptions();\n switch (descriptions.length) {\n case 0:\n return '';\n case 1:\n return descriptions[0];\n case 2:\n return descriptions[0] + ' or ' + descriptions[1];\n default:\n // For 3+ items: \"a, b, or c\"\n return (\n descriptions.slice(0, -1).join(', ') +\n ', or ' +\n descriptions[descriptions.length - 1]\n );\n }\n }\n\n getInterval(): Interval {\n const pos = this.getRightmostFailurePosition();\n return new Interval(this.input, pos, pos);\n }\n\n get message(): string {\n const detail = 'Expected ' + this.getExpectedText();\n return getLineAndColumnMessage(this.input, this.getRightmostFailurePosition()) + detail;\n }\n\n get shortMessage(): string {\n const detail = 'expected ' + this.getExpectedText();\n const errorInfo = getLineAndColumn(this.input, this.getRightmostFailurePosition());\n return 'Line ' + errorInfo.lineNum + ', col ' + errorInfo.colNum + ': ' + detail;\n }\n}\n"],"mappings":";AAAA,SAAgB,OAAO,MAAe,UAAU,oBAAkC;AAChF,KAAI,CAAC,KAAM,OAAM,IAAI,MAAM,QAAQ;;AAGrC,SAAgB,aAAgB,GAAM,MAAM,yBAAyC;AACnF,QAA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IAAI,SAAS,KAAK,OAAO,KAAK,IAAI;;CAG3C,IAAI,UAAkB;EACpB,MAAM,SAAS,cAAc,KAAK,iBAAiB;AACnD,SAAO,wBAAwB,KAAK,OAAO,KAAK,6BAA6B,CAAC,GAAG;;CAGnF,IAAI,eAAuB;EACzB,MAAM,SAAS,cAAc,KAAK,iBAAiB;EACnD,MAAM,YAAY,iBAAiB,KAAK,OAAO,KAAK,6BAA6B,CAAC;AAClF,SAAO,UAAU,UAAU,UAAU,WAAW,UAAU,SAAS,OAAO"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/assert.ts","../src/extras.ts","../src/miniohm.ts"],"sourcesContent":["export function assert(cond: boolean, message = 'Assertion failed'): asserts cond {\n if (!cond) throw new Error(message);\n}\n\nexport function checkNotNull<T>(x: T, msg = 'unexpected null value'): NonNullable<T> {\n assert(x != null, msg);\n return x as NonNullable<T>;\n}\n","// Self-contained copies of getLineAndColumn / getLineAndColumnMessage,\n// originally from packages/ohm-js/src/util.js. Inlined here so the runtime\n// package has zero dependency on the legacy engine.\n\nfunction repeatStr(str: string, n: number): string {\n return new Array(n + 1).join(str);\n}\n\nfunction padLeft(str: string, len: number, ch = ' '): string {\n if (str.length < len) {\n return repeatStr(ch, len - str.length) + str;\n }\n return str;\n}\n\nfunction padNumbersToEqualLength(arr: number[]): string[] {\n let maxLen = 0;\n const strings = arr.map(n => {\n const str = n.toString();\n maxLen = Math.max(maxLen, str.length);\n return str;\n });\n return strings.map(s => padLeft(s, maxLen));\n}\n\nfunction strcpy(dest: string, src: string, offset: number): string {\n const origDestLen = dest.length;\n const start = dest.slice(0, offset);\n const end = dest.slice(offset + src.length);\n return (start + src + end).substr(0, origDestLen);\n}\n\ninterface LineAndColumnInfo {\n offset: number;\n lineNum: number;\n colNum: number;\n line: string;\n prevLine: string | null;\n nextLine: string | null;\n toString(...ranges: [number, number][]): string;\n}\n\nfunction lineAndColumnToMessage(\n this: LineAndColumnInfo,\n ...ranges: [number, number][]\n): string {\n const lineAndCol = this;\n const {offset} = lineAndCol;\n\n let result = '';\n result += 'Line ' + lineAndCol.lineNum + ', col ' + lineAndCol.colNum + ':\\n';\n\n const lineNumbers = padNumbersToEqualLength([\n lineAndCol.prevLine == null ? 0 : lineAndCol.lineNum - 1,\n lineAndCol.lineNum,\n lineAndCol.nextLine == null ? 0 : lineAndCol.lineNum + 1,\n ]);\n\n const appendLine = (num: number, content: string, prefix: string) => {\n result += prefix + lineNumbers[num] + ' | ' + content + '\\n';\n };\n\n if (lineAndCol.prevLine != null) {\n appendLine(0, lineAndCol.prevLine, ' ');\n }\n appendLine(1, lineAndCol.line, '> ');\n\n const lineLen = lineAndCol.line.length;\n let indicationLine = repeatStr(' ', lineLen + 1);\n for (let i = 0; i < ranges.length; ++i) {\n let startIdx = ranges[i][0];\n let endIdx = ranges[i][1];\n if (!(startIdx >= 0 && startIdx <= endIdx)) {\n throw new Error('range start must be >= 0 and <= end');\n }\n\n const lineStartOffset = offset - lineAndCol.colNum + 1;\n startIdx = Math.max(0, startIdx - lineStartOffset);\n endIdx = Math.min(endIdx - lineStartOffset, lineLen);\n\n indicationLine = strcpy(indicationLine, repeatStr('~', endIdx - startIdx), startIdx);\n }\n const gutterWidth = 2 + lineNumbers[1].length + 3;\n result += repeatStr(' ', gutterWidth);\n indicationLine = strcpy(indicationLine, '^', lineAndCol.colNum - 1);\n result += indicationLine.replace(/ +$/, '') + '\\n';\n\n if (lineAndCol.nextLine != null) {\n appendLine(2, lineAndCol.nextLine, ' ');\n }\n return result;\n}\n\nexport function getLineAndColumn(str: string, offset: number): LineAndColumnInfo {\n let lineNum = 1;\n let colNum = 1;\n\n let currOffset = 0;\n let lineStartOffset = 0;\n\n let nextLine: string | null = null;\n let prevLine: string | null = null;\n let prevLineStartOffset = -1;\n\n while (currOffset < offset) {\n const c = str.charAt(currOffset++);\n if (c === '\\n') {\n lineNum++;\n colNum = 1;\n prevLineStartOffset = lineStartOffset;\n lineStartOffset = currOffset;\n } else if (c !== '\\r') {\n colNum++;\n }\n }\n\n // Find the end of the target line.\n let lineEndOffset = str.indexOf('\\n', lineStartOffset);\n if (lineEndOffset === -1) {\n lineEndOffset = str.length;\n } else {\n // Get the next line.\n const nextLineEndOffset = str.indexOf('\\n', lineEndOffset + 1);\n nextLine =\n nextLineEndOffset === -1\n ? str.slice(lineEndOffset)\n : str.slice(lineEndOffset, nextLineEndOffset);\n // Strip leading and trailing EOL char(s).\n nextLine = nextLine.replace(/^\\r?\\n/, '').replace(/\\r$/, '');\n }\n\n // Get the previous line.\n if (prevLineStartOffset >= 0) {\n // Strip trailing EOL char(s).\n prevLine = str.slice(prevLineStartOffset, lineStartOffset).replace(/\\r?\\n$/, '');\n }\n\n // Get the target line, stripping a trailing carriage return if necessary.\n const line = str.slice(lineStartOffset, lineEndOffset).replace(/\\r$/, '');\n\n return {\n offset,\n lineNum,\n colNum,\n line,\n prevLine,\n nextLine,\n toString: lineAndColumnToMessage,\n };\n}\n\nexport function getLineAndColumnMessage(\n str: string,\n offset: number,\n ...ranges: [number, number][]\n): string {\n return getLineAndColumn(str, offset).toString(...ranges);\n}\n","import {assert, checkNotNull} from './assert.ts';\nimport {getLineAndColumn, getLineAndColumnMessage} from './extras.ts';\n\nconst MATCH_RECORD_TYPE_MASK = 0b11;\n\n// A MatchRecord is the representation of a CstNode in Wasm linear memory.\nconst MatchRecordType = {\n NONTERMINAL: 0,\n TERMINAL: 1,\n ITER_FLAG: 2,\n OPTIONAL: 3,\n} as const;\n\n// A _CST node_ is the user-facing representation, built from a match record.\nexport const CstNodeType = {\n NONTERMINAL: 0,\n TERMINAL: 1,\n LIST: 2,\n OPT: 3,\n SEQ: 4,\n} as const;\n\n// Define types with the same name as the values above. This gives us roughly the\n// same functionality as a TypeScript enum, but works with erasableSyntaxOnly.\ntype MatchRecordType = (typeof MatchRecordType)[keyof typeof MatchRecordType];\nexport type CstNodeType = (typeof CstNodeType)[keyof typeof CstNodeType];\n\nconst EMPTY_CHILDREN: ReadonlyArray<CstNode> = Object.freeze([]);\n\n// Bit flags for Unicode categories, based on the order that they appear in\n// https://www.unicode.org/Public/16.0.0/ucd/extracted/DerivedGeneralCategory.txt\n\nconst UnicodeCategoryNames = [\n 'Cn', // Unassigned\n 'Lu', // Uppercase_Letter\n 'Ll', // Lowercase_Letter\n 'Lt', // Titlecase_Letter\n 'Lm', // Modifier_Letter\n 'Lo', // Other_Letter\n];\n\nconst utf8 = new TextDecoder('utf-8');\nconst utf16le = new TextDecoder('utf-16le');\n\n// Minimal implementation of Interval (for FailedMatchResult)\nexport class Interval {\n startIdx: number;\n endIdx: number;\n /** @internal */\n private _sourceString: string;\n\n constructor(sourceString: string, startIdx: number, endIdx: number) {\n this._sourceString = sourceString;\n this.startIdx = startIdx;\n this.endIdx = endIdx;\n }\n\n get sourceString(): string {\n return this._sourceString;\n }\n\n get contents(): string {\n return this._sourceString.slice(this.startIdx, this.endIdx);\n }\n}\n\nexport class Failure {\n /** @internal */\n private _description: string;\n /** @internal */\n private _fluffy: boolean;\n\n constructor(description: string, fluffy: boolean) {\n this._description = description;\n this._fluffy = fluffy;\n }\n\n isFluffy(): boolean {\n return this._fluffy;\n }\n\n toString(): string {\n return this._description;\n }\n}\n\nfunction regexFromCategoryBitmap(bitmap: number): RegExp {\n const cats: string[] = [];\n for (let i = 0; i < 32; i++) {\n const mask = 1 << i;\n if (bitmap & mask) cats.push(UnicodeCategoryNames[i]);\n }\n return new RegExp(\n cats.map(cat => `\\\\p{${cat}}`).join('|'),\n 'uy' // u: unicode, y: sticky\n );\n}\n\nfunction parseStringTable(module: WebAssembly.Module, sectionName: string): string[] {\n const sections = WebAssembly.Module.customSections(module, sectionName);\n assert(\n sections.length === 1,\n `Expected one ${sectionName} section, found ${sections.length}`\n );\n\n const data = new Uint8Array(sections[0]);\n const dataView = new DataView(data.buffer);\n let offset = 0;\n\n const parseU32 = (): number => {\n // Quick 'n dirty ULeb128 parsing, assuming no more than 2 bytes.\n const b1 = dataView.getUint8(offset++);\n let value = b1 & 0x7f;\n if (b1 & 0x80) {\n const b2 = dataView.getUint8(offset++);\n assert((b2 & 0x80) === 0, 'Expected max two bytes');\n value |= (b2 & 0x7f) << 7;\n }\n return value;\n };\n\n const numEntries = parseU32();\n const ans: string[] = [];\n for (let i = 0; i < numEntries; i++) {\n const stringLen = parseU32();\n const bytes = data.slice(offset, offset + stringLen);\n offset += stringLen;\n const name = utf8.decode(bytes);\n ans.push(name);\n }\n return ans;\n}\n\nexport class Grammar {\n name = '';\n\n /** @internal */\n private _instance?: WebAssembly.Instance = undefined;\n /** @internal */\n private _imports = {\n // System-level AssemblyScript imports.\n env: {\n abort: (msgPtr: number, filePtr: number, line: number, column: number) => {\n const msg = this._readASString(msgPtr);\n const file = this._readASString(filePtr);\n throw new Error(`Wasm abort: ${msg} at ${file}:${line}:${column}`);\n },\n },\n // For imports from ohmRuntime.ts.\n ohmRuntime: {\n printI32(val: number) {\n // eslint-disable-next-line no-console\n console.log(val);\n },\n fillInputBuffer: this._fillInputBuffer.bind(this),\n matchUnicodeChar: (catBitmap: number) => {\n const {pos} = (this._instance as any).exports;\n const re = regexFromCategoryBitmap(catBitmap);\n re.lastIndex = pos;\n const arr = re.exec(this._input);\n if (arr) {\n pos.value += arr[0].length;\n }\n return !!arr;\n },\n matchCaseInsensitive: (() => {\n const cache: RegExp[] = [];\n return (stringIdx: number) => {\n const {pos} = (this._instance as any).exports;\n let re = cache[stringIdx];\n if (!re) {\n // The pattern is pre-escaped at compile time.\n re = cache[stringIdx] = new RegExp(this._strings[stringIdx], 'iy');\n }\n re.lastIndex = pos.value;\n const arr = re.exec(this._input);\n if (arr) {\n pos.value += arr[0].length;\n }\n return !!arr;\n };\n })(),\n },\n };\n /** @internal */\n private _ruleIds = new Map<string, number>();\n /** @internal */\n private _ruleNames: string[] = [];\n /** @internal */\n private _input = '';\n\n /** @internal */\n public _strings: string[] = [];\n\n /*\n * Wasm heap memory management\n * ===========================\n *\n * The Wasm module uses a bump-pointer allocator (AssemblyScript's \"stub\"\n * runtime). Each match() call allocates a memo table and CST nodes on\n * the Wasm heap. There is no way to free individual allocations — you\n * can only reset the bump pointer.\n *\n * To allow incremental freeing, we exploit two facts:\n *\n * 1. MatchResult disposal is LIFO — you must dispose the most recent\n * result first (enforced by an assert in _dispose).\n *\n * 2. Allocations for match N are always contiguous and sit above\n * match N-1's allocations on the heap.\n *\n * Before each match, we snapshot the bump pointer (`exports.__offset`)\n * as a \"watermark\" and store it on the MatchResult. On dispose, we\n * reset the bump pointer to that watermark, freeing exactly that\n * match's allocations while keeping earlier results intact.\n *\n * When the last result is disposed, its watermark equals the initial\n * heap offset, so the entire heap is reclaimed — equivalent to the\n * old resetHeap() approach, but without the all-or-nothing limitation.\n */\n\n /** @internal */\n private _resultStack: MatchResult[] = [];\n\n /**\n * Create a new Grammar object.\n * If `bytes` is specified, the WebAssembly module will be synchronously\n * compiled and instantiated. Use `instantiate` or `instantiateStreaming`\n * to instantiate asynchronously.\n */\n constructor(bytes?: BufferSource) {\n if (bytes) {\n const mod = new WebAssembly.Module(bytes);\n this._init(mod, new WebAssembly.Instance(mod, this._imports));\n }\n }\n\n /** @internal */\n private _init(module: WebAssembly.Module, instance: WebAssembly.Instance) {\n this._instance = instance;\n this._extractStrings(module);\n this.name = this._getGrammarName(module);\n return this;\n }\n\n /** @internal */\n _manage(result: MatchResult): void {\n result._managed = true;\n }\n\n /** @internal */\n _dispose(result: MatchResult): void {\n assert(\n this._resultStack.at(-1) === result,\n `You can only dispose() the most recent MatchResult`\n );\n this._resultStack.pop();\n // Reset the bump-pointer allocator to the watermark recorded before this\n // match. Because disposal is LIFO, this frees exactly this match's\n // allocations (memo table + CST nodes) while keeping earlier ones intact.\n (this._instance as any).exports.__offset.value = result._heapWatermark;\n result._attached = false;\n result._ctx.view = new DataView(new ArrayBuffer(0));\n }\n\n static async instantiate(source: BufferSource): Promise<Grammar> {\n return new Grammar()._instantiate(source);\n }\n\n static async instantiateStreaming(source: Response | Promise<Response>): Promise<Grammar> {\n return new Grammar()._instantiateStreaming(source);\n }\n\n /** @internal */\n async _instantiate(source: BufferSource, debugImports: any = {}): Promise<Grammar> {\n const {module, instance} = await WebAssembly.instantiate(source, {\n ...this._imports,\n debug: debugImports,\n });\n return this._init(module, instance);\n }\n\n /** @internal */\n async _instantiateStreaming(\n source: Response | Promise<Response>,\n debugImports: any = {}\n ): Promise<Grammar> {\n const {module, instance} = await WebAssembly.instantiateStreaming(source, {\n ...this._imports,\n debug: debugImports,\n });\n return this._init(module, instance);\n }\n\n /** @internal */\n private _getGrammarName(module: WebAssembly.Module): string {\n const sections = WebAssembly.Module.customSections(module, 'name');\n assert(sections.length === 1, `Expected one name section, found ${sections.length}`);\n const data = new Uint8Array(sections[0]);\n return utf8.decode(data);\n }\n\n /** @internal */\n private _extractStrings(module: WebAssembly.Module): void {\n assert(this._ruleNames.length === 0);\n assert(this._ruleIds.size === 0);\n for (const ruleName of parseStringTable(module, 'ruleNames')) {\n this._ruleIds.set(ruleName, this._ruleIds.size);\n this._ruleNames.push(ruleName);\n }\n for (const str of parseStringTable(module, 'strings')) {\n this._strings.push(str);\n }\n }\n\n match<T>(input: string, ruleName?: string): MatchResult {\n assert(\n this._resultStack.every(r => r._managed),\n 'Cannot match while there are unmanaged MatchResults. ' +\n 'Use `using` or `.use()` to manage the MatchResult lifecycle.'\n );\n this._input = input;\n if (typeof process !== 'undefined' && process.env.OHM_DEBUG === '1') debugger; // eslint-disable-line no-debugger\n const exports = (this._instance as any).exports;\n const ruleId = checkNotNull(\n this._ruleIds.get(ruleName || this._ruleNames[0]),\n `unknown rule: '${ruleName}'`\n );\n const heapWatermark = exports.__offset.value;\n const succeeded = exports.match(input.length, ruleId);\n const buffer = exports.memory.buffer;\n\n // If the Wasm match triggered memory.grow() (e.g. for the memo table or\n // CST nodes), the old ArrayBuffer is detached. Refresh the DataView in\n // all existing match contexts so that their CstNodes can still read data.\n for (const r of this._resultStack) {\n if (r._ctx.view.buffer !== buffer) {\n r._ctx.view = new DataView(buffer);\n }\n }\n\n const ctx: MatchContext = {\n ruleNames: this._ruleNames,\n view: new DataView(buffer),\n input,\n };\n const result = createMatchResult(this, ruleName || this._ruleNames[0], ctx, !!succeeded);\n result._heapWatermark = heapWatermark;\n result.dispose = this._dispose.bind(this, result);\n this._resultStack.push(result);\n return result;\n }\n\n /** @internal */\n recordFailures(): number[] {\n const {exports} = this._instance as any;\n exports.recordFailures(this._input.length, this._ruleIds.get(this._ruleNames[0]));\n const ans: number[] = [];\n for (let i = 0; i < exports.getRecordedFailuresLength(); i++) {\n if (!exports.isFluffy(i)) {\n // Filter out fluffy failures\n ans.push(exports.recordedFailuresAt(i));\n }\n }\n // Deduplicate\n return [...new Set(ans)];\n }\n\n getFailureDescription(id: number): string {\n return this._strings[id];\n }\n\n getMemorySizeBytes(): number {\n return (this._instance as any).exports.memory.buffer.byteLength;\n }\n\n /** @internal Read an AssemblyScript string from Wasm linear memory. */\n private _readASString(ptr: number): string {\n if (!ptr || !this._instance) return '(unknown)';\n try {\n const buffer = (this._instance as any).exports.memory.buffer;\n // AS managed object layout: rtSize (byte length) is at ptr - 4.\n const byteLen = new DataView(buffer).getUint32(ptr - 4, true);\n return utf16le.decode(new Uint8Array(buffer, ptr, byteLen));\n } catch {\n return `(ptr=${ptr})`;\n }\n }\n\n /** @internal */\n _getCstRoot(ctx?: MatchContext): CstNode {\n const {exports} = this._instance as any;\n ctx ??= {\n ruleNames: this._ruleNames,\n view: new DataView(exports.memory.buffer),\n input: this._input,\n };\n const firstNode = new CstNodeImpl(ctx, exports.bindingsAt(0), 0);\n assert(firstNode.isNonterminal());\n if (firstNode.ctorName !== '$spaces') {\n return firstNode;\n }\n assert(exports.getBindingsLength() > 1 && firstNode.ctorName === '$spaces');\n const nextAddr = exports.bindingsAt(1);\n const root = new CstNodeImpl(ctx, nextAddr, firstNode.matchLength);\n root.leadingSpaces = firstNode;\n return root as CstNode;\n }\n\n /** @internal */\n private _fillInputBuffer(ptr: number, length: number): number {\n const {memory} = (this._instance as any).exports;\n const buf = new Uint16Array(memory.buffer, ptr, length);\n for (let i = 0; i < length; i++) {\n buf[i] = this._input.charCodeAt(i);\n }\n return length;\n }\n\n getRightmostFailurePosition(): number {\n return (this._instance as any).exports.rightmostFailurePos.value;\n }\n}\n\ninterface MatchContext {\n ruleNames: string[];\n view: DataView;\n input: string;\n}\n\nexport type CstNode = NonterminalNode | TerminalNode | ListNode | OptNode | SeqNode;\nexport type CstNodeChildren = readonly CstNode[];\n\nexport interface CstNodeBase {\n ctorName: string;\n source: {startIdx: number; endIdx: number};\n sourceString: string;\n matchLength: number;\n\n isNonterminal(): this is NonterminalNode;\n isTerminal(): this is TerminalNode;\n isOptional(): this is OptNode;\n isSeq(): this is SeqNode;\n isList(): this is ListNode;\n}\n\nexport interface NonterminalNode<TChildren extends CstNodeChildren = CstNodeChildren>\n extends CstNodeBase {\n type: typeof CstNodeType.NONTERMINAL;\n ctorName: string;\n leadingSpaces?: NonterminalNode;\n children: TChildren;\n\n isSyntactic(): boolean;\n isLexical(): boolean;\n}\n\nexport interface TerminalNode extends CstNodeBase {\n type: typeof CstNodeType.TERMINAL;\n ctorName: '_terminal';\n leadingSpaces?: NonterminalNode;\n children: readonly [];\n value: string;\n}\n\nexport interface ListNode<TNode extends CstNode = CstNode> extends CstNodeBase {\n type: typeof CstNodeType.LIST;\n ctorName: '_list';\n children: readonly TNode[];\n collect: <R>(cb: (...children: CstNode[]) => R) => R[];\n}\n\nexport interface OptNode<TChild extends CstNode = CstNode> extends CstNodeBase {\n type: typeof CstNodeType.OPT;\n ctorName: '_opt';\n children: [] | [TChild];\n\n // If the child is a SeqNode, the `consume` callback receives its unpacked children.\n // Otherwise, it receives the child node itself.\n ifPresent<R>(\n consume: TChild extends SeqNode<infer T> ? (...children: T) => R : (child: TChild) => R,\n orElse?: () => R\n ): R;\n ifPresent<R>(\n consume: TChild extends SeqNode<infer T> ? (...children: T) => R : (child: TChild) => R\n ): R | undefined;\n isPresent(): boolean;\n isEmpty(): boolean;\n}\n\nexport interface SeqNode<TChildren extends CstNodeChildren = CstNodeChildren>\n extends CstNodeBase {\n type: typeof CstNodeType.SEQ;\n ctorName: '_seq';\n children: TChildren;\n unpack: <R>(cb: (...children: TChildren) => R) => R;\n}\n\nclass CstNodeImpl implements CstNodeBase {\n _ctx!: MatchContext;\n _children?: CstNodeChildren = undefined;\n _base: number;\n startIdx: number;\n leadingSpaces?: NonterminalNode = undefined;\n source: {startIdx: number; endIdx: number};\n\n constructor(ctx: MatchContext, ptr: number, startIdx: number) {\n // Non-enumerable properties\n Object.defineProperties(this, {\n _ctx: {value: ctx},\n _children: {writable: true},\n });\n this._base = ptr;\n this.startIdx = startIdx;\n this.source = {\n startIdx,\n endIdx: startIdx + this.sourceString.length,\n };\n if (this.matchRecordType === MatchRecordType.TERMINAL || this.count === 0) {\n this._children = EMPTY_CHILDREN;\n }\n }\n\n get type(): CstNodeType {\n switch (this._typeAndDetails & MATCH_RECORD_TYPE_MASK) {\n case MatchRecordType.NONTERMINAL:\n return CstNodeType.NONTERMINAL;\n case MatchRecordType.TERMINAL:\n return CstNodeType.TERMINAL;\n case MatchRecordType.ITER_FLAG:\n return CstNodeType.LIST;\n default:\n throw new Error('unreachable');\n }\n }\n\n private get matchRecordType(): MatchRecordType {\n return (this._typeAndDetails & MATCH_RECORD_TYPE_MASK) as MatchRecordType;\n }\n\n isNonterminal(): this is NonterminalNode {\n return this.type === CstNodeType.NONTERMINAL;\n }\n\n isTerminal(): this is TerminalNode {\n return this.type === CstNodeType.TERMINAL;\n }\n\n isList(): this is ListNode {\n return this.type === CstNodeType.LIST;\n }\n\n isOptional(): this is OptNode {\n return this.type === CstNodeType.OPT;\n }\n\n isSeq(): this is SeqNode {\n return this.type === CstNodeType.SEQ;\n }\n\n get ctorName(): string {\n switch (this.type) {\n case CstNodeType.NONTERMINAL: {\n const {ruleNames, view} = this._ctx;\n const ruleId = view.getInt32(this._base + 8, true) >>> 2;\n return ruleNames[ruleId].split('<')[0];\n }\n case CstNodeType.TERMINAL:\n return '_terminal';\n case CstNodeType.LIST:\n return '_list';\n case CstNodeType.OPT:\n return '_opt';\n case CstNodeType.SEQ:\n return '_seq';\n }\n }\n\n get count(): number {\n return this._ctx.view.getUint32(this._base, true);\n }\n\n get matchLength(): number {\n return this._ctx.view.getUint32(this._base + 4, true);\n }\n\n get _typeAndDetails(): number {\n return this._ctx.view.getInt32(this._base + 8, true);\n }\n\n get arity(): number {\n return this._typeAndDetails >>> 2;\n }\n\n get children(): CstNodeChildren {\n if (!this._children) {\n this._children = this._computeChildren().map((n): CstNode => {\n const {matchRecordType} = n;\n if (matchRecordType === MatchRecordType.OPTIONAL) {\n const child: CstNode | undefined =\n n.children.length <= 1\n ? n.children[0]\n : new SeqNodeImpl(n.children, n.source, n.sourceString);\n return new OptNodeImpl(child, n.source, n.sourceString);\n } else if (matchRecordType === MatchRecordType.ITER_FLAG) {\n if (n.arity <= 1) {\n return new ListNodeImpl(n.children, n.source, n.sourceString);\n }\n const arr: CstNode[] = [];\n let startIdx = n.startIdx;\n for (let i = 0; i < n.children.length; i += n.arity) {\n // FIXME: We don't need any of this nonsense if we actually build the SeqNodes at parse time.\n const seqChildren = n.children.slice(i, i + n.arity);\n const endIdx = checkNotNull(seqChildren.at(-1)).source.endIdx;\n const sourceString = n._ctx.input.slice(startIdx, endIdx);\n arr.push(new SeqNodeImpl(seqChildren, {startIdx, endIdx}, sourceString));\n startIdx = endIdx;\n }\n assert(startIdx === n.source.endIdx);\n return new ListNodeImpl(arr, n.source, n.sourceString);\n }\n return n as CstNode; // FIXME\n });\n }\n return this._children;\n }\n\n _computeChildren(): CstNodeImpl[] {\n const children: CstNodeImpl[] = [];\n const {ruleNames, view, input} = this._ctx;\n let spaces: NonterminalNode | undefined;\n let {startIdx} = this;\n for (let i = 0; i < this.count; i++) {\n const slotOffset = this._base + 16 + i * 4;\n const ptr = view.getUint32(slotOffset, true);\n // TODO: Avoid allocating $spaces nodes altogether?\n const node = new CstNodeImpl(this._ctx, ptr, startIdx);\n if (\n node.matchRecordType === MatchRecordType.NONTERMINAL &&\n node.ctorName === '$spaces'\n ) {\n assert(!spaces, 'Multiple $spaces nodes found');\n spaces = node as NonterminalNode; // FIXME\n } else {\n if (spaces) {\n node.leadingSpaces = spaces;\n spaces = undefined;\n }\n children.push(node);\n }\n startIdx += node.matchLength;\n }\n assert(spaces === undefined, 'Unclaimed $spaces!');\n return children;\n }\n\n get sourceString(): string {\n return this._ctx.input.slice(this.startIdx, this.startIdx + this.matchLength);\n }\n\n isSyntactic(): boolean {\n assert(this.isNonterminal(), 'Not a nonterminal');\n const firstChar = this.ctorName[0];\n return firstChar === firstChar.toUpperCase();\n }\n\n isLexical(): boolean {\n assert(this.isNonterminal(), 'Not a nonterminal');\n return !this.isSyntactic();\n }\n\n toString(): string {\n const ctorName = this.isTerminal() ? '_terminal' : this.isSeq() ? '_iter' : this.ctorName;\n const {sourceString, startIdx} = this;\n return `CstNode {ctorName: ${ctorName}, sourceString: ${sourceString}, startIdx: ${startIdx} }`;\n }\n}\n\nabstract class WrapperNode implements CstNodeBase {\n abstract ctorName: string;\n source: {startIdx: number; endIdx: number};\n sourceString: string;\n\n constructor(source: {startIdx: number; endIdx: number}, sourceString: string) {\n this.source = source;\n this.sourceString = sourceString;\n }\n\n get matchLength(): number {\n return this.sourceString.length;\n }\n\n isNonterminal(): this is NonterminalNode {\n return false;\n }\n isTerminal(): this is TerminalNode {\n return false;\n }\n isOptional(): this is OptNode {\n return false;\n }\n isSeq(): this is SeqNode {\n return false;\n }\n isList(): this is ListNode {\n return false;\n }\n}\n\nclass SeqNodeImpl<TChildren extends CstNodeChildren = CstNodeChildren>\n extends WrapperNode\n implements SeqNode<TChildren>\n{\n type: typeof CstNodeType.SEQ = CstNodeType.SEQ;\n ctorName = '_seq' as const;\n children: TChildren;\n\n constructor(\n children: TChildren,\n source: {startIdx: number; endIdx: number},\n sourceString: string\n ) {\n super(source, sourceString);\n this.children = children;\n }\n\n override isSeq(): this is SeqNode {\n return true;\n }\n\n unpack<R>(cb: (...args: TChildren) => R): R {\n assert(\n cb.length === this.children.length,\n `bad arity: expected ${this.children.length}, got ${cb.length}`\n );\n return cb.call(null, ...this.children); // FIXME\n }\n}\n\nclass ListNodeImpl<TNode extends CstNode = CstNode>\n extends WrapperNode\n implements ListNode<TNode>\n{\n type: typeof CstNodeType.LIST = CstNodeType.LIST;\n ctorName = '_list' as const;\n children: readonly TNode[];\n\n constructor(\n children: readonly TNode[],\n source: {startIdx: number; endIdx: number},\n sourceString: string\n ) {\n super(source, sourceString);\n this.children = children;\n }\n\n override isList(): this is ListNode {\n return true;\n }\n\n collect<R>(cb: (...args: CstNode[]) => R): R[] {\n return this.children.map(c => {\n return c?.isSeq() ? c.unpack(cb) : cb(c);\n });\n }\n}\n\nclass OptNodeImpl<TNode extends CstNode = CstNode>\n extends WrapperNode\n implements OptNode<TNode>\n{\n type: typeof CstNodeType.OPT = CstNodeType.OPT;\n ctorName = '_opt' as const;\n children: [] | [TNode];\n\n constructor(\n child: TNode | undefined,\n source: {startIdx: number; endIdx: number},\n sourceString: string\n ) {\n super(source, sourceString);\n this.children = child ? [child] : [];\n }\n\n override isOptional(): this is OptNode {\n return true;\n }\n\n ifPresent<R>(\n consume: TNode extends SeqNode<infer T> ? (...children: T) => R : (child: TNode) => R,\n orElse?: () => R\n ): R | undefined {\n const child = this.children[0];\n if (child) {\n return child.isSeq()\n ? child.unpack(consume as (...children: any[]) => R)\n : (consume as (child: TNode) => R)(child);\n }\n if (orElse) return orElse();\n }\n\n isPresent(): boolean {\n return this.children.length > 0;\n }\n\n isEmpty(): boolean {\n return this.children.length === 0;\n }\n}\n\nexport abstract class MatchResult {\n // Note: This is different from the JS implementation, which has:\n // matcher: Matcher;\n // …instead.\n grammar: Grammar;\n startExpr: string;\n /** @internal */\n _ctx: MatchContext;\n /** @internal */\n _succeeded: boolean;\n /** @internal */\n _attached = true;\n /** @internal */\n _managed = false;\n /** @internal */\n _heapWatermark = 0;\n\n /** @internal */\n protected constructor(\n grammar: Grammar,\n startExpr: string,\n ctx: MatchContext,\n succeeded: boolean\n ) {\n this.grammar = grammar;\n this.startExpr = startExpr;\n this._ctx = ctx;\n this._succeeded = succeeded;\n }\n\n get input(): string {\n return (this.grammar as any)._input;\n }\n\n // `using` accesses [Symbol.dispose] at declaration time to get the\n // disposal method. We use this as the signal that the result is managed.\n get [Symbol.dispose](): () => void {\n this.grammar._manage(this);\n return () => this.dispose();\n }\n\n dispose(): void {\n throw new Error('MatchResult is not attached to any grammar');\n }\n\n succeeded(): this is SucceededMatchResult {\n return this._succeeded;\n }\n\n failed(): this is FailedMatchResult {\n return !this._succeeded;\n }\n\n toString(): string {\n return this.failed()\n ? '[match failed at position ' + this.getRightmostFailurePosition() + ']'\n : '[match succeeded]';\n }\n\n use<T>(cb: (r: this) => T): T {\n this.grammar._manage(this);\n try {\n return cb(this);\n } finally {\n this.dispose();\n }\n }\n}\n\nfunction createMatchResult(\n grammar: Grammar,\n startExpr: string,\n ctx: MatchContext,\n succeeded: boolean\n): MatchResult {\n return succeeded\n ? new SucceededMatchResult(grammar, startExpr, ctx, succeeded)\n : new FailedMatchResult(\n grammar,\n startExpr,\n ctx,\n succeeded,\n grammar.getRightmostFailurePosition()\n );\n}\n\nexport class SucceededMatchResult extends MatchResult {\n /** @internal */\n _cst: CstNode;\n\n /** @internal */\n protected constructor(\n grammar: Grammar,\n startExpr: string,\n ctx: MatchContext,\n succeeded: boolean\n ) {\n super(grammar, startExpr, ctx, succeeded);\n this._cst = grammar._getCstRoot(ctx);\n }\n\n getCstRoot(): CstNode {\n return this._cst;\n }\n}\n\nexport class FailedMatchResult extends MatchResult {\n /** @internal */\n _rightmostFailurePosition: number;\n /** @internal */\n private _rightmostFailures: Failure[] | null = null;\n /** @internal */\n private _failureDescriptions: string[] | null = null;\n\n /** @internal */\n protected constructor(\n grammar: Grammar,\n startExpr: string,\n ctx: MatchContext,\n succeeded: boolean,\n rightmostFailurePosition: number\n ) {\n super(grammar, startExpr, ctx, succeeded);\n this._rightmostFailurePosition = rightmostFailurePosition;\n }\n\n /** @internal */\n private _assertAttached(property: string) {\n if (!this._attached) {\n throw new Error(\n `Cannot access '${property}' after MatchResult has been disposed. ` +\n `Access failure information before calling dispose(), or use result.use().`\n );\n }\n }\n\n getRightmostFailurePosition(): number {\n return this._rightmostFailurePosition;\n }\n\n getRightmostFailures(): Failure[] {\n if (this._rightmostFailures === null) {\n this._assertAttached('getRightmostFailures()');\n const {exports} = (this.grammar as any)._instance;\n const ruleIds = (this.grammar as any)._ruleIds;\n const ruleNames = (this.grammar as any)._ruleNames;\n const inputLength = (this.grammar as any)._input.length;\n exports.recordFailures(inputLength, ruleIds.get(ruleNames[0]));\n\n // Use a Map to deduplicate by description while preserving fluffy status.\n // A failure is only fluffy if ALL occurrences are fluffy.\n const failureMap = new Map<string, boolean>();\n const len = exports.getRecordedFailuresLength();\n for (let i = 0; i < len; i++) {\n const id = exports.recordedFailuresAt(i);\n const desc = this.grammar.getFailureDescription(id);\n const fluffy = exports.isFluffy(i);\n if (failureMap.has(desc)) {\n // Only keep fluffy=true if both are fluffy\n failureMap.set(desc, failureMap.get(desc)! && fluffy);\n } else {\n failureMap.set(desc, fluffy);\n }\n }\n\n this._rightmostFailures = Array.from(failureMap.entries()).map(\n ([desc, fluffy]) => new Failure(desc, fluffy)\n );\n }\n return this._rightmostFailures;\n }\n\n // Get the non-fluffy failure descriptions.\n /** @internal */\n private _getFailureDescriptions(): string[] {\n if (this._failureDescriptions === null) {\n this._failureDescriptions = this.getRightmostFailures()\n .filter(f => !f.isFluffy())\n .map(f => f.toString());\n }\n return this._failureDescriptions;\n }\n\n // Return a string summarizing the expected contents of the input stream when\n // the match failure occurred.\n getExpectedText(): string {\n assert(!this._succeeded, 'cannot get expected text of a successful MatchResult');\n const descriptions = this._getFailureDescriptions();\n switch (descriptions.length) {\n case 0:\n return '';\n case 1:\n return descriptions[0];\n case 2:\n return descriptions[0] + ' or ' + descriptions[1];\n default:\n // For 3+ items: \"a, b, or c\"\n return (\n descriptions.slice(0, -1).join(', ') +\n ', or ' +\n descriptions[descriptions.length - 1]\n );\n }\n }\n\n getInterval(): Interval {\n const pos = this.getRightmostFailurePosition();\n return new Interval(this.input, pos, pos);\n }\n\n get message(): string {\n const detail = 'Expected ' + this.getExpectedText();\n return getLineAndColumnMessage(this.input, this.getRightmostFailurePosition()) + detail;\n }\n\n get shortMessage(): string {\n const detail = 'expected ' + this.getExpectedText();\n const errorInfo = getLineAndColumn(this.input, this.getRightmostFailurePosition());\n return 'Line ' + errorInfo.lineNum + ', col ' + errorInfo.colNum + ': ' + detail;\n }\n}\n"],"mappings":";AAAA,SAAgB,OAAO,MAAe,UAAU,oBAAkC;AAChF,KAAI,CAAC,KAAM,OAAM,IAAI,MAAM,QAAQ;;AAGrC,SAAgB,aAAgB,GAAM,MAAM,yBAAyC;AACnF,QAAO,KAAK,MAAM,IAAI;AACtB,QAAO;;;;;ACFT,SAAS,UAAU,KAAa,GAAmB;AACjD,QAAO,IAAI,MAAM,IAAI,EAAE,CAAC,KAAK,IAAI;;AAGnC,SAAS,QAAQ,KAAa,KAAa,KAAK,KAAa;AAC3D,KAAI,IAAI,SAAS,IACf,QAAO,UAAU,IAAI,MAAM,IAAI,OAAO,GAAG;AAE3C,QAAO;;AAGT,SAAS,wBAAwB,KAAyB;CACxD,IAAI,SAAS;AAMb,QALgB,IAAI,KAAI,MAAK;EAC3B,MAAM,MAAM,EAAE,UAAU;AACxB,WAAS,KAAK,IAAI,QAAQ,IAAI,OAAO;AACrC,SAAO;GACP,CACa,KAAI,MAAK,QAAQ,GAAG,OAAO,CAAC;;AAG7C,SAAS,OAAO,MAAc,KAAa,QAAwB;CACjE,MAAM,cAAc,KAAK;CACzB,MAAM,QAAQ,KAAK,MAAM,GAAG,OAAO;CACnC,MAAM,MAAM,KAAK,MAAM,SAAS,IAAI,OAAO;AAC3C,SAAQ,QAAQ,MAAM,KAAK,OAAO,GAAG,YAAY;;AAanD,S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