| ... | @@ -3,7 +3,7 @@ const string = []const u8; | ... | @@ -3,7 +3,7 @@ const string = []const u8; |
| 3 | const extras = @import("extras"); | 3 | const extras = @import("extras"); |
| 4 | const tracer = @import("tracer"); | 4 | const tracer = @import("tracer"); |
| 5 | | 5 | |
| 6 | const Error = std.mem.Allocator.Error || error{ MalformedJson, EndOfStream }; | 6 | const Error = error{ OutOfMemory, EndOfStream, MalformedJson }; |
| 7 | const ObjectHashMap = std.AutoArrayHashMapUnmanaged(StringIndex, ValueIndex); | 7 | const ObjectHashMap = std.AutoArrayHashMapUnmanaged(StringIndex, ValueIndex); |
| 8 | | 8 | |
| 9 | pub fn parse(alloc: std.mem.Allocator, path: string, inreader: anytype, options: Parser.Options) (@TypeOf(inreader).Error || Error)!Document { | 9 | pub fn parse(alloc: std.mem.Allocator, path: string, inreader: anytype, options: Parser.Options) (@TypeOf(inreader).Error || Error)!Document { |
| ... | @@ -28,7 +28,8 @@ pub fn parse(alloc: std.mem.Allocator, path: string, inreader: anytype, options: | ... | @@ -28,7 +28,8 @@ pub fn parse(alloc: std.mem.Allocator, path: string, inreader: anytype, options: |
| 28 | std.debug.assert(try p.addArray(alloc, &.{}) == .empty_array); | 28 | std.debug.assert(try p.addArray(alloc, &.{}) == .empty_array); |
| 29 | std.debug.assert(try p.addObject(alloc, &ObjectHashMap{}) == .empty_object); | 29 | std.debug.assert(try p.addObject(alloc, &ObjectHashMap{}) == .empty_object); |
| 30 | | 30 | |
| 31 | const root = parseElement(alloc, &p) catch |err| return @errorCast(err); | 31 | const root_err: (@TypeOf(inreader).Error || Error)!ValueIndex = @errorCast(parseElement(alloc, &p)); |
| | 32 | const root = try root_err; |
| 32 | if (p.avail() > 0) return error.MalformedJson; | 33 | if (p.avail() > 0) return error.MalformedJson; |
| 33 | const data = try p.extras.toOwnedSlice(alloc); | 34 | const data = try p.extras.toOwnedSlice(alloc); |
| 34 | | 35 | |
| ... | @@ -351,10 +352,10 @@ const Parser = struct { | ... | @@ -351,10 +352,10 @@ const Parser = struct { |
| 351 | | 352 | |
| 352 | pub fn shift(p: *Parser) !u21 { | 353 | pub fn shift(p: *Parser) !u21 { |
| 353 | try p.peekAmt(1) orelse return error.EndOfStream; | 354 | try p.peekAmt(1) orelse return error.EndOfStream; |
| 354 | const len = try std.unicode.utf8ByteSequenceLength(p.slice()[0]); | 355 | const len = std.unicode.utf8ByteSequenceLength(p.slice()[0]) catch return error.MalformedJson; |
| 355 | try p.peekAmt(len) orelse return error.EndOfStream; | 356 | try p.peekAmt(len) orelse return error.EndOfStream; |
| 356 | defer p.idx += len; | 357 | defer p.idx += len; |
| 357 | return std.unicode.utf8Decode(p.slice()[0..len]); | 358 | return std.unicode.utf8Decode(p.slice()[0..len]) catch return error.MalformedJson; |
| 358 | } | 359 | } |
| 359 | | 360 | |
| 360 | pub fn shiftBytesN(p: *Parser, comptime n: usize) ![n]u8 { | 361 | pub fn shiftBytesN(p: *Parser, comptime n: usize) ![n]u8 { |