Skip to content

Commit

Permalink
feat(format): Format do expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
Marwes committed Dec 2, 2017
1 parent a94c684 commit 71157db
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
18 changes: 17 additions & 1 deletion format/src/pretty_print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{iter, ops};
use itertools::{Either, Itertools};
use pretty::{Arena, DocAllocator, DocBuilder};

use base::ast::{Expr, Pattern, SpannedExpr, SpannedPattern, ValueBinding};
use base::ast::{Do, Expr, Pattern, SpannedExpr, SpannedPattern, ValueBinding};
use base::kind::Kind;
use base::pos::{self, BytePos, HasSpan, Span, Spanned};
use base::source;
Expand Down Expand Up @@ -288,6 +288,22 @@ impl<'a: 'e, 'e> Printer<'a, 'e> {
self.pretty_expr_(binds.last().unwrap().alias.span.end, body)
].group()
}
Expr::Do(Do {
ref id,
ref bound,
ref body,
..
}) => chain![arena;
chain![arena;
"do",
self.space_before(id.span.start),
id.value.name.as_ref(),
self.space_after(id.span.end),
"=",
self.hang(arena.nil(), bound).group()
].group(),
self.pretty_expr_(bound.span.end, body)
],
Expr::Error(_) => arena.text("<error>"),
};
comments.append(doc)
Expand Down
10 changes: 10 additions & 0 deletions format/tests/pretty_print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,13 @@ let semigroup =
"#;
assert_diff!(&format_expr(expr).unwrap(), expr, " ", 0);
}

#[test]
fn do_expression() {
let expr = r#"
do /* x1 */ x /* x2 */ = Some 1
// test
test abc 1232 ""
"#;
assert_diff!(&format_expr(expr).unwrap(), expr, " ", 0);
}

0 comments on commit 71157db

Please sign in to comment.