@ohm-js/wasm 0.7.0 → 0.7.1

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.
@@ -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;
@@ -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
- _rightmostFailurePosition;
656
- _rightmostFailures = null;
657
- _failureDescriptions = null;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ohm-js/wasm",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "Compile Ohm.js grammars to WebAsssembly",
5
5
  "main": "dist/index.js",
6
6
  "exports": {