Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#155] !=, <=, >= 연산자 등 토큰화 구현 #157

Merged
merged 6 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/executor/initializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ impl Executor {
self.check_output_status(output)
}

#[allow(dead_code)]
async fn write_and_check_err(
&self,
base_path: PathBuf,
Expand Down
33 changes: 33 additions & 0 deletions src/lexer/test/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,17 @@ pub fn test_operators() {
Token::Integer(2),
],
},
TestCase {
name: "연산자: <=".to_owned(),
input: r#"SELECT 1 <= 2"#.to_owned(),
want_error: false,
expected: vec![
Token::Select,
Token::Integer(1),
Token::Operator(OperatorToken::Lte),
Token::Integer(2),
],
},
TestCase {
name: "연산자: >".to_owned(),
input: r#"SELECT 1 > 2"#.to_owned(),
Expand All @@ -199,6 +210,17 @@ pub fn test_operators() {
Token::Integer(2),
],
},
TestCase {
name: "연산자: >=".to_owned(),
input: r#"SELECT 1 >= 2"#.to_owned(),
want_error: false,
expected: vec![
Token::Select,
Token::Integer(1),
Token::Operator(OperatorToken::Gte),
Token::Integer(2),
],
},
TestCase {
name: "연산자: -".to_owned(),
input: r#"SELECT 1 - 2"#.to_owned(),
Expand Down Expand Up @@ -243,6 +265,17 @@ pub fn test_operators() {
Token::Integer(2),
],
},
TestCase {
name: "연산자: !=".to_owned(),
input: r#"SELECT 1 != 2"#.to_owned(),
want_error: false,
expected: vec![
Token::Select,
Token::Integer(1),
Token::Operator(OperatorToken::Neq),
Token::Integer(2),
],
},
TestCase {
name: "연산자: !".to_owned(),
input: r#"SELECT ! True"#.to_owned(),
Expand Down
42 changes: 39 additions & 3 deletions src/lexer/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,46 @@ impl Tokenizer {
}
'+' => Token::Operator(OperatorToken::Plus),
'*' => Token::Operator(OperatorToken::Asterisk),
'!' => Token::Operator(OperatorToken::Not), // TODO: != 연산자 처리
'!' => {
// 다음 문자가 =일 경우 != 연산자로 처리

self.read_char();

if self.last_char == '=' {
Token::Operator(OperatorToken::Neq)
} else {
self.unread_char();

Token::Operator(OperatorToken::Not)
}
}
'=' => Token::Operator(OperatorToken::Eq),
'<' => Token::Operator(OperatorToken::Lt), // TODO: <= 연산자 처리
'>' => Token::Operator(OperatorToken::Gt), // TODO: >= 연산자 처리
'<' => {
// 다음 문자가 =일 경우 <= 연산자로 처리

self.read_char();

if self.last_char == '=' {
Token::Operator(OperatorToken::Lte)
} else {
self.unread_char();

Token::Operator(OperatorToken::Lt)
}
}
'>' => {
// 다음 문자가 =일 경우 >= 연산자로 처리

self.read_char();

if self.last_char == '=' {
Token::Operator(OperatorToken::Gte)
} else {
self.unread_char();

Token::Operator(OperatorToken::Gt)
}
}
_ => {
return Err(LexingError::wrap(format!(
"unexpected operator: {:?}",
Expand Down
Loading