mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-07-07 17:04:59 +00:00
Refactoring
This commit is contained in:
parent
2e20b15c2e
commit
037ebb0f73
4 changed files with 22 additions and 17 deletions
|
@ -62,19 +62,24 @@ impl SQLTokenizer<AcmeToken> for AcmeTokenizer {
|
|||
}
|
||||
|
||||
struct AcmeParser {
|
||||
ansi_parser: Arc<Mutex<SQLParser<AcmeToken, AcmeExpr>>>
|
||||
tokenizer: Arc<Mutex<SQLTokenizer<AcmeToken>>>
|
||||
}
|
||||
|
||||
impl AcmeParser {
|
||||
|
||||
pub fn new(tokenizer: Arc<Mutex<SQLTokenizer<AcmeToken>>>) -> Self {
|
||||
AcmeParser { tokenizer: tokenizer.clone() }
|
||||
}
|
||||
|
||||
}
|
||||
impl SQLParser<AcmeToken, AcmeExpr> for AcmeParser {
|
||||
|
||||
fn parse_prefix(&mut self, chars: &mut CharSeq) -> Result<Box<SQLExpr<AcmeExpr>>, ParserError<AcmeToken>> {
|
||||
//TODO: add custom overrides
|
||||
self.ansi_parser.lock().unwrap().parse_prefix(chars)
|
||||
fn parse_prefix(&mut self, chars: &mut CharSeq) -> Result<Option<Box<SQLExpr<AcmeExpr>>>, ParserError<AcmeToken>> {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
fn parse_infix(&mut self, chars: &mut CharSeq, left: &SQLExpr<AcmeExpr>, precedence: usize) -> Result<Option<Box<SQLExpr<AcmeExpr>>>, ParserError<AcmeToken>> {
|
||||
//TODO: add custom overrides
|
||||
self.ansi_parser.lock().unwrap().parse_infix(chars, left, precedence)
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,14 +95,18 @@ fn main() {
|
|||
ansi_tokenizer: ansi_tokenizer.clone()
|
||||
}));
|
||||
|
||||
// Create parsers
|
||||
let ansi_parser = Arc::new(Mutex::new(ANSISQLParser::new(acme_tokenizer.clone())));
|
||||
let acme_parser = Arc::new(Mutex::new(AcmeParser::new(acme_tokenizer.clone())));
|
||||
|
||||
//let parser_list: Vec<Arc<Mutex<SQLParser<>>>> = vec![acme_parser, ansi_parser];
|
||||
|
||||
// Custom ACME parser
|
||||
let acme_parser: Arc<Mutex<SQLParser<AcmeToken, AcmeExpr>>> = Arc::new(Mutex::new(AcmeParser {
|
||||
ansi_parser: Arc::new(Mutex::new(ANSISQLParser::new(acme_tokenizer)))
|
||||
}));
|
||||
// let acme_parser: Arc<Mutex<SQLParser<AcmeToken, AcmeExpr>>> = Arc::new(Mutex::new(AcmeParser {
|
||||
// ansi_parser: Arc::new(Mutex::new(ANSISQLParser::new(acme_tokenizer)))
|
||||
// }));
|
||||
|
||||
// let expr = parse_expr(acme_parser).unwrap();
|
||||
//
|
||||
// println!("Parsed: {:?}", expr);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ impl<TokenType> ANSISQLParser<TokenType> where TokenType: Debug + PartialEq {
|
|||
impl<TokenType, ExprType> SQLParser<TokenType, ExprType> for ANSISQLParser<TokenType>
|
||||
where TokenType: Debug + PartialEq, ExprType: Debug {
|
||||
|
||||
fn parse_prefix(&mut self, chars: &mut CharSeq) -> Result<Box<SQLExpr<ExprType>>, ParserError<TokenType>> {
|
||||
fn parse_prefix(&mut self, chars: &mut CharSeq) -> Result<Option<Box<SQLExpr<ExprType>>>, ParserError<TokenType>> {
|
||||
|
||||
match self.tokenizer.lock().unwrap().next_token(chars)? {
|
||||
Some(SQLToken::Keyword(ref k)) => match k.to_uppercase().as_ref() {
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
use std::cmp::PartialEq;
|
||||
use std::fmt::Debug;
|
||||
use std::iter::Peekable;
|
||||
use std::str::Chars;
|
||||
|
||||
use super::super::tokenizer::*;
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
use std::cmp::PartialEq;
|
||||
use std::fmt::Debug;
|
||||
use std::rc::Rc;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use super::tokenizer::*;
|
||||
|
||||
|
@ -110,7 +108,7 @@ pub trait SQLParser<TokenType, ExprType>
|
|||
where TokenType: Debug + PartialEq, ExprType: Debug {
|
||||
|
||||
/// parse the prefix and stop once an infix operator is reached
|
||||
fn parse_prefix(&mut self, chars: &mut CharSeq) -> Result<Box<SQLExpr<ExprType>>, ParserError<TokenType>> ;
|
||||
fn parse_prefix(&mut self, chars: &mut CharSeq) -> Result<Option<Box<SQLExpr<ExprType>>>, ParserError<TokenType>> ;
|
||||
/// parse the next infix expression, returning None if the precedence has changed
|
||||
fn parse_infix(&mut self, chars: &mut CharSeq, left: &SQLExpr<ExprType>, precedence: usize) -> Result<Option<Box<SQLExpr<ExprType>>>, ParserError<TokenType>>;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue