diff --git a/crates/ra_mbe/src/lib.rs b/crates/ra_mbe/src/lib.rs index 87782e5b91..b9f555ef6c 100644 --- a/crates/ra_mbe/src/lib.rs +++ b/crates/ra_mbe/src/lib.rs @@ -30,7 +30,7 @@ pub use crate::syntax_bridge::ast_to_token_tree; /// be very confusing is that AST has almost exactly the same shape as /// `tt::TokenTree`, but there's a crucial difference: in macro rules, `$ident` /// and `$()*` have special meaning (see `Var` and `Repeat` data structures) -#[derive(Debug)] +#[derive(Debug, PartialEq, Eq)] pub struct MacroRules { pub(crate) rules: Vec, } @@ -44,13 +44,13 @@ impl MacroRules { } } -#[derive(Debug)] +#[derive(Debug, PartialEq, Eq)] pub(crate) struct Rule { pub(crate) lhs: Subtree, pub(crate) rhs: Subtree, } -#[derive(Debug)] +#[derive(Debug, PartialEq, Eq)] pub(crate) enum TokenTree { Leaf(Leaf), Subtree(Subtree), @@ -58,7 +58,7 @@ pub(crate) enum TokenTree { } impl_froms!(TokenTree: Leaf, Subtree, Repeat); -#[derive(Debug)] +#[derive(Debug, PartialEq, Eq)] pub(crate) enum Leaf { Literal(Literal), Punct(Punct), @@ -67,37 +67,37 @@ pub(crate) enum Leaf { } impl_froms!(Leaf: Literal, Punct, Ident, Var); -#[derive(Debug)] +#[derive(Debug, PartialEq, Eq)] pub(crate) struct Subtree { pub(crate) delimiter: Delimiter, pub(crate) token_trees: Vec, } -#[derive(Debug)] +#[derive(Debug, PartialEq, Eq)] pub(crate) struct Repeat { pub(crate) subtree: Subtree, pub(crate) kind: RepeatKind, pub(crate) separator: Option, } -#[derive(Debug)] +#[derive(Debug, PartialEq, Eq)] pub(crate) enum RepeatKind { ZeroOrMore, OneOrMore, ZeroOrOne, } -#[derive(Debug)] +#[derive(Debug, PartialEq, Eq)] pub(crate) struct Literal { pub(crate) text: SmolStr, } -#[derive(Debug)] +#[derive(Debug, PartialEq, Eq)] pub(crate) struct Ident { pub(crate) text: SmolStr, } -#[derive(Debug)] +#[derive(Debug, PartialEq, Eq)] pub(crate) struct Var { pub(crate) text: SmolStr, pub(crate) kind: Option, diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 256277609f..d2b080743b 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs @@ -1908,6 +1908,7 @@ impl ToOwned for MacroCall { } +impl ast::NameOwner for MacroCall {} impl MacroCall { pub fn token_tree(&self) -> Option<&TokenTree> { super::child_opt(self) diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index d428bc5955..2e4b2d776c 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron @@ -545,7 +545,10 @@ Grammar( "Visibility": (), "Name": (), "NameRef": (), - "MacroCall": ( options: [ "TokenTree", "Path" ] ), + "MacroCall": ( + traits: [ "NameOwner" ], + options: [ "TokenTree", "Path" ], + ), "Attr": ( options: [ ["value", "TokenTree"] ] ), "TokenTree": (), "TypeParamList": ( diff --git a/crates/ra_syntax/src/grammar/items.rs b/crates/ra_syntax/src/grammar/items.rs index a61f260cf1..4b962c1f37 100644 --- a/crates/ra_syntax/src/grammar/items.rs +++ b/crates/ra_syntax/src/grammar/items.rs @@ -347,7 +347,9 @@ fn macro_call(p: &mut Parser) -> BlockLike { pub(super) fn macro_call_after_excl(p: &mut Parser) -> BlockLike { p.expect(EXCL); - p.eat(IDENT); + if p.at(IDENT) { + name(p); + } match p.current() { L_CURLY => { token_tree(p); diff --git a/crates/ra_syntax/tests/data/parser/err/0028_macro_2.0.txt b/crates/ra_syntax/tests/data/parser/err/0028_macro_2.0.txt index 12919fab7a..440bd7f92a 100644 --- a/crates/ra_syntax/tests/data/parser/err/0028_macro_2.0.txt +++ b/crates/ra_syntax/tests/data/parser/err/0028_macro_2.0.txt @@ -6,7 +6,8 @@ SOURCE_FILE@[0; 349) IDENT@[0; 5) "macro" err: `expected EXCL` WHITESPACE@[5; 6) - IDENT@[6; 21) "parse_use_trees" + NAME@[6; 21) + IDENT@[6; 21) "parse_use_trees" TOKEN_TREE@[21; 41) L_PAREN@[21; 22) DOLLAR@[22; 23) diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0062_mod_contents.txt b/crates/ra_syntax/tests/data/parser/inline/ok/0062_mod_contents.txt index 62528ca47c..6ccd0ffc30 100644 --- a/crates/ra_syntax/tests/data/parser/inline/ok/0062_mod_contents.txt +++ b/crates/ra_syntax/tests/data/parser/inline/ok/0062_mod_contents.txt @@ -19,7 +19,8 @@ SOURCE_FILE@[0; 70) IDENT@[12; 23) "macro_rules" EXCL@[23; 24) WHITESPACE@[24; 25) - IDENT@[25; 28) "foo" + NAME@[25; 28) + IDENT@[25; 28) "foo" WHITESPACE@[28; 29) TOKEN_TREE@[29; 31) L_CURLY@[29; 30) diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0096_no_semi_after_block.txt b/crates/ra_syntax/tests/data/parser/inline/ok/0096_no_semi_after_block.txt index 63b2300916..ac789651a5 100644 --- a/crates/ra_syntax/tests/data/parser/inline/ok/0096_no_semi_after_block.txt +++ b/crates/ra_syntax/tests/data/parser/inline/ok/0096_no_semi_after_block.txt @@ -92,7 +92,8 @@ SOURCE_FILE@[0; 167) IDENT@[109; 120) "macro_rules" EXCL@[120; 121) WHITESPACE@[121; 122) - IDENT@[122; 126) "test" + NAME@[122; 126) + IDENT@[122; 126) "test" WHITESPACE@[126; 127) TOKEN_TREE@[127; 152) L_CURLY@[127; 128) diff --git a/crates/ra_tt/src/lib.rs b/crates/ra_tt/src/lib.rs index 043417abcc..df31f72f39 100644 --- a/crates/ra_tt/src/lib.rs +++ b/crates/ra_tt/src/lib.rs @@ -39,7 +39,7 @@ pub struct Subtree { pub token_trees: Vec, } -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Delimiter { Parenthesis, Brace,