Skip to content

Commit 55776f2

Browse files
author
Keegan McAllister
committed
Parse macros in patterns
Fixes #6830.
1 parent b2f6dd5 commit 55776f2

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

src/libsyntax/parse/parser.rs

+20-7
Original file line numberDiff line numberDiff line change
@@ -2911,15 +2911,28 @@ impl<'a> Parser<'a> {
29112911
pat = PatRange(start, end);
29122912
} else if is_plain_ident(&self.token) && !can_be_enum_or_struct {
29132913
let name = self.parse_path(NoTypesAllowed).path;
2914-
let sub;
2915-
if self.eat(&token::AT) {
2916-
// parse foo @ pat
2917-
sub = Some(self.parse_pat());
2914+
if self.eat(&token::NOT) {
2915+
// macro invocation
2916+
let ket = token::close_delimiter_for(&self.token)
2917+
.unwrap_or_else(|| self.fatal("expected open delimiter"));
2918+
self.bump();
2919+
2920+
let tts = self.parse_seq_to_end(&ket,
2921+
seq_sep_none(),
2922+
|p| p.parse_token_tree());
2923+
2924+
let mac = MacInvocTT(name, tts, EMPTY_CTXT);
2925+
pat = ast::PatMac(codemap::Spanned {node: mac, span: self.span});
29182926
} else {
2919-
// or just foo
2920-
sub = None;
2927+
let sub = if self.eat(&token::AT) {
2928+
// parse foo @ pat
2929+
Some(self.parse_pat())
2930+
} else {
2931+
// or just foo
2932+
None
2933+
};
2934+
pat = PatIdent(BindByValue(MutImmutable), name, sub);
29212935
}
2922-
pat = PatIdent(BindByValue(MutImmutable), name, sub);
29232936
} else {
29242937
// parse an enum pat
29252938
let enum_path = self.parse_path(LifetimeAndTypesWithColons)

0 commit comments

Comments
 (0)