mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 14:21:44 +00:00
split macros across crates
This commit is contained in:
parent
ad80a0c551
commit
40feacdeb9
11 changed files with 57 additions and 29 deletions
88
crates/ra_mbe/src/lib.rs
Normal file
88
crates/ra_mbe/src/lib.rs
Normal file
|
@ -0,0 +1,88 @@
|
|||
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 use tt::{Delimiter, Punct};
|
||||
|
||||
pub use crate::{
|
||||
mbe_parser::parse,
|
||||
mbe_expander::exapnd,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct MacroRules {
|
||||
pub(crate) rules: Vec<Rule>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct Rule {
|
||||
pub(crate) lhs: Subtree,
|
||||
pub(crate) rhs: Subtree,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) enum TokenTree {
|
||||
Leaf(Leaf),
|
||||
Subtree(Subtree),
|
||||
Repeat(Repeat),
|
||||
}
|
||||
impl_froms!(TokenTree: Leaf, Subtree, Repeat);
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) enum Leaf {
|
||||
Literal(Literal),
|
||||
Punct(Punct),
|
||||
Ident(Ident),
|
||||
Var(Var),
|
||||
}
|
||||
impl_froms!(Leaf: Literal, Punct, Ident, Var);
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct Subtree {
|
||||
pub(crate) delimiter: Delimiter,
|
||||
pub(crate) token_trees: Vec<TokenTree>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct Repeat {
|
||||
pub(crate) subtree: Subtree,
|
||||
pub(crate) kind: RepeatKind,
|
||||
pub(crate) separator: Option<char>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) enum RepeatKind {
|
||||
ZeroOrMore,
|
||||
OneOrMore,
|
||||
ZeroOrOne,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct Literal {
|
||||
pub(crate) text: SmolStr,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct Ident {
|
||||
pub(crate) text: SmolStr,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct Var {
|
||||
pub(crate) text: SmolStr,
|
||||
pub(crate) kind: Option<SmolStr>,
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue