-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Adds pattern matching to GDScript #6845
Conversation
Here the final "specification" of the pattern matching features. The match statement can be used inside blocks (so where all the other statements can be used too). Abstract syntax of a match statement: match expression:
pattern: block
pattern: block
... A pattern can be of 6 types:
Edit: I forgot one, it isn't really a pattern type but anyway...
Since it's not really a pattern type it can't be used in array and dictionary patterns, only as a "toplevel" pattern. The body can contain match statements as well. Pattern are checked from top to bottom, left to right. A A |
|
||
|
||
|
||
Error err = _parse_block(codegen, branch.body, p_stack_level, p_break_addr, continue_addr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If p_break_addr
is changed to break_addr
then break will work inside of a pattern branch. So no big changes needed to support that. However I think it would be a bad idea to do that since it will cause a lot of confusion amongst newbies and may lead people the wrong way.
break
isn't match-idiomatic, so I think it would be a mistake to implement it that way.
Assigning to @reduz to review, since it is a new gdscript feature. |
I think GDScript syntax is complete, maybe missing ternary operator and while, so I'm against merging. |
@pkowal1982 ternary operators are implemented on |
🎉 |
@karroffel Now you have to write docs 😛 |
oh snap. I actually thought about that in bed, will do after Akiens huge formatting code review |
@karroffel I'm speaking of godotengine/godot-docs, heh |
As I proposed in #6593 here is the implementation of pattern matching in GDScript.
Right now the highlighting for thematch
keywords doesn't work but I think this isn't too important for code reviewing.