-
Notifications
You must be signed in to change notification settings - Fork 430
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 top level extensions #2693
Fix top level extensions #2693
Changes from all commits
4e6b021
39d3977
8496594
f3421f7
f4837b5
dcaadad
223a304
f6e5783
8774a7e
1356763
dfff5f8
48e5ac9
1daa3cd
b283f33
6290f3b
bb96b3b
b48ec14
bb16770
d346065
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -350,6 +350,8 @@ let () = { | |
something_else(); | ||
}; | ||
|
||
let f = [%bs.raw x => x]; | ||
|
||
[%bs.raw x => x]; | ||
|
||
let work = () => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -348,6 +348,8 @@ let () = { | |
something_else(); | ||
}; | ||
|
||
let f = [%bs.raw x => x]; | ||
|
||
[%bs.raw x => x]; | ||
|
||
let work = () => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7576,29 +7576,42 @@ let printer = object(self:'self) | |
| Pmod_constraint _ | ||
| Pmod_structure _ -> self#simple_module_expr x | ||
|
||
|
||
method structure structureItems = | ||
(* We don't have any way to know if an extension is placed at the top level by the parsetree | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought we supported extensions at the toplevel with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is a BuckleScript thing, but we support both cases. Would be a nice idea to unify all of these cases with Melange. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't get what needs to be unified? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could avoid having |
||
while there's a difference syntactically (% for structure_items/expressons and %% for top_level). | ||
This small fn detects this particular case (structure > structure_item > extension > value) and | ||
prints with double % *) | ||
let structure_item item = | ||
match item.pstr_desc with | ||
| Pstr_extension ((extension, PStr [item]), attrs) -> | ||
begin match item.pstr_desc with | ||
(* In case of a value, the extension gets inlined `let%private a = 1` *) | ||
| Pstr_value (rf, vb_list) -> self#bindings ~extension (rf, vb_list) | ||
| _ -> self#attach_std_item_attrs attrs (self#payload "%%" extension (PStr [item])) | ||
end | ||
| _ -> self#structure_item item | ||
in | ||
match structureItems with | ||
| [] -> atom "" | ||
| first::_ as structureItems -> | ||
| first :: _ as structureItems -> | ||
let last = match (List.rev structureItems) with | last::_ -> last | [] -> assert false in | ||
let loc_start = first.pstr_loc.loc_start in | ||
let loc_end = last.pstr_loc.loc_end in | ||
let items = | ||
groupAndPrint | ||
~xf:self#structure_item | ||
~xf:structure_item | ||
~getLoc:(fun x -> x.pstr_loc) | ||
~comments:self#comments | ||
structureItems | ||
in | ||
source_map ~loc:{loc_start; loc_end; loc_ghost = false} | ||
(makeList | ||
~postSpace:true | ||
~break:Always_rec | ||
~indent:0 | ||
~inline:(true, false) | ||
~sep:(SepFinal (";", ";")) | ||
items) | ||
~postSpace:true | ||
~break:Always_rec | ||
~indent:0 | ||
~inline:(true, false) | ||
~sep:(SepFinal (";", ";")) | ||
items) | ||
|
||
(* | ||
How do modules become parsed? | ||
|
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.
don't we also accept this form? I think it should keep being tested.
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.
Pushed back the test case, we do support them.
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.
It's still removed. did you forget to push?
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 added all of the cases in the cram tests. Let me add them in the
formatTest
as well