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...@@ -36,9 +36,9 @@ pub fn parse(alloc: std.mem.Allocator, path: string, inreader: anytype) anyerror
36}36}
3737
38fn parseElement(alloc: std.mem.Allocator, p: *Parser) anyerror!ValueIndex {38fn parseElement(alloc: std.mem.Allocator, p: *Parser) anyerror!ValueIndex {
39 try parseWs(alloc, p);39 try parseWs(p);
40 const v = try parseValue(alloc, p);40 const v = try parseValue(alloc, p);
41 parseWs(alloc, p) catch |err| switch (err) {41 parseWs(p) catch |err| switch (err) {
42 error.EndOfStream => {},42 error.EndOfStream => {},
43 else => |e| return e,43 else => |e| return e,
44 };44 };
...@@ -63,21 +63,21 @@ fn parseObject(alloc: std.mem.Allocator, p: *Parser) anyerror!?ValueIndex {...@@ -63,21 +63,21 @@ fn parseObject(alloc: std.mem.Allocator, p: *Parser) anyerror!?ValueIndex {
63 defer members.deinit(alloc);63 defer members.deinit(alloc);
6464
65 while (true) {65 while (true) {
66 try parseWs(alloc, p);66 try parseWs(p);
67 if (try p.eatByte('}')) |_| break;67 if (try p.eatByte('}')) |_| break;
6868
69 const key = try parseString(alloc, p) orelse return error.JsonExpectedObjectKey;69 const key = try parseString(alloc, p) orelse return error.JsonExpectedObjectKey;
70 try parseWs(alloc, p);70 try parseWs(p);
71 _ = try p.eatByte(':') orelse return error.JsonExpectedObjectColon;71 _ = try p.eatByte(':') orelse return error.JsonExpectedObjectColon;
72 try parseWs(alloc, p);72 try parseWs(p);
73 const value = try parseValue(alloc, p);73 const value = try parseValue(alloc, p);
74 try members.put(alloc, key, value);74 try members.put(alloc, key, value);
75 try parseWs(alloc, p);75 try parseWs(p);
76 _ = try p.eatByte(',') orelse {76 _ = try p.eatByte(',') orelse {
77 _ = try p.eatByte('}') orelse return error.JsonExpectedTODO;77 _ = try p.eatByte('}') orelse return error.JsonExpectedTODO;
78 break;78 break;
79 };79 };
80 try parseWs(alloc, p);80 try parseWs(p);
81 if (try p.eatByte('}')) |_| break;81 if (try p.eatByte('}')) |_| break;
82 }82 }
83 return try p.addObject(alloc, &members);83 return try p.addObject(alloc, &members);
...@@ -90,17 +90,17 @@ fn parseArray(alloc: std.mem.Allocator, p: *Parser) anyerror!?ValueIndex {...@@ -90,17 +90,17 @@ fn parseArray(alloc: std.mem.Allocator, p: *Parser) anyerror!?ValueIndex {
90 defer elements.deinit(alloc);90 defer elements.deinit(alloc);
9191
92 while (true) {92 while (true) {
93 try parseWs(alloc, p);93 try parseWs(p);
94 if (try p.eatByte(']')) |_| break;94 if (try p.eatByte(']')) |_| break;
9595
96 const elem = try parseValue(alloc, p);96 const elem = try parseValue(alloc, p);
97 try elements.append(alloc, elem);97 try elements.append(alloc, elem);
98 try parseWs(alloc, p);98 try parseWs(p);
99 _ = try p.eatByte(',') orelse {99 _ = try p.eatByte(',') orelse {
100 _ = try p.eatByte(']') orelse return error.JsonExpectedTODO;100 _ = try p.eatByte(']') orelse return error.JsonExpectedTODO;
101 break;101 break;
102 };102 };
103 try parseWs(alloc, p);103 try parseWs(p);
104 if (try p.eatByte(']')) |_| break;104 if (try p.eatByte(']')) |_| break;
105 }105 }
106 return try p.addArray(alloc, elements.items);106 return try p.addArray(alloc, elements.items);
...@@ -189,8 +189,7 @@ fn parseNumber(alloc: std.mem.Allocator, p: *Parser) anyerror!?ValueIndex {...@@ -189,8 +189,7 @@ fn parseNumber(alloc: std.mem.Allocator, p: *Parser) anyerror!?ValueIndex {
189 return try p.addNumber(alloc, characters.items);189 return try p.addNumber(alloc, characters.items);
190}190}
191191
192fn parseWs(alloc: std.mem.Allocator, p: *Parser) !void {192fn parseWs(p: *Parser) !void {
193 _ = alloc;
194 while (true) {193 while (true) {
195 if (try p.eatByte(0x20)) |_| continue; // space194 if (try p.eatByte(0x20)) |_| continue; // space
196 if (try p.eatByte(0x0A)) |_| continue; // NL195 if (try p.eatByte(0x0A)) |_| continue; // NL