aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-31 10:59:25 +0000
committerAleksey Kladov <[email protected]>2019-01-31 20:23:30 +0000
commitd2a1e0715088d61ab40b64d0fd8ad296251ccfa1 (patch)
tree3500b8a8393ae8f4dafc172fe6592c7f7dc2ccdb
parent09a8d753512ac878224455a148ad66d0f14a20da (diff)
more expand boilerplate
-rw-r--r--crates/ra_macros/Cargo.toml1
-rw-r--r--crates/ra_macros/src/mbe_expander.rs25
2 files changed, 24 insertions, 2 deletions
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"
5authors = ["Aleksey Kladov <[email protected]>"] 5authors = ["Aleksey Kladov <[email protected]>"]
6 6
7[dependencies] 7[dependencies]
8rustc_hash = "1.0.0"
8smol_str = "0.1.9" 9smol_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 @@
1use rustc_hash::FxHashMap;
2use smol_str::SmolStr;
3
1use crate::{mbe, tt}; 4use crate::{mbe, tt};
2 5
3pub fn exapnd(rules: &mbe::MacroRules, input: tt::Subtree) -> Option<tt::Subtree> { 6pub fn exapnd(rules: &mbe::MacroRules, input: &tt::Subtree) -> Option<tt::Subtree> {
4 Some(input) 7 rules.rules.iter().find_map(|it| expand_rule(it, input))
8}
9
10fn expand_rule(rule: &mbe::Rule, input: &tt::Subtree) -> Option<tt::Subtree> {
11 let bidings = match_lhs(&rule.lhs, input)?;
12 expand_rhs(&rule.rhs, &bindings)
13}
14
15#[derive(Debug, Default)]
16struct Bindings {
17 inner: FxHashMap<SmolStr, tt::TokenTree>,
18}
19
20fn match_lhs(pattern: &mbe::TokenTree, input: &tt::Subtree) -> Option<Bindings> {
21 Some(Bindings::default())
22}
23
24fn expand_rhs(template: &mbe::TokenTree, bindings: &Bindings) -> Option<tt::Subtree> {
25 None
5} 26}