Skip to content

Commit 77ccac7

Browse files
bors[bot]matklad
andcommitted
Merge #790
790: make macro-rules eq r=matklad a=matklad Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 parents a180674 + 2efdf41 commit 77ccac7

File tree

8 files changed

+25
-16
lines changed

8 files changed

+25
-16
lines changed

crates/ra_mbe/src/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub use crate::syntax_bridge::ast_to_token_tree;
3030
/// be very confusing is that AST has almost exactly the same shape as
3131
/// `tt::TokenTree`, but there's a crucial difference: in macro rules, `$ident`
3232
/// and `$()*` have special meaning (see `Var` and `Repeat` data structures)
33-
#[derive(Debug)]
33+
#[derive(Debug, PartialEq, Eq)]
3434
pub struct MacroRules {
3535
pub(crate) rules: Vec<Rule>,
3636
}
@@ -44,21 +44,21 @@ impl MacroRules {
4444
}
4545
}
4646

47-
#[derive(Debug)]
47+
#[derive(Debug, PartialEq, Eq)]
4848
pub(crate) struct Rule {
4949
pub(crate) lhs: Subtree,
5050
pub(crate) rhs: Subtree,
5151
}
5252

53-
#[derive(Debug)]
53+
#[derive(Debug, PartialEq, Eq)]
5454
pub(crate) enum TokenTree {
5555
Leaf(Leaf),
5656
Subtree(Subtree),
5757
Repeat(Repeat),
5858
}
5959
impl_froms!(TokenTree: Leaf, Subtree, Repeat);
6060

61-
#[derive(Debug)]
61+
#[derive(Debug, PartialEq, Eq)]
6262
pub(crate) enum Leaf {
6363
Literal(Literal),
6464
Punct(Punct),
@@ -67,37 +67,37 @@ pub(crate) enum Leaf {
6767
}
6868
impl_froms!(Leaf: Literal, Punct, Ident, Var);
6969

70-
#[derive(Debug)]
70+
#[derive(Debug, PartialEq, Eq)]
7171
pub(crate) struct Subtree {
7272
pub(crate) delimiter: Delimiter,
7373
pub(crate) token_trees: Vec<TokenTree>,
7474
}
7575

76-
#[derive(Debug)]
76+
#[derive(Debug, PartialEq, Eq)]
7777
pub(crate) struct Repeat {
7878
pub(crate) subtree: Subtree,
7979
pub(crate) kind: RepeatKind,
8080
pub(crate) separator: Option<char>,
8181
}
8282

83-
#[derive(Debug)]
83+
#[derive(Debug, PartialEq, Eq)]
8484
pub(crate) enum RepeatKind {
8585
ZeroOrMore,
8686
OneOrMore,
8787
ZeroOrOne,
8888
}
8989

90-
#[derive(Debug)]
90+
#[derive(Debug, PartialEq, Eq)]
9191
pub(crate) struct Literal {
9292
pub(crate) text: SmolStr,
9393
}
9494

95-
#[derive(Debug)]
95+
#[derive(Debug, PartialEq, Eq)]
9696
pub(crate) struct Ident {
9797
pub(crate) text: SmolStr,
9898
}
9999

100-
#[derive(Debug)]
100+
#[derive(Debug, PartialEq, Eq)]
101101
pub(crate) struct Var {
102102
pub(crate) text: SmolStr,
103103
pub(crate) kind: Option<SmolStr>,

crates/ra_syntax/src/ast/generated.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,6 +1908,7 @@ impl ToOwned for MacroCall {
19081908
}
19091909

19101910

1911+
impl ast::NameOwner for MacroCall {}
19111912
impl MacroCall {
19121913
pub fn token_tree(&self) -> Option<&TokenTree> {
19131914
super::child_opt(self)

crates/ra_syntax/src/grammar.ron

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,10 @@ Grammar(
545545
"Visibility": (),
546546
"Name": (),
547547
"NameRef": (),
548-
"MacroCall": ( options: [ "TokenTree", "Path" ] ),
548+
"MacroCall": (
549+
traits: [ "NameOwner" ],
550+
options: [ "TokenTree", "Path" ],
551+
),
549552
"Attr": ( options: [ ["value", "TokenTree"] ] ),
550553
"TokenTree": (),
551554
"TypeParamList": (

crates/ra_syntax/src/grammar/items.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,9 @@ fn macro_call(p: &mut Parser) -> BlockLike {
347347

348348
pub(super) fn macro_call_after_excl(p: &mut Parser) -> BlockLike {
349349
p.expect(EXCL);
350-
p.eat(IDENT);
350+
if p.at(IDENT) {
351+
name(p);
352+
}
351353
match p.current() {
352354
L_CURLY => {
353355
token_tree(p);

crates/ra_syntax/tests/data/parser/err/0028_macro_2.0.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ SOURCE_FILE@[0; 349)
66
IDENT@[0; 5) "macro"
77
err: `expected EXCL`
88
WHITESPACE@[5; 6)
9-
IDENT@[6; 21) "parse_use_trees"
9+
NAME@[6; 21)
10+
IDENT@[6; 21) "parse_use_trees"
1011
TOKEN_TREE@[21; 41)
1112
L_PAREN@[21; 22)
1213
DOLLAR@[22; 23)

crates/ra_syntax/tests/data/parser/inline/ok/0062_mod_contents.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ SOURCE_FILE@[0; 70)
1919
IDENT@[12; 23) "macro_rules"
2020
EXCL@[23; 24)
2121
WHITESPACE@[24; 25)
22-
IDENT@[25; 28) "foo"
22+
NAME@[25; 28)
23+
IDENT@[25; 28) "foo"
2324
WHITESPACE@[28; 29)
2425
TOKEN_TREE@[29; 31)
2526
L_CURLY@[29; 30)

crates/ra_syntax/tests/data/parser/inline/ok/0096_no_semi_after_block.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ SOURCE_FILE@[0; 167)
9292
IDENT@[109; 120) "macro_rules"
9393
EXCL@[120; 121)
9494
WHITESPACE@[121; 122)
95-
IDENT@[122; 126) "test"
95+
NAME@[122; 126)
96+
IDENT@[122; 126) "test"
9697
WHITESPACE@[126; 127)
9798
TOKEN_TREE@[127; 152)
9899
L_CURLY@[127; 128)

crates/ra_tt/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub struct Subtree {
3939
pub token_trees: Vec<TokenTree>,
4040
}
4141

42-
#[derive(Clone, Copy, Debug)]
42+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
4343
pub enum Delimiter {
4444
Parenthesis,
4545
Brace,

0 commit comments

Comments
 (0)