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

Merged
merged 44 commits into from
Dec 4, 2024
Merged

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 95.28986% with 13 lines in your changes missing coverage. Please review.

Project coverage is 66.02%. Comparing base (4226a65) to head (61ea9a5).
Report is 21 commits behind head on feature-kotlin.

Files with missing lines Patch % Lines
...ava/org/cqframework/cql/cql2elm/CqlTranslator.java 50.00% 6 Missing ⚠️
...lm/preprocessor/CqlPreprocessorElmCommonVisitor.kt 14.28% 0 Missing and 6 partials ⚠️
...in/java/org/cqframework/cql/elm/IdObjectFactory.kt 99.57% 1 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                  @@
##             feature-kotlin    #1443      +/-   ##
====================================================
+ Coverage             64.47%   66.02%   +1.54%     
- Complexity             2180     3001     +821     
====================================================
  Files                   492      486       -6     
  Lines                 27972    28447     +475     
  Branches               5537     5463      -74     
====================================================
+ Hits                  18036    18782     +746     
+ Misses                 7701     7467     -234     
+ Partials               2235     2198      -37     

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

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 Outdated Show resolved Hide resolved
@vitorpamplona
Copy link
Contributor

Very cool to see all of this!

@JPercival JPercival changed the base branch from master to feature-kotlin December 2, 2024 16:16
Copy link

sonarcloud bot commented Dec 4, 2024

@JPercival JPercival merged commit 14102fe into feature-kotlin Dec 4, 2024
7 checks passed
@JPercival JPercival deleted the feature-multiplatform-cql-parser branch December 4, 2024 16:58
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