-
Notifications
You must be signed in to change notification settings - Fork 76
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
Express pattern guards using Jane_syntax #1672
Express pattern guards using Jane_syntax #1672
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.
I haven't finished review, but I've marked the files I have finished reviewing as "Viewed" and will continue from there the next time I take a look.
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.
Done revieweing for now. I made a few minor comments.
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.
Thanks, this is easier to review now.
9166657
to
1c51765
Compare
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 have a few small comments, but nothing major. This is coming along well — we should be able to merge soon.
Builds will fail until #1747 is merged. |
Co-authored-by: Nick Roberts <nroberts02@gmail.com>
Co-authored-by: Nick Roberts <nroberts02@gmail.com>
Co-authored-by: Nick Roberts <nroberts02@gmail.com>
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 will be good to merge once CI turns green.
* express pattern guards in jane syntax * fix ocamlprof and flags * update ast_mapper and ast_iterator * add flag for failure on wrong syntactic category * fix parsetree printer * promote seq_bad output * clean up types * fix parsing test * ignore attrs in pretty printer * update field names in ocamlprof * whitespace in seq_bad reference * fix typechecking order of boolean guards * add test for disambiguation from guard * test: move nested match to test functionality * remove attributes from jane_syntax cases * rewrite case jane_syntax to use extension nodes * update jane_syntax_parsing documentation * remove debug print * inline pattern guard generation in parser * fix ocamlprof type * remove bad advice in parsetree comment * comment: give better advice about parsed cases Co-authored-by: Nick Roberts <nroberts02@gmail.com> * reintroduce pc_rhs variants within typecore * fix `Ast_helper.Exp.case` API * remove unnecessary let Co-authored-by: Nick Roberts <nroberts02@gmail.com> * remove unnecessary optional arguments * unabbreviate parsed case rhs in helper * type_approx_function bug * check for jane syntax for uncurried function * delete test that didn't exhibit previous badness * move [fail_if_wrong_syntactic_category] to functor * add test flags * minimize diff from base * fix syntax error post-rebase * add parsetree tests back * update [fail_if_wrong_syntactic_category] comment Co-authored-by: Nick Roberts <nroberts02@gmail.com> * minor wording change to comment * fail if pattern guarded case has pc_guard set * documented Case0 fail_if_wrong_syntactic_category --------- Co-authored-by: Nick Roberts <nroberts02@gmail.com>
Changing
Parsetree
requires painful updates to ppx's, so this PR rewrites the pattern guard feature usingJane_syntax
.In doing so, it creates a new syntactic category:
Jane_syntax.Case
.The attribute marking the extension and the location of a
Parsetree.case
which represents aJane_syntax.Case.t
are stored in its fieldpc_rhs: Parsetree.expression
. This rhs should never be interpreted as an expression by itself, which is why everywhere in the code that accesses the rhs of aParsetree.case
should first applyJane_syntax.Case.of_ast
(as documented inparsetree.mli
). Ensuring that this invariant is introduced everywhere is one of the main difficulties of this PR.However, the field
pc_rhs
is rarely accessed: ripgrepping yields the following files:Of these, only
printast.ml
doesn't applyof_ast
for cases, but this is fine as it doesn't apply it for any other syntactic category (it just prints the raw Parsetree instead).Currently, there is only one constructor for the variant
Jane_syntax.Case.t
, namelyJcase_pattern_guarded of Jane_syntax.Pattern_guarded.case
. The payload of this constructor stores the same data asPpattern_guarded_rhs
did previously, together with the case's lhs.It is also worth noting the exact ast representation of
Jane_syntax.Pattern_guarded.Pg_case { scrutinee; cases }
iscase : Parsetree.case
withcase.pc_rhs.pexp_desc = Pexp_match (scrutinee, cases)
, with extension attribute and location stored as described above.