clarity-pattern-parser 10.1.2 → 10.1.3
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 +10 -6
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +10 -6
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +10 -6
- 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 +13 -4
- package/src/patterns/Reference.ts +2 -3
|
@@ -9,12 +9,17 @@ export declare class Context implements Pattern {
|
|
|
9
9
|
private _parent;
|
|
10
10
|
private _children;
|
|
11
11
|
private _pattern;
|
|
12
|
+
private _patterns;
|
|
12
13
|
get id(): string;
|
|
13
14
|
get type(): string;
|
|
14
15
|
get name(): string;
|
|
15
16
|
get parent(): Pattern | null;
|
|
16
17
|
set parent(pattern: Pattern | null);
|
|
17
18
|
get children(): Pattern[];
|
|
19
|
+
getPatternWithinContext(name: string): Pattern | null;
|
|
20
|
+
getPatternsWithinContext(): {
|
|
21
|
+
[x: string]: Pattern;
|
|
22
|
+
};
|
|
18
23
|
constructor(name: string, pattern: Pattern, context?: Pattern[]);
|
|
19
24
|
parse(cursor: Cursor): Node | null;
|
|
20
25
|
exec(text: string, record?: boolean | undefined): ParseResult;
|
package/package.json
CHANGED
package/src/patterns/Context.ts
CHANGED
|
@@ -12,6 +12,7 @@ export class Context implements Pattern {
|
|
|
12
12
|
private _parent: Pattern | null;
|
|
13
13
|
private _children: Pattern[];
|
|
14
14
|
private _pattern: Pattern;
|
|
15
|
+
private _patterns: Record<string, Pattern>;
|
|
15
16
|
|
|
16
17
|
get id(): string {
|
|
17
18
|
return this._id;
|
|
@@ -37,20 +38,28 @@ export class Context implements Pattern {
|
|
|
37
38
|
return this._children;
|
|
38
39
|
}
|
|
39
40
|
|
|
41
|
+
getPatternWithinContext(name: string): Pattern | null {
|
|
42
|
+
return this._patterns[name] || null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
getPatternsWithinContext() {
|
|
46
|
+
return { ...this._patterns };
|
|
47
|
+
}
|
|
48
|
+
|
|
40
49
|
constructor(name: string, pattern: Pattern, context: Pattern[] = []) {
|
|
41
50
|
this._id = `context-${contextId++}`;
|
|
42
51
|
this._type = "context";
|
|
43
52
|
this._name = name;
|
|
44
53
|
this._parent = null;
|
|
54
|
+
this._patterns = {};
|
|
45
55
|
|
|
46
|
-
const clonedContext = context.map(p => p.clone());
|
|
47
|
-
const clonedPattern = pattern.clone();
|
|
48
56
|
|
|
49
|
-
|
|
57
|
+
const clonedPattern = pattern.clone();
|
|
58
|
+
context.forEach(p => this._patterns[p.name] = p);
|
|
50
59
|
clonedPattern.parent = this;
|
|
51
60
|
|
|
52
61
|
this._pattern = clonedPattern;
|
|
53
|
-
this._children = [
|
|
62
|
+
this._children = [clonedPattern];
|
|
54
63
|
}
|
|
55
64
|
|
|
56
65
|
parse(cursor: Cursor): Node | null {
|
|
@@ -3,6 +3,7 @@ import { Cursor } from "./Cursor";
|
|
|
3
3
|
import { Pattern } from "./Pattern";
|
|
4
4
|
import { findPattern } from "./findPattern";
|
|
5
5
|
import { ParseResult } from "./ParseResult";
|
|
6
|
+
import { Context } from "./Context";
|
|
6
7
|
|
|
7
8
|
let idIndex = 0;
|
|
8
9
|
|
|
@@ -105,9 +106,7 @@ export class Reference implements Pattern {
|
|
|
105
106
|
continue;
|
|
106
107
|
}
|
|
107
108
|
|
|
108
|
-
const foundPattern =
|
|
109
|
-
return pattern.name === this._name && pattern.type !== "reference" && pattern.type !== "context";
|
|
110
|
-
});
|
|
109
|
+
const foundPattern = (pattern as Context).getPatternWithinContext(this.name);
|
|
111
110
|
|
|
112
111
|
if (foundPattern != null) {
|
|
113
112
|
return foundPattern;
|