Skip to content
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

Secspressions! #7037

Merged
merged 27 commits into from
Nov 23, 2024
Merged

Secspressions! #7037

merged 27 commits into from
Nov 23, 2024

Conversation

Moderocky
Copy link
Member

@Moderocky Moderocky commented Sep 5, 2024

Description

Adds a special type of expression, the SectionExpression!

SectionExpressions are like simple expressions, but they are allowed to start a section when used in a compatible effect.

This means that a regular effect can be followed by a section iff it contains a section expression.
The expression is allowed to determine the parsing/loading of the following section.

Its only difference from a regular expression is that it may be given a (nullable) SectionNode and List<TriggerItem> during init as an EffectSection would.

Note: this is just API, no new syntax is included in this PR.

More Info

Q: Does this change any existing syntax?
A: No.

Q: Does a section expression need to have a section?
A: No, like an EffectSection it could be used as a regular expression, but this is up to the implementation.

Q: What are the possible uses of this?
A: It's mainly offered for addons, but potentially future syntax. You can easily create 'lambda'-style things like below:

set {_my sword} to a diamond sword:
    set the item's name to "swordzie"
give {_my sword} to player
set {_runnable} to a new runnable:
    broadcast "hello"
# The expression can choose to run the code when it likes, or never

run {_runnable} # broadcasts hello
run {_runnable} # broadcasts hello
set {_java} to some java code:
    System.out.println("hello");
# The section actually has authority over how/whether to parse the raw text node
# so you can make pretty much anything with it

Note: these are just examples of what people might do with the API. None are included in this pull request.

Q: What happens if I use a section expression inside a line that's already a section header, like a condition/loop/while? E.g. loop <my section expression>:
A: This will produce a parse-time error.

Q: What happens if I use multiple section expressions in one line? E.g. teleport <my section expression> to <my section expression>:
A: This will produce a parse-time error.

Q: What happens if I add a colon : and indent code, but have no section expression/condition/regular section before it?
A: This will produce a parse-time error.

Q: Is there a restriction on where I can use section expressions?
A: Technically no, as long as: A) it's not in a regular section line, B) there isn't already a section expression in the line. Obviously they look better in some lines (set) than others (teleport or whatever) but there is deliberately no restriction on this so that addons can implement them how they like.

Q: Is code in the section automatically run?
A: No. Everything is left up to the expression, as in an EffectSection. That means you can run the code when the expression is requested, run it later, never run it, or even have something that isn't code in the section. You get the raw SectionNode during init, and complete freedom how to process it.


Target Minecraft Versions: any
Requirements: none
Related Issues: #6536, closes #4472

Copy link
Member

@sovdeeth sovdeeth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good but i'd like to see more documentation on the new classes

src/test/skript/tests/misc/expression sections.sk Outdated Show resolved Hide resolved
src/test/skript/tests/syntaxes/sections/SecParse.sk Outdated Show resolved Hide resolved
@sovdeeth sovdeeth added the feature Pull request adding a new feature. label Sep 6, 2024
@Moderocky Moderocky marked this pull request as ready for review September 6, 2024 07:55
@Moderocky Moderocky added enhancement Feature request, an issue about something that could be improved, or a PR improving something. 2.10 Targeting a 2.10.X version release labels Sep 6, 2024
}

@ApiStatus.Internal
protected boolean canInitSafely() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used anywhere?

@Moderocky Moderocky added the feature-ready A PR/issue that has been approved, tested and can be merged/closed in the next feature version. label Sep 22, 2024
@Phill310 Phill310 mentioned this pull request Sep 25, 2024
13 tasks
Copy link
Member

@APickledWalrus APickledWalrus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good

Copy link
Member

@APickledWalrus APickledWalrus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few final touches

Copy link
Member

@APickledWalrus APickledWalrus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be good to go now

@sovdeeth sovdeeth merged commit 59b1ff4 into SkriptLang:dev/feature Nov 23, 2024
5 checks passed
@Moderocky Moderocky deleted the expression-sections branch November 23, 2024 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.10 Targeting a 2.10.X version release enhancement Feature request, an issue about something that could be improved, or a PR improving something. feature Pull request adding a new feature. feature-ready A PR/issue that has been approved, tested and can be merged/closed in the next feature version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants