clarity-pattern-parser 6.0.0 → 6.0.2
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 +9 -7
- package/dist/index.browser.js +72 -22
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +72 -22
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +72 -22
- package/dist/index.js.map +1 -1
- package/dist/intellisense/AutoComplete.d.ts +12 -6
- package/dist/intellisense/Suggestion.d.ts +1 -2
- package/dist/patterns/And.d.ts +1 -0
- package/dist/patterns/Literal.d.ts +1 -0
- package/dist/patterns/Not.d.ts +1 -0
- package/dist/patterns/Or.d.ts +1 -0
- package/dist/patterns/Pattern.d.ts +2 -1
- package/dist/patterns/Reference.d.ts +1 -0
- package/dist/patterns/Regex.d.ts +1 -0
- package/dist/patterns/Repeat.d.ts +1 -0
- package/package.json +1 -1
- package/src/ast/Node.test.ts +6 -0
- package/src/intellisense/AutoComplete.test.ts +104 -37
- package/src/intellisense/AutoComplete.ts +51 -24
- package/src/intellisense/Suggestion.ts +1 -1
- package/src/intellisense/javascript/Javascript.test.ts +35 -11
- package/src/intellisense/javascript/{expressionStatement.ts → assignment.ts} +7 -8
- package/src/intellisense/javascript/expression.ts +44 -26
- package/src/intellisense/javascript/infixOperator.ts +6 -2
- package/src/intellisense/javascript/keywords.ts +3 -0
- package/src/intellisense/javascript/objectAccess.ts +9 -0
- package/src/intellisense/javascript/objectLiteral.ts +3 -3
- package/src/intellisense/javascript/propertyAccess.ts +8 -3
- package/src/intellisense/javascript/stringLiteral.ts +16 -8
- package/src/patterns/And.test.ts +13 -0
- package/src/patterns/And.ts +14 -0
- package/src/patterns/Literal.test.ts +9 -0
- package/src/patterns/Literal.ts +4 -0
- package/src/patterns/Not.test.ts +11 -0
- package/src/patterns/Not.ts +4 -0
- package/src/patterns/Or.test.ts +11 -0
- package/src/patterns/Or.ts +10 -0
- package/src/patterns/Pattern.ts +2 -1
- package/src/patterns/Reference.test.ts +10 -0
- package/src/patterns/Reference.ts +4 -0
- package/src/patterns/Regex.test.ts +9 -0
- package/src/patterns/Regex.ts +4 -0
- package/src/patterns/Repeat.test.ts +9 -0
- package/src/patterns/Repeat.ts +4 -0
|
@@ -6,7 +6,7 @@ import { name } from "./name";
|
|
|
6
6
|
|
|
7
7
|
const dotPropertyAccess = new And("dot-property-access", [
|
|
8
8
|
new Literal("period", "."),
|
|
9
|
-
name
|
|
9
|
+
name.clone("property-name")
|
|
10
10
|
]);
|
|
11
11
|
|
|
12
12
|
const bracketPropertyAccess = new And("bracket-property-access", [
|
|
@@ -15,9 +15,14 @@ const bracketPropertyAccess = new And("bracket-property-access", [
|
|
|
15
15
|
new Literal("close-square-bracket", "]"),
|
|
16
16
|
]);
|
|
17
17
|
|
|
18
|
-
const
|
|
18
|
+
const propertyAccessTypes = new Or("property-access-types", [
|
|
19
19
|
dotPropertyAccess,
|
|
20
|
-
bracketPropertyAccess
|
|
20
|
+
bracketPropertyAccess
|
|
21
|
+
]);
|
|
22
|
+
|
|
23
|
+
const propertyAccess = new And("property-access", [
|
|
24
|
+
propertyAccessTypes,
|
|
25
|
+
new Reference("property-access", true)
|
|
21
26
|
]);
|
|
22
27
|
|
|
23
28
|
export { propertyAccess }
|
|
@@ -7,19 +7,27 @@ import { escapedCharacter } from "./escapedCharacter";
|
|
|
7
7
|
|
|
8
8
|
const doubleQuoteStringLiteral = new And("double-string-literal", [
|
|
9
9
|
new Literal("double-quote", "\""),
|
|
10
|
-
new Repeat("characters",
|
|
11
|
-
new
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
new Repeat("characters",
|
|
11
|
+
new Or("characters", [
|
|
12
|
+
new Regex("normal-characters", "[^\\\"]+"),
|
|
13
|
+
escapedCharacter
|
|
14
|
+
]),
|
|
15
|
+
undefined,
|
|
16
|
+
true
|
|
17
|
+
),
|
|
14
18
|
new Literal("double-quote", "\""),
|
|
15
19
|
]);
|
|
16
20
|
|
|
17
21
|
const singleQuoteStringLiteral = new And("single-string-literal", [
|
|
18
22
|
new Literal("single-quote", "'"),
|
|
19
|
-
new Repeat("characters",
|
|
20
|
-
new
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
new Repeat("characters",
|
|
24
|
+
new Or("characters", [
|
|
25
|
+
new Regex("normal-characters", "[^\\']+"),
|
|
26
|
+
escapedCharacter
|
|
27
|
+
]),
|
|
28
|
+
undefined,
|
|
29
|
+
true
|
|
30
|
+
),
|
|
23
31
|
new Literal("single-quote", "'"),
|
|
24
32
|
]);
|
|
25
33
|
|
package/src/patterns/And.test.ts
CHANGED
|
@@ -289,6 +289,19 @@ describe("And", () => {
|
|
|
289
289
|
expect(tokens.length).toBe(0);
|
|
290
290
|
});
|
|
291
291
|
|
|
292
|
+
test("Get Patterns", () => {
|
|
293
|
+
const sequence = new And("sequence", [
|
|
294
|
+
new Literal("a", "A", true),
|
|
295
|
+
new Literal("b", "B"),
|
|
296
|
+
], true);
|
|
297
|
+
const tokens = sequence.getPatterns();
|
|
298
|
+
const a = sequence.findPattern(p=>p.name === "a");
|
|
299
|
+
const b = sequence.findPattern(p=>p.name === "b");
|
|
300
|
+
const expected = [a, b]
|
|
301
|
+
|
|
302
|
+
expect(tokens).toEqual(expected);
|
|
303
|
+
});
|
|
304
|
+
|
|
292
305
|
test("Get Next Patterns", () => {
|
|
293
306
|
const sequence = new And("sequence", [new Literal("a", "A")]);
|
|
294
307
|
const parent = new And("parent", [sequence, new Literal("b", "B")]);
|
package/src/patterns/And.ts
CHANGED
|
@@ -234,6 +234,20 @@ export class And implements Pattern {
|
|
|
234
234
|
return this.parent.getTokensAfter(this);
|
|
235
235
|
}
|
|
236
236
|
|
|
237
|
+
getPatterns(): Pattern[] {
|
|
238
|
+
const patterns: Pattern[] = [];
|
|
239
|
+
|
|
240
|
+
for (const pattern of this._children) {
|
|
241
|
+
patterns.push(...pattern.getPatterns());
|
|
242
|
+
|
|
243
|
+
if (!pattern.isOptional) {
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return patterns;
|
|
249
|
+
}
|
|
250
|
+
|
|
237
251
|
getPatternsAfter(childReference: Pattern): Pattern[] {
|
|
238
252
|
let nextSibling: Pattern | null = null;
|
|
239
253
|
let nextSiblingIndex = -1;
|
|
@@ -132,6 +132,15 @@ describe("Literal", () => {
|
|
|
132
132
|
expect(tokens.length).toBe(0);
|
|
133
133
|
});
|
|
134
134
|
|
|
135
|
+
test("Get Patterns", () => {
|
|
136
|
+
const a = new Literal("a", "A");
|
|
137
|
+
|
|
138
|
+
const tokens = a.getPatterns();
|
|
139
|
+
const expectedTokens = [a];
|
|
140
|
+
|
|
141
|
+
expect(tokens).toEqual(expectedTokens);
|
|
142
|
+
});
|
|
143
|
+
|
|
135
144
|
test("Get Next Patterns", () => {
|
|
136
145
|
const sequence = new And("sequence", [new Literal("a", "A")]);
|
|
137
146
|
const parent = new And("parent", [sequence, new Literal("b", "B")]);
|
package/src/patterns/Literal.ts
CHANGED
package/src/patterns/Not.test.ts
CHANGED
|
@@ -128,6 +128,17 @@ describe("Not", () => {
|
|
|
128
128
|
expect(child).not.toBeNull();
|
|
129
129
|
});
|
|
130
130
|
|
|
131
|
+
test("Get Patterns", () => {
|
|
132
|
+
const notAboutUs = new Not("not-about-us", new Literal("about-us", "About Us"));
|
|
133
|
+
const sequence = new And("sequence", [notAboutUs, new Literal("about-them", "About Them")]);
|
|
134
|
+
|
|
135
|
+
const cloneNotAboutUs = sequence.findPattern(p => p.name === "not-about-us") as Pattern;
|
|
136
|
+
const nextPatterns = cloneNotAboutUs.getPatterns();
|
|
137
|
+
const expected = [sequence.findPattern(p=>p.name === "about-them")];
|
|
138
|
+
|
|
139
|
+
expect(nextPatterns).toEqual(expected);
|
|
140
|
+
});
|
|
141
|
+
|
|
131
142
|
test("Get Next Patterns", () => {
|
|
132
143
|
const notAboutUs = new Not("not-about-us", new Literal("about-us", "About Us"));
|
|
133
144
|
const sequence = new And("sequence", [notAboutUs, new Literal("about-them", "About Them")]);
|
package/src/patterns/Not.ts
CHANGED
|
@@ -106,6 +106,10 @@ export class Not implements Pattern {
|
|
|
106
106
|
return this.parent.getTokensAfter(this);
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
getPatterns(): Pattern[] {
|
|
110
|
+
return [...this.getNextPatterns().map(p => p.getPatterns()).flat()];
|
|
111
|
+
}
|
|
112
|
+
|
|
109
113
|
getPatternsAfter(_childReference: Pattern): Pattern[] {
|
|
110
114
|
const parent = this._parent;
|
|
111
115
|
|
package/src/patterns/Or.test.ts
CHANGED
|
@@ -153,6 +153,17 @@ describe("Or", () => {
|
|
|
153
153
|
expect(tokens[0]).toBe("C");
|
|
154
154
|
});
|
|
155
155
|
|
|
156
|
+
test("Get Patterns", () => {
|
|
157
|
+
const aOrB = new Or("a-b", [new Literal("a", "A"), new Literal("b", "B")]);
|
|
158
|
+
const patterns = aOrB.getPatterns();
|
|
159
|
+
const expected = [
|
|
160
|
+
aOrB.findPattern(p => p.name === "a"),
|
|
161
|
+
aOrB.findPattern(p => p.name === "b")
|
|
162
|
+
];
|
|
163
|
+
|
|
164
|
+
expect(patterns).toEqual(expected);
|
|
165
|
+
});
|
|
166
|
+
|
|
156
167
|
test("Get Patterns After", () => {
|
|
157
168
|
const sequence = new And("sequence", [
|
|
158
169
|
new Or("a-or-b", [
|
package/src/patterns/Or.ts
CHANGED
|
@@ -136,6 +136,16 @@ export class Or implements Pattern {
|
|
|
136
136
|
return this._parent.getTokensAfter(this);
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
+
getPatterns(): Pattern[] {
|
|
140
|
+
const patterns: Pattern[] = [];
|
|
141
|
+
|
|
142
|
+
for (const pattern of this._children) {
|
|
143
|
+
patterns.push(...pattern.getPatterns());
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return patterns;
|
|
147
|
+
}
|
|
148
|
+
|
|
139
149
|
getPatternsAfter(_childReference: Pattern): Pattern[] {
|
|
140
150
|
if (this._parent === null) {
|
|
141
151
|
return [];
|
package/src/patterns/Pattern.ts
CHANGED
|
@@ -15,8 +15,9 @@ export interface Pattern {
|
|
|
15
15
|
clone(name?: string, isOptional?: boolean): Pattern;
|
|
16
16
|
getTokens(): string[];
|
|
17
17
|
getTokensAfter(childReference: Pattern): string[];
|
|
18
|
+
getNextTokens(): string[];
|
|
19
|
+
getPatterns(): Pattern[];
|
|
18
20
|
getPatternsAfter(childReference: Pattern): Pattern[];
|
|
19
21
|
getNextPatterns(): Pattern[];
|
|
20
|
-
getNextTokens(): string[];
|
|
21
22
|
findPattern(predicate: (p: Pattern) => boolean): Pattern | null;
|
|
22
23
|
}
|
|
@@ -152,6 +152,16 @@ describe("Reference", () => {
|
|
|
152
152
|
expect(tokens).toEqual([])
|
|
153
153
|
});
|
|
154
154
|
|
|
155
|
+
test("Get Patterns", () => {
|
|
156
|
+
const value = createValuePattern();
|
|
157
|
+
const ref = findPattern(value, (p) => p.type === "reference");
|
|
158
|
+
const patterns = ref?.getPatterns() || [];
|
|
159
|
+
|
|
160
|
+
expect(patterns.length).toBe(2);
|
|
161
|
+
expect(patterns[0].name).toBe("number");
|
|
162
|
+
expect(patterns[1].name).toBe("open-bracket");
|
|
163
|
+
});
|
|
164
|
+
|
|
155
165
|
test("Get Patterns After", () => {
|
|
156
166
|
const value = createValuePattern();
|
|
157
167
|
const reference = value.findPattern(p => p.type === "reference") as Pattern;
|
|
@@ -127,6 +127,10 @@ export class Reference implements Pattern {
|
|
|
127
127
|
return this.parent.getTokensAfter(this);
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
+
getPatterns(): Pattern[] {
|
|
131
|
+
return this._getPatternSafely().getPatterns();
|
|
132
|
+
}
|
|
133
|
+
|
|
130
134
|
getPatternsAfter(_childReference: Pattern): Pattern[] {
|
|
131
135
|
if (this._parent == null) {
|
|
132
136
|
return [];
|
|
@@ -99,6 +99,15 @@ describe("Regex", () => {
|
|
|
99
99
|
expect(tokens).toEqual([]);
|
|
100
100
|
});
|
|
101
101
|
|
|
102
|
+
test("Get Patterns", () => {
|
|
103
|
+
const a = new Regex("a", "A");
|
|
104
|
+
|
|
105
|
+
const tokens = a.getPatterns();
|
|
106
|
+
const expectedTokens = [a];
|
|
107
|
+
|
|
108
|
+
expect(tokens).toEqual(expectedTokens);
|
|
109
|
+
});
|
|
110
|
+
|
|
102
111
|
test("Get Patterns After", () => {
|
|
103
112
|
const a = new Regex("a", "A")
|
|
104
113
|
const patterns = a.getPatternsAfter(new Literal("bogus", "bogus"));
|
package/src/patterns/Regex.ts
CHANGED
|
@@ -198,6 +198,15 @@ describe("Repeat", () => {
|
|
|
198
198
|
expect(digitClone).not.toBeNull();
|
|
199
199
|
});
|
|
200
200
|
|
|
201
|
+
test("Get Patterns", () => {
|
|
202
|
+
const a = new Literal("a", "A");
|
|
203
|
+
const manyA = new Repeat("number", a);
|
|
204
|
+
const patterns = manyA.getPatterns();
|
|
205
|
+
const expected = [manyA.findPattern(p => p.name === "a")];
|
|
206
|
+
|
|
207
|
+
expect(patterns).toEqual(expected)
|
|
208
|
+
});
|
|
209
|
+
|
|
201
210
|
test("Get Next Patterns", () => {
|
|
202
211
|
const integer = new Repeat("integer", new Regex("digit", "\\d"));
|
|
203
212
|
const parent = new And("parent", [integer, new Literal("pow", "!")]);
|
package/src/patterns/Repeat.ts
CHANGED
|
@@ -216,6 +216,10 @@ export class Repeat implements Pattern {
|
|
|
216
216
|
return this.parent.getTokensAfter(this);
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
+
getPatterns(): Pattern[] {
|
|
220
|
+
return this._pattern.getPatterns();
|
|
221
|
+
}
|
|
222
|
+
|
|
219
223
|
getPatternsAfter(childReference: Pattern): Pattern[] {
|
|
220
224
|
let index = -1;
|
|
221
225
|
const patterns: Pattern[] = [];
|