Expand description

A tokenizer for spreadsheet formulas.

This is meant to feed a formula parser.

You will need to instantiate it with a language and a locale.

It supports two working modes:

  1. A1 or display mode This is for user formulas. References are like D4, D$4 or F5:T10
  2. R1C1, internal or runtime mode A reference like R1C1 refers to $A$1 and R3C4 to $D$4 R[2]C[5] refers to a cell two rows below and five columns to the right It uses the ‘en’ locale and language. This is used internally at runtime.

Formulas look different in different locales:

=IF(A1, B1, NA()) versus =IF(A1; B1; NA())

Also numbers are different:

1,123.45 versus 1.123,45

The names of the errors and functions are different in different languages, but they stay the same in different locales.

Note that in IronCalc if you are using a locale different from ‘en’ or a language different from ‘en’ you will still need the ‘en’ locale and language because formulas are stored in that language and locale

Examples:

use ironcalc_base::expressions::lexer::{Lexer, LexerMode};
use ironcalc_base::expressions::token::{TokenType, OpCompare};
use ironcalc_base::locale::get_locale;
use ironcalc_base::language::get_language;

let locale = get_locale("en").unwrap();
let language = get_language("en").unwrap();
let mut lexer = Lexer::new("=A1*SUM(Sheet2!C3:D5)", LexerMode::A1, &locale, &language);
assert_eq!(lexer.next_token(), TokenType::Compare(OpCompare::Equal));
assert!(matches!(lexer.next_token(), TokenType::Reference { .. }));

Modules

Structs

Enums