use std::fmt;
use crate::verifier::MAX_WORD_LEN;
#[derive(Debug, PartialEq)]
pub enum ValueErrorType {
InvalidTossi,
InvalidCharacter,
LimitLength,
}
impl fmt::Display for ValueErrorType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
ValueErrorType::InvalidTossi => write!(f, "This value is not correct tossi"),
ValueErrorType::InvalidCharacter => {
write!(f, "This value is not a valid Hangul character")
}
ValueErrorType::LimitLength => write!(
f,
"The length has been exceeded. Set the word length to less than {MAX_WORD_LEN}"
),
}
}
}
#[derive(Debug, PartialEq)]
pub struct ValueError {
pub error: ValueErrorType,
pub description: String,
}
impl ValueError {
pub fn new(error: ValueErrorType) -> Self {
ValueError {
description: error.to_string(),
error,
}
}
}
impl fmt::Display for ValueError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.error)
}
}
#[derive(Debug, PartialEq)]
pub enum ParseErrorType {
InvalidValue(ValueErrorType),
AreNotBalanced,
IsNotBrace,
NestedParentheses,
SplitTossiWord,
TossiIsEmpty,
WordIsEmpty,
}
impl fmt::Display for ParseErrorType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
ParseErrorType::InvalidValue(_value_error) => write!(f, "{_value_error}."),
ParseErrorType::AreNotBalanced => write!(
f,
"The sentence can not be parsed. Please check the sentence has incorrect parentheses."
),
ParseErrorType::IsNotBrace => write!(
f,
"The sentence can not be parsed. Please set the parentheses as a brace."
),
ParseErrorType::NestedParentheses => {
write!(f, "The sentence includes Nested Parentheses.")
}
ParseErrorType::SplitTossiWord => write!(
f,
"The sentence can not be parsed. Please separate words and tossi with a comma."
),
ParseErrorType::TossiIsEmpty => write!(
f,
"The sentence can not be parsed. Please fill the tossi section in the parentheses."
),
ParseErrorType::WordIsEmpty => write!(
f,
"The sentence can not be parsed. Please fill the word section in the parentheses."
),
}
}
}
#[derive(Debug, PartialEq)]
pub struct ParseError {
pub error: ParseErrorType,
pub description: String,
}
impl ParseError {
pub fn new(error: ParseErrorType) -> Self {
ParseError {
description: error.to_string(),
error,
}
}
}
impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.error)
}
}