diff options
author | Greg Brown <gmb60@cam.ac.uk> | 2021-04-26 11:14:21 +0100 |
---|---|---|
committer | Greg Brown <gmb60@cam.ac.uk> | 2021-04-30 14:45:12 +0100 |
commit | ef485d6f3e4df6e1a424ba3797388fa0bba6eb2e (patch) | |
tree | 33d6cd11b21791e5727f29a428051578d3ab17fc /src/nibble | |
parent | bf46a471fb268f7c0798a179740b295f8aaa1a31 (diff) |
Replace substitution with translation.
Diffstat (limited to 'src/nibble')
-rw-r--r-- | src/nibble/convert.rs | 19 |
1 files changed, 12 insertions, 7 deletions
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<I: IntoIterator<Item = Name>, F: FnOnce(&mut Self) -> R, R>(&mut self, names: I, f: F) -> R { + pub fn with_variables<I: IntoIterator<Item = Name>, 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<NamedExpression, ConvertError> { 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, }) - } } |