12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- use std::{error::Error, fmt, fmt::Display};
-
- #[derive(Debug, PartialEq)]
- pub struct LexerError {
- message: String,
- }
-
- impl LexerError {
- pub fn new(message: &str) -> Self {
- Self {
- message: message.to_string(),
- }
- }
- }
-
- impl Display for LexerError {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "{}", &self.message)
- }
- }
-
- impl Error for LexerError {}
-
- impl From<LexerError> for std::io::Error {
- fn from(e: LexerError) -> Self {
- Self::new(std::io::ErrorKind::InvalidInput, e.message)
- }
- }
-
- #[derive(Debug, PartialEq)]
- pub struct ParserError {
- message: String,
- }
-
- impl ParserError {
- pub fn new(message: &str) -> Self {
- Self {
- message: message.to_string(),
- }
- }
- }
-
- impl Display for ParserError {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "{}", &self.message)
- }
- }
-
- impl Error for ParserError {}
-
- impl From<ParserError> for std::io::Error {
- fn from(e: ParserError) -> Self {
- Self::new(std::io::ErrorKind::InvalidInput, e.message)
- }
- }
-
- #[derive(Debug, PartialEq)]
- pub struct CompilerError {
- message: String,
- }
-
- impl CompilerError {
- pub fn new(message: &str) -> Self {
- Self {
- message: message.to_string(),
- }
- }
- }
-
- impl Display for CompilerError {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "{}", &self.message)
- }
- }
-
- impl Error for CompilerError {}
-
- impl From<CompilerError> for std::io::Error {
- fn from(e: CompilerError) -> Self {
- Self::new(std::io::ErrorKind::InvalidInput, e.message)
- }
- }
|