clarity-pattern-parser 10.1.23 → 10.1.24
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 +25 -17
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +25 -17
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +25 -17
- package/dist/index.js.map +1 -1
- package/dist/patterns/Context.d.ts +2 -2
- package/dist/patterns/ParseError.d.ts +6 -4
- package/package.json +1 -1
- package/src/intellisense/AutoComplete.test.ts +37 -1
- package/src/intellisense/AutoComplete.ts +6 -6
- package/src/patterns/Context.ts +16 -9
- package/src/patterns/Cursor.test.ts +3 -3
- package/src/patterns/CursorHistory.test.ts +6 -6
- package/src/patterns/CursorHistory.ts +1 -1
- package/src/patterns/ExpressionPattern.ts +15 -5
- package/src/patterns/Literal.test.ts +2 -2
- package/src/patterns/ParseError.ts +9 -5
- package/src/patterns/Sequence.test.ts +2 -2
package/dist/index.js
CHANGED
|
@@ -266,9 +266,11 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
266
266
|
};
|
|
267
267
|
|
|
268
268
|
class ParseError {
|
|
269
|
-
constructor(startIndex,
|
|
269
|
+
constructor(startIndex, lastIndex, pattern) {
|
|
270
|
+
this.firstIndex = startIndex;
|
|
270
271
|
this.startIndex = startIndex;
|
|
271
|
-
this.
|
|
272
|
+
this.lastIndex = lastIndex;
|
|
273
|
+
this.endIndex = lastIndex + 1;
|
|
272
274
|
this.pattern = pattern;
|
|
273
275
|
}
|
|
274
276
|
}
|
|
@@ -358,7 +360,7 @@ class CursorHistory {
|
|
|
358
360
|
recordErrorAt(startIndex, endIndex, pattern) {
|
|
359
361
|
const error = new ParseError(startIndex, endIndex, pattern);
|
|
360
362
|
this._currentError = error;
|
|
361
|
-
if (this._furthestError === null || endIndex > this._furthestError.
|
|
363
|
+
if (this._furthestError === null || endIndex > this._furthestError.lastIndex) {
|
|
362
364
|
this._furthestError = error;
|
|
363
365
|
}
|
|
364
366
|
if (this._isRecording) {
|
|
@@ -2410,18 +2412,18 @@ class AutoComplete {
|
|
|
2410
2412
|
const furthestError = cursor.furthestError;
|
|
2411
2413
|
const furthestMatch = cursor.allMatchedNodes[cursor.allMatchedNodes.length - 1];
|
|
2412
2414
|
if (furthestError && furthestMatch) {
|
|
2413
|
-
if (furthestError.
|
|
2415
|
+
if (furthestError.lastIndex > furthestMatch.endIndex) {
|
|
2414
2416
|
return furthestMatch.endIndex;
|
|
2415
2417
|
}
|
|
2416
2418
|
else {
|
|
2417
|
-
return furthestError.
|
|
2419
|
+
return furthestError.lastIndex;
|
|
2418
2420
|
}
|
|
2419
2421
|
}
|
|
2420
2422
|
if (furthestError == null && furthestMatch != null) {
|
|
2421
2423
|
return furthestMatch.endIndex;
|
|
2422
2424
|
}
|
|
2423
2425
|
if (furthestMatch == null && furthestError != null) {
|
|
2424
|
-
return furthestError.
|
|
2426
|
+
return furthestError.lastIndex;
|
|
2425
2427
|
}
|
|
2426
2428
|
return 0;
|
|
2427
2429
|
}
|
|
@@ -2442,11 +2444,11 @@ class AutoComplete {
|
|
|
2442
2444
|
}
|
|
2443
2445
|
_getOptionsFromErrors() {
|
|
2444
2446
|
// These errored because the length of the string.
|
|
2445
|
-
const errors = this._cursor.errors.filter(e => e.
|
|
2447
|
+
const errors = this._cursor.errors.filter(e => e.lastIndex === this._cursor.length);
|
|
2446
2448
|
const suggestions = errors.map(e => {
|
|
2447
2449
|
const tokens = this._getTokensForPattern(e.pattern);
|
|
2448
|
-
const adjustedTokens = tokens.map(t => t.slice(e.
|
|
2449
|
-
return this._createSuggestions(e.
|
|
2450
|
+
const adjustedTokens = tokens.map(t => t.slice(e.lastIndex - e.startIndex));
|
|
2451
|
+
return this._createSuggestions(e.lastIndex, adjustedTokens);
|
|
2450
2452
|
});
|
|
2451
2453
|
return suggestions.flat();
|
|
2452
2454
|
}
|
|
@@ -2626,26 +2628,32 @@ class Context {
|
|
|
2626
2628
|
getTokens() {
|
|
2627
2629
|
return this._pattern.getTokens();
|
|
2628
2630
|
}
|
|
2629
|
-
getTokensAfter(
|
|
2630
|
-
if (this.
|
|
2631
|
+
getTokensAfter(_childReference) {
|
|
2632
|
+
if (this._parent == null) {
|
|
2631
2633
|
return [];
|
|
2632
2634
|
}
|
|
2633
|
-
return this.
|
|
2635
|
+
return this._parent.getTokensAfter(this);
|
|
2634
2636
|
}
|
|
2635
2637
|
getNextTokens() {
|
|
2636
|
-
|
|
2638
|
+
if (this._parent == null) {
|
|
2639
|
+
return [];
|
|
2640
|
+
}
|
|
2641
|
+
return this._parent.getTokensAfter(this);
|
|
2637
2642
|
}
|
|
2638
2643
|
getPatterns() {
|
|
2639
2644
|
return this._pattern.getPatterns();
|
|
2640
2645
|
}
|
|
2641
|
-
getPatternsAfter(
|
|
2642
|
-
if (this.
|
|
2646
|
+
getPatternsAfter(_childReference) {
|
|
2647
|
+
if (this._parent == null) {
|
|
2643
2648
|
return [];
|
|
2644
2649
|
}
|
|
2645
|
-
return this.
|
|
2650
|
+
return this._parent.getPatternsAfter(this);
|
|
2646
2651
|
}
|
|
2647
2652
|
getNextPatterns() {
|
|
2648
|
-
|
|
2653
|
+
if (this._parent == null) {
|
|
2654
|
+
return [];
|
|
2655
|
+
}
|
|
2656
|
+
return this._parent.getPatternsAfter(this);
|
|
2649
2657
|
}
|
|
2650
2658
|
find(predicate) {
|
|
2651
2659
|
return this._pattern.find(predicate);
|