@ohm-js/wasm 0.6.14 → 0.6.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/miniohm.d.ts +6 -5
- package/dist/src/miniohm.js +7 -5
- package/package.json +1 -1
package/dist/src/miniohm.d.ts
CHANGED
|
@@ -38,7 +38,7 @@ export declare class WasmGrammar {
|
|
|
38
38
|
private _fillInputBuffer;
|
|
39
39
|
getRightmostFailurePosition(): number;
|
|
40
40
|
}
|
|
41
|
-
|
|
41
|
+
interface MatchContext {
|
|
42
42
|
ruleNames: string[];
|
|
43
43
|
view: DataView;
|
|
44
44
|
input: string;
|
|
@@ -71,6 +71,7 @@ export interface TerminalNode extends CstNodeBase {
|
|
|
71
71
|
type: typeof CstNodeType.TERMINAL;
|
|
72
72
|
ctorName: '_terminal';
|
|
73
73
|
leadingSpaces?: NonterminalNode;
|
|
74
|
+
children: readonly [];
|
|
74
75
|
value: string;
|
|
75
76
|
}
|
|
76
77
|
export interface ListNode<TNode extends CstNode = CstNode> extends CstNodeBase {
|
|
@@ -202,16 +203,16 @@ export declare class MatchResult {
|
|
|
202
203
|
toString(): string;
|
|
203
204
|
use<T>(cb: (r: MatchResult) => T): T;
|
|
204
205
|
}
|
|
205
|
-
declare class SucceededMatchResult extends MatchResult {
|
|
206
|
+
export declare class SucceededMatchResult extends MatchResult {
|
|
206
207
|
_cst: CstNode;
|
|
207
208
|
constructor(grammar: WasmGrammar, startExpr: string, ctx: MatchContext, succeeded: boolean);
|
|
208
209
|
}
|
|
209
|
-
declare class FailedMatchResult extends MatchResult {
|
|
210
|
+
export declare class FailedMatchResult extends MatchResult {
|
|
210
211
|
constructor(grammar: WasmGrammar, startExpr: string, ctx: MatchContext, succeeded: boolean, rightmostFailurePosition: number, optRecordedFailures?: any);
|
|
211
212
|
_rightmostFailurePosition: number;
|
|
212
213
|
_rightmostFailures: any;
|
|
213
|
-
shortMessage
|
|
214
|
-
message
|
|
214
|
+
shortMessage: string;
|
|
215
|
+
message: string;
|
|
215
216
|
getRightmostFailurePosition(): number;
|
|
216
217
|
getRightmostFailures(): any;
|
|
217
218
|
getExpectedText(): string;
|
package/dist/src/miniohm.js
CHANGED
|
@@ -15,6 +15,7 @@ export const CstNodeType = {
|
|
|
15
15
|
OPT: 3,
|
|
16
16
|
SEQ: 4,
|
|
17
17
|
};
|
|
18
|
+
const EMPTY_CHILDREN = Object.freeze([]);
|
|
18
19
|
const compileOptions = {
|
|
19
20
|
builtins: ['js-string'],
|
|
20
21
|
};
|
|
@@ -261,6 +262,9 @@ export class CstNodeImpl {
|
|
|
261
262
|
startIdx,
|
|
262
263
|
endIdx: startIdx + this.sourceString.length,
|
|
263
264
|
};
|
|
265
|
+
if (this.matchRecordType === MatchRecordType.TERMINAL || this.count === 0) {
|
|
266
|
+
this._children = EMPTY_CHILDREN;
|
|
267
|
+
}
|
|
264
268
|
}
|
|
265
269
|
get type() {
|
|
266
270
|
switch (this._typeAndDetails & MATCH_RECORD_TYPE_MASK) {
|
|
@@ -569,22 +573,20 @@ function createMatchResult(grammar, startExpr, ctx, succeeded) {
|
|
|
569
573
|
? new SucceededMatchResult(grammar, startExpr, ctx, succeeded)
|
|
570
574
|
: new FailedMatchResult(grammar, startExpr, ctx, succeeded, grammar.getRightmostFailurePosition());
|
|
571
575
|
}
|
|
572
|
-
class SucceededMatchResult extends MatchResult {
|
|
576
|
+
export class SucceededMatchResult extends MatchResult {
|
|
573
577
|
_cst;
|
|
574
578
|
constructor(grammar, startExpr, ctx, succeeded) {
|
|
575
579
|
super(grammar, startExpr, ctx, succeeded);
|
|
576
580
|
this._cst = grammar.getCstRoot();
|
|
577
581
|
}
|
|
578
582
|
}
|
|
579
|
-
class FailedMatchResult extends MatchResult {
|
|
583
|
+
export class FailedMatchResult extends MatchResult {
|
|
580
584
|
constructor(grammar, startExpr, ctx, succeeded, rightmostFailurePosition, optRecordedFailures) {
|
|
581
585
|
super(grammar, startExpr, ctx, succeeded);
|
|
582
586
|
this._rightmostFailurePosition = rightmostFailurePosition;
|
|
583
587
|
this._rightmostFailures = optRecordedFailures;
|
|
584
588
|
// TODO: Define these as lazy properties, like in the JS implementation.
|
|
585
|
-
|
|
586
|
-
this.shortMessage = this.message = `Match failed at pos ${rightmostFailurePosition}`;
|
|
587
|
-
}
|
|
589
|
+
this.shortMessage = this.message = `Match failed at pos ${rightmostFailurePosition}`;
|
|
588
590
|
}
|
|
589
591
|
_rightmostFailurePosition;
|
|
590
592
|
_rightmostFailures;
|