diff options
| author | Marijn Haverbeke <marijnh@gmail.com> | 2011-10-21 14:11:24 +0200 |
|---|---|---|
| committer | Marijn Haverbeke <marijnh@gmail.com> | 2011-10-21 14:24:14 +0200 |
| commit | 71147024962318033ade76ba741d1ecc1dfae3ce (patch) | |
| tree | 42b750199d41f59916ac0542aa141fb254bd9be0 /src/comp/syntax/parse | |
| parent | 0ce40f60e79598c198851154cc978375ed5e7747 (diff) | |
| download | rust-71147024962318033ade76ba741d1ecc1dfae3ce.tar.gz rust-71147024962318033ade76ba741d1ecc1dfae3ce.zip | |
Change the way block calls are parsed, mark them as block-calls.
This makes it possible to omit the semicolon after the block, and will cause the pretty-printer to properly print such calls (if pretty-printing of blocks wasn't so broken). Block calls (with the block outside of the parentheses) can now only occur at statement level, and their value can not be used. When calling a block-style function that returns a useful value, the block must be put insde the parentheses. Issue #1054
Diffstat (limited to 'src/comp/syntax/parse')
| -rw-r--r-- | src/comp/syntax/parse/parser.rs | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index 1a29a033f56..8f632165772 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -977,7 +977,7 @@ fn parse_bottom_expr(p: parser) -> @ast::expr { parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA), parse_expr, p); hi = es.span.hi; - ex = ast::expr_call(f, es.node); + ex = ast::expr_call(f, es.node, false); } else if p.peek() == token::MOD_SEP || is_ident(p.peek()) && !is_word(p, "true") && !is_word(p, "false") { @@ -1051,7 +1051,7 @@ fn parse_dot_or_call_expr_with(p: parser, e: @ast::expr) -> @ast::expr { let es = parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA), parse_expr, p); hi = es.span.hi; - let nd = ast::expr_call(e, es.node); + let nd = ast::expr_call(e, es.node, false); e = mk_expr(p, lo, hi, nd); } } @@ -1073,19 +1073,6 @@ fn parse_dot_or_call_expr_with(p: parser, e: @ast::expr) -> @ast::expr { t { unexpected(p, t); } } } - token::LBRACE. when is_bar(p.look_ahead(1u)) { - p.bump(); - let blk = parse_fn_block_expr(p); - alt e.node { - ast::expr_call(f, args) { - e = @{node: ast::expr_call(f, args + [blk]) with *e}; - } - _ { - e = mk_expr(p, lo, p.get_last_hi_pos(), - ast::expr_call(e, [blk])); - } - } - } _ { ret e; } } } @@ -1569,7 +1556,6 @@ fn parse_source_stmt(p: parser) -> @ast::stmt { let decl = parse_let(p); ret @spanned(lo, decl.span.hi, ast::stmt_decl(decl, p.get_id())); } else { - let item_attrs; alt parse_outer_attrs_or_ext(p) { none. { item_attrs = []; } @@ -1589,7 +1575,6 @@ fn parse_source_stmt(p: parser) -> @ast::stmt { } } - alt maybe_item { some(i) { let hi = i.span.hi; @@ -1599,6 +1584,21 @@ fn parse_source_stmt(p: parser) -> @ast::stmt { none. { // Remainder are line-expr stmts. let e = parse_expr(p); + // See if it is a block call + if p.peek() == token::LBRACE && is_bar(p.look_ahead(1u)) { + p.bump(); + let blk = parse_fn_block_expr(p); + alt e.node { + ast::expr_call(f, args, false) { + e = @{node: ast::expr_call(f, args + [blk], true) + with *e}; + } + _ { + e = mk_expr(p, lo, p.get_last_hi_pos(), + ast::expr_call(e, [blk], true)); + } + } + } ret @spanned(lo, e.span.hi, ast::stmt_expr(e, p.get_id())); } _ { p.fatal("expected statement"); } @@ -1624,6 +1624,7 @@ fn expr_has_value(e: @ast::expr) -> bool { ast::expr_for(_, _, blk) | ast::expr_do_while(blk, _) { !option::is_none(blk.node.expr) } + ast::expr_call(_, _, true) { false } _ { true } } } |
