From 3e0bb895418b2042ee9cd14b2444a36c87a3f449 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Thu, 24 Dec 2020 09:26:03 +0100 Subject: Fix macro_rules not accepting brackets or parentheses --- crates/parser/src/grammar/items.rs | 9 +++- .../inline/ok/0158_macro_rules_non_brace.rast | 57 ++++++++++++++++++++++ .../parser/inline/ok/0158_macro_rules_non_brace.rs | 2 + 3 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 crates/syntax/test_data/parser/inline/ok/0158_macro_rules_non_brace.rast create mode 100644 crates/syntax/test_data/parser/inline/ok/0158_macro_rules_non_brace.rs diff --git a/crates/parser/src/grammar/items.rs b/crates/parser/src/grammar/items.rs index 72b73f891..cf4168d32 100644 --- a/crates/parser/src/grammar/items.rs +++ b/crates/parser/src/grammar/items.rs @@ -389,10 +389,15 @@ fn macro_rules(p: &mut Parser, m: Marker) { } match p.current() { - T!['{'] => { + // test macro_rules_non_brace + // macro_rules! m ( ($i:ident) => {} ); + // macro_rules! m [ ($i:ident) => {} ]; + T!['['] | T!['('] => { token_tree(p); + p.expect(T![;]); } - _ => p.error("expected `{`"), + T!['{'] => token_tree(p), + _ => p.error("expected `{`, `[`, `(`"), } m.complete(p, MACRO_RULES); } diff --git a/crates/syntax/test_data/parser/inline/ok/0158_macro_rules_non_brace.rast b/crates/syntax/test_data/parser/inline/ok/0158_macro_rules_non_brace.rast new file mode 100644 index 000000000..4a1f712aa --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0158_macro_rules_non_brace.rast @@ -0,0 +1,57 @@ +SOURCE_FILE@0..74 + MACRO_RULES@0..36 + MACRO_RULES_KW@0..11 "macro_rules" + BANG@11..12 "!" + WHITESPACE@12..13 " " + NAME@13..14 + IDENT@13..14 "m" + WHITESPACE@14..15 " " + TOKEN_TREE@15..35 + L_PAREN@15..16 "(" + WHITESPACE@16..17 " " + TOKEN_TREE@17..27 + L_PAREN@17..18 "(" + DOLLAR@18..19 "$" + IDENT@19..20 "i" + COLON@20..21 ":" + IDENT@21..26 "ident" + R_PAREN@26..27 ")" + WHITESPACE@27..28 " " + EQ@28..29 "=" + R_ANGLE@29..30 ">" + WHITESPACE@30..31 " " + TOKEN_TREE@31..33 + L_CURLY@31..32 "{" + R_CURLY@32..33 "}" + WHITESPACE@33..34 " " + R_PAREN@34..35 ")" + SEMICOLON@35..36 ";" + WHITESPACE@36..37 "\n" + MACRO_RULES@37..73 + MACRO_RULES_KW@37..48 "macro_rules" + BANG@48..49 "!" + WHITESPACE@49..50 " " + NAME@50..51 + IDENT@50..51 "m" + WHITESPACE@51..52 " " + TOKEN_TREE@52..72 + L_BRACK@52..53 "[" + WHITESPACE@53..54 " " + TOKEN_TREE@54..64 + L_PAREN@54..55 "(" + DOLLAR@55..56 "$" + IDENT@56..57 "i" + COLON@57..58 ":" + IDENT@58..63 "ident" + R_PAREN@63..64 ")" + WHITESPACE@64..65 " " + EQ@65..66 "=" + R_ANGLE@66..67 ">" + WHITESPACE@67..68 " " + TOKEN_TREE@68..70 + L_CURLY@68..69 "{" + R_CURLY@69..70 "}" + WHITESPACE@70..71 " " + R_BRACK@71..72 "]" + SEMICOLON@72..73 ";" + WHITESPACE@73..74 "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0158_macro_rules_non_brace.rs b/crates/syntax/test_data/parser/inline/ok/0158_macro_rules_non_brace.rs new file mode 100644 index 000000000..6033a28cd --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0158_macro_rules_non_brace.rs @@ -0,0 +1,2 @@ +macro_rules! m ( ($i:ident) => {} ); +macro_rules! m [ ($i:ident) => {} ]; -- cgit v1.2.3