@ohm-js/wasm 0.7.2 → 0.7.3
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const destImportCount = 5;
|
|
2
|
-
export declare const startFuncidx =
|
|
2
|
+
export declare const startFuncidx = 62;
|
|
3
3
|
export declare const funcidxByName: {
|
|
4
4
|
resetHeap: number;
|
|
5
5
|
match: number;
|
|
@@ -16,14 +16,12 @@ export declare const funcidxByName: {
|
|
|
16
16
|
bindingsAt: number;
|
|
17
17
|
doMatchUnicodeChar: number;
|
|
18
18
|
recordFailure: number;
|
|
19
|
-
makeFluffyFrom: number;
|
|
20
19
|
isFluffy: number;
|
|
21
20
|
getRecordedFailuresLength: number;
|
|
22
21
|
setRecordedFailuresLength: number;
|
|
23
22
|
recordedFailuresAt: number;
|
|
24
23
|
pushFluffySavePoint: number;
|
|
25
|
-
|
|
26
|
-
dropFluffySavePoint: number;
|
|
24
|
+
popFluffySavePoint: number;
|
|
27
25
|
};
|
|
28
26
|
export declare const typesec: {
|
|
29
27
|
entryCount: number;
|
|
@@ -7,26 +7,48 @@ function decodeBase64(str) {
|
|
|
7
7
|
return result;
|
|
8
8
|
}
|
|
9
9
|
export const destImportCount = 5;
|
|
10
|
-
export const startFuncidx =
|
|
11
|
-
export const funcidxByName = {
|
|
10
|
+
export const startFuncidx = 62;
|
|
11
|
+
export const funcidxByName = {
|
|
12
|
+
resetHeap: 22,
|
|
13
|
+
match: 45,
|
|
14
|
+
recordFailures: 46,
|
|
15
|
+
evalApplyGeneralized: 47,
|
|
16
|
+
evalApplyNoMemo0: 48,
|
|
17
|
+
evalApply0: 42,
|
|
18
|
+
handleLeftRecursion: 41,
|
|
19
|
+
newTerminalNode: 49,
|
|
20
|
+
newNonterminalNode: 39,
|
|
21
|
+
newIterationNode: 50,
|
|
22
|
+
getBindingsLength: 51,
|
|
23
|
+
setBindingsLength: 52,
|
|
24
|
+
bindingsAt: 53,
|
|
25
|
+
doMatchUnicodeChar: 54,
|
|
26
|
+
recordFailure: 43,
|
|
27
|
+
isFluffy: 55,
|
|
28
|
+
getRecordedFailuresLength: 56,
|
|
29
|
+
setRecordedFailuresLength: 57,
|
|
30
|
+
recordedFailuresAt: 58,
|
|
31
|
+
pushFluffySavePoint: 59,
|
|
32
|
+
popFluffySavePoint: 61,
|
|
33
|
+
};
|
|
12
34
|
export const typesec = {
|
|
13
35
|
entryCount: 12,
|
|
14
|
-
contents: decodeBase64(
|
|
36
|
+
contents: decodeBase64('YAF/AX9gAn9/AGACf38Bf2AAAGABfwBgAAF/YAR/f39/AGADf39/AGAFf39/f38Bf2ABbwF/YAR/f39/AX9gAm9/AX8='),
|
|
15
37
|
};
|
|
16
38
|
export const importsec = {
|
|
17
39
|
entryCount: 4,
|
|
18
|
-
contents: decodeBase64(
|
|
40
|
+
contents: decodeBase64('A2VudgVhYm9ydAAGDndhc206anMtc3RyaW5nBmxlbmd0aAAJCm9obVJ1bnRpbWUPaXNSdWxlU3ludGFjdGljAAAKb2htUnVudGltZRBtYXRjaFVuaWNvZGVDaGFyAAA='),
|
|
19
41
|
};
|
|
20
42
|
export const funcsec = {
|
|
21
|
-
entryCount:
|
|
22
|
-
contents: decodeBase64(
|
|
43
|
+
entryCount: 58,
|
|
44
|
+
contents: decodeBase64('BAEAAQEBAQIHAQEBAQIDAwMDAwAAAAAAAAICBgACAgACAQgHCgAEAAsEAgACCAUEAAAABQQAAwAEAw=='),
|
|
23
45
|
};
|
|
24
46
|
export const globalsec = {
|
|
25
|
-
entryCount:
|
|
26
|
-
contents: decodeBase64(
|
|
47
|
+
entryCount: 17,
|
|
48
|
+
contents: decodeBase64('fwFBAAt/AUEAC28B0G8LfwFBAAt/AUEAC38BQX8LfwFBAAt/AEEAC38AQQELfwBBAgt/AUEAC38BQQALfwBBAAt/AUEAC38BQQALfwFBAAt/AEGcgwQL'),
|
|
27
49
|
};
|
|
28
50
|
export const codesec = {
|
|
29
|
-
entryCount:
|
|
30
|
-
contents: decodeBase64(
|
|
51
|
+
entryCount: 58,
|
|
52
|
+
contents: decodeBase64('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JQ8LCgAgABADQQBHDwsTACMOIAAQJUGAgICAeHFBAEcPCwcAIw4QJA8LCAAjDiAAECYLEwAjDiAAECVBgICAgHhBf3NxDwsUACMFQQBIBEAPCyMPIw4QJBAiGgs/AQJ/IAAQGiEBIAFBAUgEQEGAgwRB0IAEQY8CQRIQAAALIAAQISABQQFrIgFBAnRqKAIAIQIgACABEBEgAg8LUAECfyMFQQBIBEAPCyMPECRBAEYEQA8LIw8QPCEBIAAEQCABIQIDQCACIw4QJEgEQCMOIAIjDiACECVBgICAgHhyECggAkEBaiECDAELCwsLBAAQEws='),
|
|
31
53
|
};
|
|
32
54
|
//# sourceMappingURL=ohmRuntime.wasm_sections.js.map
|
package/dist/src/Compiler.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export class Compiler {
|
|
|
7
7
|
paramTypes: any[];
|
|
8
8
|
resultTypes: any[];
|
|
9
9
|
}[];
|
|
10
|
-
ruleIdByName:
|
|
10
|
+
ruleIdByName: any;
|
|
11
11
|
_failureDescriptions: StringTable;
|
|
12
12
|
_endOfInputFailureId: any;
|
|
13
13
|
_deferredRuleIds: Set<any>;
|
|
@@ -17,6 +17,8 @@ export class Compiler {
|
|
|
17
17
|
_lexContextStack: any[];
|
|
18
18
|
_applySpacesImplicit: ir.Apply;
|
|
19
19
|
getOrAddFailure(str: any): any;
|
|
20
|
+
toFailureDescription(exp: any): any;
|
|
21
|
+
_prefixNot(str: any): string | null;
|
|
20
22
|
toFailure(exp: any): any;
|
|
21
23
|
importCount(): number;
|
|
22
24
|
ruleId(name: any): any;
|
|
@@ -62,9 +64,7 @@ export class Compiler {
|
|
|
62
64
|
emitLookahead({ child }: {
|
|
63
65
|
child: any;
|
|
64
66
|
}): void;
|
|
65
|
-
emitNot(
|
|
66
|
-
child: any;
|
|
67
|
-
}): void;
|
|
67
|
+
emitNot(exp: any): void;
|
|
68
68
|
emitOpt({ child }: {
|
|
69
69
|
child: any;
|
|
70
70
|
}): void;
|
|
@@ -91,7 +91,9 @@ export namespace ConstantsForTesting {
|
|
|
91
91
|
}
|
|
92
92
|
declare class StringTable {
|
|
93
93
|
_map: Map<any, any>;
|
|
94
|
+
_strs: any[];
|
|
94
95
|
add(str: any): any;
|
|
96
|
+
getStr(idx: any): any;
|
|
95
97
|
getIndex(item: any): any;
|
|
96
98
|
has(item: any): boolean;
|
|
97
99
|
get size(): number;
|
|
@@ -175,7 +177,7 @@ declare class Assembler {
|
|
|
175
177
|
restoreGlobalFailurePos(): void;
|
|
176
178
|
updateGlobalFailurePos(): void;
|
|
177
179
|
updateLocalFailurePos(origPosThunk: any): void;
|
|
178
|
-
maybeRecordFailure(origPosThunk: any, failureId: any
|
|
180
|
+
maybeRecordFailure(origPosThunk: any, failureId: any): void;
|
|
179
181
|
pushDescriptionFrame(): void;
|
|
180
182
|
handleDescriptionFailure(descriptionId: any): void;
|
|
181
183
|
incPos(): void;
|
|
@@ -186,7 +188,8 @@ declare class Assembler {
|
|
|
186
188
|
i32Max(aThunk: any, bThunk: any): void;
|
|
187
189
|
depthOf(label: any): number;
|
|
188
190
|
pushFluffySavePoint(): void;
|
|
189
|
-
|
|
191
|
+
popFluffySavePoint(shouldMark: any): void;
|
|
192
|
+
popFluffySavePointIfAtErrorPos(): void;
|
|
190
193
|
ruleEvalReturn(): void;
|
|
191
194
|
}
|
|
192
195
|
declare namespace Assembler {
|
package/dist/src/Compiler.js
CHANGED
|
@@ -76,6 +76,7 @@ const asciiChars = Array.from({ length: 128 }).map((_, i) => String.fromCharCode
|
|
|
76
76
|
class StringTable {
|
|
77
77
|
constructor() {
|
|
78
78
|
this._map = new Map();
|
|
79
|
+
this._strs = [];
|
|
79
80
|
}
|
|
80
81
|
add(str) {
|
|
81
82
|
if (this._map.has(str)) {
|
|
@@ -83,8 +84,12 @@ class StringTable {
|
|
|
83
84
|
}
|
|
84
85
|
const idx = this._map.size;
|
|
85
86
|
this._map.set(checkNotNull(str), idx);
|
|
87
|
+
this._strs.push(str);
|
|
86
88
|
return idx;
|
|
87
89
|
}
|
|
90
|
+
getStr(idx) {
|
|
91
|
+
return this._strs[idx];
|
|
92
|
+
}
|
|
88
93
|
getIndex(item) {
|
|
89
94
|
return this._map.get(item);
|
|
90
95
|
}
|
|
@@ -513,7 +518,7 @@ class Assembler {
|
|
|
513
518
|
this.i32Max(() => this.localGet('failurePos'), origPosThunk);
|
|
514
519
|
this.localSet('failurePos');
|
|
515
520
|
}
|
|
516
|
-
maybeRecordFailure(origPosThunk, failureId
|
|
521
|
+
maybeRecordFailure(origPosThunk, failureId) {
|
|
517
522
|
this.globalGet('errorMessagePos');
|
|
518
523
|
this.i32Const(0);
|
|
519
524
|
this.emit(instr.i32.ge_s);
|
|
@@ -525,9 +530,7 @@ class Assembler {
|
|
|
525
530
|
this.emit('failure#' + failureId);
|
|
526
531
|
if (failureId === undefined)
|
|
527
532
|
throw new Error('bad failureId');
|
|
528
|
-
|
|
529
|
-
const idToRecord = isNot ? failureId | 0x80000000 : failureId;
|
|
530
|
-
this.i32Const(idToRecord);
|
|
533
|
+
this.i32Const(failureId);
|
|
531
534
|
this.callPrebuiltFunc('recordFailure');
|
|
532
535
|
});
|
|
533
536
|
});
|
|
@@ -629,21 +632,20 @@ class Assembler {
|
|
|
629
632
|
assert(i !== -1, `Unknown label: ${label}`);
|
|
630
633
|
return this._blockStack.length - i - 1;
|
|
631
634
|
}
|
|
632
|
-
// Emit scoped fluffy marking: save the failure count, and after success
|
|
633
|
-
// at the recording position, mark only the new failures as fluffy.
|
|
634
|
-
// This mirrors ohm-js's MatchState.eval_ scoped failure recording.
|
|
635
635
|
pushFluffySavePoint() {
|
|
636
636
|
this.callPrebuiltFunc('pushFluffySavePoint');
|
|
637
637
|
}
|
|
638
|
-
|
|
638
|
+
popFluffySavePoint(shouldMark) {
|
|
639
|
+
this.i32Const(shouldMark ? 1 : 0);
|
|
640
|
+
this.callPrebuiltFunc('popFluffySavePoint');
|
|
641
|
+
}
|
|
642
|
+
// Pop the fluffy save point, marking failures as fluffy only when
|
|
643
|
+
// pos matches errorMessagePos. This mirrors ohm-js's scoped failure recording.
|
|
644
|
+
popFluffySavePointIfAtErrorPos() {
|
|
639
645
|
this.globalGet('errorMessagePos');
|
|
640
646
|
this.globalGet('pos');
|
|
641
647
|
this.i32Eq();
|
|
642
|
-
this.
|
|
643
|
-
this.callPrebuiltFunc('markFluffyFromSavePoint');
|
|
644
|
-
}, () => {
|
|
645
|
-
this.callPrebuiltFunc('dropFluffySavePoint');
|
|
646
|
-
});
|
|
648
|
+
this.callPrebuiltFunc('popFluffySavePoint');
|
|
647
649
|
}
|
|
648
650
|
ruleEvalReturn() {
|
|
649
651
|
// Convert the value in `ret` to a single bit in position 0.
|
|
@@ -702,31 +704,72 @@ export class Compiler {
|
|
|
702
704
|
getOrAddFailure(str) {
|
|
703
705
|
return this._failureDescriptions.add(str);
|
|
704
706
|
}
|
|
705
|
-
|
|
707
|
+
// Returns a failure description string for the given expression, or null
|
|
708
|
+
// if a description can't be generated. For compound expressions (Alt, Seq,
|
|
709
|
+
// Not, Iter, etc.), this recursively composes descriptions from children —
|
|
710
|
+
// matching the behavior of ohm-js's pexprs-toFailure.js.
|
|
711
|
+
toFailureDescription(exp) {
|
|
706
712
|
switch (exp.type) {
|
|
707
713
|
case 'Any':
|
|
708
|
-
return
|
|
714
|
+
return 'any character';
|
|
709
715
|
case 'Range':
|
|
710
|
-
return
|
|
716
|
+
return `${JSON.stringify(exp.lo)}..${JSON.stringify(exp.hi)}`;
|
|
711
717
|
case 'Terminal':
|
|
712
|
-
return
|
|
718
|
+
return JSON.stringify(exp.value);
|
|
713
719
|
case 'End':
|
|
714
|
-
return
|
|
720
|
+
return 'end of input';
|
|
715
721
|
case 'Apply':
|
|
716
|
-
// Use the rule's description if it has one.
|
|
717
722
|
if (exp.descriptionId != null && exp.descriptionId >= 0) {
|
|
718
|
-
return exp.descriptionId;
|
|
723
|
+
return this._failureDescriptions.getStr(exp.descriptionId);
|
|
719
724
|
}
|
|
720
|
-
// Fallback for built-in rules without descriptions.
|
|
721
725
|
if (exp.ruleName === 'end')
|
|
722
|
-
return
|
|
726
|
+
return 'end of input';
|
|
723
727
|
if (exp.ruleName === 'any')
|
|
724
|
-
return
|
|
725
|
-
return
|
|
728
|
+
return 'any character';
|
|
729
|
+
return null;
|
|
730
|
+
case 'Alt': {
|
|
731
|
+
const strs = exp.children.map(c => this.toFailureDescription(c));
|
|
732
|
+
if (strs.some(s => s == null))
|
|
733
|
+
return null;
|
|
734
|
+
return '(' + strs.join(' or ') + ')';
|
|
735
|
+
}
|
|
736
|
+
case 'Seq': {
|
|
737
|
+
const strs = exp.children.map(c => this.toFailureDescription(c));
|
|
738
|
+
if (strs.some(s => s == null))
|
|
739
|
+
return null;
|
|
740
|
+
return '(' + strs.join(' ') + ')';
|
|
741
|
+
}
|
|
742
|
+
case 'Not':
|
|
743
|
+
if (exp.child.type === 'Any')
|
|
744
|
+
return 'nothing';
|
|
745
|
+
return this._prefixNot(this.toFailureDescription(exp.child));
|
|
746
|
+
case 'Lookahead':
|
|
747
|
+
case 'Lex':
|
|
748
|
+
return this.toFailureDescription(exp.child);
|
|
749
|
+
case 'Opt':
|
|
750
|
+
case 'Star':
|
|
751
|
+
case 'Plus': {
|
|
752
|
+
const childStr = this.toFailureDescription(exp.child);
|
|
753
|
+
if (childStr == null)
|
|
754
|
+
return null;
|
|
755
|
+
const op = exp.type === 'Opt' ? '?' : exp.type === 'Star' ? '*' : '+';
|
|
756
|
+
return '(' + childStr + op + ')';
|
|
757
|
+
}
|
|
758
|
+
case 'UnicodeChar':
|
|
759
|
+
return 'a Unicode [' + exp.categoryOrProp + '] character';
|
|
760
|
+
case 'CaseInsensitive':
|
|
761
|
+
return JSON.stringify(exp.value);
|
|
726
762
|
default:
|
|
727
|
-
return
|
|
763
|
+
return null;
|
|
728
764
|
}
|
|
729
765
|
}
|
|
766
|
+
_prefixNot(str) {
|
|
767
|
+
return str != null ? 'not ' + str : null;
|
|
768
|
+
}
|
|
769
|
+
toFailure(exp) {
|
|
770
|
+
const str = this.toFailureDescription(exp);
|
|
771
|
+
return str != null ? this.getOrAddFailure(str) : -1;
|
|
772
|
+
}
|
|
730
773
|
importCount() {
|
|
731
774
|
return prebuilt.importsec.entryCount + this.importDecls.length;
|
|
732
775
|
}
|
|
@@ -835,12 +878,11 @@ export class Compiler {
|
|
|
835
878
|
asm.addGlobal('__ASC_RUNTIME', w.valtype.i32, w.mut.const, () => asm.i32Const(0));
|
|
836
879
|
asm.addGlobal('bindings', w.valtype.i32, w.mut.var, () => asm.i32Const(0));
|
|
837
880
|
asm.addGlobal('recordedFailures', w.valtype.i32, w.mut.var, () => asm.i32Const(0));
|
|
838
|
-
asm.addGlobal('fluffyFlags', w.valtype.i32, w.mut.var, () => asm.i32Const(0));
|
|
839
881
|
asm.addGlobal('fluffySaveStack', w.valtype.i32, w.mut.var, () => asm.i32Const(0));
|
|
840
882
|
asm.addGlobal('__heap_base', w.valtype.i32, w.mut.var, () => asm.i32Const(65948));
|
|
841
883
|
// Reserve a fixed number of imports for debug labels.
|
|
842
884
|
if (DEBUG) {
|
|
843
|
-
for (let i = 0; i <
|
|
885
|
+
for (let i = 0; i < 10000; i++) {
|
|
844
886
|
this.importDecls.push({
|
|
845
887
|
module: 'debug',
|
|
846
888
|
name: `debug${i}`,
|
|
@@ -1031,9 +1073,9 @@ export class Compiler {
|
|
|
1031
1073
|
// ohm-js's MatchState.eval_, which uses scoped failure recording.
|
|
1032
1074
|
asm.localGet('ret');
|
|
1033
1075
|
asm.if(w.blocktype.empty, () => {
|
|
1034
|
-
asm.
|
|
1076
|
+
asm.popFluffySavePointIfAtErrorPos();
|
|
1035
1077
|
}, () => {
|
|
1036
|
-
asm.
|
|
1078
|
+
asm.popFluffySavePoint(false);
|
|
1037
1079
|
});
|
|
1038
1080
|
// Handle rules with descriptions - must come BEFORE restoreFailurePos
|
|
1039
1081
|
if (hasDescription)
|
|
@@ -1521,20 +1563,28 @@ export class Compiler {
|
|
|
1521
1563
|
// When lookahead succeeds, mark inner failures as fluffy (scoped).
|
|
1522
1564
|
asm.localGet('ret');
|
|
1523
1565
|
asm.if(w.blocktype.empty, () => {
|
|
1524
|
-
asm.
|
|
1566
|
+
asm.popFluffySavePointIfAtErrorPos();
|
|
1525
1567
|
}, () => {
|
|
1526
|
-
asm.
|
|
1568
|
+
asm.popFluffySavePoint(false);
|
|
1527
1569
|
});
|
|
1528
1570
|
}
|
|
1529
|
-
emitNot(
|
|
1571
|
+
emitNot(exp) {
|
|
1572
|
+
const { child } = exp;
|
|
1530
1573
|
const { asm } = this;
|
|
1531
|
-
const failureId = this.toFailure(
|
|
1532
|
-
|
|
1533
|
-
|
|
1574
|
+
const failureId = this.toFailure(exp);
|
|
1575
|
+
const NOT_FRAME_SIZE = 12;
|
|
1576
|
+
// Save failurePos, globalFailurePos, AND recordedFailures.length
|
|
1577
|
+
// directly onto the stack frame. We use setRecordedFailuresLength
|
|
1578
|
+
// to directly truncate after the child evaluation. This matches
|
|
1579
|
+
// JS's pushFailuresInfo/popFailuresInfo for Not expressions.
|
|
1534
1580
|
asm.pushStackFrame(() => {
|
|
1535
|
-
asm.saveFailurePos();
|
|
1536
|
-
asm.saveGlobalFailurePos();
|
|
1537
|
-
|
|
1581
|
+
asm.saveFailurePos(); // offset 0
|
|
1582
|
+
asm.saveGlobalFailurePos(); // offset 4
|
|
1583
|
+
// Save recordedFailures.length at offset 8
|
|
1584
|
+
asm.globalGet('sp');
|
|
1585
|
+
asm.callPrebuiltFunc('getRecordedFailuresLength');
|
|
1586
|
+
asm.i32Store(8);
|
|
1587
|
+
}, NOT_FRAME_SIZE);
|
|
1538
1588
|
this.emitPExpr(child);
|
|
1539
1589
|
// Invert the result.
|
|
1540
1590
|
asm.localGet('ret');
|
|
@@ -1543,22 +1593,28 @@ export class Compiler {
|
|
|
1543
1593
|
// Restore all global and local state.
|
|
1544
1594
|
asm.restoreGlobalFailurePos();
|
|
1545
1595
|
asm.restoreFailurePos();
|
|
1546
|
-
|
|
1596
|
+
// Discard all child failures by restoring recordedFailures.length
|
|
1597
|
+
// from the stack frame (offset 8). Only during the recording pass.
|
|
1598
|
+
asm.globalGet('errorMessagePos');
|
|
1599
|
+
asm.i32Const(0);
|
|
1600
|
+
asm.emit(instr.i32.ge_s);
|
|
1601
|
+
asm.if(w.blocktype.empty, () => {
|
|
1602
|
+
asm.globalGet('sp');
|
|
1603
|
+
asm.i32Load(8);
|
|
1604
|
+
asm.callPrebuiltFunc('setRecordedFailuresLength');
|
|
1605
|
+
});
|
|
1606
|
+
asm.popStackFrame(NOT_FRAME_SIZE);
|
|
1547
1607
|
asm.restoreBindingsLength();
|
|
1548
1608
|
asm.restorePos();
|
|
1549
1609
|
asm.localGet('ret');
|
|
1550
|
-
asm.
|
|
1551
|
-
// When not succeeds (child failed), mark inner failures as fluffy (scoped).
|
|
1552
|
-
asm.maybeMarkFluffyFromSavePoint();
|
|
1553
|
-
}, () => {
|
|
1554
|
-
asm.callPrebuiltFunc('dropFluffySavePoint');
|
|
1610
|
+
asm.ifFalse(w.blocktype.empty, () => {
|
|
1555
1611
|
// When not fails (child succeeded), update failurePos to origPos.
|
|
1556
1612
|
// This is equivalent to Ohm.js's processFailure(origPos, this).
|
|
1557
1613
|
// Note: pos has already been restored by restorePos() above.
|
|
1558
1614
|
asm.updateLocalFailurePos(() => asm.globalGet('pos'));
|
|
1559
1615
|
asm.updateGlobalFailurePos();
|
|
1560
1616
|
if (failureId >= 0) {
|
|
1561
|
-
asm.maybeRecordFailure(() => asm.globalGet('pos'), failureId
|
|
1617
|
+
asm.maybeRecordFailure(() => asm.globalGet('pos'), failureId);
|
|
1562
1618
|
}
|
|
1563
1619
|
});
|
|
1564
1620
|
}
|
|
@@ -1573,7 +1629,7 @@ export class Compiler {
|
|
|
1573
1629
|
});
|
|
1574
1630
|
asm.newIterNodeWithSavedPosAndBindings(ir.outArity(child), true);
|
|
1575
1631
|
// Opt always succeeds, so mark inner failures as fluffy (scoped).
|
|
1576
|
-
asm.
|
|
1632
|
+
asm.popFluffySavePointIfAtErrorPos();
|
|
1577
1633
|
asm.localSet('ret');
|
|
1578
1634
|
}
|
|
1579
1635
|
emitPlus(plusExp) {
|
|
@@ -1650,7 +1706,7 @@ export class Compiler {
|
|
|
1650
1706
|
asm.popStackFrame();
|
|
1651
1707
|
asm.newIterNodeWithSavedPosAndBindings(ir.outArity(child));
|
|
1652
1708
|
// Star always succeeds, so mark inner failures as fluffy (scoped).
|
|
1653
|
-
asm.
|
|
1709
|
+
asm.popFluffySavePointIfAtErrorPos();
|
|
1654
1710
|
asm.localSet('ret');
|
|
1655
1711
|
}
|
|
1656
1712
|
wrapTerminalLike(thunk, failureId) {
|
package/dist/src/miniohm.js
CHANGED
|
@@ -269,10 +269,7 @@ export class WasmGrammar {
|
|
|
269
269
|
return [...new Set(ans)];
|
|
270
270
|
}
|
|
271
271
|
getFailureDescription(id) {
|
|
272
|
-
|
|
273
|
-
const realId = id & 0x7fffffff;
|
|
274
|
-
const desc = this._failureDescriptions[realId];
|
|
275
|
-
return isNot ? 'not ' + desc : desc;
|
|
272
|
+
return this._failureDescriptions[id];
|
|
276
273
|
}
|
|
277
274
|
getMemorySizeBytes() {
|
|
278
275
|
return this._instance.exports.memory.buffer.byteLength;
|
|
@@ -676,7 +673,8 @@ export class FailedMatchResult extends MatchResult {
|
|
|
676
673
|
// Use a Map to deduplicate by description while preserving fluffy status.
|
|
677
674
|
// A failure is only fluffy if ALL occurrences are fluffy.
|
|
678
675
|
const failureMap = new Map();
|
|
679
|
-
|
|
676
|
+
const len = exports.getRecordedFailuresLength();
|
|
677
|
+
for (let i = 0; i < len; i++) {
|
|
680
678
|
const id = exports.recordedFailuresAt(i);
|
|
681
679
|
const desc = this.grammar.getFailureDescription(id);
|
|
682
680
|
const fluffy = exports.isFluffy(i);
|