-
-
Notifications
You must be signed in to change notification settings - Fork 389
Syntax Simplification #7841
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: dev/feature
Are you sure you want to change the base?
Syntax Simplification #7841
Conversation
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.
Looking good so far. Do you think Arithmetic tests that verify the SyntaxElement is a Literal would be possible?
src/main/java/org/skriptlang/skript/lang/simplification/SimplifiedLiteral.java
Show resolved
Hide resolved
…) on expressions capable of 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.
Looking really good. I might prefer to see the classes of the new simplification package under ch.njol. Mainly, given that rewritten classes are possible in the future, it'll make compatibility easier to handle
* Gets the original expression this literal was created from. | ||
* @return the original expression | ||
*/ | ||
public Expression<T> getPresimplifiedExpr() { |
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.
Isn't this just the same as Expression#getSource
? Could you override that?
@@ -375,6 +375,9 @@ private static void userDisableHooks(Class<? extends Hook<?>> hookClass, boolean | |||
public static final Option<Integer> variableChangesUntilSave = new Option<>("variable changes until save", 1000) | |||
.setter(FlatFileStorage::setRequiredChangesForResave); | |||
|
|||
public static final Option<Boolean> simplifySyntaxesOnParse = new Option<>("simplify syntax on parse", true) |
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 would include a comment that this option is intentionally omitted from the config. that is, it has to be added manually
|
||
@Override | ||
public Expression<? extends Number> simplify() { | ||
// as of INSERT VERSION, there are no literal locations but this is implemented for when pure functions can |
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.
just want to note that the insert version script won't cover cases like this
@Override | ||
@Nullable | ||
public Class<?>[] acceptChange(final ChangeMode mode) { | ||
if ((mode == ChangeMode.SET || mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) && getExpr().isSingle() && ChangerUtils.acceptsChange(getExpr(), ChangeMode.SET, Location.class)) | ||
public Class<?>[] acceptChange(final Changer.ChangeMode mode) { |
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.
Should keep ChangeMode directly imported
Expression<? extends T> convertedExpression = source.simplify().getConvertedExpression(to); | ||
if (convertedExpression != null) | ||
return convertedExpression; | ||
source = source.simplify(); |
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 this change? Calling getConvertedExpression again could potentially result in a Literal of the desired (conversion) type, which seems like something we'd want. Or is the concern over losing the source information?
Description
Skript has always had this little method on Expression called simplify(), which has never been implemented. It's intended to take expressions and, if possible, simplify them to Literals or similarly simplify the code tree.
This PR attempts to properly implement that idea via a Simplifiable interface. A config option is added to allow users to opt out if issues arise.
Every element is simplified immediately after init() in SkriptParser. In addition, it may be called at any time by parent elements, though it should be ensured that no other objects maintain critical references to the element, as simplify may return new objects.
ExprArithmetic is a special case that can only be simplified once all elements in the chain have been parsed and ordered, so it requires checking the ParsingStack to see if it's the top-level element in the chain. If so, it can then call simplify recursively on all elements in the chain.
Todo:
Target Minecraft Versions: any
Requirements: none
Related Issues: none