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())
.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,
}
}

View File

@ -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>(

View File

@ -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 { .. }