diff --git a/Cargo.lock b/Cargo.lock index b487216221..426f4af272 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -940,8 +940,9 @@ dependencies = [ "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "ra_arena 0.1.0", "ra_db 0.1.0", - "ra_macros 0.1.0", + "ra_mbe 0.1.0", "ra_syntax 0.1.0", + "ra_tt 0.1.0", "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "test_utils 0.1.0", @@ -1019,9 +1020,10 @@ dependencies = [ ] [[package]] -name = "ra_macros" +name = "ra_mbe" version = "0.1.0" dependencies = [ + "ra_tt 0.1.0", "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "smol_str 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1052,6 +1054,14 @@ dependencies = [ "text_unit 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "ra_tt" +version = "0.1.0" +dependencies = [ + "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "smol_str 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "ra_vfs" version = "0.1.0" diff --git a/crates/ra_hir/Cargo.toml b/crates/ra_hir/Cargo.toml index f0988acc80..4309a05d6b 100644 --- a/crates/ra_hir/Cargo.toml +++ b/crates/ra_hir/Cargo.toml @@ -16,7 +16,8 @@ join_to_string = "0.1.3" ra_syntax = { path = "../ra_syntax" } ra_arena = { path = "../ra_arena" } ra_db = { path = "../ra_db" } -ra_macros = { path = "../ra_macros" } +mbe = { path = "../ra_mbe", package = "ra_mbe" } +tt = { path = "../ra_tt", package = "ra_tt" } test_utils = { path = "../test_utils" } [dev-dependencies] diff --git a/crates/ra_hir/src/macros.rs b/crates/ra_hir/src/macros.rs index e6ba8c08fd..ffcf1c3f94 100644 --- a/crates/ra_hir/src/macros.rs +++ b/crates/ra_hir/src/macros.rs @@ -14,7 +14,6 @@ use ra_syntax::{ SyntaxKind::*, ast::{self, NameOwner}, }; -use ra_macros::{tt, mbe}; use crate::{HirDatabase, MacroCallId}; diff --git a/crates/ra_macros/src/lib.rs b/crates/ra_macros/src/lib.rs deleted file mode 100644 index e35a056ccf..0000000000 --- a/crates/ra_macros/src/lib.rs +++ /dev/null @@ -1,17 +0,0 @@ -macro_rules! impl_froms { - ($e:ident: $($v:ident), *) => { - $( - impl From<$v> for $e { - fn from(it: $v) -> $e { - $e::$v(it) - } - } - )* - } -} - -pub mod tt; -pub mod mbe; -mod tt_cursor; -mod mbe_parser; -mod mbe_expander; diff --git a/crates/ra_mbe/Cargo.toml b/crates/ra_mbe/Cargo.toml new file mode 100644 index 0000000000..b7f03cd381 --- /dev/null +++ b/crates/ra_mbe/Cargo.toml @@ -0,0 +1,10 @@ +[package] +edition = "2018" +name = "ra_mbe" +version = "0.1.0" +authors = ["Aleksey Kladov "] + +[dependencies] +tt = { path = "../ra_tt", package = "ra_tt" } +rustc-hash = "1.0.0" +smol_str = "0.1.9" diff --git a/crates/ra_macros/src/mbe.rs b/crates/ra_mbe/src/lib.rs similarity index 79% rename from crates/ra_macros/src/mbe.rs rename to crates/ra_mbe/src/lib.rs index d4106a41c2..38bf3431a0 100644 --- a/crates/ra_macros/src/mbe.rs +++ b/crates/ra_mbe/src/lib.rs @@ -1,6 +1,22 @@ +macro_rules! impl_froms { + ($e:ident: $($v:ident), *) => { + $( + impl From<$v> for $e { + fn from(it: $v) -> $e { + $e::$v(it) + } + } + )* + } +} + +mod tt_cursor; +mod mbe_parser; +mod mbe_expander; + use smol_str::SmolStr; -pub(crate) use crate::tt::{Delimiter, Punct}; +pub use tt::{Delimiter, Punct}; pub use crate::{ mbe_parser::parse, diff --git a/crates/ra_macros/src/mbe_expander.rs b/crates/ra_mbe/src/mbe_expander.rs similarity index 99% rename from crates/ra_macros/src/mbe_expander.rs rename to crates/ra_mbe/src/mbe_expander.rs index 5d53632618..92ad26889c 100644 --- a/crates/ra_macros/src/mbe_expander.rs +++ b/crates/ra_mbe/src/mbe_expander.rs @@ -1,7 +1,7 @@ use rustc_hash::FxHashMap; use smol_str::SmolStr; -use crate::{mbe, tt, tt_cursor::TtCursor}; +use crate::{self as mbe, tt_cursor::TtCursor}; pub fn exapnd(rules: &mbe::MacroRules, input: &tt::Subtree) -> Option { rules.rules.iter().find_map(|it| expand_rule(it, input)) diff --git a/crates/ra_macros/src/mbe_parser.rs b/crates/ra_mbe/src/mbe_parser.rs similarity index 95% rename from crates/ra_macros/src/mbe_parser.rs rename to crates/ra_mbe/src/mbe_parser.rs index 4835945903..a70ed1d52e 100644 --- a/crates/ra_macros/src/mbe_parser.rs +++ b/crates/ra_mbe/src/mbe_parser.rs @@ -1,5 +1,4 @@ -use crate::{tt, mbe}; -use crate::tt_cursor::TtCursor; +use crate::{self as mbe, tt_cursor::TtCursor}; /// This module parses a raw `tt::TokenStream` into macro-by-example token /// stream. This is a *mostly* identify function, expect for handling of @@ -43,7 +42,7 @@ fn parse_subtree(tt: &tt::Subtree) -> Option { mbe::Leaf::from(mbe::Literal { text: text.clone() }).into() } }, - tt::TokenTree::Subtree(subtree) => parse_subtree(subtree)?.into(), + tt::TokenTree::Subtree(subtree) => parse_subtree(&subtree)?.into(), }; token_trees.push(child); } diff --git a/crates/ra_macros/src/tt_cursor.rs b/crates/ra_mbe/src/tt_cursor.rs similarity index 99% rename from crates/ra_macros/src/tt_cursor.rs rename to crates/ra_mbe/src/tt_cursor.rs index 046770a0fd..30c8eda673 100644 --- a/crates/ra_macros/src/tt_cursor.rs +++ b/crates/ra_mbe/src/tt_cursor.rs @@ -1,5 +1,3 @@ -use crate::tt; - #[derive(Clone)] pub(crate) struct TtCursor<'a> { subtree: &'a tt::Subtree, diff --git a/crates/ra_macros/Cargo.toml b/crates/ra_tt/Cargo.toml similarity index 89% rename from crates/ra_macros/Cargo.toml rename to crates/ra_tt/Cargo.toml index 7d3cb055c7..357a5c5a33 100644 --- a/crates/ra_macros/Cargo.toml +++ b/crates/ra_tt/Cargo.toml @@ -1,6 +1,6 @@ [package] edition = "2018" -name = "ra_macros" +name = "ra_tt" version = "0.1.0" authors = ["Aleksey Kladov "] diff --git a/crates/ra_macros/src/tt.rs b/crates/ra_tt/src/lib.rs similarity index 92% rename from crates/ra_macros/src/tt.rs rename to crates/ra_tt/src/lib.rs index 2855bae51f..d7c3c62bf7 100644 --- a/crates/ra_macros/src/tt.rs +++ b/crates/ra_tt/src/lib.rs @@ -1,3 +1,15 @@ +macro_rules! impl_froms { + ($e:ident: $($v:ident), *) => { + $( + impl From<$v> for $e { + fn from(it: $v) -> $e { + $e::$v(it) + } + } + )* + } +} + use std::fmt; use smol_str::SmolStr;