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

Method parse_like

src/sql-parser/src/parser.rs:1643–1671  ·  view source on GitHub ↗

Parses `LIKE [ ESCAPE ]`, assuming the `LIKE` keyword was already consumed

(
        &mut self,
        expr: Expr<Raw>,
        case_insensitive: bool,
        negated: bool,
    )

Source from the content-addressed store, hash-verified

1641
1642 /// Parses `LIKE <pattern> [ ESCAPE <char> ]`, assuming the `LIKE` keyword was already consumed
1643 fn parse_like(
1644 &mut self,
1645 expr: Expr<Raw>,
1646 case_insensitive: bool,
1647 negated: bool,
1648 ) -> Result<Expr<Raw>, ParserError> {
1649 if let Some(kw) = self.parse_one_of_keywords(ANY_ALL_KEYWORDS) {
1650 let op = match (case_insensitive, negated) {
1651 (false, false) => "~~",
1652 (false, true) => "!~~",
1653 (true, false) => "~~*",
1654 (true, true) => "!~~*",
1655 };
1656 return self.parse_any_all(expr, Op::bare(op), kw);
1657 }
1658 let pattern = self.parse_subexpr(Precedence::Like)?;
1659 let escape = if self.parse_keyword(ESCAPE) {
1660 Some(Box::new(self.parse_subexpr(Precedence::Like)?))
1661 } else {
1662 None
1663 };
1664 Ok(Expr::Like {
1665 expr: Box::new(expr),
1666 pattern: Box::new(pattern),
1667 escape,
1668 case_insensitive,
1669 negated,
1670 })
1671 }
1672
1673 /// Parse a postgresql casting style which is in the form of `expr::datatype`
1674 fn parse_pg_cast(&mut self, expr: Expr<Raw>) -> Result<Expr<Raw>, ParserError> {

Callers 1

parse_infixMethod · 0.80

Calls 4

parse_one_of_keywordsMethod · 0.80
parse_any_allMethod · 0.80
parse_subexprMethod · 0.80
parse_keywordMethod · 0.80

Tested by

no test coverage detected