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

Improve the error messages displayed by the JSON5 lexer and parser. #182

Merged

Conversation

gcluzel
Copy link
Contributor

@gcluzel gcluzel commented Jun 7, 2024

Since JSON5 is a standard intended to parse JSON written by humans, it's a bit unfortunate that the error messages were not very descriptive.
I tried to make them closer to the ones displayed by the classic YoJson parser. Also, when it's available, the line where the error message is located is displayed.

* Display the line number in the error message
* Try to harmonize the error messages with the ones displayed by
  the classic yojson parser.
CHANGES.md Outdated Show resolved Hide resolved
lib/json5/lexer.ml Outdated Show resolved Hide resolved
lib/json5/lexer.ml Outdated Show resolved Hide resolved
lib/json5/lexer.ml Outdated Show resolved Hide resolved
lib/json5/parser.ml Outdated Show resolved Hide resolved
lib/json5/parser.ml Show resolved Hide resolved
@Leonidas-from-XIV
Copy link
Member

Thanks for the PR, it's definitely useful to have some better error messages. Can you add some tests for the error messages so that we know they are working fine and how they look? That will also serve as regression test.

@gcluzel
Copy link
Contributor Author

gcluzel commented Jun 9, 2024

Thanks for the review.
I have added 4 tests, I let you tell me if you think that it's worth adding other tests. Note that there already are tests that test the parsing error case, they just don't check the error messages displayed in those cases.

@Leonidas-from-XIV
Copy link
Member

I think this is good for now. If you want to add more tests you're welcome. The CI failures are known and I have opened ocaml/opam-repository#26154 and ocaml/opam-repository#26156 to solve them but they are unrelated to the PR. Merging.

Thanks for your contribution!

@Leonidas-from-XIV Leonidas-from-XIV merged commit 93f3496 into ocaml-community:master Jun 27, 2024
3 of 4 checks passed
Leonidas-from-XIV added a commit to Leonidas-from-XIV/opam-repository that referenced this pull request Jun 27, 2024
CHANGES:

*2024-06-27*

### Added

- Add locations in the JSON5 parser error messages (@gcluzel, ocaml-community/yojson#182)
avsm pushed a commit to avsm/opam-repository that referenced this pull request Sep 5, 2024
CHANGES:

*2024-06-27*

### Added

- Add locations in the JSON5 parser error messages (@gcluzel, ocaml-community/yojson#182)
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