Skip to content

Commit

Permalink
[#148] parse_expression 서브쿼리 파싱 버그 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
myyrakle committed Aug 9, 2024
1 parent 88a47d5 commit ea8391a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/parser/implements/dml/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ impl Parser {
// from 없는 select절로 간주. 종료.
return Ok(query_builder.build());
}
Token::RightParentheses => {
// from 없는 select절로 간주. 종료.
self.unget_next_token(current_token);
return Ok(query_builder.build());
}
Token::Comma => continue,
Token::Operator(OperatorToken::Asterisk) => {
query_builder =
Expand Down Expand Up @@ -129,6 +134,10 @@ impl Parser {
Token::SemiColon => {
return Ok(query_builder.build());
}
Token::RightParentheses => {
self.unget_next_token(current_token);
return Ok(query_builder.build());
}
Token::Comma => continue,
Token::Having | Token::Limit | Token::Offset | Token::Order => {
self.unget_next_token(current_token);
Expand Down Expand Up @@ -219,6 +228,10 @@ impl Parser {
Token::SemiColon => {
return Ok(query_builder.build());
}
Token::RightParentheses => {
self.unget_next_token(current_token);
return Ok(query_builder.build());
}
Token::Comma => continue,
Token::Group | Token::Limit | Token::Offset => {
self.unget_next_token(current_token);
Expand Down Expand Up @@ -313,7 +326,7 @@ impl Parser {
// 현재 select_item은 종료된 것으로 판단.
Ok(select_item.build())
}
Token::SemiColon => {
Token::SemiColon | Token::RightParentheses => {
self.unget_next_token(current_token);
// 현재 select_item은 종료된 것으로 판단.
Ok(select_item.build())
Expand Down
29 changes: 29 additions & 0 deletions src/parser/test/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use crate::ast::dml::expressions::not_between::NotBetweenExpression;
use crate::ast::dml::expressions::operators::{BinaryOperator, UnaryOperator};
use crate::ast::dml::expressions::parentheses::ParenthesesExpression;
use crate::ast::dml::expressions::unary::UnaryOperatorExpression;
use crate::ast::dml::parts::select_item::SelectItem;
use crate::ast::dml::select::SelectQuery;
use crate::ast::types::{ConditionalFunction, SQLExpression, UserDefinedFunction};
use crate::lexer::predule::OperatorToken;
use crate::lexer::tokens::Token;
Expand Down Expand Up @@ -577,6 +579,33 @@ fn test_parse_expression() {
.into(),
want_error: false,
},
TestCase {
name: r#"(SELECT 1) + 10"#.into(),
input: vec![
Token::LeftParentheses,
Token::Select,
Token::Integer(1),
Token::RightParentheses,
Token::Operator(OperatorToken::Plus),
Token::Integer(10),
],
expected: BinaryOperatorExpression {
operator: BinaryOperator::Add,
lhs: SQLExpression::Subquery(
SelectQuery::builder()
.add_select_item(
SelectItem::builder()
.set_item(SQLExpression::Integer(1))
.build(),
)
.build()
.into(),
),
rhs: SQLExpression::Integer(10),
}
.into(),
want_error: false,
},
TestCase {
name: "오류: * 5".into(),
input: vec![Token::Operator(OperatorToken::Asterisk), Token::Integer(5)],
Expand Down

0 comments on commit ea8391a

Please sign in to comment.