more expand boilerplate

This commit is contained in:
Aleksey Kladov 2019-01-31 13:59:25 +03:00
parent 09a8d75351
commit d2a1e07150
2 changed files with 24 additions and 2 deletions

View File

@ -5,4 +5,5 @@ version = "0.1.0"
authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>"]
[dependencies]
rustc_hash = "1.0.0"
smol_str = "0.1.9"

View File

@ -1,5 +1,26 @@
use rustc_hash::FxHashMap;
use smol_str::SmolStr;
use crate::{mbe, tt};
pub fn exapnd(rules: &mbe::MacroRules, input: tt::Subtree) -> Option<tt::Subtree> {
Some(input)
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
}