-
-
Notifications
You must be signed in to change notification settings - Fork 97
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
Give match statements a "next" keyword instead of "continue" #4667
Comments
Related to #160. |
There is also no way to escape several levels of nested for loops or while loops at the same time, and a new keyword wouldn't solve anything there. |
I deleted my original response, as I felt it was somewhat presumptive, but I'm not quite satisfied with this answer. Everything I've read says that a case-switch statement is not a loop, so presumably you would not be escaping from a nested |
My point was that there are other cases where you might want to break or continue with several layers of scopes nested. And other cases could not be helped by a new keyword, because they are homogeneous and use the same syntax. If your main issue is that you need to break from the parent scope, then this is just a tiny change that doesn't help a vast majority of cases. |
So |
Describe the project you are working on
A low-level scripting language that compiles into gdscript.
Describe the problem or limitation you are having in your project
I am trying to reformat source code into a more legible format for the compiler, but I also want to preserve line breaks inside quote marks, substitute tabs for different punctuation, etc. Rather than smash my head in with twenty different highly specific regexes, I've decided it's easier to go through the code character-by-character and rebuild the script.
It would be very useful to have a for loop that uses a match statement, a little like this one:
You get the idea.
However, because the match statement has a different and conflicting use for the continue statement, there's no way to get out of the for loop without dispensing with the match statement and just using inelegant if-else statements.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Add a
next
keyword which will be used instead of thecontinue
keyword in match statements, givingcontinue
one specific meaning and freeing it solely for manipulating iterating loops, allowing for the use of the much more elegantmatch
statement instead of forcing people to use longif-else
chains.Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
This pseudocode will format a text, removing extra spaces except within a quote block. This is a simple task that surely has simpler implementations, but it's a demonstration on how you can use this pattern for very complex formatting, selectively formatting text.
If this enhancement will not be used often, can it be worked around with a few lines of script?
Yes, you could use big if-else statements, but the entire point of a match statement is to avoid ugly if-else blocks. There is nothing an if-else could do that a match statement couldn't.
Is there a reason why this should be core and not an add-on in the asset library?
This is a fundamental change to the code.
The text was updated successfully, but these errors were encountered: