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:
Nickolay Ponomarev 2019-02-03 04:54:11 +03:00
parent 6b107065ac
commit 05a70a358a

View file

@ -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();