@ohm-js/wasm 0.6.5 → 0.6.6
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/src/miniohm.d.ts +1 -0
- package/dist/src/miniohm.js +8 -0
- package/package.json +1 -1
package/dist/src/miniohm.d.ts
CHANGED
|
@@ -61,6 +61,7 @@ export declare class CstNode {
|
|
|
61
61
|
isLexical(ruleName?: string): boolean;
|
|
62
62
|
toString(): string;
|
|
63
63
|
map<T>(callbackFn: (...args: CstNode[]) => T): T[];
|
|
64
|
+
unpack<T>(someFn: (...args: CstNode[]) => T, noneFn: () => T): T;
|
|
64
65
|
}
|
|
65
66
|
export declare function dumpCstNode(node: CstNode, depth?: number): void;
|
|
66
67
|
export declare class MatchResult {
|
package/dist/src/miniohm.js
CHANGED
|
@@ -328,6 +328,7 @@ export class CstNode {
|
|
|
328
328
|
const { sourceString, startIdx } = this;
|
|
329
329
|
return `CstNode {ctorName: ${ctorName}, sourceString: ${sourceString}, startIdx: ${startIdx} }`;
|
|
330
330
|
}
|
|
331
|
+
// Other possible names: collect, mapChildren, mapUnpack, unpackEach, …
|
|
331
332
|
map(callbackFn) {
|
|
332
333
|
const { arity, children } = this;
|
|
333
334
|
assert(callbackFn.length === arity, 'bad arity');
|
|
@@ -337,6 +338,13 @@ export class CstNode {
|
|
|
337
338
|
}
|
|
338
339
|
return ans;
|
|
339
340
|
}
|
|
341
|
+
unpack(someFn, noneFn) {
|
|
342
|
+
assert(this.isOptional(), 'Not an optional');
|
|
343
|
+
if (this.children.length === 0)
|
|
344
|
+
return noneFn();
|
|
345
|
+
assert(someFn.length === this.children.length, `bad arity: expected ${this.children.length}, got ${someFn.length}`);
|
|
346
|
+
return someFn(...this.children);
|
|
347
|
+
}
|
|
340
348
|
}
|
|
341
349
|
export function dumpCstNode(node, depth = 0) {
|
|
342
350
|
const { _base, children, ctorName, matchLength, startIdx } = node;
|