clarity-pattern-parser 10.1.15 → 10.1.16
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 +38 -9
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +38 -9
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +38 -9
- package/dist/index.js.map +1 -1
- package/dist/patterns/Options.d.ts +2 -0
- package/package.json +1 -1
- package/src/grammar/ComplexGrammar.test.ts +2 -2
- package/src/patterns/Options.ts +39 -1
package/dist/index.browser.js
CHANGED
|
@@ -967,6 +967,34 @@
|
|
|
967
967
|
this._children = children;
|
|
968
968
|
this._firstIndex = 0;
|
|
969
969
|
this._isGreedy = isGreedy;
|
|
970
|
+
this._recursiveDepth = this._calculateRecursiveDepth();
|
|
971
|
+
}
|
|
972
|
+
_calculateRecursiveDepth() {
|
|
973
|
+
let depth = 0;
|
|
974
|
+
this._children.forEach((child) => {
|
|
975
|
+
let hasReference = false;
|
|
976
|
+
let descendant = child.children[0];
|
|
977
|
+
while (descendant != null) {
|
|
978
|
+
if (descendant.type === "reference" && descendant.name === this.name) {
|
|
979
|
+
hasReference = true;
|
|
980
|
+
break;
|
|
981
|
+
}
|
|
982
|
+
if (descendant.type === "context") {
|
|
983
|
+
const pattern = descendant.getPatternWithinContext(this.name);
|
|
984
|
+
if (pattern != null) {
|
|
985
|
+
break;
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
descendant = descendant.children[0];
|
|
989
|
+
}
|
|
990
|
+
if (hasReference) {
|
|
991
|
+
depth++;
|
|
992
|
+
}
|
|
993
|
+
});
|
|
994
|
+
if (depth === 0) {
|
|
995
|
+
depth = this.children.length;
|
|
996
|
+
}
|
|
997
|
+
return depth;
|
|
970
998
|
}
|
|
971
999
|
_assignChildrenToParent(children) {
|
|
972
1000
|
for (const child of children) {
|
|
@@ -1028,7 +1056,7 @@
|
|
|
1028
1056
|
if (pattern.id === this.id) {
|
|
1029
1057
|
depth++;
|
|
1030
1058
|
}
|
|
1031
|
-
if (depth
|
|
1059
|
+
if (depth > this._recursiveDepth) {
|
|
1032
1060
|
return true;
|
|
1033
1061
|
}
|
|
1034
1062
|
pattern = pattern.parent;
|
|
@@ -2385,15 +2413,16 @@
|
|
|
2385
2413
|
}
|
|
2386
2414
|
_getAllOptions() {
|
|
2387
2415
|
const errorMatches = this._getOptionsFromErrors();
|
|
2388
|
-
const
|
|
2389
|
-
const
|
|
2390
|
-
|
|
2391
|
-
|
|
2416
|
+
const validLeafMatches = this._cursor.leafMatches.filter(v => { var _a; return ((_a = v.node) === null || _a === void 0 ? void 0 : _a.lastIndex) === this._cursor.getLastIndex(); });
|
|
2417
|
+
const leafMatchSuggestions = validLeafMatches.map((m) => this._createSuggestionsFromMatch(m)).flat();
|
|
2418
|
+
const uniqueResults = [];
|
|
2419
|
+
[...leafMatchSuggestions, ...errorMatches].forEach(m => {
|
|
2420
|
+
const index = uniqueResults.findIndex(f => m.text === f.text);
|
|
2392
2421
|
if (index === -1) {
|
|
2393
|
-
|
|
2422
|
+
uniqueResults.push(m);
|
|
2394
2423
|
}
|
|
2395
2424
|
});
|
|
2396
|
-
return
|
|
2425
|
+
return uniqueResults;
|
|
2397
2426
|
}
|
|
2398
2427
|
_getOptionsFromErrors() {
|
|
2399
2428
|
// These errored because the length of the string.
|
|
@@ -2402,8 +2431,8 @@
|
|
|
2402
2431
|
const tokens = this._getTokensForPattern(e.pattern);
|
|
2403
2432
|
const adjustedTokens = tokens.map(t => t.slice(e.endIndex - e.startIndex));
|
|
2404
2433
|
return this._createSuggestions(e.endIndex, adjustedTokens);
|
|
2405
|
-
});
|
|
2406
|
-
return suggestions
|
|
2434
|
+
}).flat();
|
|
2435
|
+
return suggestions;
|
|
2407
2436
|
}
|
|
2408
2437
|
_createSuggestionsFromRoot() {
|
|
2409
2438
|
const suggestions = [];
|