-
Notifications
You must be signed in to change notification settings - Fork 0
19927: fix: change token consumption to pick to test on EOF in parser #202
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -658,7 +658,7 @@ impl<'a> DFParser<'a> { | |||||
| } | ||||||
| } | ||||||
| } else { | ||||||
| let token = self.parser.next_token(); | ||||||
| let token = self.parser.peek_token(); | ||||||
| if token == Token::EOF || token == Token::SemiColon { | ||||||
| break; | ||||||
| } else { | ||||||
|
|
@@ -1079,7 +1079,7 @@ impl<'a> DFParser<'a> { | |||||
| } | ||||||
| } | ||||||
| } else { | ||||||
| let token = self.parser.next_token(); | ||||||
| let token = self.parser.peek_token(); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change from
Suggested change
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. value:annoying; category:bug; feedback:The Gemini AI reviewer is not correct to suggest this code change because it will lose the indentation and the code will be harder to read. And most probably |
||||||
| if token == Token::EOF || token == Token::SemiColon { | ||||||
| break; | ||||||
| } else { | ||||||
|
|
@@ -2026,6 +2026,48 @@ mod tests { | |||||
| ); | ||||||
| } | ||||||
|
|
||||||
| #[test] | ||||||
| fn test_multistatement() { | ||||||
| let sql = "COPY foo TO bar STORED AS CSV; \ | ||||||
| CREATE EXTERNAL TABLE t(c1 int) STORED AS CSV LOCATION 'foo.csv'; \ | ||||||
| RESET var;"; | ||||||
| let statements = DFParser::parse_sql(sql).unwrap(); | ||||||
| assert_eq!( | ||||||
| statements, | ||||||
| vec![ | ||||||
| Statement::CopyTo(CopyToStatement { | ||||||
| source: object_name("foo"), | ||||||
| target: "bar".to_string(), | ||||||
| partitioned_by: vec![], | ||||||
| stored_as: Some("CSV".to_owned()), | ||||||
| options: vec![], | ||||||
| }), | ||||||
| { | ||||||
| let name = ObjectName::from(vec![Ident::from("t")]); | ||||||
| let display = None; | ||||||
| Statement::CreateExternalTable(CreateExternalTable { | ||||||
| name: name.clone(), | ||||||
| columns: vec![make_column_def("c1", DataType::Int(display))], | ||||||
| file_type: "CSV".to_string(), | ||||||
| location: "foo.csv".into(), | ||||||
| table_partition_cols: vec![], | ||||||
| order_exprs: vec![], | ||||||
| if_not_exists: false, | ||||||
| or_replace: false, | ||||||
| temporary: false, | ||||||
| unbounded: false, | ||||||
| options: vec![], | ||||||
| constraints: vec![], | ||||||
| }) | ||||||
| }, | ||||||
| { | ||||||
| let name = ObjectName::from(vec![Ident::from("var")]); | ||||||
| Statement::Reset(ResetStatement::Variable(name)) | ||||||
| } | ||||||
| ] | ||||||
| ); | ||||||
| } | ||||||
|
Comment on lines
+2030
to
+2069
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The addition of |
||||||
|
|
||||||
| fn expect_parse_expr_ok(sql: &str, expected: ExprWithAlias) { | ||||||
| let expr = DFParser::parse_sql_into_expr(sql).unwrap(); | ||||||
| assert_eq!(expr, expected, "actual:\n{expr:#?}"); | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing
next_token()topeek_token()here is a crucial correctness fix. The original implementation would consume the token regardless of whether it wasEOForSemiColon, potentially leading to incorrect parsing or error messages if the token was not one of those.peek_token()allows for inspection without consumption, which is the correct approach in this control flow.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value:annoying; category:bug; feedback:The Gemini AI reviewer is not correct to suggest this code change because it will lose the indentation and the code will be harder to read. And most probably
cargo fmt --checkwill complain about it.