]> git.lizzy.rs Git - rust.git/commitdiff
more expand boilerplate
authorAleksey Kladov <aleksey.kladov@gmail.com>
Thu, 31 Jan 2019 10:59:25 +0000 (13:59 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Thu, 31 Jan 2019 20:23:30 +0000 (22:23 +0200)
crates/ra_macros/Cargo.toml
crates/ra_macros/src/mbe_expander.rs

index b4fdbfd184fae9102187df8495ed9f37c8aa422a..21c128442dcda98a21b74e379cf36c274aa43be9 100644 (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"
index 42622965951ff7e52a751377e9876a4ec1c23cdd..9436baa2837c106d89db744d0f16d43fd8f3b3e0 100644 (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
 }