binders boilerplate
This commit is contained in:
parent
2def5b4e6f
commit
8d5a8f085c
1 changed files with 42 additions and 2 deletions
|
@ -14,11 +14,51 @@ fn expand_rule(rule: &mbe::Rule, input: &tt::Subtree) -> Option<tt::Subtree> {
|
|||
|
||||
#[derive(Debug, Default)]
|
||||
struct Bindings {
|
||||
inner: FxHashMap<SmolStr, tt::TokenTree>,
|
||||
inner: FxHashMap<SmolStr, Binding>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum Binding {
|
||||
Simple(tt::TokenTree),
|
||||
Nested(Vec<Binding>),
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
macro_rules! impl_froms {
|
||||
($e:ident: $($v:ident),*) => {
|
||||
$(
|
||||
impl From<$v> for $e {
|
||||
fn from(it: $v) -> $e {
|
||||
$e::$v(it)
|
||||
}
|
||||
}
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
||||
impl_froms! (Foo: Bar, Baz)
|
||||
|
||||
*/
|
||||
|
||||
fn match_lhs(pattern: &mbe::Subtree, input: &tt::Subtree) -> Option<Bindings> {
|
||||
Some(Bindings::default())
|
||||
let mut res = Bindings::default();
|
||||
for pat in pattern.token_trees.iter() {
|
||||
match pat {
|
||||
mbe::TokenTree::Leaf(leaf) => match leaf {
|
||||
mbe::Leaf::Var(mbe::Var { text, kind }) => {
|
||||
let kind = kind.clone()?;
|
||||
match kind.as_str() {
|
||||
"ident" => (),
|
||||
_ => return None,
|
||||
}
|
||||
}
|
||||
_ => return None,
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
Some(res)
|
||||
}
|
||||
|
||||
fn expand_rhs(template: &mbe::Subtree, bindings: &Bindings) -> Option<tt::Subtree> {
|
||||
|
|
Loading…
Add table
Reference in a new issue