From dfc08ff2c6580bbeb3951b223e0332546ba3b0d9 Mon Sep 17 00:00:00 2001 From: Greg Brown Date: Thu, 6 May 2021 19:40:59 +0100 Subject: Introduce lambda expressions. --- src/chomp/ast/error.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/chomp/ast/error.rs') diff --git a/src/chomp/ast/error.rs b/src/chomp/ast/error.rs index 9057ec3..ea145a7 100644 --- a/src/chomp/ast/error.rs +++ b/src/chomp/ast/error.rs @@ -6,31 +6,31 @@ use std::{ }; #[derive(Debug)] -pub enum TranslateError { +pub enum ReductionError { CallNotAFunction { on: Expression, - span: Option, + span: Span, }, WrongArgCount { lambda: Lambda, args: Vec, - span: Option, + span: Span, }, } -impl From for syn::Error { - fn from(e: TranslateError) -> Self { +impl From for syn::Error { + fn from(e: ReductionError) -> Self { let msg = e.to_string(); let span = match e { - TranslateError::CallNotAFunction { span, .. } - | TranslateError::WrongArgCount { span, .. } => span, + ReductionError::CallNotAFunction { span, .. } + | ReductionError::WrongArgCount { span, .. } => span, }; - Self::new(span.unwrap_or_else(Span::call_site), msg) + Self::new(span, msg) } } -impl Display for TranslateError { +impl Display for ReductionError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::CallNotAFunction { .. } => { @@ -38,7 +38,7 @@ impl Display for TranslateError { } Self::WrongArgCount { lambda, args, .. } => match (lambda.args.len(), args.len()) { (1, n) => write!(f, "this function takes 1 argument but {} were supplied", n), - (m, _) => write!(f, "this function takes {} arguments but 1 was supplied", m), + (m, 1) => write!(f, "this function takes {} arguments but 1 was supplied", m), (m, n) => write!( f, "this function takes {} arguments but {} were supplied", @@ -49,4 +49,4 @@ impl Display for TranslateError { } } -impl Error for TranslateError {} +impl Error for ReductionError {} -- cgit v1.2.3