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

[HELP WANTED] Maybe(?) fixes(?) regex #1793

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Kapu1178
Copy link
Contributor

This pr is basically a shot in the dark. I believe that regex.Find() was broken when it was a global regex. Also impliments proper regex functionality for findtext() and replacetext()

@boring-cyborg boring-cyborg bot added Compiler Involves the OpenDream compiler Runtime Involves the OpenDream server/runtime labels May 16, 2024
Copy link
Contributor Author

@Kapu1178 Kapu1178 left a comment

Choose a reason for hiding this comment

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

english

DMCompiler/DMStandard/Types/Regex.dm Outdated Show resolved Hide resolved
DMCompiler/DMStandard/Types/Regex.dm Outdated Show resolved Hide resolved
@@ -20,14 +20,15 @@
src.flags = flags

proc/Find(haystack, start = 1, end = 0)
return findtext(text, src, start, end)
Copy link
Member

Choose a reason for hiding this comment

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

The runtime replaces this proc with the native proc found in DreamProcNativeRegex.cs so this doesn't do anything.

proc/Replace(haystack, replacement, start = 1, end = 0)
return replacetext(text, src, replacement, start, end)
Copy link
Member

Choose a reason for hiding this comment

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

Same with this proc


proc/Replace_char(haystack, replacement, start = 1, end = 0)
set opendream_unimplemented = TRUE
return haystack
Copy link
Member

Choose a reason for hiding this comment

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

Why was this removed?

Comment on lines +15 to +16
state.GetArgument(1, "start").TryGetValueAsInteger(out int start);
state.GetArgument(2, "end").TryGetValueAsInteger(out int end);
Copy link
Member

Choose a reason for hiding this comment

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

It needs to be verified that these are both treated as 0 for non-integer values.

return await RegexFind(state, state.Src, haystack, start, end);
}

public static async Task<DreamValue> RegexFind(AsyncNativeProc.State state, DreamObject regexInstance, DreamValue haystack, int start, int end) {
Copy link
Member

Choose a reason for hiding this comment

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

Why async? I don't see anything in here that is asynchronous.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just copied this from RegexReplace, not gonna lie!

int start = bundle.GetArgument(2, "Start").MustGetValueAsInteger(); //1-indexed
int end = bundle.GetArgument(3, "End").MustGetValueAsInteger(); //1-indexed
if(!needleArg.TryGetValueAsString(out var needle))
return DreamValue.True;
Copy link
Member

Choose a reason for hiding this comment

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

BYOND returns different values for different combinations of invalid arguments. Are those still replicated?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compiler Involves the OpenDream compiler Runtime Involves the OpenDream server/runtime size/M
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants