diff options
| author | Huon Wilson <dbau.pp+github@gmail.com> | 2014-02-24 00:53:59 +1100 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-02-24 21:22:27 -0800 |
| commit | 6757053cffb585249105fbd76f83a2fe7501219b (patch) | |
| tree | 1af550708ee4ee42e1ebcb02a8e38e6cc226d4e1 /src/libsyntax/parse | |
| parent | 0309104cc59d6290fba2fe6dd9bfdc18aacab5f8 (diff) | |
| download | rust-6757053cffb585249105fbd76f83a2fe7501219b.tar.gz rust-6757053cffb585249105fbd76f83a2fe7501219b.zip | |
syntax: allow stmt/expr macro invocations to be delimited by {}.
This makes using control-flow-y macros like `spawn! { ... }` more fluent
and natural.
cc #11892.
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index dac668da343..cbe371a06a5 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3185,15 +3185,35 @@ impl Parser { let pth = self.parse_path(NoTypesAllowed).path; self.bump(); - let id = if self.token == token::LPAREN { + let id = if self.token == token::LPAREN || self.token == token::LBRACE { token::special_idents::invalid // no special identifier } else { self.parse_ident() }; + // check that we're pointing at delimiters (need to check + // again after the `if`, because of `parse_ident` + // consuming more tokens). + let (bra, ket) = match self.token { + token::LPAREN => (token::LPAREN, token::RPAREN), + token::LBRACE => (token::LBRACE, token::RBRACE), + _ => { + // we only expect an ident if we didn't parse one + // above. + let ident_str = if id == token::special_idents::invalid { + "identifier, " + } else { + "" + }; + let tok_str = self.this_token_to_str(); + self.fatal(format!("expected {}`(` or `\\{`, but found `{}`", + ident_str, tok_str)) + } + }; + let tts = self.parse_unspanned_seq( - &token::LPAREN, - &token::RPAREN, + &bra, + &ket, seq_sep_none(), |p| p.parse_token_tree() ); |
