clarity-pattern-parser 10.2.13 → 10.2.14
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 +51 -7
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +51 -7
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +51 -7
- package/dist/index.js.map +1 -1
- package/dist/patterns/Context.d.ts +1 -0
- package/dist/patterns/ExpressionPattern.d.ts +1 -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 +1 -0
- package/dist/patterns/Sequence.d.ts +1 -0
- package/package.json +1 -1
- package/src/ast/Node.ts +5 -0
- package/src/patterns/Context.ts +3 -0
- package/src/patterns/ExpressionPattern.ts +3 -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 +4 -0
- package/src/patterns/RightAssociatedPattern.ts +2 -0
- package/src/patterns/Sequence.ts +7 -0
package/dist/patterns/Not.d.ts
CHANGED
package/dist/patterns/Regex.d.ts
CHANGED
package/package.json
CHANGED
package/src/ast/Node.ts
CHANGED
package/src/patterns/Context.ts
CHANGED
|
@@ -14,6 +14,8 @@ export class Context implements Pattern {
|
|
|
14
14
|
private _pattern: Pattern;
|
|
15
15
|
private _patterns: Record<string, Pattern>;
|
|
16
16
|
|
|
17
|
+
shouldCompactAst = false;
|
|
18
|
+
|
|
17
19
|
get id(): string {
|
|
18
20
|
return this._id;
|
|
19
21
|
}
|
|
@@ -76,6 +78,7 @@ export class Context implements Pattern {
|
|
|
76
78
|
clone(name = this._name): Pattern {
|
|
77
79
|
const clone = new Context(name, this._pattern, Object.values(this._patterns));
|
|
78
80
|
clone._id = this._id;
|
|
81
|
+
clone.shouldCompactAst = this.shouldCompactAst;
|
|
79
82
|
return clone;
|
|
80
83
|
}
|
|
81
84
|
|
|
@@ -35,6 +35,8 @@ export class ExpressionPattern implements Pattern {
|
|
|
35
35
|
private _precedenceMap: Record<string, number>;
|
|
36
36
|
private _binaryNames: string[];
|
|
37
37
|
|
|
38
|
+
shouldCompactAst = false;
|
|
39
|
+
|
|
38
40
|
get id(): string {
|
|
39
41
|
return this._id;
|
|
40
42
|
}
|
|
@@ -514,6 +516,7 @@ export class ExpressionPattern implements Pattern {
|
|
|
514
516
|
clone(name = this._name): Pattern {
|
|
515
517
|
const clone = new ExpressionPattern(name, this._originalPatterns);
|
|
516
518
|
clone._id = this._id;
|
|
519
|
+
clone.shouldCompactAst = this.shouldCompactAst;
|
|
517
520
|
return clone;
|
|
518
521
|
}
|
|
519
522
|
|
|
@@ -24,6 +24,8 @@ export class FiniteRepeat implements Pattern {
|
|
|
24
24
|
private _max: number;
|
|
25
25
|
private _trimDivider: boolean;
|
|
26
26
|
|
|
27
|
+
shouldCompactAst = false;
|
|
28
|
+
|
|
27
29
|
get id() {
|
|
28
30
|
return this._id;
|
|
29
31
|
}
|
|
@@ -140,7 +142,13 @@ export class FiniteRepeat implements Pattern {
|
|
|
140
142
|
cursor.resolveError();
|
|
141
143
|
cursor.moveTo(lastIndex);
|
|
142
144
|
|
|
143
|
-
|
|
145
|
+
const node = new Node(this._type, this.name, firstIndex, lastIndex, nodes);
|
|
146
|
+
|
|
147
|
+
if (this.shouldCompactAst) {
|
|
148
|
+
node.compact();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return node;
|
|
144
152
|
}
|
|
145
153
|
|
|
146
154
|
test(text: string): boolean {
|
|
@@ -178,6 +186,7 @@ export class FiniteRepeat implements Pattern {
|
|
|
178
186
|
);
|
|
179
187
|
|
|
180
188
|
clone._id = this._id;
|
|
189
|
+
clone.shouldCompactAst = this.shouldCompactAst;
|
|
181
190
|
|
|
182
191
|
return clone;
|
|
183
192
|
}
|
|
@@ -26,6 +26,8 @@ export class InfiniteRepeat implements Pattern {
|
|
|
26
26
|
private _min: number;
|
|
27
27
|
private _trimDivider: boolean;
|
|
28
28
|
|
|
29
|
+
shouldCompactAst = false;
|
|
30
|
+
|
|
29
31
|
get id(): string {
|
|
30
32
|
return this._id;
|
|
31
33
|
}
|
|
@@ -118,6 +120,10 @@ export class InfiniteRepeat implements Pattern {
|
|
|
118
120
|
if (node != null) {
|
|
119
121
|
cursor.moveTo(node.lastIndex);
|
|
120
122
|
cursor.recordMatch(this, node);
|
|
123
|
+
|
|
124
|
+
if (this.shouldCompactAst) {
|
|
125
|
+
node.compact();
|
|
126
|
+
}
|
|
121
127
|
}
|
|
122
128
|
|
|
123
129
|
return node;
|
|
@@ -352,6 +358,7 @@ export class InfiniteRepeat implements Pattern {
|
|
|
352
358
|
);
|
|
353
359
|
|
|
354
360
|
clone._id = this._id;
|
|
361
|
+
clone.shouldCompactAst = this.shouldCompactAst;
|
|
355
362
|
|
|
356
363
|
return clone;
|
|
357
364
|
}
|
package/src/patterns/Literal.ts
CHANGED
|
@@ -16,6 +16,8 @@ export class Literal implements Pattern {
|
|
|
16
16
|
private _lastIndex: number;
|
|
17
17
|
private _endIndex: number;
|
|
18
18
|
|
|
19
|
+
shouldCompactAst = false;
|
|
20
|
+
|
|
19
21
|
get id(): string {
|
|
20
22
|
return this._id;
|
|
21
23
|
}
|
|
@@ -141,6 +143,7 @@ export class Literal implements Pattern {
|
|
|
141
143
|
clone(name = this._name): Pattern {
|
|
142
144
|
const clone = new Literal(name, this._token);
|
|
143
145
|
clone._id = this._id;
|
|
146
|
+
clone.shouldCompactAst = this.shouldCompactAst;
|
|
144
147
|
return clone;
|
|
145
148
|
}
|
|
146
149
|
|
package/src/patterns/Not.ts
CHANGED
package/src/patterns/Optional.ts
CHANGED
|
@@ -12,6 +12,8 @@ export class Optional 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
|
}
|
|
@@ -74,15 +76,20 @@ export class Optional implements Pattern {
|
|
|
74
76
|
|
|
75
77
|
return null;
|
|
76
78
|
} else {
|
|
79
|
+
if (node != null && this.shouldCompactAst) {
|
|
80
|
+
node.compact();
|
|
81
|
+
}
|
|
82
|
+
|
|
77
83
|
return node;
|
|
78
84
|
}
|
|
79
85
|
|
|
80
86
|
}
|
|
81
87
|
|
|
82
88
|
clone(name = this._name): Pattern {
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
89
|
+
const clone = new Optional(name, this._children[0]);
|
|
90
|
+
clone._id = this._id;
|
|
91
|
+
clone.shouldCompactAst = this.shouldCompactAst;
|
|
92
|
+
return clone;
|
|
86
93
|
}
|
|
87
94
|
|
|
88
95
|
getTokens(): string[] {
|
package/src/patterns/Options.ts
CHANGED
|
@@ -23,6 +23,8 @@ export class Options implements Pattern {
|
|
|
23
23
|
private _isGreedy: boolean;
|
|
24
24
|
private _firstIndex: number;
|
|
25
25
|
|
|
26
|
+
shouldCompactAst = false;
|
|
27
|
+
|
|
26
28
|
get id(): string {
|
|
27
29
|
return this._id;
|
|
28
30
|
}
|
|
@@ -102,6 +104,11 @@ export class Options implements Pattern {
|
|
|
102
104
|
if (node != null) {
|
|
103
105
|
cursor.moveTo(node.lastIndex);
|
|
104
106
|
cursor.resolveError();
|
|
107
|
+
|
|
108
|
+
if (this.shouldCompactAst) {
|
|
109
|
+
node.compact();
|
|
110
|
+
}
|
|
111
|
+
|
|
105
112
|
return node;
|
|
106
113
|
}
|
|
107
114
|
|
|
@@ -202,9 +209,10 @@ export class Options implements Pattern {
|
|
|
202
209
|
}
|
|
203
210
|
|
|
204
211
|
clone(name = this._name): Pattern {
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
212
|
+
const clone = new Options(name, this._children, this._isGreedy);
|
|
213
|
+
clone._id = this._id;
|
|
214
|
+
clone.shouldCompactAst = this.shouldCompactAst;
|
|
215
|
+
return clone;
|
|
208
216
|
}
|
|
209
217
|
|
|
210
218
|
isEqual(pattern: Options): boolean {
|
package/src/patterns/Pattern.ts
CHANGED
|
@@ -16,6 +16,8 @@ export class Reference implements Pattern {
|
|
|
16
16
|
private _pattern: Pattern | null;
|
|
17
17
|
private _children: Pattern[];
|
|
18
18
|
|
|
19
|
+
shouldCompactAst = false;
|
|
20
|
+
|
|
19
21
|
get id(): string {
|
|
20
22
|
return this._id;
|
|
21
23
|
}
|
|
@@ -196,6 +198,7 @@ export class Reference implements Pattern {
|
|
|
196
198
|
clone(name = this._name): Pattern {
|
|
197
199
|
const clone = new Reference(name);
|
|
198
200
|
clone._id = this._id;
|
|
201
|
+
clone.shouldCompactAst = this.shouldCompactAst;
|
|
199
202
|
|
|
200
203
|
// Optimize future clones, by caching the pattern we already found.
|
|
201
204
|
if (this._pattern != null) {
|
package/src/patterns/Regex.ts
CHANGED
|
@@ -18,6 +18,8 @@ export class Regex implements Pattern {
|
|
|
18
18
|
private _substring = "";
|
|
19
19
|
private _tokens: string[] = [];
|
|
20
20
|
|
|
21
|
+
shouldCompactAst = false;
|
|
22
|
+
|
|
21
23
|
get id(): string {
|
|
22
24
|
return this._id;
|
|
23
25
|
}
|
|
@@ -30,7 +32,7 @@ export class Regex implements Pattern {
|
|
|
30
32
|
return this._name;
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
get regex(): string{
|
|
35
|
+
get regex(): string {
|
|
34
36
|
return this._originalRegexString;
|
|
35
37
|
}
|
|
36
38
|
|
|
@@ -145,8 +147,9 @@ export class Regex implements Pattern {
|
|
|
145
147
|
clone(name = this._name) {
|
|
146
148
|
const clone = new Regex(name, this._originalRegexString);
|
|
147
149
|
clone._tokens = this._tokens.slice();
|
|
148
|
-
|
|
149
150
|
clone._id = this._id;
|
|
151
|
+
clone.shouldCompactAst = this.shouldCompactAst;
|
|
152
|
+
|
|
150
153
|
return clone;
|
|
151
154
|
}
|
|
152
155
|
|
package/src/patterns/Repeat.ts
CHANGED
|
@@ -28,6 +28,8 @@ export class Repeat implements Pattern {
|
|
|
28
28
|
private _options: InternalRepeatOptions;
|
|
29
29
|
private _children: Pattern[];
|
|
30
30
|
|
|
31
|
+
shouldCompactAst = false;
|
|
32
|
+
|
|
31
33
|
get id() {
|
|
32
34
|
return this._id;
|
|
33
35
|
}
|
|
@@ -76,6 +78,7 @@ export class Repeat implements Pattern {
|
|
|
76
78
|
this._repeatPattern = new InfiniteRepeat(name, pattern, this._options);
|
|
77
79
|
}
|
|
78
80
|
|
|
81
|
+
this._repeatPattern.shouldCompactAst = this.shouldCompactAst;
|
|
79
82
|
this._children = [this._repeatPattern];
|
|
80
83
|
this._repeatPattern.parent = this;
|
|
81
84
|
}
|
|
@@ -97,6 +100,7 @@ export class Repeat implements Pattern {
|
|
|
97
100
|
const clone = new Repeat(name, this._pattern, { ...this._options, min });
|
|
98
101
|
|
|
99
102
|
clone._id = this._id;
|
|
103
|
+
clone.shouldCompactAst = this.shouldCompactAst;
|
|
100
104
|
return clone;
|
|
101
105
|
}
|
|
102
106
|
|
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
|
}
|