https://github.com/dzhibas/bool_expr_parser
Boolean expresion parser and evaluation function for feature flagging - flipper
https://github.com/dzhibas/bool_expr_parser
boolean-expression parser rust
Last synced: 3 months ago
JSON representation
Boolean expresion parser and evaluation function for feature flagging - flipper
- Host: GitHub
- URL: https://github.com/dzhibas/bool_expr_parser
- Owner: dzhibas
- Created: 2022-04-03T13:29:15.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-11-08T20:40:57.000Z (over 2 years ago)
- Last Synced: 2025-01-11T14:49:03.232Z (about 1 year ago)
- Topics: boolean-expression, parser, rust
- Language: Rust
- Homepage:
- Size: 82 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Bool Expr Parser lib
Boolean expresion parser and evaluation function for feature flagging - flipper
It parses expression and given input hashmap evaluates and returns true/false
Example of complex expression you can parse and evaluate:
```
(countryCode=NL or countryCode=DE)
AND uid in (121321,2312312,231231)
and role in (Admin, "Super admin")
and (
uid not in ( ca3ed35c-114f-488d-82b7-7c4d1bd5cbcd, b83f48af-ecb6-4b50-9d5e-b690db2a332b )
or uid <= 0
)
and !(street_name='Random street 1' and countryCode=NL)
```
given a input hashmap of
```
let map = HashMap::from([
("countryCode", "DE"),
("uid", "2312312"),
("role", "Super admin"),
("street_name", "Random street 2"),
]);
```
result would be `true`
```
assert_eq!(
eval(
BoolExprParser::parse(Rule::main, &expression)
.expect("Parse error"),
&map
),
true
);
```
Please see test in src/test.rs test_in_readme_documentation()