Repository navigation
dax: crate, lexer, parser, type surface, function catalog and the evaluator's scalar core (#2228) #3406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alosslessdev
wants to merge
73
commits into
storytold:main
Choose a base branch
from
alosslessdev:dax/core
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
dax: crate, lexer, parser, type surface, function catalog and the evaluator's scalar core (#2228) #3406
Changes from all commits
Commits
Show all changes
73 commits
Select commit
Hold shift + click to select a range
d049f1a
dax: crate scaffolding, README and workspace wiring (#2228)
alosslessdev 4f65003
dax: lexer, Pratt parser, AST, canonical printer and query statements…
alosslessdev 5c0e27c
dax: function catalog for every dax.guide category (#2228)
alosslessdev a89acaa
dax: static types, binder and call validation (#2228)
alosslessdev 81a593d
dax: scalar values, columnar storage, evaluator framework and scalar …
alosslessdev a7abdde
dax: evaluator, storage and pivot test suites (#2228)
alosslessdev 4ff7407
dax: keep the SUMMARIZE subtotal row context beside the evaluator's o…
alosslessdev faab395
dax: align the README and validate docs with the implemented surface …
alosslessdev 4e2fe32
dax: find relationship cycles that close through a bidirectional reve…
alosslessdev c24fe0d
dax: bind every documented CROSSFILTER direction and RANK reset keywo…
alosslessdev 40350ba
dax: fix the evaluator core's rounding, aggregation types, blank memb…
alosslessdev eebfbf5
dax: give each evaluator family its own registry marker line (#2228)
alosslessdev 7332a12
dax: follow DAX equality and the documented CROSSFILTER contract (#2228)
alosslessdev 5a73c66
dax: fold text in filter matching and harden keywords, months and piv…
alosslessdev 21212be
Merge remote-tracking branch 'upstream/main' into coreL3406
alosslessdev d1cc151
dax: bind the documented ASC/DESC slots of RANK.EQ, TOPNSKIP, SAMPLE …
alosslessdev 3f5c55a
dax: join numeric keys by value in strict equality (#2228)
alosslessdev 934561c
dax: make the README example compile as Rust and drop the CLI sentenc…
alosslessdev e96107d
dax: keep exact whole inputs, folded groups and exact relationship ke…
alosslessdev 9e74972
dax: let a large numeric key match itself in strict equality (#2228)
alosslessdev 6dbb9e3
dax: take the pivot, integrity and functions-reference files into the…
alosslessdev 278f95e
dax: replay the umbrella's hop index, blank-key orphan rule and CONCA…
alosslessdev 5e1b519
dax: carry the grouping scope, read integer columns exactly and put I…
alosslessdev 292f0a3
dax: bind every repeated order pair of SAMPLE and TOPNSKIP (#2228)
alosslessdev c37fa6a
dax: read the browser clock for NOW/TODAY on wasm (#2228)
alosslessdev f00e1da
dax: document the variable index and look through VAR/RETURN in opera…
alosslessdev 14916f6
dax: drop the unused manifest dependency and align the pivot filter d…
alosslessdev 2af770d
dax: document IN at the comparison tier (#2228)
alosslessdev d24deba
dax: give families a per-evaluation memo slot and state the CUSTOMDAT…
alosslessdev a8e8bd7
dax: normalize numeric relationship joins, scope keyword shadowing an…
alosslessdev 707cbc0
dax: compare same-variant integers exactly (#2228)
alosslessdev b4c8238
dax: count every non-blank value in the implicit Count measure (#2228)
alosslessdev 88717cd
dax: compare integers exactly across variants and keep DATATABLE type…
alosslessdev b3e2543
dax: normalize numeric keys in propagation, integrity and hop lookups…
alosslessdev 39ece86
dax: keep NaN and inexact currency keys out of the normalized join (#…
alosslessdev 10a2c02
dax: exclude NaN keys from joins and apply the currency rule to stric…
alosslessdev c040089
dax: clear NAMEOF's volatile flag, infer Pow as Decimal and widen the…
alosslessdev 68389e8
dax: report NaN foreign keys as orphans and name the supported ALL fu…
alosslessdev 581b085
dax: make exponentiation left-associative like every DAX operator (#2…
alosslessdev 6f96571
dax: keep non-finite finding keys JSON-safe and count NaN foreign key…
alosslessdev 0f074e4
dax: note that Excel agrees on left-associative exponentiation (#2228)
alosslessdev 682d777
dax: count nonblank dimension NaN keys in the integrity report (#2228)
alosslessdev a8b9913
dax: give CONTAINSROW evaluable documented examples (#2228)
alosslessdev 1198e1d
dax: state the valid WEEKNUM codes and name the real pivot remedy (#2…
alosslessdev 8662072
Merge remote-tracking branch 'upstream/main' into coreL3406
alosslessdev 94bdc71
dax: fold numeric variants in filter and distinct keys, and guard non…
alosslessdev 0ade51f
dax: keep filter keys in their own variant and fold at comparison (#2…
alosslessdev 2464b4f
dax: intersect filters and narrow pivot cells under folded equality (…
alosslessdev ccb757d
dax: align the storage and functions-reference docs with the typed ag…
alosslessdev f9921b9
dax: blank a repeated Outline label under folded equality (#2228)
alosslessdev 9fab68f
dax: list exponentiation as left-associative in the operator table (#…
alosslessdev 77c6bfb
Merge remote-tracking branch 'upstream/main' into coreL3406
alosslessdev 98d7238
dax: document the flat-chain depth limit and clear the wrong sugar li…
alosslessdev f94413a
dax: answer the alphabetical extremum for MIN/MAX over a text column …
alosslessdev 1c2d4ce
dax: drop the stale DISTINCTCOUNTNOBLANK sugar row from the README (#…
alosslessdev 3334512
dax: derive singletons from the visible column and skip NaN extrema (…
alosslessdev 4c2257b
dax: qualify the DISTINCTCOUNTNOBLANK Excel claim and use the storage…
alosslessdev 7904742
dax: validate a measure's home table while parsing the model (#2228)
alosslessdev 62abd0e
dax: validate pivot fields before grouping so empty tables report mis…
alosslessdev 415c715
dax: format Currency text from the exact scaled integer (#2228)
alosslessdev 3769d34
dax: skip NaN candidates in the storage extremum scan (#2228)
alosslessdev 40bfb1b
dax: keep a variable from shadowing the documented interval keywords …
alosslessdev c32aac3
dax: print negative zero as zero in DAX text (#2228)
alosslessdev c5cc91f
dax: drop the one-name INFO overload the evaluator rejects (#2228)
alosslessdev 2aeba77
dax: cover the extreme month offsets EOMONTH and EDATE saturate (#2228)
alosslessdev 5a12205
dax: give time-intelligence intervals precedence over table and measu…
alosslessdev 7eb0698
dax: format the interval table-name test (#2228)
alosslessdev 3039a9c
dax: bind only documented enum words as keywords, saturate extreme DA…
alosslessdev 60ca297
dax: restrict RANKX Ties and DATEDIFF slots to documented words, drop…
alosslessdev c0953eb
dax: rustfmt the DATEDIFF clause_keyword call (#2228)
alosslessdev 04021c8
dax: model INFO restrictions as repeating pairs, reject odd arities (…
alosslessdev e90c408
dax: drop accidental worktree link from INFO-pairs commit (#2228)
alosslessdev fd01ea9
dax: restrict CONVERT and DATATABLE type slots, reject Boolean-number…
alosslessdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,35 @@ | ||
| [package] | ||
| name = "gridcraft-dax" | ||
| # A first release of this crate, not the workspace release line: nothing depends on a published | ||
| # version of it yet, and 0.1.0 says what it is — new. | ||
| version = "0.1.0" | ||
| edition.workspace = true | ||
| license.workspace = true | ||
| description = "GridCraft DAX language: lexer, Pratt parser, syntax tree and canonical printer" | ||
|
|
||
| [lints] | ||
| workspace = true | ||
|
|
||
| [dependencies] | ||
| serde = { workspace = true } | ||
| serde_json = { workspace = true } | ||
| thiserror = { workspace = true } | ||
| # Calendar arithmetic (date serials, month lengths, leap years) goes through chrono on every | ||
| # target, as AGENTS.md requires. The web build has no clock and uses the fixed fallback in | ||
| # `eval/support.rs`, but the date types it needs build for wasm too (`gridcraft-core` does the | ||
| # same with the same workspace dependency). | ||
| chrono = { workspace = true } | ||
|
|
||
| [target.'cfg(target_arch = "wasm32")'.dependencies] | ||
| # The browser clock for NOW/TODAY under wasm, the same dependency `crates/core` uses: the standard | ||
| # library clock traps there, and `eval/support.rs` would otherwise freeze at 1970. | ||
| js-sys = "0.3" | ||
|
|
||
| [[example]] | ||
| name = "parse" | ||
| # Cargo does not test examples by default; this one carries assertions on the query-to-expression | ||
| # fallback, so it has to run under `cargo test`. | ||
| test = true | ||
|
|
||
| [dev-dependencies] | ||
| serde_json = { workspace = true } |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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,69 @@ | ||
| //! Parse DAX from the command line (or stdin), print its syntax tree and canonical text. | ||
| //! | ||
| //! ```text | ||
| //! cargo run -p gridcraft-dax --example parse -- "1 + 2 * 3" | ||
| //! echo "EVALUATE SUM('Sales'[Amount])" | cargo run -p gridcraft-dax --example parse | ||
| //! ``` | ||
|
|
||
| use std::io::{self, Read}; | ||
|
|
||
| use gridcraft_dax::{TokenKind, parse_expression, parse_query, print_expression, print_query, tokenize}; | ||
|
|
||
| fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
| let mut text = std::env::args().skip(1).collect::<Vec<_>>().join(" "); | ||
| if text.trim().is_empty() { | ||
| io::stdin().read_to_string(&mut text)?; | ||
| } | ||
| let text = text.trim(); | ||
| if text.is_empty() { | ||
| return Err("no DAX expression supplied; pass it as an argument or on stdin".into()); | ||
| } | ||
| print!("{}", render(text)?); | ||
| Ok(()) | ||
| } | ||
|
|
||
| /// Parses and renders one input. Queries are preferred; when the query parser fails, a valid | ||
| /// expression is still accepted (`DEFINE` is a legal bare name), and the query diagnostic is kept | ||
| /// only when both parsers fail for input that starts with a query keyword. | ||
| fn render(text: &str) -> Result<String, String> { | ||
| match parse_query(text) { | ||
| Ok(query) => Ok(format!("Query\n{query:#?}\nCanonical: {}\n", print_query(&query))), | ||
| Err(query_error) => { | ||
| let expr = match parse_expression(text) { | ||
| Ok(expr) => expr, | ||
| Err(expr_error) => { | ||
| if starts_with_query_keyword(text) { | ||
| return Err(query_error.to_string()); | ||
| } | ||
| return Err(expr_error.to_string()); | ||
| } | ||
| }; | ||
| Ok(format!("AST\n{expr:#?}\nCanonical: {}\n", print_expression(&expr))) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fn starts_with_query_keyword(text: &str) -> bool { | ||
| tokenize(text).is_ok_and(|tokens| match tokens.first().map(|token| &token.kind) { | ||
| Some(TokenKind::Evaluate) => true, | ||
| Some(TokenKind::Ident(word)) => word.eq_ignore_ascii_case("DEFINE"), | ||
| _ => false, | ||
| }) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn query_only_keywords_stay_on_the_query_parser() { | ||
| assert!(starts_with_query_keyword("EVALUATE Sales")); | ||
| assert!(starts_with_query_keyword("DEFINE MEASURE Sales[M] = 1 EVALUATE Sales")); | ||
| assert!(starts_with_query_keyword(" define measure Sales[M] = 1")); | ||
| assert!(!starts_with_query_keyword("SUM(Sales[Amount])")); | ||
| // `DEFINE` alone is a valid expression, so the expression parser wins. | ||
| assert!(render("DEFINE").expect("bare name expression").starts_with("AST")); | ||
| let error = render("DEFINE MEASURE").expect_err("malformed query"); | ||
| assert!(error.contains("measure name"), "{error}"); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.