diff options
author | Aleksey Kladov <[email protected]> | 2019-01-31 10:59:25 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-31 20:23:30 +0000 |
commit | d2a1e0715088d61ab40b64d0fd8ad296251ccfa1 (patch) | |
tree | 3500b8a8393ae8f4dafc172fe6592c7f7dc2ccdb /crates/ra_macros | |
parent | 09a8d753512ac878224455a148ad66d0f14a20da (diff) |
more expand boilerplate
Diffstat (limited to 'crates/ra_macros')
-rw-r--r-- | crates/ra_macros/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_macros/src/mbe_expander.rs | 25 |
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" | |||
5 | authors = ["Aleksey Kladov <[email protected]>"] | 5 | authors = ["Aleksey Kladov <[email protected]>"] |
6 | 6 | ||
7 | [dependencies] | 7 | [dependencies] |
8 | rustc_hash = "1.0.0" | ||
8 | smol_str = "0.1.9" | 9 | 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 @@ | |||
1 | use rustc_hash::FxHashMap; | ||
2 | use smol_str::SmolStr; | ||
3 | |||
1 | use crate::{mbe, tt}; | 4 | use crate::{mbe, tt}; |
2 | 5 | ||
3 | pub fn exapnd(rules: &mbe::MacroRules, input: tt::Subtree) -> Option<tt::Subtree> { | 6 | pub 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 | |||
10 | fn 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)] | ||
16 | struct Bindings { | ||
17 | inner: FxHashMap<SmolStr, tt::TokenTree>, | ||
18 | } | ||
19 | |||
20 | fn match_lhs(pattern: &mbe::TokenTree, input: &tt::Subtree) -> Option<Bindings> { | ||
21 | Some(Bindings::default()) | ||
22 | } | ||
23 | |||
24 | fn expand_rhs(template: &mbe::TokenTree, bindings: &Bindings) -> Option<tt::Subtree> { | ||
25 | None | ||
5 | } | 26 | } |