aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-02-11 16:24:39 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-02-11 16:24:39 +0000
commit77ccac74f94fbe387fc587d46f9d93f04fce3644 (patch)
treef0cc15c1fb77ca429717fcb1d5975f5cb5622c9e /crates
parenta180674986df6ff4c1934dc92f29b49e607477db (diff)
parent2efdf41bdb178ebf1ff0f8e3b335f491c84d7fa3 (diff)
Merge #790
790: make macro-rules eq r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_mbe/src/lib.rs20
-rw-r--r--crates/ra_syntax/src/ast/generated.rs1
-rw-r--r--crates/ra_syntax/src/grammar.ron5
-rw-r--r--crates/ra_syntax/src/grammar/items.rs4
-rw-r--r--crates/ra_syntax/tests/data/parser/err/0028_macro_2.0.txt3
-rw-r--r--crates/ra_syntax/tests/data/parser/inline/ok/0062_mod_contents.txt3
-rw-r--r--crates/ra_syntax/tests/data/parser/inline/ok/0096_no_semi_after_block.txt3
-rw-r--r--crates/ra_tt/src/lib.rs2
8 files changed, 25 insertions, 16 deletions
diff --git a/crates/ra_mbe/src/lib.rs b/crates/ra_mbe/src/lib.rs
index 87782e5b9..b9f555ef6 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;
30/// be very confusing is that AST has almost exactly the same shape as 30/// be very confusing is that AST has almost exactly the same shape as
31/// `tt::TokenTree`, but there's a crucial difference: in macro rules, `$ident` 31/// `tt::TokenTree`, but there's a crucial difference: in macro rules, `$ident`
32/// and `$()*` have special meaning (see `Var` and `Repeat` data structures) 32/// and `$()*` have special meaning (see `Var` and `Repeat` data structures)
33#[derive(Debug)] 33#[derive(Debug, PartialEq, Eq)]
34pub struct MacroRules { 34pub struct MacroRules {
35 pub(crate) rules: Vec<Rule>, 35 pub(crate) rules: Vec<Rule>,
36} 36}
@@ -44,13 +44,13 @@ impl MacroRules {
44 } 44 }
45} 45}
46 46
47#[derive(Debug)] 47#[derive(Debug, PartialEq, Eq)]
48pub(crate) struct Rule { 48pub(crate) struct Rule {
49 pub(crate) lhs: Subtree, 49 pub(crate) lhs: Subtree,
50 pub(crate) rhs: Subtree, 50 pub(crate) rhs: Subtree,
51} 51}
52 52
53#[derive(Debug)] 53#[derive(Debug, PartialEq, Eq)]
54pub(crate) enum TokenTree { 54pub(crate) enum TokenTree {
55 Leaf(Leaf), 55 Leaf(Leaf),
56 Subtree(Subtree), 56 Subtree(Subtree),
@@ -58,7 +58,7 @@ pub(crate) enum TokenTree {
58} 58}
59impl_froms!(TokenTree: Leaf, Subtree, Repeat); 59impl_froms!(TokenTree: Leaf, Subtree, Repeat);
60 60
61#[derive(Debug)] 61#[derive(Debug, PartialEq, Eq)]
62pub(crate) enum Leaf { 62pub(crate) enum Leaf {
63 Literal(Literal), 63 Literal(Literal),
64 Punct(Punct), 64 Punct(Punct),
@@ -67,37 +67,37 @@ pub(crate) enum Leaf {
67} 67}
68impl_froms!(Leaf: Literal, Punct, Ident, Var); 68impl_froms!(Leaf: Literal, Punct, Ident, Var);
69 69
70#[derive(Debug)] 70#[derive(Debug, PartialEq, Eq)]
71pub(crate) struct Subtree { 71pub(crate) struct Subtree {
72 pub(crate) delimiter: Delimiter, 72 pub(crate) delimiter: Delimiter,
73 pub(crate) token_trees: Vec<TokenTree>, 73 pub(crate) token_trees: Vec<TokenTree>,
74} 74}
75 75
76#[derive(Debug)] 76#[derive(Debug, PartialEq, Eq)]
77pub(crate) struct Repeat { 77pub(crate) struct Repeat {
78 pub(crate) subtree: Subtree, 78 pub(crate) subtree: Subtree,
79 pub(crate) kind: RepeatKind, 79 pub(crate) kind: RepeatKind,
80 pub(crate) separator: Option<char>, 80 pub(crate) separator: Option<char>,
81} 81}
82 82
83#[derive(Debug)] 83#[derive(Debug, PartialEq, Eq)]
84pub(crate) enum RepeatKind { 84pub(crate) enum RepeatKind {
85 ZeroOrMore, 85 ZeroOrMore,
86 OneOrMore, 86 OneOrMore,
87 ZeroOrOne, 87 ZeroOrOne,
88} 88}
89 89
90#[derive(Debug)] 90#[derive(Debug, PartialEq, Eq)]
91pub(crate) struct Literal { 91pub(crate) struct Literal {
92 pub(crate) text: SmolStr, 92 pub(crate) text: SmolStr,
93} 93}
94 94
95#[derive(Debug)] 95#[derive(Debug, PartialEq, Eq)]
96pub(crate) struct Ident { 96pub(crate) struct Ident {
97 pub(crate) text: SmolStr, 97 pub(crate) text: SmolStr,
98} 98}
99 99
100#[derive(Debug)] 100#[derive(Debug, PartialEq, Eq)]
101pub(crate) struct Var { 101pub(crate) struct Var {
102 pub(crate) text: SmolStr, 102 pub(crate) text: SmolStr,
103 pub(crate) kind: Option<SmolStr>, 103 pub(crate) kind: Option<SmolStr>,
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs
index 256277609..d2b080743 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 {
1908} 1908}
1909 1909
1910 1910
1911impl ast::NameOwner for MacroCall {}
1911impl MacroCall { 1912impl MacroCall {
1912 pub fn token_tree(&self) -> Option<&TokenTree> { 1913 pub fn token_tree(&self) -> Option<&TokenTree> {
1913 super::child_opt(self) 1914 super::child_opt(self)
diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron
index d428bc595..2e4b2d776 100644
--- a/crates/ra_syntax/src/grammar.ron
+++ b/crates/ra_syntax/src/grammar.ron
@@ -545,7 +545,10 @@ Grammar(
545 "Visibility": (), 545 "Visibility": (),
546 "Name": (), 546 "Name": (),
547 "NameRef": (), 547 "NameRef": (),
548 "MacroCall": ( options: [ "TokenTree", "Path" ] ), 548 "MacroCall": (
549 traits: [ "NameOwner" ],
550 options: [ "TokenTree", "Path" ],
551 ),
549 "Attr": ( options: [ ["value", "TokenTree"] ] ), 552 "Attr": ( options: [ ["value", "TokenTree"] ] ),
550 "TokenTree": (), 553 "TokenTree": (),
551 "TypeParamList": ( 554 "TypeParamList": (
diff --git a/crates/ra_syntax/src/grammar/items.rs b/crates/ra_syntax/src/grammar/items.rs
index a61f260cf..4b962c1f3 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 {
347 347
348pub(super) fn macro_call_after_excl(p: &mut Parser) -> BlockLike { 348pub(super) fn macro_call_after_excl(p: &mut Parser) -> BlockLike {
349 p.expect(EXCL); 349 p.expect(EXCL);
350 p.eat(IDENT); 350 if p.at(IDENT) {
351 name(p);
352 }
351 match p.current() { 353 match p.current() {
352 L_CURLY => { 354 L_CURLY => {
353 token_tree(p); 355 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 12919fab7..440bd7f92 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)
6 IDENT@[0; 5) "macro" 6 IDENT@[0; 5) "macro"
7 err: `expected EXCL` 7 err: `expected EXCL`
8 WHITESPACE@[5; 6) 8 WHITESPACE@[5; 6)
9 IDENT@[6; 21) "parse_use_trees" 9 NAME@[6; 21)
10 IDENT@[6; 21) "parse_use_trees"
10 TOKEN_TREE@[21; 41) 11 TOKEN_TREE@[21; 41)
11 L_PAREN@[21; 22) 12 L_PAREN@[21; 22)
12 DOLLAR@[22; 23) 13 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 62528ca47..6ccd0ffc3 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)
19 IDENT@[12; 23) "macro_rules" 19 IDENT@[12; 23) "macro_rules"
20 EXCL@[23; 24) 20 EXCL@[23; 24)
21 WHITESPACE@[24; 25) 21 WHITESPACE@[24; 25)
22 IDENT@[25; 28) "foo" 22 NAME@[25; 28)
23 IDENT@[25; 28) "foo"
23 WHITESPACE@[28; 29) 24 WHITESPACE@[28; 29)
24 TOKEN_TREE@[29; 31) 25 TOKEN_TREE@[29; 31)
25 L_CURLY@[29; 30) 26 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 63b230091..ac789651a 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)
92 IDENT@[109; 120) "macro_rules" 92 IDENT@[109; 120) "macro_rules"
93 EXCL@[120; 121) 93 EXCL@[120; 121)
94 WHITESPACE@[121; 122) 94 WHITESPACE@[121; 122)
95 IDENT@[122; 126) "test" 95 NAME@[122; 126)
96 IDENT@[122; 126) "test"
96 WHITESPACE@[126; 127) 97 WHITESPACE@[126; 127)
97 TOKEN_TREE@[127; 152) 98 TOKEN_TREE@[127; 152)
98 L_CURLY@[127; 128) 99 L_CURLY@[127; 128)
diff --git a/crates/ra_tt/src/lib.rs b/crates/ra_tt/src/lib.rs
index 043417abc..df31f72f3 100644
--- a/crates/ra_tt/src/lib.rs
+++ b/crates/ra_tt/src/lib.rs
@@ -39,7 +39,7 @@ pub struct Subtree {
39 pub token_trees: Vec<TokenTree>, 39 pub token_trees: Vec<TokenTree>,
40} 40}
41 41
42#[derive(Clone, Copy, Debug)] 42#[derive(Clone, Copy, Debug, PartialEq, Eq)]
43pub enum Delimiter { 43pub enum Delimiter {
44 Parenthesis, 44 Parenthesis,
45 Brace, 45 Brace,