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, } #[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, } #[derive(Debug)] pub(crate) struct Repeat { pub(crate) subtree: Subtree, pub(crate) kind: RepeatKind, pub(crate) separator: Option, } #[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, }