1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
//! # FormCalc - Formula Calculator Engine
//!
//! A powerful and flexible formula evaluation engine with automatic dependency resolution
//! and parallel execution capabilities.
//!
//! ## Features
//!
//! - **Formula Parsing**: Parse and evaluate complex formulas with arithmetic, logical, and comparison operations
//! - **Dependency Management**: Automatically resolve and execute formulas in the correct order based on dependencies
//! - **Parallel Execution**: Formulas in the same dependency layer are executed in parallel for maximum performance
//! - **Built-in Functions**: Support for mathematical, string, and date functions
//! - **Custom Functions**: Register custom functions to extend functionality
//! - **Variables**: Support for variables in formulas
//! - **Type System**: Strong typing with support for numbers, strings, and booleans
//! - **Error Handling**: Comprehensive error reporting with detailed messages
//!
//! ## Quick Start
//!
//! ```rust
//! use formcalc::{Engine, Formula, Value};
//!
//! let mut engine = Engine::new();
//!
//! // Simple calculation
//! let formula = Formula::new("calculation", "return 2 + 2 * 3");
//! engine.execute(vec![formula]).unwrap();
//! let result = engine.get_result("calculation").unwrap();
//! assert_eq!(result, Value::Number(8.0));
//! ```
//!
//! ## Using Variables
//!
//! ```rust
//! use formcalc::{Engine, Formula, Value};
//!
//! let mut engine = Engine::new();
//! engine.set_variable("price".to_string(), Value::Number(100.0));
//! engine.set_variable("tax_rate".to_string(), Value::Number(0.2));
//!
//! let formula = Formula::new("total", "return price * (1 + tax_rate)");
//! engine.execute(vec![formula]).unwrap();
//!
//! let result = engine.get_result("total").unwrap();
//! assert_eq!(result, Value::Number(120.0));
//! ```
//!
//! ## Formula Dependencies
//!
//! The engine automatically resolves dependencies between formulas:
//!
//! ```rust
//! use formcalc::{Engine, Formula, Value};
//!
//! let mut engine = Engine::new();
//!
//! let formula1 = Formula::new("base_price", "return 100");
//! let formula2 = Formula::new("with_tax", "return get_output_from('base_price') * 1.2");
//! let formula3 = Formula::new("final_price", "return get_output_from('with_tax') + 10");
//!
//! // The engine automatically resolves dependencies and executes in correct order
//! engine.execute(vec![formula1, formula2, formula3]).unwrap();
//!
//! let result = engine.get_result("final_price").unwrap();
//! assert_eq!(result, Value::Number(130.0));
//! ```
//!
//! ## Custom Functions
//!
//! Extend the engine with custom functions:
//!
//! ```rust
//! use formcalc::{Engine, Formula, Function, Value, Result, CalculatorError};
//! use std::sync::Arc;
//!
//! struct DoubleFunction;
//!
//! impl Function for DoubleFunction {
//! fn name(&self) -> &str {
//! "double"
//! }
//!
//! fn num_args(&self) -> usize {
//! 1
//! }
//!
//! fn execute(&self, params: &[Value]) -> Result<Value> {
//! match params[0] {
//! Value::Number(n) => Ok(Value::Number(n * 2.0)),
//! _ => Err(CalculatorError::TypeError("Expected number".to_string())),
//! }
//! }
//! }
//!
//! let mut engine = Engine::new();
//! engine.register_function(Arc::new(DoubleFunction));
//!
//! let formula = Formula::new("test", "return double(21)");
//! engine.execute(vec![formula]).unwrap();
//!
//! let result = engine.get_result("test").unwrap();
//! assert_eq!(result, Value::Number(42.0));
//! ```
// Re-export main types
pub use Engine;
pub use ;
pub use ;
pub use Function;
pub use Value;