mirror of
https://github.com/PaddiM8/kalker.git
synced 2025-06-26 20:52:29 +02:00
Fixed merge issues, updated version numbers, and updated README with syntax instructions.
This commit is contained in:
parent
b966658fa7
commit
2c3f70e3f2
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -138,7 +138,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "kalk"
|
name = "kalk"
|
||||||
version = "0.1.11"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"phf",
|
"phf",
|
||||||
@ -149,7 +149,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "kalk_cli"
|
name = "kalk_cli"
|
||||||
version = "0.1.10"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ansi_term",
|
"ansi_term",
|
||||||
"kalk",
|
"kalk",
|
||||||
|
30
README.md
30
README.md
@ -5,7 +5,7 @@
|
|||||||

|

|
||||||
|
|
||||||
|
|
||||||
Kalk is a calculator (both program and library) that supports user-defined variables and functions.
|
Kalk is a calculator (both program and library) that supports user-defined variables, functions, and units (experimental).
|
||||||
[Project kanban board (Kolan)](https://kolan.smrk.me/Board/4RAdMjLDz)
|
[Project kanban board (Kolan)](https://kolan.smrk.me/Board/4RAdMjLDz)
|
||||||
|
|
||||||

|

|
||||||
@ -15,6 +15,7 @@ Kalk is a calculator (both program and library) that supports user-defined varia
|
|||||||
* Groups: (), ⌈⌉, ⌋⌊
|
* Groups: (), ⌈⌉, ⌋⌊
|
||||||
* [Pre-defined functions and constants](https://github.com/PaddiM8/kalk/blob/master/kalk/src/prelude.rs)
|
* [Pre-defined functions and constants](https://github.com/PaddiM8/kalk/blob/master/kalk/src/prelude.rs)
|
||||||
* User-defined functions and variables. `f(x, y) = xy`, `x = 5`
|
* User-defined functions and variables. `f(x, y) = xy`, `x = 5`
|
||||||
|
* User-defined units (experimental). `unit m = cm/100`, `2m/50cm`, `50cm to m`
|
||||||
* Understands fairly ambiguous syntax. Eg. `2sin50 + 2xy`
|
* Understands fairly ambiguous syntax. Eg. `2sin50 + 2xy`
|
||||||
* Syntax highlighting
|
* Syntax highlighting
|
||||||
* Special-symbol completion on tab. Eg. write `sqrt` and press tab. It will be turned into `√`.
|
* Special-symbol completion on tab. Eg. write `sqrt` and press tab. It will be turned into `√`.
|
||||||
@ -33,3 +34,30 @@ Run `cargo install kalk_cli`
|
|||||||
1. Go into the `kalk_cli` directory.
|
1. Go into the `kalk_cli` directory.
|
||||||
2. Run `cargo build --release`
|
2. Run `cargo build --release`
|
||||||
3. Grab the binary from `targets/release`
|
3. Grab the binary from `targets/release`
|
||||||
|
|
||||||
|
## Syntax
|
||||||
|
|
||||||
|
### Functions
|
||||||
|
__Defining:__ name(parameter1, parameter2, ...) = expression
|
||||||
|
**Example:** `f(x) = 2x+3`
|
||||||
|
|
||||||
|
__Using:__ name(argument1, argument2)
|
||||||
|
**Example:** `f(2)`
|
||||||
|
|
||||||
|
### Variables
|
||||||
|
__Defining:__ name = expression
|
||||||
|
**Example:** `x = 3`
|
||||||
|
|
||||||
|
__Using:__ name
|
||||||
|
**Example:** `x`
|
||||||
|
|
||||||
|
### Units
|
||||||
|
*Note: You only need to define the relationship between two units once. You will be able to convert between both of them.*
|
||||||
|
__Defining:__ `unit` name = expression
|
||||||
|
**Example:** `unit deg = (rad*180)/π`
|
||||||
|
|
||||||
|
__Using:__ Use them freely in expressions.
|
||||||
|
**Example:** `2m/50cm`
|
||||||
|
|
||||||
|
__Converting:__ expression `to` unit
|
||||||
|
**Example:** `2 m to cm`
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "kalk"
|
name = "kalk"
|
||||||
version = "0.1.11"
|
version = "0.2.0"
|
||||||
authors = ["PaddiM8"]
|
authors = ["PaddiM8"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
description = "A math evaluator library that supports user-defined functions and variables and can handle fairly ambiguous syntax."
|
description = "A math evaluator library that supports user-defined functions, variables and units, and can handle fairly ambiguous syntax."
|
||||||
repository = "https://github.com/PaddiM8/kalk/tree/master/kalk"
|
repository = "https://github.com/PaddiM8/kalk/tree/master/kalk"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
keywords = ["math", "calculator", "evaluator"]
|
keywords = ["math", "calculator", "evaluator"]
|
||||||
|
@ -27,20 +27,27 @@ impl<'a> Context<'a> {
|
|||||||
statements: Vec<Stmt>,
|
statements: Vec<Stmt>,
|
||||||
) -> Result<Option<(Float, String)>, CalcError> {
|
) -> Result<Option<(Float, String)>, CalcError> {
|
||||||
for (i, stmt) in statements.iter().enumerate() {
|
for (i, stmt) in statements.iter().enumerate() {
|
||||||
let value = eval_stmt(self, stmt);
|
let (value, unit) = eval_stmt(self, stmt)?;
|
||||||
|
|
||||||
// Insert the last value into the `ans` variable.
|
// Insert the last value into the `ans` variable.
|
||||||
self.symbol_table.set(
|
self.symbol_table.set(if (&unit).len() > 0 {
|
||||||
"ans",
|
|
||||||
Stmt::VarDecl(
|
Stmt::VarDecl(
|
||||||
String::from("ans"),
|
String::from("ans"),
|
||||||
Box::new(Expr::Literal(value.clone()?.to_string())),
|
Box::new(Expr::Unit(
|
||||||
),
|
unit.clone(),
|
||||||
);
|
Box::new(Expr::Literal(value.clone().to_string())),
|
||||||
|
)),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
Stmt::VarDecl(
|
||||||
|
String::from("ans"),
|
||||||
|
Box::new(Expr::Literal(value.clone().to_string())),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
if i == statements.len() - 1 {
|
if i == statements.len() - 1 {
|
||||||
if let Stmt::Expr(_) = stmt {
|
if let Stmt::Expr(_) = stmt {
|
||||||
return Ok(Some(value?));
|
return Ok(Some((value, unit)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "kalk_cli"
|
name = "kalk_cli"
|
||||||
version = "0.1.10"
|
version = "0.2.0"
|
||||||
authors = ["PaddiM8"]
|
authors = ["PaddiM8"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
readme = "../README.md"
|
readme = "../README.md"
|
||||||
description = "A calculator that supports user-defined functions and variables and can handle fairly ambiguous syntax."
|
description = "A calculator that supports user-defined functions, variables and units, and can handle fairly ambiguous syntax."
|
||||||
repository = "https://github.com/PaddiM8/kalk"
|
repository = "https://github.com/PaddiM8/kalk"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
keywords = ["math", "calculator", "cli", "command-line"]
|
keywords = ["math", "calculator", "cli", "command-line"]
|
||||||
@ -15,7 +15,7 @@ path = "src/main.rs"
|
|||||||
name = "kalk"
|
name = "kalk"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
kalk = { path = "../kalk", version = "^0.1.11" }
|
kalk = { path = "../kalk", version = "^0.2.0" }
|
||||||
rustyline = "6.1.2"
|
rustyline = "6.1.2"
|
||||||
ansi_term = "0.12"
|
ansi_term = "0.12"
|
||||||
regex = "1"
|
regex = "1"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user