MCPcopy Create free account
hub / github.com/Pometry/Raphtory / parse_expr

Function parse_expr

raphtory-cypher/src/parser/mod.rs:285–340  ·  view source on GitHub ↗
(pairs: Pairs<Rule>)

Source from the content-addressed store, hash-verified

283}
284
285pub fn parse_expr(pairs: Pairs<Rule>) -> Result<Expr, ParseError> {
286 PRATT_PARSER
287 .map_primary(|primary| parse_primary(primary))
288 .map_infix(|lhs, op, rhs| {
289 let bin_op_type = match op.as_rule() {
290 Rule::add => BinOpType::Add,
291 Rule::subtract => BinOpType::Sub,
292 Rule::multiply => BinOpType::Mul,
293 Rule::divide => BinOpType::Div,
294 Rule::pow => BinOpType::Pow,
295 Rule::eq => BinOpType::Eq,
296 Rule::modulo => BinOpType::Mod,
297 Rule::lt => BinOpType::Lt,
298 Rule::lte => BinOpType::Lte,
299 Rule::gt => BinOpType::Gt,
300 Rule::gte => BinOpType::Gte,
301 Rule::ne => BinOpType::Neq,
302 Rule::and => BinOpType::And,
303 Rule::or => BinOpType::Or,
304 Rule::xor => BinOpType::Xor,
305 Rule::IN => BinOpType::In,
306 Rule::contains => BinOpType::Contains,
307 Rule::starts_with => BinOpType::StartsWith,
308 Rule::ends_with => BinOpType::EndsWith,
309 rule => return unsupported("parse_expr", &rule),
310 };
311
312 Ok(Expr::BinOp {
313 op: bin_op_type,
314 left: Box::new(lhs?),
315 right: Box::new(rhs?),
316 })
317 })
318 .map_prefix(|op, expr| match op.as_rule() {
319 Rule::not => Ok(Expr::UnaryOp {
320 op: UnaryOpType::Not,
321 expr: Box::new(expr?),
322 }),
323 Rule::minus => Ok(Expr::UnaryOp {
324 op: UnaryOpType::Neg,
325 expr: Box::new(expr?),
326 }),
327 rule => unsupported("parse_expr", &rule),
328 })
329 .map_postfix(|expr, op| match op.as_rule() {
330 Rule::is_null => {
331 if let Some(Rule::NOT) = op.into_inner().next().map(|op| op.as_rule()) {
332 Ok(Expr::is_not_null(expr?))
333 } else {
334 Ok(Expr::is_null(expr?))
335 }
336 }
337 rule => unsupported("parse_expr", &rule),
338 })
339 .parse(pairs)
340}
341
342pub fn parse_primary(pair: Pair<Rule>) -> Result<Expr, ParseError> {

Callers 14

parse_matchFunction · 0.85
parse_returnFunction · 0.85
parse_orderFunction · 0.85
parse_return_itemFunction · 0.85
parse_primaryFunction · 0.85
parse_atomFunction · 0.85
parse_funcion_invocationFunction · 0.85
parse_map_literalFunction · 0.85
parse_list_literalFunction · 0.85
check_property_exprFunction · 0.85
and_expressionFunction · 0.85

Calls 5

parse_primaryFunction · 0.85
unsupportedFunction · 0.85
mapMethod · 0.45
nextMethod · 0.45
into_innerMethod · 0.45

Tested by 5

check_property_exprFunction · 0.68
and_expressionFunction · 0.68
in_expressionFunction · 0.68
test_parse_bin_exprFunction · 0.68