authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-05-24 04:40:06 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-05-24 04:40:06 -07:00
log344139d6e74fafc561780465623529853d1ae778
tree2698977c8f19153684a4917d2501152251c3f739
parent6cf02810b6268ca8542d41271b1897c627d82746

parseWs doesnt need an Allocator parameter


1 files changed, 11 insertions(+), 12 deletions(-)

json.zig+11-12
......@@ -36,9 +36,9 @@ pub fn parse(alloc: std.mem.Allocator, path: string, inreader: anytype) anyerror
3636}
3737
3838fn parseElement(alloc: std.mem.Allocator, p: *Parser) anyerror!ValueIndex {
39 try parseWs(alloc, p);
39 try parseWs(p);
4040 const v = try parseValue(alloc, p);
41 parseWs(alloc, p) catch |err| switch (err) {
41 parseWs(p) catch |err| switch (err) {
4242 error.EndOfStream => {},
4343 else => |e| return e,
4444 };
......@@ -63,21 +63,21 @@ fn parseObject(alloc: std.mem.Allocator, p: *Parser) anyerror!?ValueIndex {
6363 defer members.deinit(alloc);
6464
6565 while (true) {
66 try parseWs(alloc, p);
66 try parseWs(p);
6767 if (try p.eatByte('}')) |_| break;
6868
6969 const key = try parseString(alloc, p) orelse return error.JsonExpectedObjectKey;
70 try parseWs(alloc, p);
70 try parseWs(p);
7171 _ = try p.eatByte(':') orelse return error.JsonExpectedObjectColon;
72 try parseWs(alloc, p);
72 try parseWs(p);
7373 const value = try parseValue(alloc, p);
7474 try members.put(alloc, key, value);
75 try parseWs(alloc, p);
75 try parseWs(p);
7676 _ = try p.eatByte(',') orelse {
7777 _ = try p.eatByte('}') orelse return error.JsonExpectedTODO;
7878 break;
7979 };
80 try parseWs(alloc, p);
80 try parseWs(p);
8181 if (try p.eatByte('}')) |_| break;
8282 }
8383 return try p.addObject(alloc, &members);
......@@ -90,17 +90,17 @@ fn parseArray(alloc: std.mem.Allocator, p: *Parser) anyerror!?ValueIndex {
9090 defer elements.deinit(alloc);
9191
9292 while (true) {
93 try parseWs(alloc, p);
93 try parseWs(p);
9494 if (try p.eatByte(']')) |_| break;
9595
9696 const elem = try parseValue(alloc, p);
9797 try elements.append(alloc, elem);
98 try parseWs(alloc, p);
98 try parseWs(p);
9999 _ = try p.eatByte(',') orelse {
100100 _ = try p.eatByte(']') orelse return error.JsonExpectedTODO;
101101 break;
102102 };
103 try parseWs(alloc, p);
103 try parseWs(p);
104104 if (try p.eatByte(']')) |_| break;
105105 }
106106 return try p.addArray(alloc, elements.items);
......@@ -189,8 +189,7 @@ fn parseNumber(alloc: std.mem.Allocator, p: *Parser) anyerror!?ValueIndex {
189189 return try p.addNumber(alloc, characters.items);
190190}
191191
192fn parseWs(alloc: std.mem.Allocator, p: *Parser) !void {
193 _ = alloc;
192fn parseWs(p: *Parser) !void {
194193 while (true) {
195194 if (try p.eatByte(0x20)) |_| continue; // space
196195 if (try p.eatByte(0x0A)) |_| continue; // NL