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.
- package/dist/ast/Node.d.ts +1 -0
- package/dist/index.browser.js +100 -9
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +100 -9
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +100 -9
- package/dist/index.js.map +1 -1
- package/dist/patterns/Context.d.ts +1 -0
- package/dist/patterns/ExpressionPattern.d.ts +3 -0
- package/dist/patterns/FiniteRepeat.d.ts +1 -0
- package/dist/patterns/InfiniteRepeat.d.ts +1 -0
- package/dist/patterns/Literal.d.ts +1 -0
- package/dist/patterns/Not.d.ts +1 -0
- package/dist/patterns/Optional.d.ts +1 -0
- package/dist/patterns/Options.d.ts +1 -0
- package/dist/patterns/Pattern.d.ts +1 -0
- package/dist/patterns/Reference.d.ts +1 -0
- package/dist/patterns/Regex.d.ts +1 -0
- package/dist/patterns/Repeat.d.ts +3 -0
- package/dist/patterns/Sequence.d.ts +1 -0
- package/package.json +1 -1
- package/src/ast/Node.ts +6 -2
- package/src/grammar/Grammar.test.ts +53 -3
- package/src/grammar/Grammar.ts +20 -0
- package/src/grammar/patterns/statement.ts +7 -2
- package/src/patterns/Context.ts +3 -0
- package/src/patterns/ExpressionPattern.ts +35 -0
- package/src/patterns/FiniteRepeat.ts +10 -1
- package/src/patterns/InfiniteRepeat.ts +7 -0
- package/src/patterns/Literal.ts +3 -0
- package/src/patterns/Not.ts +2 -0
- package/src/patterns/Optional.ts +10 -3
- package/src/patterns/Options.ts +11 -3
- package/src/patterns/Pattern.ts +1 -0
- package/src/patterns/Reference.ts +3 -0
- package/src/patterns/Regex.ts +5 -2
- package/src/patterns/Repeat.ts +12 -0
- package/src/patterns/RightAssociatedPattern.ts +2 -0
- package/src/patterns/Sequence.ts +7 -0
package/src/patterns/Repeat.ts
CHANGED
|
@@ -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
|
|
package/src/patterns/Sequence.ts
CHANGED
|
@@ -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
|
}
|