rust-analyzer/crates/ra_macros/src/mbe.rs

73 lines
1.2 KiB
Rust
Raw Normal View History

2019-01-31 10:40:05 +00:00
use smol_str::SmolStr;
2019-01-30 20:17:32 +00:00
2019-01-31 14:16:02 +00:00
pub(crate) use crate::tt::{Delimiter, Punct};
2019-01-30 20:25:02 +00:00
2019-01-31 10:49:57 +00:00
pub use crate::{
mbe_parser::parse,
mbe_expander::exapnd,
};
2019-01-31 10:46:40 +00:00
2019-01-31 08:09:19 +00:00
#[derive(Debug)]
2019-01-31 10:40:05 +00:00
pub struct MacroRules {
2019-01-31 10:46:40 +00:00
pub(crate) rules: Vec<Rule>,
2019-01-30 20:17:32 +00:00
}
2019-01-31 08:09:19 +00:00
#[derive(Debug)]
2019-01-31 10:46:40 +00:00
pub(crate) struct Rule {
pub(crate) lhs: Subtree,
pub(crate) rhs: Subtree,
2019-01-30 20:17:32 +00:00
}
2019-01-31 08:09:19 +00:00
#[derive(Debug)]
2019-01-31 10:46:40 +00:00
pub(crate) enum TokenTree {
2019-01-30 20:17:32 +00:00
Leaf(Leaf),
Subtree(Subtree),
2019-01-31 07:33:11 +00:00
Repeat(Repeat),
2019-01-30 20:17:32 +00:00
}
2019-01-31 10:32:40 +00:00
impl_froms!(TokenTree: Leaf, Subtree, Repeat);
2019-01-30 20:17:32 +00:00
2019-01-31 08:09:19 +00:00
#[derive(Debug)]
2019-01-31 10:46:40 +00:00
pub(crate) enum Leaf {
2019-01-30 20:17:32 +00:00
Literal(Literal),
Punct(Punct),
Ident(Ident),
Var(Var),
}
2019-01-31 10:32:40 +00:00
impl_froms!(Leaf: Literal, Punct, Ident, Var);
2019-01-30 20:17:32 +00:00
2019-01-31 08:09:19 +00:00
#[derive(Debug)]
2019-01-31 10:46:40 +00:00
pub(crate) struct Subtree {
pub(crate) delimiter: Delimiter,
pub(crate) token_trees: Vec<TokenTree>,
2019-01-30 20:17:32 +00:00
}
2019-01-31 08:09:19 +00:00
#[derive(Debug)]
2019-01-31 10:46:40 +00:00
pub(crate) struct Repeat {
pub(crate) subtree: Subtree,
pub(crate) kind: RepeatKind,
2019-01-31 15:51:17 +00:00
pub(crate) separator: Option<char>,
2019-01-31 07:33:11 +00:00
}
2019-01-31 08:09:19 +00:00
#[derive(Debug)]
2019-01-31 10:46:40 +00:00
pub(crate) enum RepeatKind {
2019-01-31 07:33:11 +00:00
ZeroOrMore,
OneOrMore,
ZeroOrOne,
}
2019-01-31 08:09:19 +00:00
#[derive(Debug)]
2019-01-31 10:46:40 +00:00
pub(crate) struct Literal {
pub(crate) text: SmolStr,
2019-01-30 20:17:32 +00:00
}
2019-01-31 08:09:19 +00:00
#[derive(Debug)]
2019-01-31 10:46:40 +00:00
pub(crate) struct Ident {
pub(crate) text: SmolStr,
2019-01-30 20:17:32 +00:00
}
2019-01-31 08:09:19 +00:00
#[derive(Debug)]
2019-01-31 10:46:40 +00:00
pub(crate) struct Var {
pub(crate) text: SmolStr,
pub(crate) kind: Option<SmolStr>,
2019-01-30 20:25:02 +00:00
}