From 0d01692c97ea8ca6fc4b229e5b9678cb252bceda Mon Sep 17 00:00:00 2001 From: Greg Brown Date: Sat, 9 Jan 2021 14:31:02 +0000 Subject: Introduce chomp as a procedural macro. Add a bunch of tests. Fix chomp and chewed so autochomp compiles. --- src/chomp/error.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/chomp/error.rs') diff --git a/src/chomp/error.rs b/src/chomp/error.rs index ffcbdd0..e7e4660 100644 --- a/src/chomp/error.rs +++ b/src/chomp/error.rs @@ -358,6 +358,19 @@ pub enum SubstituteError { WrongArgCount { call: Call, expected: usize }, } +impl From for syn::Error { + fn from(e: SubstituteError) -> Self { + match e { + SubstituteError::FreeParameter(param) => { + Self::new(param.name().span().unwrap_or_else(Span::call_site), format!("undeclared variable `{}'", param.name())) + } + SubstituteError::WrongArgCount { call, expected } => { + Self::new(call.span().unwrap_or_else(Span::call_site), format!("wrong number of arguments. Expected {}, got {}", expected, call.args().len())) + } + } + } +} + impl Display for SubstituteError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { @@ -378,8 +391,8 @@ impl Display for SubstituteError { "{}:{}: wrong number of arguments. Expected {}, got {}", start.line, start.column, - call.args().len(), - expected + expected, + call.args().len() ) } } -- cgit v1.2.3