-
Notifications
You must be signed in to change notification settings - Fork 65
[IMP] evaluation: implement curly brackets #7212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
df549b5
to
bb47554
Compare
Allow entering literal arrays when composing formulas using curly brackets {}. Task: 4735250
bb47554
to
420ca7f
Compare
function leftOperandNeedsParenthesis(operationAST: ASTOperation | ASTUnaryOperation): boolean { | ||
const mainOperator = operationAST.value; | ||
const leftOperation = "left" in operationAST ? operationAST.left : operationAST.operand; | ||
if (leftOperation.type !== "BIN_OPERATION") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why have you changed these lines ? It does the same thing (except the assignment of leftOperator), doesn't it ?
if (rightOperation.type !== "BIN_OPERATION") { | ||
return false; | ||
} | ||
const rightPriority = OP_PRIORITY[rightOperation.value]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same questions as above
} | ||
if (nextToken.type === "ARRAY_ROW_SEPARATOR") { | ||
tokens.shift(); | ||
if (expectValue) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we want to have an empty cell inside the row of an array ? Isn't there any case where we sohuld want it ?
")": { type: "RIGHT_PAREN", value: ")" }, | ||
} as const; | ||
|
||
const braces = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: Maybe we can put these just before tokenizeBraces ?
export function extractFormulaIdFromToken(tokenAtCursor: EnrichedToken) { | ||
const idAst = tokenAtCursor.functionContext?.args[0]; | ||
if (!idAst || !["STRING", "NUMBER"].includes(idAst.type)) { | ||
if (!idAst || (idAst.type !== "STRING" && idAst.type !== "NUMBER")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: Another useless diff. If you ally want to add them, maybe make another commit ?
} | ||
const pivotFormulaId = extractFormulaIdFromToken(tokenAtCursor); | ||
const pivotId = this.getters.getPivotId(pivotFormulaId); | ||
if (pivotFormulaId === undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All these changes should go in another commit with all the others minor changes you made to improve the code
expect(() => parse("={1;}")).toThrow("Unexpected empty array element"); | ||
}); | ||
|
||
test("array literal with mismatched row length not throws", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
array literal with mismatched row length DOES not throw
Task: 4735250