-
Notifications
You must be signed in to change notification settings - Fork 60
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
JSON5 Support #152
JSON5 Support #152
Conversation
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.
Hi @dhilst. Thanks for your effort! It's quite a lot of code, so I expect we'll need some iterations on that. I took a first look through the code and wrote some suggestions on how to improve. I haven't tried the code yet, so this is just a cursory view with my impressions.
Since we're not using CPPO in this part of the codebase, I think it would be reasonable to add OCamlformat support to it, disable it and only enable it in the new part of the codebase, so we won't have to discuss style and formatting. I have found the experience of not dealing with that save a lot of time and nerves (and also being able to write code in any way and then have ocamlformat
make it look good was useful).
Looking at the CI it looks that some code is failing on older versions. Given this PR uses sedlex we have to restrict the minimum version of this subpackage to OCaml 4.08 (which I think is completely ok) and make sure the library and tests are only part of the yojson_json5
package (this can be done in the dune
files). That should solve at least some of the minimum version failures.
I remember @gorm-issuu had some discussions about escape sequences in strings with @andersfugmann. Gorm, do you remember what the point in question was?
@Leonidas-from-XIV thank you for the review, I will address the comments and let you know when it's ready for review again! |
I do vaguely remember some discussions about escape sequences, but forgot the details. |
The problem with ocamllex is that it is not unicode-aware and the JSON5 spec specifies that the sequences are unicode. I am sure this can be hacked in ocamllex, but the advantage of using sedlex in this case is that the lexer can be basically lifted out of the JSON5 specification with all the Unicode codepoints specified, instead of attempting to match on potentially multi-byte characters. Also, ocamllex has the disadvantage that the |
Hi @Leonidas-from-XIV I would like to ask for another review, I addressed the comments. Something that caught my attention is |
2c88737
to
e52402d
Compare
|
Oh it seems that I need to rebase, the master has dung-lang > 2.0 so I should get formating for free by rebasing |
6005f94
to
7cfc654
Compare
I have this error on the CI
I think this is because the |
Yes, also if you take a look at this PR you'll see ocamlformat being enabled (since I realized we can already enable it for the tests). I hope to merge it soon, so you'll be able to rebase on master and get the config and all set up. |
I checked out the tests and they are not being run, so I needed to add this
At which point the tests ran successfully. The failures in the CI are happening on older versions where |
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.
Some more tips & suggestions. Sorry for the parallel work going on in the other PRs which might need to some rebasing once they're done, but I hope it shouldn't be too bad.
lib/json5/yojson_json5.mli
Outdated
@@ -0,0 +1,101 @@ | |||
module Safe : sig | |||
type t = Yojson.Safe.t | |||
type result := (t, string) Result.t |
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.
I would try to avoid this alias, in case people unwisely do open
since it clashes with the built-in ('a, 'e) result
type.
test/json5/json5_test.ml
Outdated
end | ||
let yojson_json5 = Alcotest.testable M.pp M.equal | ||
|
||
let test_pp () = |
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 appears to be unused?
lib/json5/lexer.ml
Outdated
|
||
let escape_sequence = | ||
[%sedlex.regexp? character_escape_sequence | '0' | unicode_escape_sequence] | ||
(* TODO *) |
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.
There is still this TODO.
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.
I remove the TODO it seems to be remaining.
Thanks for the review @Leonidas-from-XIV I will address the comments and let you know when it's ready for another review round! |
da4a0f1
to
cf03600
Compare
Hello @Leonidas-from-XIV, this PR is ready for review again. If the code is okay I think I can focus on doing more tests in the next round, what do you think? |
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.
Thanks! Looks like we're reaching the home stretch. I looked up the TODO in the spec and found a missing part (that would be nice to add as a test), but apart from that it's mostly cosmetic changes.
f824843
to
8e77ded
Compare
703d505
to
59659e2
Compare
I fixed the conflict! You can try it by pinning the branch with opam, you can check the Maybe this is a good time to talk about documentation as I didn't touch the documentation at all |
I looked at the code and it looks pretty good. I can't comment on the sedlex part because I don't know sedlex, but it'd be good to get JSON5 support and not delay this much further imvho. |
@dhilst I tried pushing some fixes on top of your branch but I don't have the permission. Could you contact GH to reroute your fork from issuu/yojson to ocaml-community/yojson? They have a form for that, in the meantime I've temporarily created #176 with my changes. |
|
The lexer should return a string, no need to add double or single quotes when lexing, they are not the content of the string.
0dc2ce4
to
5a81430
Compare
Looks like the remaining CI failures are unrelated to this PR, fixed the multiple dangling comma issue, so I think this is ready to go. Thanks to @dhilst @gertsonderby @gorm-issuu @c-cube for contributing and reviewing. I think this should be good to be released as part of Yojson 2.2. |
2f1d378
into
ocaml-community:master
Thanks a lot to everyone involved in this PR! This will be a huge quality of life improvement for dealing with handwritten json config files! |
CHANGES: *2024-05-31* ### Added - Added support for JSON5 (@dhilst, @gorm-issuu, @gertsonderby, ocaml-community/yojson#152) ### Removed - Remove CPPO dependency to make the Yojson installation lighter (@Leonidas-from-XIV, ocaml-community/yojson#175)
CHANGES: *2024-05-31* ### Added - Added support for JSON5 (@dhilst, @gorm-issuu, @gertsonderby, ocaml-community/yojson#152) ### Removed - Remove CPPO dependency to make the Yojson installation lighter (@Leonidas-from-XIV, ocaml-community/yojson#175)
Hello,
This MR creates a Yojson_json5 library on top of Yojson adding support for JSON5, it's based on the work of @gorm-issuu and @gertsonderby
It's regarding #106
I have a primary interface for parsing strings, files, and channels to
Yojson.Safe.t
Yojson.Basic.t
andYojson.Raw.t
, the comments are dropped. OCaml is new to me I would like to ask for help with the next steps.