Skip to content

Commit

Permalink
returns clause
Browse files Browse the repository at this point in the history
  • Loading branch information
tjhance committed Oct 1, 2024
1 parent 8f026df commit 2c3949a
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,7 @@ fn to_doc<'a>(

Rule::decreases_str
| Rule::ensures_str
| Rule::returns_str
| Rule::invariant_except_break_str
| Rule::invariant_str
| Rule::invariant_ensures_str
Expand Down Expand Up @@ -1335,6 +1336,7 @@ fn to_doc<'a>(
Rule::verus_clause_non_expr => map_to_doc(ctx, arena, pair),
Rule::requires_clause => map_to_doc(ctx, arena, pair),
Rule::ensures_clause => map_to_doc(ctx, arena, pair),
Rule::returns_clause => map_to_doc(ctx, arena, pair),
Rule::invariant_except_break_clause => map_to_doc(ctx, arena, pair),
Rule::invariant_clause => map_to_doc(ctx, arena, pair),
Rule::invariant_ensures_clause => map_to_doc(ctx, arena, pair),
Expand Down
8 changes: 7 additions & 1 deletion src/verus.pest
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ do_str = ${ "do" ~ !("_" | ASCII_ALPHANUMERIC) }
dyn_str = ${ "dyn" ~ !("_" | ASCII_ALPHANUMERIC) }
else_str = ${ "else" ~ !("_" | ASCII_ALPHANUMERIC) }
ensures_str = ${ "ensures" ~ !("_" | ASCII_ALPHANUMERIC) }
returns_str = ${ "returns" ~ !("_" | ASCII_ALPHANUMERIC) }
enum_str = ${ "enum" ~ !("_" | ASCII_ALPHANUMERIC) }
exec_str = ${ "exec" ~ !("_" | ASCII_ALPHANUMERIC) }
exists_str = ${ "exists" ~ !("_" | ASCII_ALPHANUMERIC) }
Expand Down Expand Up @@ -701,7 +702,7 @@ use_tree_list = {
}

fn_qualifier = {
(requires_clause | recommends_clause | ensures_clause | decreases_clause | opens_invariants_clause | unwind_clause)*
(requires_clause | recommends_clause | ensures_clause | returns_clause | decreases_clause | opens_invariants_clause | unwind_clause)*
}

fn_terminator = {
Expand Down Expand Up @@ -1715,6 +1716,7 @@ verus_clause_non_expr = _{
"{" // TODO: Why is this permitted here?
| requires_str
| ensures_str
| returns_str
| invariant_except_break_str
| invariant_str
| invariant_ensures_str
Expand All @@ -1733,6 +1735,10 @@ ensures_clause = {
ensures_str ~ comma_delimited_exprs_for_verus_clauses?
}

returns_clause = {
returns_str ~ comma_delimited_exprs_for_verus_clauses?
}

invariant_except_break_clause = {
invariant_except_break_str ~ comma_delimited_exprs_for_verus_clauses?
}
Expand Down
84 changes: 84 additions & 0 deletions tests/verus-consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2601,3 +2601,87 @@ verus! {
} // verus!
"###)
}

#[test]
fn verus_support_returns_clause() {
let file = r#"
verus!{
fn test(b: bool) -> (c: bool)
requires x,
ensures c == !b,
returns !b,
{
}
fn test2(b: bool) -> (c: bool)
requires x,
ensures c == !b,
returns !b
{
}
fn test3(b: bool) -> (c: bool)
requires x,
ensures c == !b,
returns !b
opens_invariants any
{
}
fn test4(b: bool) -> (c: bool)
requires x,
ensures c == !b,
returns !b,
opens_invariants any
{
}
}
"#;
assert_snapshot!(parse_and_format(file).unwrap(), @r###"
verus! {
fn test(b: bool) -> (c: bool)
requires
x,
ensures
c == !b,
returns
!b,
{
}
fn test2(b: bool) -> (c: bool)
requires
x,
ensures
c == !b,
returns
!b,
{
}
fn test3(b: bool) -> (c: bool)
requires
x,
ensures
c == !b,
returns
!b,
opens_invariants any
{
}
fn test4(b: bool) -> (c: bool)
requires
x,
ensures
c == !b,
returns
!b,
opens_invariants any
{
}
} // verus!
"###)
}

0 comments on commit 2c3949a

Please sign in to comment.