mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
parse expect
This commit is contained in:
parent
50942325b9
commit
700e7d9686
12 changed files with 223 additions and 5 deletions
|
@ -3,6 +3,7 @@ use crate::pattern::fmt_pattern;
|
|||
use crate::spaces::{fmt_spaces, newline, INDENT};
|
||||
use bumpalo::collections::String;
|
||||
use roc_parse::ast::{Def, Expr, Pattern};
|
||||
use roc_region::all::Located;
|
||||
|
||||
/// A Located formattable value is also formattable
|
||||
impl<'a> Formattable<'a> for Def<'a> {
|
||||
|
@ -16,6 +17,7 @@ impl<'a> Formattable<'a> for Def<'a> {
|
|||
}
|
||||
Body(loc_pattern, loc_expr) => loc_pattern.is_multiline() || loc_expr.is_multiline(),
|
||||
AnnotatedBody { .. } => true,
|
||||
Expect(loc_expr) => loc_expr.is_multiline(),
|
||||
SpaceBefore(sub_def, spaces) | SpaceAfter(sub_def, spaces) => {
|
||||
spaces.iter().any(|s| s.is_comment()) || sub_def.is_multiline()
|
||||
}
|
||||
|
@ -72,6 +74,7 @@ impl<'a> Formattable<'a> for Def<'a> {
|
|||
Body(loc_pattern, loc_expr) => {
|
||||
fmt_body(buf, &loc_pattern.value, &loc_expr.value, indent);
|
||||
}
|
||||
Expect(condition) => fmt_expect(buf, condition, self.is_multiline(), indent),
|
||||
AnnotatedBody {
|
||||
ann_pattern,
|
||||
ann_type,
|
||||
|
@ -103,6 +106,22 @@ impl<'a> Formattable<'a> for Def<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn fmt_expect<'a>(
|
||||
buf: &mut String<'a>,
|
||||
condition: &'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);
|
||||
}
|
||||
|
||||
pub fn fmt_def<'a>(buf: &mut String<'a>, def: &Def<'a>, indent: u16) {
|
||||
def.format(buf, indent);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue