Skip to content

Commit

Permalink
feat: update README
Browse files Browse the repository at this point in the history
  • Loading branch information
ashyanSpada committed Mar 23, 2023
1 parent 064d843 commit ecf0834
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "expression_engine"
version = "0.2.0"
version = "0.3.0"
edition = "2021"
description = "An expression engine written in pure rust"
license = "Apache-2.0"
Expand Down
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,41 @@ Rhs:
```

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.
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:

| Operator | Precedence | Desc |
| --------- | ---------- | ---- |
| \|= | 20 | |
| <<= | 20 | |
| = | 20 | |
| += | 20 | |
| ^= | 20 | |
| /= | 20 | |
| &= | 20 | |
| >>= | 20 | |
| %= | 20 | |
| -= | 20 | |
| *= | 20 | |
| \|\| | 40 | |
| && | 50 | |
| > | 60 | |
| >= | 60 | |
| <= | 60 | |
| != | 60 | |
| < | 60 | |
| == | 60 | |
| \| | 70 | |
| ^ | 80 | |
| & | 90 | |
| >> | 100 | |
| << | 100 | |
| + | 110 | |
| - | 110 | |
| * | 120 | |
| % | 120 | |
| / | 120 | |
| beginWith | 200 | |
| endWith | 200 | |

### TernaryExpression

Expand Down
27 changes: 27 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
//! Expression engine is a library written in pure Rust which provides an engine to compile and execute expressions.
//! 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).
//! Expression engine aims to provide an engine for users that can execute complex logics using configurations without recompiling.
//! It's a proper alternative as the basis to build business rule engines.
//! ## Features
//! + Easy to Use (three lines at least)
//! + Abundant Types and Expressions (Five fundamental types and seven kinds of expressions)
//! + Pre-defined Operators Support (Common boolean, numeric and string operators)
//! + Support function and operators registration
//! + Support operator redirection
mod ast;
mod define;
mod error;
Expand All @@ -11,6 +22,22 @@ mod tokenizer;
mod value;
mod context;

/// ## Usage
///
/// 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.
///
/// ``` rust
/// use expression_engine::Value;
/// use expression_engine::Context;
/// use expression_engine::execute;
/// let input = "(3+4)*5+mm*2";
/// let mut ctx = Context::new();
/// ctx.set_variable("mm", Value::from(2));
/// match execute(input, ctx) {
/// Err(e) => println!("{}", e),
/// Ok(param) => println!("ans is {}", param),
/// };
/// ```
pub fn execute(expr: &str, mut ctx: context::Context) -> define::Result<value::Value> {
ast::AST::new(expr)?
.parse_chain_expression()?
Expand Down

0 comments on commit ecf0834

Please sign in to comment.