Skip to content

Commit

Permalink
feat: format infix expressions (#3001)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench authored Oct 5, 2023
1 parent a38b15f commit 7926ada
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions tooling/nargo_fmt/src/visitor/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ impl FmtVisitor<'_> {
ExpressionKind::Prefix(prefix) => {
format!("{}{}", prefix.operator, self.format_expr(prefix.rhs))
}
ExpressionKind::Infix(infix) => {
format!(
"{} {} {}",
self.format_expr(infix.lhs),
infix.operator.contents.as_string(),
self.format_expr(infix.rhs)
)
}
// TODO:
_expr => slice!(self, span.start(), span.end()).to_string(),
}
Expand Down
4 changes: 2 additions & 2 deletions tooling/nargo_fmt/tests/input/infix.nr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fn foo() {
40 + 2;
!40 + 2;
40 + 2 == 42;
!40+2;
40 + 2 == 42;
}

0 comments on commit 7926ada

Please sign in to comment.