Skip to content

Commit 557cb4a

Browse files
nikomatsakisbrson
authored andcommitted
---
yaml --- r: 20767 b: refs/heads/snap-stage3 c: c206d02 h: refs/heads/master i: 20765: 62a450e 20763: a5c4869 20759: 7181113 20751: cc8fd37 20735: 2213fe5 v: v3
1 parent f486cdc commit 557cb4a

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,7 +1,7 @@
11
---
22
refs/heads/master: e430a699f2c60890d9b86069fd0c68a70ece7120
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: a89ed49d3d01abbd49889832d87650b6c99ff85c
4+
refs/heads/snap-stage3: c206d024eb31124a5d6536ce1f355c4ac0698cab
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libsyntax/ast_util.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,13 @@ fn view_path_id(p: @view_path) -> node_id {
588588
}
589589
}
590590

591+
fn lone_block_expr(blk: blk) -> option<@ast::expr> {
592+
if blk.node.view_items.len() != 0 { ret none; }
593+
if blk.node.stmts.len() != 0 { ret none; }
594+
if blk.node.rules != default_blk { ret none; }
595+
ret blk.node.expr;
596+
}
597+
591598
// Local Variables:
592599
// mode: rust
593600
// fill-column: 78;

branches/snap-stage3/src/libsyntax/parse/parser.rs

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

branches/snap-stage3/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
import util::interner;
@@ -1034,7 +1034,8 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
10341034
print_maybe_parens_discrim(s, expr);
10351035
space(s.s);
10361036
bopen(s);
1037-
for arms.each |arm| {
1037+
let len = arms.len();
1038+
for arms.eachi |i, arm| {
10381039
space(s.s);
10391040
cbox(s, alt_indent_unit);
10401041
ibox(s, 0u);
@@ -1050,8 +1051,19 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
10501051
some(e) { word_space(s, ~"if"); print_expr(s, e); space(s.s); }
10511052
none { }
10521053
}
1053-
print_possibly_embedded_block(s, arm.body, block_normal,
1054-
alt_indent_unit);
1054+
word_space(s, ~"=>");
1055+
alt lone_block_expr(arm.body) {
1056+
some(expr) => {
1057+
end(s); // close the ibox for the pattern
1058+
print_expr(s, expr);
1059+
if i < len - 1 { word_space(s, ~","); }
1060+
end(s); // close enclosing cbox
1061+
}
1062+
none => {
1063+
print_possibly_embedded_block(s, arm.body, block_normal,
1064+
alt_indent_unit);
1065+
}
1066+
}
10551067
}
10561068
bclose_(s, expr.span, alt_indent_unit);
10571069
}
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)