Skip to content

Initial implementation of AST for CQL#1640

Merged
JPercival merged 40 commits intomasterfrom
ast
Feb 11, 2026
Merged

Initial implementation of AST for CQL#1640
JPercival merged 40 commits intomasterfrom
ast

Conversation

@antvaset
Copy link
Copy Markdown
Contributor

@antvaset antvaset commented Nov 14, 2025

  • Parsing CQL source files into ASTs modeled using CQL language constructs (distinct from ELM).
  • Implementation of AST walker for read-only traversal of the CQL AST.
  • WIP implementation of ELM emitter that transforms CQL AST to ELM.
  • Showing the parse tree and AST in the playground.
  • KMP for SystemModelInfoProvider.
  • New FilesToStringsTask Gradle task with codegen enabling file contents to be inlined at compile time and used as strings (useful for e.g. inlining system-modelinfo.xml for SystemModelInfoProvider-in-JS).
  • New LoadTestResourcesTask Gradle task with multiplatform codegen enabling access to test resources in commonTest.
  • Limiting multiplatform test execution to JVM and JS-in-Node.js

@github-actions
Copy link
Copy Markdown

Formatting check succeeded!

@antvaset antvaset marked this pull request as draft November 14, 2025 00:23
@codecov
Copy link
Copy Markdown

codecov bot commented Nov 14, 2025

Codecov Report

❌ Patch coverage is 0% with 112 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.65%. Comparing base (d0643c5) to head (419c3dd).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...tlin/org/cqframework/cql/cql2elm/ast/ElmEmitter.kt 0.00% 96 Missing ⚠️
...framework/cql/cql2elm/frontend/CompilerFrontend.kt 0.00% 16 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1640      +/-   ##
============================================
- Coverage     65.91%   65.65%   -0.27%     
  Complexity     1645     1645              
============================================
  Files           478      480       +2     
  Lines         27664    27776     +112     
  Branches       5499     5523      +24     
============================================
  Hits          18235    18235              
- Misses         7104     7216     +112     
  Partials       2325     2325              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@antvaset antvaset marked this pull request as ready for review November 14, 2025 01:22
@antvaset antvaset marked this pull request as draft November 14, 2025 01:25
@antvaset antvaset marked this pull request as ready for review November 14, 2025 02:33
@cmoesel
Copy link
Copy Markdown
Member

cmoesel commented Nov 14, 2025

I don't have any comments on the code (haven't looked at it), but I'm curious -- what's the motivation/vision for this CQL AST?

@cmoesel
Copy link
Copy Markdown
Member

cmoesel commented Nov 24, 2025

The ultimate goal is to split the compiler into a frontend (parsing, AST generation, type inference, some types of optimization like inlining) and a backend (ELM generation). The motivations for that are multi-fold...

Thanks for additional insight. That's helpful. It's been a while since I've written any significant CQL-to-ELM code (probably nearing a decade). I didn't realize the ELM model itself caused so much complexity -- I assumed it was mainly the type inference, function resolution, and other various CQL magic, but it sounds like that stuff is just shifting to the AST generator now. That said, ELM was based on Health e-Decisions, so I shouldn't be surprised that conforming to that schema might introduce additional complications.

There's not much to argue with here: better separation of concerns, better testing, better consistency across versions, better IDE tools, and easier translation into other target formats. I like it.

One small note: I wanted to see what the AST looks like, so I built it and ran the CQL playground. In the process of doing that, I found that the CQL-to-ELM UI README needs to be updated. It currently says to browse to http://localhost:3000/cql-to-elm-ui, but that should be http://localhost:3000/clinical_quality_language/playground now.

@antvaset
Copy link
Copy Markdown
Contributor Author

Hi @cmoesel, sorry the README got outdated after we deployed the UI to cqframework.org. Now it's fixed.

@JPercival
Copy link
Copy Markdown
Contributor

There's not much to argue with here... I like it.

Is that "I like the idea" or "I like the AST implementation?"

@cmoesel
Copy link
Copy Markdown
Member

cmoesel commented Dec 1, 2025

There's not much to argue with here... I like it.

Is that "I like the idea" or "I like the AST implementation?"

I like the idea. I haven't looked at the implementation closely enough to comment on that. Is there any documentation that lists all of the possible AST nodes and their relationships?

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Dec 9, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@JPercival
Copy link
Copy Markdown
Contributor

@cmoesel - Docs updated. A few key ones:

Src/java/cql/README.md

Src/java/docs/DECISIONS.md

Src/java/cql/AST.md

@brynrhodes
Copy link
Copy Markdown
Member

I don't disagree with the AST approach here, there are some good arguments there, but I disagree with the premise of number 3, where are you seeing that "CQL has begun to evolve independently of ELM"? I don't think that's true at all, Every change that has been proposed in CQL 2.0 has a corresponding change in the ELM representation. I don't think it changes the thrust of the arguments, but I want to clarify the statement.

@JPercival
Copy link
Copy Markdown
Contributor

@brynrhodes - I don't see that in the AST docs anywhere? Was there some particular statement that needed to be clarified?

@brynrhodes
Copy link
Copy Markdown
Member

It's not in the docs so far as I know, I was referring to the comment thread above (#1640 (comment))

@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@JPercival JPercival merged commit f179c8f into master Feb 11, 2026
8 of 9 checks passed
@JPercival JPercival deleted the ast branch February 11, 2026 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants