@ohm-js/wasm 0.7.1 → 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.
- package/dist/build/ohmRuntime.wasm_sections.d.ts +3 -2
- package/dist/build/ohmRuntime.wasm_sections.js +29 -28
- package/dist/src/Compiler.d.ts +9 -5
- package/dist/src/Compiler.js +126 -41
- package/dist/src/miniohm.js +3 -5
- package/package.json +1 -1
- package/dist/src/util.d.ts +0 -16
- package/dist/src/util.js +0 -150
|
@@ -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,11 +16,12 @@ export declare const funcidxByName: {
|
|
|
16
16
|
bindingsAt: number;
|
|
17
17
|
doMatchUnicodeChar: number;
|
|
18
18
|
recordFailure: number;
|
|
19
|
-
makeFluffy: number;
|
|
20
19
|
isFluffy: number;
|
|
21
20
|
getRecordedFailuresLength: number;
|
|
22
21
|
setRecordedFailuresLength: number;
|
|
23
22
|
recordedFailuresAt: number;
|
|
23
|
+
pushFluffySavePoint: number;
|
|
24
|
+
popFluffySavePoint: number;
|
|
24
25
|
};
|
|
25
26
|
export declare const typesec: {
|
|
26
27
|
entryCount: number;
|
|
@@ -7,47 +7,48 @@ function decodeBase64(str) {
|
|
|
7
7
|
return result;
|
|
8
8
|
}
|
|
9
9
|
export const destImportCount = 5;
|
|
10
|
-
export const startFuncidx =
|
|
10
|
+
export const startFuncidx = 62;
|
|
11
11
|
export const funcidxByName = {
|
|
12
|
-
resetHeap:
|
|
13
|
-
match:
|
|
14
|
-
recordFailures:
|
|
15
|
-
evalApplyGeneralized:
|
|
16
|
-
evalApplyNoMemo0:
|
|
17
|
-
evalApply0:
|
|
18
|
-
handleLeftRecursion:
|
|
19
|
-
newTerminalNode:
|
|
20
|
-
newNonterminalNode:
|
|
21
|
-
newIterationNode:
|
|
22
|
-
getBindingsLength:
|
|
23
|
-
setBindingsLength:
|
|
24
|
-
bindingsAt:
|
|
25
|
-
doMatchUnicodeChar:
|
|
26
|
-
recordFailure:
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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,
|
|
32
33
|
};
|
|
33
34
|
export const typesec = {
|
|
34
|
-
entryCount:
|
|
35
|
-
contents: decodeBase64('YAF/AX9gAn9/AGACf38Bf2AAAGABfwBgAAF/YAR/f39/AGADf39/AGAFf39/f38Bf2ABbwF/YAR/f39/
|
|
35
|
+
entryCount: 12,
|
|
36
|
+
contents: decodeBase64('YAF/AX9gAn9/AGACf38Bf2AAAGABfwBgAAF/YAR/f39/AGADf39/AGAFf39/f38Bf2ABbwF/YAR/f39/AX9gAm9/AX8='),
|
|
36
37
|
};
|
|
37
38
|
export const importsec = {
|
|
38
39
|
entryCount: 4,
|
|
39
40
|
contents: decodeBase64('A2VudgVhYm9ydAAGDndhc206anMtc3RyaW5nBmxlbmd0aAAJCm9obVJ1bnRpbWUPaXNSdWxlU3ludGFjdGljAAAKb2htUnVudGltZRBtYXRjaFVuaWNvZGVDaGFyAAA='),
|
|
40
41
|
};
|
|
41
42
|
export const funcsec = {
|
|
42
|
-
entryCount:
|
|
43
|
-
contents: decodeBase64('
|
|
43
|
+
entryCount: 58,
|
|
44
|
+
contents: decodeBase64('BAEAAQEBAQIHAQEBAQIDAwMDAwAAAAAAAAICBgACAgACAQgHCgAEAAsEAgACCAUEAAAABQQAAwAEAw=='),
|
|
44
45
|
};
|
|
45
46
|
export const globalsec = {
|
|
46
47
|
entryCount: 17,
|
|
47
|
-
contents: decodeBase64('fwFBAAt/AUEAC28B0G8LfwFBAAt/AUEAC38BQX8LfwFBAAt/AEEAC38AQQELfwBBAgt/AUEAC38BQQALfwBBAAt/AUEAC38BQQALfwFBAAt/
|
|
48
|
+
contents: decodeBase64('fwFBAAt/AUEAC28B0G8LfwFBAAt/AUEAC38BQX8LfwFBAAt/AEEAC38AQQELfwBBAgt/AUEAC38BQQALfwBBAAt/AUEAC38BQQALfwFBAAt/AEGcgwQL'),
|
|
48
49
|
};
|
|
49
50
|
export const codesec = {
|
|
50
|
-
entryCount:
|
|
51
|
-
contents: decodeBase64('YAEGfz8AIQEgAUEQdEEPakEPQX9zcSECIAAgAksEQCAAIAJrQf//A2pB//8DQX9zcUEQdiEDIAEiBCADIgUgBCAFShshBiAGQABBAEgEQCADQABBAEgEQAALCwsgACQLCwkAIAAgATYCAAtWAQR/IABB/P///wNLBEBBgIEEQcCBBEEhQR0QAAALIwshASMLQQRqIQICfyAAIQMgA0EEakEPakEPQX9zcUEEawwACyEEIAIgBGoQBSABIAQQBiACDwsJACAAIAE2AgQLCQAgACABNgIICwkAIAAgATYCDAsJACAAIAE2AhALTgECfyAAQez///8DSwRAQYCBBEHAgQRB1gBBHhAAAAtBECAAahAHIQIgAkEEayEDIANBABAIIANBABAJIAMgARAKIAMgABALIAJBEGoPCwMAAQsRACAAIAE2AgAgACABQQAQDQsJACAAIAE2AgQLCQAgACABNgIICwkAIAAgATYCDAuNAQEEfyAARQRAQRBBBBAMIQALIABBABAOIABBABAPIABBABAQIABBABARIAFB/P///
|
|
51
|
+
entryCount: 58,
|
|
52
|
+
contents: decodeBase64('YAEGfz8AIQEgAUEQdEEPakEPQX9zcSECIAAgAksEQCAAIAJrQf//A2pB//8DQX9zcUEQdiEDIAEiBCADIgUgBCAFShshBiAGQABBAEgEQCADQABBAEgEQAALCwsgACQLCwkAIAAgATYCAAtWAQR/IABB/P///wNLBEBBgIEEQcCBBEEhQR0QAAALIwshASMLQQRqIQICfyAAIQMgA0EEakEPakEPQX9zcUEEawwACyEEIAIgBGoQBSABIAQQBiACDwsJACAAIAE2AgQLCQAgACABNgIICwkAIAAgATYCDAsJACAAIAE2AhALTgECfyAAQez///8DSwRAQYCBBEHAgQRB1gBBHhAAAAtBECAAahAHIQIgAkEEayEDIANBABAIIANBABAJIAMgARAKIAMgABALIAJBEGoPCwMAAQsRACAAIAE2AgAgACABQQAQDQsJACAAIAE2AgQLCQAgACABNgIICwkAIAAgATYCDAuNAQEEfyAARQRAQRBBBBAMIQALIABBABAOIABBABAPIABBABAQIABBABARIAFB/P///wNBAnZLBEBBoIAEQdCABEHGAEE8EAAACyABIgJBCCIDIAIgA0sbQQJ0IQQgBEEBEAwhBUEAIwlHGiAFQQAgBPwLACAAIAUQDiAAIAUQDyAAIAQQECAAIAEQESAACzEAIxBBBGpBD2pBD0F/c3FBBGskCiMKJAtBAEEAEBIkDUEAQQAQEiQOQQBBABASJA8LBgAjCiQLCwcAQQEaEBQLBAAQFQsYAEEAJABBfyQEQYCABCQGQQBBABASJA0LBwAgABAHDwshAQJ/IABBAWpBgAhsIQEgARAYIQIgAkEAIAH8CwAgAg8LBwAgACgCDAsHACAAKAIICwcAIAAoAgALBwAgACgCAAvNAQEIfyAAQQBHBH8gAEEPcUUFQQALRQRAQQBBwIEEQS1BAxAAAAsgAEEEayECIAIQHSEDIAAgA2ojC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ISgMAQsLIw0gGxAmIw0gHxAiGiAfDAALDwsHACMNECQPCwkAIw0gABAmDwsJACMNIAAQJQ8LCgAgABADQQBHDwsTACMOIAAQJUGAgICAeHFBAEcPCwcAIw4QJA8LCAAjDiAAECYLEwAjDiAAECVBgICAgHhBf3NxDwsUACMFQQBIBEAPCyMPIw4QJBAiGgs/AQJ/IAAQGiEBIAFBAUgEQEGAgwRB0IAEQY8CQRIQAAALIAAQISABQQFrIgFBAnRqKAIAIQIgACABEBEgAg8LUAECfyMFQQBIBEAPCyMPECRBAEYEQA8LIw8QPCEBIAAEQCABIQIDQCACIw4QJEgEQCMOIAIjDiACECVBgICAgHhyECggAkEBaiECDAELCwsLBAAQEws='),
|
|
52
53
|
};
|
|
53
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;
|
|
@@ -185,7 +187,9 @@ declare class Assembler {
|
|
|
185
187
|
newTerminalNode(): void;
|
|
186
188
|
i32Max(aThunk: any, bThunk: any): void;
|
|
187
189
|
depthOf(label: any): number;
|
|
188
|
-
|
|
190
|
+
pushFluffySavePoint(): void;
|
|
191
|
+
popFluffySavePoint(shouldMark: any): void;
|
|
192
|
+
popFluffySavePointIfAtErrorPos(): void;
|
|
189
193
|
ruleEvalReturn(): void;
|
|
190
194
|
}
|
|
191
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,14 +632,20 @@ class Assembler {
|
|
|
629
632
|
assert(i !== -1, `Unknown label: ${label}`);
|
|
630
633
|
return this._blockStack.length - i - 1;
|
|
631
634
|
}
|
|
632
|
-
|
|
633
|
-
|
|
635
|
+
pushFluffySavePoint() {
|
|
636
|
+
this.callPrebuiltFunc('pushFluffySavePoint');
|
|
637
|
+
}
|
|
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() {
|
|
634
645
|
this.globalGet('errorMessagePos');
|
|
635
|
-
this.
|
|
636
|
-
this.
|
|
637
|
-
this.
|
|
638
|
-
this.callPrebuiltFunc('makeFluffy');
|
|
639
|
-
});
|
|
646
|
+
this.globalGet('pos');
|
|
647
|
+
this.i32Eq();
|
|
648
|
+
this.callPrebuiltFunc('popFluffySavePoint');
|
|
640
649
|
}
|
|
641
650
|
ruleEvalReturn() {
|
|
642
651
|
// Convert the value in `ret` to a single bit in position 0.
|
|
@@ -695,31 +704,72 @@ export class Compiler {
|
|
|
695
704
|
getOrAddFailure(str) {
|
|
696
705
|
return this._failureDescriptions.add(str);
|
|
697
706
|
}
|
|
698
|
-
|
|
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) {
|
|
699
712
|
switch (exp.type) {
|
|
700
713
|
case 'Any':
|
|
701
|
-
return
|
|
714
|
+
return 'any character';
|
|
702
715
|
case 'Range':
|
|
703
|
-
return
|
|
716
|
+
return `${JSON.stringify(exp.lo)}..${JSON.stringify(exp.hi)}`;
|
|
704
717
|
case 'Terminal':
|
|
705
|
-
return
|
|
718
|
+
return JSON.stringify(exp.value);
|
|
706
719
|
case 'End':
|
|
707
|
-
return
|
|
720
|
+
return 'end of input';
|
|
708
721
|
case 'Apply':
|
|
709
|
-
// Use the rule's description if it has one.
|
|
710
722
|
if (exp.descriptionId != null && exp.descriptionId >= 0) {
|
|
711
|
-
return exp.descriptionId;
|
|
723
|
+
return this._failureDescriptions.getStr(exp.descriptionId);
|
|
712
724
|
}
|
|
713
|
-
// Fallback for built-in rules without descriptions.
|
|
714
725
|
if (exp.ruleName === 'end')
|
|
715
|
-
return
|
|
726
|
+
return 'end of input';
|
|
716
727
|
if (exp.ruleName === 'any')
|
|
717
|
-
return
|
|
718
|
-
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);
|
|
719
762
|
default:
|
|
720
|
-
return
|
|
763
|
+
return null;
|
|
721
764
|
}
|
|
722
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
|
+
}
|
|
723
773
|
importCount() {
|
|
724
774
|
return prebuilt.importsec.entryCount + this.importDecls.length;
|
|
725
775
|
}
|
|
@@ -828,11 +878,11 @@ export class Compiler {
|
|
|
828
878
|
asm.addGlobal('__ASC_RUNTIME', w.valtype.i32, w.mut.const, () => asm.i32Const(0));
|
|
829
879
|
asm.addGlobal('bindings', w.valtype.i32, w.mut.var, () => asm.i32Const(0));
|
|
830
880
|
asm.addGlobal('recordedFailures', w.valtype.i32, w.mut.var, () => asm.i32Const(0));
|
|
831
|
-
asm.addGlobal('
|
|
881
|
+
asm.addGlobal('fluffySaveStack', w.valtype.i32, w.mut.var, () => asm.i32Const(0));
|
|
832
882
|
asm.addGlobal('__heap_base', w.valtype.i32, w.mut.var, () => asm.i32Const(65948));
|
|
833
883
|
// Reserve a fixed number of imports for debug labels.
|
|
834
884
|
if (DEBUG) {
|
|
835
|
-
for (let i = 0; i <
|
|
885
|
+
for (let i = 0; i < 10000; i++) {
|
|
836
886
|
this.importDecls.push({
|
|
837
887
|
module: 'debug',
|
|
838
888
|
name: `debug${i}`,
|
|
@@ -1004,6 +1054,9 @@ export class Compiler {
|
|
|
1004
1054
|
asm.addLocal('failurePos', w.valtype.i32);
|
|
1005
1055
|
asm.globalGet('rightmostFailurePos');
|
|
1006
1056
|
asm.localSet('failurePos');
|
|
1057
|
+
// Save the failure count so we can scope fluffy marking to failures
|
|
1058
|
+
// recorded during this rule's evaluation only.
|
|
1059
|
+
asm.pushFluffySavePoint();
|
|
1007
1060
|
if (hasDescription) {
|
|
1008
1061
|
asm.pushDescriptionFrame();
|
|
1009
1062
|
}
|
|
@@ -1015,6 +1068,15 @@ export class Compiler {
|
|
|
1015
1068
|
}
|
|
1016
1069
|
asm.emit(`BEGIN eval:${name}`);
|
|
1017
1070
|
this.emitPExpr(ruleInfo.body);
|
|
1071
|
+
// When a rule body succeeds and pos matches errorMessagePos, mark
|
|
1072
|
+
// failures recorded DURING this rule eval as fluffy. This mirrors
|
|
1073
|
+
// ohm-js's MatchState.eval_, which uses scoped failure recording.
|
|
1074
|
+
asm.localGet('ret');
|
|
1075
|
+
asm.if(w.blocktype.empty, () => {
|
|
1076
|
+
asm.popFluffySavePointIfAtErrorPos();
|
|
1077
|
+
}, () => {
|
|
1078
|
+
asm.popFluffySavePoint(false);
|
|
1079
|
+
});
|
|
1018
1080
|
// Handle rules with descriptions - must come BEFORE restoreFailurePos
|
|
1019
1081
|
if (hasDescription)
|
|
1020
1082
|
asm.handleDescriptionFailure(descriptionId);
|
|
@@ -1494,23 +1556,35 @@ export class Compiler {
|
|
|
1494
1556
|
emitLookahead({ child }) {
|
|
1495
1557
|
const { asm } = this;
|
|
1496
1558
|
// TODO: Should positive lookahead record a CST?
|
|
1559
|
+
asm.pushFluffySavePoint();
|
|
1497
1560
|
this.emitPExpr(child);
|
|
1498
1561
|
asm.restoreBindingsLength();
|
|
1499
1562
|
asm.restorePos();
|
|
1500
|
-
// When lookahead succeeds, mark failures as fluffy
|
|
1563
|
+
// When lookahead succeeds, mark inner failures as fluffy (scoped).
|
|
1501
1564
|
asm.localGet('ret');
|
|
1502
1565
|
asm.if(w.blocktype.empty, () => {
|
|
1503
|
-
asm.
|
|
1566
|
+
asm.popFluffySavePointIfAtErrorPos();
|
|
1567
|
+
}, () => {
|
|
1568
|
+
asm.popFluffySavePoint(false);
|
|
1504
1569
|
});
|
|
1505
1570
|
}
|
|
1506
|
-
emitNot(
|
|
1571
|
+
emitNot(exp) {
|
|
1572
|
+
const { child } = exp;
|
|
1507
1573
|
const { asm } = this;
|
|
1508
|
-
const failureId = this.toFailure(
|
|
1509
|
-
|
|
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.
|
|
1510
1580
|
asm.pushStackFrame(() => {
|
|
1511
|
-
asm.saveFailurePos();
|
|
1512
|
-
asm.saveGlobalFailurePos();
|
|
1513
|
-
|
|
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);
|
|
1514
1588
|
this.emitPExpr(child);
|
|
1515
1589
|
// Invert the result.
|
|
1516
1590
|
asm.localGet('ret');
|
|
@@ -1519,26 +1593,34 @@ export class Compiler {
|
|
|
1519
1593
|
// Restore all global and local state.
|
|
1520
1594
|
asm.restoreGlobalFailurePos();
|
|
1521
1595
|
asm.restoreFailurePos();
|
|
1522
|
-
|
|
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);
|
|
1523
1607
|
asm.restoreBindingsLength();
|
|
1524
1608
|
asm.restorePos();
|
|
1525
1609
|
asm.localGet('ret');
|
|
1526
|
-
asm.
|
|
1527
|
-
// When not succeeds (child failed), mark failures as fluffy
|
|
1528
|
-
asm.maybeMarkFailuresAsFluffy();
|
|
1529
|
-
}, () => {
|
|
1610
|
+
asm.ifFalse(w.blocktype.empty, () => {
|
|
1530
1611
|
// When not fails (child succeeded), update failurePos to origPos.
|
|
1531
1612
|
// This is equivalent to Ohm.js's processFailure(origPos, this).
|
|
1532
1613
|
// Note: pos has already been restored by restorePos() above.
|
|
1533
1614
|
asm.updateLocalFailurePos(() => asm.globalGet('pos'));
|
|
1534
1615
|
asm.updateGlobalFailurePos();
|
|
1535
1616
|
if (failureId >= 0) {
|
|
1536
|
-
asm.maybeRecordFailure(() => asm.globalGet('pos'), failureId
|
|
1617
|
+
asm.maybeRecordFailure(() => asm.globalGet('pos'), failureId);
|
|
1537
1618
|
}
|
|
1538
1619
|
});
|
|
1539
1620
|
}
|
|
1540
1621
|
emitOpt({ child }) {
|
|
1541
1622
|
const { asm } = this;
|
|
1623
|
+
asm.pushFluffySavePoint();
|
|
1542
1624
|
this.emitPExpr(child);
|
|
1543
1625
|
asm.localGet('ret');
|
|
1544
1626
|
asm.ifFalse(w.blocktype.empty, () => {
|
|
@@ -1546,7 +1628,8 @@ export class Compiler {
|
|
|
1546
1628
|
asm.restoreBindingsLength();
|
|
1547
1629
|
});
|
|
1548
1630
|
asm.newIterNodeWithSavedPosAndBindings(ir.outArity(child), true);
|
|
1549
|
-
|
|
1631
|
+
// Opt always succeeds, so mark inner failures as fluffy (scoped).
|
|
1632
|
+
asm.popFluffySavePointIfAtErrorPos();
|
|
1550
1633
|
asm.localSet('ret');
|
|
1551
1634
|
}
|
|
1552
1635
|
emitPlus(plusExp) {
|
|
@@ -1603,6 +1686,7 @@ export class Compiler {
|
|
|
1603
1686
|
}
|
|
1604
1687
|
emitStar({ child }, { reuseStackFrame } = {}) {
|
|
1605
1688
|
const { asm } = this;
|
|
1689
|
+
asm.pushFluffySavePoint();
|
|
1606
1690
|
// We push another stack frame because we need to save and restore
|
|
1607
1691
|
// the position just before the last (failed) expression.
|
|
1608
1692
|
asm.pushStackFrame();
|
|
@@ -1621,7 +1705,8 @@ export class Compiler {
|
|
|
1621
1705
|
asm.restoreBindingsLength();
|
|
1622
1706
|
asm.popStackFrame();
|
|
1623
1707
|
asm.newIterNodeWithSavedPosAndBindings(ir.outArity(child));
|
|
1624
|
-
|
|
1708
|
+
// Star always succeeds, so mark inner failures as fluffy (scoped).
|
|
1709
|
+
asm.popFluffySavePointIfAtErrorPos();
|
|
1625
1710
|
asm.localSet('ret');
|
|
1626
1711
|
}
|
|
1627
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);
|
package/package.json
CHANGED
package/dist/src/util.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export function awaitBuiltInRules(cb: any): void;
|
|
2
|
-
export function announceBuiltInRules(grammar: any): void;
|
|
3
|
-
export function getLineAndColumn(str: any, offset: any): {
|
|
4
|
-
offset: any;
|
|
5
|
-
lineNum: number;
|
|
6
|
-
colNum: number;
|
|
7
|
-
line: any;
|
|
8
|
-
prevLine: any;
|
|
9
|
-
nextLine: any;
|
|
10
|
-
toString: typeof lineAndColumnToMessage;
|
|
11
|
-
};
|
|
12
|
-
export function getLineAndColumnMessage(str: any, offset: any, ...ranges: any[]): any;
|
|
13
|
-
export function uniqueId(prefix: any): string;
|
|
14
|
-
declare function lineAndColumnToMessage(...ranges: any[]): any;
|
|
15
|
-
export {};
|
|
16
|
-
//# sourceMappingURL=util.d.ts.map
|
package/dist/src/util.js
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import * as common from './common.js';
|
|
2
|
-
// --------------------------------------------------------------------
|
|
3
|
-
// Private stuff
|
|
4
|
-
// --------------------------------------------------------------------
|
|
5
|
-
// Given an array of numbers `arr`, return an array of the numbers as strings,
|
|
6
|
-
// right-justified and padded to the same length.
|
|
7
|
-
function padNumbersToEqualLength(arr) {
|
|
8
|
-
let maxLen = 0;
|
|
9
|
-
const strings = arr.map(n => {
|
|
10
|
-
const str = n.toString();
|
|
11
|
-
maxLen = Math.max(maxLen, str.length);
|
|
12
|
-
return str;
|
|
13
|
-
});
|
|
14
|
-
return strings.map(s => common.padLeft(s, maxLen));
|
|
15
|
-
}
|
|
16
|
-
// Produce a new string that would be the result of copying the contents
|
|
17
|
-
// of the string `src` onto `dest` at offset `offest`.
|
|
18
|
-
function strcpy(dest, src, offset) {
|
|
19
|
-
const origDestLen = dest.length;
|
|
20
|
-
const start = dest.slice(0, offset);
|
|
21
|
-
const end = dest.slice(offset + src.length);
|
|
22
|
-
return (start + src + end).substr(0, origDestLen);
|
|
23
|
-
}
|
|
24
|
-
// Casts the underlying lineAndCol object to a formatted message string,
|
|
25
|
-
// highlighting `ranges`.
|
|
26
|
-
function lineAndColumnToMessage(...ranges) {
|
|
27
|
-
const lineAndCol = this;
|
|
28
|
-
const { offset } = lineAndCol;
|
|
29
|
-
const { repeatStr } = common;
|
|
30
|
-
const sb = new common.StringBuffer();
|
|
31
|
-
sb.append('Line ' + lineAndCol.lineNum + ', col ' + lineAndCol.colNum + ':\n');
|
|
32
|
-
// An array of the previous, current, and next line numbers as strings of equal length.
|
|
33
|
-
const lineNumbers = padNumbersToEqualLength([
|
|
34
|
-
lineAndCol.prevLine == null ? 0 : lineAndCol.lineNum - 1,
|
|
35
|
-
lineAndCol.lineNum,
|
|
36
|
-
lineAndCol.nextLine == null ? 0 : lineAndCol.lineNum + 1,
|
|
37
|
-
]);
|
|
38
|
-
// Helper for appending formatting input lines to the buffer.
|
|
39
|
-
const appendLine = (num, content, prefix) => {
|
|
40
|
-
sb.append(prefix + lineNumbers[num] + ' | ' + content + '\n');
|
|
41
|
-
};
|
|
42
|
-
// Include the previous line for context if possible.
|
|
43
|
-
if (lineAndCol.prevLine != null) {
|
|
44
|
-
appendLine(0, lineAndCol.prevLine, ' ');
|
|
45
|
-
}
|
|
46
|
-
// Line that the error occurred on.
|
|
47
|
-
appendLine(1, lineAndCol.line, '> ');
|
|
48
|
-
// Build up the line that points to the offset and possible indicates one or more ranges.
|
|
49
|
-
// Start with a blank line, and indicate each range by overlaying a string of `~` chars.
|
|
50
|
-
const lineLen = lineAndCol.line.length;
|
|
51
|
-
let indicationLine = repeatStr(' ', lineLen + 1);
|
|
52
|
-
for (let i = 0; i < ranges.length; ++i) {
|
|
53
|
-
let startIdx = ranges[i][0];
|
|
54
|
-
let endIdx = ranges[i][1];
|
|
55
|
-
common.assert(startIdx >= 0 && startIdx <= endIdx, 'range start must be >= 0 and <= end');
|
|
56
|
-
const lineStartOffset = offset - lineAndCol.colNum + 1;
|
|
57
|
-
startIdx = Math.max(0, startIdx - lineStartOffset);
|
|
58
|
-
endIdx = Math.min(endIdx - lineStartOffset, lineLen);
|
|
59
|
-
indicationLine = strcpy(indicationLine, repeatStr('~', endIdx - startIdx), startIdx);
|
|
60
|
-
}
|
|
61
|
-
const gutterWidth = 2 + lineNumbers[1].length + 3;
|
|
62
|
-
sb.append(repeatStr(' ', gutterWidth));
|
|
63
|
-
indicationLine = strcpy(indicationLine, '^', lineAndCol.colNum - 1);
|
|
64
|
-
sb.append(indicationLine.replace(/ +$/, '') + '\n');
|
|
65
|
-
// Include the next line for context if possible.
|
|
66
|
-
if (lineAndCol.nextLine != null) {
|
|
67
|
-
appendLine(2, lineAndCol.nextLine, ' ');
|
|
68
|
-
}
|
|
69
|
-
return sb.contents();
|
|
70
|
-
}
|
|
71
|
-
// --------------------------------------------------------------------
|
|
72
|
-
// Exports
|
|
73
|
-
// --------------------------------------------------------------------
|
|
74
|
-
let builtInRulesCallbacks = [];
|
|
75
|
-
// Since Grammar.BuiltInRules is bootstrapped, most of Ohm can't directly depend it.
|
|
76
|
-
// This function allows modules that do depend on the built-in rules to register a callback
|
|
77
|
-
// that will be called later in the initialization process.
|
|
78
|
-
export function awaitBuiltInRules(cb) {
|
|
79
|
-
builtInRulesCallbacks.push(cb);
|
|
80
|
-
}
|
|
81
|
-
export function announceBuiltInRules(grammar) {
|
|
82
|
-
builtInRulesCallbacks.forEach(cb => {
|
|
83
|
-
cb(grammar);
|
|
84
|
-
});
|
|
85
|
-
builtInRulesCallbacks = null;
|
|
86
|
-
}
|
|
87
|
-
// Return an object with the line and column information for the given
|
|
88
|
-
// offset in `str`.
|
|
89
|
-
export function getLineAndColumn(str, offset) {
|
|
90
|
-
let lineNum = 1;
|
|
91
|
-
let colNum = 1;
|
|
92
|
-
let currOffset = 0;
|
|
93
|
-
let lineStartOffset = 0;
|
|
94
|
-
let nextLine = null;
|
|
95
|
-
let prevLine = null;
|
|
96
|
-
let prevLineStartOffset = -1;
|
|
97
|
-
while (currOffset < offset) {
|
|
98
|
-
const c = str.charAt(currOffset++);
|
|
99
|
-
if (c === '\n') {
|
|
100
|
-
lineNum++;
|
|
101
|
-
colNum = 1;
|
|
102
|
-
prevLineStartOffset = lineStartOffset;
|
|
103
|
-
lineStartOffset = currOffset;
|
|
104
|
-
}
|
|
105
|
-
else if (c !== '\r') {
|
|
106
|
-
colNum++;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
// Find the end of the target line.
|
|
110
|
-
let lineEndOffset = str.indexOf('\n', lineStartOffset);
|
|
111
|
-
if (lineEndOffset === -1) {
|
|
112
|
-
lineEndOffset = str.length;
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
// Get the next line.
|
|
116
|
-
const nextLineEndOffset = str.indexOf('\n', lineEndOffset + 1);
|
|
117
|
-
nextLine =
|
|
118
|
-
nextLineEndOffset === -1
|
|
119
|
-
? str.slice(lineEndOffset)
|
|
120
|
-
: str.slice(lineEndOffset, nextLineEndOffset);
|
|
121
|
-
// Strip leading and trailing EOL char(s).
|
|
122
|
-
nextLine = nextLine.replace(/^\r?\n/, '').replace(/\r$/, '');
|
|
123
|
-
}
|
|
124
|
-
// Get the previous line.
|
|
125
|
-
if (prevLineStartOffset >= 0) {
|
|
126
|
-
// Strip trailing EOL char(s).
|
|
127
|
-
prevLine = str.slice(prevLineStartOffset, lineStartOffset).replace(/\r?\n$/, '');
|
|
128
|
-
}
|
|
129
|
-
// Get the target line, stripping a trailing carriage return if necessary.
|
|
130
|
-
const line = str.slice(lineStartOffset, lineEndOffset).replace(/\r$/, '');
|
|
131
|
-
return {
|
|
132
|
-
offset,
|
|
133
|
-
lineNum,
|
|
134
|
-
colNum,
|
|
135
|
-
line,
|
|
136
|
-
prevLine,
|
|
137
|
-
nextLine,
|
|
138
|
-
toString: lineAndColumnToMessage,
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
// Return a nicely-formatted string describing the line and column for the
|
|
142
|
-
// given offset in `str` highlighting `ranges`.
|
|
143
|
-
export function getLineAndColumnMessage(str, offset, ...ranges) {
|
|
144
|
-
return getLineAndColumn(str, offset).toString(...ranges);
|
|
145
|
-
}
|
|
146
|
-
export const uniqueId = (() => {
|
|
147
|
-
let idCounter = 0;
|
|
148
|
-
return prefix => '' + prefix + idCounter++;
|
|
149
|
-
})();
|
|
150
|
-
//# sourceMappingURL=util.js.map
|