This commit is contained in:
PaddiM8 2021-10-01 09:21:11 +02:00 committed by PaddiM8
parent 6d3065a3e0
commit 1b0496ea67
7 changed files with 22 additions and 34 deletions

View File

@ -9,11 +9,11 @@ license = "MIT"
name = "kalker" name = "kalker"
readme = "../README.md" readme = "../README.md"
repository = "https://github.com/PaddiM8/kalker" repository = "https://github.com/PaddiM8/kalker"
version = "1.0.0" version = "1.0.1"
[dependencies] [dependencies]
ansi_term = "0.12.1" ansi_term = "0.12.1"
kalk = { path = "../kalk", version = "^2.1.0" } kalk = { path = "../kalk", version = "^2.1.2" }
lazy_static = "1.4.0" lazy_static = "1.4.0"
regex = "1" regex = "1"
rustyline = "7.1.0" rustyline = "7.1.0"

View File

@ -1,6 +1,6 @@
[package] [package]
name = "kalk" name = "kalk"
version = "2.1.1" version = "2.1.2"
authors = ["PaddiM8"] authors = ["PaddiM8"]
edition = "2018" edition = "2018"
readme = "README.md" readme = "README.md"

View File

@ -309,7 +309,7 @@ pub(crate) fn eval_fn_call_expr(
// Special functions // Special functions
match identifier.full_name.as_ref() { match identifier.full_name.as_ref() {
"sum" | "Σ" | "" | "prod" | "" => { "sum" | "prod" => {
// Make sure exactly 3 arguments were supplied. // Make sure exactly 3 arguments were supplied.
if expressions.len() != 3 { if expressions.len() != 3 {
return Err(CalcError::IncorrectAmountOfArguments( return Err(CalcError::IncorrectAmountOfArguments(
@ -323,10 +323,7 @@ pub(crate) fn eval_fn_call_expr(
let end = eval_expr(context, &expressions[1], "")?.to_f64() as i128; let end = eval_expr(context, &expressions[1], "")?.to_f64() as i128;
let sum_else_prod = match identifier.full_name.as_ref() { let sum_else_prod = match identifier.full_name.as_ref() {
"sum" => true, "sum" => true,
"Σ" => true,
"" => true,
"prod" => false, "prod" => false,
"" => false,
_ => unreachable!(), _ => unreachable!(),
}; };
let mut sum = if sum_else_prod { let mut sum = if sum_else_prod {
@ -352,7 +349,7 @@ pub(crate) fn eval_fn_call_expr(
return Ok(sum); return Ok(sum);
} }
"integrate" | "integral" | "" => { "integrate" => {
// Make sure either 3 or 4 arguments were supplied. // Make sure either 3 or 4 arguments were supplied.
if expressions.len() < 3 || expressions.len() > 4 {} if expressions.len() < 3 || expressions.len() > 4 {}

View File

@ -138,12 +138,12 @@ impl<'a> Lexer<'a> {
'≤' => build(TokenKind::LessOrEquals, "", span), '≤' => build(TokenKind::LessOrEquals, "", span),
// Some of the special symbols will be lexed here, // Some of the special symbols will be lexed here,
// so that they don't merge with other symbols. // so that they don't merge with other symbols.
'π' => build(TokenKind::Identifier, "π", span), 'π' => build(TokenKind::Identifier, "pi", span),
'√' => build(TokenKind::Identifier, "", span), '√' => build(TokenKind::Identifier, "sqrt", span),
'τ' => build(TokenKind::Identifier, "τ", span), 'τ' => build(TokenKind::Identifier, "tau", span),
'ϕ' => build(TokenKind::Identifier, "ϕ", span), 'ϕ' => build(TokenKind::Identifier, "phi", span),
'Γ' => build(TokenKind::Identifier, "Γ", span), 'Γ' => build(TokenKind::Identifier, "gamma", span),
'∏' => build(TokenKind::Identifier, "Γ", span), '∏' => build(TokenKind::Identifier, "prod", span),
_ => build(TokenKind::Unknown, "", span), _ => build(TokenKind::Unknown, "", span),
}; };
@ -234,9 +234,12 @@ impl<'a> Lexer<'a> {
_ => TokenKind::Identifier, _ => TokenKind::Identifier,
}; };
if &value == "°" { let value = match value.as_ref() {
value = String::from("deg"); "Σ" | "" => String::from("sum"),
} "" => String::from("integrate"),
"°" => String::from("deg"),
_ => value,
};
build(kind, &value, (start, end)) build(kind, &value, (start, end))
} }

View File

@ -31,10 +31,6 @@ lazy_static! {
"pi", "pi",
3.1415926535897932384626433832795028841971693993751058209749445923, 3.1415926535897932384626433832795028841971693993751058209749445923,
); );
m.insert(
"π",
3.1415926535897932384626433832795028841971693993751058209749445923,
);
m.insert( m.insert(
"e", "e",
2.7182818284590452353602874713526624977572470936999595749669676277, 2.7182818284590452353602874713526624977572470936999595749669676277,
@ -43,18 +39,10 @@ lazy_static! {
"tau", "tau",
6.2831853071795864769252867665590057683943387987502116419498891846, 6.2831853071795864769252867665590057683943387987502116419498891846,
); );
m.insert(
"τ",
6.2831853071795864769252867665590057683943387987502116419498891846,
);
m.insert( m.insert(
"phi", "phi",
1.6180339887498948482045868343656381177203091798057628621354486227, 1.6180339887498948482045868343656381177203091798057628621354486227,
); );
m.insert(
"ϕ",
1.6180339887498948482045868343656381177203091798057628621354486227,
);
m m
}; };
pub static ref UNARY_FUNCS: HashMap<&'static str, (UnaryFuncInfo, &'static str)> = { pub static ref UNARY_FUNCS: HashMap<&'static str, (UnaryFuncInfo, &'static str)> = {

View File

@ -1,6 +1,6 @@
{ {
"name": "kalk_mobile", "name": "kalk_mobile",
"version": "1.0.1", "version": "1.0.2",
"description": "kalk mobile", "description": "kalk mobile",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
@ -16,7 +16,7 @@
"@capacitor/android": "^2.4.5", "@capacitor/android": "^2.4.5",
"@capacitor/cli": "^2.4.5", "@capacitor/cli": "^2.4.5",
"@capacitor/core": "^2.4.5", "@capacitor/core": "^2.4.5",
"@paddim8/kalk-component": "^1.3.0" "@paddim8/kalk-component": "^1.3.2"
}, },
"devDependencies": { "devDependencies": {
"@capacitor-community/electron": "^1.3.2", "@capacitor-community/electron": "^1.3.2",

View File

@ -1,6 +1,6 @@
{ {
"name": "@paddim8/kalk-component", "name": "@paddim8/kalk-component",
"version": "1.3.1", "version": "1.3.2",
"description": "A Svelte component for kalk, a calculator that supports user-defined functions and variables.", "description": "A Svelte component for kalk, a calculator that supports user-defined functions and variables.",
"svelte": "src/main.ts", "svelte": "src/main.ts",
"main": "public/build/bundle.js", "main": "public/build/bundle.js",
@ -55,7 +55,7 @@
"webpack-dev-server": "^3.11.0" "webpack-dev-server": "^3.11.0"
}, },
"dependencies": { "dependencies": {
"@paddim8/kalk": "^2.1.0", "@paddim8/kalk": "^2.1.2",
"shadow-selection-polyfill": "^1.1.0" "shadow-selection-polyfill": "^1.1.0"
}, },
"browserslist": [ "browserslist": [