mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 22:09:09 +00:00
parse expect
This commit is contained in:
parent
50942325b9
commit
700e7d9686
12 changed files with 223 additions and 5 deletions
|
|
@ -59,6 +59,10 @@ impl<'a> Formattable<'a> for Expr<'a> {
|
|||
loc_expr.is_multiline() || args.iter().any(|loc_arg| loc_arg.is_multiline())
|
||||
}
|
||||
|
||||
Expect(condition, continuation) => {
|
||||
condition.is_multiline() || continuation.is_multiline()
|
||||
}
|
||||
|
||||
If(branches, final_else) => {
|
||||
final_else.is_multiline()
|
||||
|| branches
|
||||
|
|
@ -280,6 +284,9 @@ impl<'a> Formattable<'a> for Expr<'a> {
|
|||
// still print the return value.
|
||||
ret.format_with_options(buf, Parens::NotNeeded, Newlines::Yes, indent);
|
||||
}
|
||||
Expect(condition, continuation) => {
|
||||
fmt_expect(buf, condition, continuation, self.is_multiline(), indent);
|
||||
}
|
||||
If(branches, final_else) => {
|
||||
fmt_if(buf, branches, final_else, self.is_multiline(), indent);
|
||||
}
|
||||
|
|
@ -629,6 +636,25 @@ fn fmt_when<'a>(
|
|||
}
|
||||
}
|
||||
|
||||
fn fmt_expect<'a>(
|
||||
buf: &mut String<'a>,
|
||||
condition: &'a Located<Expr<'a>>,
|
||||
continuation: &'a Located<Expr<'a>>,
|
||||
is_multiline: bool,
|
||||
indent: u16,
|
||||
) {
|
||||
let return_indent = if is_multiline {
|
||||
indent + INDENT
|
||||
} else {
|
||||
indent
|
||||
};
|
||||
|
||||
buf.push_str("expect");
|
||||
condition.format(buf, return_indent);
|
||||
buf.push('\n');
|
||||
continuation.format(buf, return_indent);
|
||||
}
|
||||
|
||||
fn fmt_if<'a>(
|
||||
buf: &mut String<'a>,
|
||||
branches: &'a [(Located<Expr<'a>>, Located<Expr<'a>>)],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue