Skip to content

Commit

Permalink
Implement std::error::Error for ParserError
Browse files Browse the repository at this point in the history
  • Loading branch information
benesch committed May 26, 2019
1 parent 4f944dd commit 373a926
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/sqlparser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use super::dialect::keywords;
use super::dialect::Dialect;
use super::sqlast::*;
use super::sqltokenizer::*;
use std::error::Error;

#[derive(Debug, Clone, PartialEq)]
pub enum ParserError {
Expand Down Expand Up @@ -47,6 +48,21 @@ impl From<TokenizerError> for ParserError {
}
}

impl std::fmt::Display for ParserError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(
f,
"sql parser error: {}",
match self {
ParserError::TokenizerError(s) => s,
ParserError::ParserError(s) => s,
}
)
}
}

impl Error for ParserError {}

/// SQL Parser
pub struct Parser {
tokens: Vec<Token>,
Expand Down

0 comments on commit 373a926

Please sign in to comment.