-
Notifications
You must be signed in to change notification settings - Fork 2
Add support for (de)serializing infinite numbers #2
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
base: main
Are you sure you want to change the base?
Conversation
|
I like this idea. Since the specifications for DJS are not finalized, it is definitely possible for us to add additional token types at this point. However, DJS is designed as a subset of XJS. Thus, any tokens in DJS must also be legal in XJS. If I were to support infinity, it would most likely be a lowercase In regards to supporting I am not positive yet whether it is ideal to include an infinity token in DJS. This will need more discussion. Pinging @dshadowwolf. I may merge these changes in the future (before 1.0), but will need to put some thought into it. In the meantime, I think it would be appropriate to support this feature as a DSL extension. We would need some kind of Here's my initial thought on how to implement that:
Perhaps this solution is not ideal. I am open to suggestions. Let's also discuss the implications of adding new tokens into the specifications. If we're changing this now, we need an official BNF or other spec to start with. |
| assertEquals(12.34, this.parse("12.34").asDouble()); | ||
| } | ||
|
|
||
| @Test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to go in DjsParserTest since it should not apply to JSON or other formats.
| } | ||
|
|
||
| @Test | ||
| public void write_printsInfiniteNumbers() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Infinity is not a reserved keyword in JSON format and should not be supported by the JSON serializers.
| } | ||
| final String text = t.parsed(); | ||
| return switch (text) { | ||
| case "Infinity" -> new JsonNumber(Double.POSITIVE_INFINITY); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments in thread
Also remove json tests, but I think it still works in json
I am attempting to add support for serializing and deserializing infinite numbers (
Double.POSITIVE_INFINITYandDouble.NEGATIVE_INFINITY)The output should be
Infinityand-InfinityImplementation may be a bit weird because it still treats Infinity as a
WORDtoken type. Also, since it is hardcoded into the Djs parser, other parsers don't have support.If I can make the token stream treat infinite numbers as a number token then everything would be fine.
Anyway, what do you think?