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/TODO.md
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
* Fix Grammar with alias reference, by adding an additional parameter to the constructor of Reference to be the name and then the cloned name of the pattern eventually found.
|
|
2
|
-
|
|
3
1
|
* We should make a Block, Segments Pattern. These will be breadth first patterns. It look something like this.
|
|
4
2
|
|
|
5
3
|
```ts
|
|
6
|
-
new Block(startPattern,
|
|
4
|
+
new Block("block", startPattern,endPattern);
|
|
7
5
|
```
|
|
8
6
|
|
|
9
7
|
```
|
package/dist/ast/Node.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export interface CycleFreeNode {
|
|
2
|
+
id: string;
|
|
2
3
|
type: string;
|
|
3
4
|
name: string;
|
|
4
5
|
startIndex: number;
|
|
@@ -7,6 +8,7 @@ export interface CycleFreeNode {
|
|
|
7
8
|
children: CycleFreeNode[];
|
|
8
9
|
}
|
|
9
10
|
export declare class Node {
|
|
11
|
+
private _id;
|
|
10
12
|
private _type;
|
|
11
13
|
private _name;
|
|
12
14
|
private _firstIndex;
|
|
@@ -14,6 +16,7 @@ export declare class Node {
|
|
|
14
16
|
private _parent;
|
|
15
17
|
private _children;
|
|
16
18
|
private _value;
|
|
19
|
+
get id(): string;
|
|
17
20
|
get type(): string;
|
|
18
21
|
get name(): string;
|
|
19
22
|
get value(): string;
|
package/dist/index.browser.js
CHANGED
|
@@ -7,7 +7,11 @@
|
|
|
7
7
|
function defaultVisitor(node) {
|
|
8
8
|
return node;
|
|
9
9
|
}
|
|
10
|
+
let idIndex$b = 0;
|
|
10
11
|
class Node {
|
|
12
|
+
get id() {
|
|
13
|
+
return this._id;
|
|
14
|
+
}
|
|
11
15
|
get type() {
|
|
12
16
|
return this._type;
|
|
13
17
|
}
|
|
@@ -42,6 +46,7 @@
|
|
|
42
46
|
return !this.hasChildren;
|
|
43
47
|
}
|
|
44
48
|
constructor(type, name, firstIndex, lastIndex, children = [], value = "") {
|
|
49
|
+
this._id = String(idIndex$b++);
|
|
45
50
|
this._type = type;
|
|
46
51
|
this._name = name;
|
|
47
52
|
this._firstIndex = firstIndex;
|
|
@@ -202,7 +207,8 @@
|
|
|
202
207
|
}
|
|
203
208
|
}
|
|
204
209
|
clone() {
|
|
205
|
-
|
|
210
|
+
const node = new Node(this._type, this._name, this._firstIndex, this._lastIndex, this._children.map((c) => c.clone()), this._value);
|
|
211
|
+
return node;
|
|
206
212
|
}
|
|
207
213
|
normalize(startIndex = this._firstIndex) {
|
|
208
214
|
let length = 0;
|
|
@@ -230,6 +236,7 @@
|
|
|
230
236
|
}
|
|
231
237
|
toCycleFreeObject() {
|
|
232
238
|
return {
|
|
239
|
+
id: this._id,
|
|
233
240
|
type: this._type,
|
|
234
241
|
name: this._name,
|
|
235
242
|
value: this.toString(),
|
|
@@ -242,7 +249,12 @@
|
|
|
242
249
|
return JSON.stringify(this.toCycleFreeObject(), null, space);
|
|
243
250
|
}
|
|
244
251
|
isEqual(node) {
|
|
245
|
-
return node.
|
|
252
|
+
return node._type === this._type &&
|
|
253
|
+
node._name === this._name &&
|
|
254
|
+
node._firstIndex === this._firstIndex &&
|
|
255
|
+
node._lastIndex === this._lastIndex &&
|
|
256
|
+
node._value === this._value &&
|
|
257
|
+
this._children.every((child, index) => child.isEqual(node._children[index]));
|
|
246
258
|
}
|
|
247
259
|
static createValueNode(type, name, value = "") {
|
|
248
260
|
return new Node(type, name, 0, 0, [], value);
|
|
@@ -354,14 +366,15 @@
|
|
|
354
366
|
return this._patterns;
|
|
355
367
|
}
|
|
356
368
|
recordMatch(pattern, node) {
|
|
369
|
+
const record = {
|
|
370
|
+
pattern,
|
|
371
|
+
ast: node,
|
|
372
|
+
error: null
|
|
373
|
+
};
|
|
357
374
|
if (this._isRecording) {
|
|
358
375
|
this._patterns.push(pattern);
|
|
359
376
|
this._nodes.push(node);
|
|
360
|
-
this._records.push(
|
|
361
|
-
pattern,
|
|
362
|
-
ast: node,
|
|
363
|
-
error: null
|
|
364
|
-
});
|
|
377
|
+
this._records.push(record);
|
|
365
378
|
}
|
|
366
379
|
this._rootMatch.pattern = pattern;
|
|
367
380
|
this._rootMatch.node = node;
|
|
@@ -395,28 +408,29 @@
|
|
|
395
408
|
}
|
|
396
409
|
recordErrorAt(startIndex, lastIndex, pattern) {
|
|
397
410
|
const error = new ParseError(startIndex, lastIndex, pattern);
|
|
411
|
+
const record = {
|
|
412
|
+
pattern,
|
|
413
|
+
ast: null,
|
|
414
|
+
error
|
|
415
|
+
};
|
|
398
416
|
this._currentError = error;
|
|
399
417
|
if (this._furthestError === null || lastIndex > this._furthestError.lastIndex) {
|
|
400
418
|
this._furthestError = error;
|
|
401
419
|
}
|
|
402
420
|
if (this._isRecording) {
|
|
403
421
|
this._errors.push(error);
|
|
404
|
-
this.records.push(
|
|
405
|
-
pattern,
|
|
406
|
-
ast: null,
|
|
407
|
-
error
|
|
408
|
-
});
|
|
422
|
+
this.records.push(record);
|
|
409
423
|
}
|
|
410
424
|
}
|
|
425
|
+
resolveError() {
|
|
426
|
+
this._currentError = null;
|
|
427
|
+
}
|
|
411
428
|
startRecording() {
|
|
412
429
|
this._isRecording = true;
|
|
413
430
|
}
|
|
414
431
|
stopRecording() {
|
|
415
432
|
this._isRecording = false;
|
|
416
433
|
}
|
|
417
|
-
resolveError() {
|
|
418
|
-
this._currentError = null;
|
|
419
|
-
}
|
|
420
434
|
}
|
|
421
435
|
|
|
422
436
|
class Cursor {
|
|
@@ -513,8 +527,8 @@
|
|
|
513
527
|
recordMatch(pattern, node) {
|
|
514
528
|
this._history.recordMatch(pattern, node);
|
|
515
529
|
}
|
|
516
|
-
recordErrorAt(startIndex,
|
|
517
|
-
this._history.recordErrorAt(startIndex,
|
|
530
|
+
recordErrorAt(startIndex, lastIndex, onPattern) {
|
|
531
|
+
this._history.recordErrorAt(startIndex, lastIndex, onPattern);
|
|
518
532
|
}
|
|
519
533
|
resolveError() {
|
|
520
534
|
this._history.resolveError();
|
|
@@ -898,7 +912,7 @@
|
|
|
898
912
|
for (let pattern of this._recursiveAncestors) {
|
|
899
913
|
if (pattern.startedOnIndex === this.startedOnIndex) {
|
|
900
914
|
depth++;
|
|
901
|
-
if (depth >
|
|
915
|
+
if (depth > 1) {
|
|
902
916
|
return true;
|
|
903
917
|
}
|
|
904
918
|
}
|
|
@@ -3239,7 +3253,9 @@
|
|
|
3239
3253
|
if (foundMatch) {
|
|
3240
3254
|
cursor.moveTo(cursorIndex - 1);
|
|
3241
3255
|
const value = cursor.getChars(this.startedOnIndex, cursorIndex - 1);
|
|
3242
|
-
|
|
3256
|
+
const node = Node.createValueNode(this._type, this._name, value);
|
|
3257
|
+
cursor.recordMatch(this, node);
|
|
3258
|
+
return node;
|
|
3243
3259
|
}
|
|
3244
3260
|
else {
|
|
3245
3261
|
cursor.moveTo(this.startedOnIndex);
|