Skip to content

Commit

Permalink
[#148] parse_expression between 파싱 버그 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
myyrakle committed Aug 9, 2024
1 parent ea8391a commit 6dd2813
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/parser/implements/dml/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl Parser {
context: ParserContext,
) -> Result<SQLExpression, RRDBError> {
if !self.has_next_token() {
return Err(ParsingError::wrap("E0201 need more tokens"));
return Err(ParsingError::wrap("E0216 need more tokens"));
}

let current_token = self.get_next_token();
Expand Down Expand Up @@ -493,7 +493,9 @@ impl Parser {
a: SQLExpression,
context: ParserContext,
) -> Result<SQLExpression, RRDBError> {
let context = context.set_in_between_clause(true);
let context = context
.set_in_between_clause(true)
.set_in_parentheses(false);

if !self.has_next_token() {
return Err(ParsingError::wrap("E0210 need more tokens"));
Expand Down
51 changes: 51 additions & 0 deletions src/parser/test/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,28 @@ fn test_parse_expression() {
.into(),
want_error: false,
},
TestCase {
name: "(3 between 1 and 5)".into(),
input: vec![
Token::LeftParentheses,
Token::Integer(3),
Token::Between,
Token::Integer(1),
Token::And,
Token::Integer(5),
Token::RightParentheses,
],
expected: ParenthesesExpression {
expression: BetweenExpression {
a: SQLExpression::Integer(3),
x: SQLExpression::Integer(1),
y: SQLExpression::Integer(5),
}
.into(),
}
.into(),
want_error: false,
},
TestCase {
name: "3.0 between 1.2 and 5.3".into(),
input: vec![
Expand Down Expand Up @@ -606,6 +628,35 @@ fn test_parse_expression() {
.into(),
want_error: false,
},
TestCase {
name: r#"(SELECT 1) BETWEEN 0 AND 5"#.into(),
input: vec![
Token::LeftParentheses,
Token::Select,
Token::Integer(1),
Token::RightParentheses,
Token::Between,
Token::Integer(0),
Token::And,
Token::Integer(5),
],
expected: BetweenExpression {
a: SQLExpression::Subquery(
SelectQuery::builder()
.add_select_item(
SelectItem::builder()
.set_item(SQLExpression::Integer(1))
.build(),
)
.build()
.into(),
),
x: SQLExpression::Integer(0),
y: SQLExpression::Integer(5),
}
.into(),
want_error: false,
},
TestCase {
name: "오류: * 5".into(),
input: vec![Token::Operator(OperatorToken::Asterisk), Token::Integer(5)],
Expand Down

0 comments on commit 6dd2813

Please sign in to comment.