clarity-pattern-parser 11.2.0 → 11.2.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.
@@ -37,6 +37,8 @@ export declare class Grammar {
37
37
  private _buildSequence;
38
38
  private _saveRepeat;
39
39
  private _buildRepeat;
40
+ private _saveTakeUntil;
41
+ private _buildTakeUntil;
40
42
  private _saveConfigurableAnonymous;
41
43
  private _buildComplexAnonymousPattern;
42
44
  private _resolveImports;
@@ -0,0 +1,2 @@
1
+ import { Sequence } from "../../patterns/Sequence";
2
+ export declare const takeUntilLiteral: Sequence;
@@ -556,7 +556,7 @@
556
556
  return !result.cursor.hasError;
557
557
  }
558
558
 
559
- let idIndex$9 = 0;
559
+ let idIndex$a = 0;
560
560
  class Literal {
561
561
  get id() {
562
562
  return this._id;
@@ -586,7 +586,7 @@
586
586
  if (value.length === 0) {
587
587
  throw new Error("Value Cannot be empty.");
588
588
  }
589
- this._id = `literal-${idIndex$9++}`;
589
+ this._id = `literal-${idIndex$a++}`;
590
590
  this._type = "literal";
591
591
  this._name = name;
592
592
  this._token = value;
@@ -677,7 +677,7 @@
677
677
  }
678
678
  }
679
679
 
680
- let idIndex$8 = 0;
680
+ let idIndex$9 = 0;
681
681
  class Regex {
682
682
  get id() {
683
683
  return this._id;
@@ -709,7 +709,7 @@
709
709
  this._firstIndex = 0;
710
710
  this._substring = "";
711
711
  this._tokens = [];
712
- this._id = `regex-${idIndex$8++}`;
712
+ this._id = `regex-${idIndex$9++}`;
713
713
  this._type = "regex";
714
714
  this._name = name;
715
715
  this._parent = null;
@@ -829,7 +829,7 @@
829
829
  }
830
830
  }
831
831
 
832
- let idIndex$7 = 0;
832
+ let idIndex$8 = 0;
833
833
  class Reference {
834
834
  get id() {
835
835
  return this._id;
@@ -853,7 +853,7 @@
853
853
  return this._firstIndex;
854
854
  }
855
855
  constructor(name, referencePatternName) {
856
- this._id = `reference-${idIndex$7++}`;
856
+ this._id = `reference-${idIndex$8++}`;
857
857
  this._type = "reference";
858
858
  this._name = name;
859
859
  this._referencePatternName = referencePatternName || name;
@@ -1030,7 +1030,7 @@
1030
1030
  return false;
1031
1031
  }
1032
1032
 
1033
- let idIndex$6 = 0;
1033
+ let idIndex$7 = 0;
1034
1034
  class Options {
1035
1035
  get id() {
1036
1036
  return this._id;
@@ -1059,7 +1059,7 @@
1059
1059
  }
1060
1060
  const children = clonePatterns(options);
1061
1061
  this._assignChildrenToParent(children);
1062
- this._id = `options-${idIndex$6++}`;
1062
+ this._id = `options-${idIndex$7++}`;
1063
1063
  this._type = "options";
1064
1064
  this._name = name;
1065
1065
  this._parent = null;
@@ -1164,7 +1164,7 @@
1164
1164
  }
1165
1165
  }
1166
1166
 
1167
- let idIndex$5 = 0;
1167
+ let idIndex$6 = 0;
1168
1168
  class FiniteRepeat {
1169
1169
  get id() {
1170
1170
  return this._id;
@@ -1194,7 +1194,7 @@
1194
1194
  return this._firstIndex;
1195
1195
  }
1196
1196
  constructor(name, pattern, options = {}) {
1197
- this._id = `finite-repeat-${idIndex$5++}`;
1197
+ this._id = `finite-repeat-${idIndex$6++}`;
1198
1198
  this._type = "finite-repeat";
1199
1199
  this._name = name;
1200
1200
  this._parent = null;
@@ -1336,7 +1336,7 @@
1336
1336
  }
1337
1337
  }
1338
1338
 
1339
- let idIndex$4 = 0;
1339
+ let idIndex$5 = 0;
1340
1340
  class InfiniteRepeat {
1341
1341
  get id() {
1342
1342
  return this._id;
@@ -1373,7 +1373,7 @@
1373
1373
  children = [pattern.clone()];
1374
1374
  }
1375
1375
  this._assignChildrenToParent(children);
1376
- this._id = `infinite-repeat-${idIndex$4++}`;
1376
+ this._id = `infinite-repeat-${idIndex$5++}`;
1377
1377
  this._type = "infinite-repeat";
1378
1378
  this._name = name;
1379
1379
  this._min = min;
@@ -1591,7 +1591,7 @@
1591
1591
  }
1592
1592
  }
1593
1593
 
1594
- let idIndex$3 = 0;
1594
+ let idIndex$4 = 0;
1595
1595
  class Repeat {
1596
1596
  get id() {
1597
1597
  return this._id;
@@ -1627,7 +1627,7 @@
1627
1627
  return this._options;
1628
1628
  }
1629
1629
  constructor(name, pattern, options = {}) {
1630
- this._id = `repeat-${idIndex$3++}`;
1630
+ this._id = `repeat-${idIndex$4++}`;
1631
1631
  this._pattern = pattern;
1632
1632
  this._parent = null;
1633
1633
  this._options = Object.assign(Object.assign({}, options), { min: options.min == null ? 1 : options.min, max: options.max == null ? Infinity : options.max });
@@ -1706,7 +1706,7 @@
1706
1706
  return filteredNodes;
1707
1707
  }
1708
1708
 
1709
- let idIndex$2 = 0;
1709
+ let idIndex$3 = 0;
1710
1710
  class Sequence {
1711
1711
  get id() {
1712
1712
  return this._id;
@@ -1735,7 +1735,7 @@
1735
1735
  }
1736
1736
  const children = clonePatterns(sequence);
1737
1737
  this._assignChildrenToParent(children);
1738
- this._id = `sequence-${idIndex$2++}`;
1738
+ this._id = `sequence-${idIndex$3++}`;
1739
1739
  this._type = "sequence";
1740
1740
  this._name = name;
1741
1741
  this._parent = null;
@@ -1971,12 +1971,13 @@
1971
1971
  new Reference("repeat-literal"),
1972
1972
  ]);
1973
1973
  const anonymousWrappedLiterals = new Options("anonymous-wrapped-literals", [
1974
+ new Reference("take-until-literal"),
1974
1975
  new Reference("options-literal"),
1975
1976
  new Reference("sequence-literal"),
1976
1977
  new Reference("complex-anonymous-pattern")
1977
1978
  ]);
1978
1979
 
1979
- let idIndex$1 = 0;
1980
+ let idIndex$2 = 0;
1980
1981
  class Optional {
1981
1982
  get id() {
1982
1983
  return this._id;
@@ -2000,7 +2001,7 @@
2000
2001
  return this._children[0].startedOnIndex;
2001
2002
  }
2002
2003
  constructor(name, pattern) {
2003
- this._id = `optional-${idIndex$1++}`;
2004
+ this._id = `optional-${idIndex$2++}`;
2004
2005
  this._type = "optional";
2005
2006
  this._name = name;
2006
2007
  this._parent = null;
@@ -2072,12 +2073,12 @@
2072
2073
 
2073
2074
  const inlinePatternOpenParen = new Literal("anonymous-pattern-open-paren", "(");
2074
2075
  const inlinePatternCloseParen = new Literal("anonymous-pattern-close-paren", ")");
2075
- const optionalLineSpaces$3 = new Optional("optional-line-spaces", lineSpaces$1);
2076
+ const optionalLineSpaces$4 = new Optional("optional-line-spaces", lineSpaces$1);
2076
2077
  const complexAnonymousPattern = new Sequence("complex-anonymous-pattern", [
2077
2078
  inlinePatternOpenParen,
2078
- optionalLineSpaces$3,
2079
+ optionalLineSpaces$4,
2079
2080
  anonymousWrappedLiterals,
2080
- optionalLineSpaces$3,
2081
+ optionalLineSpaces$4,
2081
2082
  inlinePatternCloseParen,
2082
2083
  ]);
2083
2084
  const anonymousPattern = new Options("anonymous-pattern", [
@@ -2164,6 +2165,20 @@
2164
2165
  const divider = new Options("options-divider", [defaultDivider, greedyDivider]);
2165
2166
  const optionsLiteral = new Repeat("options-literal", patterns$1, { divider, min: 2, trimDivider: true });
2166
2167
 
2168
+ const anyChar = new Literal("any-char", "?");
2169
+ const upTo = new Literal("up-to", "->");
2170
+ const wall = new Literal("wall", "|");
2171
+ const optionalLineSpaces$3 = new Optional("optional-line-spaces", lineSpaces$1);
2172
+ const takeUntilLiteral = new Sequence("take-until-literal", [
2173
+ anyChar,
2174
+ optionalLineSpaces$3,
2175
+ upTo,
2176
+ optionalLineSpaces$3,
2177
+ wall,
2178
+ optionalLineSpaces$3,
2179
+ new Reference("pattern")
2180
+ ]);
2181
+
2167
2182
  const aliasLiteral = name$1.clone("alias-literal");
2168
2183
  aliasLiteral.setTokens(["[ALIAS_LITERAL]"]);
2169
2184
  const optionalIsOptional = new Optional("optional-flag", new Literal("is-optional", "?"));
@@ -2172,6 +2187,7 @@
2172
2187
  literal$1,
2173
2188
  regexLiteral,
2174
2189
  repeatLiteral,
2190
+ takeUntilLiteral,
2175
2191
  aliasLiteral,
2176
2192
  optionsLiteral,
2177
2193
  sequenceLiteral,
@@ -2365,7 +2381,7 @@
2365
2381
  optionalSpaces
2366
2382
  ]);
2367
2383
 
2368
- let idIndex = 0;
2384
+ let idIndex$1 = 0;
2369
2385
  class Not {
2370
2386
  get id() {
2371
2387
  return this._id;
@@ -2389,7 +2405,7 @@
2389
2405
  return this.children[0].startedOnIndex;
2390
2406
  }
2391
2407
  constructor(name, pattern) {
2392
- this._id = `not-${idIndex++}`;
2408
+ this._id = `not-${idIndex$1++}`;
2393
2409
  this._type = "not";
2394
2410
  this._name = name;
2395
2411
  this._parent = null;
@@ -3158,6 +3174,126 @@
3158
3174
  }
3159
3175
  }
3160
3176
 
3177
+ let idIndex = 0;
3178
+ class TakeUntil {
3179
+ get id() {
3180
+ return this._id;
3181
+ }
3182
+ get type() {
3183
+ return this._type;
3184
+ }
3185
+ get name() {
3186
+ return this._name;
3187
+ }
3188
+ get children() {
3189
+ return this._children;
3190
+ }
3191
+ get parent() {
3192
+ return this._parent;
3193
+ }
3194
+ set parent(pattern) {
3195
+ this._parent = pattern;
3196
+ }
3197
+ get startedOnIndex() {
3198
+ return this._startedOnIndex;
3199
+ }
3200
+ constructor(name, terminatingPattern) {
3201
+ this._id = String(idIndex++);
3202
+ this._type = "take-until";
3203
+ this._name = name;
3204
+ this._parent = null;
3205
+ this._terminatingPattern = terminatingPattern;
3206
+ this._children = [this._terminatingPattern];
3207
+ this._tokens = [];
3208
+ this._startedOnIndex = 0;
3209
+ }
3210
+ parse(cursor) {
3211
+ let cursorIndex = cursor.index;
3212
+ let foundMatch = false;
3213
+ this._startedOnIndex = cursor.index;
3214
+ let terminatingResult = this._terminatingPattern.parse(cursor);
3215
+ if (terminatingResult == null) {
3216
+ foundMatch = true;
3217
+ cursor.moveTo(cursorIndex);
3218
+ cursorIndex += 1;
3219
+ cursor.hasNext() && cursor.next();
3220
+ cursor.resolveError();
3221
+ }
3222
+ while (true) {
3223
+ terminatingResult = this._terminatingPattern.parse(cursor);
3224
+ if (terminatingResult == null) {
3225
+ cursor.moveTo(cursorIndex);
3226
+ cursorIndex += 1;
3227
+ if (cursor.hasNext()) {
3228
+ cursor.next();
3229
+ }
3230
+ else {
3231
+ break;
3232
+ }
3233
+ cursor.resolveError();
3234
+ }
3235
+ else {
3236
+ break;
3237
+ }
3238
+ }
3239
+ if (foundMatch) {
3240
+ cursor.moveTo(cursorIndex - 1);
3241
+ const value = cursor.getChars(this.startedOnIndex, cursorIndex - 1);
3242
+ return Node.createValueNode(this._type, this._name, value);
3243
+ }
3244
+ else {
3245
+ cursor.resolveError();
3246
+ cursor.moveTo(this.startedOnIndex);
3247
+ cursor.recordErrorAt(this._startedOnIndex, this._startedOnIndex, this);
3248
+ return null;
3249
+ }
3250
+ }
3251
+ exec(text, record) {
3252
+ return execPattern(this, text, record);
3253
+ }
3254
+ test(text, record) {
3255
+ return testPattern(this, text, record);
3256
+ }
3257
+ clone(name = this.name) {
3258
+ const clone = new TakeUntil(name, this._terminatingPattern);
3259
+ clone._id = this._id;
3260
+ return clone;
3261
+ }
3262
+ getTokens() {
3263
+ return this._tokens;
3264
+ }
3265
+ getTokensAfter(_childReference) {
3266
+ return [];
3267
+ }
3268
+ getNextTokens() {
3269
+ if (this.parent == null) {
3270
+ return [];
3271
+ }
3272
+ return this.parent.getTokensAfter(this);
3273
+ }
3274
+ getPatterns() {
3275
+ return [this];
3276
+ }
3277
+ getPatternsAfter(_childReference) {
3278
+ return [];
3279
+ }
3280
+ getNextPatterns() {
3281
+ if (this.parent == null) {
3282
+ return [];
3283
+ }
3284
+ return this.parent.getPatternsAfter(this);
3285
+ }
3286
+ find(_predicate) {
3287
+ return null;
3288
+ }
3289
+ setTokens(tokens) {
3290
+ this._tokens = tokens;
3291
+ }
3292
+ isEqual(pattern) {
3293
+ return pattern.type === this.type && this.children.every((c, index) => c.isEqual(pattern.children[index]));
3294
+ }
3295
+ }
3296
+
3161
3297
  let indexId = 0;
3162
3298
  class RightAssociated {
3163
3299
  get id() {
@@ -3288,6 +3424,7 @@
3288
3424
  "sequence-literal": true,
3289
3425
  "repeat-literal": true,
3290
3426
  "alias-literal": true,
3427
+ "take-until-literal": true,
3291
3428
  "configurable-anonymous-pattern": true
3292
3429
  };
3293
3430
  class ParseContext {
@@ -3398,6 +3535,10 @@
3398
3535
  this._saveAlias(n);
3399
3536
  break;
3400
3537
  }
3538
+ case "take-until-literal": {
3539
+ this._saveTakeUntil(n);
3540
+ break;
3541
+ }
3401
3542
  case "configurable-anonymous-pattern": {
3402
3543
  this._saveConfigurableAnonymous(n);
3403
3544
  break;
@@ -3517,6 +3658,9 @@
3517
3658
  case "sequence-literal": {
3518
3659
  return this._buildSequence(name, node);
3519
3660
  }
3661
+ case "take-until-literal": {
3662
+ return this._buildTakeUntil(name, node);
3663
+ }
3520
3664
  case "complex-anonymous-pattern": {
3521
3665
  return this._buildComplexAnonymousPattern(node);
3522
3666
  }
@@ -3600,6 +3744,19 @@
3600
3744
  }
3601
3745
  return isOptional ? new Optional(name, new Repeat(`inner-optional-${name}`, pattern, options)) : new Repeat(name, pattern, options);
3602
3746
  }
3747
+ _saveTakeUntil(statementNode) {
3748
+ const nameNode = statementNode.find(n => n.name === "name");
3749
+ const name = nameNode.value;
3750
+ const takeUntilNode = statementNode.find(n => n.name === "take-until-literal");
3751
+ const takeUntil = this._buildTakeUntil(name, takeUntilNode);
3752
+ this._applyDecorators(statementNode, takeUntil);
3753
+ this._parseContext.patternsByName.set(name, takeUntil);
3754
+ }
3755
+ _buildTakeUntil(name, takeUntilNode) {
3756
+ const patternNode = takeUntilNode.children[takeUntilNode.children.length - 1];
3757
+ const untilPattern = this._buildPattern(patternNode);
3758
+ return new TakeUntil(name, untilPattern);
3759
+ }
3603
3760
  _saveConfigurableAnonymous(node) {
3604
3761
  const nameNode = node.find(n => n.name === "name");
3605
3762
  const name = nameNode.value;