Revert "accept naked exprs with commas in pattern arms" due to pretty-printing failures
This reverts commit f712b2d76b
.
In alt arms, the parser needs to do a little lookahead to determine
whether it's looking at a record literal or a block.
Also there are some indentation issues in the expected source.
This commit is contained in:
parent
00aa5f163f
commit
978ca03cb2
6 changed files with 6 additions and 76 deletions
|
@ -568,13 +568,6 @@ fn view_path_id(p: @view_path) -> node_id {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lone_block_expr(blk: blk) -> option<@ast::expr> {
|
|
||||||
if blk.node.view_items.len() != 0 { ret none; }
|
|
||||||
if blk.node.stmts.len() != 0 { ret none; }
|
|
||||||
if blk.node.rules != default_blk { ret none; }
|
|
||||||
ret blk.node.expr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Local Variables:
|
// Local Variables:
|
||||||
// mode: rust
|
// mode: rust
|
||||||
// fill-column: 78;
|
// fill-column: 78;
|
||||||
|
|
|
@ -1509,25 +1509,8 @@ class parser {
|
||||||
let pats = self.parse_pats();
|
let pats = self.parse_pats();
|
||||||
let mut guard = none;
|
let mut guard = none;
|
||||||
if self.eat_keyword(~"if") { guard = some(self.parse_expr()); }
|
if self.eat_keyword(~"if") { guard = some(self.parse_expr()); }
|
||||||
let blk = if self.token != token::FAT_ARROW {
|
if self.token == token::FAT_ARROW { self.bump(); }
|
||||||
self.parse_block()
|
let blk = self.parse_block();
|
||||||
} else {
|
|
||||||
self.bump();
|
|
||||||
if self.token == token::LBRACE {
|
|
||||||
self.parse_block()
|
|
||||||
} else {
|
|
||||||
let expr = self.parse_expr();
|
|
||||||
if self.token != token::RBRACE {
|
|
||||||
self.expect(token::COMMA);
|
|
||||||
}
|
|
||||||
{node: {view_items: ~[],
|
|
||||||
stmts: ~[],
|
|
||||||
expr: some(expr),
|
|
||||||
id: self.get_id(),
|
|
||||||
rules: default_blk},
|
|
||||||
span: expr.span}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
vec::push(arms, {pats: pats, guard: guard, body: blk});
|
vec::push(arms, {pats: pats, guard: guard, body: blk});
|
||||||
}
|
}
|
||||||
let mut hi = self.span.hi;
|
let mut hi = self.span.hi;
|
||||||
|
|
|
@ -6,7 +6,7 @@ import pp::{break_offset, word, printer,
|
||||||
inconsistent, eof};
|
inconsistent, eof};
|
||||||
import diagnostic;
|
import diagnostic;
|
||||||
import ast::{required, provided};
|
import ast::{required, provided};
|
||||||
import ast_util::{operator_prec, lone_block_expr};
|
import ast_util::operator_prec;
|
||||||
import dvec::{dvec, extensions};
|
import dvec::{dvec, extensions};
|
||||||
import parse::classify::*;
|
import parse::classify::*;
|
||||||
|
|
||||||
|
@ -998,8 +998,7 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
|
||||||
print_maybe_parens_discrim(s, expr);
|
print_maybe_parens_discrim(s, expr);
|
||||||
space(s.s);
|
space(s.s);
|
||||||
bopen(s);
|
bopen(s);
|
||||||
let len = arms.len();
|
for arms.each |arm| {
|
||||||
for arms.eachi |i, arm| {
|
|
||||||
space(s.s);
|
space(s.s);
|
||||||
cbox(s, alt_indent_unit);
|
cbox(s, alt_indent_unit);
|
||||||
ibox(s, 0u);
|
ibox(s, 0u);
|
||||||
|
@ -1015,19 +1014,8 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
|
||||||
some(e) { word_space(s, ~"if"); print_expr(s, e); space(s.s); }
|
some(e) { word_space(s, ~"if"); print_expr(s, e); space(s.s); }
|
||||||
none { }
|
none { }
|
||||||
}
|
}
|
||||||
word_space(s, ~"=>");
|
print_possibly_embedded_block(s, arm.body, block_normal,
|
||||||
alt lone_block_expr(arm.body) {
|
alt_indent_unit);
|
||||||
some(expr) => {
|
|
||||||
end(s); // close the ibox for the pattern
|
|
||||||
print_expr(s, expr);
|
|
||||||
if i < len - 1 { word_space(s, ~","); }
|
|
||||||
end(s); // close enclosing cbox
|
|
||||||
}
|
|
||||||
none => {
|
|
||||||
print_possibly_embedded_block(s, arm.body, block_normal,
|
|
||||||
alt_indent_unit);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
bclose_(s, expr.span, alt_indent_unit);
|
bclose_(s, expr.span, alt_indent_unit);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
// pretty-exact
|
|
||||||
|
|
||||||
// actually this doesn't quite look how I want it to, but I can't
|
|
||||||
// get the prettyprinter to indent the long expr
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let x = some(3);
|
|
||||||
let y =
|
|
||||||
alt x {
|
|
||||||
some(_) =>
|
|
||||||
"some" + "very" + "very" + "very" + "very" + "very" + "very" +
|
|
||||||
"very" + "very" + "long" + "string",
|
|
||||||
|
|
||||||
none => "none"
|
|
||||||
};
|
|
||||||
assert y == "some(_)";
|
|
||||||
}
|
|
|
@ -1,10 +0,0 @@
|
||||||
// pretty-exact
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let x = some(3);
|
|
||||||
let _y =
|
|
||||||
alt x {
|
|
||||||
some(_) => ~[~"some(_)", ~"not", ~"SO", ~"long", ~"string"],
|
|
||||||
none => ~[~"none"]
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
// pretty-exact
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let x = some(3);
|
|
||||||
let y = alt x { some(_) => "some(_)", none => "none" };
|
|
||||||
assert y == "some(_)";
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue