-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UPDATE: Implement the implicit Intersection Operator
The II operator takes a range and returns a single cell that is in the same column or the same row as the present cell. This is needed for backwards compatibility with old Excel models and as a first step towards dynamic arrays. In the past Excel would evaluate `=A1:A10` in cell `C3` as `A3`, but today in results in an array containing all values in the range. To be compatible with old workbooks Excel inserts the II operator on those cases. So this PR performs an static analysis on all formulas inserting on import automatically the II operator where necessary. This we call the _automatic implicit operator_. When exporting to Excel the operator is striped away. You can also manually use the II. For instance `=SUM(@A1:A10)` in cell `C3`. This was not possible before and such a formula would break backwards compatibility with Excel. To Excel that "non automatic" form of the II is exported as `_xlfn.SINGLE()`. Th static analysis has to be done for all arithmetic operations and all functions. This is a bit of a daunting task and it is not done fully in this PR. We also need to implement arrays and dynamic arrays. My believe is that once the core operations have been implemented we can go formula by formula writing proper tests and documentation. After this PR formulas like `=A1:A10` for instance will return `#N/IMPL!` instead of performing the implicit intersection
- Loading branch information
Showing
31 changed files
with
1,623 additions
and
694 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
mod test_common; | ||
mod test_implicit_intersection; | ||
mod test_language; | ||
mod test_locale; | ||
mod test_ranges; | ||
|
25 changes: 25 additions & 0 deletions
25
base/src/expressions/lexer/test/test_implicit_intersection.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#![allow(clippy::unwrap_used)] | ||
|
||
use crate::expressions::{ | ||
lexer::{Lexer, LexerMode}, | ||
token::TokenType::*, | ||
}; | ||
use crate::language::get_language; | ||
use crate::locale::get_locale; | ||
|
||
fn new_lexer(formula: &str) -> Lexer { | ||
let locale = get_locale("en").unwrap(); | ||
let language = get_language("en").unwrap(); | ||
Lexer::new(formula, LexerMode::A1, locale, language) | ||
} | ||
|
||
#[test] | ||
fn sum_implicit_intersection() { | ||
let mut lx = new_lexer("sum(@A1:A3)"); | ||
assert_eq!(lx.next_token(), Ident("sum".to_string())); | ||
assert_eq!(lx.next_token(), LeftParenthesis); | ||
assert_eq!(lx.next_token(), At); | ||
assert!(matches!(lx.next_token(), Range { .. })); | ||
assert_eq!(lx.next_token(), RightParenthesis); | ||
assert_eq!(lx.next_token(), EOF); | ||
} |
Oops, something went wrong.