Merge pull request #72 from benesch/error

Implement std::error::Error for ParserError
This commit is contained in:
Nickolay Ponomarev 2019-05-30 02:32:02 +03:00 committed by GitHub
commit bc1ec47e4b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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 {
@ -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>,