-
Notifications
You must be signed in to change notification settings - Fork 119
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
RFC: match statement #560
base: develop
Are you sure you want to change the base?
RFC: match statement #560
Conversation
fdb855d
to
3b61e59
Compare
3b61e59
to
490fdef
Compare
Admittedly, this is not "real" pattern matching. It's more of a glorified |
match_lines.size() | ||
) | ||
var pairs = match_expr.parse(match_lines) | ||
escoria.logger.trace("%d arms found for match" % pairs.size()) |
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.
Can we rename "arm" to something like "condition_option" please? It's not very intuitive.
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.
Or "branch".
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.
Assuming this gets the green light, please update the documentation as part of the PR.
Also, is there any way to add conditional logic to this? i.e. issue 220 |
Very good improvement to the language. I have nothing particular to add about it, apart that obviously documentation is required in the code and some TODOs need to be adresse. Otherwise, great addition, thanks! |
else: | ||
# TODO: error? | ||
pass |
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.
else: | |
# TODO: error? | |
pass |
I'd simply remove this. match_lines.size() > 0 is really just a safety guard. If it really is empty, then we don't care.
# A RegEx identifying a match block | ||
const REGEX = '^([^>]*)>>\\s*(?<expr>.+)$' | ||
|
||
const MATCH_ARM_REGEX = '^\\s*(?<cond_expr>.+)\\s+=>\\s*$' |
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.
Please add a doc comment to this as well.
return ESCExecution.RC_OK | ||
|
||
|
||
func parse(lines: Array) -> Array: |
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.
Please add a doc comment
|
||
|
||
func run() -> int: | ||
# Must ensure that at most one condition is satisfied. |
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.
This part actually should be put into is_valid
I think.
match_lines.size() | ||
) | ||
var pairs = match_expr.parse(match_lines) | ||
escoria.logger.trace("%d arms found for match" % pairs.size()) |
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.
Or "branch".
As an initial attempt, I first made a small update to initially set a global in
room02_bridge.esc
:which then makes the
:look
command inbutton.esc
a bit cleaner when using the newmatch
statement:For the moment, to avoid introducing a new keyword (which would take away a possible command name),
>>
is used to indicate the start of a match statement. As you can see, the condition arms use a=>
syntax like Rust (and a number of other languages that support pattern matching).Arguably, using a match statement avoids repeating the comparison valuable, eliminates the need for
stop
in many cases, and makes it easier to see that all cases are covered.