Parse a scalar expression
(expr: Expr, depth: usize)
| 217 | |
| 218 | /// Parse a scalar expression |
| 219 | fn parse_expr(expr: Expr, depth: usize) -> SqlParseResult<SqlExpr> { |
| 220 | recursion::guard(depth, recursion::MAX_RECURSION_EXPR, "sql-parser::parse_expr")?; |
| 221 | match expr { |
| 222 | Expr::Nested(expr) => parse_expr(*expr, depth + 1), |
| 223 | Expr::Value(Value::Placeholder(param)) if ¶m == ":sender" => Ok(SqlExpr::Param(Parameter::Sender)), |
| 224 | Expr::Value(v) => Ok(SqlExpr::Lit(parse_literal(v)?)), |
| 225 | Expr::UnaryOp { |
| 226 | op: UnaryOperator::Plus, |
| 227 | expr, |
| 228 | } => Ok(SqlExpr::Lit(parse_signed_literal_expr( |
| 229 | UnaryOperator::Plus, |
| 230 | *expr, |
| 231 | SqlUnsupported::Expr, |
| 232 | )?)), |
| 233 | Expr::UnaryOp { |
| 234 | op: UnaryOperator::Minus, |
| 235 | expr, |
| 236 | } => Ok(SqlExpr::Lit(parse_signed_literal_expr( |
| 237 | UnaryOperator::Minus, |
| 238 | *expr, |
| 239 | SqlUnsupported::Expr, |
| 240 | )?)), |
| 241 | Expr::Identifier(ident) => Ok(SqlExpr::Var(ident.into())), |
| 242 | Expr::CompoundIdentifier(mut idents) if idents.len() == 2 => { |
| 243 | let table = idents.swap_remove(0).into(); |
| 244 | let field = idents.swap_remove(0).into(); |
| 245 | Ok(SqlExpr::Field(table, field)) |
| 246 | } |
| 247 | Expr::BinaryOp { |
| 248 | left, |
| 249 | op: BinaryOperator::And, |
| 250 | right, |
| 251 | } => { |
| 252 | let l = parse_expr(*left, depth + 1)?; |
| 253 | let r = parse_expr(*right, depth + 1)?; |
| 254 | Ok(SqlExpr::Log(Box::new(l), Box::new(r), LogOp::And)) |
| 255 | } |
| 256 | Expr::BinaryOp { |
| 257 | left, |
| 258 | op: BinaryOperator::Or, |
| 259 | right, |
| 260 | } => { |
| 261 | let l = parse_expr(*left, depth + 1)?; |
| 262 | let r = parse_expr(*right, depth + 1)?; |
| 263 | Ok(SqlExpr::Log(Box::new(l), Box::new(r), LogOp::Or)) |
| 264 | } |
| 265 | Expr::BinaryOp { left, op, right } => { |
| 266 | let l = parse_expr(*left, depth + 1)?; |
| 267 | let r = parse_expr(*right, depth + 1)?; |
| 268 | Ok(SqlExpr::Bin(Box::new(l), Box::new(r), parse_binop(op)?)) |
| 269 | } |
| 270 | _ => Err(SqlUnsupported::Expr(expr).into()), |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | fn parse_signed_literal_expr( |
| 275 | op: UnaryOperator, |
no test coverage detected
searching dependent graphs…