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

String literal. #6718

Merged
merged 5 commits into from
Jul 1, 2024
Merged

Conversation

Moderocky
Copy link
Member

Description

Adds a LiteralString.
During string parsing, if the string is 'simple' (has no interpolation inputs or weird parsy bits and bobs) then rather than returning a 'simple' VariableString, it will return a LiteralString. This is a Literal<String>.
Incidentally, this is also a VariableString, so nothing existing will break.

You can now specify %*string% to accept (literal) strings obtainable during init, and use strings in places where only literals are allowed.
Obviously, strings with expressions inside (like "hello %player%") aren't literal and so won't be matched.


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

@Moderocky Moderocky added the enhancement Feature request, an issue about something that could be improved, or a PR improving something. label May 24, 2024
@Moderocky Moderocky requested review from APickledWalrus, sovdeeth and UnderscoreTud and removed request for APickledWalrus and sovdeeth May 24, 2024 14:43
@Moderocky Moderocky mentioned this pull request May 24, 2024
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.

wonderful thank you kenzie

Comment on lines +612 to +613
if (!aClass.getC().isAssignableFrom(String.class))
continue;
Copy link
Member Author

Choose a reason for hiding this comment

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

Literals can only be converted to other literals, so we don't really want to return a literal unless the input actually wants a string (otherwise a lot of places might break because they can't be converted)

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.

some non-critical suggestions


import java.util.Optional;

public class LiteralString extends VariableString implements Literal<String> {
Copy link
Member

Choose a reason for hiding this comment

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

Might be worth adding some javadoc for the class itself

@Moderocky Moderocky added feature-ready A PR/issue that has been approved, tested and can be merged/closed in the next feature version. 2.9 Targeting a 2.9.X version release labels May 31, 2024
@Moderocky Moderocky mentioned this pull request Jun 2, 2024
@APickledWalrus APickledWalrus merged commit 0348a71 into SkriptLang:dev/feature Jul 1, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.9 Targeting a 2.9.X version release enhancement Feature request, an issue about something that could be improved, or a PR improving something. 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.

3 participants