clarity-pattern-parser 11.3.8 → 11.3.10
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/index.browser.js +61 -34
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +61 -34
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +61 -34
- package/dist/index.js.map +1 -1
- package/dist/patterns/InfiniteRepeat.d.ts +1 -0
- package/package.json +1 -1
- package/src/intellisense/AutoComplete.test.ts +23 -0
- package/src/patterns/FiniteRepeat.ts +4 -6
- package/src/patterns/InfiniteRepeat.ts +7 -1
package/package.json
CHANGED
|
@@ -523,6 +523,29 @@ describe("AutoComplete", () => {
|
|
|
523
523
|
expect(result.options).toEqual([{ text: 'a', startIndex: 4 }]);
|
|
524
524
|
});
|
|
525
525
|
|
|
526
|
+
test("Remove options divider", () => {
|
|
527
|
+
const jediLuke = new Literal(`jedi`, 'luke');
|
|
528
|
+
const names = new Options('names', [jediLuke]);
|
|
529
|
+
const literalA = new Literal('literal-a', 'a');
|
|
530
|
+
const literalB = new Literal('literal-b', 'b');
|
|
531
|
+
|
|
532
|
+
const optionsDivider = new Options('options-divider', [literalA, literalB]);
|
|
533
|
+
|
|
534
|
+
// control to prove the pattern works without trimDivider
|
|
535
|
+
const controlPattern = new Repeat('name-list', names, { divider: optionsDivider });
|
|
536
|
+
const controlAutoComplete = new AutoComplete(controlPattern);
|
|
537
|
+
const controlResult = controlAutoComplete.suggestFor('lukea');
|
|
538
|
+
expect(controlResult.isComplete).toEqual(true);
|
|
539
|
+
|
|
540
|
+
const trimPattern = new Repeat('name-list', names, { divider: optionsDivider, trimDivider: true });
|
|
541
|
+
const trimAutoComplete = new AutoComplete(trimPattern);
|
|
542
|
+
|
|
543
|
+
const trimResult = trimAutoComplete.suggestFor('lukea');
|
|
544
|
+
expect(trimResult.isComplete).toEqual(false);
|
|
545
|
+
})
|
|
546
|
+
|
|
547
|
+
|
|
548
|
+
|
|
526
549
|
test("Expect Divider", () => {
|
|
527
550
|
const repeat = new Repeat("repeat", new Literal("a", "a"), { divider: new Literal("pipe", "|") });
|
|
528
551
|
const autoComplete = new AutoComplete(repeat);
|
|
@@ -123,12 +123,10 @@ export class FiniteRepeat implements Pattern {
|
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
cursor.moveTo(node.firstIndex);
|
|
131
|
-
}
|
|
126
|
+
const endedOnDivider = this._hasDivider && nodes.length % modulo === 0;
|
|
127
|
+
if (this._trimDivider && endedOnDivider) {
|
|
128
|
+
const node = nodes.pop() as Node;
|
|
129
|
+
cursor.moveTo(node.firstIndex);
|
|
132
130
|
}
|
|
133
131
|
|
|
134
132
|
if (matchCount < this._min) {
|
|
@@ -26,6 +26,7 @@ export class InfiniteRepeat implements Pattern {
|
|
|
26
26
|
private _firstIndex: number;
|
|
27
27
|
private _min: number;
|
|
28
28
|
private _trimDivider: boolean;
|
|
29
|
+
private _patterns: Pattern[];
|
|
29
30
|
|
|
30
31
|
get id(): string {
|
|
31
32
|
return this._id;
|
|
@@ -83,6 +84,7 @@ export class InfiniteRepeat implements Pattern {
|
|
|
83
84
|
this._firstIndex = 0;
|
|
84
85
|
this._nodes = [];
|
|
85
86
|
this._trimDivider = options.trimDivider == null ? false : options.trimDivider;
|
|
87
|
+
this._patterns = [];
|
|
86
88
|
}
|
|
87
89
|
|
|
88
90
|
private _assignChildrenToParent(children: Pattern[]): void {
|
|
@@ -102,6 +104,7 @@ export class InfiniteRepeat implements Pattern {
|
|
|
102
104
|
parse(cursor: Cursor): Node | null {
|
|
103
105
|
this._firstIndex = cursor.index;
|
|
104
106
|
this._nodes = [];
|
|
107
|
+
this._patterns = [];
|
|
105
108
|
|
|
106
109
|
const passed = this._tryToParse(cursor);
|
|
107
110
|
|
|
@@ -165,6 +168,7 @@ export class InfiniteRepeat implements Pattern {
|
|
|
165
168
|
|
|
166
169
|
if (repeatNode != null) {
|
|
167
170
|
this._nodes.push(repeatNode);
|
|
171
|
+
this._patterns.push(this._pattern);
|
|
168
172
|
|
|
169
173
|
if (!cursor.hasNext()) {
|
|
170
174
|
passed = true;
|
|
@@ -192,6 +196,7 @@ export class InfiniteRepeat implements Pattern {
|
|
|
192
196
|
}
|
|
193
197
|
} else {
|
|
194
198
|
this._nodes.push(dividerNode);
|
|
199
|
+
this._patterns.push(this._divider);
|
|
195
200
|
|
|
196
201
|
if (!cursor.hasNext()) {
|
|
197
202
|
passed = true;
|
|
@@ -220,11 +225,12 @@ export class InfiniteRepeat implements Pattern {
|
|
|
220
225
|
|
|
221
226
|
private _createNode(cursor: Cursor): Node | null {
|
|
222
227
|
const hasDivider = this._divider != null;
|
|
228
|
+
const lastPattern = this._patterns[this._patterns.length - 1];
|
|
223
229
|
|
|
224
230
|
if (
|
|
225
231
|
hasDivider &&
|
|
226
232
|
this._trimDivider &&
|
|
227
|
-
|
|
233
|
+
lastPattern === this._divider
|
|
228
234
|
) {
|
|
229
235
|
const dividerNode = this._nodes.pop() as Node;
|
|
230
236
|
cursor.moveTo(dividerNode.firstIndex);
|