Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jaybosamiya-ms committed Jul 5, 2024
1 parent fcc32f2 commit c3d2e50
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
12 changes: 7 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1603,7 +1603,7 @@ fn parse_and_format(s: &str) -> miette::Result<String> {
match rule {
Rule::non_verus | Rule::COMMENT => {
formatted_output += pair.as_str();
if matches!(pair.as_rule(), Rule::COMMENT) && is_multiline_comment(&pair) {
if matches!(pair.as_rule(), Rule::COMMENT) {
formatted_output += "\n";
}
}
Expand All @@ -1625,12 +1625,8 @@ fn parse_and_format(s: &str) -> miette::Result<String> {
(prefix_comments, body, suffix_comments)
};
formatted_output += VERUS_PREFIX;
let mut final_prefix_comment_is_multiline = false;
for comment in &prefix_comments {
formatted_output += comment.as_str();
final_prefix_comment_is_multiline = is_multiline_comment(comment);
}
if !prefix_comments.is_empty() && final_prefix_comment_is_multiline {
formatted_output += "\n";
}

Expand All @@ -1639,7 +1635,13 @@ fn parse_and_format(s: &str) -> miette::Result<String> {
if !suffix_comments.is_empty() {
formatted_output += "\n";
}
let mut first = true;
for comment in suffix_comments {
if !first {
formatted_output += "\n";
} else {
first = false;
}
formatted_output += comment.as_str();
}
formatted_output += VERUS_SUFFIX;
Expand Down
6 changes: 5 additions & 1 deletion src/verus.pest
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,11 @@ broadcast_use_list = {
}

broadcast_uses = {
broadcast_use+
// We explicitly eat up the extra WHITESPACEs here
// to prevent it from messing with the MULTI_NEWLINE
// handling, which would otherwise cause extra newlines
// to show up.
broadcast_use+ ~ WHITESPACE*
}

broadcast_use = {
Expand Down
16 changes: 15 additions & 1 deletion tests/verus-consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ pub fn test() {
pub fn test() {
let Some((key, val)) = cur else { panic!() /* covered by while condition */ };
let Some((key, val)) = cur else { panic!() };
}
Expand Down Expand Up @@ -782,7 +783,6 @@ fn len<T>(l: List<T>) -> nat {
_ => false,
}
}
}
}
Expand Down Expand Up @@ -2424,5 +2424,19 @@ fn fff() {
"#;

assert_snapshot!(parse_and_format(file).unwrap(), @r###"
verus! {
fn fff() {
reveal(f1); // reveal f1's definition just inside this block
reveal(f1); // reveal f1's definition just inside this block
foo;
bar;
baz;
}
} // verus!
"###);
}

0 comments on commit c3d2e50

Please sign in to comment.