diff options
| author | Marijn Haverbeke <marijnh@gmail.com> | 2011-12-09 09:42:09 +0100 |
|---|---|---|
| committer | Marijn Haverbeke <marijnh@gmail.com> | 2011-12-09 09:42:22 +0100 |
| commit | 44ffd8e3aadccbceb544074a3b96e255d0d97325 (patch) | |
| tree | 17b80b745a6bd1ac8171c9a8cff553b5b2bed149 /src/comp/syntax/parse | |
| parent | 54f72fbc10e3846214423d8734c15eebe0228575 (diff) | |
| download | rust-44ffd8e3aadccbceb544074a3b96e255d0d97325.tar.gz rust-44ffd8e3aadccbceb544074a3b96e255d0d97325.zip | |
Allow type annotations for blocks
I.e. {|foo: int| -> int foo + 2}
Issue #1275
Diffstat (limited to 'src/comp/syntax/parse')
| -rw-r--r-- | src/comp/syntax/parse/parser.rs | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index 52e2d92e799..7b8bd726eed 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -567,7 +567,8 @@ fn parse_arg(p: parser) -> ast::arg { fn parse_fn_block_arg(p: parser) -> ast::arg { let m = parse_arg_mode(p); let i = parse_value_ident(p); - let t = @spanned(p.get_lo_pos(), p.get_hi_pos(), ast::ty_infer); + let t = eat(p, token::COLON) ? parse_ty(p, false) : + @spanned(p.get_lo_pos(), p.get_hi_pos(), ast::ty_infer); ret {mode: m, ty: t, ident: i, id: p.get_id()}; } @@ -1747,16 +1748,13 @@ fn parse_fn_decl(p: parser, purity: ast::purity, il: ast::inlineness) -> } fn parse_fn_block_decl(p: parser) -> ast::fn_decl { - let inputs = - if p.peek() == token::OROR { - p.bump(); - [] - } else { - parse_seq(token::BINOP(token::OR), token::BINOP(token::OR), - seq_sep(token::COMMA), parse_fn_block_arg, p).node - }; + let inputs = eat(p, token::OROR) ? [] : + parse_seq(token::BINOP(token::OR), token::BINOP(token::OR), + seq_sep(token::COMMA), parse_fn_block_arg, p).node; + let output = eat(p, token::RARROW) ? parse_ty(p, false) : + @spanned(p.get_lo_pos(), p.get_hi_pos(), ast::ty_infer); ret {inputs: inputs, - output: @spanned(p.get_lo_pos(), p.get_hi_pos(), ast::ty_infer), + output: output, purity: ast::impure_fn, il: ast::il_normal, cf: ast::return_val, |
