clarity-pattern-parser 11.2.0 → 11.2.2
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 +179 -23
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +179 -23
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +179 -23
- package/dist/index.js.map +1 -1
- package/dist/patterns/TakeUntil.d.ts +35 -0
- package/package.json +1 -1
- package/src/patterns/TakeUntil.ts +2 -5
|
@@ -37,6 +37,8 @@ export declare class Grammar {
|
|
|
37
37
|
private _buildSequence;
|
|
38
38
|
private _saveRepeat;
|
|
39
39
|
private _buildRepeat;
|
|
40
|
+
private _saveTakeUntil;
|
|
41
|
+
private _buildTakeUntil;
|
|
40
42
|
private _saveConfigurableAnonymous;
|
|
41
43
|
private _buildComplexAnonymousPattern;
|
|
42
44
|
private _resolveImports;
|
package/dist/index.browser.js
CHANGED
|
@@ -556,7 +556,7 @@
|
|
|
556
556
|
return !result.cursor.hasError;
|
|
557
557
|
}
|
|
558
558
|
|
|
559
|
-
let idIndex$
|
|
559
|
+
let idIndex$a = 0;
|
|
560
560
|
class Literal {
|
|
561
561
|
get id() {
|
|
562
562
|
return this._id;
|
|
@@ -586,7 +586,7 @@
|
|
|
586
586
|
if (value.length === 0) {
|
|
587
587
|
throw new Error("Value Cannot be empty.");
|
|
588
588
|
}
|
|
589
|
-
this._id = `literal-${idIndex$
|
|
589
|
+
this._id = `literal-${idIndex$a++}`;
|
|
590
590
|
this._type = "literal";
|
|
591
591
|
this._name = name;
|
|
592
592
|
this._token = value;
|
|
@@ -677,7 +677,7 @@
|
|
|
677
677
|
}
|
|
678
678
|
}
|
|
679
679
|
|
|
680
|
-
let idIndex$
|
|
680
|
+
let idIndex$9 = 0;
|
|
681
681
|
class Regex {
|
|
682
682
|
get id() {
|
|
683
683
|
return this._id;
|
|
@@ -709,7 +709,7 @@
|
|
|
709
709
|
this._firstIndex = 0;
|
|
710
710
|
this._substring = "";
|
|
711
711
|
this._tokens = [];
|
|
712
|
-
this._id = `regex-${idIndex$
|
|
712
|
+
this._id = `regex-${idIndex$9++}`;
|
|
713
713
|
this._type = "regex";
|
|
714
714
|
this._name = name;
|
|
715
715
|
this._parent = null;
|
|
@@ -829,7 +829,7 @@
|
|
|
829
829
|
}
|
|
830
830
|
}
|
|
831
831
|
|
|
832
|
-
let idIndex$
|
|
832
|
+
let idIndex$8 = 0;
|
|
833
833
|
class Reference {
|
|
834
834
|
get id() {
|
|
835
835
|
return this._id;
|
|
@@ -853,7 +853,7 @@
|
|
|
853
853
|
return this._firstIndex;
|
|
854
854
|
}
|
|
855
855
|
constructor(name, referencePatternName) {
|
|
856
|
-
this._id = `reference-${idIndex$
|
|
856
|
+
this._id = `reference-${idIndex$8++}`;
|
|
857
857
|
this._type = "reference";
|
|
858
858
|
this._name = name;
|
|
859
859
|
this._referencePatternName = referencePatternName || name;
|
|
@@ -1030,7 +1030,7 @@
|
|
|
1030
1030
|
return false;
|
|
1031
1031
|
}
|
|
1032
1032
|
|
|
1033
|
-
let idIndex$
|
|
1033
|
+
let idIndex$7 = 0;
|
|
1034
1034
|
class Options {
|
|
1035
1035
|
get id() {
|
|
1036
1036
|
return this._id;
|
|
@@ -1059,7 +1059,7 @@
|
|
|
1059
1059
|
}
|
|
1060
1060
|
const children = clonePatterns(options);
|
|
1061
1061
|
this._assignChildrenToParent(children);
|
|
1062
|
-
this._id = `options-${idIndex$
|
|
1062
|
+
this._id = `options-${idIndex$7++}`;
|
|
1063
1063
|
this._type = "options";
|
|
1064
1064
|
this._name = name;
|
|
1065
1065
|
this._parent = null;
|
|
@@ -1164,7 +1164,7 @@
|
|
|
1164
1164
|
}
|
|
1165
1165
|
}
|
|
1166
1166
|
|
|
1167
|
-
let idIndex$
|
|
1167
|
+
let idIndex$6 = 0;
|
|
1168
1168
|
class FiniteRepeat {
|
|
1169
1169
|
get id() {
|
|
1170
1170
|
return this._id;
|
|
@@ -1194,7 +1194,7 @@
|
|
|
1194
1194
|
return this._firstIndex;
|
|
1195
1195
|
}
|
|
1196
1196
|
constructor(name, pattern, options = {}) {
|
|
1197
|
-
this._id = `finite-repeat-${idIndex$
|
|
1197
|
+
this._id = `finite-repeat-${idIndex$6++}`;
|
|
1198
1198
|
this._type = "finite-repeat";
|
|
1199
1199
|
this._name = name;
|
|
1200
1200
|
this._parent = null;
|
|
@@ -1336,7 +1336,7 @@
|
|
|
1336
1336
|
}
|
|
1337
1337
|
}
|
|
1338
1338
|
|
|
1339
|
-
let idIndex$
|
|
1339
|
+
let idIndex$5 = 0;
|
|
1340
1340
|
class InfiniteRepeat {
|
|
1341
1341
|
get id() {
|
|
1342
1342
|
return this._id;
|
|
@@ -1373,7 +1373,7 @@
|
|
|
1373
1373
|
children = [pattern.clone()];
|
|
1374
1374
|
}
|
|
1375
1375
|
this._assignChildrenToParent(children);
|
|
1376
|
-
this._id = `infinite-repeat-${idIndex$
|
|
1376
|
+
this._id = `infinite-repeat-${idIndex$5++}`;
|
|
1377
1377
|
this._type = "infinite-repeat";
|
|
1378
1378
|
this._name = name;
|
|
1379
1379
|
this._min = min;
|
|
@@ -1591,7 +1591,7 @@
|
|
|
1591
1591
|
}
|
|
1592
1592
|
}
|
|
1593
1593
|
|
|
1594
|
-
let idIndex$
|
|
1594
|
+
let idIndex$4 = 0;
|
|
1595
1595
|
class Repeat {
|
|
1596
1596
|
get id() {
|
|
1597
1597
|
return this._id;
|
|
@@ -1627,7 +1627,7 @@
|
|
|
1627
1627
|
return this._options;
|
|
1628
1628
|
}
|
|
1629
1629
|
constructor(name, pattern, options = {}) {
|
|
1630
|
-
this._id = `repeat-${idIndex$
|
|
1630
|
+
this._id = `repeat-${idIndex$4++}`;
|
|
1631
1631
|
this._pattern = pattern;
|
|
1632
1632
|
this._parent = null;
|
|
1633
1633
|
this._options = Object.assign(Object.assign({}, options), { min: options.min == null ? 1 : options.min, max: options.max == null ? Infinity : options.max });
|
|
@@ -1706,7 +1706,7 @@
|
|
|
1706
1706
|
return filteredNodes;
|
|
1707
1707
|
}
|
|
1708
1708
|
|
|
1709
|
-
let idIndex$
|
|
1709
|
+
let idIndex$3 = 0;
|
|
1710
1710
|
class Sequence {
|
|
1711
1711
|
get id() {
|
|
1712
1712
|
return this._id;
|
|
@@ -1735,7 +1735,7 @@
|
|
|
1735
1735
|
}
|
|
1736
1736
|
const children = clonePatterns(sequence);
|
|
1737
1737
|
this._assignChildrenToParent(children);
|
|
1738
|
-
this._id = `sequence-${idIndex$
|
|
1738
|
+
this._id = `sequence-${idIndex$3++}`;
|
|
1739
1739
|
this._type = "sequence";
|
|
1740
1740
|
this._name = name;
|
|
1741
1741
|
this._parent = null;
|
|
@@ -1971,12 +1971,13 @@
|
|
|
1971
1971
|
new Reference("repeat-literal"),
|
|
1972
1972
|
]);
|
|
1973
1973
|
const anonymousWrappedLiterals = new Options("anonymous-wrapped-literals", [
|
|
1974
|
+
new Reference("take-until-literal"),
|
|
1974
1975
|
new Reference("options-literal"),
|
|
1975
1976
|
new Reference("sequence-literal"),
|
|
1976
1977
|
new Reference("complex-anonymous-pattern")
|
|
1977
1978
|
]);
|
|
1978
1979
|
|
|
1979
|
-
let idIndex$
|
|
1980
|
+
let idIndex$2 = 0;
|
|
1980
1981
|
class Optional {
|
|
1981
1982
|
get id() {
|
|
1982
1983
|
return this._id;
|
|
@@ -2000,7 +2001,7 @@
|
|
|
2000
2001
|
return this._children[0].startedOnIndex;
|
|
2001
2002
|
}
|
|
2002
2003
|
constructor(name, pattern) {
|
|
2003
|
-
this._id = `optional-${idIndex$
|
|
2004
|
+
this._id = `optional-${idIndex$2++}`;
|
|
2004
2005
|
this._type = "optional";
|
|
2005
2006
|
this._name = name;
|
|
2006
2007
|
this._parent = null;
|
|
@@ -2072,12 +2073,12 @@
|
|
|
2072
2073
|
|
|
2073
2074
|
const inlinePatternOpenParen = new Literal("anonymous-pattern-open-paren", "(");
|
|
2074
2075
|
const inlinePatternCloseParen = new Literal("anonymous-pattern-close-paren", ")");
|
|
2075
|
-
const optionalLineSpaces$
|
|
2076
|
+
const optionalLineSpaces$4 = new Optional("optional-line-spaces", lineSpaces$1);
|
|
2076
2077
|
const complexAnonymousPattern = new Sequence("complex-anonymous-pattern", [
|
|
2077
2078
|
inlinePatternOpenParen,
|
|
2078
|
-
optionalLineSpaces$
|
|
2079
|
+
optionalLineSpaces$4,
|
|
2079
2080
|
anonymousWrappedLiterals,
|
|
2080
|
-
optionalLineSpaces$
|
|
2081
|
+
optionalLineSpaces$4,
|
|
2081
2082
|
inlinePatternCloseParen,
|
|
2082
2083
|
]);
|
|
2083
2084
|
const anonymousPattern = new Options("anonymous-pattern", [
|
|
@@ -2164,6 +2165,20 @@
|
|
|
2164
2165
|
const divider = new Options("options-divider", [defaultDivider, greedyDivider]);
|
|
2165
2166
|
const optionsLiteral = new Repeat("options-literal", patterns$1, { divider, min: 2, trimDivider: true });
|
|
2166
2167
|
|
|
2168
|
+
const anyChar = new Literal("any-char", "?");
|
|
2169
|
+
const upTo = new Literal("up-to", "->");
|
|
2170
|
+
const wall = new Literal("wall", "|");
|
|
2171
|
+
const optionalLineSpaces$3 = new Optional("optional-line-spaces", lineSpaces$1);
|
|
2172
|
+
const takeUntilLiteral = new Sequence("take-until-literal", [
|
|
2173
|
+
anyChar,
|
|
2174
|
+
optionalLineSpaces$3,
|
|
2175
|
+
upTo,
|
|
2176
|
+
optionalLineSpaces$3,
|
|
2177
|
+
wall,
|
|
2178
|
+
optionalLineSpaces$3,
|
|
2179
|
+
new Reference("pattern")
|
|
2180
|
+
]);
|
|
2181
|
+
|
|
2167
2182
|
const aliasLiteral = name$1.clone("alias-literal");
|
|
2168
2183
|
aliasLiteral.setTokens(["[ALIAS_LITERAL]"]);
|
|
2169
2184
|
const optionalIsOptional = new Optional("optional-flag", new Literal("is-optional", "?"));
|
|
@@ -2172,6 +2187,7 @@
|
|
|
2172
2187
|
literal$1,
|
|
2173
2188
|
regexLiteral,
|
|
2174
2189
|
repeatLiteral,
|
|
2190
|
+
takeUntilLiteral,
|
|
2175
2191
|
aliasLiteral,
|
|
2176
2192
|
optionsLiteral,
|
|
2177
2193
|
sequenceLiteral,
|
|
@@ -2365,7 +2381,7 @@
|
|
|
2365
2381
|
optionalSpaces
|
|
2366
2382
|
]);
|
|
2367
2383
|
|
|
2368
|
-
let idIndex = 0;
|
|
2384
|
+
let idIndex$1 = 0;
|
|
2369
2385
|
class Not {
|
|
2370
2386
|
get id() {
|
|
2371
2387
|
return this._id;
|
|
@@ -2389,7 +2405,7 @@
|
|
|
2389
2405
|
return this.children[0].startedOnIndex;
|
|
2390
2406
|
}
|
|
2391
2407
|
constructor(name, pattern) {
|
|
2392
|
-
this._id = `not-${idIndex++}`;
|
|
2408
|
+
this._id = `not-${idIndex$1++}`;
|
|
2393
2409
|
this._type = "not";
|
|
2394
2410
|
this._name = name;
|
|
2395
2411
|
this._parent = null;
|
|
@@ -3158,6 +3174,125 @@
|
|
|
3158
3174
|
}
|
|
3159
3175
|
}
|
|
3160
3176
|
|
|
3177
|
+
let idIndex = 0;
|
|
3178
|
+
class TakeUntil {
|
|
3179
|
+
get id() {
|
|
3180
|
+
return this._id;
|
|
3181
|
+
}
|
|
3182
|
+
get type() {
|
|
3183
|
+
return this._type;
|
|
3184
|
+
}
|
|
3185
|
+
get name() {
|
|
3186
|
+
return this._name;
|
|
3187
|
+
}
|
|
3188
|
+
get children() {
|
|
3189
|
+
return this._children;
|
|
3190
|
+
}
|
|
3191
|
+
get parent() {
|
|
3192
|
+
return this._parent;
|
|
3193
|
+
}
|
|
3194
|
+
set parent(pattern) {
|
|
3195
|
+
this._parent = pattern;
|
|
3196
|
+
}
|
|
3197
|
+
get startedOnIndex() {
|
|
3198
|
+
return this._startedOnIndex;
|
|
3199
|
+
}
|
|
3200
|
+
constructor(name, terminatingPattern) {
|
|
3201
|
+
this._id = String(idIndex++);
|
|
3202
|
+
this._type = "take-until";
|
|
3203
|
+
this._name = name;
|
|
3204
|
+
this._parent = null;
|
|
3205
|
+
this._terminatingPattern = terminatingPattern;
|
|
3206
|
+
this._children = [this._terminatingPattern];
|
|
3207
|
+
this._tokens = [];
|
|
3208
|
+
this._startedOnIndex = 0;
|
|
3209
|
+
}
|
|
3210
|
+
parse(cursor) {
|
|
3211
|
+
let cursorIndex = cursor.index;
|
|
3212
|
+
let foundMatch = false;
|
|
3213
|
+
this._startedOnIndex = cursor.index;
|
|
3214
|
+
let terminatingResult = this._terminatingPattern.parse(cursor);
|
|
3215
|
+
cursor.resolveError();
|
|
3216
|
+
if (terminatingResult == null) {
|
|
3217
|
+
foundMatch = true;
|
|
3218
|
+
cursor.moveTo(cursorIndex);
|
|
3219
|
+
cursorIndex += 1;
|
|
3220
|
+
cursor.hasNext() && cursor.next();
|
|
3221
|
+
}
|
|
3222
|
+
while (true) {
|
|
3223
|
+
terminatingResult = this._terminatingPattern.parse(cursor);
|
|
3224
|
+
cursor.resolveError();
|
|
3225
|
+
if (terminatingResult == null) {
|
|
3226
|
+
cursor.moveTo(cursorIndex);
|
|
3227
|
+
cursorIndex += 1;
|
|
3228
|
+
if (cursor.hasNext()) {
|
|
3229
|
+
cursor.next();
|
|
3230
|
+
}
|
|
3231
|
+
else {
|
|
3232
|
+
break;
|
|
3233
|
+
}
|
|
3234
|
+
}
|
|
3235
|
+
else {
|
|
3236
|
+
break;
|
|
3237
|
+
}
|
|
3238
|
+
}
|
|
3239
|
+
if (foundMatch) {
|
|
3240
|
+
cursor.moveTo(cursorIndex - 1);
|
|
3241
|
+
const value = cursor.getChars(this.startedOnIndex, cursorIndex - 1);
|
|
3242
|
+
return Node.createValueNode(this._type, this._name, value);
|
|
3243
|
+
}
|
|
3244
|
+
else {
|
|
3245
|
+
cursor.moveTo(this.startedOnIndex);
|
|
3246
|
+
cursor.recordErrorAt(this._startedOnIndex, this._startedOnIndex, this);
|
|
3247
|
+
return null;
|
|
3248
|
+
}
|
|
3249
|
+
}
|
|
3250
|
+
exec(text, record) {
|
|
3251
|
+
return execPattern(this, text, record);
|
|
3252
|
+
}
|
|
3253
|
+
test(text, record) {
|
|
3254
|
+
return testPattern(this, text, record);
|
|
3255
|
+
}
|
|
3256
|
+
clone(name = this.name) {
|
|
3257
|
+
const clone = new TakeUntil(name, this._terminatingPattern);
|
|
3258
|
+
clone._id = this._id;
|
|
3259
|
+
return clone;
|
|
3260
|
+
}
|
|
3261
|
+
getTokens() {
|
|
3262
|
+
return this._tokens;
|
|
3263
|
+
}
|
|
3264
|
+
getTokensAfter(_childReference) {
|
|
3265
|
+
return [];
|
|
3266
|
+
}
|
|
3267
|
+
getNextTokens() {
|
|
3268
|
+
if (this.parent == null) {
|
|
3269
|
+
return [];
|
|
3270
|
+
}
|
|
3271
|
+
return this.parent.getTokensAfter(this);
|
|
3272
|
+
}
|
|
3273
|
+
getPatterns() {
|
|
3274
|
+
return [this];
|
|
3275
|
+
}
|
|
3276
|
+
getPatternsAfter(_childReference) {
|
|
3277
|
+
return [];
|
|
3278
|
+
}
|
|
3279
|
+
getNextPatterns() {
|
|
3280
|
+
if (this.parent == null) {
|
|
3281
|
+
return [];
|
|
3282
|
+
}
|
|
3283
|
+
return this.parent.getPatternsAfter(this);
|
|
3284
|
+
}
|
|
3285
|
+
find(_predicate) {
|
|
3286
|
+
return null;
|
|
3287
|
+
}
|
|
3288
|
+
setTokens(tokens) {
|
|
3289
|
+
this._tokens = tokens;
|
|
3290
|
+
}
|
|
3291
|
+
isEqual(pattern) {
|
|
3292
|
+
return pattern.type === this.type && this.children.every((c, index) => c.isEqual(pattern.children[index]));
|
|
3293
|
+
}
|
|
3294
|
+
}
|
|
3295
|
+
|
|
3161
3296
|
let indexId = 0;
|
|
3162
3297
|
class RightAssociated {
|
|
3163
3298
|
get id() {
|
|
@@ -3288,6 +3423,7 @@
|
|
|
3288
3423
|
"sequence-literal": true,
|
|
3289
3424
|
"repeat-literal": true,
|
|
3290
3425
|
"alias-literal": true,
|
|
3426
|
+
"take-until-literal": true,
|
|
3291
3427
|
"configurable-anonymous-pattern": true
|
|
3292
3428
|
};
|
|
3293
3429
|
class ParseContext {
|
|
@@ -3398,6 +3534,10 @@
|
|
|
3398
3534
|
this._saveAlias(n);
|
|
3399
3535
|
break;
|
|
3400
3536
|
}
|
|
3537
|
+
case "take-until-literal": {
|
|
3538
|
+
this._saveTakeUntil(n);
|
|
3539
|
+
break;
|
|
3540
|
+
}
|
|
3401
3541
|
case "configurable-anonymous-pattern": {
|
|
3402
3542
|
this._saveConfigurableAnonymous(n);
|
|
3403
3543
|
break;
|
|
@@ -3517,6 +3657,9 @@
|
|
|
3517
3657
|
case "sequence-literal": {
|
|
3518
3658
|
return this._buildSequence(name, node);
|
|
3519
3659
|
}
|
|
3660
|
+
case "take-until-literal": {
|
|
3661
|
+
return this._buildTakeUntil(name, node);
|
|
3662
|
+
}
|
|
3520
3663
|
case "complex-anonymous-pattern": {
|
|
3521
3664
|
return this._buildComplexAnonymousPattern(node);
|
|
3522
3665
|
}
|
|
@@ -3600,6 +3743,19 @@
|
|
|
3600
3743
|
}
|
|
3601
3744
|
return isOptional ? new Optional(name, new Repeat(`inner-optional-${name}`, pattern, options)) : new Repeat(name, pattern, options);
|
|
3602
3745
|
}
|
|
3746
|
+
_saveTakeUntil(statementNode) {
|
|
3747
|
+
const nameNode = statementNode.find(n => n.name === "name");
|
|
3748
|
+
const name = nameNode.value;
|
|
3749
|
+
const takeUntilNode = statementNode.find(n => n.name === "take-until-literal");
|
|
3750
|
+
const takeUntil = this._buildTakeUntil(name, takeUntilNode);
|
|
3751
|
+
this._applyDecorators(statementNode, takeUntil);
|
|
3752
|
+
this._parseContext.patternsByName.set(name, takeUntil);
|
|
3753
|
+
}
|
|
3754
|
+
_buildTakeUntil(name, takeUntilNode) {
|
|
3755
|
+
const patternNode = takeUntilNode.children[takeUntilNode.children.length - 1];
|
|
3756
|
+
const untilPattern = this._buildPattern(patternNode);
|
|
3757
|
+
return new TakeUntil(name, untilPattern);
|
|
3758
|
+
}
|
|
3603
3759
|
_saveConfigurableAnonymous(node) {
|
|
3604
3760
|
const nameNode = node.find(n => n.name === "name");
|
|
3605
3761
|
const name = nameNode.value;
|