Skip to content

Commit

Permalink
fix typo and testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
trdthg committed May 22, 2024
1 parent c29d531 commit 58928e2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 28 deletions.
6 changes: 3 additions & 3 deletions src/lib/chunk_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ let add_chunk q chunk = Queue.add chunk q

[@@@coverage off]
let rec prerr_chunk indent = function
| Comment (comment_type, n, col, contents, tralling) ->
| Comment (comment_type, n, col, contents, trailing) ->
let s, e = comment_type_delimiters comment_type in
Printf.eprintf "%sComment: blank=%d col=%d tralling=%b %s%s%s\n" indent n col tralling s contents e
Printf.eprintf "%sComment: blank=%d col=%d trailing=%b %s%s%s\n" indent n col trailing s contents e
| Spacer (line, w) -> Printf.eprintf "%sSpacer:%b %d\n" indent line w
| Atom str -> Printf.eprintf "%sAtom:%s\n" indent str
| String_literal str -> Printf.eprintf "%sString_literal:%s\n" indent str
Expand Down Expand Up @@ -444,7 +444,7 @@ let rec pop_comments_until_loc_end comments chunks l =
| None -> ()
| Some (Lexer.Comment (comment_type, comment_s, comment_e, contents)) -> begin
match Reporting.simp_loc l with
| Some (_, e) when comment_s.pos_cnum <= e.pos_cnum ->
| Some (_, e) when comment_s.pos_cnum < e.pos_cnum ->
let _ = Stack.pop comments in
Queue.add
(Comment
Expand Down
8 changes: 4 additions & 4 deletions src/lib/format_sail.ml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ let rec map_last f = function
let x = f false x in
x :: map_last f xs

let line_comment_opt = function Comment (Lexer.Comment_line, _, _, contents, _tralling) -> Some contents | _ -> None
let line_comment_opt = function Comment (Lexer.Comment_line, _, _, contents, _trailing) -> Some contents | _ -> None

(* Remove additional (> 1) trailing newlines at the end of a string *)
let discard_extra_trailing_newlines s =
Expand Down Expand Up @@ -707,10 +707,10 @@ module Make (Config : CONFIG) = struct
match (chunk, Queue.peek_opt chunks) with
| Comment _, _ -> !doc_acc
| Spacer _, _ -> !doc_acc
| _, Some (Comment (_, _, _, _, tralling)) ->
| _, Some (Comment (_, _, _, _, trailing)) ->
doc_acc := !doc_acc ^^ terminator;
(* if current is not a Comment or Spacer, and next is not tralling, then insert a hardline *)
if not tralling then doc_acc := !doc_acc ^^ hardline;
(* if current is not a Comment or Spacer, and next is not trailing, then insert a hardline *)
if not trailing then doc_acc := !doc_acc ^^ hardline;
doc_acc := !doc_acc ^^ doc_chunk opts (Queue.pop chunks);
if Queue.peek_opt chunks = None then requires_hardline := true;
!doc_acc
Expand Down
2 changes: 0 additions & 2 deletions test/format/comments.sail
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ function b () -> int = {
}// comment
};

};

1
// comment
}
Expand Down
22 changes: 3 additions & 19 deletions test/format/default/comments.expect
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ function b () -> int = {
};

let g3 = {
1
// comment
1 // comment
// comment
}
} // comment
};

1
Expand All @@ -60,22 +59,7 @@ let d =
{
1
// comment
}

// comment
// comment
// comment
function block_return_with_tralling_space () -> int = {
1 // comment
// comment
}

function block_return_without_tralling_space () -> int = {
1
// comment
}

// comment
} // comment
// comment
// comment
// comment

0 comments on commit 58928e2

Please sign in to comment.