-
Notifications
You must be signed in to change notification settings - Fork 631
Fix placeholder spans #1979
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
Merged
+42
−6
Merged
Fix placeholder spans #1979
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9584,16 +9584,21 @@ impl<'a> Parser<'a> { | |
Token::HexStringLiteral(ref s) => ok_value(Value::HexStringLiteral(s.to_string())), | ||
Token::Placeholder(ref s) => ok_value(Value::Placeholder(s.to_string())), | ||
tok @ Token::Colon | tok @ Token::AtSign => { | ||
// Not calling self.parse_identifier(false)? because only in placeholder we want to check numbers as idfentifies | ||
// This because snowflake allows numbers as placeholders | ||
let next_token = self.next_token(); | ||
// 1. Not calling self.parse_identifier(false)? | ||
// because only in placeholder we want to check | ||
// numbers as idfentifies. This because snowflake | ||
// allows numbers as placeholders | ||
// 2. Not calling self.next_token() to enforce `tok` | ||
// be followed immediately by a word/number, ie. | ||
// without any whitespace in between | ||
let next_token = self.next_token_no_skip().unwrap_or(&EOF_TOKEN).clone(); | ||
let ident = match next_token.token { | ||
Token::Word(w) => Ok(w.into_ident(next_token.span)), | ||
Token::Number(w, false) => Ok(Ident::new(w)), | ||
Token::Number(w, false) => Ok(Ident::with_span(next_token.span, w)), | ||
_ => self.expected("placeholder", next_token), | ||
}?; | ||
let placeholder = tok.to_string() + &ident.value; | ||
ok_value(Value::Placeholder(placeholder)) | ||
Ok(Value::Placeholder(tok.to_string() + &ident.value) | ||
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. Can we add a test case for this to avoid future regressions? we have some span test cases here that we could add to |
||
.with_span(Span::new(span.start, ident.span.end))) | ||
} | ||
unexpected => self.expected( | ||
"a value", | ||
|
@@ -17494,4 +17499,12 @@ mod tests { | |
canonical, | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_placeholder_invalid_whitespace() { | ||
for w in [" ", "/*invalid*/"] { | ||
let sql = format!("\nSELECT\n :{w}fooBar"); | ||
assert!(Parser::parse_sql(&GenericDialect, &sql).is_err()); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
If I understand the intent correctly is this saying that e.g.
SELECT :foo
is to be parsed as a placeholder butSELECT : foo
should not? If so I think it would be good to mention that in a comment. Also can we add a test case to demonstrate this change?