rust/crates/ra_macros/src/mbe_expander.rs

27 lines
696 B
Rust
Raw Normal View History

2019-01-31 04:59:25 -06:00
use rustc_hash::FxHashMap;
use smol_str::SmolStr;
2019-01-31 04:49:57 -06:00
use crate::{mbe, tt};
2019-01-31 04:59:25 -06:00
pub fn exapnd(rules: &mbe::MacroRules, input: &tt::Subtree) -> Option<tt::Subtree> {
rules.rules.iter().find_map(|it| expand_rule(it, input))
}
fn expand_rule(rule: &mbe::Rule, input: &tt::Subtree) -> Option<tt::Subtree> {
let bidings = match_lhs(&rule.lhs, input)?;
expand_rhs(&rule.rhs, &bindings)
}
#[derive(Debug, Default)]
struct Bindings {
inner: FxHashMap<SmolStr, tt::TokenTree>,
}
fn match_lhs(pattern: &mbe::TokenTree, input: &tt::Subtree) -> Option<Bindings> {
Some(Bindings::default())
}
fn expand_rhs(template: &mbe::TokenTree, bindings: &Bindings) -> Option<tt::Subtree> {
None
2019-01-31 04:49:57 -06:00
}