| ... | @@ -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 | } |
| 37 | | 37 | |
| 38 | fn parseElement(alloc: std.mem.Allocator, p: *Parser) anyerror!ValueIndex { | 38 | fn 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); |
| 64 | | 64 | |
| 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; |
| 68 | | 68 | |
| 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); |
| 91 | | 91 | |
| 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; |
| 95 | | 95 | |
| 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 | } |
| 191 | | 191 | |
| 192 | fn parseWs(alloc: std.mem.Allocator, p: *Parser) !void { | 192 | fn parseWs(p: *Parser) !void { |
| 193 | _ = alloc; | | |
| 194 | while (true) { | 193 | while (true) { |
| 195 | if (try p.eatByte(0x20)) |_| continue; // space | 194 | if (try p.eatByte(0x20)) |_| continue; // space |
| 196 | if (try p.eatByte(0x0A)) |_| continue; // NL | 195 | if (try p.eatByte(0x0A)) |_| continue; // NL |