clarity-pattern-parser 3.0.9 → 3.0.10
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/package.json
CHANGED
package/src/TextSuggester.ts
CHANGED
|
@@ -172,15 +172,17 @@ export default class TextSuggester {
|
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
private saveNextToken() {
|
|
175
|
-
|
|
175
|
+
const isCompleteMatch =
|
|
176
176
|
this.patternMatch?.pattern === this.rootPattern &&
|
|
177
|
-
this.cursor?.didSuccessfullyParse()
|
|
178
|
-
|
|
177
|
+
this.cursor?.didSuccessfullyParse();
|
|
178
|
+
const noMatch = this.patternMatch?.astNode == null;
|
|
179
|
+
|
|
180
|
+
if (isCompleteMatch) {
|
|
179
181
|
this.tokens = null;
|
|
180
182
|
return;
|
|
181
183
|
}
|
|
182
184
|
|
|
183
|
-
if (
|
|
185
|
+
if (noMatch) {
|
|
184
186
|
let options = this.rootPattern?.getTokens();
|
|
185
187
|
|
|
186
188
|
options = options?.filter((option: any) => {
|
|
@@ -209,7 +211,7 @@ export default class TextSuggester {
|
|
|
209
211
|
endIndex: this.text.length - 1,
|
|
210
212
|
};
|
|
211
213
|
this.error = null;
|
|
212
|
-
|
|
214
|
+
|
|
213
215
|
return;
|
|
214
216
|
}
|
|
215
217
|
|
|
@@ -3,6 +3,8 @@ import RepeatComposite from "../patterns/composite/RepeatComposite";
|
|
|
3
3
|
import AndComposite from "../patterns/composite/AndComposite";
|
|
4
4
|
import OptionalComposite from "../patterns/composite/OptionalComposite";
|
|
5
5
|
import Literal from "../patterns/value/Literal";
|
|
6
|
+
import Cursor from "../Cursor";
|
|
7
|
+
import OrComposite from "../patterns/composite/OrComposite";
|
|
6
8
|
|
|
7
9
|
describe("RepeatComposite", () => {
|
|
8
10
|
test("Cannot use optional patterns.", () => {
|
|
@@ -24,4 +26,21 @@ describe("RepeatComposite", () => {
|
|
|
24
26
|
|
|
25
27
|
expect(clone.name).toBe("full-names-2");
|
|
26
28
|
});
|
|
29
|
+
|
|
30
|
+
test("parse.", () => {
|
|
31
|
+
const a = new Literal("a", "A");
|
|
32
|
+
const b = new Literal("b", "B");
|
|
33
|
+
const space = new Literal("space", " ");
|
|
34
|
+
const or = new OrComposite("names", [a, b]);
|
|
35
|
+
|
|
36
|
+
const repeat = new RepeatComposite("repeat", or, space);
|
|
37
|
+
const result = repeat.parse(new Cursor("A B"));
|
|
38
|
+
|
|
39
|
+
expect(result?.children[0].value).toBe("A");
|
|
40
|
+
expect(result?.children[0].name).toBe("a");
|
|
41
|
+
expect(result?.children[1].value).toBe(" ");
|
|
42
|
+
expect(result?.children[1].name).toBe("space");
|
|
43
|
+
expect(result?.children[2].value).toBe("B");
|
|
44
|
+
expect(result?.children[2].name).toBe("b");
|
|
45
|
+
});
|
|
27
46
|
});
|