Skip to content
This repository has been archived by the owner on Jan 29, 2025. It is now read-only.

Commit

Permalink
more friendly names for glsl ExpectedError, implement Display
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobhellermann committed Jun 18, 2021
1 parent bd226b7 commit 1dee90e
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/front/glsl/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use thiserror::Error;
fn join_with_comma(list: &[ExpectedToken]) -> String {
let mut string = "".to_string();
for (i, val) in list.iter().enumerate() {
string.push_str(&val.expected_str());
string.push_str(&val.to_string());
match i {
i if i == list.len() - 1 => {}
i if i == list.len() - 2 => string.push_str(" or "),
Expand All @@ -18,7 +18,7 @@ fn join_with_comma(list: &[ExpectedToken]) -> String {
string
}

#[derive(Debug)]
#[derive(Debug, PartialEq)]
pub enum ExpectedToken {
Token(TokenValue),
TypeName,
Expand All @@ -32,15 +32,15 @@ impl From<TokenValue> for ExpectedToken {
ExpectedToken::Token(token)
}
}
impl ExpectedToken {
fn expected_str(&self) -> String {
impl std::fmt::Display for ExpectedToken {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ExpectedToken::Token(token) => format!("{:?}", token),
ExpectedToken::TypeName => "TypeName".to_string(),
ExpectedToken::Identifier => "Identifier".to_string(),
ExpectedToken::IntLiteral => "IntLiteral".to_string(),
ExpectedToken::FloatLiteral => "FloatLiteral".to_string(),
ExpectedToken::BoolLiteral => "BoolLiteral".to_string(),
ExpectedToken::Token(token) => write!(f, "{:?}", token),
ExpectedToken::TypeName => write!(f, "a type"),
ExpectedToken::Identifier => write!(f, "identifier"),
ExpectedToken::IntLiteral => write!(f, "integer literal"),
ExpectedToken::FloatLiteral => write!(f, "float literal"),
ExpectedToken::BoolLiteral => write!(f, "bool literal"),
}
}
}
Expand Down

0 comments on commit 1dee90e

Please sign in to comment.