clarity-pattern-parser 11.0.4 → 11.0.6
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 +41 -7
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +41 -7
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +41 -7
- package/dist/index.js.map +1 -1
- package/dist/patterns/ExpressionPattern.d.ts +3 -3
- package/package.json +1 -1
- package/src/intellisense/AutoComplete.test.ts +1 -1
- package/src/patterns/ExpressionPattern.test.ts +1 -2
- package/src/patterns/ExpressionPattern.ts +57 -9
- package/src/patterns/PrecedenceTree.test.ts +1 -1
|
@@ -17,7 +17,7 @@ export declare class ExpressionPattern implements Pattern {
|
|
|
17
17
|
private _postfixNames;
|
|
18
18
|
private _binaryPatterns;
|
|
19
19
|
private _binaryNames;
|
|
20
|
-
private
|
|
20
|
+
private _associationMap;
|
|
21
21
|
private _precedenceMap;
|
|
22
22
|
private _shouldStopParsing;
|
|
23
23
|
private _precedenceTree;
|
|
@@ -55,10 +55,10 @@ export declare class ExpressionPattern implements Pattern {
|
|
|
55
55
|
test(text: string, record?: boolean): boolean;
|
|
56
56
|
exec(text: string, record?: boolean): ParseResult;
|
|
57
57
|
getTokens(): string[];
|
|
58
|
-
getTokensAfter(
|
|
58
|
+
getTokensAfter(childReference: Pattern): string[];
|
|
59
59
|
getNextTokens(): string[];
|
|
60
60
|
getPatterns(): Pattern[];
|
|
61
|
-
getPatternsAfter(
|
|
61
|
+
getPatternsAfter(childReference: Pattern): Pattern[];
|
|
62
62
|
getNextPatterns(): Pattern[];
|
|
63
63
|
find(predicate: (p: Pattern) => boolean): Pattern | null;
|
|
64
64
|
clone(name?: string): Pattern;
|
package/package.json
CHANGED
|
@@ -430,7 +430,7 @@ describe("AutoComplete", () => {
|
|
|
430
430
|
test("Repeat with bad trailing content", () => {
|
|
431
431
|
const flags = ["FlagA", "FlagB", "FlagC"];
|
|
432
432
|
const pattern = generateExpression(flags);
|
|
433
|
-
const result = new AutoComplete(pattern).suggestFor("FlagA AND FlagAlkjhgB")
|
|
433
|
+
const result = new AutoComplete(pattern).suggestFor("FlagA AND FlagAlkjhgB");
|
|
434
434
|
|
|
435
435
|
expect(result.options).toEqual([]);
|
|
436
436
|
expect(result.ast?.value).toBe("FlagA AND FlagA");
|
|
@@ -163,8 +163,7 @@ describe("Expression Pattern", () => {
|
|
|
163
163
|
const expression = createExpressionPattern();
|
|
164
164
|
|
|
165
165
|
const autoComplete = new AutoComplete(expression);
|
|
166
|
-
const suggestion = autoComplete.suggestFor("a");
|
|
167
|
-
|
|
166
|
+
const suggestion = autoComplete.suggestFor("a ? b ");
|
|
168
167
|
expect(suggestion).toBe(suggestion);
|
|
169
168
|
});
|
|
170
169
|
});
|
|
@@ -25,7 +25,7 @@ export class ExpressionPattern implements Pattern {
|
|
|
25
25
|
private _postfixNames: string[];
|
|
26
26
|
private _binaryPatterns: Pattern[];
|
|
27
27
|
private _binaryNames: string[];
|
|
28
|
-
private
|
|
28
|
+
private _associationMap: Record<string, Association>;
|
|
29
29
|
private _precedenceMap: Record<string, number>;
|
|
30
30
|
private _shouldStopParsing: boolean;
|
|
31
31
|
private _precedenceTree: PrecedenceTree;
|
|
@@ -91,12 +91,12 @@ export class ExpressionPattern implements Pattern {
|
|
|
91
91
|
this._postfixNames = [];
|
|
92
92
|
this._binaryPatterns = [];
|
|
93
93
|
this._binaryNames = [];
|
|
94
|
-
this.
|
|
94
|
+
this._associationMap = {};
|
|
95
95
|
this._precedenceMap = {};
|
|
96
96
|
this._originalPatterns = patterns;
|
|
97
97
|
this._patterns = this._organizePatterns(patterns);
|
|
98
98
|
this._shouldStopParsing = false;
|
|
99
|
-
this._precedenceTree = new PrecedenceTree(this._precedenceMap, this.
|
|
99
|
+
this._precedenceTree = new PrecedenceTree(this._precedenceMap, this._associationMap);
|
|
100
100
|
|
|
101
101
|
if (this._atomPatterns.length === 0) {
|
|
102
102
|
throw new Error("Need at least one terminating pattern with an 'expression' pattern.");
|
|
@@ -143,9 +143,9 @@ export class ExpressionPattern implements Pattern {
|
|
|
143
143
|
this._binaryNames.push(name);
|
|
144
144
|
|
|
145
145
|
if (pattern.type === "right-associated") {
|
|
146
|
-
this.
|
|
146
|
+
this._associationMap[name] = Association.right;
|
|
147
147
|
} else {
|
|
148
|
-
this.
|
|
148
|
+
this._associationMap[name] = Association.left;
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
finalPatterns.push(clone);
|
|
@@ -183,7 +183,7 @@ export class ExpressionPattern implements Pattern {
|
|
|
183
183
|
pattern = this._unwrapAssociationIfNecessary(pattern);
|
|
184
184
|
|
|
185
185
|
const firstChild = pattern.children[0];
|
|
186
|
-
const lastChild = pattern.children[1];
|
|
186
|
+
const lastChild = pattern.children[pattern.children.length -1];
|
|
187
187
|
const firstChildIsReference = this._isRecursiveReference(firstChild);
|
|
188
188
|
const lastChildIsReference = this._isRecursiveReference(lastChild);
|
|
189
189
|
|
|
@@ -238,7 +238,7 @@ export class ExpressionPattern implements Pattern {
|
|
|
238
238
|
}
|
|
239
239
|
|
|
240
240
|
private _isRecursiveReference(pattern: Pattern) {
|
|
241
|
-
if (pattern == null){
|
|
241
|
+
if (pattern == null) {
|
|
242
242
|
return false;
|
|
243
243
|
}
|
|
244
244
|
return pattern.type === "reference" && pattern.name === this.name;
|
|
@@ -457,7 +457,31 @@ export class ExpressionPattern implements Pattern {
|
|
|
457
457
|
return this.atomPatterns.map(p => p.getTokens()).flat();
|
|
458
458
|
}
|
|
459
459
|
|
|
460
|
-
getTokensAfter(
|
|
460
|
+
getTokensAfter(childReference: Pattern): string[] {
|
|
461
|
+
if (this._prefixPatterns.includes(childReference) || this._binaryPatterns.includes(childReference)) {
|
|
462
|
+
const atomTokens = this._atomPatterns.map(p => p.getTokens()).flat();
|
|
463
|
+
const prefixTokens = this.prefixPatterns.map(p => p.getTokens()).flat();
|
|
464
|
+
|
|
465
|
+
return [...prefixTokens, ...atomTokens];
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
if (this._atomPatterns.includes(childReference)) {
|
|
469
|
+
const postfixTokens = this.prefixPatterns.map(p => p.getTokens()).flat();
|
|
470
|
+
|
|
471
|
+
if (postfixTokens.length === 0){
|
|
472
|
+
return this._binaryPatterns.map(p => p.getTokens()).flat();
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
return postfixTokens;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
if (this._postfixPatterns.includes(childReference)) {
|
|
479
|
+
const postfixTokens = this.postfixPatterns.map(p => p.getTokens()).flat();
|
|
480
|
+
const binaryTokens = this._binaryPatterns.map(p => p.getTokens()).flat();
|
|
481
|
+
|
|
482
|
+
return [...postfixTokens, ...binaryTokens];
|
|
483
|
+
}
|
|
484
|
+
|
|
461
485
|
return [];
|
|
462
486
|
}
|
|
463
487
|
|
|
@@ -473,7 +497,31 @@ export class ExpressionPattern implements Pattern {
|
|
|
473
497
|
return this.atomPatterns.map(p => p.getPatterns()).flat();
|
|
474
498
|
}
|
|
475
499
|
|
|
476
|
-
getPatternsAfter(
|
|
500
|
+
getPatternsAfter(childReference: Pattern): Pattern[] {
|
|
501
|
+
if (this._prefixPatterns.includes(childReference) || this._binaryPatterns.includes(childReference)) {
|
|
502
|
+
const atomPatterns = this._atomPatterns.map(p => p.getPatterns()).flat();
|
|
503
|
+
const prefixPatterns = this.prefixPatterns.map(p => p.getPatterns()).flat();
|
|
504
|
+
|
|
505
|
+
return [...prefixPatterns, ...atomPatterns];
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
if (this._atomPatterns.includes(childReference)) {
|
|
509
|
+
const postfixPatterns = this.prefixPatterns.map(p => p.getPatterns()).flat();
|
|
510
|
+
|
|
511
|
+
if (postfixPatterns.length === 0){
|
|
512
|
+
return this._binaryPatterns.map(p => p.getPatterns()).flat();
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
return postfixPatterns;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
if (this._postfixPatterns.includes(childReference)) {
|
|
519
|
+
const postfixPaterns = this.postfixPatterns.map(p => p.getPatterns()).flat();
|
|
520
|
+
const binaryPatterns = this._binaryPatterns.map(p => p.getPatterns()).flat();
|
|
521
|
+
|
|
522
|
+
return [...postfixPaterns, ...binaryPatterns];
|
|
523
|
+
}
|
|
524
|
+
|
|
477
525
|
return [];
|
|
478
526
|
}
|
|
479
527
|
|
|
@@ -248,7 +248,7 @@ describe("Precedence Tree", () => {
|
|
|
248
248
|
expect(result?.toCycleFreeObject()).toEqual(expected.toCycleFreeObject());
|
|
249
249
|
});
|
|
250
250
|
|
|
251
|
-
test("
|
|
251
|
+
test("mul Partial Binary With Greater Precedence", () => {
|
|
252
252
|
const tree = new PrecedenceTree({
|
|
253
253
|
mul: 0,
|
|
254
254
|
add: 1,
|