A Rust library for parsing and evaluating DAX (Data Analysis Expressions) formulas using procedural macros. This library provides compile-time parsing of DAX expressions and basic evaluation capabilities.
- Compile-time parsing of DAX expressions
- Support for basic DAX functions (SUM, AVERAGE, COUNT)
- Column reference parsing using square bracket notation
- Basic arithmetic operations
- Table creation macro for testing and development
Add this to your Cargo.toml
:
[dependencies]
rust-dax = "0.1.0"
Use the parse_dax!
macro to parse DAX expressions at compile time:
use rust_dax::parse_dax;
fn main() {
let tokens = parse_dax!("SUM([Sales])");
println!("{:?}", tokens);
}
The library provides a table!
macro for creating test data tables:
use rust_dax::table;
let sales_table = table! {
"Amount" => [100.0, 200.0, 300.0],
"Quantity" => [1, 2, 3],
};
Currently supported functions include:
SUM
: Calculate the sum of a columnAVERAGE
: Calculate the average of a columnCOUNT
: Count non-empty values in a column
Example:
let result = parse_dax!("SUM([Amount])");
The library uses Rust's procedural macro system to parse DAX expressions at compile time. The parsing process includes:
- Tokenization of DAX expressions into discrete tokens (functions, columns, operators, etc.)
- Basic syntax validation
- Generation of corresponding Rust code
src/lib.rs
: Main library interface and proc macro definitionsdax-macro-impl/
: Implementation details for the procedural macrosdax-macro/
: Public macro interfaces
Current limitations include:
- Limited set of supported DAX functions
- Basic arithmetic operations only
- No support for complex filtering or relationships
- Limited error handling
Contributions are welcome! Please feel free to submit issues and pull requests.
When contributing, please:
- Add tests for any new features
- Update documentation
- Follow the existing code style
This project is licensed under the MIT License - see the LICENSE file for details.
- The Rust proc-macro2 and syn crates for making this implementation possible
- Microsoft's DAX documentation for reference implementation details