@ohm-js/wasm 0.7.2 → 0.7.4
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
|
@@ -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,80 @@ 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
|
|
715
|
-
case 'Apply':
|
|
716
|
-
// Use the rule's description if it has one.
|
|
720
|
+
return 'end of input';
|
|
721
|
+
case 'Apply': {
|
|
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
|
-
|
|
728
|
+
return 'any character';
|
|
729
|
+
// For lifted rules, expand their body to get a meaningful description.
|
|
730
|
+
if (exp.ruleName.startsWith('$lifted')) {
|
|
731
|
+
const ruleInfo = this.rules.get(exp.ruleName);
|
|
732
|
+
if (ruleInfo)
|
|
733
|
+
return this.toFailureDescription(ruleInfo.body);
|
|
734
|
+
}
|
|
735
|
+
const article = /^[aeiouAEIOU]/.test(exp.ruleName) ? 'an' : 'a';
|
|
736
|
+
return article + ' ' + exp.ruleName;
|
|
737
|
+
}
|
|
738
|
+
case 'Alt': {
|
|
739
|
+
const strs = exp.children.map(c => this.toFailureDescription(c));
|
|
740
|
+
if (strs.some(s => s == null))
|
|
741
|
+
return null;
|
|
742
|
+
return '(' + strs.join(' or ') + ')';
|
|
743
|
+
}
|
|
744
|
+
case 'Seq': {
|
|
745
|
+
const strs = exp.children.map(c => this.toFailureDescription(c));
|
|
746
|
+
if (strs.some(s => s == null))
|
|
747
|
+
return null;
|
|
748
|
+
return '(' + strs.join(' ') + ')';
|
|
749
|
+
}
|
|
750
|
+
case 'Not':
|
|
751
|
+
if (exp.child.type === 'Any')
|
|
752
|
+
return 'nothing';
|
|
753
|
+
return this._prefixNot(this.toFailureDescription(exp.child));
|
|
754
|
+
case 'Lookahead':
|
|
755
|
+
case 'Lex':
|
|
756
|
+
return this.toFailureDescription(exp.child);
|
|
757
|
+
case 'Opt':
|
|
758
|
+
case 'Star':
|
|
759
|
+
case 'Plus': {
|
|
760
|
+
const childStr = this.toFailureDescription(exp.child);
|
|
761
|
+
if (childStr == null)
|
|
762
|
+
return null;
|
|
763
|
+
const op = exp.type === 'Opt' ? '?' : exp.type === 'Star' ? '*' : '+';
|
|
764
|
+
return '(' + childStr + op + ')';
|
|
765
|
+
}
|
|
766
|
+
case 'UnicodeChar':
|
|
767
|
+
return 'a Unicode [' + exp.categoryOrProp + '] character';
|
|
768
|
+
case 'CaseInsensitive':
|
|
769
|
+
return JSON.stringify(exp.value);
|
|
726
770
|
default:
|
|
727
|
-
return
|
|
771
|
+
return null;
|
|
728
772
|
}
|
|
729
773
|
}
|
|
774
|
+
_prefixNot(str) {
|
|
775
|
+
return str != null ? 'not ' + str : null;
|
|
776
|
+
}
|
|
777
|
+
toFailure(exp) {
|
|
778
|
+
const str = this.toFailureDescription(exp);
|
|
779
|
+
return str != null ? this.getOrAddFailure(str) : -1;
|
|
780
|
+
}
|
|
730
781
|
importCount() {
|
|
731
782
|
return prebuilt.importsec.entryCount + this.importDecls.length;
|
|
732
783
|
}
|
|
@@ -835,12 +886,11 @@ export class Compiler {
|
|
|
835
886
|
asm.addGlobal('__ASC_RUNTIME', w.valtype.i32, w.mut.const, () => asm.i32Const(0));
|
|
836
887
|
asm.addGlobal('bindings', w.valtype.i32, w.mut.var, () => asm.i32Const(0));
|
|
837
888
|
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
889
|
asm.addGlobal('fluffySaveStack', w.valtype.i32, w.mut.var, () => asm.i32Const(0));
|
|
840
890
|
asm.addGlobal('__heap_base', w.valtype.i32, w.mut.var, () => asm.i32Const(65948));
|
|
841
891
|
// Reserve a fixed number of imports for debug labels.
|
|
842
892
|
if (DEBUG) {
|
|
843
|
-
for (let i = 0; i <
|
|
893
|
+
for (let i = 0; i < 10000; i++) {
|
|
844
894
|
this.importDecls.push({
|
|
845
895
|
module: 'debug',
|
|
846
896
|
name: `debug${i}`,
|
|
@@ -1031,9 +1081,9 @@ export class Compiler {
|
|
|
1031
1081
|
// ohm-js's MatchState.eval_, which uses scoped failure recording.
|
|
1032
1082
|
asm.localGet('ret');
|
|
1033
1083
|
asm.if(w.blocktype.empty, () => {
|
|
1034
|
-
asm.
|
|
1084
|
+
asm.popFluffySavePointIfAtErrorPos();
|
|
1035
1085
|
}, () => {
|
|
1036
|
-
asm.
|
|
1086
|
+
asm.popFluffySavePoint(false);
|
|
1037
1087
|
});
|
|
1038
1088
|
// Handle rules with descriptions - must come BEFORE restoreFailurePos
|
|
1039
1089
|
if (hasDescription)
|
|
@@ -1521,20 +1571,28 @@ export class Compiler {
|
|
|
1521
1571
|
// When lookahead succeeds, mark inner failures as fluffy (scoped).
|
|
1522
1572
|
asm.localGet('ret');
|
|
1523
1573
|
asm.if(w.blocktype.empty, () => {
|
|
1524
|
-
asm.
|
|
1574
|
+
asm.popFluffySavePointIfAtErrorPos();
|
|
1525
1575
|
}, () => {
|
|
1526
|
-
asm.
|
|
1576
|
+
asm.popFluffySavePoint(false);
|
|
1527
1577
|
});
|
|
1528
1578
|
}
|
|
1529
|
-
emitNot(
|
|
1579
|
+
emitNot(exp) {
|
|
1580
|
+
const { child } = exp;
|
|
1530
1581
|
const { asm } = this;
|
|
1531
|
-
const failureId = this.toFailure(
|
|
1532
|
-
|
|
1533
|
-
|
|
1582
|
+
const failureId = this.toFailure(exp);
|
|
1583
|
+
const NOT_FRAME_SIZE = 12;
|
|
1584
|
+
// Save failurePos, globalFailurePos, AND recordedFailures.length
|
|
1585
|
+
// directly onto the stack frame. We use setRecordedFailuresLength
|
|
1586
|
+
// to directly truncate after the child evaluation. This matches
|
|
1587
|
+
// JS's pushFailuresInfo/popFailuresInfo for Not expressions.
|
|
1534
1588
|
asm.pushStackFrame(() => {
|
|
1535
|
-
asm.saveFailurePos();
|
|
1536
|
-
asm.saveGlobalFailurePos();
|
|
1537
|
-
|
|
1589
|
+
asm.saveFailurePos(); // offset 0
|
|
1590
|
+
asm.saveGlobalFailurePos(); // offset 4
|
|
1591
|
+
// Save recordedFailures.length at offset 8
|
|
1592
|
+
asm.globalGet('sp');
|
|
1593
|
+
asm.callPrebuiltFunc('getRecordedFailuresLength');
|
|
1594
|
+
asm.i32Store(8);
|
|
1595
|
+
}, NOT_FRAME_SIZE);
|
|
1538
1596
|
this.emitPExpr(child);
|
|
1539
1597
|
// Invert the result.
|
|
1540
1598
|
asm.localGet('ret');
|
|
@@ -1543,22 +1601,28 @@ export class Compiler {
|
|
|
1543
1601
|
// Restore all global and local state.
|
|
1544
1602
|
asm.restoreGlobalFailurePos();
|
|
1545
1603
|
asm.restoreFailurePos();
|
|
1546
|
-
|
|
1604
|
+
// Discard all child failures by restoring recordedFailures.length
|
|
1605
|
+
// from the stack frame (offset 8). Only during the recording pass.
|
|
1606
|
+
asm.globalGet('errorMessagePos');
|
|
1607
|
+
asm.i32Const(0);
|
|
1608
|
+
asm.emit(instr.i32.ge_s);
|
|
1609
|
+
asm.if(w.blocktype.empty, () => {
|
|
1610
|
+
asm.globalGet('sp');
|
|
1611
|
+
asm.i32Load(8);
|
|
1612
|
+
asm.callPrebuiltFunc('setRecordedFailuresLength');
|
|
1613
|
+
});
|
|
1614
|
+
asm.popStackFrame(NOT_FRAME_SIZE);
|
|
1547
1615
|
asm.restoreBindingsLength();
|
|
1548
1616
|
asm.restorePos();
|
|
1549
1617
|
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');
|
|
1618
|
+
asm.ifFalse(w.blocktype.empty, () => {
|
|
1555
1619
|
// When not fails (child succeeded), update failurePos to origPos.
|
|
1556
1620
|
// This is equivalent to Ohm.js's processFailure(origPos, this).
|
|
1557
1621
|
// Note: pos has already been restored by restorePos() above.
|
|
1558
1622
|
asm.updateLocalFailurePos(() => asm.globalGet('pos'));
|
|
1559
1623
|
asm.updateGlobalFailurePos();
|
|
1560
1624
|
if (failureId >= 0) {
|
|
1561
|
-
asm.maybeRecordFailure(() => asm.globalGet('pos'), failureId
|
|
1625
|
+
asm.maybeRecordFailure(() => asm.globalGet('pos'), failureId);
|
|
1562
1626
|
}
|
|
1563
1627
|
});
|
|
1564
1628
|
}
|
|
@@ -1573,7 +1637,7 @@ export class Compiler {
|
|
|
1573
1637
|
});
|
|
1574
1638
|
asm.newIterNodeWithSavedPosAndBindings(ir.outArity(child), true);
|
|
1575
1639
|
// Opt always succeeds, so mark inner failures as fluffy (scoped).
|
|
1576
|
-
asm.
|
|
1640
|
+
asm.popFluffySavePointIfAtErrorPos();
|
|
1577
1641
|
asm.localSet('ret');
|
|
1578
1642
|
}
|
|
1579
1643
|
emitPlus(plusExp) {
|
|
@@ -1650,7 +1714,7 @@ export class Compiler {
|
|
|
1650
1714
|
asm.popStackFrame();
|
|
1651
1715
|
asm.newIterNodeWithSavedPosAndBindings(ir.outArity(child));
|
|
1652
1716
|
// Star always succeeds, so mark inner failures as fluffy (scoped).
|
|
1653
|
-
asm.
|
|
1717
|
+
asm.popFluffySavePointIfAtErrorPos();
|
|
1654
1718
|
asm.localSet('ret');
|
|
1655
1719
|
}
|
|
1656
1720
|
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);
|