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.esm.js
CHANGED
|
@@ -342,7 +342,7 @@ class Pattern {
|
|
|
342
342
|
return nextSibling.getTokens().concat(tokens);
|
|
343
343
|
}
|
|
344
344
|
else if (index === 1) {
|
|
345
|
-
return siblings[0].getTokens()
|
|
345
|
+
return siblings[0].getTokens();
|
|
346
346
|
}
|
|
347
347
|
else {
|
|
348
348
|
return this.getTokens().concat(tokens);
|
|
@@ -903,7 +903,6 @@ class RepeatValue extends ValuePattern {
|
|
|
903
903
|
else {
|
|
904
904
|
this.nodes.push(node);
|
|
905
905
|
if (node.endIndex === this.cursor.lastIndex()) {
|
|
906
|
-
this.nodes.length = 0;
|
|
907
906
|
this._processMatch();
|
|
908
907
|
break;
|
|
909
908
|
}
|
|
@@ -914,8 +913,9 @@ class RepeatValue extends ValuePattern {
|
|
|
914
913
|
}
|
|
915
914
|
}
|
|
916
915
|
_processMatch() {
|
|
916
|
+
const endsOnDivider = this.nodes.length % 2 === 0;
|
|
917
917
|
this.cursor.resolveError();
|
|
918
|
-
if (
|
|
918
|
+
if (endsOnDivider) {
|
|
919
919
|
const parseError = new ParseError(`Did not find a repeating match of ${this.name}.`, this.mark, this);
|
|
920
920
|
this.cursor.throwError(parseError);
|
|
921
921
|
this.node = null;
|
|
@@ -1200,7 +1200,6 @@ class RepeatComposite extends CompositePattern {
|
|
|
1200
1200
|
else {
|
|
1201
1201
|
this.nodes.push(node);
|
|
1202
1202
|
if (node.endIndex === this.cursor.lastIndex()) {
|
|
1203
|
-
this.nodes.length = 0;
|
|
1204
1203
|
this._processMatch();
|
|
1205
1204
|
break;
|
|
1206
1205
|
}
|
|
@@ -1211,8 +1210,9 @@ class RepeatComposite extends CompositePattern {
|
|
|
1211
1210
|
}
|
|
1212
1211
|
}
|
|
1213
1212
|
_processMatch() {
|
|
1213
|
+
const endsOnDivider = this.nodes.length % 2 === 0;
|
|
1214
1214
|
this.cursor.resolveError();
|
|
1215
|
-
if (
|
|
1215
|
+
if (endsOnDivider) {
|
|
1216
1216
|
this.cursor.throwError(new ParseError(`Did not find a repeating match of ${this.name}.`, this.mark, this));
|
|
1217
1217
|
this.node = null;
|
|
1218
1218
|
}
|
|
@@ -1500,8 +1500,21 @@ class TextSuggester {
|
|
|
1500
1500
|
};
|
|
1501
1501
|
}
|
|
1502
1502
|
saveOptions() {
|
|
1503
|
-
|
|
1504
|
-
const
|
|
1503
|
+
const parents = new Map();
|
|
1504
|
+
const cursor = this.cursor;
|
|
1505
|
+
if (cursor == null) {
|
|
1506
|
+
this.options = [];
|
|
1507
|
+
return;
|
|
1508
|
+
}
|
|
1509
|
+
const furthestMatches = cursor.history.astNodes.reduce((acc, node, index) => {
|
|
1510
|
+
const pattern = cursor.history.patterns[index];
|
|
1511
|
+
const parent = pattern.parent;
|
|
1512
|
+
if (parent != null) {
|
|
1513
|
+
parents.set(parent, parent);
|
|
1514
|
+
}
|
|
1515
|
+
if (parents.has(pattern)) {
|
|
1516
|
+
return acc;
|
|
1517
|
+
}
|
|
1505
1518
|
if (node.endIndex === acc.furthestTextIndex) {
|
|
1506
1519
|
acc.nodeIndexes.push(index);
|
|
1507
1520
|
}
|