From d2a1e0715088d61ab40b64d0fd8ad296251ccfa1 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 31 Jan 2019 13:59:25 +0300 Subject: more expand boilerplate --- crates/ra_macros/src/mbe_expander.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'crates/ra_macros/src/mbe_expander.rs') diff --git a/crates/ra_macros/src/mbe_expander.rs b/crates/ra_macros/src/mbe_expander.rs index 426229659..9436baa28 100644 --- a/crates/ra_macros/src/mbe_expander.rs +++ b/crates/ra_macros/src/mbe_expander.rs @@ -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 { - Some(input) +pub fn exapnd(rules: &mbe::MacroRules, input: &tt::Subtree) -> Option { + rules.rules.iter().find_map(|it| expand_rule(it, input)) +} + +fn expand_rule(rule: &mbe::Rule, input: &tt::Subtree) -> Option { + let bidings = match_lhs(&rule.lhs, input)?; + expand_rhs(&rule.rhs, &bindings) +} + +#[derive(Debug, Default)] +struct Bindings { + inner: FxHashMap, +} + +fn match_lhs(pattern: &mbe::TokenTree, input: &tt::Subtree) -> Option { + Some(Bindings::default()) +} + +fn expand_rhs(template: &mbe::TokenTree, bindings: &Bindings) -> Option { + None } -- cgit v1.2.3