-
Notifications
You must be signed in to change notification settings - Fork 70
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
Multiway match parsing for pattern guards #1588
Multiway match parsing for pattern guards #1588
Conversation
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 is coming along well.
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.
I'm preemptively approving to remind myself that I think this PR on the whole looks good -- there are just a few minor comments left to resolve.
e9f2f13
to
afa084b
Compare
Rebase onto #1583 to improve test formatting. |
afa084b
to
7e4b140
Compare
Rebase onto origin/pattern-guards to prevent future work |
Co-authored-by: Nick Roberts <nroberts02@gmail.com>
e3d7c76
to
4e22f63
Compare
* implements parsing for multiway matches * implements parsing for multiway pattern guards * fixes test output * support optional bar before single pattern guard * adds some multiway tests * fix ocamlprof * fix and test bar before single pattern guard * make typecore changes less disruptive * further refactor typecore * further improve typecore code readability * maps location in untypeast * fixes printast_with_mappings typo * translates single-case pattern guards successfully * move case_rhs down in iterator and mapper record * update parsetree comments * iterate over location * add whitespace to parser * fix pretty printing * matched style of printast * add tests, disable extraneous warning * fix typecore indentation * replaces polymorphic variant with rhs variant * removes staging from rhs type approx * format: nested pattern guard line break Co-authored-by: Nick Roberts <nroberts02@gmail.com> * add pattern guard syntax to source test * refactor type_approx_aux to avoid desc logic * comment purpose of jane_test * adds back test comments deleted in rebase * promote test output after rebase * refactor to sync Pexp_match and pg type approx --------- Co-authored-by: Nick Roberts <nroberts02@gmail.com>
Implements parsing for the more general "multiway match" syntax, allowing pattern guards to contain multiple cases, each with their own associated right-hand side.
We change the parsetree to reflect this change, instead of having a guard as an optional argument independent of the rhs, we roll it into a new "case rhs" type.
This changes the allowed Ocaml syntax for parsing, and this PR tests that the new construct is parsed successfully. For the moment, this PR breaks existing pattern guard typechecking and translation.
There are a lot of parts of the compiler that assume that the right hand side of a case is an expression: this is no longer true under the new parsetree type. For this reason, some existing checks needed to be modified to accomodate pattern guards.
A common transformation: for typechecking procedures, a pattern guard
| p1 when e1 match (| pi -> ei)
is treated as| p1 -> (match e1 with | pi -> ei)
.