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
fa2ef528b7
commit
a1696ccdb8
2 changed files with 22 additions and 22 deletions
|
@ -105,16 +105,11 @@ fn main() {
|
|||
let ansi_parser = Arc::new(Mutex::new(ANSISQLParser::new(acme_tokenizer.clone())));
|
||||
let acme_parser = Arc::new(Mutex::new(AcmeParser::new(acme_tokenizer.clone())));
|
||||
|
||||
// ansi_parser.lock().unwrap().next_token();
|
||||
let mut pratt_parser = PrattParser {
|
||||
chars: CharSeq::new(sql),
|
||||
parser: acme_parser
|
||||
};
|
||||
|
||||
//let parser_list = 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 expr = parse_expr(acme_parser).unwrap();
|
||||
//
|
||||
// println!("Parsed: {:?}", expr);
|
||||
let expr = pratt_parser.parse_expr().unwrap();
|
||||
println!("{:?}", expr);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use std::cmp::PartialEq;
|
||||
use std::fmt::Debug;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use super::tokenizer::*;
|
||||
|
||||
|
@ -113,11 +114,21 @@ pub trait SQLParser<TokenType, ExprType>
|
|||
fn parse_infix(&mut self, chars: &mut CharSeq, left: &SQLExpr<ExprType>, precedence: usize) -> Result<Option<Box<SQLExpr<ExprType>>>, ParserError<TokenType>>;
|
||||
}
|
||||
|
||||
//struct PrattParser<ExprType, TokenType> {
|
||||
//
|
||||
// ansi_parser:
|
||||
//
|
||||
//}
|
||||
pub struct PrattParser<TokenType, ExprType> {
|
||||
pub chars: CharSeq,
|
||||
pub parser: Arc<Mutex<SQLParser<TokenType, ExprType>>>
|
||||
}
|
||||
|
||||
impl<TokenType, ExprType> PrattParser<TokenType, ExprType> where TokenType: Debug + PartialEq, ExprType: Debug {
|
||||
|
||||
pub fn parse_expr(&mut self) -> Result<Option<Box<SQLExpr<ExprType>>>, ParserError<TokenType>> {
|
||||
|
||||
let mut p = self.parser.lock().unwrap();
|
||||
|
||||
p.parse_prefix(&mut self.chars)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
//pub fn parse_expr<'a, TokenType, ExprType>(parser: Arc<Mutex<SQLParser<TokenType, ExprType>>>)
|
||||
|
@ -130,12 +141,6 @@ pub trait SQLParser<TokenType, ExprType>
|
|||
//}
|
||||
|
||||
|
||||
//pub struct PrattParser<'a, TokenType, ExprType> {
|
||||
// chars: Peekable<Chars<'a>>,
|
||||
// tokenizer: Rc<SQLTokenizer<TokenType>>,
|
||||
// parser: Rc<SQLParser<TokenType, ExprType>>
|
||||
//}
|
||||
//
|
||||
//impl<'a, TokenType, ExprType> PrattParser<'a, TokenType, ExprType>
|
||||
// where TokenType: Debug + PartialEq, ExprType: Debug {
|
||||
//
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue