rust/crates/ra_macros/src/mbe_expander.rs

27 lines
693 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> {
2019-01-31 04:59:39 -06:00
let bindings = match_lhs(&rule.lhs, input)?;
2019-01-31 04:59:25 -06:00
expand_rhs(&rule.rhs, &bindings)
}
#[derive(Debug, Default)]
struct Bindings {
inner: FxHashMap<SmolStr, tt::TokenTree>,
}
2019-01-31 04:59:39 -06:00
fn match_lhs(pattern: &mbe::Subtree, input: &tt::Subtree) -> Option<Bindings> {
2019-01-31 04:59:25 -06:00
Some(Bindings::default())
}
2019-01-31 04:59:39 -06:00
fn expand_rhs(template: &mbe::Subtree, bindings: &Bindings) -> Option<tt::Subtree> {
2019-01-31 04:59:25 -06:00
None
2019-01-31 04:49:57 -06:00
}