Added support for ⋅ symbol

This commit is contained in:
PaddiM8 2022-01-05 15:54:46 +01:00
parent c5f99a8343
commit 971965ddce
4 changed files with 25 additions and 8 deletions

View File

@ -106,7 +106,7 @@ impl Highlighter for LineHighlighter {
let reg = Regex::new(
r"(?x)
(?P<op>([+\-/*%^!×÷]|if|otherwise|load|exit|clear|help)) |
(?P<op>([+\-/*%^!×÷]|if|otherwise|load|exit|clear|help)) |
(?P<radix>0[box][a-zA-Z0-9]+) |
(?P<identifier>[^!-@\s_|^\[\]\{\}¹²³]+(_\d+)?)",
)

View File

@ -683,8 +683,25 @@ impl KalkValue {
real * imaginary_rhs + imaginary * real_rhs,
unit.to_string(),
),
(KalkValue::Vector(_), _) | (_, KalkValue::Vector(_)) => {
calculate_vector(self, rhs, &KalkValue::mul_without_unit)
(KalkValue::Vector(values), KalkValue::Number(_, _, _)) => KalkValue::Vector(
values
.iter()
.map(|x| x.clone().mul_without_unit(&self))
.collect(),
),
(KalkValue::Number(_, _, _), KalkValue::Vector(values_rhs)) => KalkValue::Vector(
values_rhs
.iter()
.map(|x| self.clone().mul_without_unit(x))
.collect(),
),
(KalkValue::Vector(values), KalkValue::Vector(values_rhs)) => {
let mut sum = KalkValue::from(0f64);
for (value, value_rhs) in values.iter().zip(values_rhs) {
sum = sum.add_without_unit(&value.clone().mul_without_unit(value_rhs));
}
sum
}
_ => KalkValue::nan(),
}
@ -854,7 +871,7 @@ fn calculate_vector(
KalkValue::Vector(values.iter().map(|x| action(x.clone(), y)).collect())
}
(KalkValue::Number(_, _, _), KalkValue::Vector(values_rhs)) => {
KalkValue::Vector(values_rhs.iter().map(|x| action(x.clone(), x)).collect())
KalkValue::Vector(values_rhs.iter().map(|x| action(y.clone(), x)).collect())
}
(KalkValue::Vector(values), KalkValue::Vector(values_rhs)) => {
if values.len() == values_rhs.len() {

View File

@ -122,7 +122,7 @@ impl<'a> Lexer<'a> {
let token = match c {
'+' => build(TokenKind::Plus, "", span),
'-' => build(TokenKind::Minus, "", span),
'*' | '×' => build(TokenKind::Star, "", span),
'*' | '×' | '⋅' => build(TokenKind::Star, "", span),
'/' | '÷' => build(TokenKind::Slash, "", span),
'^' => build(TokenKind::Power, "", span),
'|' => build(TokenKind::Pipe, "", span),
@ -352,7 +352,7 @@ fn is_valid_identifier(c: Option<&char>) -> bool {
match c {
'+' | '-' | '/' | '*' | '%' | '^' | '!' | '(' | ')' | '=' | '.' | ',' | ';' | '|'
| '⌊' | '⌋' | '⌈' | '⌉' | '[' | ']' | '{' | '}' | 'π' | '√' | 'τ' | 'ϕ' | 'Γ' | '<'
| '>' | '≠' | '≥' | '≤' | '×' | '÷' | '\n' => false,
| '>' | '≠' | '≥' | '≤' | '×' | '÷' | '⋅' | '\n' => false,
_ => !c.is_digit(10) || is_superscript(c) || is_subscript(c),
}
} else {

View File

@ -282,7 +282,7 @@
let result = input;
let offset = 0;
result = result.replace(
/(?<radix>0[box][a-zA-Z0-9]+)|(?<comparison>(!=|[<>]=?))|(?<html>[<>&]|(\n\s*\}?|\s+))|(?<op>([+\-/*%^!≈×÷]|if|otherwise)|(?<identifier>[^!-@\s_|^⌊⌋⌈⌉≈\[\]\{\}≠≥≤⁰¹²³⁴⁵⁶⁷⁸⁹⁺⁻⁼⁽⁾₀₁₂₃₄₅₆₇₈₉₊₋₌₍₎]+(_\d+)?)\(?)/g,
/(?<radix>0[box][a-zA-Z0-9]+)|(?<comparison>(!=|[<>]=?))|(?<html>[<>&]|(\n\s*\}?|\s+))|(?<op>([+\-/*%^!≈×÷]|if|otherwise)|(?<identifier>[^!-@\s_|^⌊⌋⌈⌉≈\[\]\{\}≠≥≤⁰¹²³⁴⁵⁶⁷⁸⁹⁺⁻⁼⁽⁾₀₁₂₃₄₅₆₇₈₉₊₋₌₍₎]+(_\d+)?)\(?)/g,
(
substring,
_radix,
@ -318,7 +318,7 @@
}
if (op && !isOutput) {
if (substring == "*") return "×";
if (substring == "*") return "";
if (substring == "/") return "÷";
}