MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / get_next_precedence

Method get_next_precedence

src/sql-parser/src/parser.rs:1682–1722  ·  view source on GitHub ↗

Get the precedence of the next token

(&self)

Source from the content-addressed store, hash-verified

1680
1681 /// Get the precedence of the next token
1682 fn get_next_precedence(&self) -> Precedence {
1683 if let Some(token) = self.peek_token() {
1684 match &token {
1685 Token::Keyword(OR) => Precedence::Or,
1686 Token::Keyword(AND) => Precedence::And,
1687 Token::Keyword(NOT) => match &self.peek_nth_token(1) {
1688 // The precedence of NOT varies depending on keyword that
1689 // follows it. If it is followed by IN, BETWEEN, or LIKE,
1690 // it takes on the precedence of those tokens. Otherwise it
1691 // is not an infix operator, and therefore has zero
1692 // precedence.
1693 Some(Token::Keyword(IN)) => Precedence::Like,
1694 Some(Token::Keyword(BETWEEN)) => Precedence::Like,
1695 Some(Token::Keyword(ILIKE)) => Precedence::Like,
1696 Some(Token::Keyword(LIKE)) => Precedence::Like,
1697 _ => Precedence::Zero,
1698 },
1699 Token::Keyword(IS) | Token::Keyword(ISNULL) => Precedence::Is,
1700 Token::Keyword(IN) => Precedence::Like,
1701 Token::Keyword(BETWEEN) => Precedence::Like,
1702 Token::Keyword(ILIKE) => Precedence::Like,
1703 Token::Keyword(LIKE) => Precedence::Like,
1704 Token::Keyword(OPERATOR) => Precedence::Other,
1705 Token::Op(s) => match s.as_str() {
1706 "<" | "<=" | "<>" | "!=" | ">" | ">=" => Precedence::Cmp,
1707 "+" | "-" => Precedence::PlusMinus,
1708 "/" | "%" => Precedence::MultiplyDivide,
1709 _ => Precedence::Other,
1710 },
1711 Token::Eq => Precedence::Cmp,
1712 Token::Star => Precedence::MultiplyDivide,
1713 Token::Keyword(COLLATE) | Token::Keyword(AT) => Precedence::PostfixCollateAt,
1714 Token::DoubleColon | Token::LBracket | Token::Dot => {
1715 Precedence::PostfixSubscriptCast
1716 }
1717 _ => Precedence::Zero,
1718 }
1719 } else {
1720 Precedence::Zero
1721 }
1722 }
1723
1724 /// Return the first non-whitespace token that has not yet been processed
1725 /// (or None if reached end-of-file)

Callers 1

parse_subexpr_seededMethod · 0.80

Calls 3

peek_tokenMethod · 0.80
peek_nth_tokenMethod · 0.80
as_strMethod · 0.45

Tested by

no test coverage detected