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

Method parse_substring_expr

src/sql-parser/src/parser.rs:1496–1526  ·  view source on GitHub ↗

Parse calls to substring(), which can take the form: - substring('string', 'int') - substring('string', 'int', 'int') - substring('string' FROM 'int') - substring('string' FROM 'int' FOR 'int') - substring('string' FOR 'int')

(&mut self)

Source from the content-addressed store, hash-verified

1494 // - substring('string' FROM 'int' FOR 'int')
1495 // - substring('string' FOR 'int')
1496 fn parse_substring_expr(&mut self) -> Result<Expr<Raw>, ParserError> {
1497 self.expect_token(&Token::LParen)?;
1498 let mut exprs = vec![self.parse_expr()?];
1499 if self.parse_keyword(FROM) {
1500 // 'string' FROM 'int'
1501 exprs.push(self.parse_expr()?);
1502 if self.parse_keyword(FOR) {
1503 // 'string' FROM 'int' FOR 'int'
1504 exprs.push(self.parse_expr()?);
1505 }
1506 } else if self.parse_keyword(FOR) {
1507 // 'string' FOR 'int'
1508 exprs.push(Expr::Value(Value::Number(String::from("1"))));
1509 exprs.push(self.parse_expr()?);
1510 } else {
1511 // 'string', 'int'
1512 // or
1513 // 'string', 'int', 'int'
1514 self.expect_token(&Token::Comma)?;
1515 exprs.extend(self.parse_comma_separated(Parser::parse_expr)?);
1516 }
1517
1518 self.expect_token(&Token::RParen)?;
1519 Ok(Expr::Function(Function {
1520 name: RawItemName::Name(UnresolvedItemName::unqualified(ident!("substring"))),
1521 args: FunctionArgs::args(exprs),
1522 filter: None,
1523 over: None,
1524 distinct: false,
1525 }))
1526 }
1527
1528 /// Parse an operator reference.
1529 ///

Callers 1

parse_prefixMethod · 0.80

Calls 9

FunctionClass · 0.85
expect_tokenMethod · 0.80
parse_keywordMethod · 0.80
parse_exprMethod · 0.80
parse_comma_separatedMethod · 0.80
ValueEnum · 0.50
NameClass · 0.50
pushMethod · 0.45
extendMethod · 0.45

Tested by

no test coverage detected