authorgravatar for hello@nektro.netMeghan <hello@nektro.net> 2021-07-17 08:10:00 -07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2021-07-17 08:10:00 -07:00
log72e555fbc0776f2600aee19b01e5ab1855ebec7a
tree95070ed7c7856230c7b879aa96e40c423afd8ed1
parent659906406fbbadf415aa56718f49da8febd4f3c8
parentcf61dba709bf7fe7ced84404017b03302ab8a8a5
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #2 from TRcorp/master

Numerical change

1 files changed, 10 insertions(+), 4 deletions(-)

src/lib.zig+10-4
...@@ -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,
1011
...@@ -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 = {} },