From d39dbd6697b4c3b53b0da7c8f712c6e002375b63 Mon Sep 17 00:00:00 2001 From: Micah Kendall Date: Mon, 1 Apr 2024 15:30:10 +1100 Subject: [PATCH] fmt --- crates/aiken-lang/src/expr.rs | 6 ++++-- crates/aiken-lang/src/format.rs | 31 ++++++++++++------------------ crates/aiken-lang/src/tipo/expr.rs | 4 +++- 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/crates/aiken-lang/src/expr.rs b/crates/aiken-lang/src/expr.rs index b05ab895..864c9a78 100644 --- a/crates/aiken-lang/src/expr.rs +++ b/crates/aiken-lang/src/expr.rs @@ -371,7 +371,7 @@ impl TypedExpr { .find_node(byte_index) .or_else(|| then.find_node(byte_index)) .or(Some(Located::Expression(self))), - + TypedExpr::Emit { text, then, .. } => text .find_node(byte_index) .or_else(|| then.find_node(byte_index)) @@ -1307,7 +1307,9 @@ impl UntypedExpr { .map(|e| e.start_byte_index()) .unwrap_or(location.start), Self::PipeLine { expressions, .. } => expressions.first().start_byte_index(), - Self::Trace { location, .. } | Self::Emit{ location, .. } | Self::Assignment { location, .. } => location.start, + Self::Trace { location, .. } + | Self::Emit { location, .. } + | Self::Assignment { location, .. } => location.start, _ => self.location().start, } } diff --git a/crates/aiken-lang/src/format.rs b/crates/aiken-lang/src/format.rs index 2bf52943..b149fef1 100644 --- a/crates/aiken-lang/src/format.rs +++ b/crates/aiken-lang/src/format.rs @@ -957,9 +957,7 @@ impl<'comments> Formatter<'comments> { kind, text, then, .. } => self.trace(kind, text, then), - UntypedExpr::Emit { - text, then, .. - } => self.emit(text, then), + UntypedExpr::Emit { text, then, .. } => self.emit(text, then), UntypedExpr::When { subject, clauses, .. @@ -1049,23 +1047,18 @@ impl<'comments> Formatter<'comments> { } } - pub fn emit<'a>( - &mut self, - text: &'a UntypedExpr, - then: &'a UntypedExpr, - ) -> Document<'a> { + pub fn emit<'a>(&mut self, text: &'a UntypedExpr, then: &'a UntypedExpr) -> Document<'a> { let body = "emit" - .to_doc() - .append(" ") - .append(self.wrap_expr(text)) - .group(); - body - .append(if self.pop_empty_lines(then.start_byte_index()) { - lines(2) - } else { - line() - }) - .append(self.expr(then, true)) + .to_doc() + .append(" ") + .append(self.wrap_expr(text)) + .group(); + body.append(if self.pop_empty_lines(then.start_byte_index()) { + lines(2) + } else { + line() + }) + .append(self.expr(then, true)) } pub fn pattern_constructor<'a>( diff --git a/crates/aiken-lang/src/tipo/expr.rs b/crates/aiken-lang/src/tipo/expr.rs index 3251dce6..a1b7f173 100644 --- a/crates/aiken-lang/src/tipo/expr.rs +++ b/crates/aiken-lang/src/tipo/expr.rs @@ -2340,7 +2340,9 @@ fn assert_no_assignment(expr: &UntypedExpr) -> Result<(), Error> { location: expr.location(), expr: *value.clone(), }), - UntypedExpr::Trace { then, .. } | UntypedExpr::Emit { then, .. } => assert_no_assignment(then), + UntypedExpr::Trace { then, .. } | UntypedExpr::Emit { then, .. } => { + assert_no_assignment(then) + } UntypedExpr::Fn { .. } | UntypedExpr::BinOp { .. } | UntypedExpr::ByteArray { .. }