clarity-pattern-parser 11.2.2 → 11.3.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/TODO.md +1 -3
- package/dist/ast/Node.d.ts +3 -0
- package/dist/index.browser.js +35 -19
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +35 -19
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +35 -19
- package/dist/index.js.map +1 -1
- package/dist/patterns/Cursor.d.ts +2 -2
- package/dist/patterns/CursorHistory.d.ts +2 -6
- package/dist/patterns/HistoryRecord.d.ts +8 -0
- package/package.json +1 -1
- package/src/ast/Node.test.ts +5 -2
- package/src/ast/Node.ts +20 -3
- package/src/generator/generator.test.ts +6 -3
- package/src/grammar/patterns/takeUtilLiteral.ts +0 -1
- package/src/patterns/Cursor.ts +2 -2
- package/src/patterns/CursorHistory.ts +19 -20
- package/src/patterns/FiniteRepeat.test.ts +12 -12
- package/src/patterns/HistoryRecord.ts +9 -0
- package/src/patterns/InfiniteRepeat.test.ts +6 -6
- package/src/patterns/Literal.test.ts +3 -3
- package/src/patterns/Not.test.ts +1 -1
- package/src/patterns/Options.test.ts +3 -3
- package/src/patterns/PrecedenceTree.test.ts +9 -9
- package/src/patterns/Reference.test.ts +1 -1
- package/src/patterns/Reference.ts +1 -1
- package/src/patterns/Regex.test.ts +1 -1
- package/src/patterns/Repeat.test.ts +8 -8
- package/src/patterns/Sequence.test.ts +6 -6
- package/src/patterns/TakeUntil.ts +5 -2
package/dist/index.esm.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
function defaultVisitor(node) {
|
|
2
2
|
return node;
|
|
3
3
|
}
|
|
4
|
+
let idIndex$b = 0;
|
|
4
5
|
class Node {
|
|
6
|
+
get id() {
|
|
7
|
+
return this._id;
|
|
8
|
+
}
|
|
5
9
|
get type() {
|
|
6
10
|
return this._type;
|
|
7
11
|
}
|
|
@@ -36,6 +40,7 @@ class Node {
|
|
|
36
40
|
return !this.hasChildren;
|
|
37
41
|
}
|
|
38
42
|
constructor(type, name, firstIndex, lastIndex, children = [], value = "") {
|
|
43
|
+
this._id = String(idIndex$b++);
|
|
39
44
|
this._type = type;
|
|
40
45
|
this._name = name;
|
|
41
46
|
this._firstIndex = firstIndex;
|
|
@@ -196,7 +201,8 @@ class Node {
|
|
|
196
201
|
}
|
|
197
202
|
}
|
|
198
203
|
clone() {
|
|
199
|
-
|
|
204
|
+
const node = new Node(this._type, this._name, this._firstIndex, this._lastIndex, this._children.map((c) => c.clone()), this._value);
|
|
205
|
+
return node;
|
|
200
206
|
}
|
|
201
207
|
normalize(startIndex = this._firstIndex) {
|
|
202
208
|
let length = 0;
|
|
@@ -224,6 +230,7 @@ class Node {
|
|
|
224
230
|
}
|
|
225
231
|
toCycleFreeObject() {
|
|
226
232
|
return {
|
|
233
|
+
id: this._id,
|
|
227
234
|
type: this._type,
|
|
228
235
|
name: this._name,
|
|
229
236
|
value: this.toString(),
|
|
@@ -236,7 +243,12 @@ class Node {
|
|
|
236
243
|
return JSON.stringify(this.toCycleFreeObject(), null, space);
|
|
237
244
|
}
|
|
238
245
|
isEqual(node) {
|
|
239
|
-
return node.
|
|
246
|
+
return node._type === this._type &&
|
|
247
|
+
node._name === this._name &&
|
|
248
|
+
node._firstIndex === this._firstIndex &&
|
|
249
|
+
node._lastIndex === this._lastIndex &&
|
|
250
|
+
node._value === this._value &&
|
|
251
|
+
this._children.every((child, index) => child.isEqual(node._children[index]));
|
|
240
252
|
}
|
|
241
253
|
static createValueNode(type, name, value = "") {
|
|
242
254
|
return new Node(type, name, 0, 0, [], value);
|
|
@@ -348,14 +360,15 @@ class CursorHistory {
|
|
|
348
360
|
return this._patterns;
|
|
349
361
|
}
|
|
350
362
|
recordMatch(pattern, node) {
|
|
363
|
+
const record = {
|
|
364
|
+
pattern,
|
|
365
|
+
ast: node,
|
|
366
|
+
error: null
|
|
367
|
+
};
|
|
351
368
|
if (this._isRecording) {
|
|
352
369
|
this._patterns.push(pattern);
|
|
353
370
|
this._nodes.push(node);
|
|
354
|
-
this._records.push(
|
|
355
|
-
pattern,
|
|
356
|
-
ast: node,
|
|
357
|
-
error: null
|
|
358
|
-
});
|
|
371
|
+
this._records.push(record);
|
|
359
372
|
}
|
|
360
373
|
this._rootMatch.pattern = pattern;
|
|
361
374
|
this._rootMatch.node = node;
|
|
@@ -389,28 +402,29 @@ class CursorHistory {
|
|
|
389
402
|
}
|
|
390
403
|
recordErrorAt(startIndex, lastIndex, pattern) {
|
|
391
404
|
const error = new ParseError(startIndex, lastIndex, pattern);
|
|
405
|
+
const record = {
|
|
406
|
+
pattern,
|
|
407
|
+
ast: null,
|
|
408
|
+
error
|
|
409
|
+
};
|
|
392
410
|
this._currentError = error;
|
|
393
411
|
if (this._furthestError === null || lastIndex > this._furthestError.lastIndex) {
|
|
394
412
|
this._furthestError = error;
|
|
395
413
|
}
|
|
396
414
|
if (this._isRecording) {
|
|
397
415
|
this._errors.push(error);
|
|
398
|
-
this.records.push(
|
|
399
|
-
pattern,
|
|
400
|
-
ast: null,
|
|
401
|
-
error
|
|
402
|
-
});
|
|
416
|
+
this.records.push(record);
|
|
403
417
|
}
|
|
404
418
|
}
|
|
419
|
+
resolveError() {
|
|
420
|
+
this._currentError = null;
|
|
421
|
+
}
|
|
405
422
|
startRecording() {
|
|
406
423
|
this._isRecording = true;
|
|
407
424
|
}
|
|
408
425
|
stopRecording() {
|
|
409
426
|
this._isRecording = false;
|
|
410
427
|
}
|
|
411
|
-
resolveError() {
|
|
412
|
-
this._currentError = null;
|
|
413
|
-
}
|
|
414
428
|
}
|
|
415
429
|
|
|
416
430
|
class Cursor {
|
|
@@ -507,8 +521,8 @@ class Cursor {
|
|
|
507
521
|
recordMatch(pattern, node) {
|
|
508
522
|
this._history.recordMatch(pattern, node);
|
|
509
523
|
}
|
|
510
|
-
recordErrorAt(startIndex,
|
|
511
|
-
this._history.recordErrorAt(startIndex,
|
|
524
|
+
recordErrorAt(startIndex, lastIndex, onPattern) {
|
|
525
|
+
this._history.recordErrorAt(startIndex, lastIndex, onPattern);
|
|
512
526
|
}
|
|
513
527
|
resolveError() {
|
|
514
528
|
this._history.resolveError();
|
|
@@ -892,7 +906,7 @@ class Reference {
|
|
|
892
906
|
for (let pattern of this._recursiveAncestors) {
|
|
893
907
|
if (pattern.startedOnIndex === this.startedOnIndex) {
|
|
894
908
|
depth++;
|
|
895
|
-
if (depth >
|
|
909
|
+
if (depth > 1) {
|
|
896
910
|
return true;
|
|
897
911
|
}
|
|
898
912
|
}
|
|
@@ -3233,7 +3247,9 @@ class TakeUntil {
|
|
|
3233
3247
|
if (foundMatch) {
|
|
3234
3248
|
cursor.moveTo(cursorIndex - 1);
|
|
3235
3249
|
const value = cursor.getChars(this.startedOnIndex, cursorIndex - 1);
|
|
3236
|
-
|
|
3250
|
+
const node = Node.createValueNode(this._type, this._name, value);
|
|
3251
|
+
cursor.recordMatch(this, node);
|
|
3252
|
+
return node;
|
|
3237
3253
|
}
|
|
3238
3254
|
else {
|
|
3239
3255
|
cursor.moveTo(this.startedOnIndex);
|