From ef485d6f3e4df6e1a424ba3797388fa0bba6eb2e Mon Sep 17 00:00:00 2001 From: Greg Brown Date: Mon, 26 Apr 2021 11:14:21 +0100 Subject: Replace substitution with translation. --- src/nibble/convert.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/nibble/convert.rs') diff --git a/src/nibble/convert.rs b/src/nibble/convert.rs index 1e1ea08..e5e8c5d 100644 --- a/src/nibble/convert.rs +++ b/src/nibble/convert.rs @@ -39,7 +39,11 @@ impl Context { res } - pub fn with_variables, F: FnOnce(&mut Self) -> R, R>(&mut self, names: I, f: F) -> R { + pub fn with_variables, F: FnOnce(&mut Self) -> R, R>( + &mut self, + names: I, + f: F, + ) -> R { let len = self.bindings.len(); self.bindings.extend(names); let res = f(self); @@ -286,17 +290,18 @@ impl Convert for Alt { impl Convert for Lambda { fn convert(self, context: &mut Context) -> Result { let span = self.span(); - let mut names = self.args.into_iter().map(Name::from); + let mut args: Vec<_> = self.args.into_iter().map(Name::from).collect(); let expr = self.expr; - let inner = context.with_variables(names.clone(), |ctx| expr.convert(ctx))?; - let first = names.next().unwrap(); - let rest = names.collect(); + let inner = context.with_variables(args.clone(), |ctx| expr.convert(ctx))?; Ok(NamedExpression { name: None, - expr: ast::Lambda { first, rest, inner: Box::new(inner)}.into(), + expr: ast::Lambda { + args, + inner: Box::new(inner), + } + .into(), span, }) - } } -- cgit v1.2.3