Skip to content

Commit

Permalink
Merge pull request #157 from myyrakle/feat/#155
Browse files Browse the repository at this point in the history
[#155] !=, <=, >= 연산자 등 토큰화 구현
  • Loading branch information
myyrakle authored Aug 18, 2024
2 parents fde8061 + 73c012e commit 5a1f765
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 3 deletions.
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

0 comments on commit 5a1f765

Please sign in to comment.