@ohm-js/wasm 0.7.0 → 0.7.2
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 +5 -2
- package/dist/build/ohmRuntime.wasm_sections.js +11 -32
- package/dist/src/Compiler.d.ts +3 -2
- package/dist/src/Compiler.js +41 -12
- package/dist/src/miniohm.d.ts +3 -1
- package/dist/src/miniohm.js +12 -3
- 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 = 76;
|
|
3
3
|
export declare const funcidxByName: {
|
|
4
4
|
resetHeap: number;
|
|
5
5
|
match: number;
|
|
@@ -16,11 +16,14 @@ export declare const funcidxByName: {
|
|
|
16
16
|
bindingsAt: number;
|
|
17
17
|
doMatchUnicodeChar: number;
|
|
18
18
|
recordFailure: number;
|
|
19
|
-
|
|
19
|
+
makeFluffyFrom: number;
|
|
20
20
|
isFluffy: number;
|
|
21
21
|
getRecordedFailuresLength: number;
|
|
22
22
|
setRecordedFailuresLength: number;
|
|
23
23
|
recordedFailuresAt: number;
|
|
24
|
+
pushFluffySavePoint: number;
|
|
25
|
+
markFluffyFromSavePoint: number;
|
|
26
|
+
dropFluffySavePoint: number;
|
|
24
27
|
};
|
|
25
28
|
export declare const typesec: {
|
|
26
29
|
entryCount: number;
|
|
@@ -7,47 +7,26 @@ function decodeBase64(str) {
|
|
|
7
7
|
return result;
|
|
8
8
|
}
|
|
9
9
|
export const destImportCount = 5;
|
|
10
|
-
export const startFuncidx =
|
|
11
|
-
export const funcidxByName = {
|
|
12
|
-
resetHeap: 30,
|
|
13
|
-
match: 67,
|
|
14
|
-
recordFailures: 69,
|
|
15
|
-
evalApplyGeneralized: 70,
|
|
16
|
-
evalApplyNoMemo0: 71,
|
|
17
|
-
evalApply0: 50,
|
|
18
|
-
handleLeftRecursion: 49,
|
|
19
|
-
newTerminalNode: 72,
|
|
20
|
-
newNonterminalNode: 47,
|
|
21
|
-
newIterationNode: 73,
|
|
22
|
-
getBindingsLength: 74,
|
|
23
|
-
setBindingsLength: 75,
|
|
24
|
-
bindingsAt: 76,
|
|
25
|
-
doMatchUnicodeChar: 77,
|
|
26
|
-
recordFailure: 65,
|
|
27
|
-
makeFluffy: 79,
|
|
28
|
-
isFluffy: 81,
|
|
29
|
-
getRecordedFailuresLength: 82,
|
|
30
|
-
setRecordedFailuresLength: 83,
|
|
31
|
-
recordedFailuresAt: 84,
|
|
32
|
-
};
|
|
10
|
+
export const startFuncidx = 76;
|
|
11
|
+
export const funcidxByName = { "resetHeap": 27, "match": 54, "recordFailures": 55, "evalApplyGeneralized": 56, "evalApplyNoMemo0": 57, "evalApply0": 47, "handleLeftRecursion": 46, "newTerminalNode": 58, "newNonterminalNode": 44, "newIterationNode": 59, "getBindingsLength": 60, "setBindingsLength": 61, "bindingsAt": 62, "doMatchUnicodeChar": 63, "recordFailure": 52, "makeFluffyFrom": 66, "isFluffy": 68, "getRecordedFailuresLength": 69, "setRecordedFailuresLength": 70, "recordedFailuresAt": 71, "pushFluffySavePoint": 72, "markFluffyFromSavePoint": 74, "dropFluffySavePoint": 75 };
|
|
33
12
|
export const typesec = {
|
|
34
|
-
entryCount:
|
|
35
|
-
contents: decodeBase64(
|
|
13
|
+
entryCount: 12,
|
|
14
|
+
contents: decodeBase64("YAF/AX9gAn9/AGACf38Bf2AAAGABfwBgAAF/YAN/f38AYAR/f39/AGAFf39/f38Bf2ABbwF/YAR/f39/AX9gAm9/AX8=")
|
|
36
15
|
};
|
|
37
16
|
export const importsec = {
|
|
38
17
|
entryCount: 4,
|
|
39
|
-
contents: decodeBase64(
|
|
18
|
+
contents: decodeBase64("A2VudgVhYm9ydAAHDndhc206anMtc3RyaW5nBmxlbmd0aAAJCm9obVJ1bnRpbWUPaXNSdWxlU3ludGFjdGljAAAKb2htUnVudGltZRBtYXRjaFVuaWNvZGVDaGFyAAA=")
|
|
40
19
|
};
|
|
41
20
|
export const funcsec = {
|
|
42
|
-
entryCount:
|
|
43
|
-
contents: decodeBase64(
|
|
21
|
+
entryCount: 72,
|
|
22
|
+
contents: decodeBase64("BAEAAQEBAQIGAQEBAQIBAQEBAgMDAwMDAAAAAAAAAgIHAAICAAIBCAYKAAEAAAIEAAsEAgACCAUEAAAABgQCAAUEAAMAAwMD")
|
|
44
23
|
};
|
|
45
24
|
export const globalsec = {
|
|
46
|
-
entryCount:
|
|
47
|
-
contents: decodeBase64(
|
|
25
|
+
entryCount: 18,
|
|
26
|
+
contents: decodeBase64("fwFBAAt/AUEAC28B0G8LfwFBAAt/AUEAC38BQX8LfwFBAAt/AEEAC38AQQELfwBBAgt/AUEAC38BQQALfwBBAAt/AUEAC38BQQALfwFBAAt/AUEAC38AQZyDBAs=")
|
|
48
27
|
};
|
|
49
28
|
export const codesec = {
|
|
50
|
-
entryCount:
|
|
51
|
-
contents: decodeBase64(
|
|
29
|
+
entryCount: 72,
|
|
30
|
+
contents: decodeBase64("YAEGfz8AIQEgAUEQdEEPakEPQX9zcSECIAAgAksEQCAAIAJrQf//A2pB//8DQX9zcUEQdiEDIAEiBCADIgUgBCAFShshBiAGQABBAEgEQCADQABBAEgEQAALCwsgACQLCwkAIAAgATYCAAtWAQR/IABB/P///wNLBEBBgIEEQcCBBEEhQR0QAAALIwshASMLQQRqIQICfyAAIQMgA0EEakEPakEPQX9zcUEEawwACyEEIAIgBGoQBSABIAQQBiACDwsJACAAIAE2AgQLCQAgACABNgIICwkAIAAgATYCDAsJACAAIAE2AhALTgECfyAAQez///8DSwRAQYCBBEHAgQRB1gBBHhAAAAtBECAAahAHIQIgAkEEayEDIANBABAIIANBABAJIAMgARAKIAMgABALIAJBEGoPCwMAAQsRACAAIAE2AgAgACABQQAQDQsJACAAIAE2AgQLCQAgACABNgIICwkAIAAgATYCDAuNAQEEfyAAR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AaCyYBAX8gACEBA0AgASMPEEBIBEAjDyABQQEQQSABQQFqIQEMAQsLCzMBAX8gASAAEDFPBEBBwIIEQdCABEHyAEEqEAAACyAAEDIgAUEAdGotAAAhAkEAGiACDwsMACMPIAAQQ0EARw8LBwAjDhApDwsOACMOIAAQKyMPIAAQMAsJACMOIAAQKg8LFAAjBUEASARADwsjECMOECkQJxoLPwECfyAAEB8hASABQQFIBEBBgIMEQdCABEGPAkESEAAACyAAECYgAUEBayIBQQJ0aigCACECIAAgARARIAIPC0ABAn8jBUEASARADwsjEBApQQBGBEAPCyMQEEkhACAAIQEDQCABIw8QQEgEQCMPIAFBARBBIAFBAWohAQwBCwsLGwAjBUEASARADwsjEBApQQBGBEAPCyMQEEkaCwQAEBgL")
|
|
52
31
|
};
|
|
53
32
|
//# 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: StringTable;
|
|
11
11
|
_failureDescriptions: StringTable;
|
|
12
12
|
_endOfInputFailureId: any;
|
|
13
13
|
_deferredRuleIds: Set<any>;
|
|
@@ -185,7 +185,8 @@ declare class Assembler {
|
|
|
185
185
|
newTerminalNode(): void;
|
|
186
186
|
i32Max(aThunk: any, bThunk: any): void;
|
|
187
187
|
depthOf(label: any): number;
|
|
188
|
-
|
|
188
|
+
pushFluffySavePoint(): void;
|
|
189
|
+
maybeMarkFluffyFromSavePoint(): void;
|
|
189
190
|
ruleEvalReturn(): void;
|
|
190
191
|
}
|
|
191
192
|
declare namespace Assembler {
|
package/dist/src/Compiler.js
CHANGED
|
@@ -629,13 +629,20 @@ class Assembler {
|
|
|
629
629
|
assert(i !== -1, `Unknown label: ${label}`);
|
|
630
630
|
return this._blockStack.length - i - 1;
|
|
631
631
|
}
|
|
632
|
-
|
|
633
|
-
|
|
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
|
+
pushFluffySavePoint() {
|
|
636
|
+
this.callPrebuiltFunc('pushFluffySavePoint');
|
|
637
|
+
}
|
|
638
|
+
maybeMarkFluffyFromSavePoint() {
|
|
634
639
|
this.globalGet('errorMessagePos');
|
|
635
|
-
this.
|
|
636
|
-
this.
|
|
640
|
+
this.globalGet('pos');
|
|
641
|
+
this.i32Eq();
|
|
637
642
|
this.if(w.blocktype.empty, () => {
|
|
638
|
-
this.callPrebuiltFunc('
|
|
643
|
+
this.callPrebuiltFunc('markFluffyFromSavePoint');
|
|
644
|
+
}, () => {
|
|
645
|
+
this.callPrebuiltFunc('dropFluffySavePoint');
|
|
639
646
|
});
|
|
640
647
|
}
|
|
641
648
|
ruleEvalReturn() {
|
|
@@ -828,7 +835,8 @@ export class Compiler {
|
|
|
828
835
|
asm.addGlobal('__ASC_RUNTIME', w.valtype.i32, w.mut.const, () => asm.i32Const(0));
|
|
829
836
|
asm.addGlobal('bindings', w.valtype.i32, w.mut.var, () => asm.i32Const(0));
|
|
830
837
|
asm.addGlobal('recordedFailures', w.valtype.i32, w.mut.var, () => asm.i32Const(0));
|
|
831
|
-
asm.addGlobal('
|
|
838
|
+
asm.addGlobal('fluffyFlags', w.valtype.i32, w.mut.var, () => asm.i32Const(0));
|
|
839
|
+
asm.addGlobal('fluffySaveStack', w.valtype.i32, w.mut.var, () => asm.i32Const(0));
|
|
832
840
|
asm.addGlobal('__heap_base', w.valtype.i32, w.mut.var, () => asm.i32Const(65948));
|
|
833
841
|
// Reserve a fixed number of imports for debug labels.
|
|
834
842
|
if (DEBUG) {
|
|
@@ -1004,6 +1012,9 @@ export class Compiler {
|
|
|
1004
1012
|
asm.addLocal('failurePos', w.valtype.i32);
|
|
1005
1013
|
asm.globalGet('rightmostFailurePos');
|
|
1006
1014
|
asm.localSet('failurePos');
|
|
1015
|
+
// Save the failure count so we can scope fluffy marking to failures
|
|
1016
|
+
// recorded during this rule's evaluation only.
|
|
1017
|
+
asm.pushFluffySavePoint();
|
|
1007
1018
|
if (hasDescription) {
|
|
1008
1019
|
asm.pushDescriptionFrame();
|
|
1009
1020
|
}
|
|
@@ -1015,6 +1026,15 @@ export class Compiler {
|
|
|
1015
1026
|
}
|
|
1016
1027
|
asm.emit(`BEGIN eval:${name}`);
|
|
1017
1028
|
this.emitPExpr(ruleInfo.body);
|
|
1029
|
+
// When a rule body succeeds and pos matches errorMessagePos, mark
|
|
1030
|
+
// failures recorded DURING this rule eval as fluffy. This mirrors
|
|
1031
|
+
// ohm-js's MatchState.eval_, which uses scoped failure recording.
|
|
1032
|
+
asm.localGet('ret');
|
|
1033
|
+
asm.if(w.blocktype.empty, () => {
|
|
1034
|
+
asm.maybeMarkFluffyFromSavePoint();
|
|
1035
|
+
}, () => {
|
|
1036
|
+
asm.callPrebuiltFunc('dropFluffySavePoint');
|
|
1037
|
+
});
|
|
1018
1038
|
// Handle rules with descriptions - must come BEFORE restoreFailurePos
|
|
1019
1039
|
if (hasDescription)
|
|
1020
1040
|
asm.handleDescriptionFailure(descriptionId);
|
|
@@ -1494,19 +1514,23 @@ export class Compiler {
|
|
|
1494
1514
|
emitLookahead({ child }) {
|
|
1495
1515
|
const { asm } = this;
|
|
1496
1516
|
// TODO: Should positive lookahead record a CST?
|
|
1517
|
+
asm.pushFluffySavePoint();
|
|
1497
1518
|
this.emitPExpr(child);
|
|
1498
1519
|
asm.restoreBindingsLength();
|
|
1499
1520
|
asm.restorePos();
|
|
1500
|
-
// When lookahead succeeds, mark failures as fluffy
|
|
1521
|
+
// When lookahead succeeds, mark inner failures as fluffy (scoped).
|
|
1501
1522
|
asm.localGet('ret');
|
|
1502
1523
|
asm.if(w.blocktype.empty, () => {
|
|
1503
|
-
asm.
|
|
1524
|
+
asm.maybeMarkFluffyFromSavePoint();
|
|
1525
|
+
}, () => {
|
|
1526
|
+
asm.callPrebuiltFunc('dropFluffySavePoint');
|
|
1504
1527
|
});
|
|
1505
1528
|
}
|
|
1506
1529
|
emitNot({ child }) {
|
|
1507
1530
|
const { asm } = this;
|
|
1508
1531
|
const failureId = this.toFailure(child);
|
|
1509
1532
|
// Push an inner stack frame with the failure positions.
|
|
1533
|
+
asm.pushFluffySavePoint();
|
|
1510
1534
|
asm.pushStackFrame(() => {
|
|
1511
1535
|
asm.saveFailurePos();
|
|
1512
1536
|
asm.saveGlobalFailurePos();
|
|
@@ -1524,9 +1548,10 @@ export class Compiler {
|
|
|
1524
1548
|
asm.restorePos();
|
|
1525
1549
|
asm.localGet('ret');
|
|
1526
1550
|
asm.ifElse(w.blocktype.empty, () => {
|
|
1527
|
-
// When not succeeds (child failed), mark failures as fluffy
|
|
1528
|
-
asm.
|
|
1551
|
+
// When not succeeds (child failed), mark inner failures as fluffy (scoped).
|
|
1552
|
+
asm.maybeMarkFluffyFromSavePoint();
|
|
1529
1553
|
}, () => {
|
|
1554
|
+
asm.callPrebuiltFunc('dropFluffySavePoint');
|
|
1530
1555
|
// When not fails (child succeeded), update failurePos to origPos.
|
|
1531
1556
|
// This is equivalent to Ohm.js's processFailure(origPos, this).
|
|
1532
1557
|
// Note: pos has already been restored by restorePos() above.
|
|
@@ -1539,6 +1564,7 @@ export class Compiler {
|
|
|
1539
1564
|
}
|
|
1540
1565
|
emitOpt({ child }) {
|
|
1541
1566
|
const { asm } = this;
|
|
1567
|
+
asm.pushFluffySavePoint();
|
|
1542
1568
|
this.emitPExpr(child);
|
|
1543
1569
|
asm.localGet('ret');
|
|
1544
1570
|
asm.ifFalse(w.blocktype.empty, () => {
|
|
@@ -1546,7 +1572,8 @@ export class Compiler {
|
|
|
1546
1572
|
asm.restoreBindingsLength();
|
|
1547
1573
|
});
|
|
1548
1574
|
asm.newIterNodeWithSavedPosAndBindings(ir.outArity(child), true);
|
|
1549
|
-
|
|
1575
|
+
// Opt always succeeds, so mark inner failures as fluffy (scoped).
|
|
1576
|
+
asm.maybeMarkFluffyFromSavePoint();
|
|
1550
1577
|
asm.localSet('ret');
|
|
1551
1578
|
}
|
|
1552
1579
|
emitPlus(plusExp) {
|
|
@@ -1603,6 +1630,7 @@ export class Compiler {
|
|
|
1603
1630
|
}
|
|
1604
1631
|
emitStar({ child }, { reuseStackFrame } = {}) {
|
|
1605
1632
|
const { asm } = this;
|
|
1633
|
+
asm.pushFluffySavePoint();
|
|
1606
1634
|
// We push another stack frame because we need to save and restore
|
|
1607
1635
|
// the position just before the last (failed) expression.
|
|
1608
1636
|
asm.pushStackFrame();
|
|
@@ -1621,7 +1649,8 @@ export class Compiler {
|
|
|
1621
1649
|
asm.restoreBindingsLength();
|
|
1622
1650
|
asm.popStackFrame();
|
|
1623
1651
|
asm.newIterNodeWithSavedPosAndBindings(ir.outArity(child));
|
|
1624
|
-
|
|
1652
|
+
// Star always succeeds, so mark inner failures as fluffy (scoped).
|
|
1653
|
+
asm.maybeMarkFluffyFromSavePoint();
|
|
1625
1654
|
asm.localSet('ret');
|
|
1626
1655
|
}
|
|
1627
1656
|
wrapTerminalLike(thunk, failureId) {
|
package/dist/src/miniohm.d.ts
CHANGED
|
@@ -213,6 +213,7 @@ export declare class MatchResult {
|
|
|
213
213
|
startExpr: string;
|
|
214
214
|
_ctx: MatchContext;
|
|
215
215
|
_succeeded: boolean;
|
|
216
|
+
_attached: boolean;
|
|
216
217
|
constructor(grammar: WasmGrammar, startExpr: string, ctx: MatchContext, succeeded: boolean);
|
|
217
218
|
get input(): string;
|
|
218
219
|
[Symbol.dispose](): void;
|
|
@@ -227,10 +228,11 @@ export declare class SucceededMatchResult extends MatchResult {
|
|
|
227
228
|
constructor(grammar: WasmGrammar, startExpr: string, ctx: MatchContext, succeeded: boolean);
|
|
228
229
|
}
|
|
229
230
|
export declare class FailedMatchResult extends MatchResult {
|
|
230
|
-
constructor(grammar: WasmGrammar, startExpr: string, ctx: MatchContext, succeeded: boolean, rightmostFailurePosition: number);
|
|
231
231
|
_rightmostFailurePosition: number;
|
|
232
232
|
private _rightmostFailures;
|
|
233
233
|
private _failureDescriptions;
|
|
234
|
+
constructor(grammar: WasmGrammar, startExpr: string, ctx: MatchContext, succeeded: boolean, rightmostFailurePosition: number);
|
|
235
|
+
private _assertAttached;
|
|
234
236
|
getRightmostFailurePosition(): number;
|
|
235
237
|
getRightmostFailures(): Failure[];
|
|
236
238
|
private _getFailureDescriptions;
|
package/dist/src/miniohm.js
CHANGED
|
@@ -236,6 +236,7 @@ export class WasmGrammar {
|
|
|
236
236
|
assert(this._resultStack.at(-1) === result, `You can only detach() the most recent MatchResult`);
|
|
237
237
|
this._beginUse(result);
|
|
238
238
|
this._endUse(result);
|
|
239
|
+
result._attached = false;
|
|
239
240
|
}
|
|
240
241
|
match(input, ruleName) {
|
|
241
242
|
assert(this._resultStack.length === this._managedResultCount, 'Cannot match while there are unmanaged MatchResults');
|
|
@@ -599,6 +600,7 @@ export class MatchResult {
|
|
|
599
600
|
startExpr;
|
|
600
601
|
_ctx;
|
|
601
602
|
_succeeded;
|
|
603
|
+
_attached = true;
|
|
602
604
|
constructor(grammar, startExpr, ctx, succeeded) {
|
|
603
605
|
this.grammar = grammar;
|
|
604
606
|
this.startExpr = startExpr;
|
|
@@ -648,18 +650,25 @@ export class SucceededMatchResult extends MatchResult {
|
|
|
648
650
|
}
|
|
649
651
|
}
|
|
650
652
|
export class FailedMatchResult extends MatchResult {
|
|
653
|
+
_rightmostFailurePosition;
|
|
654
|
+
_rightmostFailures = null;
|
|
655
|
+
_failureDescriptions = null;
|
|
651
656
|
constructor(grammar, startExpr, ctx, succeeded, rightmostFailurePosition) {
|
|
652
657
|
super(grammar, startExpr, ctx, succeeded);
|
|
653
658
|
this._rightmostFailurePosition = rightmostFailurePosition;
|
|
654
659
|
}
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
660
|
+
_assertAttached(property) {
|
|
661
|
+
if (!this._attached) {
|
|
662
|
+
throw new Error(`Cannot access '${property}' after MatchResult has been detached. ` +
|
|
663
|
+
`Access failure information before calling detach(), or use result.use().`);
|
|
664
|
+
}
|
|
665
|
+
}
|
|
658
666
|
getRightmostFailurePosition() {
|
|
659
667
|
return this._rightmostFailurePosition;
|
|
660
668
|
}
|
|
661
669
|
getRightmostFailures() {
|
|
662
670
|
if (this._rightmostFailures === null) {
|
|
671
|
+
this._assertAttached('getRightmostFailures()');
|
|
663
672
|
const { exports } = this.grammar._instance;
|
|
664
673
|
const ruleIds = this.grammar._ruleIds;
|
|
665
674
|
const ruleNames = this.grammar._ruleNames;
|
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
|