Skip to content

Commit

Permalink
fix: structure items
Browse files Browse the repository at this point in the history
  • Loading branch information
anmonteiro committed Aug 21, 2024
1 parent dd9fe22 commit 75aeb81
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/reason-parser/reason_declarative_lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ rule token state = parse
lexbuf.lex_start_p <- string_start;
let txt = flush_buffer raw_buffer in
let idloc = compute_quoted_string_idloc orig_loc 3 id in
QUOTED_STRING_EXPR (id, idloc, txt, Some "") }
QUOTED_STRING_ITEM (id, idloc, txt, Some "") }
| "{%%" (extattrident as id) blank+ (lowercase* as delim) "|"
{ let orig_loc = Location.curr lexbuf in
let string_start = lexbuf.lex_start_p in
Expand All @@ -505,7 +505,7 @@ rule token state = parse
lexbuf.lex_start_p <- string_start;
let txt = flush_buffer raw_buffer in
let idloc = compute_quoted_string_idloc orig_loc 3 id in
QUOTED_STRING_EXPR (id, idloc, txt, Some delim) }
QUOTED_STRING_ITEM (id, idloc, txt, Some delim) }
| "'" newline "'"
{ (* newline can span multiple characters
(if the newline starts with \13)
Expand Down
37 changes: 22 additions & 15 deletions src/reason-parser/reason_pprint_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,20 @@ let createFormatter () =
fn Format.str_formatter term;
atom (Format.flush_str_formatter ())

let quoted_ext ?(pct = "%") extension i delim =
wrap
(fun ppf () ->
Format.fprintf
ppf
"{%s%s%s%s|%s|%s}"
pct
extension.txt
(if delim != "" then " " else "")
delim
i
delim)
()

(* Don't use `trim` since it kills line return too? *)
let rec beginsWithStar_ line length idx =
if idx = length
Expand Down Expand Up @@ -7710,25 +7724,12 @@ let createFormatter () =
| None, _ ->
(match expression_extension_sugar x with
| None -> Some (self#extension e)
| Some ({ txt = ext; _ }, x') ->
| Some (ext, x') ->
(match x'.pexp_desc with
| Pexp_let _ | Pexp_letop _ | Pexp_letmodule _ ->
Some (makeLetSequence (self#letList x))
| Pexp_constant (Pconst_string (i, _, Some delim)) ->
let quoted_ext =
wrap
(fun ppf () ->
Format.fprintf
ppf
"{%%%s%s%s|%s|%s}"
ext
(if delim != "" then " " else "")
delim
i
delim)
()
in
Some quoted_ext
Some (quoted_ext ext i delim)
| _ -> Some (self#extension e))))
| Pexp_open (me, e) ->
if self#isSeriesOfOpensFollowedByNonSequencyExpression x
Expand Down Expand Up @@ -9227,6 +9228,12 @@ let createFormatter () =
| Pstr_open od -> self#pstr_open ~extension od
| Pstr_type (rf, l) -> self#type_def_list ~extension rf l
| Pstr_typext te -> self#type_extension ~extension te
| Pstr_eval
( { pexp_desc =
Pexp_constant (Pconst_string (i, _, Some delim))
}
, _ ) ->
quoted_ext ~pct:"%%" extension i delim
| _ ->
self#attach_std_item_attrs
attrs
Expand Down
2 changes: 1 addition & 1 deletion test/extensions.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -390,5 +390,5 @@ Format extensions
external%foo x: int => int = "caml_prim";
external%foo x: int => int = "caml_prim";

{%M.foo | <hello>{x} |};
{%%M.foo | <hello>{x} |};
let x = {%M.foo bar| <hello>{|x|} |bar};

0 comments on commit 75aeb81

Please sign in to comment.