diff --git a/Cargo.lock b/Cargo.lock index e35ce08..847b457 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -255,7 +255,7 @@ checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "xlformula_engine" -version = "0.4.2" +version = "0.4.3" dependencies = [ "assert_approx_eq", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 9d10b7b..d3a9e15 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0" name = "xlformula_engine" readme = "README.md" repository = "https://github.com/jiradaherbst/XLFormula-Engine" -version = "0.4.2" +version = "0.4.3" [dependencies] chrono = { version = "0.4.41", default-features = false } diff --git a/src/calculate/operation/function.rs b/src/calculate/operation/function.rs index e937323..d036ab7 100644 --- a/src/calculate/operation/function.rs +++ b/src/calculate/operation/function.rs @@ -142,6 +142,7 @@ where types::Function::Find => calculate_find(get_find_args(exp, f)), types::Function::Search => calculate_search(get_find_args(exp, f)), types::Function::IsError => calculate_iserror(get_unary_function_arg(exp, f)), + types::Function::Blank => types::Value::Blank, } } diff --git a/src/grammar.pest b/src/grammar.pest index 0f72991..aa47f15 100644 --- a/src/grammar.pest +++ b/src/grammar.pest @@ -36,7 +36,7 @@ logical_operator = _{ equal | not_equal | greater_or_equal | greater greater_or_equal= { ">=" } less_or_equal = { "<=" } -function = _{ abs | sum | product | average | negate | days | year | month | day | right | left | iff | isblank | find | search | iserror | custom_function } +function = _{ abs | sum | product | average | negate | days | year | month | day | right | left | iff | isblank | find | search | iserror | blank_func | custom_function } abs = { ^"ABS" ~ "(" ~ expr ~ ")" } sum = { ^"SUM" ~ function_param_with_atomic_expr} product = { ^"PRODUCT" ~ function_param_with_atomic_expr} @@ -53,6 +53,7 @@ function = _{ abs | sum | product | average | negate | days | year | month | day find = { ^"FIND" ~ function_param } search = { ^"SEARCH" ~ function_param } iserror = { ^"ISERROR" ~ function_param } + blank_func = { ^"BLANK" ~ empty_param } custom_function = { reference ~ (function_param | empty_param) } logical_function = _{ or | and | xor | not } diff --git a/src/parse_formula.rs b/src/parse_formula.rs index 7c0bbdc..b757585 100644 --- a/src/parse_formula.rs +++ b/src/parse_formula.rs @@ -125,6 +125,14 @@ where types::Formula::Operation(operation) } +fn build_formula_blank_func() -> types::Formula +where + N: XlNum, + ::Err: Debug, +{ + types::Formula::Value(types::Value::Blank) +} + fn build_formula_reference(pair: pest::iterators::Pair) -> types::Formula where N: XlNum, @@ -197,6 +205,7 @@ fn rule_to_function_operator(collective_operation: Rule) -> types::Operator { Rule::find => types::Operator::Function(types::Function::Find), Rule::search => types::Operator::Function(types::Function::Search), Rule::iserror => types::Operator::Function(types::Function::IsError), + Rule::blank_func => types::Operator::Function(types::Function::Blank), _ => unreachable!(), } } @@ -410,6 +419,7 @@ where Rule::find => build_formula_collective_operator(Rule::find, pair, f), Rule::search => build_formula_collective_operator(Rule::search, pair, f), Rule::iserror => build_formula_collective_operator(Rule::iserror, pair, f), + Rule::blank_func => build_formula_blank_func(), _ => unreachable!(), }) .map_infix( diff --git a/src/types.rs b/src/types.rs index 70d9bfb..facce2e 100644 --- a/src/types.rs +++ b/src/types.rs @@ -4,6 +4,7 @@ use std::{ fmt::{Debug, Display}, str::FromStr, }; + /// Defines Excel Functions. #[derive(Debug, Copy, Clone)] pub enum Function { @@ -27,6 +28,7 @@ pub enum Function { Find, Search, IsError, + Blank, } /// Defines Excel Operators. diff --git a/tests/test.rs b/tests/test.rs index b81c214..ae6f386 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -468,6 +468,13 @@ fn it_evaluate_wrong_parens1() { test_all_types!(evaluate_formula_string, "=Hello World", "#PARSE!"); } +//////////////////////////// Blank ////////////////////////////////// + +#[test] +fn it_evaluate_blank() { + test_all_types!(evaluate_formula_string, "=BLANK()", "0"); +} + //////////////////////////// Boolean ////////////////////////////////// #[test] fn it_evaluate_comparison_operators() {