-
Notifications
You must be signed in to change notification settings - Fork 66
[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
bb47554 to
420ca7f
Compare
| @@ -332,20 +354,21 @@ export function astToFormula(ast: AST): string { | |||
| 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 ?
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.
These are some minor changes made when I re-dived into the code to better understand what it does. But in fact this is refactoring and does not belong here. I am removing it as well as the others you mentioned. ;)
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.
I didn't say anything; the change is necessary since I created a new AST (ASTArray) that no longer has the value attribute.
So, should we avoid this by keeping value to store the matrix and thus losing comprehension? It's up to the team to decide.
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.
Then shoudn't we also do the same change for mainOperator 2 lines above ?
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.
This is just so TypeScript can compile on
https://github.com/odoo/o-spreadsheet/pull/7212/files#diff-88a81a3427c2adbad1c2ca7ed98a682c8145fc3487db8eb01e60155b8d204043R361
mainOperator is defined as ASTOperation, so we can be sure that value exists on it.
| } | ||
| 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 ?
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.
Here, I've chosen to arbitrarily replicate Google's behavior. But we can ask ourselves why they return an error directly to the parser:
In their mindset, curly brackets are used to aggregate objects if and only if their dimensions are compatible. An empty value here would correspond to an object without dimensions, which would therefore not be compatible with the other objects.
--> So they allow themselves to return the error directly to the parser to avoid unnecessary evaluation.
(I suppose)
To the question, how to introduce empty cells: using the value 0, or a subsection composed of several 0, e.g.:
={ A1:B2, {0,0;0,0} }
| 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 ?
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 answer :)
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.
How can this be the same "maybe we don't have value" answer ? Here we have exactly the same behavior, don't we ?
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.
typescript fails to infer that with includes the type can only be "STRING" or "NUMBER". So it assumes it can also be "ARRAY" and the code fails to compile.
420ca7f to
eee6b87
Compare
Allow entering literal arrays when composing formulas using curly brackets {}.
Task: 4735250
eee6b87 to
407e955
Compare

Task: 4735250