-
-
Notifications
You must be signed in to change notification settings - Fork 368
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
Fix math order #3736
Fix math order #3736
Conversation
Imo it will be better to split arthimetic pure logic and expression. Also, dont forget to comment methods who aren't explicits (if i remember, i'll submit changes where i think comment or Javadoc is necessary). |
I don't understand what you mean by this, can you explain it? |
as possible, split more methods/enums in a other file (it's my personal opinion, it can be false) |
I agree, but that would probably mean placing it in |
imo, it can be do for arithmetic expression because it's a major expression |
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.
epic pr 😎
I recommend adding a test just in case (it wouldn't hurt to have). I think it would be okay to split it up like discussed in the comments. Another review from another developer would be appreciated.
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.
Looks pretty good. It could make use of encapsulation in some places, but that's more of a nitpick than anything.
src/main/java/ch/njol/skript/expressions/arithmetic/ArithmeticChain.java
Outdated
Show resolved
Hide resolved
src/main/java/ch/njol/skript/expressions/arithmetic/ArithmeticChain.java
Outdated
Show resolved
Hide resolved
src/main/java/ch/njol/skript/expressions/arithmetic/ExprArithmetic.java
Outdated
Show resolved
Hide resolved
src/test/skript/tests/regressions/535-math is done in the wrong order.sk
Outdated
Show resolved
Hide resolved
I would do it on initialization if possible, i.e.: literals or if we can simplify the expression. In other cases, parsing can be done at runtime. |
Description
Fixes Skript's order of mathematical operations.
Each pattern now has all permutations of surrounding parentheses on the
%number%
s, because this information would otherwise be lost in the parsing process. The patterns with parentheses should come first, otherwise it wouldn't have effect, as Skript would match it against the other patterns.The expression forms a chain of alternating expression and operators on
init
(e.g.[Literal(5), Operator(PLUS), Literal(3)]
). The first part of the chain is the first parameter, the second is the operator and the third is the second parameter. If either of the two parameters is an instance ofExprArithmetic
(and is not surrounded by parentheses), it is not added to the chain, but instead parameters chain is added. This chain is then parsed using the proper operation order, and this parsed chain (forming a tree structure) is used for evaluating the expression.Two things I'd appreciate feedback on:
init
, or in the first evaluation (since doing it ininit
is useless for any innerExprArithmetic
s, which won't be if it's called inget
, with the tradeoff of having to parse it on runtime)Target Minecraft Versions: any
Requirements: none
Related Issues: #535