clarity-pattern-parser 3.0.12 → 3.0.13
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 +16 -5
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +16 -5
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +16 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/TextSuggester.ts +20 -1
- package/src/patterns/Pattern.ts +1 -1
- package/src/patterns/composite/RepeatComposite.ts +0 -1
- package/src/patterns/value/RepeatValue.ts +0 -1
- package/src/tests/TextSuggester.test.ts +58 -12
package/src/TextSuggester.ts
CHANGED
|
@@ -260,8 +260,27 @@ export default class TextSuggester {
|
|
|
260
260
|
}
|
|
261
261
|
|
|
262
262
|
private saveOptions() {
|
|
263
|
-
const
|
|
263
|
+
const parents = new Map<Pattern, Pattern>();
|
|
264
|
+
const cursor = this.cursor;
|
|
265
|
+
|
|
266
|
+
if (cursor == null) {
|
|
267
|
+
this.options = [];
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const furthestMatches = cursor.history.astNodes.reduce(
|
|
264
272
|
(acc: any, node: any, index: any) => {
|
|
273
|
+
const pattern = cursor.history.patterns[index];
|
|
274
|
+
const parent = pattern.parent;
|
|
275
|
+
|
|
276
|
+
if (parent != null) {
|
|
277
|
+
parents.set(parent, parent);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
if (parents.has(pattern)){
|
|
281
|
+
return acc;
|
|
282
|
+
}
|
|
283
|
+
|
|
265
284
|
if (node.endIndex === acc.furthestTextIndex) {
|
|
266
285
|
acc.nodeIndexes.push(index);
|
|
267
286
|
} else if (node.endIndex > acc.furthestTextIndex) {
|
package/src/patterns/Pattern.ts
CHANGED
|
@@ -114,7 +114,7 @@ export default abstract class Pattern {
|
|
|
114
114
|
if (index === 0 && siblings.length > 1) {
|
|
115
115
|
return nextSibling.getTokens().concat(tokens);
|
|
116
116
|
} else if (index === 1) {
|
|
117
|
-
return siblings[0].getTokens()
|
|
117
|
+
return siblings[0].getTokens();
|
|
118
118
|
} else {
|
|
119
119
|
return this.getTokens().concat(tokens);
|
|
120
120
|
}
|
|
@@ -7,7 +7,40 @@ import OrValue from "../patterns/value/OrValue";
|
|
|
7
7
|
import json from "./javascriptPatterns/json";
|
|
8
8
|
import OrComposite from "../patterns/composite/OrComposite";
|
|
9
9
|
import RepeatComposite from "../patterns/composite/RepeatComposite";
|
|
10
|
-
import
|
|
10
|
+
import AndComposite from "../patterns/composite/AndComposite";
|
|
11
|
+
import RecursivePattern from "../patterns/RecursivePattern";
|
|
12
|
+
|
|
13
|
+
function generateFlagFromList(flagNames: string[]) {
|
|
14
|
+
return flagNames.map((flagName) => {
|
|
15
|
+
return new Literal("flag-name", flagName);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function generateExpression(flagNames: string[]) {
|
|
20
|
+
const openParen = new Literal("open-paren", "(");
|
|
21
|
+
const closeParen = new Literal("close-paren", ")");
|
|
22
|
+
const andLiteral = new Literal("and-literal", "AND");
|
|
23
|
+
const space = new Literal("space", " ");
|
|
24
|
+
const orLiteral = new Literal("or-literal", "OR");
|
|
25
|
+
const and = new AndValue("and", [space, andLiteral, space]);
|
|
26
|
+
const or = new AndValue("or", [space, orLiteral, space]);
|
|
27
|
+
|
|
28
|
+
const booleanOperator = new OrComposite("booleanOperator", [and, or]);
|
|
29
|
+
const flag = new OrComposite("flags", generateFlagFromList(flagNames));
|
|
30
|
+
const group = new AndComposite("group", [
|
|
31
|
+
openParen,
|
|
32
|
+
new RecursivePattern("flag-expression"),
|
|
33
|
+
closeParen,
|
|
34
|
+
]);
|
|
35
|
+
const flagOrGroup = new OrComposite("flag-or-group", [flag, group]);
|
|
36
|
+
const flagExpression = new RepeatComposite(
|
|
37
|
+
"flag-expression",
|
|
38
|
+
flagOrGroup,
|
|
39
|
+
booleanOperator
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
return flagExpression;
|
|
43
|
+
}
|
|
11
44
|
|
|
12
45
|
describe("TextInspector", () => {
|
|
13
46
|
test("Partial Match", () => {
|
|
@@ -218,19 +251,32 @@ describe("TextInspector", () => {
|
|
|
218
251
|
expect(inspection.isComplete).toBe(false);
|
|
219
252
|
});
|
|
220
253
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
254
|
+
// This is a current bug. Repeat can end on a divider and that isn't right.
|
|
255
|
+
|
|
256
|
+
// test("Suggest another item in the repeat.", () => {
|
|
257
|
+
// const a = new Literal("a", "A");
|
|
258
|
+
// const b = new Literal("b", "B");
|
|
259
|
+
// const space = new Literal("space", " ");
|
|
260
|
+
// const or = new OrComposite("names", [a, b]);
|
|
261
|
+
|
|
262
|
+
// const repeat = new RepeatComposite("repeat", or, space);
|
|
263
|
+
|
|
264
|
+
// const result = TextSuggester.suggest("A B ", repeat);
|
|
226
265
|
|
|
227
|
-
|
|
266
|
+
// expect(result.isComplete).toBe(false);
|
|
267
|
+
// expect(result.options.values[0]).toBe("A");
|
|
268
|
+
// expect(result.options.values[1]).toBe("B");
|
|
269
|
+
// expect(result.options.values.length).toBe(2);
|
|
270
|
+
// });
|
|
228
271
|
|
|
229
|
-
|
|
272
|
+
test("Repeating pattern.", () => {
|
|
273
|
+
const expression = generateExpression(["FlagX", "FlagY", "FlagZ"]);
|
|
274
|
+
const result = TextSuggester.suggest("(FlagX AND ", expression);
|
|
230
275
|
|
|
231
|
-
expect(result.
|
|
232
|
-
expect(result.options.values[0]).toBe("
|
|
233
|
-
expect(result.options.values[1]).toBe("
|
|
234
|
-
expect(result.options.values
|
|
276
|
+
expect(result.options.values.length).toBe(4);
|
|
277
|
+
expect(result.options.values[0]).toBe("FlagX");
|
|
278
|
+
expect(result.options.values[1]).toBe("FlagY");
|
|
279
|
+
expect(result.options.values[2]).toBe("FlagZ");
|
|
280
|
+
expect(result.options.values[3]).toBe("(");
|
|
235
281
|
});
|
|
236
282
|
});
|