From b8534b374e3a81c417d1c04a5a1be4b933fb1fce Mon Sep 17 00:00:00 2001 From: Robert Masen Date: Sun, 5 Feb 2023 14:18:53 -0600 Subject: [PATCH 1/2] fix: Error type is now Send + Sync --- src/error.rs | 31 ++++++++++++++++++++++++++++--- src/regex.rs | 7 ++----- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/error.rs b/src/error.rs index e82e8fe..b62a596 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,5 +1,6 @@ use ress::{tokens::Keyword, Position}; use std::fmt::{Display, Formatter, Result}; + #[derive(Debug)] pub enum Error { UnexpectedEoF, @@ -43,7 +44,8 @@ pub enum Error { UndefinedExports(Vec), ContinueOfNotIterationLabel(Position, String), Scanner(ress::error::Error), - Other(Box), + Regex(res_regex::Error), + Io(std::io::Error), Misc(String), } @@ -91,7 +93,8 @@ impl Display for Error { Error::UndefinedExports(ref names) => write!(f, "Undefined exports in module: {}", names.join(", ")), Error::ContinueOfNotIterationLabel(ref pos, ref token) => write!(f, "Label `{}` is does not label a loop, continue is invalid at {}", token, pos), Error::Scanner(ref e) => write!(f, "Error when tokenizing {}", e), - Error::Other(ref e) => write!(f, "{}", e), + Error::Regex(ref e) => write!(f, "{}", e), + Error::Io(ref e) => write!(f, "{}", e), Error::Misc(ref e) => write!(f, "{}", e), } } @@ -153,7 +156,7 @@ impl Error { impl From<::std::io::Error> for Error { fn from(other: ::std::io::Error) -> Self { - Error::Other(Box::new(other)) + Error::Io(other) } } impl ::std::error::Error for Error {} @@ -163,3 +166,25 @@ impl From for Error { Error::Scanner(other) } } + +impl From for Error { + fn from(value: res_regex::Error) -> Self { + Self::Regex(value) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn error_is_send_and_sync() { + fn print_error(arg: E) + where + E: std::error::Error + Send + Sync, + { + println!("{arg}"); + } + print_error(Error::Misc("some misc error".to_string())) + } +} diff --git a/src/regex.rs b/src/regex.rs index e5eaeb9..6f94b0e 100644 --- a/src/regex.rs +++ b/src/regex.rs @@ -1,12 +1,9 @@ -use super::{Error, Res}; +use super::Res; use res_regex::RegexParser; /// Validate that an already parsed regular expression /// literal does not contain any illegal constructs /// like a duplicate flag or invalid class range pub fn validate_regex<'a>(regex: &'a str) -> Res<()> { - RegexParser::new(®ex) - .map_err(|e| Error::Other(Box::new(e)))? - .validate() - .map_err(|e| Error::Other(Box::new(e)))?; + RegexParser::new(®ex)?.validate()?; Ok(()) } From 1e85283d9603d81cfa4986a4a40be75faff049eb Mon Sep 17 00:00:00 2001 From: Robert Masen Date: Sun, 4 Jun 2023 10:56:32 -0500 Subject: [PATCH 2/2] bump version to 0.9.0-alpha.2 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 422e707..316ddca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ressa" -version = "0.9.0-alpha.1" +version = "0.9.0-alpha.2" authors = ["Robert Masen "] repository = "https://github.com/rusty-ecma/RESSA" description = "An ECMAscript parser"