clarity-pattern-parser 10.2.11 → 10.2.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 +8 -2
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +8 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +8 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/ast/Node.test.ts +20 -2
- package/src/ast/Node.ts +7 -1
- package/src/patterns/ExpressionPattern.test.ts +11 -11
- package/src/patterns/ExpressionPattern.ts +2 -2
package/package.json
CHANGED
package/src/ast/Node.test.ts
CHANGED
|
@@ -392,6 +392,26 @@ describe("Node", () => {
|
|
|
392
392
|
expect(parent.endIndex).toBe(11);
|
|
393
393
|
});
|
|
394
394
|
|
|
395
|
+
test("Normalize values and index deep", () => {
|
|
396
|
+
const firstChild = new Node("literal", "first", 0, 0, [], "first");
|
|
397
|
+
const secondChild = new Node("literal", "second", 0, 0, [], "second");
|
|
398
|
+
const grandChild = new Node("literal", "three", 0, 0, [], "three");
|
|
399
|
+
const parent = new Node("literal", "parent", 0, 0);
|
|
400
|
+
|
|
401
|
+
parent.appendChild(firstChild);
|
|
402
|
+
parent.appendChild(secondChild);
|
|
403
|
+
|
|
404
|
+
parent.normalize();
|
|
405
|
+
|
|
406
|
+
secondChild.appendChild(grandChild);
|
|
407
|
+
parent.normalize();
|
|
408
|
+
|
|
409
|
+
expect(parent.startIndex).toBe(0);
|
|
410
|
+
expect(parent.firstIndex).toBe(0);
|
|
411
|
+
expect(parent.lastIndex).toBe(9);
|
|
412
|
+
expect(parent.endIndex).toBe(10);
|
|
413
|
+
});
|
|
414
|
+
|
|
395
415
|
test("Normalize values with no values", () => {
|
|
396
416
|
const node = new Node("literal", "node", 0, 0, [], "");
|
|
397
417
|
node.normalize();
|
|
@@ -451,8 +471,6 @@ describe("Node", () => {
|
|
|
451
471
|
Node.createValueNode("aunt", "aunt")
|
|
452
472
|
]);
|
|
453
473
|
|
|
454
|
-
|
|
455
|
-
|
|
456
474
|
expect(result.toJson()).toBe(expected.toJson());
|
|
457
475
|
});
|
|
458
476
|
|
package/src/ast/Node.ts
CHANGED
|
@@ -291,11 +291,17 @@ export class Node {
|
|
|
291
291
|
|
|
292
292
|
normalize(startIndex = this._firstIndex): number {
|
|
293
293
|
let length = 0;
|
|
294
|
+
let runningOffset = startIndex;
|
|
294
295
|
|
|
295
296
|
if (this.children.length === 0) {
|
|
296
297
|
length = this._value.length;
|
|
297
298
|
} else {
|
|
298
|
-
|
|
299
|
+
for (let x = 0; x < this.children.length; x++) {
|
|
300
|
+
const child = this.children[x];
|
|
301
|
+
const childLength = child.normalize(runningOffset);
|
|
302
|
+
runningOffset += childLength;
|
|
303
|
+
length += childLength;
|
|
304
|
+
}
|
|
299
305
|
}
|
|
300
306
|
|
|
301
307
|
this._firstIndex = startIndex;
|
|
@@ -76,7 +76,7 @@ function createExpressionPattern() {
|
|
|
76
76
|
]);
|
|
77
77
|
|
|
78
78
|
const expression = new ExpressionPattern("expression", [
|
|
79
|
-
multDivExpression,
|
|
79
|
+
new RightAssociatedPattern(multDivExpression),
|
|
80
80
|
addSubExpression,
|
|
81
81
|
boolExpression,
|
|
82
82
|
ternary,
|
|
@@ -100,20 +100,20 @@ describe("Expression Pattern", () => {
|
|
|
100
100
|
test("Single Expression", () => {
|
|
101
101
|
const expression = createExpressionPattern();
|
|
102
102
|
let result = expression.exec("a || c || b / c * a + d");
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
103
|
+
result = expression.exec("a + b");
|
|
104
|
+
result = expression.exec("a + b * c * d");
|
|
105
|
+
result = expression.exec("a + b * c || d + e");
|
|
106
|
+
result = expression.exec("(a + b) * (c + d)");
|
|
107
|
+
result = expression.exec("(a + b) * c + (d + e)");
|
|
108
|
+
result = expression.exec("a + b * c ? d : e");
|
|
109
|
+
result = expression.exec("a + b * (a + b * c ? d : e) ? d : e");
|
|
110
|
+
result = expression.exec("a + b * a + b * c ? d : e ? d : e");
|
|
111
|
+
result = expression.exec("a + b * ?");
|
|
112
112
|
|
|
113
113
|
expect(result).toBe(result);
|
|
114
114
|
});
|
|
115
115
|
|
|
116
|
-
test("Options like", ()=>{
|
|
116
|
+
test("Options like", () => {
|
|
117
117
|
const expression = createOptionsExpression();
|
|
118
118
|
const autoComplete = new AutoComplete(expression);
|
|
119
119
|
const suggestion = autoComplete.suggestFor("a");
|
|
@@ -301,7 +301,7 @@ export class ExpressionPattern implements Pattern {
|
|
|
301
301
|
}
|
|
302
302
|
break;
|
|
303
303
|
}
|
|
304
|
-
}
|
|
304
|
+
}
|
|
305
305
|
|
|
306
306
|
cursor.resolveError();
|
|
307
307
|
cursor.moveTo(onIndex);
|
|
@@ -332,7 +332,7 @@ export class ExpressionPattern implements Pattern {
|
|
|
332
332
|
lastBinaryNode = node;
|
|
333
333
|
} else if (lastBinaryNode != null && lastUnaryNode != null && delimiterNode != null) {
|
|
334
334
|
const precedence = this._precedenceMap[name];
|
|
335
|
-
const lastPrecendece = lastBinaryNode == null ? 0 : this._precedenceMap[lastBinaryNode.name]
|
|
335
|
+
const lastPrecendece = lastBinaryNode == null ? 0 : this._precedenceMap[lastBinaryNode.name] == null ? -1 : this._precedenceMap[lastBinaryNode.name];
|
|
336
336
|
const association = this._binaryAssociation[i];
|
|
337
337
|
|
|
338
338
|
if (precedence === lastPrecendece && association === Association.right) {
|