clarity-pattern-parser 11.2.0 → 11.2.1
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/grammar/Grammar.d.ts +2 -0
- package/dist/grammar/patterns/takeUtilLiteral.d.ts +2 -0
- package/dist/index.browser.js +180 -23
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +180 -23
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +180 -23
- package/dist/index.js.map +1 -1
- package/dist/patterns/TakeUntil.d.ts +35 -0
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -550,7 +550,7 @@ function testPattern(pattern, text, record = false) {
|
|
|
550
550
|
return !result.cursor.hasError;
|
|
551
551
|
}
|
|
552
552
|
|
|
553
|
-
let idIndex$
|
|
553
|
+
let idIndex$a = 0;
|
|
554
554
|
class Literal {
|
|
555
555
|
get id() {
|
|
556
556
|
return this._id;
|
|
@@ -580,7 +580,7 @@ class Literal {
|
|
|
580
580
|
if (value.length === 0) {
|
|
581
581
|
throw new Error("Value Cannot be empty.");
|
|
582
582
|
}
|
|
583
|
-
this._id = `literal-${idIndex$
|
|
583
|
+
this._id = `literal-${idIndex$a++}`;
|
|
584
584
|
this._type = "literal";
|
|
585
585
|
this._name = name;
|
|
586
586
|
this._token = value;
|
|
@@ -671,7 +671,7 @@ class Literal {
|
|
|
671
671
|
}
|
|
672
672
|
}
|
|
673
673
|
|
|
674
|
-
let idIndex$
|
|
674
|
+
let idIndex$9 = 0;
|
|
675
675
|
class Regex {
|
|
676
676
|
get id() {
|
|
677
677
|
return this._id;
|
|
@@ -703,7 +703,7 @@ class Regex {
|
|
|
703
703
|
this._firstIndex = 0;
|
|
704
704
|
this._substring = "";
|
|
705
705
|
this._tokens = [];
|
|
706
|
-
this._id = `regex-${idIndex$
|
|
706
|
+
this._id = `regex-${idIndex$9++}`;
|
|
707
707
|
this._type = "regex";
|
|
708
708
|
this._name = name;
|
|
709
709
|
this._parent = null;
|
|
@@ -823,7 +823,7 @@ function findPattern(pattern, predicate) {
|
|
|
823
823
|
}
|
|
824
824
|
}
|
|
825
825
|
|
|
826
|
-
let idIndex$
|
|
826
|
+
let idIndex$8 = 0;
|
|
827
827
|
class Reference {
|
|
828
828
|
get id() {
|
|
829
829
|
return this._id;
|
|
@@ -847,7 +847,7 @@ class Reference {
|
|
|
847
847
|
return this._firstIndex;
|
|
848
848
|
}
|
|
849
849
|
constructor(name, referencePatternName) {
|
|
850
|
-
this._id = `reference-${idIndex$
|
|
850
|
+
this._id = `reference-${idIndex$8++}`;
|
|
851
851
|
this._type = "reference";
|
|
852
852
|
this._name = name;
|
|
853
853
|
this._referencePatternName = referencePatternName || name;
|
|
@@ -1024,7 +1024,7 @@ function isRecursivePattern(pattern) {
|
|
|
1024
1024
|
return false;
|
|
1025
1025
|
}
|
|
1026
1026
|
|
|
1027
|
-
let idIndex$
|
|
1027
|
+
let idIndex$7 = 0;
|
|
1028
1028
|
class Options {
|
|
1029
1029
|
get id() {
|
|
1030
1030
|
return this._id;
|
|
@@ -1053,7 +1053,7 @@ class Options {
|
|
|
1053
1053
|
}
|
|
1054
1054
|
const children = clonePatterns(options);
|
|
1055
1055
|
this._assignChildrenToParent(children);
|
|
1056
|
-
this._id = `options-${idIndex$
|
|
1056
|
+
this._id = `options-${idIndex$7++}`;
|
|
1057
1057
|
this._type = "options";
|
|
1058
1058
|
this._name = name;
|
|
1059
1059
|
this._parent = null;
|
|
@@ -1158,7 +1158,7 @@ class Options {
|
|
|
1158
1158
|
}
|
|
1159
1159
|
}
|
|
1160
1160
|
|
|
1161
|
-
let idIndex$
|
|
1161
|
+
let idIndex$6 = 0;
|
|
1162
1162
|
class FiniteRepeat {
|
|
1163
1163
|
get id() {
|
|
1164
1164
|
return this._id;
|
|
@@ -1188,7 +1188,7 @@ class FiniteRepeat {
|
|
|
1188
1188
|
return this._firstIndex;
|
|
1189
1189
|
}
|
|
1190
1190
|
constructor(name, pattern, options = {}) {
|
|
1191
|
-
this._id = `finite-repeat-${idIndex$
|
|
1191
|
+
this._id = `finite-repeat-${idIndex$6++}`;
|
|
1192
1192
|
this._type = "finite-repeat";
|
|
1193
1193
|
this._name = name;
|
|
1194
1194
|
this._parent = null;
|
|
@@ -1330,7 +1330,7 @@ class FiniteRepeat {
|
|
|
1330
1330
|
}
|
|
1331
1331
|
}
|
|
1332
1332
|
|
|
1333
|
-
let idIndex$
|
|
1333
|
+
let idIndex$5 = 0;
|
|
1334
1334
|
class InfiniteRepeat {
|
|
1335
1335
|
get id() {
|
|
1336
1336
|
return this._id;
|
|
@@ -1367,7 +1367,7 @@ class InfiniteRepeat {
|
|
|
1367
1367
|
children = [pattern.clone()];
|
|
1368
1368
|
}
|
|
1369
1369
|
this._assignChildrenToParent(children);
|
|
1370
|
-
this._id = `infinite-repeat-${idIndex$
|
|
1370
|
+
this._id = `infinite-repeat-${idIndex$5++}`;
|
|
1371
1371
|
this._type = "infinite-repeat";
|
|
1372
1372
|
this._name = name;
|
|
1373
1373
|
this._min = min;
|
|
@@ -1585,7 +1585,7 @@ class InfiniteRepeat {
|
|
|
1585
1585
|
}
|
|
1586
1586
|
}
|
|
1587
1587
|
|
|
1588
|
-
let idIndex$
|
|
1588
|
+
let idIndex$4 = 0;
|
|
1589
1589
|
class Repeat {
|
|
1590
1590
|
get id() {
|
|
1591
1591
|
return this._id;
|
|
@@ -1621,7 +1621,7 @@ class Repeat {
|
|
|
1621
1621
|
return this._options;
|
|
1622
1622
|
}
|
|
1623
1623
|
constructor(name, pattern, options = {}) {
|
|
1624
|
-
this._id = `repeat-${idIndex$
|
|
1624
|
+
this._id = `repeat-${idIndex$4++}`;
|
|
1625
1625
|
this._pattern = pattern;
|
|
1626
1626
|
this._parent = null;
|
|
1627
1627
|
this._options = Object.assign(Object.assign({}, options), { min: options.min == null ? 1 : options.min, max: options.max == null ? Infinity : options.max });
|
|
@@ -1700,7 +1700,7 @@ function filterOutNull(nodes) {
|
|
|
1700
1700
|
return filteredNodes;
|
|
1701
1701
|
}
|
|
1702
1702
|
|
|
1703
|
-
let idIndex$
|
|
1703
|
+
let idIndex$3 = 0;
|
|
1704
1704
|
class Sequence {
|
|
1705
1705
|
get id() {
|
|
1706
1706
|
return this._id;
|
|
@@ -1729,7 +1729,7 @@ class Sequence {
|
|
|
1729
1729
|
}
|
|
1730
1730
|
const children = clonePatterns(sequence);
|
|
1731
1731
|
this._assignChildrenToParent(children);
|
|
1732
|
-
this._id = `sequence-${idIndex$
|
|
1732
|
+
this._id = `sequence-${idIndex$3++}`;
|
|
1733
1733
|
this._type = "sequence";
|
|
1734
1734
|
this._name = name;
|
|
1735
1735
|
this._parent = null;
|
|
@@ -1965,12 +1965,13 @@ const anonymousLiterals = new Options("anonymous-literals", [
|
|
|
1965
1965
|
new Reference("repeat-literal"),
|
|
1966
1966
|
]);
|
|
1967
1967
|
const anonymousWrappedLiterals = new Options("anonymous-wrapped-literals", [
|
|
1968
|
+
new Reference("take-until-literal"),
|
|
1968
1969
|
new Reference("options-literal"),
|
|
1969
1970
|
new Reference("sequence-literal"),
|
|
1970
1971
|
new Reference("complex-anonymous-pattern")
|
|
1971
1972
|
]);
|
|
1972
1973
|
|
|
1973
|
-
let idIndex$
|
|
1974
|
+
let idIndex$2 = 0;
|
|
1974
1975
|
class Optional {
|
|
1975
1976
|
get id() {
|
|
1976
1977
|
return this._id;
|
|
@@ -1994,7 +1995,7 @@ class Optional {
|
|
|
1994
1995
|
return this._children[0].startedOnIndex;
|
|
1995
1996
|
}
|
|
1996
1997
|
constructor(name, pattern) {
|
|
1997
|
-
this._id = `optional-${idIndex$
|
|
1998
|
+
this._id = `optional-${idIndex$2++}`;
|
|
1998
1999
|
this._type = "optional";
|
|
1999
2000
|
this._name = name;
|
|
2000
2001
|
this._parent = null;
|
|
@@ -2066,12 +2067,12 @@ class Optional {
|
|
|
2066
2067
|
|
|
2067
2068
|
const inlinePatternOpenParen = new Literal("anonymous-pattern-open-paren", "(");
|
|
2068
2069
|
const inlinePatternCloseParen = new Literal("anonymous-pattern-close-paren", ")");
|
|
2069
|
-
const optionalLineSpaces$
|
|
2070
|
+
const optionalLineSpaces$4 = new Optional("optional-line-spaces", lineSpaces$1);
|
|
2070
2071
|
const complexAnonymousPattern = new Sequence("complex-anonymous-pattern", [
|
|
2071
2072
|
inlinePatternOpenParen,
|
|
2072
|
-
optionalLineSpaces$
|
|
2073
|
+
optionalLineSpaces$4,
|
|
2073
2074
|
anonymousWrappedLiterals,
|
|
2074
|
-
optionalLineSpaces$
|
|
2075
|
+
optionalLineSpaces$4,
|
|
2075
2076
|
inlinePatternCloseParen,
|
|
2076
2077
|
]);
|
|
2077
2078
|
const anonymousPattern = new Options("anonymous-pattern", [
|
|
@@ -2158,6 +2159,20 @@ greedyDivider.setTokens(["<|>"]);
|
|
|
2158
2159
|
const divider = new Options("options-divider", [defaultDivider, greedyDivider]);
|
|
2159
2160
|
const optionsLiteral = new Repeat("options-literal", patterns$1, { divider, min: 2, trimDivider: true });
|
|
2160
2161
|
|
|
2162
|
+
const anyChar = new Literal("any-char", "?");
|
|
2163
|
+
const upTo = new Literal("up-to", "->");
|
|
2164
|
+
const wall = new Literal("wall", "|");
|
|
2165
|
+
const optionalLineSpaces$3 = new Optional("optional-line-spaces", lineSpaces$1);
|
|
2166
|
+
const takeUntilLiteral = new Sequence("take-until-literal", [
|
|
2167
|
+
anyChar,
|
|
2168
|
+
optionalLineSpaces$3,
|
|
2169
|
+
upTo,
|
|
2170
|
+
optionalLineSpaces$3,
|
|
2171
|
+
wall,
|
|
2172
|
+
optionalLineSpaces$3,
|
|
2173
|
+
new Reference("pattern")
|
|
2174
|
+
]);
|
|
2175
|
+
|
|
2161
2176
|
const aliasLiteral = name$1.clone("alias-literal");
|
|
2162
2177
|
aliasLiteral.setTokens(["[ALIAS_LITERAL]"]);
|
|
2163
2178
|
const optionalIsOptional = new Optional("optional-flag", new Literal("is-optional", "?"));
|
|
@@ -2166,6 +2181,7 @@ const pattern = new Options("pattern", [
|
|
|
2166
2181
|
literal$1,
|
|
2167
2182
|
regexLiteral,
|
|
2168
2183
|
repeatLiteral,
|
|
2184
|
+
takeUntilLiteral,
|
|
2169
2185
|
aliasLiteral,
|
|
2170
2186
|
optionsLiteral,
|
|
2171
2187
|
sequenceLiteral,
|
|
@@ -2359,7 +2375,7 @@ const grammar = new Sequence("grammar", [
|
|
|
2359
2375
|
optionalSpaces
|
|
2360
2376
|
]);
|
|
2361
2377
|
|
|
2362
|
-
let idIndex = 0;
|
|
2378
|
+
let idIndex$1 = 0;
|
|
2363
2379
|
class Not {
|
|
2364
2380
|
get id() {
|
|
2365
2381
|
return this._id;
|
|
@@ -2383,7 +2399,7 @@ class Not {
|
|
|
2383
2399
|
return this.children[0].startedOnIndex;
|
|
2384
2400
|
}
|
|
2385
2401
|
constructor(name, pattern) {
|
|
2386
|
-
this._id = `not-${idIndex++}`;
|
|
2402
|
+
this._id = `not-${idIndex$1++}`;
|
|
2387
2403
|
this._type = "not";
|
|
2388
2404
|
this._name = name;
|
|
2389
2405
|
this._parent = null;
|
|
@@ -3152,6 +3168,126 @@ class Expression {
|
|
|
3152
3168
|
}
|
|
3153
3169
|
}
|
|
3154
3170
|
|
|
3171
|
+
let idIndex = 0;
|
|
3172
|
+
class TakeUntil {
|
|
3173
|
+
get id() {
|
|
3174
|
+
return this._id;
|
|
3175
|
+
}
|
|
3176
|
+
get type() {
|
|
3177
|
+
return this._type;
|
|
3178
|
+
}
|
|
3179
|
+
get name() {
|
|
3180
|
+
return this._name;
|
|
3181
|
+
}
|
|
3182
|
+
get children() {
|
|
3183
|
+
return this._children;
|
|
3184
|
+
}
|
|
3185
|
+
get parent() {
|
|
3186
|
+
return this._parent;
|
|
3187
|
+
}
|
|
3188
|
+
set parent(pattern) {
|
|
3189
|
+
this._parent = pattern;
|
|
3190
|
+
}
|
|
3191
|
+
get startedOnIndex() {
|
|
3192
|
+
return this._startedOnIndex;
|
|
3193
|
+
}
|
|
3194
|
+
constructor(name, terminatingPattern) {
|
|
3195
|
+
this._id = String(idIndex++);
|
|
3196
|
+
this._type = "take-until";
|
|
3197
|
+
this._name = name;
|
|
3198
|
+
this._parent = null;
|
|
3199
|
+
this._terminatingPattern = terminatingPattern;
|
|
3200
|
+
this._children = [this._terminatingPattern];
|
|
3201
|
+
this._tokens = [];
|
|
3202
|
+
this._startedOnIndex = 0;
|
|
3203
|
+
}
|
|
3204
|
+
parse(cursor) {
|
|
3205
|
+
let cursorIndex = cursor.index;
|
|
3206
|
+
let foundMatch = false;
|
|
3207
|
+
this._startedOnIndex = cursor.index;
|
|
3208
|
+
let terminatingResult = this._terminatingPattern.parse(cursor);
|
|
3209
|
+
if (terminatingResult == null) {
|
|
3210
|
+
foundMatch = true;
|
|
3211
|
+
cursor.moveTo(cursorIndex);
|
|
3212
|
+
cursorIndex += 1;
|
|
3213
|
+
cursor.hasNext() && cursor.next();
|
|
3214
|
+
cursor.resolveError();
|
|
3215
|
+
}
|
|
3216
|
+
while (true) {
|
|
3217
|
+
terminatingResult = this._terminatingPattern.parse(cursor);
|
|
3218
|
+
if (terminatingResult == null) {
|
|
3219
|
+
cursor.moveTo(cursorIndex);
|
|
3220
|
+
cursorIndex += 1;
|
|
3221
|
+
if (cursor.hasNext()) {
|
|
3222
|
+
cursor.next();
|
|
3223
|
+
}
|
|
3224
|
+
else {
|
|
3225
|
+
break;
|
|
3226
|
+
}
|
|
3227
|
+
cursor.resolveError();
|
|
3228
|
+
}
|
|
3229
|
+
else {
|
|
3230
|
+
break;
|
|
3231
|
+
}
|
|
3232
|
+
}
|
|
3233
|
+
if (foundMatch) {
|
|
3234
|
+
cursor.moveTo(cursorIndex - 1);
|
|
3235
|
+
const value = cursor.getChars(this.startedOnIndex, cursorIndex - 1);
|
|
3236
|
+
return Node.createValueNode(this._type, this._name, value);
|
|
3237
|
+
}
|
|
3238
|
+
else {
|
|
3239
|
+
cursor.resolveError();
|
|
3240
|
+
cursor.moveTo(this.startedOnIndex);
|
|
3241
|
+
cursor.recordErrorAt(this._startedOnIndex, this._startedOnIndex, this);
|
|
3242
|
+
return null;
|
|
3243
|
+
}
|
|
3244
|
+
}
|
|
3245
|
+
exec(text, record) {
|
|
3246
|
+
return execPattern(this, text, record);
|
|
3247
|
+
}
|
|
3248
|
+
test(text, record) {
|
|
3249
|
+
return testPattern(this, text, record);
|
|
3250
|
+
}
|
|
3251
|
+
clone(name = this.name) {
|
|
3252
|
+
const clone = new TakeUntil(name, this._terminatingPattern);
|
|
3253
|
+
clone._id = this._id;
|
|
3254
|
+
return clone;
|
|
3255
|
+
}
|
|
3256
|
+
getTokens() {
|
|
3257
|
+
return this._tokens;
|
|
3258
|
+
}
|
|
3259
|
+
getTokensAfter(_childReference) {
|
|
3260
|
+
return [];
|
|
3261
|
+
}
|
|
3262
|
+
getNextTokens() {
|
|
3263
|
+
if (this.parent == null) {
|
|
3264
|
+
return [];
|
|
3265
|
+
}
|
|
3266
|
+
return this.parent.getTokensAfter(this);
|
|
3267
|
+
}
|
|
3268
|
+
getPatterns() {
|
|
3269
|
+
return [this];
|
|
3270
|
+
}
|
|
3271
|
+
getPatternsAfter(_childReference) {
|
|
3272
|
+
return [];
|
|
3273
|
+
}
|
|
3274
|
+
getNextPatterns() {
|
|
3275
|
+
if (this.parent == null) {
|
|
3276
|
+
return [];
|
|
3277
|
+
}
|
|
3278
|
+
return this.parent.getPatternsAfter(this);
|
|
3279
|
+
}
|
|
3280
|
+
find(_predicate) {
|
|
3281
|
+
return null;
|
|
3282
|
+
}
|
|
3283
|
+
setTokens(tokens) {
|
|
3284
|
+
this._tokens = tokens;
|
|
3285
|
+
}
|
|
3286
|
+
isEqual(pattern) {
|
|
3287
|
+
return pattern.type === this.type && this.children.every((c, index) => c.isEqual(pattern.children[index]));
|
|
3288
|
+
}
|
|
3289
|
+
}
|
|
3290
|
+
|
|
3155
3291
|
let indexId = 0;
|
|
3156
3292
|
class RightAssociated {
|
|
3157
3293
|
get id() {
|
|
@@ -3282,6 +3418,7 @@ const patternNodes = {
|
|
|
3282
3418
|
"sequence-literal": true,
|
|
3283
3419
|
"repeat-literal": true,
|
|
3284
3420
|
"alias-literal": true,
|
|
3421
|
+
"take-until-literal": true,
|
|
3285
3422
|
"configurable-anonymous-pattern": true
|
|
3286
3423
|
};
|
|
3287
3424
|
class ParseContext {
|
|
@@ -3392,6 +3529,10 @@ class Grammar {
|
|
|
3392
3529
|
this._saveAlias(n);
|
|
3393
3530
|
break;
|
|
3394
3531
|
}
|
|
3532
|
+
case "take-until-literal": {
|
|
3533
|
+
this._saveTakeUntil(n);
|
|
3534
|
+
break;
|
|
3535
|
+
}
|
|
3395
3536
|
case "configurable-anonymous-pattern": {
|
|
3396
3537
|
this._saveConfigurableAnonymous(n);
|
|
3397
3538
|
break;
|
|
@@ -3511,6 +3652,9 @@ class Grammar {
|
|
|
3511
3652
|
case "sequence-literal": {
|
|
3512
3653
|
return this._buildSequence(name, node);
|
|
3513
3654
|
}
|
|
3655
|
+
case "take-until-literal": {
|
|
3656
|
+
return this._buildTakeUntil(name, node);
|
|
3657
|
+
}
|
|
3514
3658
|
case "complex-anonymous-pattern": {
|
|
3515
3659
|
return this._buildComplexAnonymousPattern(node);
|
|
3516
3660
|
}
|
|
@@ -3594,6 +3738,19 @@ class Grammar {
|
|
|
3594
3738
|
}
|
|
3595
3739
|
return isOptional ? new Optional(name, new Repeat(`inner-optional-${name}`, pattern, options)) : new Repeat(name, pattern, options);
|
|
3596
3740
|
}
|
|
3741
|
+
_saveTakeUntil(statementNode) {
|
|
3742
|
+
const nameNode = statementNode.find(n => n.name === "name");
|
|
3743
|
+
const name = nameNode.value;
|
|
3744
|
+
const takeUntilNode = statementNode.find(n => n.name === "take-until-literal");
|
|
3745
|
+
const takeUntil = this._buildTakeUntil(name, takeUntilNode);
|
|
3746
|
+
this._applyDecorators(statementNode, takeUntil);
|
|
3747
|
+
this._parseContext.patternsByName.set(name, takeUntil);
|
|
3748
|
+
}
|
|
3749
|
+
_buildTakeUntil(name, takeUntilNode) {
|
|
3750
|
+
const patternNode = takeUntilNode.children[takeUntilNode.children.length - 1];
|
|
3751
|
+
const untilPattern = this._buildPattern(patternNode);
|
|
3752
|
+
return new TakeUntil(name, untilPattern);
|
|
3753
|
+
}
|
|
3597
3754
|
_saveConfigurableAnonymous(node) {
|
|
3598
3755
|
const nameNode = node.find(n => n.name === "name");
|
|
3599
3756
|
const name = nameNode.value;
|