clarity-pattern-parser 3.0.12 → 3.0.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/index.browser.js +20 -7
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +20 -7
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +20 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/TextSuggester.ts +20 -1
- package/src/patterns/Pattern.ts +1 -1
- package/src/patterns/composite/RepeatComposite.ts +2 -2
- package/src/patterns/value/RepeatValue.ts +2 -2
- package/src/tests/TextSuggester.test.ts +45 -1
package/dist/index.js
CHANGED
|
@@ -346,7 +346,7 @@ class Pattern {
|
|
|
346
346
|
return nextSibling.getTokens().concat(tokens);
|
|
347
347
|
}
|
|
348
348
|
else if (index === 1) {
|
|
349
|
-
return siblings[0].getTokens()
|
|
349
|
+
return siblings[0].getTokens();
|
|
350
350
|
}
|
|
351
351
|
else {
|
|
352
352
|
return this.getTokens().concat(tokens);
|
|
@@ -907,7 +907,6 @@ class RepeatValue extends ValuePattern {
|
|
|
907
907
|
else {
|
|
908
908
|
this.nodes.push(node);
|
|
909
909
|
if (node.endIndex === this.cursor.lastIndex()) {
|
|
910
|
-
this.nodes.length = 0;
|
|
911
910
|
this._processMatch();
|
|
912
911
|
break;
|
|
913
912
|
}
|
|
@@ -918,8 +917,9 @@ class RepeatValue extends ValuePattern {
|
|
|
918
917
|
}
|
|
919
918
|
}
|
|
920
919
|
_processMatch() {
|
|
920
|
+
const endsOnDivider = this.nodes.length % 2 === 0;
|
|
921
921
|
this.cursor.resolveError();
|
|
922
|
-
if (
|
|
922
|
+
if (endsOnDivider) {
|
|
923
923
|
const parseError = new ParseError(`Did not find a repeating match of ${this.name}.`, this.mark, this);
|
|
924
924
|
this.cursor.throwError(parseError);
|
|
925
925
|
this.node = null;
|
|
@@ -1204,7 +1204,6 @@ class RepeatComposite extends CompositePattern {
|
|
|
1204
1204
|
else {
|
|
1205
1205
|
this.nodes.push(node);
|
|
1206
1206
|
if (node.endIndex === this.cursor.lastIndex()) {
|
|
1207
|
-
this.nodes.length = 0;
|
|
1208
1207
|
this._processMatch();
|
|
1209
1208
|
break;
|
|
1210
1209
|
}
|
|
@@ -1215,8 +1214,9 @@ class RepeatComposite extends CompositePattern {
|
|
|
1215
1214
|
}
|
|
1216
1215
|
}
|
|
1217
1216
|
_processMatch() {
|
|
1217
|
+
const endsOnDivider = this.nodes.length % 2 === 0;
|
|
1218
1218
|
this.cursor.resolveError();
|
|
1219
|
-
if (
|
|
1219
|
+
if (endsOnDivider) {
|
|
1220
1220
|
this.cursor.throwError(new ParseError(`Did not find a repeating match of ${this.name}.`, this.mark, this));
|
|
1221
1221
|
this.node = null;
|
|
1222
1222
|
}
|
|
@@ -1504,8 +1504,21 @@ class TextSuggester {
|
|
|
1504
1504
|
};
|
|
1505
1505
|
}
|
|
1506
1506
|
saveOptions() {
|
|
1507
|
-
|
|
1508
|
-
const
|
|
1507
|
+
const parents = new Map();
|
|
1508
|
+
const cursor = this.cursor;
|
|
1509
|
+
if (cursor == null) {
|
|
1510
|
+
this.options = [];
|
|
1511
|
+
return;
|
|
1512
|
+
}
|
|
1513
|
+
const furthestMatches = cursor.history.astNodes.reduce((acc, node, index) => {
|
|
1514
|
+
const pattern = cursor.history.patterns[index];
|
|
1515
|
+
const parent = pattern.parent;
|
|
1516
|
+
if (parent != null) {
|
|
1517
|
+
parents.set(parent, parent);
|
|
1518
|
+
}
|
|
1519
|
+
if (parents.has(pattern)) {
|
|
1520
|
+
return acc;
|
|
1521
|
+
}
|
|
1509
1522
|
if (node.endIndex === acc.furthestTextIndex) {
|
|
1510
1523
|
acc.nodeIndexes.push(index);
|
|
1511
1524
|
}
|