Add support for (de)serializing infinite numbers#2
Add support for (de)serializing infinite numbers#2EthanRStokes wants to merge 3 commits intoExJson:mainfrom
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.
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.
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.
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?