SeraphScript/src/logger/messages.rs

41 lines
1.2 KiB
Rust

use crate::parsing::lexer::lex_tokens::TokenType;
#[derive(Debug)]
pub enum Message {
UnexpectedCharacter(char),
InvalidCharacter {
found: char,
expected: char,
},
UnclosedStringLiteral,
UnexpectedToken {
found: TokenType,
expected: Vec<TokenType>,
},
EmptyProperty,
}
impl Message {
pub fn stringify(&self) -> String {
match self {
Message::UnexpectedCharacter(c) => {
format!("Encountered unexpected character '{}'", c)
}
Message::InvalidCharacter { found, expected } => {
format!(
"Encountered invalid character '{}', expected '{}'",
found, expected
)
}
Message::UnclosedStringLiteral => "Encountered unclosed string literal".to_string(),
Message::UnexpectedToken { found, expected } => {
format!(
"Encountered unexpected token '{:?}', expected any of {:?}",
found, expected
)
}
Message::EmptyProperty => "Property encountered without a getter or setter".to_string(),
}
}
}