clarity-pattern-parser 10.1.17 → 10.1.21
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 +41 -11
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +41 -11
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +41 -11
- package/dist/index.js.map +1 -1
- package/dist/intellisense/AutoComplete.d.ts +1 -0
- package/package.json +1 -1
- package/src/intellisense/AutoComplete.test.ts +85 -0
- package/src/intellisense/AutoComplete.ts +28 -9
- package/src/patterns/ExpressionPattern.ts +133 -0
- package/src/patterns/Options.ts +8 -4
- package/src/patterns/RightAssociatedPattern.ts +71 -0
- package/src/patterns/Sequence.ts +14 -6
package/dist/index.esm.js
CHANGED
|
@@ -1044,8 +1044,11 @@ class Options {
|
|
|
1044
1044
|
}
|
|
1045
1045
|
getTokens() {
|
|
1046
1046
|
const tokens = [];
|
|
1047
|
-
for (const
|
|
1048
|
-
|
|
1047
|
+
for (const pattern of this._children) {
|
|
1048
|
+
if (pattern.type === "reference" && pattern.name === this.name) {
|
|
1049
|
+
continue;
|
|
1050
|
+
}
|
|
1051
|
+
tokens.push(...pattern.getTokens());
|
|
1049
1052
|
}
|
|
1050
1053
|
return tokens;
|
|
1051
1054
|
}
|
|
@@ -1064,6 +1067,9 @@ class Options {
|
|
|
1064
1067
|
getPatterns() {
|
|
1065
1068
|
const patterns = [];
|
|
1066
1069
|
for (const pattern of this._children) {
|
|
1070
|
+
if (pattern.type === "reference" && pattern.name === this.name) {
|
|
1071
|
+
continue;
|
|
1072
|
+
}
|
|
1067
1073
|
patterns.push(...pattern.getPatterns());
|
|
1068
1074
|
}
|
|
1069
1075
|
return patterns;
|
|
@@ -1791,9 +1797,12 @@ class Sequence {
|
|
|
1791
1797
|
}
|
|
1792
1798
|
getTokens() {
|
|
1793
1799
|
const tokens = [];
|
|
1794
|
-
for (const
|
|
1795
|
-
|
|
1796
|
-
|
|
1800
|
+
for (const pattern of this._children) {
|
|
1801
|
+
if (pattern.type === "reference" && pattern.name === this.name && pattern === this.children[0]) {
|
|
1802
|
+
return tokens;
|
|
1803
|
+
}
|
|
1804
|
+
tokens.push(...pattern.getTokens());
|
|
1805
|
+
if (pattern.type !== "optional" && pattern.type !== "not") {
|
|
1797
1806
|
break;
|
|
1798
1807
|
}
|
|
1799
1808
|
}
|
|
@@ -1813,9 +1822,12 @@ class Sequence {
|
|
|
1813
1822
|
}
|
|
1814
1823
|
getPatterns() {
|
|
1815
1824
|
const patterns = [];
|
|
1816
|
-
for (const
|
|
1817
|
-
|
|
1818
|
-
|
|
1825
|
+
for (const pattern of this._children) {
|
|
1826
|
+
if (pattern.type === "reference" && pattern.name === this.name && pattern === this.children[0]) {
|
|
1827
|
+
return patterns;
|
|
1828
|
+
}
|
|
1829
|
+
patterns.push(...pattern.getPatterns());
|
|
1830
|
+
if (pattern.type !== "optional" && pattern.type !== "not") {
|
|
1819
1831
|
break;
|
|
1820
1832
|
}
|
|
1821
1833
|
}
|
|
@@ -2363,9 +2375,8 @@ class AutoComplete {
|
|
|
2363
2375
|
errorAtIndex = startIndex;
|
|
2364
2376
|
}
|
|
2365
2377
|
else if (!isComplete && this._cursor.hasError && this._cursor.furthestError != null) {
|
|
2366
|
-
errorAtIndex = this.
|
|
2367
|
-
error = this.
|
|
2368
|
-
errorAtIndex = options.reduce((errorAtIndex, option) => Math.max(errorAtIndex, option.startIndex), errorAtIndex);
|
|
2378
|
+
errorAtIndex = this.getFurthestPosition(cursor);
|
|
2379
|
+
error = new ParseError(errorAtIndex, errorAtIndex, this._pattern);
|
|
2369
2380
|
}
|
|
2370
2381
|
return {
|
|
2371
2382
|
isComplete: isComplete,
|
|
@@ -2376,6 +2387,25 @@ class AutoComplete {
|
|
|
2376
2387
|
ast,
|
|
2377
2388
|
};
|
|
2378
2389
|
}
|
|
2390
|
+
getFurthestPosition(cursor) {
|
|
2391
|
+
const furthestError = cursor.furthestError;
|
|
2392
|
+
const furthestMatch = cursor.allMatchedNodes[cursor.allMatchedNodes.length - 1];
|
|
2393
|
+
if (furthestError && furthestMatch) {
|
|
2394
|
+
if (furthestError.endIndex > furthestMatch.endIndex) {
|
|
2395
|
+
return furthestMatch.endIndex;
|
|
2396
|
+
}
|
|
2397
|
+
else {
|
|
2398
|
+
return furthestError.endIndex;
|
|
2399
|
+
}
|
|
2400
|
+
}
|
|
2401
|
+
if (furthestError == null && furthestMatch != null) {
|
|
2402
|
+
return furthestMatch.endIndex;
|
|
2403
|
+
}
|
|
2404
|
+
if (furthestMatch == null && furthestError != null) {
|
|
2405
|
+
return furthestError.endIndex;
|
|
2406
|
+
}
|
|
2407
|
+
return 0;
|
|
2408
|
+
}
|
|
2379
2409
|
suggestFor(text) {
|
|
2380
2410
|
return this.suggestForWithCursor(new Cursor(text));
|
|
2381
2411
|
}
|