ohm-js 16.3.1 → 16.3.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/ohm.esm.js CHANGED
@@ -293,20 +293,19 @@ exports.unexpectedObjToString = function(obj) {
293
293
 
294
294
  const common$k = common$l;
295
295
 
296
- // Ensures that the deprecation warning for `primitiveValue` only appears once.
297
- let didWarnForPrimitiveValue = false;
298
-
299
296
  // --------------------------------------------------------------------
300
297
  // Private stuff
301
298
  // --------------------------------------------------------------------
302
299
 
303
300
  class Node {
304
- constructor(grammar, ctorName, matchLength) {
305
- this.grammar = grammar;
306
- this.ctorName = ctorName;
301
+ constructor(matchLength) {
307
302
  this.matchLength = matchLength;
308
303
  }
309
304
 
305
+ get ctorName() {
306
+ throw new Error('subclass responsibility');
307
+ }
308
+
310
309
  numChildren() {
311
310
  return this.children ? this.children.length : 0;
312
311
  }
@@ -400,52 +399,38 @@ class Node {
400
399
  isOptional() {
401
400
  return false;
402
401
  }
403
-
404
- toJSON() {
405
- return {[this.ctorName]: this.children};
406
- }
407
402
  }
408
403
 
409
404
  // Terminals
410
405
 
411
406
  class TerminalNode$2 extends Node {
412
- constructor(grammar, value) {
413
- const matchLength = value ? value.length : 0;
414
- super(grammar, '_terminal', matchLength);
415
- this._value = value;
407
+ get ctorName() {
408
+ return '_terminal';
416
409
  }
417
410
 
418
411
  isTerminal() {
419
412
  return true;
420
413
  }
421
414
 
422
- toJSON() {
423
- return {[this.ctorName]: this._value};
424
- }
425
-
426
415
  get primitiveValue() {
427
- if (!didWarnForPrimitiveValue) {
428
- // eslint-disable-next-line no-console
429
- console.warn(
430
- 'Warning: primitiveValue is deprecated and will be removed in a future version of Ohm. ' +
431
- 'Use sourceString instead.'
432
- );
433
- didWarnForPrimitiveValue = true;
434
- }
435
-
436
- return this._value;
416
+ throw new Error('The `primitiveValue` property was removed in Ohm v17.');
437
417
  }
438
418
  }
439
419
 
440
420
  // Nonterminals
441
421
 
442
422
  class NonterminalNode$1 extends Node {
443
- constructor(grammar, ruleName, children, childOffsets, matchLength) {
444
- super(grammar, ruleName, matchLength);
423
+ constructor(ruleName, children, childOffsets, matchLength) {
424
+ super(matchLength);
425
+ this.ruleName = ruleName;
445
426
  this.children = children;
446
427
  this.childOffsets = childOffsets;
447
428
  }
448
429
 
430
+ get ctorName() {
431
+ return this.ruleName;
432
+ }
433
+
449
434
  isNonterminal() {
450
435
  return true;
451
436
  }
@@ -462,13 +447,17 @@ class NonterminalNode$1 extends Node {
462
447
  // Iterations
463
448
 
464
449
  class IterationNode$2 extends Node {
465
- constructor(grammar, children, childOffsets, matchLength, isOptional) {
466
- super(grammar, '_iter', matchLength);
450
+ constructor(children, childOffsets, matchLength, isOptional) {
451
+ super(matchLength);
467
452
  this.children = children;
468
453
  this.childOffsets = childOffsets;
469
454
  this.optional = isOptional;
470
455
  }
471
456
 
457
+ get ctorName() {
458
+ return '_iter';
459
+ }
460
+
472
461
  isIteration() {
473
462
  return true;
474
463
  }
@@ -2023,7 +2012,7 @@ pexprs$g.any.eval = function(state) {
2023
2012
  const origPos = inputStream.pos;
2024
2013
  const ch = inputStream.next();
2025
2014
  if (ch) {
2026
- state.pushBinding(new TerminalNode$1(state.grammar, ch), origPos);
2015
+ state.pushBinding(new TerminalNode$1(ch.length), origPos);
2027
2016
  return true;
2028
2017
  } else {
2029
2018
  state.processFailure(origPos, this);
@@ -2035,7 +2024,7 @@ pexprs$g.end.eval = function(state) {
2035
2024
  const {inputStream} = state;
2036
2025
  const origPos = inputStream.pos;
2037
2026
  if (inputStream.atEnd()) {
2038
- state.pushBinding(new TerminalNode$1(state.grammar, undefined), origPos);
2027
+ state.pushBinding(new TerminalNode$1(0), origPos);
2039
2028
  return true;
2040
2029
  } else {
2041
2030
  state.processFailure(origPos, this);
@@ -2050,7 +2039,7 @@ pexprs$g.Terminal.prototype.eval = function(state) {
2050
2039
  state.processFailure(origPos, this);
2051
2040
  return false;
2052
2041
  } else {
2053
- state.pushBinding(new TerminalNode$1(state.grammar, this.obj), origPos);
2042
+ state.pushBinding(new TerminalNode$1(this.obj.length), origPos);
2054
2043
  return true;
2055
2044
  }
2056
2045
  };
@@ -2066,7 +2055,7 @@ pexprs$g.Range.prototype.eval = function(state) {
2066
2055
  // Always compare by code point value to get the correct result in all scenarios.
2067
2056
  // Note that for strings of length 1, codePointAt(0) and charPointAt(0) are equivalent.
2068
2057
  if (cp !== undefined && this.from.codePointAt(0) <= cp && cp <= this.to.codePointAt(0)) {
2069
- state.pushBinding(new TerminalNode$1(state.grammar, String.fromCodePoint(cp)), origPos);
2058
+ state.pushBinding(new TerminalNode$1(String.fromCodePoint(cp).length), origPos);
2070
2059
  return true;
2071
2060
  } else {
2072
2061
  state.processFailure(origPos, this);
@@ -2151,7 +2140,7 @@ pexprs$g.Iter.prototype.eval = function(state) {
2151
2140
  const isOptional = this instanceof pexprs$g.Opt;
2152
2141
  for (idx = 0; idx < cols.length; idx++) {
2153
2142
  state._bindings.push(
2154
- new IterationNode$1(state.grammar, cols[idx], colOffsets[idx], matchLength, isOptional)
2143
+ new IterationNode$1(cols[idx], colOffsets[idx], matchLength, isOptional)
2155
2144
  );
2156
2145
  state._bindingOffsets.push(offset);
2157
2146
  }
@@ -2326,13 +2315,8 @@ pexprs$g.Apply.prototype.evalOnce = function(expr, state) {
2326
2315
  const arity = expr.getArity();
2327
2316
  const bindings = state._bindings.splice(state._bindings.length - arity, arity);
2328
2317
  const offsets = state._bindingOffsets.splice(state._bindingOffsets.length - arity, arity);
2329
- return new NonterminalNode(
2330
- state.grammar,
2331
- this.ruleName,
2332
- bindings,
2333
- offsets,
2334
- inputStream.pos - origPos
2335
- );
2318
+ const matchLength = inputStream.pos - origPos;
2319
+ return new NonterminalNode(this.ruleName, bindings, offsets, matchLength);
2336
2320
  } else {
2337
2321
  return false;
2338
2322
  }
@@ -2387,7 +2371,7 @@ pexprs$g.UnicodeChar.prototype.eval = function(state) {
2387
2371
  const origPos = inputStream.pos;
2388
2372
  const ch = inputStream.next();
2389
2373
  if (ch && this.pattern.test(ch)) {
2390
- state.pushBinding(new TerminalNode$1(state.grammar, ch), origPos);
2374
+ state.pushBinding(new TerminalNode$1(ch.length), origPos);
2391
2375
  return true;
2392
2376
  } else {
2393
2377
  state.processFailure(origPos, this);
@@ -3169,7 +3153,7 @@ class CaseInsensitiveTerminal$1 extends PExpr {
3169
3153
  state.processFailure(origPos, this);
3170
3154
  return false;
3171
3155
  } else {
3172
- state.pushBinding(new TerminalNode(state.grammar, matchStr), origPos);
3156
+ state.pushBinding(new TerminalNode(matchStr.length), origPos);
3173
3157
  return true;
3174
3158
  }
3175
3159
  }
@@ -3730,7 +3714,7 @@ MatchState$1.prototype = {
3730
3714
  // Returns the memoized trace entry for `expr` at `pos`, if one exists, `null` otherwise.
3731
3715
  getMemoizedTraceEntry(pos, expr) {
3732
3716
  const posInfo = this.memoTable[pos];
3733
- if (posInfo && expr.ruleName) {
3717
+ if (posInfo && expr instanceof pexprs$5.Apply) {
3734
3718
  const memoRec = posInfo.memo[expr.toMemoKey()];
3735
3719
  if (memoRec && memoRec.traceEntry) {
3736
3720
  const entry = memoRec.traceEntry.cloneWithExpr(expr);
@@ -3872,11 +3856,15 @@ MatchState$1.prototype = {
3872
3856
  key => this.recordedFailures[key]
3873
3857
  );
3874
3858
  }
3859
+ const cst = this._bindings[0];
3860
+ if (cst) {
3861
+ cst.grammar = this.grammar;
3862
+ }
3875
3863
  return new MatchResult$1(
3876
3864
  this.matcher,
3877
3865
  this.input,
3878
3866
  this.startExpr,
3879
- this._bindings[0],
3867
+ cst,
3880
3868
  this._bindingOffsets[0],
3881
3869
  this.rightmostFailurePosition,
3882
3870
  rightmostFailures
@@ -4059,11 +4047,6 @@ class Wrapper {
4059
4047
  return '[semantics wrapper for ' + this._node.grammar.name + ']';
4060
4048
  }
4061
4049
 
4062
- // This is used by ohm editor to display a node wrapper appropriately.
4063
- toJSON() {
4064
- return this.toString();
4065
- }
4066
-
4067
4050
  _forgetMemoizedResultFor(attributeName) {
4068
4051
  // Remove the memoized attribute from the cstNode and all its children.
4069
4052
  delete this._node[this._semantics.attributeKeys[attributeName]];
@@ -4143,7 +4126,7 @@ class Wrapper {
4143
4126
  const childWrappers = optChildWrappers || [];
4144
4127
 
4145
4128
  const childNodes = childWrappers.map(c => c._node);
4146
- const iter = new IterationNode(this._node.grammar, childNodes, [], -1, false);
4129
+ const iter = new IterationNode(childNodes, [], -1, false);
4147
4130
 
4148
4131
  const wrapper = this._semantics.wrap(iter, null, null);
4149
4132
  wrapper._childWrappers = childWrappers;
@@ -4170,18 +4153,6 @@ class Wrapper {
4170
4153
  return this._node.numChildren();
4171
4154
  }
4172
4155
 
4173
- // Returns the primitive value of this CST node, if it's a terminal node. Otherwise,
4174
- // throws an exception.
4175
- // DEPRECATED: Use `sourceString` instead.
4176
- get primitiveValue() {
4177
- if (this.isTerminal()) {
4178
- return this._node.primitiveValue;
4179
- }
4180
- throw new TypeError(
4181
- "tried to access the 'primitiveValue' attribute of a non-terminal CST node"
4182
- );
4183
- }
4184
-
4185
4156
  // Returns the contents of the input stream consumed by this CST node.
4186
4157
  get sourceString() {
4187
4158
  return this.source.contents;
@@ -5489,7 +5460,7 @@ Builder$2.prototype = {
5489
5460
  var Builder_1 = Builder$2;
5490
5461
 
5491
5462
  var name = "ohm-js";
5492
- var version$2 = "16.3.1";
5463
+ var version$2 = "16.3.2";
5493
5464
  var description = "An object-oriented language for parsing and pattern matching";
5494
5465
  var repository = "https://github.com/harc/ohm";
5495
5466
  var keywords = [