clarity-pattern-parser 10.1.2 → 10.1.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 +11 -7
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +11 -7
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +11 -7
- package/dist/index.js.map +1 -1
- package/dist/patterns/Context.d.ts +5 -0
- package/package.json +1 -1
- package/src/patterns/Context.ts +14 -5
- package/src/patterns/Reference.ts +2 -3
package/dist/index.js
CHANGED
|
@@ -845,9 +845,7 @@ class Reference {
|
|
|
845
845
|
pattern = pattern.parent;
|
|
846
846
|
continue;
|
|
847
847
|
}
|
|
848
|
-
const foundPattern =
|
|
849
|
-
return pattern.name === this._name && pattern.type !== "reference" && pattern.type !== "context";
|
|
850
|
-
});
|
|
848
|
+
const foundPattern = pattern.getPatternWithinContext(this.name);
|
|
851
849
|
if (foundPattern != null) {
|
|
852
850
|
return foundPattern;
|
|
853
851
|
}
|
|
@@ -2540,17 +2538,23 @@ class Context {
|
|
|
2540
2538
|
get children() {
|
|
2541
2539
|
return this._children;
|
|
2542
2540
|
}
|
|
2541
|
+
getPatternWithinContext(name) {
|
|
2542
|
+
return this._patterns[name] || null;
|
|
2543
|
+
}
|
|
2544
|
+
getPatternsWithinContext() {
|
|
2545
|
+
return Object.assign({}, this._patterns);
|
|
2546
|
+
}
|
|
2543
2547
|
constructor(name, pattern, context = []) {
|
|
2544
2548
|
this._id = `context-${contextId++}`;
|
|
2545
2549
|
this._type = "context";
|
|
2546
2550
|
this._name = name;
|
|
2547
2551
|
this._parent = null;
|
|
2548
|
-
|
|
2552
|
+
this._patterns = {};
|
|
2549
2553
|
const clonedPattern = pattern.clone();
|
|
2550
|
-
|
|
2554
|
+
context.forEach(p => this._patterns[p.name] = p);
|
|
2551
2555
|
clonedPattern.parent = this;
|
|
2552
2556
|
this._pattern = clonedPattern;
|
|
2553
|
-
this._children = [
|
|
2557
|
+
this._children = [clonedPattern];
|
|
2554
2558
|
}
|
|
2555
2559
|
parse(cursor) {
|
|
2556
2560
|
return this._pattern.parse(cursor);
|
|
@@ -2562,7 +2566,7 @@ class Context {
|
|
|
2562
2566
|
return this._pattern.test(text, record);
|
|
2563
2567
|
}
|
|
2564
2568
|
clone(name = this._name) {
|
|
2565
|
-
const clone = new Context(name, this._pattern, this.
|
|
2569
|
+
const clone = new Context(name, this._pattern, Object.values(this._patterns));
|
|
2566
2570
|
return clone;
|
|
2567
2571
|
}
|
|
2568
2572
|
getTokens() {
|