Skip to content

Commit

Permalink
Add tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
jonybur committed Oct 11, 2023
1 parent cf42de8 commit 0073ba5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tooling/nargo_fmt/src/visitor/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ impl FmtVisitor<'_> {
self.format_expr(infix.rhs)
)
}
ExpressionKind::Tuple(elements) => {
let formatted_elements = elements
.iter()
.map(|e| {
let formatted = self.format_expr(e.clone()).trim().to_string();
formatted
})
.collect::<Vec<_>>()
.join(", ");
format!("({})", formatted_elements)
}
ExpressionKind::MemberAccess(member_access_expr) => {
let lhs_str = self.format_expr(member_access_expr.lhs);
format!("{}.{}", lhs_str, member_access_expr.rhs)
Expand Down
3 changes: 3 additions & 0 deletions tooling/nargo_fmt/tests/expected/tuple.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
let my_tuple = (1, 2, 3, 4);
}
3 changes: 3 additions & 0 deletions tooling/nargo_fmt/tests/input/tuple.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
let my_tuple = ( 1,2 , 3 ,4);
}

0 comments on commit 0073ba5

Please sign in to comment.