Skip to content
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

Multiplatform CQL parser #1443

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open

Conversation

JPercival
Copy link
Contributor

  • Change the output of ANTLR to Kotlin, rather than Java
  • Use Kotlin multiplatform to generate Java and JS lexer/parsers for CQL
  • Add a demo application showing the parser working in JS

antvaset and others added 2 commits November 15, 2024 13:59
* Add demo for the UI that uses Kotlin/JS- and Kotlin/WASM-based CQL parser

* Tweak config

* Update README.md

* Update docs

* Update docs
Copy link

github-actions bot commented Nov 18, 2024

Formatting check succeeded!

Copy link

codecov bot commented Nov 18, 2024

Codecov Report

Attention: Patch coverage is 96.20690% with 11 lines in your changes missing coverage. Please review.

Project coverage is 64.47%. Comparing base (935ef51) to head (4226a65).
Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
...ava/org/cqframework/cql/cql2elm/CqlTranslator.java 50.00% 6 Missing ⚠️
.../java/org/cqframework/cql/cql2elm/model/Chunk.java 83.33% 0 Missing and 2 partials ⚠️
...mework/cql/cql2elm/targetmap/TargetMapVisitor.java 0.00% 2 Missing ⚠️
...in/java/org/cqframework/cql/elm/IdObjectFactory.kt 99.57% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1443      +/-   ##
============================================
+ Coverage     64.35%   64.47%   +0.11%     
- Complexity     1920     2180     +260     
============================================
  Files           494      492       -2     
  Lines         28131    27972     -159     
  Branches       5588     5537      -51     
============================================
- Hits          18105    18036      -69     
+ Misses         7773     7701      -72     
+ Partials       2253     2235      -18     

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


🚨 Try these New Features:

Copy link
Member

@cmoesel cmoesel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is way cool. The JS parser demo app worked great. I also ran a regression test of the Java translator against a set of CQL libraries and everything came out clean.

I left a few questions and minor comments/suggestions for your consideration. Some of it we discussed a bit already (like Gradle 8.11) but I had already made the comment by then, so I left it for posterity.

Comment on lines +13 to +17
/**
* GrammarTest ensures that the grammar (and generated parsers) work as expected. If non-compatible changes are made
* to the grammar, these tests should fail. If the change is intentional, modify the tests to pass-- otherwise, fix
* the grammar.
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you run this test? As far as I can tell, it's not included in the normal test run.

* to the grammar, these tests should fail. If the change is intentional, modify the tests to pass-- otherwise, fix
* the grammar.
*/
internal class JsTest {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except for the classname, this file is exactly the same as the GrammarTest.kt file in commonTest. Is it necessary to have both? If so, is there a better way to re-use code (e.g., can JsTest extend GrammarTest or literally call the test functions from GrammarTest)?

If we need both files and both files each need to repeat all the test code verbatim, I'd suggest that you add a comment in each one pointing to the other. I assume that if you need to make a change in one, you'll probably want to make the same change in the other -- so we should make it hard to forget to do that.

cqlLexer lexer = new cqlLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
tokens.fill();
cqlParser parser = new cqlParser(tokens);
parser.setBuildParseTree(true);
ParserRuleContext tree = parser.library();
Trees.inspect(tree, parser);
// Trees.inspect(tree, parser);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't call Trees.inspect then what is the point of this file? It builds the tree but then does nothing with it. Should it be modified to at least print a text tree to the console?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, good idea. Because of this little gui application we had inadvertently added some GUI dependencies to the compiler. That was discovered when we refactored to make it multiplatform. Another option is to simple break this out into its own "tree viewer" tool in the tools subproject, alongside the formatter.

Src/java/buildSrc/settings.gradle.kts Show resolved Hide resolved
Copy link

sonarcloud bot commented Nov 21, 2024

@vitorpamplona
Copy link
Contributor

Very cool to see all of this!

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