You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, for binary and unary expressions, the operator is being set as a Token. However, this can be simplified by introducing new enum types: BinaryOperator, UnaryOperator, AssignmentOperator, SetIndexOperator.
Example:
enumBinaryOperator{Add,Sub,Div,Mul,Mod,Equality,// ... etc}enumUnaryOperator{Add,Sub}// Binary Expression would bestructBinary{publeft:Box<Expr>,pub right Box<Expr>,puboperator:BinaryOperator}// And similarly Unary Expression, and so on..
These would be less bloated than having a token in each expression.
Less Error prone since you get compile time check when setting the operator in the expressions. For instance, you can't set the BinaryOperator to some arbitrary token. I'm sure the appropriate checks are being made, however, this is cleaner IMO.
@tuqqu, I have created a draft PR: #5 to show the proof of concept. Let me know if any improvements can be made so that I can start updating other expressions to use operators.
To provide meaningful error messages, we must have access to the token location. Replacing Token with these operator enums does not make sense in this case.
Yes, basically we always need a Token to rely on. I see the profit of having proper enums for each type of an operator, but something is to be done with token metadata (location and later even a file path it was in, when we have file imports).
For simplicity I'd leave it as is.
Currently, for binary and unary expressions, the operator is being set as a
Token
. However, this can be simplified by introducing new enum types:BinaryOperator
,UnaryOperator
,AssignmentOperator
,SetIndexOperator
.Example:
What do you think @tuqqu?
The text was updated successfully, but these errors were encountered: