Skip to content

Commit ecf0834

Browse files
committed
feat: update README
1 parent 064d843 commit ecf0834

4 files changed

Lines changed: 64 additions & 3 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "expression_engine"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
edition = "2021"
55
description = "An expression engine written in pure rust"
66
license = "Apache-2.0"

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,41 @@ Rhs:
114114
115115
```
116116

117-
A binary expression contains two operands separated by an operator. All the binary operators have right-to-left associativity while their precedences may be not the same.
117+
A binary expression contains two operands separated by an operator. All the binary operators have right-to-left associativity while their precedences may be not the same. The supported binary operators are as below:
118+
119+
| Operator | Precedence | Desc |
120+
| --------- | ---------- | ---- |
121+
| \|= | 20 | |
122+
| <<= | 20 | |
123+
| = | 20 | |
124+
| += | 20 | |
125+
| ^= | 20 | |
126+
| /= | 20 | |
127+
| &= | 20 | |
128+
| >>= | 20 | |
129+
| %= | 20 | |
130+
| -= | 20 | |
131+
| *= | 20 | |
132+
| \|\| | 40 | |
133+
| && | 50 | |
134+
| > | 60 | |
135+
| >= | 60 | |
136+
| <= | 60 | |
137+
| != | 60 | |
138+
| < | 60 | |
139+
| == | 60 | |
140+
| \| | 70 | |
141+
| ^ | 80 | |
142+
| & | 90 | |
143+
| >> | 100 | |
144+
| << | 100 | |
145+
| + | 110 | |
146+
| - | 110 | |
147+
| * | 120 | |
148+
| % | 120 | |
149+
| / | 120 | |
150+
| beginWith | 200 | |
151+
| endWith | 200 | |
118152

119153
### TernaryExpression
120154

src/lib.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
//! Expression engine is a library written in pure Rust which provides an engine to compile and execute expressions.
2+
//! An expression indicates a string-like sentence that can be executed with some contexts and return a value (mostly, but not limited to, boolean, string and number).
3+
//! Expression engine aims to provide an engine for users that can execute complex logics using configurations without recompiling.
4+
//! It's a proper alternative as the basis to build business rule engines.
5+
//! ## Features
6+
7+
//! + Easy to Use (three lines at least)
8+
//! + Abundant Types and Expressions (Five fundamental types and seven kinds of expressions)
9+
//! + Pre-defined Operators Support (Common boolean, numeric and string operators)
10+
//! + Support function and operators registration
11+
//! + Support operator redirection
112
mod ast;
213
mod define;
314
mod error;
@@ -11,6 +22,22 @@ mod tokenizer;
1122
mod value;
1223
mod context;
1324

25+
/// ## Usage
26+
///
27+
/// Calling the engine is simple. At first, define the expression you want to execute. Secondly, create a context to cache the pre-defined inner functions and variables. And then, register the variables and functions to the context. Finally, call the execute function with the expression and context to get the executing result.
28+
///
29+
/// ``` rust
30+
/// use expression_engine::Value;
31+
/// use expression_engine::Context;
32+
/// use expression_engine::execute;
33+
/// let input = "(3+4)*5+mm*2";
34+
/// let mut ctx = Context::new();
35+
/// ctx.set_variable("mm", Value::from(2));
36+
/// match execute(input, ctx) {
37+
/// Err(e) => println!("{}", e),
38+
/// Ok(param) => println!("ans is {}", param),
39+
/// };
40+
/// ```
1441
pub fn execute(expr: &str, mut ctx: context::Context) -> define::Result<value::Value> {
1542
ast::AST::new(expr)?
1643
.parse_chain_expression()?

0 commit comments

Comments
 (0)