MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / parse_predicate

Function parse_predicate

nodedb/src/control/security/predicate_parser.rs:23–34  ·  view source on GitHub ↗

Parse a predicate expression string into a compiled `RlsPredicate`. Grammar: ```text expr = or_expr or_expr = and_expr ("OR" and_expr) and_expr = atom ("AND" atom) atom = comparison | contains | intersects | "NOT" atom | "(" expr ")" comparison = field_ref op value_ref contains = value_ref "CONTAINS" value_ref intersects = value_ref "INTERSECTS" value_ref field_ref = identifier |

(input: &str)

Source from the content-addressed store, hash-verified

21/// value_ref = literal | field_ref
22/// ```
23pub fn parse_predicate(input: &str) -> Result<RlsPredicate, PredicateParseError> {
24 let tokens = tokenize(input)?;
25 let mut pos = 0;
26 let result = parse_or_expr(&tokens, &mut pos)?;
27 if pos < tokens.len() {
28 return Err(PredicateParseError::UnexpectedToken {
29 token: tokens[pos].clone(),
30 position: pos,
31 });
32 }
33 Ok(result)
34}
35
36/// Predicate parse errors.
37#[derive(Debug, Clone, thiserror::Error)]

Callers 10

parse_simple_equalityFunction · 0.85
parse_and_orFunction · 0.85
parse_parenthesizedFunction · 0.85
parse_containsFunction · 0.85
parse_intersectsFunction · 0.85
parse_notFunction · 0.85
compile_rls_predicateFunction · 0.85

Calls 4

parse_or_exprFunction · 0.85
tokenizeFunction · 0.70
lenMethod · 0.45
cloneMethod · 0.45

Tested by 9

parse_simple_equalityFunction · 0.68
parse_and_orFunction · 0.68
parse_parenthesizedFunction · 0.68
parse_containsFunction · 0.68
parse_intersectsFunction · 0.68
parse_notFunction · 0.68