MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / parse_expr

Function parse_expr

crates/sql-parser/src/parser/mod.rs:219–272  ·  view source on GitHub ↗

Parse a scalar expression

(expr: Expr, depth: usize)

Source from the content-addressed store, hash-verified

217
218/// Parse a scalar expression
219fn 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 &param == ":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
274fn parse_signed_literal_expr(
275 op: UnaryOperator,

Callers 2

parse_joinMethod · 0.85
parse_expr_optFunction · 0.85

Calls 10

guardFunction · 0.85
parse_literalFunction · 0.85
parse_binopFunction · 0.85
ExprEnum · 0.85
OkFunction · 0.50
LogClass · 0.50
newFunction · 0.50
ErrFunction · 0.50
lenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…