Skript icon indicating copy to clipboard operation
Skript copied to clipboard

Syntax Simplification

Open sovdeeth opened this issue 9 months ago • 0 comments

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:

  • [x] Properly simplify ConvertedExpressions. The existing method was stripping the converting part off a lot of converted expressions.
  • [x] Implement simplify on many more expressions that could support it.

Target Minecraft Versions: any Requirements: none Related Issues: none

sovdeeth avatar Apr 30 '25 21:04 sovdeeth