Skip to content
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

Fix 2695: local open + let bindings #2716

Merged
merged 7 commits into from
Jun 30, 2024

Conversation

SanderSpies
Copy link
Contributor

@SanderSpies SanderSpies commented Apr 24, 2023

Solves #2695.

Makes it possible to use:

 let y = Promise.Ops.(
  let* x = Js.Promise.resolve(42);
  Js.Promise.resolve(x * 2);
);

Printing isn't perfect, but good enough for now.

@SanderSpies SanderSpies changed the title Fix 2695 Fix 2695: local open + let bindings Apr 24, 2023
@SanderSpies SanderSpies marked this pull request as ready for review April 24, 2023 18:49
Copy link
Member

@anmonteiro anmonteiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thanks!

@@ -6442,7 +6442,12 @@ let printer = object(self:'self)
(atom (".")))
(self#formatNonSequencyExpression e))
else
Some (makeLetSequence (self#letList x))
Some
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks exactly like the then branch.

I'm surprised this doesn't break let open Foo; bar; for example?

Perhaps the letop case should be added to isSeriesOfOpensFollowedByNonSequencyExpression, then we'd get printing for free?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, not exactly the same. The first branch results into extra braces:

-      let* x = Js.Promise.resolve(42);
-      Js.Promise.resolve(x * 2);
+      {
+        let* x = Js.Promise.resolve(42);
+        Js.Promise.resolve(x * 2);
+      }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did make a small change to avoid code duplication

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how this is correct yet. I might be missing something.

Aren't we replacing ALL open calls with Foo.( ... )?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anmonteiro

Not exactly, but the solution wasn't perfect (it didn't work for nested local open modules). I've tried to improve on it with help of an extra attribute set by the parser.

@anmonteiro
Copy link
Member

Thank you again, and sorry for the delay

@anmonteiro anmonteiro merged commit 555e229 into reasonml:master Jun 30, 2024
15 checks passed
anmonteiro added a commit to anmonteiro/opam-repository that referenced this pull request Jul 23, 2024
CHANGES:

- Add `\u{hex-escape}` syntax (@anmonteiro,
  [reasonml/reason#2738](reasonml/reason#2738))
- Support local open and let bindings (@SanderSpies) [reasonml/reason#2716](reasonml/reason#2716)
- outcome printer: change the printing of `@bs.*` to `@mel.*` (@anmonteiro, [reasonml/reason#2755](reasonml/reason#2755))
- Fix outcome printing of optional arguments on OCaml 5.2 (@anmonteiro, [reasonml/reason#2753](reasonml/reason#2753))
- support parsing and printing of `external%extension` (@anmonteiro, [reasonml/reason#2750](reasonml/reason#2750), [reasonml/reason#2766](reasonml/reason#2766), [reasonml/reason#2767](reasonml/reason#2767))
- install `refmt` manpage (@anmonteiro, [reasonml/reason#2760](reasonml/reason#2760))
- add support for parsing / printing of refutation clause in `switch` (@anmonteiro, [reasonml/reason#2765](reasonml/reason#2765))
- support `let%ppx` in signatures (@anmonteiro, [reasonml/reason#2770](reasonml/reason#2770))
avsm pushed a commit to avsm/opam-repository that referenced this pull request Sep 5, 2024
CHANGES:

- Add `\u{hex-escape}` syntax (@anmonteiro,
  [reasonml/reason#2738](reasonml/reason#2738))
- Support local open and let bindings (@SanderSpies) [reasonml/reason#2716](reasonml/reason#2716)
- outcome printer: change the printing of `@bs.*` to `@mel.*` (@anmonteiro, [reasonml/reason#2755](reasonml/reason#2755))
- Fix outcome printing of optional arguments on OCaml 5.2 (@anmonteiro, [reasonml/reason#2753](reasonml/reason#2753))
- support parsing and printing of `external%extension` (@anmonteiro, [reasonml/reason#2750](reasonml/reason#2750), [reasonml/reason#2766](reasonml/reason#2766), [reasonml/reason#2767](reasonml/reason#2767))
- install `refmt` manpage (@anmonteiro, [reasonml/reason#2760](reasonml/reason#2760))
- add support for parsing / printing of refutation clause in `switch` (@anmonteiro, [reasonml/reason#2765](reasonml/reason#2765))
- support `let%ppx` in signatures (@anmonteiro, [reasonml/reason#2770](reasonml/reason#2770))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants