tasks.rs: add exit function

This commit is contained in:
Ivan Bushchik 2023-02-03 15:45:34 +03:00
parent 3288601040
commit aa996ec3ef
No known key found for this signature in database
GPG key ID: 9F6DDABE11A2674D
2 changed files with 88 additions and 81 deletions

View file

@ -15,7 +15,7 @@ cargo install feval
Supported binary operators:
| Operator | Precedence | Description |
|----------|------------|-------------|
|---------------|------------|--------------------------------------------------------------------|
| ^ | 120 | Exponentiation |
| * | 100 | Product |
| / | 100 | Division (integer if both arguments are integers, otherwise float) |
@ -52,7 +52,7 @@ Supported unary operators:
## Functions
| Identifier | Argument Amount | Argument Types | Description |
|----------------------|-----------------|------------------------|-------------|
|---------------------|-----------------|-------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `min` | >= 1 | Numeric | Returns the minimum of the arguments |
| `max` | >= 1 | Numeric | Returns the maximum of the arguments |
| `len` | 1 | String/Tuple | Returns the character length of a string, or the amount of elements in a tuple (not recursively) |
@ -98,10 +98,11 @@ Supported unary operators:
| `bitnot` | 1 | Int | Computes the bitwise not of the given integer |
| `shl` | 2 | Int | Computes the given integer bitwise shifted left by the other given integer |
| `shr` | 2 | Int | Computes the given integer bitwise shifted right by the other given integer |
| `exit` | 0 | None | Exits |
## Constants
| Identifier | Value | Description |
|------------|-------|-------------|
|------------|--------------------------------------------|----------------|
| `math::pi` | 3.141592653589793 (`std::f64::consts::PI`) | Pi |
| `math::e` | 2.718281828459045 (`std::f64::consts::E`) | Euler's number |

View file

@ -2,9 +2,15 @@ pub mod tasks {
use std::f64::consts;
pub fn all(expr: String) -> String {
convert_constants(expr)
convert_constants(exit(expr))
}
fn convert_constants(expr: String) -> String {
expr.replace("math::pi", &consts::PI.to_string()).replace("math::e", &consts::E.to_string())
}
fn exit(expr: String) -> String {
if expr.contains("exit") {
std::process::exit(0);
}
expr
}
}