#[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> {