| ... | @@ -1188,7 +1188,7 @@ pub const Parser = struct { | ... | @@ -1188,7 +1188,7 @@ pub const Parser = struct { |
| 1188 | } | 1188 | } |
| 1189 | | 1189 | |
| 1190 | var value = p.stack.pop(); | 1190 | var value = p.stack.pop(); |
| 1191 | try p.pushToParent(value); | 1191 | try p.pushToParent(&value); |
| 1192 | }, | 1192 | }, |
| 1193 | Token.Id.String => { | 1193 | Token.Id.String => { |
| 1194 | try p.stack.append(try p.parseString(allocator, token, input, i)); | 1194 | try p.stack.append(try p.parseString(allocator, token, input, i)); |
| ... | @@ -1251,7 +1251,7 @@ pub const Parser = struct { | ... | @@ -1251,7 +1251,7 @@ pub const Parser = struct { |
| 1251 | } | 1251 | } |
| 1252 | | 1252 | |
| 1253 | var value = p.stack.pop(); | 1253 | var value = p.stack.pop(); |
| 1254 | try p.pushToParent(value); | 1254 | try p.pushToParent(&value); |
| 1255 | }, | 1255 | }, |
| 1256 | Token.Id.ObjectBegin => { | 1256 | Token.Id.ObjectBegin => { |
| 1257 | try p.stack.append(Value{ .Object = ObjectMap.init(allocator) }); | 1257 | try p.stack.append(Value{ .Object = ObjectMap.init(allocator) }); |
| ... | @@ -1312,19 +1312,19 @@ pub const Parser = struct { | ... | @@ -1312,19 +1312,19 @@ pub const Parser = struct { |
| 1312 | } | 1312 | } |
| 1313 | } | 1313 | } |
| 1314 | | 1314 | |
| 1315 | fn pushToParent(p: *Parser, value: Value) !void { | 1315 | fn pushToParent(p: *Parser, value: *const Value) !void { |
| 1316 | switch (p.stack.at(p.stack.len - 1)) { | 1316 | switch (p.stack.toSlice()[p.stack.len - 1]) { |
| 1317 | // Object Parent -> [ ..., object, <key>, value ] | 1317 | // Object Parent -> [ ..., object, <key>, value ] |
| 1318 | Value.String => |key| { | 1318 | Value.String => |key| { |
| 1319 | _ = p.stack.pop(); | 1319 | _ = p.stack.pop(); |
| 1320 | | 1320 | |
| 1321 | var object = &p.stack.items[p.stack.len - 1].Object; | 1321 | var object = &p.stack.items[p.stack.len - 1].Object; |
| 1322 | _ = try object.put(key, value); | 1322 | _ = try object.put(key, value.*); |
| 1323 | p.state = State.ObjectKey; | 1323 | p.state = State.ObjectKey; |
| 1324 | }, | 1324 | }, |
| 1325 | // Array Parent -> [ ..., <array>, value ] | 1325 | // Array Parent -> [ ..., <array>, value ] |
| 1326 | Value.Array => |*array| { | 1326 | Value.Array => |*array| { |
| 1327 | try array.append(value); | 1327 | try array.append(value.*); |
| 1328 | p.state = State.ArrayValue; | 1328 | p.state = State.ArrayValue; |
| 1329 | }, | 1329 | }, |
| 1330 | else => { | 1330 | else => { |
| ... | @@ -1364,7 +1364,8 @@ test "json.parser.dynamic" { | ... | @@ -1364,7 +1364,8 @@ test "json.parser.dynamic" { |
| 1364 | \\ "Width": 100 | 1364 | \\ "Width": 100 |
| 1365 | \\ }, | 1365 | \\ }, |
| 1366 | \\ "Animated" : false, | 1366 | \\ "Animated" : false, |
| 1367 | \\ "IDs": [116, 943, 234, 38793] | 1367 | \\ "IDs": [116, 943, 234, 38793], |
| | 1368 | \\ "ArrayOfObject": [{"n": "m"}] |
| 1368 | \\ } | 1369 | \\ } |
| 1369 | \\} | 1370 | \\} |
| 1370 | ; | 1371 | ; |
| ... | @@ -1387,4 +1388,10 @@ test "json.parser.dynamic" { | ... | @@ -1387,4 +1388,10 @@ test "json.parser.dynamic" { |
| 1387 | | 1388 | |
| 1388 | const animated = image.Object.get("Animated").?.value; | 1389 | const animated = image.Object.get("Animated").?.value; |
| 1389 | debug.assert(animated.Bool == false); | 1390 | debug.assert(animated.Bool == false); |
| | 1391 | |
| | 1392 | const array_of_object = image.Object.get("ArrayOfObject").?.value; |
| | 1393 | debug.assert(array_of_object.Array.len == 1); |
| | 1394 | |
| | 1395 | const obj0 = array_of_object.Array.at(0).Object.get("n").?.value; |
| | 1396 | debug.assert(mem.eql(u8, obj0.String, "m")); |
| 1390 | } | 1397 | } |