Formatting

This commit is contained in:
Wilco Kusee 2019-03-02 20:49:13 +01:00
parent d3a252b559
commit dffe318701

View file

@ -9,7 +9,10 @@ use crate::{MacroRulesError, Result};
use crate::tt_cursor::TtCursor; use crate::tt_cursor::TtCursor;
pub(crate) fn expand(rules: &crate::MacroRules, input: &tt::Subtree) -> Result<tt::Subtree> { pub(crate) fn expand(rules: &crate::MacroRules, input: &tt::Subtree) -> Result<tt::Subtree> {
rules.rules.iter().find_map(|it| expand_rule(it, input).ok()) rules
.rules
.iter()
.find_map(|it| expand_rule(it, input).ok())
.ok_or(MacroRulesError::NoMatchingRule) .ok_or(MacroRulesError::NoMatchingRule)
} }
@ -80,21 +83,24 @@ enum Binding {
impl Bindings { impl Bindings {
fn get(&self, name: &SmolStr, nesting: &[usize]) -> Result<&tt::TokenTree> { fn get(&self, name: &SmolStr, nesting: &[usize]) -> Result<&tt::TokenTree> {
let mut b = self.inner.get(name).ok_or(MacroRulesError::BindingError( let mut b = self
format!("could not find binding {}", name) .inner
))?; .get(name)
.ok_or(MacroRulesError::BindingError(format!("could not find binding {}", name)))?;
for &idx in nesting.iter() { for &idx in nesting.iter() {
b = match b { b = match b {
Binding::Simple(_) => break, Binding::Simple(_) => break,
Binding::Nested(bs) => bs.get(idx).ok_or(MacroRulesError::BindingError( Binding::Nested(bs) => bs.get(idx).ok_or(MacroRulesError::BindingError(
format!("could not find nested binding {}", name)) format!("could not find nested binding {}", name),
)?, ))?,
}; };
} }
match b { match b {
Binding::Simple(it) => Ok(it), Binding::Simple(it) => Ok(it),
Binding::Nested(_) => Err(MacroRulesError::BindingError( Binding::Nested(_) => Err(MacroRulesError::BindingError(format!(
format!("expected simple binding, found nested binding {}", name))), "expected simple binding, found nested binding {}",
name
))),
} }
} }
@ -105,8 +111,12 @@ impl Bindings {
} }
match self.inner.get_mut(&key) { match self.inner.get_mut(&key) {
Some(Binding::Nested(it)) => it.push(value), Some(Binding::Nested(it)) => it.push(value),
_ => return Err(MacroRulesError::BindingError( _ => {
format!("nested binding for {} not found", key))), return Err(MacroRulesError::BindingError(format!(
"nested binding for {} not found",
key
)))
}
} }
} }
Ok(()) Ok(())