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
a1696ccdb8
commit
375671e208
2 changed files with 14 additions and 4 deletions
|
@ -107,7 +107,7 @@ fn main() {
|
|||
|
||||
let mut pratt_parser = PrattParser {
|
||||
chars: CharSeq::new(sql),
|
||||
parser: acme_parser
|
||||
parsers: vec![acme_parser, ansi_parser]
|
||||
};
|
||||
|
||||
let expr = pratt_parser.parse_expr().unwrap();
|
||||
|
|
|
@ -116,16 +116,26 @@ pub trait SQLParser<TokenType, ExprType>
|
|||
|
||||
pub struct PrattParser<TokenType, ExprType> {
|
||||
pub chars: CharSeq,
|
||||
pub parser: Arc<Mutex<SQLParser<TokenType, ExprType>>>
|
||||
pub parsers: Vec<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();
|
||||
for i in 0..self.parsers.len() {
|
||||
let mut p = self.parsers[i].lock().unwrap();
|
||||
let expr = p.parse_prefix(&mut self.chars)?;
|
||||
|
||||
p.parse_prefix(&mut self.chars)
|
||||
// return as soon as we have a match
|
||||
match expr {
|
||||
Some(_) => return Ok(expr),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
// found no valid token
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue