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/Cargo.toml | 1 + crates/ra_macros/src/mbe_expander.rs | 25 +++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) (limited to 'crates') diff --git a/crates/ra_macros/Cargo.toml b/crates/ra_macros/Cargo.toml index b4fdbfd18..21c128442 100644 --- a/crates/ra_macros/Cargo.toml +++ b/crates/ra_macros/Cargo.toml @@ -5,4 +5,5 @@ version = "0.1.0" authors = ["Aleksey Kladov "] [dependencies] +rustc_hash = "1.0.0" smol_str = "0.1.9" 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