mirror of
https://github.com/ivabus/feval
synced 2024-12-05 05:05:07 +03:00
tasks.rs: add exit function
This commit is contained in:
parent
3288601040
commit
aa996ec3ef
2 changed files with 88 additions and 81 deletions
|
@ -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 |
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue