clarity-pattern-parser 10.1.22 → 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 +29 -15
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +29 -15
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +29 -15
- 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 +21 -7
- 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 +24 -6
- 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.esm.js
CHANGED
|
@@ -262,9 +262,11 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
262
262
|
};
|
|
263
263
|
|
|
264
264
|
class ParseError {
|
|
265
|
-
constructor(startIndex,
|
|
265
|
+
constructor(startIndex, lastIndex, pattern) {
|
|
266
|
+
this.firstIndex = startIndex;
|
|
266
267
|
this.startIndex = startIndex;
|
|
267
|
-
this.
|
|
268
|
+
this.lastIndex = lastIndex;
|
|
269
|
+
this.endIndex = lastIndex + 1;
|
|
268
270
|
this.pattern = pattern;
|
|
269
271
|
}
|
|
270
272
|
}
|
|
@@ -354,7 +356,7 @@ class CursorHistory {
|
|
|
354
356
|
recordErrorAt(startIndex, endIndex, pattern) {
|
|
355
357
|
const error = new ParseError(startIndex, endIndex, pattern);
|
|
356
358
|
this._currentError = error;
|
|
357
|
-
if (this._furthestError === null || endIndex > this._furthestError.
|
|
359
|
+
if (this._furthestError === null || endIndex > this._furthestError.lastIndex) {
|
|
358
360
|
this._furthestError = error;
|
|
359
361
|
}
|
|
360
362
|
if (this._isRecording) {
|
|
@@ -2406,18 +2408,18 @@ class AutoComplete {
|
|
|
2406
2408
|
const furthestError = cursor.furthestError;
|
|
2407
2409
|
const furthestMatch = cursor.allMatchedNodes[cursor.allMatchedNodes.length - 1];
|
|
2408
2410
|
if (furthestError && furthestMatch) {
|
|
2409
|
-
if (furthestError.
|
|
2411
|
+
if (furthestError.lastIndex > furthestMatch.endIndex) {
|
|
2410
2412
|
return furthestMatch.endIndex;
|
|
2411
2413
|
}
|
|
2412
2414
|
else {
|
|
2413
|
-
return furthestError.
|
|
2415
|
+
return furthestError.lastIndex;
|
|
2414
2416
|
}
|
|
2415
2417
|
}
|
|
2416
2418
|
if (furthestError == null && furthestMatch != null) {
|
|
2417
2419
|
return furthestMatch.endIndex;
|
|
2418
2420
|
}
|
|
2419
2421
|
if (furthestMatch == null && furthestError != null) {
|
|
2420
|
-
return furthestError.
|
|
2422
|
+
return furthestError.lastIndex;
|
|
2421
2423
|
}
|
|
2422
2424
|
return 0;
|
|
2423
2425
|
}
|
|
@@ -2438,11 +2440,11 @@ class AutoComplete {
|
|
|
2438
2440
|
}
|
|
2439
2441
|
_getOptionsFromErrors() {
|
|
2440
2442
|
// These errored because the length of the string.
|
|
2441
|
-
const errors = this._cursor.errors.filter(e => e.
|
|
2443
|
+
const errors = this._cursor.errors.filter(e => e.lastIndex === this._cursor.length);
|
|
2442
2444
|
const suggestions = errors.map(e => {
|
|
2443
2445
|
const tokens = this._getTokensForPattern(e.pattern);
|
|
2444
|
-
const adjustedTokens = tokens.map(t => t.slice(e.
|
|
2445
|
-
return this._createSuggestions(e.
|
|
2446
|
+
const adjustedTokens = tokens.map(t => t.slice(e.lastIndex - e.startIndex));
|
|
2447
|
+
return this._createSuggestions(e.lastIndex, adjustedTokens);
|
|
2446
2448
|
});
|
|
2447
2449
|
return suggestions.flat();
|
|
2448
2450
|
}
|
|
@@ -2622,20 +2624,32 @@ class Context {
|
|
|
2622
2624
|
getTokens() {
|
|
2623
2625
|
return this._pattern.getTokens();
|
|
2624
2626
|
}
|
|
2625
|
-
getTokensAfter(
|
|
2626
|
-
|
|
2627
|
+
getTokensAfter(_childReference) {
|
|
2628
|
+
if (this._parent == null) {
|
|
2629
|
+
return [];
|
|
2630
|
+
}
|
|
2631
|
+
return this._parent.getTokensAfter(this);
|
|
2627
2632
|
}
|
|
2628
2633
|
getNextTokens() {
|
|
2629
|
-
|
|
2634
|
+
if (this._parent == null) {
|
|
2635
|
+
return [];
|
|
2636
|
+
}
|
|
2637
|
+
return this._parent.getTokensAfter(this);
|
|
2630
2638
|
}
|
|
2631
2639
|
getPatterns() {
|
|
2632
2640
|
return this._pattern.getPatterns();
|
|
2633
2641
|
}
|
|
2634
|
-
getPatternsAfter(
|
|
2635
|
-
|
|
2642
|
+
getPatternsAfter(_childReference) {
|
|
2643
|
+
if (this._parent == null) {
|
|
2644
|
+
return [];
|
|
2645
|
+
}
|
|
2646
|
+
return this._parent.getPatternsAfter(this);
|
|
2636
2647
|
}
|
|
2637
2648
|
getNextPatterns() {
|
|
2638
|
-
|
|
2649
|
+
if (this._parent == null) {
|
|
2650
|
+
return [];
|
|
2651
|
+
}
|
|
2652
|
+
return this._parent.getPatternsAfter(this);
|
|
2639
2653
|
}
|
|
2640
2654
|
find(predicate) {
|
|
2641
2655
|
return this._pattern.find(predicate);
|