SeraphScript/src/logger/messages.rs

41 lines
1.2 KiB
Rust
Raw Normal View History

2021-06-05 19:03:14 +00:00
use crate::parsing::lexer::lex_tokens::TokenType;
#[derive(Debug)]
pub enum Message {
UnexpectedCharacter(char),
2021-06-05 19:03:14 +00:00
InvalidCharacter {
found: char,
expected: char,
},
UnclosedStringLiteral,
2021-06-05 19:03:14 +00:00
UnexpectedToken {
found: TokenType,
expected: Vec<TokenType>,
},
2022-01-01 16:48:57 +00:00
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(),
}
}
}