| ... | ... | @@ -81,7 +81,6 @@ pub const Value = union(enum) { |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | pub fn jsonParse(allocator: Allocator, source: anytype, options: ParseOptions) ParseError(@TypeOf(source.*))!@This() { |
| 84 | | _ = options; |
| 85 | 84 | // The grammar of the stack is: |
| 86 | 85 | // (.array | .object .string)* |
| 87 | 86 | var stack = Array.init(allocator); |
| ... | ... | @@ -93,21 +92,21 @@ pub const Value = union(enum) { |
| 93 | 92 | stack.items[stack.items.len - 1] == .array or |
| 94 | 93 | (stack.items[stack.items.len - 2] == .object and stack.items[stack.items.len - 1] == .string)); |
| 95 | 94 | |
| 96 | | switch (try source.nextAlloc(allocator, .alloc_always)) { |
| 95 | switch (try source.nextAllocMax(allocator, .alloc_always, options.max_value_len.?)) { |
| 97 | 96 | .allocated_string => |s| { |
| 98 | | return try handleCompleteValue(&stack, allocator, source, Value{ .string = s }) orelse continue; |
| 97 | return try handleCompleteValue(&stack, allocator, source, Value{ .string = s }, options) orelse continue; |
| 99 | 98 | }, |
| 100 | 99 | .allocated_number => |slice| { |
| 101 | | return try handleCompleteValue(&stack, allocator, source, Value.parseFromNumberSlice(slice)) orelse continue; |
| 100 | return try handleCompleteValue(&stack, allocator, source, Value.parseFromNumberSlice(slice), options) orelse continue; |
| 102 | 101 | }, |
| 103 | 102 | |
| 104 | | .null => return try handleCompleteValue(&stack, allocator, source, .null) orelse continue, |
| 105 | | .true => return try handleCompleteValue(&stack, allocator, source, Value{ .bool = true }) orelse continue, |
| 106 | | .false => return try handleCompleteValue(&stack, allocator, source, Value{ .bool = false }) orelse continue, |
| 103 | .null => return try handleCompleteValue(&stack, allocator, source, .null, options) orelse continue, |
| 104 | .true => return try handleCompleteValue(&stack, allocator, source, Value{ .bool = true }, options) orelse continue, |
| 105 | .false => return try handleCompleteValue(&stack, allocator, source, Value{ .bool = false }, options) orelse continue, |
| 107 | 106 | |
| 108 | 107 | .object_begin => { |
| 109 | | switch (try source.nextAlloc(allocator, .alloc_always)) { |
| 110 | | .object_end => return try handleCompleteValue(&stack, allocator, source, Value{ .object = ObjectMap.init(allocator) }) orelse continue, |
| 108 | switch (try source.nextAllocMax(allocator, .alloc_always, options.max_value_len.?)) { |
| 109 | .object_end => return try handleCompleteValue(&stack, allocator, source, Value{ .object = ObjectMap.init(allocator) }, options) orelse continue, |
| 111 | 110 | .allocated_string => |key| { |
| 112 | 111 | try stack.appendSlice(&[_]Value{ |
| 113 | 112 | Value{ .object = ObjectMap.init(allocator) }, |
| ... | ... | @@ -120,7 +119,7 @@ pub const Value = union(enum) { |
| 120 | 119 | .array_begin => { |
| 121 | 120 | try stack.append(Value{ .array = Array.init(allocator) }); |
| 122 | 121 | }, |
| 123 | | .array_end => return try handleCompleteValue(&stack, allocator, source, stack.pop()) orelse continue, |
| 122 | .array_end => return try handleCompleteValue(&stack, allocator, source, stack.pop(), options) orelse continue, |
| 124 | 123 | |
| 125 | 124 | else => unreachable, |
| 126 | 125 | } |
| ... | ... | @@ -134,7 +133,7 @@ pub const Value = union(enum) { |
| 134 | 133 | } |
| 135 | 134 | }; |
| 136 | 135 | |
| 137 | | fn handleCompleteValue(stack: *Array, allocator: Allocator, source: anytype, value_: Value) !?Value { |
| 136 | fn handleCompleteValue(stack: *Array, allocator: Allocator, source: anytype, value_: Value, options: ParseOptions) !?Value { |
| 138 | 137 | if (stack.items.len == 0) return value_; |
| 139 | 138 | var value = value_; |
| 140 | 139 | while (true) { |
| ... | ... | @@ -152,7 +151,7 @@ fn handleCompleteValue(stack: *Array, allocator: Allocator, source: anytype, val |
| 152 | 151 | |
| 153 | 152 | // This is an invalid state to leave the stack in, |
| 154 | 153 | // so we have to process the next token before we return. |
| 155 | | switch (try source.nextAlloc(allocator, .alloc_always)) { |
| 154 | switch (try source.nextAllocMax(allocator, .alloc_always, options.max_value_len.?)) { |
| 156 | 155 | .object_end => { |
| 157 | 156 | // This object is complete. |
| 158 | 157 | value = stack.pop(); |