diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_hir/src/macros.rs | 6 | ||||
-rw-r--r-- | crates/ra_macros/Cargo.toml | 8 | ||||
-rw-r--r-- | crates/ra_macros/src/lib.rs | 14 | ||||
-rw-r--r-- | crates/ra_macros/src/mbe.rs (renamed from crates/ra_hir/src/macros/mbe.rs) | 10 | ||||
-rw-r--r-- | crates/ra_macros/src/tt.rs (renamed from crates/ra_hir/src/macros/tt.rs) | 26 |
6 files changed, 42 insertions, 23 deletions
diff --git a/crates/ra_hir/Cargo.toml b/crates/ra_hir/Cargo.toml index 57a4b155b..f0988acc8 100644 --- a/crates/ra_hir/Cargo.toml +++ b/crates/ra_hir/Cargo.toml | |||
@@ -16,6 +16,7 @@ join_to_string = "0.1.3" | |||
16 | ra_syntax = { path = "../ra_syntax" } | 16 | ra_syntax = { path = "../ra_syntax" } |
17 | ra_arena = { path = "../ra_arena" } | 17 | ra_arena = { path = "../ra_arena" } |
18 | ra_db = { path = "../ra_db" } | 18 | ra_db = { path = "../ra_db" } |
19 | ra_macros = { path = "../ra_macros" } | ||
19 | test_utils = { path = "../test_utils" } | 20 | test_utils = { path = "../test_utils" } |
20 | 21 | ||
21 | [dev-dependencies] | 22 | [dev-dependencies] |
diff --git a/crates/ra_hir/src/macros.rs b/crates/ra_hir/src/macros.rs index dc016a704..7e9aba3f2 100644 --- a/crates/ra_hir/src/macros.rs +++ b/crates/ra_hir/src/macros.rs | |||
@@ -1,8 +1,3 @@ | |||
1 | #[allow(unused)] | ||
2 | mod tt; | ||
3 | #[allow(unused)] | ||
4 | mod mbe; | ||
5 | |||
6 | /// Machinery for macro expansion. | 1 | /// Machinery for macro expansion. |
7 | /// | 2 | /// |
8 | /// One of the more complicated things about macros is managing the source code | 3 | /// One of the more complicated things about macros is managing the source code |
@@ -19,6 +14,7 @@ use ra_syntax::{ | |||
19 | SyntaxKind::*, | 14 | SyntaxKind::*, |
20 | ast::{self, NameOwner}, | 15 | ast::{self, NameOwner}, |
21 | }; | 16 | }; |
17 | use ra_macros::{tt, mbe}; | ||
22 | 18 | ||
23 | use crate::{HirDatabase, MacroCallId}; | 19 | use crate::{HirDatabase, MacroCallId}; |
24 | 20 | ||
diff --git a/crates/ra_macros/Cargo.toml b/crates/ra_macros/Cargo.toml new file mode 100644 index 000000000..b4fdbfd18 --- /dev/null +++ b/crates/ra_macros/Cargo.toml | |||
@@ -0,0 +1,8 @@ | |||
1 | [package] | ||
2 | edition = "2018" | ||
3 | name = "ra_macros" | ||
4 | version = "0.1.0" | ||
5 | authors = ["Aleksey Kladov <[email protected]>"] | ||
6 | |||
7 | [dependencies] | ||
8 | smol_str = "0.1.9" | ||
diff --git a/crates/ra_macros/src/lib.rs b/crates/ra_macros/src/lib.rs new file mode 100644 index 000000000..6063c06c2 --- /dev/null +++ b/crates/ra_macros/src/lib.rs | |||
@@ -0,0 +1,14 @@ | |||
1 | macro_rules! impl_froms { | ||
2 | ($e:ident: $($v:ident), *) => { | ||
3 | $( | ||
4 | impl From<$v> for $e { | ||
5 | fn from(it: $v) -> $e { | ||
6 | $e::$v(it) | ||
7 | } | ||
8 | } | ||
9 | )* | ||
10 | } | ||
11 | } | ||
12 | |||
13 | pub mod tt; | ||
14 | pub mod mbe; | ||
diff --git a/crates/ra_hir/src/macros/mbe.rs b/crates/ra_macros/src/mbe.rs index 6c93ae5e3..1aa6be736 100644 --- a/crates/ra_hir/src/macros/mbe.rs +++ b/crates/ra_macros/src/mbe.rs | |||
@@ -1,9 +1,9 @@ | |||
1 | use ra_syntax::SmolStr; | 1 | use smol_str::SmolStr; |
2 | 2 | ||
3 | use crate::macros::tt::{self, Delimiter}; | 3 | use crate::tt::{self, Delimiter}; |
4 | 4 | ||
5 | #[derive(Debug)] | 5 | #[derive(Debug)] |
6 | pub(crate) struct MacroRules { | 6 | pub struct MacroRules { |
7 | rules: Vec<Rule>, | 7 | rules: Vec<Rule>, |
8 | } | 8 | } |
9 | 9 | ||
@@ -71,7 +71,7 @@ struct Var { | |||
71 | kind: Option<SmolStr>, | 71 | kind: Option<SmolStr>, |
72 | } | 72 | } |
73 | 73 | ||
74 | pub(crate) fn parse(tt: &tt::Subtree) -> Option<MacroRules> { | 74 | pub fn parse(tt: &tt::Subtree) -> Option<MacroRules> { |
75 | let mut parser = RulesParser::new(tt); | 75 | let mut parser = RulesParser::new(tt); |
76 | let mut rules = Vec::new(); | 76 | let mut rules = Vec::new(); |
77 | while !parser.is_eof() { | 77 | while !parser.is_eof() { |
@@ -140,7 +140,7 @@ fn parse_var(p: &mut RulesParser) -> Option<Var> { | |||
140 | fn parse_repeat(p: &mut RulesParser) -> Option<Repeat> { | 140 | fn parse_repeat(p: &mut RulesParser) -> Option<Repeat> { |
141 | let subtree = p.eat_subtree().unwrap(); | 141 | let subtree = p.eat_subtree().unwrap(); |
142 | let subtree = parse_subtree(subtree)?; | 142 | let subtree = parse_subtree(subtree)?; |
143 | let mut sep = p.eat_punct()?; | 143 | let sep = p.eat_punct()?; |
144 | let (separator, rep) = match sep.char { | 144 | let (separator, rep) = match sep.char { |
145 | '*' | '+' | '?' => (None, sep.char), | 145 | '*' | '+' | '?' => (None, sep.char), |
146 | char => (Some(Punct { char }), p.eat_punct()?.char), | 146 | char => (Some(Punct { char }), p.eat_punct()?.char), |
diff --git a/crates/ra_hir/src/macros/tt.rs b/crates/ra_macros/src/tt.rs index 64e88ddc5..364eed9e6 100644 --- a/crates/ra_hir/src/macros/tt.rs +++ b/crates/ra_macros/src/tt.rs | |||
@@ -1,14 +1,14 @@ | |||
1 | use ra_syntax::SmolStr; | 1 | use smol_str::SmolStr; |
2 | 2 | ||
3 | #[derive(Debug)] | 3 | #[derive(Debug)] |
4 | pub(crate) enum TokenTree { | 4 | pub enum TokenTree { |
5 | Leaf(Leaf), | 5 | Leaf(Leaf), |
6 | Subtree(Subtree), | 6 | Subtree(Subtree), |
7 | } | 7 | } |
8 | impl_froms!(TokenTree: Leaf, Subtree); | 8 | impl_froms!(TokenTree: Leaf, Subtree); |
9 | 9 | ||
10 | #[derive(Debug)] | 10 | #[derive(Debug)] |
11 | pub(crate) enum Leaf { | 11 | pub enum Leaf { |
12 | Literal(Literal), | 12 | Literal(Literal), |
13 | Punct(Punct), | 13 | Punct(Punct), |
14 | Ident(Ident), | 14 | Ident(Ident), |
@@ -16,13 +16,13 @@ pub(crate) enum Leaf { | |||
16 | impl_froms!(Leaf: Literal, Punct, Ident); | 16 | impl_froms!(Leaf: Literal, Punct, Ident); |
17 | 17 | ||
18 | #[derive(Debug)] | 18 | #[derive(Debug)] |
19 | pub(crate) struct Subtree { | 19 | pub struct Subtree { |
20 | pub(crate) delimiter: Delimiter, | 20 | pub delimiter: Delimiter, |
21 | pub(crate) token_trees: Vec<TokenTree>, | 21 | pub token_trees: Vec<TokenTree>, |
22 | } | 22 | } |
23 | 23 | ||
24 | #[derive(Clone, Copy, Debug)] | 24 | #[derive(Clone, Copy, Debug)] |
25 | pub(crate) enum Delimiter { | 25 | pub enum Delimiter { |
26 | Parenthesis, | 26 | Parenthesis, |
27 | Brace, | 27 | Brace, |
28 | Bracket, | 28 | Bracket, |
@@ -30,16 +30,16 @@ pub(crate) enum Delimiter { | |||
30 | } | 30 | } |
31 | 31 | ||
32 | #[derive(Debug)] | 32 | #[derive(Debug)] |
33 | pub(crate) struct Literal { | 33 | pub struct Literal { |
34 | pub(crate) text: SmolStr, | 34 | pub text: SmolStr, |
35 | } | 35 | } |
36 | 36 | ||
37 | #[derive(Debug)] | 37 | #[derive(Debug)] |
38 | pub(crate) struct Punct { | 38 | pub struct Punct { |
39 | pub(crate) char: char, | 39 | pub char: char, |
40 | } | 40 | } |
41 | 41 | ||
42 | #[derive(Debug)] | 42 | #[derive(Debug)] |
43 | pub(crate) struct Ident { | 43 | pub struct Ident { |
44 | pub(crate) text: SmolStr, | 44 | pub text: SmolStr, |
45 | } | 45 | } |