Merge pull request #107 from benesch/prec

Fix precedence of unary NOT
This commit is contained in:
Nikhil Benesch 2019-06-06 17:26:00 -04:00 committed by GitHub
commit fc5e662b91
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions

View file

@ -580,11 +580,12 @@ impl Parser {
// The precedence of NOT varies depending on keyword that
// follows it. If it is followed by IN, BETWEEN, or LIKE,
// it takes on the precedence of those tokens. Otherwise it
// takes on UNARY_NOT_PREC.
// is not an infix operator, and therefore has zero
// precedence.
Some(Token::SQLWord(k)) if k.keyword == "IN" => Ok(Self::BETWEEN_PREC),
Some(Token::SQLWord(k)) if k.keyword == "BETWEEN" => Ok(Self::BETWEEN_PREC),
Some(Token::SQLWord(k)) if k.keyword == "LIKE" => Ok(Self::BETWEEN_PREC),
_ => Ok(Self::UNARY_NOT_PREC),
_ => Ok(0),
},
Token::SQLWord(k) if k.keyword == "IS" => Ok(17),
Token::SQLWord(k) if k.keyword == "IN" => Ok(Self::BETWEEN_PREC),

View file

@ -352,7 +352,7 @@ fn parse_not() {
fn parse_invalid_infix_not() {
let res = parse_sql_statements("SELECT c FROM t WHERE c NOT (");
assert_eq!(
ParserError::ParserError("Expected IN or BETWEEN after NOT, found: (".to_string()),
ParserError::ParserError("Expected end of statement, found: NOT".to_string()),
res.unwrap_err(),
);
}