split macros across crates

This commit is contained in:
Aleksey Kladov 2019-01-31 21:09:43 +03:00
parent ad80a0c551
commit 40feacdeb9
11 changed files with 57 additions and 29 deletions

88
crates/ra_mbe/src/lib.rs Normal file
View 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>,
}