std.json: Add support for recursive objects to std.json.parse (#9307)

* Add support for recursive objects to std.json.parse

* Remove previously defined error set

* Try with function which returns an error set

* Don't analyze already inferred types

* Add comptime to inferred_type parameter

* Make ParseInternalError to accept only a single argument

* Add public `ParseError` for `parse` function

* Use error.Foo syntax for errors instead of a named error set

* Better formatting

* Update to latest code changes
This commit is contained in:
Dmitry Matveyev
2021-08-20 17:52:48 +06:00
committed by GitHub
parent cfb2827b0a
commit b2e970d157
3 changed files with 132 additions and 5 deletions

View File

@@ -349,7 +349,9 @@ fn caseInEql(a: []const u8, b: []const u8) bool {
return true;
}
pub fn parseFloat(comptime T: type, s: []const u8) !T {
pub const ParseFloatError = error{InvalidCharacter};
pub fn parseFloat(comptime T: type, s: []const u8) ParseFloatError!T {
if (s.len == 0 or (s.len == 1 and (s[0] == '+' or s[0] == '-'))) {
return error.InvalidCharacter;
}