Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
1 change: 1 addition & 0 deletions src/calculate/operation/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/grammar.pest
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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 }
Expand Down
10 changes: 10 additions & 0 deletions src/parse_formula.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ where
types::Formula::Operation(operation)
}

fn build_formula_blank_func<N>() -> types::Formula<N>
where
N: XlNum,
<N as FromStr>::Err: Debug,
{
types::Formula::Value(types::Value::Blank)
}

fn build_formula_reference<N>(pair: pest::iterators::Pair<Rule>) -> types::Formula<N>
where
N: XlNum,
Expand Down Expand Up @@ -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!(),
}
}
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::{
fmt::{Debug, Display},
str::FromStr,
};

/// Defines Excel Functions.
#[derive(Debug, Copy, Clone)]
pub enum Function {
Expand All @@ -27,6 +28,7 @@ pub enum Function {
Find,
Search,
IsError,
Blank,
}

/// Defines Excel Operators.
Expand Down
7 changes: 7 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down