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.browser.js
CHANGED
|
@@ -268,9 +268,11 @@
|
|
|
268
268
|
};
|
|
269
269
|
|
|
270
270
|
class ParseError {
|
|
271
|
-
constructor(startIndex,
|
|
271
|
+
constructor(startIndex, lastIndex, pattern) {
|
|
272
|
+
this.firstIndex = startIndex;
|
|
272
273
|
this.startIndex = startIndex;
|
|
273
|
-
this.
|
|
274
|
+
this.lastIndex = lastIndex;
|
|
275
|
+
this.endIndex = lastIndex + 1;
|
|
274
276
|
this.pattern = pattern;
|
|
275
277
|
}
|
|
276
278
|
}
|
|
@@ -360,7 +362,7 @@
|
|
|
360
362
|
recordErrorAt(startIndex, endIndex, pattern) {
|
|
361
363
|
const error = new ParseError(startIndex, endIndex, pattern);
|
|
362
364
|
this._currentError = error;
|
|
363
|
-
if (this._furthestError === null || endIndex > this._furthestError.
|
|
365
|
+
if (this._furthestError === null || endIndex > this._furthestError.lastIndex) {
|
|
364
366
|
this._furthestError = error;
|
|
365
367
|
}
|
|
366
368
|
if (this._isRecording) {
|
|
@@ -2412,18 +2414,18 @@
|
|
|
2412
2414
|
const furthestError = cursor.furthestError;
|
|
2413
2415
|
const furthestMatch = cursor.allMatchedNodes[cursor.allMatchedNodes.length - 1];
|
|
2414
2416
|
if (furthestError && furthestMatch) {
|
|
2415
|
-
if (furthestError.
|
|
2417
|
+
if (furthestError.lastIndex > furthestMatch.endIndex) {
|
|
2416
2418
|
return furthestMatch.endIndex;
|
|
2417
2419
|
}
|
|
2418
2420
|
else {
|
|
2419
|
-
return furthestError.
|
|
2421
|
+
return furthestError.lastIndex;
|
|
2420
2422
|
}
|
|
2421
2423
|
}
|
|
2422
2424
|
if (furthestError == null && furthestMatch != null) {
|
|
2423
2425
|
return furthestMatch.endIndex;
|
|
2424
2426
|
}
|
|
2425
2427
|
if (furthestMatch == null && furthestError != null) {
|
|
2426
|
-
return furthestError.
|
|
2428
|
+
return furthestError.lastIndex;
|
|
2427
2429
|
}
|
|
2428
2430
|
return 0;
|
|
2429
2431
|
}
|
|
@@ -2444,11 +2446,11 @@
|
|
|
2444
2446
|
}
|
|
2445
2447
|
_getOptionsFromErrors() {
|
|
2446
2448
|
// These errored because the length of the string.
|
|
2447
|
-
const errors = this._cursor.errors.filter(e => e.
|
|
2449
|
+
const errors = this._cursor.errors.filter(e => e.lastIndex === this._cursor.length);
|
|
2448
2450
|
const suggestions = errors.map(e => {
|
|
2449
2451
|
const tokens = this._getTokensForPattern(e.pattern);
|
|
2450
|
-
const adjustedTokens = tokens.map(t => t.slice(e.
|
|
2451
|
-
return this._createSuggestions(e.
|
|
2452
|
+
const adjustedTokens = tokens.map(t => t.slice(e.lastIndex - e.startIndex));
|
|
2453
|
+
return this._createSuggestions(e.lastIndex, adjustedTokens);
|
|
2452
2454
|
});
|
|
2453
2455
|
return suggestions.flat();
|
|
2454
2456
|
}
|
|
@@ -2628,20 +2630,32 @@
|
|
|
2628
2630
|
getTokens() {
|
|
2629
2631
|
return this._pattern.getTokens();
|
|
2630
2632
|
}
|
|
2631
|
-
getTokensAfter(
|
|
2632
|
-
|
|
2633
|
+
getTokensAfter(_childReference) {
|
|
2634
|
+
if (this._parent == null) {
|
|
2635
|
+
return [];
|
|
2636
|
+
}
|
|
2637
|
+
return this._parent.getTokensAfter(this);
|
|
2633
2638
|
}
|
|
2634
2639
|
getNextTokens() {
|
|
2635
|
-
|
|
2640
|
+
if (this._parent == null) {
|
|
2641
|
+
return [];
|
|
2642
|
+
}
|
|
2643
|
+
return this._parent.getTokensAfter(this);
|
|
2636
2644
|
}
|
|
2637
2645
|
getPatterns() {
|
|
2638
2646
|
return this._pattern.getPatterns();
|
|
2639
2647
|
}
|
|
2640
|
-
getPatternsAfter(
|
|
2641
|
-
|
|
2648
|
+
getPatternsAfter(_childReference) {
|
|
2649
|
+
if (this._parent == null) {
|
|
2650
|
+
return [];
|
|
2651
|
+
}
|
|
2652
|
+
return this._parent.getPatternsAfter(this);
|
|
2642
2653
|
}
|
|
2643
2654
|
getNextPatterns() {
|
|
2644
|
-
|
|
2655
|
+
if (this._parent == null) {
|
|
2656
|
+
return [];
|
|
2657
|
+
}
|
|
2658
|
+
return this._parent.getPatternsAfter(this);
|
|
2645
2659
|
}
|
|
2646
2660
|
find(predicate) {
|
|
2647
2661
|
return this._pattern.find(predicate);
|