mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-01 03:37:21 +00:00
Assert when an unknown keyword was passed to parse_keyword()
This happens all the time when I forget to check that the keyword I wanted to use is actually listed in keywords.rs, this should help with debugging.
This commit is contained in:
parent
6b107065ac
commit
05a70a358a
1 changed files with 5 additions and 0 deletions
|
@ -473,6 +473,11 @@ impl Parser {
|
|||
/// Look for an expected keyword and consume it if it exists
|
||||
#[must_use]
|
||||
pub fn parse_keyword(&mut self, expected: &'static str) -> bool {
|
||||
// Ideally, we'd accept a enum variant, not a string, but since
|
||||
// it's not trivial to maintain the enum without duplicating all
|
||||
// the keywords three times, we'll settle for a run-time check that
|
||||
// the string actually represents a known keyword...
|
||||
assert!(keywords::ALL_KEYWORDS.contains(&expected));
|
||||
match self.peek_token() {
|
||||
Some(Token::SQLWord(ref k)) if expected.eq_ignore_ascii_case(&k.keyword) => {
|
||||
self.next_token();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue