clarity-pattern-parser 10.0.7 → 10.1.0

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.
@@ -285,6 +285,7 @@
285
285
  this._patterns = [];
286
286
  this._nodes = [];
287
287
  this._errors = [];
288
+ this._records = [];
288
289
  }
289
290
  get isRecording() {
290
291
  return this._isRecording;
@@ -307,6 +308,9 @@
307
308
  get error() {
308
309
  return this._currentError;
309
310
  }
311
+ get records() {
312
+ return this._records;
313
+ }
310
314
  get nodes() {
311
315
  return this._nodes;
312
316
  }
@@ -317,6 +321,11 @@
317
321
  if (this._isRecording) {
318
322
  this._patterns.push(pattern);
319
323
  this._nodes.push(node);
324
+ this._records.push({
325
+ pattern,
326
+ ast: node,
327
+ error: null
328
+ });
320
329
  }
321
330
  this._rootMatch.pattern = pattern;
322
331
  this._rootMatch.node = node;
@@ -356,6 +365,11 @@
356
365
  }
357
366
  if (this._isRecording) {
358
367
  this._errors.push(error);
368
+ this.records.push({
369
+ pattern,
370
+ ast: null,
371
+ error
372
+ });
359
373
  }
360
374
  }
361
375
  startRecording() {
@@ -406,6 +420,9 @@
406
420
  get errors() {
407
421
  return this._history.errors;
408
422
  }
423
+ get records() {
424
+ return this._history.records;
425
+ }
409
426
  get index() {
410
427
  return this._index;
411
428
  }
@@ -784,6 +801,7 @@
784
801
  this._name = name;
785
802
  this._parent = null;
786
803
  this._pattern = null;
804
+ this._cachedPattern = null;
787
805
  this._children = [];
788
806
  }
789
807
  test(text) {
@@ -805,7 +823,13 @@
805
823
  }
806
824
  _getPatternSafely() {
807
825
  if (this._pattern === null) {
808
- const pattern = this._findPattern();
826
+ let pattern = null;
827
+ if (this._cachedPattern == null) {
828
+ pattern = this._findPattern();
829
+ }
830
+ else {
831
+ pattern = this._cachedPattern;
832
+ }
809
833
  if (pattern === null) {
810
834
  throw new Error(`Couldn't find '${this._name}' pattern within tree.`);
811
835
  }
@@ -871,6 +895,10 @@
871
895
  clone(name = this._name) {
872
896
  const clone = new Reference(name);
873
897
  clone._id = this._id;
898
+ // Optimize future clones, by caching the pattern we already found.
899
+ if (this._pattern != null) {
900
+ clone._cachedPattern = this._pattern;
901
+ }
874
902
  return clone;
875
903
  }
876
904
  isEqual(pattern) {