| ... | @@ -4,7 +4,8 @@ pub const Value = union(enum) { | ... | @@ -4,7 +4,8 @@ pub const Value = union(enum) { |
| 4 | Object: []Member, | 4 | Object: []Member, |
| 5 | Array: []Value, | 5 | Array: []Value, |
| 6 | String: []const u8, | 6 | String: []const u8, |
| 7 | Number: f64, | 7 | Int: i64, |
| | 8 | Float: f64, |
| 8 | Bool: bool, | 9 | Bool: bool, |
| 9 | Null: void, | 10 | Null: void, |
| 10 | | 11 | |
| ... | @@ -81,8 +82,11 @@ pub const Value = union(enum) { | ... | @@ -81,8 +82,11 @@ pub const Value = union(enum) { |
| 81 | .String => { | 82 | .String => { |
| 82 | try writer.print("\"{s}\"", .{self.String}); | 83 | try writer.print("\"{s}\"", .{self.String}); |
| 83 | }, | 84 | }, |
| 84 | .Number => { | 85 | .Int => { |
| 85 | try writer.print("{}", .{self.Number}); | 86 | try writer.print("{d}", .{self.Int}); |
| | 87 | }, |
| | 88 | .Float => { |
| | 89 | try writer.print("{}", .{self.Float}); |
| 86 | }, | 90 | }, |
| 87 | .Bool => { | 91 | .Bool => { |
| 88 | try writer.print("{}", .{self.Bool}); | 92 | try writer.print("{}", .{self.Bool}); |
| ... | @@ -139,6 +143,7 @@ const Parser = struct { | ... | @@ -139,6 +143,7 @@ const Parser = struct { |
| 139 | std.fs.File.OpenError || | 143 | std.fs.File.OpenError || |
| 140 | std.json.StreamingParser.Error || | 144 | std.json.StreamingParser.Error || |
| 141 | std.mem.Allocator.Error || | 145 | std.mem.Allocator.Error || |
| | 146 | error{ Overflow } || |
| 142 | error{InvalidCharacter} || | 147 | error{InvalidCharacter} || |
| 143 | error{ JsonExpectedObjKey, JsonExpectedValueStartGotEnd }; | 148 | error{ JsonExpectedObjKey, JsonExpectedValueStartGotEnd }; |
| 144 | }; | 149 | }; |
| ... | @@ -162,7 +167,8 @@ fn parse_value(p: *Parser, start: ?std.json.Token) Parser.Error!Value { | ... | @@ -162,7 +167,8 @@ fn parse_value(p: *Parser, start: ?std.json.Token) Parser.Error!Value { |
| 162 | .ArrayBegin => Value{ .Array = try parse_array(p) }, | 167 | .ArrayBegin => Value{ .Array = try parse_array(p) }, |
| 163 | .ArrayEnd => error.JsonExpectedValueStartGotEnd, | 168 | .ArrayEnd => error.JsonExpectedValueStartGotEnd, |
| 164 | .String => |t| Value{ .String = t.slice(p.input, p.index - 1) }, | 169 | .String => |t| Value{ .String = t.slice(p.input, p.index - 1) }, |
| 165 | .Number => |t| Value{ .Number = try std.fmt.parseFloat(f64, t.slice(p.input, p.index - 1)) }, | 170 | .Number => |t| if (t.is_integer) Value{ .Int = try std.fmt.parseInt(i64, t.slice(p.input, p.index - 1), 10) } |
| | 171 | else Value{ .Float = try std.fmt.parseFloat(f64, t.slice(p.input, p.index - 1)) }, |
| 166 | .True => Value{ .Bool = true }, | 172 | .True => Value{ .Bool = true }, |
| 167 | .False => Value{ .Bool = false }, | 173 | .False => Value{ .Bool = false }, |
| 168 | .Null => Value{ .Null = {} }, | 174 | .Null => Value{ .Null = {} }, |