Rewrite Custom Syntax#165
Conversation
# Conflicts: # build.gradle # src/main/java/com/btk5h/skriptmirror/ParseOrderWorkarounds.java # src/main/java/com/btk5h/skriptmirror/SkriptMirror.java # src/main/java/com/btk5h/skriptmirror/skript/custom/ExprExpression.java # src/main/java/com/btk5h/skriptmirror/skript/custom/ExprParseTags.java # src/main/java/com/btk5h/skriptmirror/skript/custom/ExprRawExpression.java # src/main/java/com/btk5h/skriptmirror/skript/reflect/ExprJavaCall.java # src/main/java/org/skriptlang/reflect/syntax/custom/event/EventValuesEntryData.java # src/main/java/org/skriptlang/reflect/syntax/custom/expression/ChangerEntryData.java # src/main/java/org/skriptlang/reflect/syntax/event/elements/CustomEvent.java # src/main/java/org/skriptlang/reflect/syntax/event/elements/EffCallEvent.java # src/main/java/org/skriptlang/reflect/syntax/event/elements/ExprCustomEvent.java # src/main/java/org/skriptlang/reflect/syntax/event/elements/ExprCustomEventValue.java # src/main/java/org/skriptlang/reflect/syntax/event/elements/ExprEventData.java # src/main/java/org/skriptlang/reflect/syntax/event/elements/ExprReplacedEventValue.java # src/main/java/org/skriptlang/reflect/syntax/event/elements/StructCustomEvent.java # src/main/java/org/skriptlang/reflect/syntax/expression/elements/ExprChangeValue.java # src/main/java/org/skriptlang/reflect/syntax/expression/elements/StructCustomExpression.java
…r than the ParserInstance
sovdeeth
left a comment
There was a problem hiding this comment.
I haven't looked through super closely but this seems fantastic from skimming it
No glaring issues (except the lack of docs annotations!)
origins and priorities should probably be handled automatically for the most part (may want to use an origin-applying registry)
The logic for the custom events looks great, good usage of ERS
# Conflicts: # build.gradle
APickledWalrus
left a comment
There was a problem hiding this comment.
Truly excellent work!
I'm going to ask that you add Documentation annotations for all of these elements. It would be nice to include skript-reflect on the new docs website 🙂
Side question: Shouldn't the new package be something like org.skriptlang.skriptreflect? (akin to org.skriptlang.skriptworldguard). I feel like the organization is a bit odd in general too. I think it might make sense to have a single subpackage like elements with further subpackages java, syntax, etc.
APickledWalrus
left a comment
There was a problem hiding this comment.
Looks great. Just about ready!
...but docs 🥺
| public static void register(SyntaxRegistry registry) { | ||
| registry.register(SyntaxRegistry.EXPRESSION, SyntaxInfo.Expression.builder(ExprParseTags.class, String.class) | ||
| .supplier(ExprParseTags::new) | ||
| .addPattern("[the] [parse[r]] tags") |
There was a problem hiding this comment.
| .addPattern("[the] [parse[r]] tags") | |
| .addPattern("[the] [:parse[r]] tags") |
Forgot this
| return getNext(); | ||
|
|
||
| Object locals = Variables.copyLocalVariables(effectEvent.getDirectEvent()); | ||
| new Thread(() -> { |
There was a problem hiding this comment.
What's this doing or what's the purpose?
There was a problem hiding this comment.
honestly not sure, i just ported it from the old custom effect logic. im guessing its a way to preserve local variables in async effects?
There was a problem hiding this comment.
So this is to restore local variables for delays effects when re-starting the code after the effect call, but it ends up with a memory leak if the user never calls continue.
What we should do instead is store the localvariables in the EffectTriggerEvent and use Variables.withLocalVariables when walking next in setContinue
| Variables.setLocalVariables(effectEvent.getDirectEvent(), locals); | ||
| } catch (InterruptedException ignored) {} | ||
| }).start(); | ||
| return null; |
There was a problem hiding this comment.
Delayed effects do not ever run the code after them, if you don't continue. Is this intended? I think it should either have an implicit continue if it reaches the end without continue, or have an error of some sort.
> test-reflect
[19:20:57 INFO]: 1
[19:20:57 INFO]: a
[19:20:57 INFO]: b
effect run after this please:
trigger:
broadcast "a"
delay the effect
broadcast "b"
command test-reflecT:
trigger:
broadcast "1"
run after this please
broadcast "2"
| return getNext(); | ||
|
|
||
| Object locals = Variables.copyLocalVariables(effectEvent.getDirectEvent()); | ||
| new Thread(() -> { |
There was a problem hiding this comment.
So this is to restore local variables for delays effects when re-starting the code after the effect call, but it ends up with a memory leak if the user never calls continue.
What we should do instead is store the localvariables in the EffectTriggerEvent and use Variables.withLocalVariables when walking next in setContinue
Problem
The current custom syntax implementation is built on very old Skript API, when modifying syntax registries at runtime wasn't natively supported. This led to code relying on hacky methods and workarounds to achieve this type of behavior, as a byproduct, the codebase for this system was extremely hard to follow, fragmented and difficult to maintain.
Solution
Rewrite the custom syntax system from the ground up to use the registration API, significantly improving its readability, maintainability and consistency.
Testing Completed
Manual testing
Supporting Information
This rewrite should not introduce any user-facing breaking changes
Review Notice
If you are reviewing this pull request, I suggest starting from the
org.skriptlang.reflect.syntax.custom.sharedpackage, as everything is built on top of the base classes found there.Completes: none
Related: none
AI assistance: none