clarity-pattern-parser 10.0.3 → 10.0.4
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 +33 -15
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +33 -15
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +33 -15
- package/dist/index.js.map +1 -1
- package/dist/patterns/Cursor.d.ts +5 -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 +13 -4
- package/src/patterns/Options.test.ts +24 -0
- package/src/patterns/Options.ts +13 -1
package/dist/index.browser.js
CHANGED
|
@@ -378,6 +378,13 @@
|
|
|
378
378
|
}
|
|
379
379
|
}
|
|
380
380
|
|
|
381
|
+
class CyclicalParseError extends Error {
|
|
382
|
+
constructor(patternId, patternName) {
|
|
383
|
+
super("Cyclical Parse Error");
|
|
384
|
+
this.patternId = patternId;
|
|
385
|
+
this.patternName = patternName;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
381
388
|
class Cursor {
|
|
382
389
|
get text() {
|
|
383
390
|
return this._text;
|
|
@@ -483,14 +490,13 @@
|
|
|
483
490
|
this._history.stopRecording();
|
|
484
491
|
}
|
|
485
492
|
startParseWith(pattern) {
|
|
486
|
-
const patternName = pattern.name;
|
|
487
493
|
const trace = {
|
|
488
494
|
pattern,
|
|
489
495
|
cursorIndex: this.index
|
|
490
496
|
};
|
|
491
|
-
const hasCycle = this._stackTrace.
|
|
497
|
+
const hasCycle = this._stackTrace.filter(t => t.pattern.id === pattern.id && this.index === t.cursorIndex).length > 1;
|
|
492
498
|
if (hasCycle) {
|
|
493
|
-
throw new
|
|
499
|
+
throw new CyclicalParseError(pattern.id, pattern.name);
|
|
494
500
|
}
|
|
495
501
|
this._history.pushStackTrace(trace);
|
|
496
502
|
this._stackTrace.push(trace);
|
|
@@ -998,7 +1004,19 @@
|
|
|
998
1004
|
const results = [];
|
|
999
1005
|
for (const pattern of this._children) {
|
|
1000
1006
|
cursor.moveTo(this._firstIndex);
|
|
1001
|
-
|
|
1007
|
+
let result = null;
|
|
1008
|
+
try {
|
|
1009
|
+
result = pattern.parse(cursor);
|
|
1010
|
+
}
|
|
1011
|
+
catch (error) {
|
|
1012
|
+
if (error.patternId === this._id) {
|
|
1013
|
+
continue;
|
|
1014
|
+
}
|
|
1015
|
+
else {
|
|
1016
|
+
cursor.endParse();
|
|
1017
|
+
throw error;
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1002
1020
|
if (this._isGreedy) {
|
|
1003
1021
|
results.push(result);
|
|
1004
1022
|
}
|
|
@@ -1994,8 +2012,8 @@
|
|
|
1994
2012
|
]);
|
|
1995
2013
|
|
|
1996
2014
|
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", "}");
|
|
2015
|
+
const openBracket$1 = new Literal("repeat-open-bracket", "{");
|
|
2016
|
+
const closeBracket$1 = new Literal("repeat-close-bracket", "}");
|
|
1999
2017
|
const comma = new Literal("comma", ",");
|
|
2000
2018
|
const integer = new Regex("integer", "([1-9][0-9]*)|0");
|
|
2001
2019
|
integer.setTokens(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]);
|
|
@@ -2032,15 +2050,15 @@
|
|
|
2032
2050
|
const dividerComma = new Regex("divider-comma", "\\s*,\\s*");
|
|
2033
2051
|
dividerComma.setTokens([", "]);
|
|
2034
2052
|
const patternName$2 = name$1.clone("pattern-name");
|
|
2035
|
-
const
|
|
2036
|
-
const
|
|
2037
|
-
const
|
|
2038
|
-
const
|
|
2053
|
+
const repeatPattern = new Options("repeat-pattern", [patternName$2, anonymousPattern]);
|
|
2054
|
+
const repeatDividerPattern = repeatPattern.clone("repeat-divider-pattern");
|
|
2055
|
+
const repeatDividerSection = new Sequence("repeat-divider-section", [dividerComma, repeatDividerPattern, trimFlag]);
|
|
2056
|
+
const repeatOptionalDividerSection = new Optional("repeat-optional-divider-section", repeatDividerSection);
|
|
2039
2057
|
const repeatLiteral = new Sequence("repeat-literal", [
|
|
2040
2058
|
openParen,
|
|
2041
2059
|
optionalSpaces$3,
|
|
2042
|
-
|
|
2043
|
-
|
|
2060
|
+
repeatPattern,
|
|
2061
|
+
repeatOptionalDividerSection,
|
|
2044
2062
|
optionalSpaces$3,
|
|
2045
2063
|
closeParen,
|
|
2046
2064
|
new Sequence("quantifier-section", [quantifier]),
|
|
@@ -2061,7 +2079,7 @@
|
|
|
2061
2079
|
|
|
2062
2080
|
const patternName = name$1.clone("pattern-name");
|
|
2063
2081
|
patternName.setTokens(["[PATTERN_NAME]"]);
|
|
2064
|
-
const patterns$1 = new Options("
|
|
2082
|
+
const patterns$1 = new Options("options-patterns", [patternName, anonymousPattern]);
|
|
2065
2083
|
const defaultDivider = new Regex("default-divider", "\\s*[|]\\s*");
|
|
2066
2084
|
defaultDivider.setTokens(["|"]);
|
|
2067
2085
|
const greedyDivider = new Regex("greedy-divider", "\\s*[<][|][>]\\s*");
|
|
@@ -2108,7 +2126,7 @@
|
|
|
2108
2126
|
const body = new Optional("optional-body", new Repeat("body", bodyLine, { divider: newLine$1 }));
|
|
2109
2127
|
|
|
2110
2128
|
const optionalSpaces$1 = new Optional("optional-spaces", allSpaces);
|
|
2111
|
-
const optionalLineSpaces$1 = new Optional("
|
|
2129
|
+
const optionalLineSpaces$1 = new Optional("optional-line-spaces", lineSpaces$1);
|
|
2112
2130
|
const importNameDivider = new Regex("import-name-divider", "(\\s+)?,(\\s+)?");
|
|
2113
2131
|
importNameDivider.setTokens([", "]);
|
|
2114
2132
|
const name = new Regex("import-name", "[^}\\s,]+");
|
|
@@ -2748,7 +2766,7 @@
|
|
|
2748
2766
|
const trimDivider = repeatNode.find(n => n.name === "trim-flag") != null;
|
|
2749
2767
|
const patterNode = repeatNode.children[1].type === "spaces" ? repeatNode.children[2] : repeatNode.children[1];
|
|
2750
2768
|
const pattern = this._buildPattern(patterNode);
|
|
2751
|
-
const dividerSectionNode = repeatNode.find(n => n.name === "divider-section");
|
|
2769
|
+
const dividerSectionNode = repeatNode.find(n => n.name === "repeat-divider-section");
|
|
2752
2770
|
const options = {
|
|
2753
2771
|
min: 1,
|
|
2754
2772
|
max: Infinity
|