Skip to content

Commit fa2ef52

Browse files
committed
Refactoring
1 parent 037ebb0 commit fa2ef52

File tree

2 files changed

+36
-22
lines changed

2 files changed

+36
-22
lines changed

examples/acme_parser.rs

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,33 @@ impl SQLTokenizer<AcmeToken> for AcmeTokenizer {
3636
}
3737

3838
fn next_token(&mut self, chars: &mut CharSeq) -> Result<Option<SQLToken<AcmeToken>>, TokenizerError> {
39-
// let mut arc = self.ansi_tokenizer.lock().unwrap();
40-
// match arc.peek_char() {
41-
// Some(&ch) => match ch {
42-
// '!' => {
43-
// arc.next_char(); // consume the first `!`
44-
// match arc.peek_char() {
45-
// Some(&ch) => match ch {
46-
// '!' => {
47-
// arc.next_char(); // consume the second `!`
48-
// Ok(Some(SQLToken::Custom(AcmeToken::Factorial)))
49-
// },
50-
// _ => Err(TokenizerError::UnexpectedChar(ch,Position::new(0,0)))
51-
// },
52-
// None => Ok(Some(SQLToken::Not))
53-
// }
54-
// }
55-
// _ => arc.next_token()
56-
// }
57-
// _ => arc.next_token()
58-
// }
59-
unimplemented!()
39+
let mut ansi = self.ansi_tokenizer.lock().unwrap();
40+
match chars.peek() {
41+
Some(&ch) => match ch {
42+
'!' => {
43+
chars.mark();
44+
chars.next(); // consume the first `!`
45+
match chars.peek() {
46+
Some(&ch) => match ch {
47+
'!' => {
48+
chars.next(); // consume the second `!`
49+
Ok(Some(SQLToken::Custom(AcmeToken::Factorial)))
50+
},
51+
_ => {
52+
chars.reset();
53+
ansi.next_token(chars)
54+
}
55+
},
56+
None => {
57+
chars.reset();
58+
ansi.next_token(chars)
59+
}
60+
}
61+
}
62+
_ => ansi.next_token(chars)
63+
}
64+
_ => ansi.next_token(chars)
65+
}
6066
}
6167

6268
}
@@ -99,7 +105,9 @@ fn main() {
99105
let ansi_parser = Arc::new(Mutex::new(ANSISQLParser::new(acme_tokenizer.clone())));
100106
let acme_parser = Arc::new(Mutex::new(AcmeParser::new(acme_tokenizer.clone())));
101107

102-
//let parser_list: Vec<Arc<Mutex<SQLParser<>>>> = vec![acme_parser, ansi_parser];
108+
// ansi_parser.lock().unwrap().next_token();
109+
110+
//let parser_list = vec![acme_parser, ansi_parser];
103111

104112
// Custom ACME parser
105113
// let acme_parser: Arc<Mutex<SQLParser<AcmeToken, AcmeExpr>>> = Arc::new(Mutex::new(AcmeParser {

src/parser.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ pub trait SQLParser<TokenType, ExprType>
113113
fn parse_infix(&mut self, chars: &mut CharSeq, left: &SQLExpr<ExprType>, precedence: usize) -> Result<Option<Box<SQLExpr<ExprType>>>, ParserError<TokenType>>;
114114
}
115115

116+
//struct PrattParser<ExprType, TokenType> {
117+
//
118+
// ansi_parser:
119+
//
120+
//}
121+
116122
//
117123
//pub fn parse_expr<'a, TokenType, ExprType>(parser: Arc<Mutex<SQLParser<TokenType, ExprType>>>)
118124
// -> Result<Box<SQLExpr<ExprType>>, ParserError<TokenType>> where TokenType: Debug + PartialEq, ExprType: Debug {

0 commit comments

Comments
 (0)