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)
| 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 | /// |
no test coverage detected