clarity-pattern-parser 6.0.2 → 7.0.0
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 -78
- package/dist/ast/Node.d.ts +1 -0
- package/dist/grammar/Grammar.d.ts +17 -0
- package/dist/grammar/patterns/andLiteral.d.ts +2 -0
- package/dist/grammar/patterns/comment.d.ts +2 -0
- package/dist/grammar/patterns/grammar.d.ts +2 -0
- package/dist/grammar/patterns/literal.d.ts +2 -0
- package/dist/grammar/patterns/name.d.ts +2 -0
- package/dist/grammar/patterns/orLiteral.d.ts +2 -0
- package/dist/grammar/patterns/pattern.d.ts +2 -0
- package/dist/grammar/patterns/regexLiteral.d.ts +2 -0
- package/dist/grammar/patterns/repeatLiteral.d.ts +3 -0
- package/dist/grammar/patterns/spaces.d.ts +2 -0
- package/dist/grammar/patterns/statement.d.ts +2 -0
- package/dist/index.browser.js +1161 -556
- package/dist/index.browser.js.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.esm.js +1159 -555
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1159 -554
- package/dist/index.js.map +1 -1
- package/dist/intellisense/AutoComplete.d.ts +2 -6
- package/dist/patterns/And.d.ts +1 -1
- package/dist/patterns/Cursor.d.ts +1 -0
- package/dist/patterns/CursorHistory.d.ts +2 -1
- package/dist/patterns/FiniteRepeat.d.ts +39 -0
- package/dist/patterns/InfiniteRepeat.d.ts +47 -0
- package/dist/patterns/Literal.d.ts +1 -1
- package/dist/patterns/Not.d.ts +1 -1
- package/dist/patterns/Or.d.ts +1 -1
- package/dist/patterns/Pattern.d.ts +1 -1
- package/dist/patterns/Reference.d.ts +1 -1
- package/dist/patterns/Regex.d.ts +1 -1
- package/dist/patterns/Repeat.d.ts +18 -22
- package/jest.config.js +0 -1
- package/jest.coverage.config.js +13 -0
- package/package.json +3 -3
- package/src/ast/Node.test.ts +15 -0
- package/src/ast/Node.ts +12 -6
- package/src/grammar/Grammar.test.ts +288 -0
- package/src/grammar/Grammar.ts +234 -0
- package/src/grammar/patterns/andLiteral.ts +8 -0
- package/src/grammar/patterns/comment.ts +3 -0
- package/src/grammar/patterns/grammar.ts +19 -0
- package/src/grammar/patterns/literal.ts +5 -0
- package/src/grammar/patterns/name.ts +3 -0
- package/src/grammar/patterns/orLiteral.ts +8 -0
- package/src/grammar/patterns/pattern.ts +13 -0
- package/src/grammar/patterns/regexLiteral.ts +4 -0
- package/src/grammar/patterns/repeatLiteral.ts +72 -0
- package/src/grammar/patterns/spaces.ts +4 -0
- package/src/grammar/patterns/statement.ts +35 -0
- package/src/grammar/spec.md +142 -0
- package/src/index.ts +6 -3
- package/src/intellisense/AutoComplete.test.ts +21 -2
- package/src/intellisense/AutoComplete.ts +14 -25
- package/src/intellisense/Suggestion.ts +0 -1
- package/src/intellisense/css/cssValue.ts +1 -1
- package/src/intellisense/css/method.ts +1 -1
- package/src/intellisense/css/values.ts +1 -1
- package/src/intellisense/javascript/Javascript.test.ts +0 -1
- package/src/intellisense/javascript/arrayLiteral.ts +1 -1
- package/src/intellisense/javascript/expression.ts +1 -1
- package/src/intellisense/javascript/invocation.ts +1 -1
- package/src/intellisense/javascript/objectLiteral.ts +1 -1
- package/src/intellisense/javascript/parameters.ts +1 -1
- package/src/intellisense/javascript/stringLiteral.ts +2 -4
- package/src/patterns/And.test.ts +5 -5
- package/src/patterns/And.ts +11 -17
- package/src/patterns/Cursor.ts +4 -0
- package/src/patterns/CursorHistory.ts +34 -5
- package/src/patterns/FiniteRepeat.test.ts +481 -0
- package/src/patterns/FiniteRepeat.ts +231 -0
- package/src/patterns/InfiniteRepeat.test.ts +296 -0
- package/src/patterns/InfiniteRepeat.ts +329 -0
- package/src/patterns/Literal.test.ts +4 -4
- package/src/patterns/Literal.ts +1 -1
- package/src/patterns/Not.test.ts +11 -11
- package/src/patterns/Not.ts +1 -1
- package/src/patterns/Or.test.ts +9 -9
- package/src/patterns/Or.ts +1 -1
- package/src/patterns/Pattern.ts +1 -1
- package/src/patterns/Reference.test.ts +8 -8
- package/src/patterns/Reference.ts +1 -1
- package/src/patterns/Regex.test.ts +4 -4
- package/src/patterns/Regex.ts +1 -1
- package/src/patterns/Repeat.test.ts +160 -165
- package/src/patterns/Repeat.ts +95 -230
package/src/patterns/Not.test.ts
CHANGED
|
@@ -88,7 +88,7 @@ describe("Not", () => {
|
|
|
88
88
|
const notAboutUs = new Not("not-about-us", new Literal("about-us", "About Us"));
|
|
89
89
|
const sequence = new And("sequence", [notAboutUs, new Literal("about-them", "About Them")]);
|
|
90
90
|
|
|
91
|
-
const cloneNotAboutUs = sequence.
|
|
91
|
+
const cloneNotAboutUs = sequence.find(p => p.name === "not-about-us") as Pattern;
|
|
92
92
|
const nextTokens = cloneNotAboutUs.getNextTokens() || [];
|
|
93
93
|
|
|
94
94
|
expect(nextTokens[0]).toBe("About Them");
|
|
@@ -105,7 +105,7 @@ describe("Not", () => {
|
|
|
105
105
|
const notAboutUs = new Not("not-about-us", new Literal("about-us", "About Us"));
|
|
106
106
|
const sequence = new And("sequence", [notAboutUs, new Literal("about-them", "About Them")]);
|
|
107
107
|
|
|
108
|
-
const cloneNotAboutUs = sequence.
|
|
108
|
+
const cloneNotAboutUs = sequence.find(p => p.name === "not-about-us") as Pattern;
|
|
109
109
|
const nextTokens = cloneNotAboutUs.getTokens() || [];
|
|
110
110
|
|
|
111
111
|
expect(nextTokens[0]).toBe("About Them");
|
|
@@ -114,8 +114,8 @@ describe("Not", () => {
|
|
|
114
114
|
test("Get Tokens After", () => {
|
|
115
115
|
const notAboutUs = new Not("not-about-us", new Literal("about-us", "About Us"));
|
|
116
116
|
const sequence = new And("sequence", [notAboutUs, new Literal("about-them", "About Them")]);
|
|
117
|
-
const notAboutUsClone = sequence.
|
|
118
|
-
const aboutUsClone = sequence.
|
|
117
|
+
const notAboutUsClone = sequence.find(p => p.name === "not-about-us") as Pattern;
|
|
118
|
+
const aboutUsClone = sequence.find(p => p.name === "about-us") as Pattern;
|
|
119
119
|
const nextTokens = notAboutUsClone.getTokensAfter(aboutUsClone) || [];
|
|
120
120
|
|
|
121
121
|
expect(nextTokens[0]).toBe("About Them");
|
|
@@ -123,7 +123,7 @@ describe("Not", () => {
|
|
|
123
123
|
|
|
124
124
|
test("Find Pattern", () => {
|
|
125
125
|
const notAboutUs = new Not("not-about-us", new Literal("about-us", "About Us"));
|
|
126
|
-
const child = notAboutUs.
|
|
126
|
+
const child = notAboutUs.find(p => p.name === "about-us")
|
|
127
127
|
|
|
128
128
|
expect(child).not.toBeNull();
|
|
129
129
|
});
|
|
@@ -132,9 +132,9 @@ describe("Not", () => {
|
|
|
132
132
|
const notAboutUs = new Not("not-about-us", new Literal("about-us", "About Us"));
|
|
133
133
|
const sequence = new And("sequence", [notAboutUs, new Literal("about-them", "About Them")]);
|
|
134
134
|
|
|
135
|
-
const cloneNotAboutUs = sequence.
|
|
135
|
+
const cloneNotAboutUs = sequence.find(p => p.name === "not-about-us") as Pattern;
|
|
136
136
|
const nextPatterns = cloneNotAboutUs.getPatterns();
|
|
137
|
-
const expected = [sequence.
|
|
137
|
+
const expected = [sequence.find(p=>p.name === "about-them")];
|
|
138
138
|
|
|
139
139
|
expect(nextPatterns).toEqual(expected);
|
|
140
140
|
});
|
|
@@ -143,7 +143,7 @@ describe("Not", () => {
|
|
|
143
143
|
const notAboutUs = new Not("not-about-us", new Literal("about-us", "About Us"));
|
|
144
144
|
const sequence = new And("sequence", [notAboutUs, new Literal("about-them", "About Them")]);
|
|
145
145
|
|
|
146
|
-
const cloneNotAboutUs = sequence.
|
|
146
|
+
const cloneNotAboutUs = sequence.find(p => p.name === "not-about-us") as Pattern;
|
|
147
147
|
const patterns = cloneNotAboutUs.getNextPatterns() || [];
|
|
148
148
|
|
|
149
149
|
expect(patterns.length).toBe(1);
|
|
@@ -160,8 +160,8 @@ describe("Not", () => {
|
|
|
160
160
|
test("Get Patterns After", () => {
|
|
161
161
|
const notAboutUs = new Not("not-about-us", new Literal("about-us", "About Us"));
|
|
162
162
|
const sequence = new And("sequence", [notAboutUs, new Literal("about-them", "About Them")]);
|
|
163
|
-
const notAboutUsClone = sequence.
|
|
164
|
-
const aboutUsClone = sequence.
|
|
163
|
+
const notAboutUsClone = sequence.find(p => p.name === "not-about-us") as Pattern;
|
|
164
|
+
const aboutUsClone = sequence.find(p => p.name === "about-us") as Pattern;
|
|
165
165
|
const patterns = notAboutUsClone.getPatternsAfter(aboutUsClone) || [];
|
|
166
166
|
|
|
167
167
|
expect(patterns.length).toBe(1);
|
|
@@ -170,7 +170,7 @@ describe("Not", () => {
|
|
|
170
170
|
|
|
171
171
|
test("Get Patterns After With Null Parent", () => {
|
|
172
172
|
const notAboutUs = new Not("not-about-us", new Literal("about-us", "About Us"));
|
|
173
|
-
const aboutUsClone = notAboutUs.
|
|
173
|
+
const aboutUsClone = notAboutUs.find(p => p.name === "about-us") as Pattern;
|
|
174
174
|
const patterns = notAboutUs.getPatternsAfter(aboutUsClone) || [];
|
|
175
175
|
|
|
176
176
|
expect(patterns.length).toBe(0);
|
package/src/patterns/Not.ts
CHANGED
|
@@ -128,7 +128,7 @@ export class Not implements Pattern {
|
|
|
128
128
|
return this.parent.getPatternsAfter(this)
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
|
|
131
|
+
find(predicate: (p: Pattern) => boolean): Pattern | null {
|
|
132
132
|
return predicate(this._children[0]) ? this._children[0] : null;
|
|
133
133
|
}
|
|
134
134
|
|
package/src/patterns/Or.test.ts
CHANGED
|
@@ -118,7 +118,7 @@ describe("Or", () => {
|
|
|
118
118
|
new Literal("c", "C")
|
|
119
119
|
]);
|
|
120
120
|
|
|
121
|
-
const orClone = sequence.
|
|
121
|
+
const orClone = sequence.find(p => p.name === "a-or-b") as Pattern;
|
|
122
122
|
const tokens = orClone.getNextTokens();
|
|
123
123
|
|
|
124
124
|
expect(tokens.length).toBe(1);
|
|
@@ -145,8 +145,8 @@ describe("Or", () => {
|
|
|
145
145
|
new Literal("c", "C")
|
|
146
146
|
]);
|
|
147
147
|
|
|
148
|
-
const aClone = sequence.
|
|
149
|
-
const orClone = sequence.
|
|
148
|
+
const aClone = sequence.find(p => p.name === "a") as Pattern;
|
|
149
|
+
const orClone = sequence.find(p => p.name === "a-or-b") as Pattern;
|
|
150
150
|
const tokens = orClone.getTokensAfter(aClone);
|
|
151
151
|
|
|
152
152
|
expect(tokens.length).toBe(1);
|
|
@@ -157,8 +157,8 @@ describe("Or", () => {
|
|
|
157
157
|
const aOrB = new Or("a-b", [new Literal("a", "A"), new Literal("b", "B")]);
|
|
158
158
|
const patterns = aOrB.getPatterns();
|
|
159
159
|
const expected = [
|
|
160
|
-
aOrB.
|
|
161
|
-
aOrB.
|
|
160
|
+
aOrB.find(p => p.name === "a"),
|
|
161
|
+
aOrB.find(p => p.name === "b")
|
|
162
162
|
];
|
|
163
163
|
|
|
164
164
|
expect(patterns).toEqual(expected);
|
|
@@ -173,8 +173,8 @@ describe("Or", () => {
|
|
|
173
173
|
new Literal("c", "C")
|
|
174
174
|
]);
|
|
175
175
|
|
|
176
|
-
const aClone = sequence.
|
|
177
|
-
const orClone = sequence.
|
|
176
|
+
const aClone = sequence.find(p => p.name === "a") as Pattern;
|
|
177
|
+
const orClone = sequence.find(p => p.name === "a-or-b") as Pattern;
|
|
178
178
|
const patterns = orClone.getPatternsAfter(aClone);
|
|
179
179
|
|
|
180
180
|
expect(patterns.length).toBe(1);
|
|
@@ -186,7 +186,7 @@ describe("Or", () => {
|
|
|
186
186
|
new Literal("a", "A"),
|
|
187
187
|
new Literal("b", "B")
|
|
188
188
|
])
|
|
189
|
-
const aClone = or.
|
|
189
|
+
const aClone = or.find(p => p.name === "a") as Pattern;
|
|
190
190
|
const patterns = or.getPatternsAfter(aClone);
|
|
191
191
|
|
|
192
192
|
expect(patterns.length).toBe(0);
|
|
@@ -201,7 +201,7 @@ describe("Or", () => {
|
|
|
201
201
|
new Literal("c", "C")
|
|
202
202
|
]);
|
|
203
203
|
|
|
204
|
-
const orClone = sequence.
|
|
204
|
+
const orClone = sequence.find(p => p.name === "a-or-b") as Pattern;
|
|
205
205
|
const patterns = orClone.getNextPatterns();
|
|
206
206
|
|
|
207
207
|
expect(patterns.length).toBe(1);
|
package/src/patterns/Or.ts
CHANGED
|
@@ -162,7 +162,7 @@ export class Or implements Pattern {
|
|
|
162
162
|
return this.parent.getPatternsAfter(this)
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
-
|
|
165
|
+
find(predicate: (p: Pattern) => boolean): Pattern | null {
|
|
166
166
|
return findPattern(this, predicate);
|
|
167
167
|
}
|
|
168
168
|
|
package/src/patterns/Pattern.ts
CHANGED
|
@@ -19,5 +19,5 @@ export interface Pattern {
|
|
|
19
19
|
getPatterns(): Pattern[];
|
|
20
20
|
getPatternsAfter(childReference: Pattern): Pattern[];
|
|
21
21
|
getNextPatterns(): Pattern[];
|
|
22
|
-
|
|
22
|
+
find(predicate: (p: Pattern) => boolean): Pattern | null;
|
|
23
23
|
}
|
|
@@ -19,7 +19,7 @@ function createValuePattern() {
|
|
|
19
19
|
divider.setTokens([", "]);
|
|
20
20
|
|
|
21
21
|
const valueRef = new Reference("value");
|
|
22
|
-
const values = new Repeat("values", valueRef, divider);
|
|
22
|
+
const values = new Repeat("values", valueRef, { divider });
|
|
23
23
|
const array = new And("array", [openBracket, values, closeBracket]);
|
|
24
24
|
const value = new Or("value", [number, array]);
|
|
25
25
|
|
|
@@ -34,7 +34,7 @@ describe("Reference", () => {
|
|
|
34
34
|
|
|
35
35
|
const expected = new Node("and", "array", 0, 5, [
|
|
36
36
|
new Node("literal", "open-bracket", 0, 0, [], "["),
|
|
37
|
-
new Node("repeat", "values", 1, 4, [
|
|
37
|
+
new Node("infinite-repeat", "values", 1, 4, [
|
|
38
38
|
new Node("regex", "number", 1, 1, [], "1"),
|
|
39
39
|
new Node("regex", "divider", 2, 3, [], ", "),
|
|
40
40
|
new Node("regex", "number", 4, 4, [], "2")
|
|
@@ -114,9 +114,9 @@ describe("Reference", () => {
|
|
|
114
114
|
|
|
115
115
|
test("Find Pattern", () => {
|
|
116
116
|
const value = createValuePattern();
|
|
117
|
-
const reference = value.
|
|
117
|
+
const reference = value.find(p => p.type === "reference") as Pattern;
|
|
118
118
|
|
|
119
|
-
const pattern = reference?.
|
|
119
|
+
const pattern = reference?.find(p => p.name === "Nada");
|
|
120
120
|
|
|
121
121
|
expect(pattern).toBe(null);
|
|
122
122
|
});
|
|
@@ -124,7 +124,7 @@ describe("Reference", () => {
|
|
|
124
124
|
|
|
125
125
|
test("Get Next Tokens", () => {
|
|
126
126
|
const value = createValuePattern();
|
|
127
|
-
const reference = value.
|
|
127
|
+
const reference = value.find(p => p.type === "reference") as Pattern;
|
|
128
128
|
const tokens = reference.getNextTokens();
|
|
129
129
|
|
|
130
130
|
expect(tokens).toEqual([", ", "]"]);
|
|
@@ -139,7 +139,7 @@ describe("Reference", () => {
|
|
|
139
139
|
|
|
140
140
|
test("Get Tokens After", () => {
|
|
141
141
|
const value = createValuePattern();
|
|
142
|
-
const reference = value.
|
|
142
|
+
const reference = value.find(p => p.type === "reference") as Pattern;
|
|
143
143
|
const tokens = reference.getTokensAfter(new Literal("bogus", "Bogus"));
|
|
144
144
|
|
|
145
145
|
expect(tokens).toEqual([", ", "]"]);
|
|
@@ -164,7 +164,7 @@ describe("Reference", () => {
|
|
|
164
164
|
|
|
165
165
|
test("Get Patterns After", () => {
|
|
166
166
|
const value = createValuePattern();
|
|
167
|
-
const reference = value.
|
|
167
|
+
const reference = value.find(p => p.type === "reference") as Pattern;
|
|
168
168
|
const patterns = reference.getPatternsAfter(new Literal("bogus", "Bogus"));
|
|
169
169
|
|
|
170
170
|
expect(patterns.length).toEqual(2);
|
|
@@ -183,7 +183,7 @@ describe("Reference", () => {
|
|
|
183
183
|
|
|
184
184
|
test("Get Next Patterns", () => {
|
|
185
185
|
const value = createValuePattern();
|
|
186
|
-
const reference = value.
|
|
186
|
+
const reference = value.find(p => p.type === "reference") as Pattern;
|
|
187
187
|
const patterns = reference.getNextPatterns();
|
|
188
188
|
|
|
189
189
|
expect(patterns.length).toEqual(2);
|
|
@@ -147,7 +147,7 @@ export class Reference implements Pattern {
|
|
|
147
147
|
return this.parent.getPatternsAfter(this)
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
|
|
150
|
+
find(_predicate: (p: Pattern) => boolean): Pattern | null {
|
|
151
151
|
return null;
|
|
152
152
|
}
|
|
153
153
|
|
|
@@ -86,7 +86,7 @@ describe("Regex", () => {
|
|
|
86
86
|
|
|
87
87
|
test("Get Next Tokens", () => {
|
|
88
88
|
const parent = new And("parent", [new Regex("a", "A"), new Literal("b", "B")]);
|
|
89
|
-
const aClone = parent.
|
|
89
|
+
const aClone = parent.find(p => p.name === "a") as Pattern;
|
|
90
90
|
const tokens = aClone.getNextTokens();
|
|
91
91
|
|
|
92
92
|
expect(tokens).toEqual(["B"]);
|
|
@@ -117,15 +117,15 @@ describe("Regex", () => {
|
|
|
117
117
|
|
|
118
118
|
test("Find Pattern", () => {
|
|
119
119
|
const a = new Regex("a", "A")
|
|
120
|
-
const pattern = a.
|
|
120
|
+
const pattern = a.find(p => p.name === "other");
|
|
121
121
|
|
|
122
122
|
expect(pattern).toBeNull();
|
|
123
123
|
});
|
|
124
124
|
|
|
125
125
|
test("Get Next Patterns", () => {
|
|
126
126
|
const parent = new And("parent", [new Regex("a", "A"), new Literal("b", "B")]);
|
|
127
|
-
const aClone = parent.
|
|
128
|
-
const bClone = parent.
|
|
127
|
+
const aClone = parent.find(p => p.name === "a") as Pattern;
|
|
128
|
+
const bClone = parent.find(p => p.name === "b") as Pattern;
|
|
129
129
|
const patterns = aClone.getNextPatterns();
|
|
130
130
|
|
|
131
131
|
expect(patterns.length).toBe(1);
|
package/src/patterns/Regex.ts
CHANGED
|
@@ -173,7 +173,7 @@ export class Regex implements Pattern {
|
|
|
173
173
|
return this.parent.getPatternsAfter(this)
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
-
|
|
176
|
+
find(_predicate: (p: Pattern) => boolean): Pattern | null {
|
|
177
177
|
return null;
|
|
178
178
|
}
|
|
179
179
|
|