clarity-pattern-parser 10.0.3 → 10.0.5
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 +28 -15
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +28 -15
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +28 -15
- package/dist/index.js.map +1 -1
- package/dist/patterns/Cursor.d.ts +6 -0
- package/package.json +1 -1
- package/src/grammar/Grammar.ts +1 -1
- package/src/grammar/patterns/import.ts +1 -1
- package/src/grammar/patterns/optionsLiteral.ts +1 -1
- package/src/grammar/patterns/repeatLiteral.ts +8 -8
- package/src/intellisense/AutoComplete.ts +7 -7
- package/src/patterns/Cursor.ts +15 -4
- package/src/patterns/Options.test.ts +41 -0
- package/src/patterns/Options.ts +8 -1
package/dist/index.esm.js
CHANGED
|
@@ -372,6 +372,14 @@ class CursorHistory {
|
|
|
372
372
|
}
|
|
373
373
|
}
|
|
374
374
|
|
|
375
|
+
class CyclicalParseError extends Error {
|
|
376
|
+
constructor(patternId, patternName, cursorIndex) {
|
|
377
|
+
super("Cyclical Parse Error");
|
|
378
|
+
this.patternId = patternId;
|
|
379
|
+
this.patternName = patternName;
|
|
380
|
+
this.cursorIndex = cursorIndex;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
375
383
|
class Cursor {
|
|
376
384
|
get text() {
|
|
377
385
|
return this._text;
|
|
@@ -477,14 +485,13 @@ class Cursor {
|
|
|
477
485
|
this._history.stopRecording();
|
|
478
486
|
}
|
|
479
487
|
startParseWith(pattern) {
|
|
480
|
-
const patternName = pattern.name;
|
|
481
488
|
const trace = {
|
|
482
489
|
pattern,
|
|
483
490
|
cursorIndex: this.index
|
|
484
491
|
};
|
|
485
|
-
const hasCycle = this._stackTrace.
|
|
492
|
+
const hasCycle = this._stackTrace.filter(t => t.pattern.id === pattern.id && this.index === t.cursorIndex).length > 1;
|
|
486
493
|
if (hasCycle) {
|
|
487
|
-
throw new
|
|
494
|
+
throw new CyclicalParseError(pattern.id, pattern.name, this.index);
|
|
488
495
|
}
|
|
489
496
|
this._history.pushStackTrace(trace);
|
|
490
497
|
this._stackTrace.push(trace);
|
|
@@ -992,7 +999,13 @@ class Options {
|
|
|
992
999
|
const results = [];
|
|
993
1000
|
for (const pattern of this._children) {
|
|
994
1001
|
cursor.moveTo(this._firstIndex);
|
|
995
|
-
|
|
1002
|
+
let result = null;
|
|
1003
|
+
try {
|
|
1004
|
+
result = pattern.parse(cursor);
|
|
1005
|
+
}
|
|
1006
|
+
catch (_a) {
|
|
1007
|
+
continue;
|
|
1008
|
+
}
|
|
996
1009
|
if (this._isGreedy) {
|
|
997
1010
|
results.push(result);
|
|
998
1011
|
}
|
|
@@ -1988,8 +2001,8 @@ const anonymousPattern = new Options("anonymous-pattern", [
|
|
|
1988
2001
|
]);
|
|
1989
2002
|
|
|
1990
2003
|
const optionalSpaces$3 = new Optional("optional-spaces", spaces$1);
|
|
1991
|
-
const openBracket$1 = new Literal("open-bracket", "{");
|
|
1992
|
-
const closeBracket$1 = new Literal("close-bracket", "}");
|
|
2004
|
+
const openBracket$1 = new Literal("repeat-open-bracket", "{");
|
|
2005
|
+
const closeBracket$1 = new Literal("repeat-close-bracket", "}");
|
|
1993
2006
|
const comma = new Literal("comma", ",");
|
|
1994
2007
|
const integer = new Regex("integer", "([1-9][0-9]*)|0");
|
|
1995
2008
|
integer.setTokens(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]);
|
|
@@ -2026,15 +2039,15 @@ const closeParen = new Literal("repeat-close-paren", ")");
|
|
|
2026
2039
|
const dividerComma = new Regex("divider-comma", "\\s*,\\s*");
|
|
2027
2040
|
dividerComma.setTokens([", "]);
|
|
2028
2041
|
const patternName$2 = name$1.clone("pattern-name");
|
|
2029
|
-
const
|
|
2030
|
-
const
|
|
2031
|
-
const
|
|
2032
|
-
const
|
|
2042
|
+
const repeatPattern = new Options("repeat-pattern", [patternName$2, anonymousPattern]);
|
|
2043
|
+
const repeatDividerPattern = repeatPattern.clone("repeat-divider-pattern");
|
|
2044
|
+
const repeatDividerSection = new Sequence("repeat-divider-section", [dividerComma, repeatDividerPattern, trimFlag]);
|
|
2045
|
+
const repeatOptionalDividerSection = new Optional("repeat-optional-divider-section", repeatDividerSection);
|
|
2033
2046
|
const repeatLiteral = new Sequence("repeat-literal", [
|
|
2034
2047
|
openParen,
|
|
2035
2048
|
optionalSpaces$3,
|
|
2036
|
-
|
|
2037
|
-
|
|
2049
|
+
repeatPattern,
|
|
2050
|
+
repeatOptionalDividerSection,
|
|
2038
2051
|
optionalSpaces$3,
|
|
2039
2052
|
closeParen,
|
|
2040
2053
|
new Sequence("quantifier-section", [quantifier]),
|
|
@@ -2055,7 +2068,7 @@ const sequenceLiteral = new Repeat("sequence-literal", pattern$1, { divider: div
|
|
|
2055
2068
|
|
|
2056
2069
|
const patternName = name$1.clone("pattern-name");
|
|
2057
2070
|
patternName.setTokens(["[PATTERN_NAME]"]);
|
|
2058
|
-
const patterns$1 = new Options("
|
|
2071
|
+
const patterns$1 = new Options("options-patterns", [patternName, anonymousPattern]);
|
|
2059
2072
|
const defaultDivider = new Regex("default-divider", "\\s*[|]\\s*");
|
|
2060
2073
|
defaultDivider.setTokens(["|"]);
|
|
2061
2074
|
const greedyDivider = new Regex("greedy-divider", "\\s*[<][|][>]\\s*");
|
|
@@ -2102,7 +2115,7 @@ const bodyLine = new Sequence("body-line", [
|
|
|
2102
2115
|
const body = new Optional("optional-body", new Repeat("body", bodyLine, { divider: newLine$1 }));
|
|
2103
2116
|
|
|
2104
2117
|
const optionalSpaces$1 = new Optional("optional-spaces", allSpaces);
|
|
2105
|
-
const optionalLineSpaces$1 = new Optional("
|
|
2118
|
+
const optionalLineSpaces$1 = new Optional("optional-line-spaces", lineSpaces$1);
|
|
2106
2119
|
const importNameDivider = new Regex("import-name-divider", "(\\s+)?,(\\s+)?");
|
|
2107
2120
|
importNameDivider.setTokens([", "]);
|
|
2108
2121
|
const name = new Regex("import-name", "[^}\\s,]+");
|
|
@@ -2742,7 +2755,7 @@ class Grammar {
|
|
|
2742
2755
|
const trimDivider = repeatNode.find(n => n.name === "trim-flag") != null;
|
|
2743
2756
|
const patterNode = repeatNode.children[1].type === "spaces" ? repeatNode.children[2] : repeatNode.children[1];
|
|
2744
2757
|
const pattern = this._buildPattern(patterNode);
|
|
2745
|
-
const dividerSectionNode = repeatNode.find(n => n.name === "divider-section");
|
|
2758
|
+
const dividerSectionNode = repeatNode.find(n => n.name === "repeat-divider-section");
|
|
2746
2759
|
const options = {
|
|
2747
2760
|
min: 1,
|
|
2748
2761
|
max: Infinity
|