mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-26 11:55:04 +00:00
split macros across crates
This commit is contained in:
parent
ad80a0c551
commit
40feacdeb9
11 changed files with 57 additions and 29 deletions
14
Cargo.lock
generated
14
Cargo.lock
generated
|
@ -940,8 +940,9 @@ dependencies = [
|
||||||
"parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"ra_arena 0.1.0",
|
"ra_arena 0.1.0",
|
||||||
"ra_db 0.1.0",
|
"ra_db 0.1.0",
|
||||||
"ra_macros 0.1.0",
|
"ra_mbe 0.1.0",
|
||||||
"ra_syntax 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)",
|
"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)",
|
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"test_utils 0.1.0",
|
"test_utils 0.1.0",
|
||||||
|
@ -1019,9 +1020,10 @@ dependencies = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ra_macros"
|
name = "ra_mbe"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"ra_tt 0.1.0",
|
||||||
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"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)",
|
"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]]
|
[[package]]
|
||||||
name = "ra_vfs"
|
name = "ra_vfs"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
|
@ -16,7 +16,8 @@ join_to_string = "0.1.3"
|
||||||
ra_syntax = { path = "../ra_syntax" }
|
ra_syntax = { path = "../ra_syntax" }
|
||||||
ra_arena = { path = "../ra_arena" }
|
ra_arena = { path = "../ra_arena" }
|
||||||
ra_db = { path = "../ra_db" }
|
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" }
|
test_utils = { path = "../test_utils" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
|
|
@ -14,7 +14,6 @@ use ra_syntax::{
|
||||||
SyntaxKind::*,
|
SyntaxKind::*,
|
||||||
ast::{self, NameOwner},
|
ast::{self, NameOwner},
|
||||||
};
|
};
|
||||||
use ra_macros::{tt, mbe};
|
|
||||||
|
|
||||||
use crate::{HirDatabase, MacroCallId};
|
use crate::{HirDatabase, MacroCallId};
|
||||||
|
|
||||||
|
|
|
@ -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;
|
|
10
crates/ra_mbe/Cargo.toml
Normal file
10
crates/ra_mbe/Cargo.toml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
[package]
|
||||||
|
edition = "2018"
|
||||||
|
name = "ra_mbe"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
tt = { path = "../ra_tt", package = "ra_tt" }
|
||||||
|
rustc-hash = "1.0.0"
|
||||||
|
smol_str = "0.1.9"
|
|
@ -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;
|
use smol_str::SmolStr;
|
||||||
|
|
||||||
pub(crate) use crate::tt::{Delimiter, Punct};
|
pub use tt::{Delimiter, Punct};
|
||||||
|
|
||||||
pub use crate::{
|
pub use crate::{
|
||||||
mbe_parser::parse,
|
mbe_parser::parse,
|
|
@ -1,7 +1,7 @@
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use smol_str::SmolStr;
|
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<tt::Subtree> {
|
pub fn exapnd(rules: &mbe::MacroRules, input: &tt::Subtree) -> Option<tt::Subtree> {
|
||||||
rules.rules.iter().find_map(|it| expand_rule(it, input))
|
rules.rules.iter().find_map(|it| expand_rule(it, input))
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::{tt, mbe};
|
use crate::{self as mbe, tt_cursor::TtCursor};
|
||||||
use crate::tt_cursor::TtCursor;
|
|
||||||
|
|
||||||
/// This module parses a raw `tt::TokenStream` into macro-by-example token
|
/// This module parses a raw `tt::TokenStream` into macro-by-example token
|
||||||
/// stream. This is a *mostly* identify function, expect for handling of
|
/// stream. This is a *mostly* identify function, expect for handling of
|
||||||
|
@ -43,7 +42,7 @@ fn parse_subtree(tt: &tt::Subtree) -> Option<mbe::Subtree> {
|
||||||
mbe::Leaf::from(mbe::Literal { text: text.clone() }).into()
|
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);
|
token_trees.push(child);
|
||||||
}
|
}
|
|
@ -1,5 +1,3 @@
|
||||||
use crate::tt;
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub(crate) struct TtCursor<'a> {
|
pub(crate) struct TtCursor<'a> {
|
||||||
subtree: &'a tt::Subtree,
|
subtree: &'a tt::Subtree,
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
name = "ra_macros"
|
name = "ra_tt"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>"]
|
authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>"]
|
||||||
|
|
|
@ -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 std::fmt;
|
||||||
|
|
||||||
use smol_str::SmolStr;
|
use smol_str::SmolStr;
|
Loading…
Reference in a new issue