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

json lazy parser unparser and support for reading NULL values. #1978

Open
wants to merge 34 commits into
base: main
Choose a base branch
from

Conversation

jurgenvinju
Copy link
Member

@jurgenvinju jurgenvinju commented Jun 17, 2024

This is a new feature of the JSON serializer/deserializer; it allows us to serialize to JSON, but at given places in an algebraic data-type map the contents to JSON strings, and back parse them back to ADTs when we receive a string input.

@tvdstorm this should come in handy for salix and the vis::* library when we have more structure in Rascal than we have on the JS/TS side. Could you have a look?

I plan to use this myself to improve the styling feature in the cytoscape.js library, which uses a small string-based embedded DSL for node and edge selectors. https://js.cytoscape.org/#selectors EDIT: did that on this branch to demonstrate what you can do with the formatter/parser extension to the JSON IO library.

Copy link

codecov bot commented Jun 17, 2024

Codecov Report

Attention: Patch coverage is 33.58779% with 261 lines in your changes missing coverage. Please review.

Project coverage is 49%. Comparing base (572a62d) to head (b6782ee).
Report is 28 commits behind head on main.

Files Patch % Lines
...pl/library/lang/json/internal/JsonValueReader.java 30% 215 Missing and 21 partials ⚠️
...pl/library/lang/json/internal/JsonValueWriter.java 40% 5 Missing and 4 partials ⚠️
src/org/rascalmpl/library/lang/json/IO.java 69% 3 Missing and 1 partial ⚠️
.../rascalmpl/exceptions/RuntimeExceptionFactory.java 0% 3 Missing ⚠️
src/org/rascalmpl/values/maybe/UtilMaybe.java 76% 3 Missing ⚠️
src/org/rascalmpl/library/util/TermREPL.java 0% 2 Missing ⚠️
src/org/rascalmpl/library/util/Webserver.java 0% 2 Missing ⚠️
src/org/rascalmpl/repl/REPLContentServer.java 0% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##              main   #1978    +/-   ##
========================================
  Coverage       49%     49%            
- Complexity    6297    6325    +28     
========================================
  Files          664     665     +1     
  Lines        59558   59690   +132     
  Branches      8639    8656    +17     
========================================
+ Hits         29437   29594   +157     
+ Misses       27908   27862    -46     
- Partials      2213    2234    +21     

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

@jurgenvinju jurgenvinju self-assigned this Jun 17, 2024
@jurgenvinju jurgenvinju marked this pull request as ready for review June 17, 2024 20:17
@jurgenvinju
Copy link
Member Author

@tvdstorm I added the null values here. Do you fancy the solution?

@jurgenvinju
Copy link
Member Author

Since this adds parameters to Java methods we have to wait until after the current release cycle to merge this.

@jurgenvinju jurgenvinju changed the title json lazy parser unparser json lazy parser unparser and support for reading NULL values. Jun 26, 2024
@DavyLandman
Copy link
Member

DavyLandman commented Jul 4, 2024

A lot of things are happening in this PR, and I'm missing:

Copy link
Member

@DavyLandman DavyLandman left a comment

Choose a reason for hiding this comment

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

The changes to JsonValueReader are hard to oversee, it mostly looks fine, but I would want to take some time and test the impact on VS Code and it's use of the JsonValueReader class.

@@ -164,7 +164,7 @@
<configuration>
<isPackageCourse>false</isPackageCourse>
<enableStandardLibrary>false</enableStandardLibrary>
<errorsAsWarnings>false</errorsAsWarnings>
<errorsAsWarnings>true</errorsAsWarnings>
Copy link
Member

Choose a reason for hiding this comment

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

do we want this as part of this PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is necessary for bootstrapping the tutor


data Cons = cons(str bla = "null");

test bool dealWithNull() {
Copy link
Member

Choose a reason for hiding this comment

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

seeing the changes in JsonIOReader, I expected more tests.

Copy link
Member Author

Choose a reason for hiding this comment

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

Tests are missing for the formatter/parser functionality. I'll add simple tests later.

The feature has been tested in-depth with the vis::Graph module (which was the primary motivation)

@jurgenvinju
Copy link
Member Author

The changes to JsonValueReader are hard to oversee, it mostly looks fine, but I would want to take some time and test the impact on VS Code and it's use of the JsonValueReader class.

The changes have been designed such that there can't be impact on existing uses of the JSON IO clients, unless they were waiting for NPEs for inputs with null inside. Those exceptions will not be thrown anymore and values will be constructed to represent those null values.

Recommend to focus on that distintion. Typically catch( NullpointerException e) in java or catch Java("NullpointerException") in Rascal.

@jurgenvinju
Copy link
Member Author

The other changes are only activated by providing new actual keyword parameters to format datatypes to string or parse strings to datatypes. If not provided the code behaves as before.

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.

2 participants