From 05a70a358a20870554d9b71d82682d1c8e66f27b Mon Sep 17 00:00:00 2001 From: Nickolay Ponomarev Date: Sun, 3 Feb 2019 04:54:11 +0300 Subject: [PATCH] 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. --- src/sqlparser.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/sqlparser.rs b/src/sqlparser.rs index f2d616cc..fead1b31 100644 --- a/src/sqlparser.rs +++ b/src/sqlparser.rs @@ -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();