clarity-pattern-parser 3.0.12 → 3.0.14
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 +20 -7
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +20 -7
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +20 -7
- 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 +2 -2
- package/src/patterns/value/RepeatValue.ts +2 -2
- package/src/tests/TextSuggester.test.ts +45 -1
|
@@ -75,7 +75,6 @@ export default class RepeatComposite extends CompositePattern {
|
|
|
75
75
|
this.nodes.push(node);
|
|
76
76
|
|
|
77
77
|
if (node.endIndex === this.cursor.lastIndex()) {
|
|
78
|
-
this.nodes.length = 0;
|
|
79
78
|
this._processMatch();
|
|
80
79
|
break;
|
|
81
80
|
}
|
|
@@ -88,9 +87,10 @@ export default class RepeatComposite extends CompositePattern {
|
|
|
88
87
|
}
|
|
89
88
|
|
|
90
89
|
private _processMatch() {
|
|
90
|
+
const endsOnDivider = this.nodes.length % 2 === 0;
|
|
91
91
|
this.cursor.resolveError();
|
|
92
92
|
|
|
93
|
-
if (
|
|
93
|
+
if (endsOnDivider) {
|
|
94
94
|
this.cursor.throwError(
|
|
95
95
|
new ParseError(
|
|
96
96
|
`Did not find a repeating match of ${this.name}.`,
|
|
@@ -76,7 +76,6 @@ export default class RepeatValue extends ValuePattern {
|
|
|
76
76
|
this.nodes.push(node);
|
|
77
77
|
|
|
78
78
|
if (node.endIndex === this.cursor.lastIndex()) {
|
|
79
|
-
this.nodes.length = 0;
|
|
80
79
|
this._processMatch();
|
|
81
80
|
break;
|
|
82
81
|
}
|
|
@@ -89,9 +88,10 @@ export default class RepeatValue extends ValuePattern {
|
|
|
89
88
|
}
|
|
90
89
|
|
|
91
90
|
private _processMatch() {
|
|
91
|
+
const endsOnDivider = this.nodes.length % 2 === 0;
|
|
92
92
|
this.cursor.resolveError();
|
|
93
93
|
|
|
94
|
-
if (
|
|
94
|
+
if (endsOnDivider) {
|
|
95
95
|
const parseError = new ParseError(
|
|
96
96
|
`Did not find a repeating match of ${this.name}.`,
|
|
97
97
|
this.mark,
|
|
@@ -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", () => {
|
|
@@ -233,4 +266,15 @@ describe("TextInspector", () => {
|
|
|
233
266
|
expect(result.options.values[1]).toBe("B");
|
|
234
267
|
expect(result.options.values.length).toBe(2);
|
|
235
268
|
});
|
|
269
|
+
|
|
270
|
+
test("Repeating pattern.", () => {
|
|
271
|
+
const expression = generateExpression(["FlagX", "FlagY", "FlagZ"]);
|
|
272
|
+
const result = TextSuggester.suggest("(FlagX AND ", expression);
|
|
273
|
+
|
|
274
|
+
expect(result.options.values.length).toBe(4);
|
|
275
|
+
expect(result.options.values[0]).toBe("FlagX");
|
|
276
|
+
expect(result.options.values[1]).toBe("FlagY");
|
|
277
|
+
expect(result.options.values[2]).toBe("FlagZ");
|
|
278
|
+
expect(result.options.values[3]).toBe("(");
|
|
279
|
+
});
|
|
236
280
|
});
|