Added basic error reporting #14
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In this pull request, I added some basic error reporting, where, if
jsonValue
is unable to parse the given String, then it reports an error saying how many characters it had read in from the String when it encountered the problem, what it was expecting at that character, and what it actually found. For right now, the error reporting is pretty basic, as onlycharP
,stringP
, andparseIf
actually report error messages. Here is an example:In the first command, the
jsonValue
successfully parses the number1
and then leaves thee-s
alone because that exponent part is invalid. However, when we runjsonValue
on an array containing1e-s
, it says we expected a]
when they found thee
. Arguably, it should actually say that the exponent part of the number is invalid, but I think this will require some more complex error handling.Also, as shown above, I report the number of characters the parser has read in so far. However, I had trouble figuring out how to get the number of characters that
reads
had parsed, sincejsonNumber
was implemented usingreads
. (One way to do this was to subtract the length of the whole string by the length of the unparsed input thatreads
returned, but this solution is O(n) where n is the length of the string, which I think is pretty inefficient and clunky.) Therefore, I rewrotejsonNumber
based off the JSON Data Interchange Syntax, so that it could usecharP
,parseIf
, andspanP
, which makes it easier to update the number of characters read in so far.