This commit is contained in:
Micah Kendall 2024-04-01 15:30:10 +11:00 committed by Lucas
parent d25b8f91c7
commit d39dbd6697
3 changed files with 19 additions and 22 deletions

View File

@ -1307,7 +1307,9 @@ impl UntypedExpr {
.map(|e| e.start_byte_index()) .map(|e| e.start_byte_index())
.unwrap_or(location.start), .unwrap_or(location.start),
Self::PipeLine { expressions, .. } => expressions.first().start_byte_index(), 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, _ => self.location().start,
} }
} }

View File

@ -957,9 +957,7 @@ impl<'comments> Formatter<'comments> {
kind, text, then, .. kind, text, then, ..
} => self.trace(kind, text, then), } => self.trace(kind, text, then),
UntypedExpr::Emit { UntypedExpr::Emit { text, then, .. } => self.emit(text, then),
text, then, ..
} => self.emit(text, then),
UntypedExpr::When { UntypedExpr::When {
subject, clauses, .. subject, clauses, ..
@ -1049,18 +1047,13 @@ impl<'comments> Formatter<'comments> {
} }
} }
pub fn emit<'a>( pub fn emit<'a>(&mut self, text: &'a UntypedExpr, then: &'a UntypedExpr) -> Document<'a> {
&mut self,
text: &'a UntypedExpr,
then: &'a UntypedExpr,
) -> Document<'a> {
let body = "emit" let body = "emit"
.to_doc() .to_doc()
.append(" ") .append(" ")
.append(self.wrap_expr(text)) .append(self.wrap_expr(text))
.group(); .group();
body body.append(if self.pop_empty_lines(then.start_byte_index()) {
.append(if self.pop_empty_lines(then.start_byte_index()) {
lines(2) lines(2)
} else { } else {
line() line()

View File

@ -2340,7 +2340,9 @@ fn assert_no_assignment(expr: &UntypedExpr) -> Result<(), Error> {
location: expr.location(), location: expr.location(),
expr: *value.clone(), 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::Fn { .. }
| UntypedExpr::BinOp { .. } | UntypedExpr::BinOp { .. }
| UntypedExpr::ByteArray { .. } | UntypedExpr::ByteArray { .. }