Skip to content

Commit

Permalink
feat: open any module expr
Browse files Browse the repository at this point in the history
  • Loading branch information
anmonteiro committed Jul 28, 2024
1 parent 5ee853d commit 869428c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/reason-parser/reason_parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -2566,10 +2566,9 @@ seq_expr_no_seq [@recover.expr default_expr ()] (semi):
| Some (ext_attrs, ext_id) ->
mkexp ~loc (Pexp_extension (ext_id, PStr [mkstrexp exp ext_attrs]))
}
| item_attributes LET? OPEN override_flag as_loc(mod_longident) SEMI seq_expr(SEMI?)
| item_attributes LET? OPEN override_flag module_expr SEMI seq_expr(SEMI?)
{ let loc = (mklocation $startpos($1) $endpos($4)) in
let me = Ast_helper.Mod.ident ~loc $5 in
let od = Ast_helper.Opn.mk ~override:$4 ~loc me in
let od = Ast_helper.Opn.mk ~override:$4 ~loc $5 in
let exp = mkexp (Pexp_open(od, $7)) in
{ exp with pexp_attributes = $1 }
}
Expand Down
7 changes: 4 additions & 3 deletions src/reason-parser/reason_pprint_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ let expression_immediate_extension_sugar x =
| Some (name, expr) ->
match expr.pexp_desc with
| Pexp_for _ | Pexp_while _ | Pexp_ifthenelse _ | Pexp_function _
| Pexp_newtype _ | Pexp_try _ | Pexp_match _ (* | Pexp_letmodule _ *) ->
| Pexp_newtype _ | Pexp_try _ | Pexp_match _ ->
(Some name, expr)
| _ -> (None, x)

Expand Down Expand Up @@ -6236,8 +6236,9 @@ let printer = object(self:'self)
| ([], Pexp_letop _) -> false
| ([], Pexp_sequence _) -> false
| ([], Pexp_letmodule _) -> false
| ([], Pexp_open (me, e)) ->
me.popen_override == Fresh && self#isSeriesOfOpensFollowedByNonSequencyExpression e
| ([], Pexp_open ({ popen_override; popen_expr = { pmod_desc = Pmod_ident _; _ }; _ }, e)) ->
popen_override == Fresh && self#isSeriesOfOpensFollowedByNonSequencyExpression e
| ([], Pexp_open _) -> false
| ([], Pexp_letexception _) -> false
| ([], Pexp_extension ({txt}, _)) -> txt = "mel.obj"
| _ -> true
Expand Down
15 changes: 15 additions & 0 deletions test/modules.t/input.re
Original file line number Diff line number Diff line change
Expand Up @@ -540,3 +540,18 @@ let x = {
module%foo rec X: Y = {
let x = 1;
}

let f = () => {
open {
let x = 1;
};
();
};

let f = () => {
let open {
let x = 1;
};
();
};

16 changes: 16 additions & 0 deletions test/modules.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -706,4 +706,20 @@ Format modules
module%foo rec X: Y = {
let x = 1;
};

let f = () => {
open {
let x = 1;
};

();
};

let f = () => {
open {
let x = 1;
};

();
};
/* From http://stackoverflow.com/questions/1986374/ higher-order-type-constructors-and-functors-in-ocaml */

0 comments on commit 869428c

Please sign in to comment.