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.browser.js
CHANGED
|
@@ -378,6 +378,14 @@
|
|
|
378
378
|
}
|
|
379
379
|
}
|
|
380
380
|
|
|
381
|
+
class CyclicalParseError extends Error {
|
|
382
|
+
constructor(patternId, patternName, cursorIndex) {
|
|
383
|
+
super("Cyclical Parse Error");
|
|
384
|
+
this.patternId = patternId;
|
|
385
|
+
this.patternName = patternName;
|
|
386
|
+
this.cursorIndex = cursorIndex;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
381
389
|
class Cursor {
|
|
382
390
|
get text() {
|
|
383
391
|
return this._text;
|
|
@@ -483,14 +491,13 @@
|
|
|
483
491
|
this._history.stopRecording();
|
|
484
492
|
}
|
|
485
493
|
startParseWith(pattern) {
|
|
486
|
-
const patternName = pattern.name;
|
|
487
494
|
const trace = {
|
|
488
495
|
pattern,
|
|
489
496
|
cursorIndex: this.index
|
|
490
497
|
};
|
|
491
|
-
const hasCycle = this._stackTrace.
|
|
498
|
+
const hasCycle = this._stackTrace.filter(t => t.pattern.id === pattern.id && this.index === t.cursorIndex).length > 1;
|
|
492
499
|
if (hasCycle) {
|
|
493
|
-
throw new
|
|
500
|
+
throw new CyclicalParseError(pattern.id, pattern.name, this.index);
|
|
494
501
|
}
|
|
495
502
|
this._history.pushStackTrace(trace);
|
|
496
503
|
this._stackTrace.push(trace);
|
|
@@ -998,7 +1005,13 @@
|
|
|
998
1005
|
const results = [];
|
|
999
1006
|
for (const pattern of this._children) {
|
|
1000
1007
|
cursor.moveTo(this._firstIndex);
|
|
1001
|
-
|
|
1008
|
+
let result = null;
|
|
1009
|
+
try {
|
|
1010
|
+
result = pattern.parse(cursor);
|
|
1011
|
+
}
|
|
1012
|
+
catch (_a) {
|
|
1013
|
+
continue;
|
|
1014
|
+
}
|
|
1002
1015
|
if (this._isGreedy) {
|
|
1003
1016
|
results.push(result);
|
|
1004
1017
|
}
|
|
@@ -1994,8 +2007,8 @@
|
|
|
1994
2007
|
]);
|
|
1995
2008
|
|
|
1996
2009
|
const optionalSpaces$3 = new Optional("optional-spaces", spaces$1);
|
|
1997
|
-
const openBracket$1 = new Literal("open-bracket", "{");
|
|
1998
|
-
const closeBracket$1 = new Literal("close-bracket", "}");
|
|
2010
|
+
const openBracket$1 = new Literal("repeat-open-bracket", "{");
|
|
2011
|
+
const closeBracket$1 = new Literal("repeat-close-bracket", "}");
|
|
1999
2012
|
const comma = new Literal("comma", ",");
|
|
2000
2013
|
const integer = new Regex("integer", "([1-9][0-9]*)|0");
|
|
2001
2014
|
integer.setTokens(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]);
|
|
@@ -2032,15 +2045,15 @@
|
|
|
2032
2045
|
const dividerComma = new Regex("divider-comma", "\\s*,\\s*");
|
|
2033
2046
|
dividerComma.setTokens([", "]);
|
|
2034
2047
|
const patternName$2 = name$1.clone("pattern-name");
|
|
2035
|
-
const
|
|
2036
|
-
const
|
|
2037
|
-
const
|
|
2038
|
-
const
|
|
2048
|
+
const repeatPattern = new Options("repeat-pattern", [patternName$2, anonymousPattern]);
|
|
2049
|
+
const repeatDividerPattern = repeatPattern.clone("repeat-divider-pattern");
|
|
2050
|
+
const repeatDividerSection = new Sequence("repeat-divider-section", [dividerComma, repeatDividerPattern, trimFlag]);
|
|
2051
|
+
const repeatOptionalDividerSection = new Optional("repeat-optional-divider-section", repeatDividerSection);
|
|
2039
2052
|
const repeatLiteral = new Sequence("repeat-literal", [
|
|
2040
2053
|
openParen,
|
|
2041
2054
|
optionalSpaces$3,
|
|
2042
|
-
|
|
2043
|
-
|
|
2055
|
+
repeatPattern,
|
|
2056
|
+
repeatOptionalDividerSection,
|
|
2044
2057
|
optionalSpaces$3,
|
|
2045
2058
|
closeParen,
|
|
2046
2059
|
new Sequence("quantifier-section", [quantifier]),
|
|
@@ -2061,7 +2074,7 @@
|
|
|
2061
2074
|
|
|
2062
2075
|
const patternName = name$1.clone("pattern-name");
|
|
2063
2076
|
patternName.setTokens(["[PATTERN_NAME]"]);
|
|
2064
|
-
const patterns$1 = new Options("
|
|
2077
|
+
const patterns$1 = new Options("options-patterns", [patternName, anonymousPattern]);
|
|
2065
2078
|
const defaultDivider = new Regex("default-divider", "\\s*[|]\\s*");
|
|
2066
2079
|
defaultDivider.setTokens(["|"]);
|
|
2067
2080
|
const greedyDivider = new Regex("greedy-divider", "\\s*[<][|][>]\\s*");
|
|
@@ -2108,7 +2121,7 @@
|
|
|
2108
2121
|
const body = new Optional("optional-body", new Repeat("body", bodyLine, { divider: newLine$1 }));
|
|
2109
2122
|
|
|
2110
2123
|
const optionalSpaces$1 = new Optional("optional-spaces", allSpaces);
|
|
2111
|
-
const optionalLineSpaces$1 = new Optional("
|
|
2124
|
+
const optionalLineSpaces$1 = new Optional("optional-line-spaces", lineSpaces$1);
|
|
2112
2125
|
const importNameDivider = new Regex("import-name-divider", "(\\s+)?,(\\s+)?");
|
|
2113
2126
|
importNameDivider.setTokens([", "]);
|
|
2114
2127
|
const name = new Regex("import-name", "[^}\\s,]+");
|
|
@@ -2748,7 +2761,7 @@
|
|
|
2748
2761
|
const trimDivider = repeatNode.find(n => n.name === "trim-flag") != null;
|
|
2749
2762
|
const patterNode = repeatNode.children[1].type === "spaces" ? repeatNode.children[2] : repeatNode.children[1];
|
|
2750
2763
|
const pattern = this._buildPattern(patterNode);
|
|
2751
|
-
const dividerSectionNode = repeatNode.find(n => n.name === "divider-section");
|
|
2764
|
+
const dividerSectionNode = repeatNode.find(n => n.name === "repeat-divider-section");
|
|
2752
2765
|
const options = {
|
|
2753
2766
|
min: 1,
|
|
2754
2767
|
max: Infinity
|