clarity-pattern-parser 10.2.13 → 10.3.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.
Files changed (39) hide show
  1. package/dist/ast/Node.d.ts +1 -0
  2. package/dist/index.browser.js +100 -9
  3. package/dist/index.browser.js.map +1 -1
  4. package/dist/index.esm.js +100 -9
  5. package/dist/index.esm.js.map +1 -1
  6. package/dist/index.js +100 -9
  7. package/dist/index.js.map +1 -1
  8. package/dist/patterns/Context.d.ts +1 -0
  9. package/dist/patterns/ExpressionPattern.d.ts +3 -0
  10. package/dist/patterns/FiniteRepeat.d.ts +1 -0
  11. package/dist/patterns/InfiniteRepeat.d.ts +1 -0
  12. package/dist/patterns/Literal.d.ts +1 -0
  13. package/dist/patterns/Not.d.ts +1 -0
  14. package/dist/patterns/Optional.d.ts +1 -0
  15. package/dist/patterns/Options.d.ts +1 -0
  16. package/dist/patterns/Pattern.d.ts +1 -0
  17. package/dist/patterns/Reference.d.ts +1 -0
  18. package/dist/patterns/Regex.d.ts +1 -0
  19. package/dist/patterns/Repeat.d.ts +3 -0
  20. package/dist/patterns/Sequence.d.ts +1 -0
  21. package/package.json +1 -1
  22. package/src/ast/Node.ts +6 -2
  23. package/src/grammar/Grammar.test.ts +53 -3
  24. package/src/grammar/Grammar.ts +20 -0
  25. package/src/grammar/patterns/statement.ts +7 -2
  26. package/src/patterns/Context.ts +3 -0
  27. package/src/patterns/ExpressionPattern.ts +35 -0
  28. package/src/patterns/FiniteRepeat.ts +10 -1
  29. package/src/patterns/InfiniteRepeat.ts +7 -0
  30. package/src/patterns/Literal.ts +3 -0
  31. package/src/patterns/Not.ts +2 -0
  32. package/src/patterns/Optional.ts +10 -3
  33. package/src/patterns/Options.ts +11 -3
  34. package/src/patterns/Pattern.ts +1 -0
  35. package/src/patterns/Reference.ts +3 -0
  36. package/src/patterns/Regex.ts +5 -2
  37. package/src/patterns/Repeat.ts +12 -0
  38. package/src/patterns/RightAssociatedPattern.ts +2 -0
  39. package/src/patterns/Sequence.ts +7 -0
@@ -27,6 +27,16 @@ export class Repeat implements Pattern {
27
27
  private _pattern: Pattern;
28
28
  private _options: InternalRepeatOptions;
29
29
  private _children: Pattern[];
30
+ private _shouldCompactAst: boolean;
31
+
32
+ get shouldCompactAst() {
33
+ return this._shouldCompactAst;
34
+ }
35
+
36
+ set shouldCompactAst(value: boolean) {
37
+ this._shouldCompactAst = value;
38
+ this._repeatPattern.shouldCompactAst = value;
39
+ }
30
40
 
31
41
  get id() {
32
42
  return this._id;
@@ -64,6 +74,7 @@ export class Repeat implements Pattern {
64
74
  this._id = `repeat-${idIndex++}`;
65
75
  this._pattern = pattern;
66
76
  this._parent = null;
77
+ this._shouldCompactAst = false;
67
78
  this._options = {
68
79
  ...options,
69
80
  min: options.min == null ? 1 : options.min,
@@ -97,6 +108,7 @@ export class Repeat implements Pattern {
97
108
  const clone = new Repeat(name, this._pattern, { ...this._options, min });
98
109
 
99
110
  clone._id = this._id;
111
+ clone.shouldCompactAst = this.shouldCompactAst;
100
112
  return clone;
101
113
  }
102
114
 
@@ -12,6 +12,8 @@ export class RightAssociatedPattern implements Pattern {
12
12
  private _parent: Pattern | null;
13
13
  private _children: Pattern[];
14
14
 
15
+ shouldCompactAst = false;
16
+
15
17
  get id(): string {
16
18
  return this._id;
17
19
  }
@@ -19,6 +19,8 @@ export class Sequence implements Pattern {
19
19
  private _nodes: (Node | null)[];
20
20
  private _firstIndex: number;
21
21
 
22
+ shouldCompactAst = false;
23
+
22
24
  get id(): string {
23
25
  return this._id;
24
26
  }
@@ -100,6 +102,10 @@ export class Sequence implements Pattern {
100
102
 
101
103
  if (node !== null) {
102
104
  cursor.recordMatch(this, node);
105
+
106
+ if (this.shouldCompactAst) {
107
+ node.compact();
108
+ }
103
109
  }
104
110
 
105
111
  return node;
@@ -323,6 +329,7 @@ export class Sequence implements Pattern {
323
329
  clone(name = this._name): Pattern {
324
330
  const clone = new Sequence(name, this._children);
325
331
  clone._id = this._id;
332
+ clone.shouldCompactAst = this.shouldCompactAst;
326
333
 
327
334
  return clone;
328
335
  }