Skip to content

Commit c458aa9

Browse files
committed
---
yaml --- r: 22620 b: refs/heads/master c: f712b2d h: refs/heads/master v: v3
1 parent d01066e commit c458aa9

File tree

7 files changed

+77
-7
lines changed

7 files changed

+77
-7
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 22f492ab092b6d4948a69eb20037a7409c6119d3
2+
refs/heads/master: f712b2d76b1077a2241916cc3269aa1d83ce3088
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/src/libsyntax/ast_util.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,13 @@ fn view_path_id(p: @view_path) -> node_id {
568568
}
569569
}
570570

571+
fn lone_block_expr(blk: blk) -> option<@ast::expr> {
572+
if blk.node.view_items.len() != 0 { ret none; }
573+
if blk.node.stmts.len() != 0 { ret none; }
574+
if blk.node.rules != default_blk { ret none; }
575+
ret blk.node.expr;
576+
}
577+
571578
// Local Variables:
572579
// mode: rust
573580
// fill-column: 78;

trunk/src/libsyntax/parse/parser.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,8 +1509,25 @@ class parser {
15091509
let pats = self.parse_pats();
15101510
let mut guard = none;
15111511
if self.eat_keyword(~"if") { guard = some(self.parse_expr()); }
1512-
if self.token == token::FAT_ARROW { self.bump(); }
1513-
let blk = self.parse_block();
1512+
let blk = if self.token != token::FAT_ARROW {
1513+
self.parse_block()
1514+
} else {
1515+
self.bump();
1516+
if self.token == token::LBRACE {
1517+
self.parse_block()
1518+
} else {
1519+
let expr = self.parse_expr();
1520+
if self.token != token::RBRACE {
1521+
self.expect(token::COMMA);
1522+
}
1523+
{node: {view_items: ~[],
1524+
stmts: ~[],
1525+
expr: some(expr),
1526+
id: self.get_id(),
1527+
rules: default_blk},
1528+
span: expr.span}
1529+
}
1530+
};
15141531
vec::push(arms, {pats: pats, guard: guard, body: blk});
15151532
}
15161533
let mut hi = self.span.hi;

trunk/src/libsyntax/print/pprust.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import pp::{break_offset, word, printer,
66
inconsistent, eof};
77
import diagnostic;
88
import ast::{required, provided};
9-
import ast_util::operator_prec;
9+
import ast_util::{operator_prec, lone_block_expr};
1010
import dvec::{dvec, extensions};
1111
import parse::classify::*;
1212

@@ -998,7 +998,8 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
998998
print_maybe_parens_discrim(s, expr);
999999
space(s.s);
10001000
bopen(s);
1001-
for arms.each |arm| {
1001+
let len = arms.len();
1002+
for arms.eachi |i, arm| {
10021003
space(s.s);
10031004
cbox(s, alt_indent_unit);
10041005
ibox(s, 0u);
@@ -1014,8 +1015,19 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
10141015
some(e) { word_space(s, ~"if"); print_expr(s, e); space(s.s); }
10151016
none { }
10161017
}
1017-
print_possibly_embedded_block(s, arm.body, block_normal,
1018-
alt_indent_unit);
1018+
word_space(s, ~"=>");
1019+
alt lone_block_expr(arm.body) {
1020+
some(expr) => {
1021+
end(s); // close the ibox for the pattern
1022+
print_expr(s, expr);
1023+
if i < len - 1 { word_space(s, ~","); }
1024+
end(s); // close enclosing cbox
1025+
}
1026+
none => {
1027+
print_possibly_embedded_block(s, arm.body, block_normal,
1028+
alt_indent_unit);
1029+
}
1030+
}
10191031
}
10201032
bclose_(s, expr.span, alt_indent_unit);
10211033
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// pretty-exact
2+
3+
// actually this doesn't quite look how I want it to, but I can't
4+
// get the prettyprinter to indent the long expr
5+
6+
fn main() {
7+
let x = some(3);
8+
let y =
9+
alt x {
10+
some(_) =>
11+
"some" + "very" + "very" + "very" + "very" + "very" + "very" +
12+
"very" + "very" + "long" + "string",
13+
14+
none => "none"
15+
};
16+
assert y == "some(_)";
17+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// pretty-exact
2+
3+
fn main() {
4+
let x = some(3);
5+
let _y =
6+
alt x {
7+
some(_) => ~[~"some(_)", ~"not", ~"SO", ~"long", ~"string"],
8+
none => ~[~"none"]
9+
};
10+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// pretty-exact
2+
3+
fn main() {
4+
let x = some(3);
5+
let y = alt x { some(_) => "some(_)", none => "none" };
6+
assert y == "some(_)";
7+
}

0 commit comments

Comments
 (0)