Skip to content

Commit a1696cc

Browse files
committed
Refactoring
1 parent fa2ef52 commit a1696cc

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

examples/acme_parser.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,11 @@ fn main() {
105105
let ansi_parser = Arc::new(Mutex::new(ANSISQLParser::new(acme_tokenizer.clone())));
106106
let acme_parser = Arc::new(Mutex::new(AcmeParser::new(acme_tokenizer.clone())));
107107

108-
// ansi_parser.lock().unwrap().next_token();
108+
let mut pratt_parser = PrattParser {
109+
chars: CharSeq::new(sql),
110+
parser: acme_parser
111+
};
109112

110-
//let parser_list = vec![acme_parser, ansi_parser];
111-
112-
// Custom ACME parser
113-
// let acme_parser: Arc<Mutex<SQLParser<AcmeToken, AcmeExpr>>> = Arc::new(Mutex::new(AcmeParser {
114-
// ansi_parser: Arc::new(Mutex::new(ANSISQLParser::new(acme_tokenizer)))
115-
// }));
116-
117-
// let expr = parse_expr(acme_parser).unwrap();
118-
//
119-
// println!("Parsed: {:?}", expr);
113+
let expr = pratt_parser.parse_expr().unwrap();
114+
println!("{:?}", expr);
120115
}

src/parser.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::cmp::PartialEq;
22
use std::fmt::Debug;
3+
use std::sync::{Arc, Mutex};
34

45
use super::tokenizer::*;
56

@@ -113,11 +114,21 @@ pub trait SQLParser<TokenType, ExprType>
113114
fn parse_infix(&mut self, chars: &mut CharSeq, left: &SQLExpr<ExprType>, precedence: usize) -> Result<Option<Box<SQLExpr<ExprType>>>, ParserError<TokenType>>;
114115
}
115116

116-
//struct PrattParser<ExprType, TokenType> {
117-
//
118-
// ansi_parser:
119-
//
120-
//}
117+
pub struct PrattParser<TokenType, ExprType> {
118+
pub chars: CharSeq,
119+
pub parser: Arc<Mutex<SQLParser<TokenType, ExprType>>>
120+
}
121+
122+
impl<TokenType, ExprType> PrattParser<TokenType, ExprType> where TokenType: Debug + PartialEq, ExprType: Debug {
123+
124+
pub fn parse_expr(&mut self) -> Result<Option<Box<SQLExpr<ExprType>>>, ParserError<TokenType>> {
125+
126+
let mut p = self.parser.lock().unwrap();
127+
128+
p.parse_prefix(&mut self.chars)
129+
}
130+
131+
}
121132

122133
//
123134
//pub fn parse_expr<'a, TokenType, ExprType>(parser: Arc<Mutex<SQLParser<TokenType, ExprType>>>)
@@ -130,12 +141,6 @@ pub trait SQLParser<TokenType, ExprType>
130141
//}
131142

132143

133-
//pub struct PrattParser<'a, TokenType, ExprType> {
134-
// chars: Peekable<Chars<'a>>,
135-
// tokenizer: Rc<SQLTokenizer<TokenType>>,
136-
// parser: Rc<SQLParser<TokenType, ExprType>>
137-
//}
138-
//
139144
//impl<'a, TokenType, ExprType> PrattParser<'a, TokenType, ExprType>
140145
// where TokenType: Debug + PartialEq, ExprType: Debug {
141146
//

0 commit comments

Comments
 (0)