Skip to content

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!

(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 anmonteiro force-pushed the sanderspies/fix_2695 branch from e7308d4 to 722e1a6 Compare June 30, 2024 02:55
@anmonteiro
Copy link
Member

Thank you again, and sorry for the delay

@anmonteiro anmonteiro merged commit 555e229 into reasonml:master Jun 30, 2024
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