| author | |
| committer | |
| log | 6cf02810b6268ca8542d41271b1897c627d82746 |
| tree | 831bbebdfa3981c2aa695b9a0931d0e5d29d69d8 |
| parent | b2abe69ab629432c456cbf737de7f52ce8c1f8b0 |
6 files changed, 677 insertions(+), 12 deletions(-)
README.md+5-3| ... | @@ -1,20 +1,22 @@ | ... | @@ -1,20 +1,22 @@ |
| 1 | # zig-json | 1 | # zig-json |
| 2 |  | 2 |  |
| 3 | [](https://github.com/nektro/zig-json/blob/master/LICENSE) | 3 | [](https://github.com/nektro/zig-json/blob/master/LICENSE) |
| 4 | [](https://discord.gg/P6Y4zQC) | ||
| 5 | 4 | ||
| 6 | A JSON library for inspecting arbitrary values. | 5 | A JSON library for inspecting arbitrary values. Accepts trailing commas. |
| 7 | 6 | ||
| 8 | ## Usage | 7 | ## Usage |
| 9 | See `src/main.zig` for an example. | 8 | |
| 9 | See `test.zig` for an example. | ||
| 10 | 10 | ||
| 11 | ## Building Example Program | 11 | ## Building Example Program |
| 12 | |||
| 12 | ``` | 13 | ``` |
| 13 | $ zigmod fetch | 14 | $ zigmod fetch |
| 14 | $ zig build | 15 | $ zig build |
| 15 | ``` | 16 | ``` |
| 16 | 17 | ||
| 17 | ## Built With | 18 | ## Built With |
| 19 | |||
| 18 | - Zig Master & [Zigmod Package Manager](https://github.com/nektro/zigmod) | 20 | - Zig Master & [Zigmod Package Manager](https://github.com/nektro/zigmod) |
| 19 | 21 | ||
| 20 | ## License | 22 | ## License |
build.zig+7-9| ... | @@ -5,19 +5,17 @@ pub fn build(b: *std.Build) void { | ... | @@ -5,19 +5,17 @@ pub fn build(b: *std.Build) void { |
| 5 | const target = b.standardTargetOptions(.{}); | 5 | const target = b.standardTargetOptions(.{}); |
| 6 | const mode = b.option(std.builtin.Mode, "mode", "") orelse .Debug; | 6 | const mode = b.option(std.builtin.Mode, "mode", "") orelse .Debug; |
| 7 | 7 | ||
| 8 | const exe = b.addTest(.{ | 8 | const test_exe = b.addTest(.{ |
| 9 | .root_source_file = b.path("test.zig"), | 9 | .root_source_file = b.path("test.zig"), |
| 10 | .target = target, | 10 | .target = target, |
| 11 | .optimize = mode, | 11 | .optimize = mode, |
| 12 | }); | 12 | }); |
| 13 | deps.addAllTo(exe); | 13 | deps.addAllTo(test_exe); |
| 14 | 14 | ||
| 15 | const run_cmd = b.addRunArtifact(exe); | 15 | const test_cmd = b.addRunArtifact(test_exe); |
| 16 | run_cmd.step.dependOn(b.getInstallStep()); | 16 | test_cmd.has_side_effects = true; |
| 17 | if (b.args) |args| { | 17 | test_cmd.step.dependOn(b.getInstallStep()); |
| 18 | run_cmd.addArgs(args); | ||
| 19 | } | ||
| 20 | 18 | ||
| 21 | const run_step = b.step("test", "Run the tests"); | 19 | const test_step = b.step("test", "Run the tests"); |
| 22 | run_step.dependOn(&run_cmd.step); | 20 | test_step.dependOn(&test_cmd.step); |
| 23 | } | 21 | } |
json.zig+402| ... | @@ -1 +1,403 @@ | ... | @@ -1 +1,403 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const string = []const u8; | ||
| 3 | const extras = @import("extras"); | ||
| 4 | const tracer = @import("tracer"); | ||
| 5 | |||
| 6 | const buf_size = 64; | ||
| 7 | const Error = std.mem.Allocator.Error; | ||
| 8 | const ObjectHashMap = std.AutoArrayHashMapUnmanaged(StringIndex, ValueIndex); | ||
| 9 | |||
| 10 | pub fn parse(alloc: std.mem.Allocator, path: string, inreader: anytype) anyerror!Document { | ||
| 11 | const t = tracer.trace(@src(), "", .{}); | ||
| 12 | defer t.end(); | ||
| 13 | |||
| 14 | _ = path; | ||
| 15 | |||
| 16 | var counter = std.io.countingReader(inreader); | ||
| 17 | var buf = std.io.bufferedReader(counter.reader()); | ||
| 18 | const anyreader = extras.AnyReader.from(buf.reader()); | ||
| 19 | var p = Parser.init(alloc, anyreader); | ||
| 20 | defer p.temp.deinit(alloc); | ||
| 21 | defer p.strings_map.deinit(alloc); | ||
| 22 | errdefer p.extras.deinit(alloc); | ||
| 23 | |||
| 24 | comptime std.debug.assert(@intFromEnum(Value.zero) == 0); | ||
| 25 | try p.extras.ensureUnusedCapacity(alloc, std.mem.page_size); | ||
| 26 | p.extras.appendAssumeCapacity(@intFromEnum(Value.Tag.zero)); | ||
| 27 | p.extras.appendAssumeCapacity(@intFromEnum(Value.Tag.null)); | ||
| 28 | p.extras.appendAssumeCapacity(@intFromEnum(Value.Tag.true)); | ||
| 29 | p.extras.appendAssumeCapacity(@intFromEnum(Value.Tag.false)); | ||
| 30 | _ = try p.addStr(alloc, ""); | ||
| 31 | |||
| 32 | return .{ | ||
| 33 | .root = try parseElement(alloc, &p), | ||
| 34 | .extras = try p.extras.toOwnedSlice(alloc), | ||
| 35 | }; | ||
| 36 | } | ||
| 37 | |||
| 38 | fn parseElement(alloc: std.mem.Allocator, p: *Parser) anyerror!ValueIndex { | ||
| 39 | try parseWs(alloc, p); | ||
| 40 | const v = try parseValue(alloc, p); | ||
| 41 | parseWs(alloc, p) catch |err| switch (err) { | ||
| 42 | error.EndOfStream => {}, | ||
| 43 | else => |e| return e, | ||
| 44 | }; | ||
| 45 | return v; | ||
| 46 | } | ||
| 47 | |||
| 48 | fn parseValue(alloc: std.mem.Allocator, p: *Parser) anyerror!ValueIndex { | ||
| 49 | if (try p.eat("null")) |_| return @enumFromInt(1); | ||
| 50 | if (try p.eat("true")) |_| return @enumFromInt(2); | ||
| 51 | if (try p.eat("false")) |_| return @enumFromInt(3); | ||
| 52 | if (try parseNumber(alloc, p)) |v| return v; | ||
| 53 | if (try parseString(alloc, p)) |v| return @enumFromInt(@intFromEnum(v)); | ||
| 54 | if (try parseArray(alloc, p)) |v| return v; | ||
| 55 | if (try parseObject(alloc, p)) |v| return v; | ||
| 56 | return error.JsonExpectedValue; | ||
| 57 | } | ||
| 58 | |||
| 59 | fn parseObject(alloc: std.mem.Allocator, p: *Parser) anyerror!?ValueIndex { | ||
| 60 | _ = try p.eatByte('{') orelse return null; | ||
| 61 | |||
| 62 | var members = ObjectHashMap{}; | ||
| 63 | defer members.deinit(alloc); | ||
| 64 | |||
| 65 | while (true) { | ||
| 66 | try parseWs(alloc, p); | ||
| 67 | if (try p.eatByte('}')) |_| break; | ||
| 68 | |||
| 69 | const key = try parseString(alloc, p) orelse return error.JsonExpectedObjectKey; | ||
| 70 | try parseWs(alloc, p); | ||
| 71 | _ = try p.eatByte(':') orelse return error.JsonExpectedObjectColon; | ||
| 72 | try parseWs(alloc, p); | ||
| 73 | const value = try parseValue(alloc, p); | ||
| 74 | try members.put(alloc, key, value); | ||
| 75 | try parseWs(alloc, p); | ||
| 76 | _ = try p.eatByte(',') orelse { | ||
| 77 | _ = try p.eatByte('}') orelse return error.JsonExpectedTODO; | ||
| 78 | break; | ||
| 79 | }; | ||
| 80 | try parseWs(alloc, p); | ||
| 81 | if (try p.eatByte('}')) |_| break; | ||
| 82 | } | ||
| 83 | return try p.addObject(alloc, &members); | ||
| 84 | } | ||
| 85 | |||
| 86 | fn parseArray(alloc: std.mem.Allocator, p: *Parser) anyerror!?ValueIndex { | ||
| 87 | _ = try p.eatByte('[') orelse return null; | ||
| 88 | |||
| 89 | var elements = std.ArrayListUnmanaged(ValueIndex){}; | ||
| 90 | defer elements.deinit(alloc); | ||
| 91 | |||
| 92 | while (true) { | ||
| 93 | try parseWs(alloc, p); | ||
| 94 | if (try p.eatByte(']')) |_| break; | ||
| 95 | |||
| 96 | const elem = try parseValue(alloc, p); | ||
| 97 | try elements.append(alloc, elem); | ||
| 98 | try parseWs(alloc, p); | ||
| 99 | _ = try p.eatByte(',') orelse { | ||
| 100 | _ = try p.eatByte(']') orelse return error.JsonExpectedTODO; | ||
| 101 | break; | ||
| 102 | }; | ||
| 103 | try parseWs(alloc, p); | ||
| 104 | if (try p.eatByte(']')) |_| break; | ||
| 105 | } | ||
| 106 | return try p.addArray(alloc, elements.items); | ||
| 107 | } | ||
| 108 | |||
| 109 | fn parseString(alloc: std.mem.Allocator, p: *Parser) anyerror!?StringIndex { | ||
| 110 | var stack_fallback = std.heap.stackFallback(512, alloc); | ||
| 111 | var characters = std.ArrayList(u8).init(stack_fallback.get()); | ||
| 112 | defer characters.deinit(); | ||
| 113 | |||
| 114 | _ = try p.eatByte('"') orelse return null; | ||
| 115 | |||
| 116 | while (true) { | ||
| 117 | const c = try p.shift(); | ||
| 118 | if (c == '"') { | ||
| 119 | break; | ||
| 120 | } | ||
| 121 | if (c != '\\') { | ||
| 122 | try characters.append(@intCast(c)); | ||
| 123 | continue; | ||
| 124 | } | ||
| 125 | switch (try p.shift()) { | ||
| 126 | inline 0x22, 0x5C, 0x2F => |d| try characters.append(d), | ||
| 127 | 'b' => try characters.append(0x8), | ||
| 128 | 'f' => try characters.append(0xC), | ||
| 129 | 'n' => try characters.append(0xA), | ||
| 130 | 'r' => try characters.append(0xD), | ||
| 131 | 't' => try characters.append(0x9), | ||
| 132 | 'u' => { | ||
| 133 | var o: u32 = 0; | ||
| 134 | var d = try p.shiftBytesN(4); | ||
| 135 | if (!extras.matchesAll(u8, &d, std.ascii.isHex)) return error.JsonExpectedTODO; | ||
| 136 | d = @bitCast(@byteSwap(@as(u32, @bitCast(d)))); | ||
| 137 | for (d, 0..) |e, i| o += (e * std.math.pow(u32, 2, @intCast(i))); | ||
| 138 | // | ||
| 139 | if (o > std.math.maxInt(u21)) return error.JsonExpectedTODO; | ||
| 140 | var b: [4]u8 = undefined; | ||
| 141 | const l = std.unicode.utf8Encode(@intCast(o), &b) catch return error.JsonExpectedTODO; | ||
| 142 | try characters.appendSlice(b[0..l]); | ||
| 143 | }, | ||
| 144 | else => return error.JsonExpectedTODO, | ||
| 145 | } | ||
| 146 | } | ||
| 147 | return try p.addStr(alloc, characters.items); | ||
| 148 | } | ||
| 149 | |||
| 150 | fn parseNumber(alloc: std.mem.Allocator, p: *Parser) anyerror!?ValueIndex { | ||
| 151 | var stack_fallback = std.heap.stackFallback(512, alloc); | ||
| 152 | var characters = std.ArrayList(u8).init(stack_fallback.get()); | ||
| 153 | defer characters.deinit(); | ||
| 154 | |||
| 155 | if (try p.eatByte('-')) |c| { | ||
| 156 | try characters.append(c); | ||
| 157 | |||
| 158 | if (try p.eatByte('0')) |_| { | ||
| 159 | return try p.addNumber(alloc, "-0"); | ||
| 160 | } | ||
| 161 | } | ||
| 162 | if (try p.eatByte('0')) |_| { | ||
| 163 | return try p.addNumber(alloc, "0"); | ||
| 164 | } | ||
| 165 | while (try p.eatAnyScalar("0123456789")) |d| { | ||
| 166 | try characters.append(d); | ||
| 167 | } | ||
| 168 | if (characters.items.len == 0) { | ||
| 169 | return null; | ||
| 170 | } | ||
| 171 | if (try p.eatByte('.')) |c| { | ||
| 172 | try characters.append(c); | ||
| 173 | const l = characters.items.len; | ||
| 174 | while (try p.eatAnyScalar("0123456789")) |d| { | ||
| 175 | try characters.append(d); | ||
| 176 | } | ||
| 177 | if (characters.items.len == l) return error.JsonExpectedTODO; | ||
| 178 | } | ||
| 179 | if (try p.eatAnyScalar("eE")) |_| { | ||
| 180 | try characters.append('e'); | ||
| 181 | try characters.append(try p.eatAnyScalar("+-") orelse return error.JsonExpectedTODO); | ||
| 182 | const l = characters.items.len; | ||
| 183 | while (try p.eatAnyScalar("0123456789")) |d| { | ||
| 184 | try characters.append(d); | ||
| 185 | } | ||
| 186 | if (characters.items.len == l) return error.JsonExpectedTODO; | ||
| 187 | } | ||
| 188 | |||
| 189 | return try p.addNumber(alloc, characters.items); | ||
| 190 | } | ||
| 191 | |||
| 192 | fn parseWs(alloc: std.mem.Allocator, p: *Parser) !void { | ||
| 193 | _ = alloc; | ||
| 194 | while (true) { | ||
| 195 | if (try p.eatByte(0x20)) |_| continue; // space | ||
| 196 | if (try p.eatByte(0x0A)) |_| continue; // NL | ||
| 197 | if (try p.eatByte(0x0D)) |_| continue; // CR | ||
| 198 | if (try p.eatByte(0x09)) |_| continue; // TAB | ||
| 199 | break; | ||
| 200 | } | ||
| 201 | } | ||
| 202 | |||
| 203 | const Parser = struct { | ||
| 204 | any: extras.AnyReader, | ||
| 205 | arena: std.mem.Allocator, | ||
| 206 | temp: std.ArrayListUnmanaged(u8) = .{}, | ||
| 207 | idx: usize = 0, | ||
| 208 | end: bool = false, | ||
| 209 | line: usize = 1, | ||
| 210 | col: usize = 1, | ||
| 211 | extras: std.ArrayListUnmanaged(u8) = .{}, | ||
| 212 | strings_map: std.StringArrayHashMapUnmanaged(StringIndex) = .{}, | ||
| 213 | |||
| 214 | pub fn init(allocator: std.mem.Allocator, any: extras.AnyReader) Parser { | ||
| 215 | return .{ | ||
| 216 | .any = any, | ||
| 217 | .arena = allocator, | ||
| 218 | }; | ||
| 219 | } | ||
| 220 | |||
| 221 | pub fn avail(p: *Parser) usize { | ||
| 222 | return p.temp.items.len - p.idx; | ||
| 223 | } | ||
| 224 | |||
| 225 | pub fn slice(p: *Parser) []const u8 { | ||
| 226 | return p.temp.items[p.idx..]; | ||
| 227 | } | ||
| 228 | |||
| 229 | pub fn eat(p: *Parser, comptime test_s: string) !?void { | ||
| 230 | if (test_s.len == 1) { | ||
| 231 | _ = try p.eatByte(test_s[0]); | ||
| 232 | return; | ||
| 233 | } | ||
| 234 | try p.peekAmt(test_s.len); | ||
| 235 | if (std.mem.eql(u8, p.slice()[0..test_s.len], test_s)) { | ||
| 236 | p.idx += test_s.len; | ||
| 237 | return; | ||
| 238 | } | ||
| 239 | return null; | ||
| 240 | } | ||
| 241 | |||
| 242 | fn peekAmt(p: *Parser, amt: usize) !void { | ||
| 243 | if (p.avail() >= amt) return; | ||
| 244 | const diff_amt = amt - p.avail(); | ||
| 245 | std.debug.assert(diff_amt <= buf_size); | ||
| 246 | var buf: [buf_size]u8 = undefined; | ||
| 247 | var target_buf = buf[0..diff_amt]; | ||
| 248 | const len = try p.any.readAll(target_buf); | ||
| 249 | if (len == 0) p.end = true; | ||
| 250 | if (len == 0) return error.EndOfStream; | ||
| 251 | std.debug.assert(len <= diff_amt); | ||
| 252 | try p.temp.appendSlice(p.arena, target_buf[0..len]); | ||
| 253 | if (len != diff_amt) return error.EndOfStream; | ||
| 254 | } | ||
| 255 | |||
| 256 | pub fn eatByte(p: *Parser, test_c: u8) !?u8 { | ||
| 257 | try p.peekAmt(1); | ||
| 258 | if (p.slice()[0] == test_c) { | ||
| 259 | p.idx += 1; | ||
| 260 | return test_c; | ||
| 261 | } | ||
| 262 | return null; | ||
| 263 | } | ||
| 264 | |||
| 265 | pub fn eatAnyScalar(p: *Parser, test_s: string) !?u8 { | ||
| 266 | std.debug.assert(extras.matchesAll(u8, test_s, std.ascii.isASCII)); | ||
| 267 | try p.peekAmt(1); | ||
| 268 | if (std.mem.indexOfScalar(u8, test_s, p.slice()[0])) |idx| { | ||
| 269 | p.idx += 1; | ||
| 270 | return test_s[idx]; | ||
| 271 | } | ||
| 272 | return null; | ||
| 273 | } | ||
| 274 | |||
| 275 | pub fn shift(p: *Parser) !u21 { | ||
| 276 | try p.peekAmt(1); | ||
| 277 | const len = try std.unicode.utf8ByteSequenceLength(p.slice()[0]); | ||
| 278 | try p.peekAmt(len); | ||
| 279 | defer p.idx += len; | ||
| 280 | return std.unicode.utf8Decode(p.slice()[0..len]); | ||
| 281 | } | ||
| 282 | |||
| 283 | pub fn shiftBytesN(p: *Parser, comptime n: usize) ![n]u8 { | ||
| 284 | try p.peekAmt(n); | ||
| 285 | defer p.idx += n; | ||
| 286 | return p.slice()[0..n].*; | ||
| 287 | } | ||
| 288 | |||
| 289 | pub fn addObject(p: *Parser, alloc: std.mem.Allocator, members: *ObjectHashMap) !ValueIndex { | ||
| 290 | const r = p.extras.items.len; | ||
| 291 | const l = members.entries.len; | ||
| 292 | if (l > std.math.maxInt(u32)) return error.JsonExpectedTODO; | ||
| 293 | try p.extras.ensureUnusedCapacity(alloc, 1 + 4 + (l * 4 * 2)); | ||
| 294 | p.extras.appendAssumeCapacity(@intFromEnum(Value.Tag.object)); | ||
| 295 | p.extras.appendSliceAssumeCapacity(&std.mem.toBytes(@as(u32, @intCast(l)))); | ||
| 296 | p.extras.appendSliceAssumeCapacity(std.mem.sliceAsBytes(members.keys())); | ||
| 297 | p.extras.appendSliceAssumeCapacity(std.mem.sliceAsBytes(members.values())); | ||
| 298 | return @enumFromInt(r); | ||
| 299 | } | ||
| 300 | |||
| 301 | pub fn addArray(p: *Parser, alloc: std.mem.Allocator, items: []const ValueIndex) !ValueIndex { | ||
| 302 | const r = p.extras.items.len; | ||
| 303 | const l = items.len; | ||
| 304 | if (l > std.math.maxInt(u32)) return error.JsonExpectedTODO; | ||
| 305 | try p.extras.ensureUnusedCapacity(alloc, 1 + 4 + (l * 4)); | ||
| 306 | p.extras.appendAssumeCapacity(@intFromEnum(Value.Tag.array)); | ||
| 307 | p.extras.appendSliceAssumeCapacity(&std.mem.toBytes(@as(u32, @intCast(l)))); | ||
| 308 | p.extras.appendSliceAssumeCapacity(std.mem.sliceAsBytes(items)); | ||
| 309 | return @enumFromInt(r); | ||
| 310 | } | ||
| 311 | |||
| 312 | pub fn addStr(p: *Parser, alloc: std.mem.Allocator, str: string) !StringIndex { | ||
| 313 | const adapter: Adapter = .{ .p = p }; | ||
| 314 | const res = try p.strings_map.getOrPutAdapted(alloc, str, adapter); | ||
| 315 | if (res.found_existing) return res.value_ptr.*; | ||
| 316 | errdefer p.strings_map.orderedRemoveAt(res.index); | ||
| 317 | const r = p.extras.items.len; | ||
| 318 | const l = str.len; | ||
| 319 | try p.extras.ensureUnusedCapacity(alloc, 1 + 4 + l); | ||
| 320 | p.extras.appendAssumeCapacity(@intFromEnum(Value.Tag.string)); | ||
| 321 | p.extras.appendSliceAssumeCapacity(&std.mem.toBytes(@as(u32, @intCast(l)))); | ||
| 322 | p.extras.appendSliceAssumeCapacity(str); | ||
| 323 | res.value_ptr.* = @enumFromInt(r); | ||
| 324 | return @enumFromInt(r); | ||
| 325 | } | ||
| 326 | |||
| 327 | const Adapter = struct { | ||
| 328 | p: *const Parser, | ||
| 329 | |||
| 330 | pub fn hash(ctx: @This(), a: string) u32 { | ||
| 331 | _ = ctx; | ||
| 332 | var hasher = std.hash.Wyhash.init(0); | ||
| 333 | hasher.update(a); | ||
| 334 | return @truncate(hasher.final()); | ||
| 335 | } | ||
| 336 | |||
| 337 | pub fn eql(ctx: @This(), a: string, _: string, b_index: usize) bool { | ||
| 338 | const sidx = ctx.p.strings_map.values()[b_index]; | ||
| 339 | const b = ctx.p.getStr(sidx); | ||
| 340 | return std.mem.eql(u8, a, b); | ||
| 341 | } | ||
| 342 | }; | ||
| 343 | |||
| 344 | pub fn addNumber(p: *Parser, alloc: std.mem.Allocator, v: []const u8) !ValueIndex { | ||
| 345 | const r = p.extras.items.len; | ||
| 346 | const l = v.len; | ||
| 347 | if (l > std.math.maxInt(u8)) return error.JsonExpectedTODO; | ||
| 348 | try p.extras.ensureUnusedCapacity(alloc, 1 + 1 + l); | ||
| 349 | p.extras.appendAssumeCapacity(@intFromEnum(Value.Tag.number)); | ||
| 350 | p.extras.appendAssumeCapacity(@intCast(l)); | ||
| 351 | p.extras.appendSliceAssumeCapacity(v); | ||
| 352 | return @enumFromInt(r); | ||
| 353 | } | ||
| 354 | |||
| 355 | pub fn getStr(p: *const Parser, sidx: StringIndex) string { | ||
| 356 | const i: u32 = @intFromEnum(sidx); | ||
| 357 | std.debug.assert(@as(Value.Tag, @enumFromInt(p.extras.items[i])) == .string); | ||
| 358 | const l: u32 = @bitCast(p.extras.items[i..][1..][0..4].*); | ||
| 359 | return p.extras.items[i..][1..][4..][0..l]; | ||
| 360 | } | ||
| 361 | }; | ||
| 362 | |||
| 363 | pub const Document = struct { | ||
| 364 | extras: []const u8, | ||
| 365 | root: ValueIndex, | ||
| 366 | |||
| 367 | pub fn deinit(doc: *const Document, alloc: std.mem.Allocator) void { | ||
| 368 | alloc.free(doc.extras); | ||
| 369 | } | ||
| 370 | }; | ||
| 371 | |||
| 372 | pub const ValueIndex = enum(u32) { | ||
| 373 | _, | ||
| 374 | }; | ||
| 375 | |||
| 376 | pub const StringIndex = enum(u32) { | ||
| 377 | _, | ||
| 378 | }; | ||
| 379 | |||
| 380 | pub const ArrayIndex = enum(u32) { | ||
| 381 | _, | ||
| 382 | }; | ||
| 383 | |||
| 384 | pub const ObjectIndex = enum(u32) { | ||
| 385 | _, | ||
| 386 | }; | ||
| 387 | |||
| 388 | pub const NumberIndex = enum(u32) { | ||
| 389 | _, | ||
| 390 | }; | ||
| 391 | |||
| 392 | pub const Value = union(enum) { | ||
| 393 | zero, | ||
| 394 | null, | ||
| 395 | true, | ||
| 396 | false, | ||
| 397 | object, | ||
| 398 | array, | ||
| 399 | string, | ||
| 400 | number, | ||
| 401 | |||
| 402 | const Tag = std.meta.Tag(@This()); | ||
| 403 | }; |
licenses.txt+2| ... | @@ -1,3 +1,5 @@ | ... | @@ -1,3 +1,5 @@ |
| 1 | MIT: | 1 | MIT: |
| 2 | = https://spdx.org/licenses/MIT | 2 | = https://spdx.org/licenses/MIT |
| 3 | - This | 3 | - This |
| 4 | - git https://github.com/nektro/zig-extras | ||
| 5 | - git https://github.com/nektro/zig-tracer |
test.zig+258| ... | @@ -1 +1,259 @@ | ... | @@ -1 +1,259 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const json = @import("json"); | ||
| 3 | |||
| 4 | fn parse_full(buffer: []const u8) !void { | ||
| 5 | const alloc = std.testing.allocator; | ||
| 6 | var fbs = std.io.fixedBufferStream(buffer); | ||
| 7 | var doc = try json.parse(alloc, "", fbs.reader()); | ||
| 8 | defer doc.deinit(alloc); | ||
| 9 | } | ||
| 10 | |||
| 11 | test { | ||
| 12 | try parse_full( | ||
| 13 | \\[ | ||
| 14 | \\ { | ||
| 15 | \\ "id": 131325113, | ||
| 16 | \\ "author": { | ||
| 17 | \\ "login": "github-actions[bot]", | ||
| 18 | \\ "id": 41898282, | ||
| 19 | \\ "node_id": "MDM6Qm90NDE4OTgyODI=", | ||
| 20 | \\ "gravatar_id": "", | ||
| 21 | \\ "type": "Bot", | ||
| 22 | \\ "site_admin": false | ||
| 23 | \\ }, | ||
| 24 | \\ "node_id": "RE_kwDOEpDmIc4H09y5", | ||
| 25 | \\ "tag_name": "r89", | ||
| 26 | \\ "target_commitish": "0df96b60dee2a9e76bf12ad8b8ab1d47dba52994", | ||
| 27 | \\ "name": "r89", | ||
| 28 | \\ "draft": false, | ||
| 29 | \\ "prerelease": false, | ||
| 30 | \\ "created_at": "2023-11-24T08:33:57Z", | ||
| 31 | \\ "published_at": "2023-11-24T08:38:51Z", | ||
| 32 | \\ "assets": [ | ||
| 33 | \\ { | ||
| 34 | \\ "id": 137211731, | ||
| 35 | \\ "node_id": "RA_kwDOEpDmIc4ILa9T", | ||
| 36 | \\ "name": "zigmod-aarch64-linux", | ||
| 37 | \\ "label": "", | ||
| 38 | \\ "uploader": { | ||
| 39 | \\ "login": "github-actions[bot]", | ||
| 40 | \\ "id": 41898282, | ||
| 41 | \\ "node_id": "MDM6Qm90NDE4OTgyODI=", | ||
| 42 | \\ "gravatar_id": "", | ||
| 43 | \\ "type": "Bot", | ||
| 44 | \\ "site_admin": false | ||
| 45 | \\ }, | ||
| 46 | \\ "content_type": "application/octet-stream", | ||
| 47 | \\ "state": "uploaded", | ||
| 48 | \\ "size": 12449224, | ||
| 49 | \\ "download_count": 28, | ||
| 50 | \\ "created_at": "2023-11-24T08:38:52Z", | ||
| 51 | \\ "updated_at": "2023-11-24T08:38:53Z", | ||
| 52 | \\ }, | ||
| 53 | \\ { | ||
| 54 | \\ "id": 137211736, | ||
| 55 | \\ "node_id": "RA_kwDOEpDmIc4ILa9Y", | ||
| 56 | \\ "name": "zigmod-aarch64-macos", | ||
| 57 | \\ "label": "", | ||
| 58 | \\ "uploader": { | ||
| 59 | \\ "login": "github-actions[bot]", | ||
| 60 | \\ "id": 41898282, | ||
| 61 | \\ "node_id": "MDM6Qm90NDE4OTgyODI=", | ||
| 62 | \\ "gravatar_id": "", | ||
| 63 | \\ "type": "Bot", | ||
| 64 | \\ "site_admin": false | ||
| 65 | \\ }, | ||
| 66 | \\ "content_type": "application/octet-stream", | ||
| 67 | \\ "state": "uploaded", | ||
| 68 | \\ "size": 9137624, | ||
| 69 | \\ "download_count": 581, | ||
| 70 | \\ "created_at": "2023-11-24T08:38:55Z", | ||
| 71 | \\ "updated_at": "2023-11-24T08:38:56Z", | ||
| 72 | \\ }, | ||
| 73 | \\ { | ||
| 74 | \\ "id": 137211747, | ||
| 75 | \\ "node_id": "RA_kwDOEpDmIc4ILa9j", | ||
| 76 | \\ "name": "zigmod-aarch64-windows.exe", | ||
| 77 | \\ "label": "", | ||
| 78 | \\ "uploader": { | ||
| 79 | \\ "login": "github-actions[bot]", | ||
| 80 | \\ "id": 41898282, | ||
| 81 | \\ "node_id": "MDM6Qm90NDE4OTgyODI=", | ||
| 82 | \\ "gravatar_id": "", | ||
| 83 | \\ "type": "Bot", | ||
| 84 | \\ "site_admin": false | ||
| 85 | \\ }, | ||
| 86 | \\ "content_type": "application/octet-stream", | ||
| 87 | \\ "state": "uploaded", | ||
| 88 | \\ "size": 7738880, | ||
| 89 | \\ "download_count": 23, | ||
| 90 | \\ "created_at": "2023-11-24T08:39:00Z", | ||
| 91 | \\ "updated_at": "2023-11-24T08:39:01Z", | ||
| 92 | \\ }, | ||
| 93 | \\ { | ||
| 94 | \\ "id": 137211740, | ||
| 95 | \\ "node_id": "RA_kwDOEpDmIc4ILa9c", | ||
| 96 | \\ "name": "zigmod-aarch64-windows.pdb", | ||
| 97 | \\ "label": "", | ||
| 98 | \\ "uploader": { | ||
| 99 | \\ "login": "github-actions[bot]", | ||
| 100 | \\ "id": 41898282, | ||
| 101 | \\ "node_id": "MDM6Qm90NDE4OTgyODI=", | ||
| 102 | \\ "gravatar_id": "", | ||
| 103 | \\ "type": "Bot", | ||
| 104 | \\ "site_admin": false | ||
| 105 | \\ }, | ||
| 106 | \\ "content_type": "application/octet-stream", | ||
| 107 | \\ "state": "uploaded", | ||
| 108 | \\ "size": 3813376, | ||
| 109 | \\ "download_count": 2, | ||
| 110 | \\ "created_at": "2023-11-24T08:38:56Z", | ||
| 111 | \\ "updated_at": "2023-11-24T08:38:57Z", | ||
| 112 | \\ }, | ||
| 113 | \\ { | ||
| 114 | \\ "id": 137211748, | ||
| 115 | \\ "node_id": "RA_kwDOEpDmIc4ILa9k", | ||
| 116 | \\ "name": "zigmod-mips64-linux", | ||
| 117 | \\ "label": "", | ||
| 118 | \\ "uploader": { | ||
| 119 | \\ "login": "github-actions[bot]", | ||
| 120 | \\ "id": 41898282, | ||
| 121 | \\ "node_id": "MDM6Qm90NDE4OTgyODI=", | ||
| 122 | \\ "gravatar_id": "", | ||
| 123 | \\ "type": "Bot", | ||
| 124 | \\ "site_admin": false | ||
| 125 | \\ }, | ||
| 126 | \\ "content_type": "application/octet-stream", | ||
| 127 | \\ "state": "uploaded", | ||
| 128 | \\ "size": 12545712, | ||
| 129 | \\ "download_count": 3, | ||
| 130 | \\ "created_at": "2023-11-24T08:39:01Z", | ||
| 131 | \\ "updated_at": "2023-11-24T08:39:03Z", | ||
| 132 | \\ }, | ||
| 133 | \\ { | ||
| 134 | \\ "id": 137211749, | ||
| 135 | \\ "node_id": "RA_kwDOEpDmIc4ILa9l", | ||
| 136 | \\ "name": "zigmod-powerpc64le-linux", | ||
| 137 | \\ "label": "", | ||
| 138 | \\ "uploader": { | ||
| 139 | \\ "login": "github-actions[bot]", | ||
| 140 | \\ "id": 41898282, | ||
| 141 | \\ "node_id": "MDM6Qm90NDE4OTgyODI=", | ||
| 142 | \\ "gravatar_id": "", | ||
| 143 | \\ "type": "Bot", | ||
| 144 | \\ "site_admin": false | ||
| 145 | \\ }, | ||
| 146 | \\ "content_type": "application/octet-stream", | ||
| 147 | \\ "state": "uploaded", | ||
| 148 | \\ "size": 11638720, | ||
| 149 | \\ "download_count": 3, | ||
| 150 | \\ "created_at": "2023-11-24T08:39:03Z", | ||
| 151 | \\ "updated_at": "2023-11-24T08:39:04Z", | ||
| 152 | \\ }, | ||
| 153 | \\ { | ||
| 154 | \\ "id": 137211745, | ||
| 155 | \\ "node_id": "RA_kwDOEpDmIc4ILa9h", | ||
| 156 | \\ "name": "zigmod-riscv64-linux", | ||
| 157 | \\ "label": "", | ||
| 158 | \\ "uploader": { | ||
| 159 | \\ "login": "github-actions[bot]", | ||
| 160 | \\ "id": 41898282, | ||
| 161 | \\ "node_id": "MDM6Qm90NDE4OTgyODI=", | ||
| 162 | \\ "gravatar_id": "", | ||
| 163 | \\ "type": "Bot", | ||
| 164 | \\ "site_admin": false | ||
| 165 | \\ }, | ||
| 166 | \\ "content_type": "application/octet-stream", | ||
| 167 | \\ "state": "uploaded", | ||
| 168 | \\ "size": 17282528, | ||
| 169 | \\ "download_count": 4, | ||
| 170 | \\ "created_at": "2023-11-24T08:38:58Z", | ||
| 171 | \\ "updated_at": "2023-11-24T08:39:00Z", | ||
| 172 | \\ }, | ||
| 173 | \\ { | ||
| 174 | \\ "id": 137211752, | ||
| 175 | \\ "node_id": "RA_kwDOEpDmIc4ILa9o", | ||
| 176 | \\ "name": "zigmod-x86_64-linux", | ||
| 177 | \\ "label": "", | ||
| 178 | \\ "uploader": { | ||
| 179 | \\ "login": "github-actions[bot]", | ||
| 180 | \\ "id": 41898282, | ||
| 181 | \\ "node_id": "MDM6Qm90NDE4OTgyODI=", | ||
| 182 | \\ "gravatar_id": "", | ||
| 183 | \\ "type": "Bot", | ||
| 184 | \\ "site_admin": false | ||
| 185 | \\ }, | ||
| 186 | \\ "content_type": "application/octet-stream", | ||
| 187 | \\ "state": "uploaded", | ||
| 188 | \\ "size": 11913416, | ||
| 189 | \\ "download_count": 4906, | ||
| 190 | \\ "created_at": "2023-11-24T08:39:06Z", | ||
| 191 | \\ "updated_at": "2023-11-24T08:39:07Z", | ||
| 192 | \\ }, | ||
| 193 | \\ { | ||
| 194 | \\ "id": 137211733, | ||
| 195 | \\ "node_id": "RA_kwDOEpDmIc4ILa9V", | ||
| 196 | \\ "name": "zigmod-x86_64-macos", | ||
| 197 | \\ "label": "", | ||
| 198 | \\ "uploader": { | ||
| 199 | \\ "login": "github-actions[bot]", | ||
| 200 | \\ "id": 41898282, | ||
| 201 | \\ "node_id": "MDM6Qm90NDE4OTgyODI=", | ||
| 202 | \\ "gravatar_id": "", | ||
| 203 | \\ "type": "Bot", | ||
| 204 | \\ "site_admin": false | ||
| 205 | \\ }, | ||
| 206 | \\ "content_type": "application/octet-stream", | ||
| 207 | \\ "state": "uploaded", | ||
| 208 | \\ "size": 8618320, | ||
| 209 | \\ "download_count": 795, | ||
| 210 | \\ "created_at": "2023-11-24T08:38:53Z", | ||
| 211 | \\ "updated_at": "2023-11-24T08:38:54Z", | ||
| 212 | \\ }, | ||
| 213 | \\ { | ||
| 214 | \\ "id": 137211742, | ||
| 215 | \\ "node_id": "RA_kwDOEpDmIc4ILa9e", | ||
| 216 | \\ "name": "zigmod-x86_64-windows.exe", | ||
| 217 | \\ "label": "", | ||
| 218 | \\ "uploader": { | ||
| 219 | \\ "login": "github-actions[bot]", | ||
| 220 | \\ "id": 41898282, | ||
| 221 | \\ "node_id": "MDM6Qm90NDE4OTgyODI=", | ||
| 222 | \\ "gravatar_id": "", | ||
| 223 | \\ "type": "Bot", | ||
| 224 | \\ "site_admin": false | ||
| 225 | \\ }, | ||
| 226 | \\ "content_type": "application/octet-stream", | ||
| 227 | \\ "state": "uploaded", | ||
| 228 | \\ "size": 7557632, | ||
| 229 | \\ "download_count": 300, | ||
| 230 | \\ "created_at": "2023-11-24T08:38:57Z", | ||
| 231 | \\ "updated_at": "2023-11-24T08:38:58Z", | ||
| 232 | \\ }, | ||
| 233 | \\ { | ||
| 234 | \\ "id": 137211751, | ||
| 235 | \\ "node_id": "RA_kwDOEpDmIc4ILa9n", | ||
| 236 | \\ "name": "zigmod-x86_64-windows.pdb", | ||
| 237 | \\ "label": "", | ||
| 238 | \\ "uploader": { | ||
| 239 | \\ "login": "github-actions[bot]", | ||
| 240 | \\ "id": 41898282, | ||
| 241 | \\ "node_id": "MDM6Qm90NDE4OTgyODI=", | ||
| 242 | \\ "gravatar_id": "", | ||
| 243 | \\ "type": "Bot", | ||
| 244 | \\ "site_admin": false | ||
| 245 | \\ }, | ||
| 246 | \\ "content_type": "application/octet-stream", | ||
| 247 | \\ "state": "uploaded", | ||
| 248 | \\ "size": 4411392, | ||
| 249 | \\ "download_count": 8, | ||
| 250 | \\ "created_at": "2023-11-24T08:39:05Z", | ||
| 251 | \\ "updated_at": "2023-11-24T08:39:05Z", | ||
| 252 | \\ } | ||
| 253 | \\ ], | ||
| 254 | \\ "body": "<li><a href='https://github.com/nektro/zigmod/commit/0df96b60dee2a9e76bf12ad8b8ab1d47dba52994'><code>0df96b6</code></a> cmd/aq/{install,update}: use proper cachepath (Meghan Denny)</li>\n<li><a href='https://github.com/nektro/zigmod/commit/a1ea508279920f457c5f899022046fefd6dc146a'><code>a1ea508</code></a> main: pass proper self_path value (Meghan Denny)</li>\n<li><a href='https://github.com/nektro/zigmod/commit/09d633b1405c5cbd4e02f4c86cb34f0368bf321f'><code>09d633b</code></a> cmd: when running zigmod inside deps folder, use parent deps folder as cachepath (Meghan Denny)</li>\n<li><a href='https://github.com/nektro/zigmod/commit/65666d00836654f33ac4405acc12ccf50f93a071'><code>65666d0</code></a> add self_name arg to all execute() call signatures (Meghan Denny)</li>\n<li><a href='https://github.com/nektro/zigmod/commit/e2d42e8ff71c3e6f534a380b7d16465fa77032f7'><code>e2d42e8</code></a> add deps.addAllLibrariesTo(), closes #84 (Meghan Denny)</li>\n<li><a href='https://github.com/nektro/zigmod/commit/f3aabb5e4e3baa7cf58af4f36f8683532d49fce3'><code>f3aabb5</code></a> regenerate deps.zig (Meghan Denny)</li>\n<li><a href='https://github.com/nektro/zigmod/commit/b8cd095ebd012788b83ac2d8e1592ce531fecde9'><code>b8cd095</code></a> mark versioned dep folders as readonly, closes #53 (Meghan Denny)</li>\n<li><a href='https://github.com/nektro/zigmod/commit/255cb974db260e67d6782f785f26604292c39131'><code>255cb97</code></a> add a buffered reader for parsing zigmod.lock (Meghan Denny)</li>\n<li><a href='https://github.com/nektro/zigmod/commit/a9863df0dedb0f59bbabcbf3d13f859e33c265a2'><code>a9863df</code></a> close some file descriptors (Meghan Denny)</li>\n<li><a href='https://github.com/nektro/zigmod/commit/941ad7c971be96e2b85a683760f0a7a3a513c202'><code>941ad7c</code></a> deps: marlersoft/zigwin32: misc confirmed update (Meghan Denny)</li>\n<li><a href='https://github.com/nektro/zigmod/commit/0e7516562fea909c18c770484919174a6e81485e'><code>0e75165</code></a> deps: nektro/zig-extras: misc confirmed updates (Meghan Denny)</li>\n<li><a href='https://github.com/nektro/zigmod/commit/8e4e9ae69d8f09d32347e7ee6c250271067f0b37'><code>8e4e9ae</code></a> deps: ziglibs/known-folders: misc confirmed updates (Meghan Denny)</li>\n<li><a href='https://github.com/nektro/zigmod/commit/8ba1d87039adee5566a0af66c3645989b976f822'><code>8ba1d87</code></a> deps: truemedian/hzzp: misc confirmed updates (Meghan Denny)</li>\n<li><a href='https://github.com/nektro/zigmod/commit/ddd0eb706c5f759141a9df462c31dbee32ef3b83'><code>ddd0eb7</code></a> deps: nektro/iguanaTLS: misc confirmed updates (Meghan Denny)</li>\n<li><a href='https://github.com/nektro/zigmod/commit/02464e094476795725f261a987c53d46da8934a3'><code>02464e0</code></a> build_release.sh: use debug mode, release breaks stack traces (Meghan Denny)</li>\n<li><a href='https://github.com/nektro/zigmod/commit/6c68f38b8cc76288dcc871b6acc5e9470385d2a7'><code>6c68f38</code></a> build.zig: add a -Doption (Meghan Denny)</li>\n<li><a href='https://github.com/nektro/zigmod/commit/5403d1a72d023253754eca1d275537ea8dc0be5a'><code>5403d1a</code></a> build.zig: move -Dtag option declaration out with other options (Meghan Denny)</li>" | ||
| 255 | \\ } | ||
| 256 | \\] | ||
| 257 | \\ | ||
| 258 | ); | ||
| 259 | } |
zig.mod+3| ... | @@ -3,3 +3,6 @@ name: json | ... | @@ -3,3 +3,6 @@ name: json |
| 3 | main: json.zig | 3 | main: json.zig |
| 4 | license: MIT | 4 | license: MIT |
| 5 | description: "A JSON library for inspecting arbitrary values" | 5 | description: "A JSON library for inspecting arbitrary values" |
| 6 | dependencies: | ||
| 7 | - src: git https://github.com/nektro/zig-extras | ||
| 8 | - src: git https://github.com/nektro/zig-tracer |