Combine ! and ? into single TrySuffix AST node

This commit is contained in:
Sam Mohr 2024-08-14 22:14:08 -07:00
parent cc5bf3f164
commit 3bc5c1dc12
No known key found for this signature in database
GPG key ID: EA41D161A3C1BC99
42 changed files with 859 additions and 162 deletions

View file

@ -9,8 +9,7 @@ use crate::spaces::{
use crate::Buf;
use roc_module::called_via::{self, BinOp};
use roc_parse::ast::{
is_expr_suffixed, AssignedField, Base, Collection, CommentOrNewline, Expr, ExtractSpaces,
OldRecordBuilderField, Pattern, WhenBranch,
is_expr_suffixed, AssignedField, Base, Collection, CommentOrNewline, Expr, ExtractSpaces, OldRecordBuilderField, Pattern, TryTarget, WhenBranch
};
use roc_parse::ast::{StrLiteral, StrSegment};
use roc_parse::ident::Accessor;
@ -47,7 +46,7 @@ impl<'a> Formattable for Expr<'a> {
| OpaqueRef(_)
| Crash => false,
RecordAccess(inner, _) | TupleAccess(inner, _) | TaskAwaitBang(inner) => {
RecordAccess(inner, _) | TupleAccess(inner, _) | TrySuffix { expr: inner, .. } => {
inner.is_multiline()
}
@ -520,9 +519,12 @@ impl<'a> Formattable for Expr<'a> {
buf.push('.');
buf.push_str(key);
}
TaskAwaitBang(expr) => {
TrySuffix { expr, target } => {
expr.format_with_options(buf, Parens::InApply, Newlines::Yes, indent);
buf.push('!');
match target {
TryTarget::Task => buf.push('!'),
TryTarget::Result => buf.push('?'),
}
}
MalformedIdent(str, _) => {
buf.indent(indent);