diff options
| author | Keegan McAllister <kmcallister@mozilla.com> | 2014-05-19 15:03:48 -0700 |
|---|---|---|
| committer | Keegan McAllister <kmcallister@mozilla.com> | 2014-05-28 12:42:21 -0700 |
| commit | 55776f28221e3da7dd31c2c6c5e05f7a9a31381f (patch) | |
| tree | 5f4732c2ee2c787da7a62883048749d7fa35c7b6 /src/libsyntax | |
| parent | b2f6dd53c95c866e206798976cfcc2f9a9b2fe2a (diff) | |
| download | rust-55776f28221e3da7dd31c2c6c5e05f7a9a31381f.tar.gz rust-55776f28221e3da7dd31c2c6c5e05f7a9a31381f.zip | |
Parse macros in patterns
Fixes #6830.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 6832555f728..65ad83d4b4f 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2911,15 +2911,28 @@ impl<'a> Parser<'a> { pat = PatRange(start, end); } else if is_plain_ident(&self.token) && !can_be_enum_or_struct { let name = self.parse_path(NoTypesAllowed).path; - let sub; - if self.eat(&token::AT) { - // parse foo @ pat - sub = Some(self.parse_pat()); + if self.eat(&token::NOT) { + // macro invocation + let ket = token::close_delimiter_for(&self.token) + .unwrap_or_else(|| self.fatal("expected open delimiter")); + self.bump(); + + let tts = self.parse_seq_to_end(&ket, + seq_sep_none(), + |p| p.parse_token_tree()); + + let mac = MacInvocTT(name, tts, EMPTY_CTXT); + pat = ast::PatMac(codemap::Spanned {node: mac, span: self.span}); } else { - // or just foo - sub = None; + let sub = if self.eat(&token::AT) { + // parse foo @ pat + Some(self.parse_pat()) + } else { + // or just foo + None + }; + pat = PatIdent(BindByValue(MutImmutable), name, sub); } - pat = PatIdent(BindByValue(MutImmutable), name, sub); } else { // parse an enum pat let enum_path = self.parse_path(LifetimeAndTypesWithColons) |
