aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-31 10:40:05 +0000
committerAleksey Kladov <[email protected]>2019-01-31 20:23:30 +0000
commitce3636798bc9481ec712b84b5cad9973b7844425 (patch)
tree0f252e18492e50ce8eff8c0aacb249a763601dd0 /crates
parent9a043a163c59dd2625727f7ff5466d586625a423 (diff)
move macros to a separate crate
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/Cargo.toml1
-rw-r--r--crates/ra_hir/src/macros.rs6
-rw-r--r--crates/ra_macros/Cargo.toml8
-rw-r--r--crates/ra_macros/src/lib.rs14
-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"
16ra_syntax = { path = "../ra_syntax" } 16ra_syntax = { path = "../ra_syntax" }
17ra_arena = { path = "../ra_arena" } 17ra_arena = { path = "../ra_arena" }
18ra_db = { path = "../ra_db" } 18ra_db = { path = "../ra_db" }
19ra_macros = { path = "../ra_macros" }
19test_utils = { path = "../test_utils" } 20test_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)]
2mod tt;
3#[allow(unused)]
4mod 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};
17use ra_macros::{tt, mbe};
22 18
23use crate::{HirDatabase, MacroCallId}; 19use 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]
2edition = "2018"
3name = "ra_macros"
4version = "0.1.0"
5authors = ["Aleksey Kladov <[email protected]>"]
6
7[dependencies]
8smol_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 @@
1macro_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
13pub mod tt;
14pub 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 @@
1use ra_syntax::SmolStr; 1use smol_str::SmolStr;
2 2
3use crate::macros::tt::{self, Delimiter}; 3use crate::tt::{self, Delimiter};
4 4
5#[derive(Debug)] 5#[derive(Debug)]
6pub(crate) struct MacroRules { 6pub 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
74pub(crate) fn parse(tt: &tt::Subtree) -> Option<MacroRules> { 74pub 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> {
140fn parse_repeat(p: &mut RulesParser) -> Option<Repeat> { 140fn 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 @@
1use ra_syntax::SmolStr; 1use smol_str::SmolStr;
2 2
3#[derive(Debug)] 3#[derive(Debug)]
4pub(crate) enum TokenTree { 4pub enum TokenTree {
5 Leaf(Leaf), 5 Leaf(Leaf),
6 Subtree(Subtree), 6 Subtree(Subtree),
7} 7}
8impl_froms!(TokenTree: Leaf, Subtree); 8impl_froms!(TokenTree: Leaf, Subtree);
9 9
10#[derive(Debug)] 10#[derive(Debug)]
11pub(crate) enum Leaf { 11pub 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 {
16impl_froms!(Leaf: Literal, Punct, Ident); 16impl_froms!(Leaf: Literal, Punct, Ident);
17 17
18#[derive(Debug)] 18#[derive(Debug)]
19pub(crate) struct Subtree { 19pub 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)]
25pub(crate) enum Delimiter { 25pub 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)]
33pub(crate) struct Literal { 33pub struct Literal {
34 pub(crate) text: SmolStr, 34 pub text: SmolStr,
35} 35}
36 36
37#[derive(Debug)] 37#[derive(Debug)]
38pub(crate) struct Punct { 38pub struct Punct {
39 pub(crate) char: char, 39 pub char: char,
40} 40}
41 41
42#[derive(Debug)] 42#[derive(Debug)]
43pub(crate) struct Ident { 43pub struct Ident {
44 pub(crate) text: SmolStr, 44 pub text: SmolStr,
45} 45}