summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Brown <gmb60@cam.ac.uk>2021-01-19 22:48:36 +0000
committerGreg Brown <gmb60@cam.ac.uk>2021-01-19 22:48:36 +0000
commitfaa3f30deb32d0a1fd7cb196559762635b22ecfd (patch)
tree6ab8bc07c32f51811929c03320f0a87b4ca8ae3c
parent8f7a17e0f48e3586fae619be08351c6761b07596 (diff)
Remove usage of feature of proc_macro2.
-rw-r--r--Cargo.toml5
-rw-r--r--src/chomp/ast/error.rs61
-rw-r--r--src/nibble/convert.rs19
3 files changed, 46 insertions, 39 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 29a4509..9769ca2 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -9,9 +9,6 @@ members = ["autochomp", "chewed", "chomp-macro"]
[dependencies]
heck = "0.3.2"
+proc-macro2 = "1.0.24"
quote = "1.0.8"
syn = "1.0.58"
-
-[dependencies.proc-macro2]
-version = "1.0.24"
-features = ["span-locations"]
diff --git a/src/chomp/ast/error.rs b/src/chomp/ast/error.rs
index 7be5354..12d7b90 100644
--- a/src/chomp/ast/error.rs
+++ b/src/chomp/ast/error.rs
@@ -1,4 +1,7 @@
-use std::{error::Error, fmt::{self, Display}};
+use std::{
+ error::Error,
+ fmt::{self, Display},
+};
use proc_macro2::Span;
@@ -8,26 +11,27 @@ use super::{Call, Parameter};
#[derive(Debug)]
pub enum SubstituteError {
- FreeParameter { param: Parameter, span: Option<Span>, name: Option<Name> },
- WrongArgCount { call: Call, expected: usize, span: Option<Span> },
+ FreeParameter {
+ param: Parameter,
+ span: Option<Span>,
+ name: Option<Name>,
+ },
+ WrongArgCount {
+ call: Call,
+ expected: usize,
+ span: Option<Span>,
+ },
}
impl From<SubstituteError> for syn::Error {
fn from(e: SubstituteError) -> Self {
- match e {
- SubstituteError::FreeParameter { span, .. } => {
- Self::new(span.unwrap_or_else(Span::call_site), "unbound parameter")
- }
- SubstituteError::WrongArgCount { call, expected, span } => {
- let msg = if call.args.len() == 1 {
- format!("this function takes {} arguments but 1 was supplied", expected)
- } else {
- format!("this function takes {} arguments but {} were supplied", expected, call.args.len())
- };
+ let msg = e.to_string();
+ let span = match e {
+ SubstituteError::FreeParameter { span, .. } => span,
+ SubstituteError::WrongArgCount { span, .. } => span,
+ };
- Self::new(span.unwrap_or_else(Span::call_site), msg)
- }
- }
+ Self::new(span.unwrap_or_else(Span::call_site), msg)
}
}
@@ -35,19 +39,30 @@ impl Display for SubstituteError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::FreeParameter { param, span, name } => {
- let start = span.unwrap_or_else(Span::call_site).start();
if let Some(name) = name {
- write!(f, "{}:{}: unbound parameter `{}`", start.line, start.column, name)
+ write!(f, "unbound parameter: `{}`", name)
} else {
- write!(f, "{}:{}: unbound parameter '{}", start.line, start.column, param.index)
+ write!(f, "unbound parameter: '{}", param.index)
}
}
- Self::WrongArgCount { call, expected, span } => {
- let start = span.unwrap_or_else(Span::call_site).start();
+ Self::WrongArgCount {
+ call,
+ expected,
+ span,
+ } => {
if call.args.len() == 1 {
- write!(f, "{}:{}: this function takes {} arguments but 1 was supplied", start.line, start.column, expected)
+ write!(
+ f,
+ "this function takes {} arguments but 1 was supplied",
+ expected
+ )
} else {
- write!(f, "{}:{}: this function takes {} arguments but {} were supplied", start.line, start.column, expected, call.args.len())
+ write!(
+ f,
+ "this function takes {} arguments but {} were supplied",
+ expected,
+ call.args.len()
+ )
}
}
}
diff --git a/src/nibble/convert.rs b/src/nibble/convert.rs
index f7c20be..3310b2a 100644
--- a/src/nibble/convert.rs
+++ b/src/nibble/convert.rs
@@ -73,12 +73,12 @@ pub enum ConvertError {
impl From<ConvertError> for syn::Error {
fn from(e: ConvertError) -> Self {
- match e {
- ConvertError::UndeclaredName(name) => {
- let ident = name.into_ident(Span::call_site());
- Self::new(ident.span(), "undeclared name")
- }
- }
+ let msg = e.to_string();
+ let span = match e {
+ ConvertError::UndeclaredName(name) => name.span(),
+ };
+
+ Self::new(span.unwrap_or_else(Span::call_site), msg)
}
}
@@ -86,12 +86,7 @@ impl fmt::Display for ConvertError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::UndeclaredName(name) => {
- let start = name.span().unwrap_or_else(Span::call_site).start();
- write!(
- f,
- "{}:{}: undeclared name `{}'",
- start.line, start.column, name
- )
+ write!(f, "undeclared name: `{}`", name)
}
}
}