diff options
author | Greg Brown <gmb60@cam.ac.uk> | 2021-01-09 14:31:02 +0000 |
---|---|---|
committer | Greg Brown <gmb60@cam.ac.uk> | 2021-01-09 14:31:02 +0000 |
commit | 0d01692c97ea8ca6fc4b229e5b9678cb252bceda (patch) | |
tree | 6c5ed07740b814f50dddbc6afaefc21c11dc3440 /src/chomp/error.rs | |
parent | 487ce4fe0fa081f58d790d7d6417bf7d2659197c (diff) |
Introduce chomp as a procedural macro.
Add a bunch of tests.
Fix chomp and chewed so autochomp compiles.
Diffstat (limited to 'src/chomp/error.rs')
-rw-r--r-- | src/chomp/error.rs | 17 |
1 files changed, 15 insertions, 2 deletions
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<SubstituteError> 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() ) } } |