diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-01-17 18:40:47 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-01-17 18:40:47 +0900 |
| commit | 22a5d1617e79f176ecfca22d6c72be215f0da8b6 (patch) | |
| tree | 4424a15f2e069aa27312a9e1885d8446ad12bea1 /src/jq/execute.zig | |
| parent | d4bacf19b56c21afc7f2f0b5efb244b072873119 (diff) | |
| download | zgjq-22a5d1617e79f176ecfca22d6c72be215f0da8b6.tar.gz zgjq-22a5d1617e79f176ecfca22d6c72be215f0da8b6.tar.zst zgjq-22a5d1617e79f176ecfca22d6c72be215f0da8b6.zip | |
implement object key access
Diffstat (limited to 'src/jq/execute.zig')
| -rw-r--r-- | src/jq/execute.zig | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/jq/execute.zig b/src/jq/execute.zig index a07204a..8e9bbb0 100644 --- a/src/jq/execute.zig +++ b/src/jq/execute.zig @@ -66,6 +66,14 @@ const ValueStack = struct { else => error.InvalidType, }; } + + pub fn popObject(self: *Self) ExecuteError!jv.Object { + const value = try self.pop(); + return switch (value) { + .object => |o| o, + else => error.InvalidType, + }; + } }; pub fn execute(allocator: std.mem.Allocator, instrs: []const Instr, input: jv.Value) !jv.Value { @@ -86,6 +94,11 @@ pub fn execute(allocator: std.mem.Allocator, instrs: []const Instr, input: jv.Va const result = if (index < array.items.len) array.items[index] else .null; try value_stack.push(result); }, + .object_key => |key| { + const obj = try value_stack.popObject(); + const result = obj.get(key) orelse .null; + try value_stack.push(result); + }, .literal => |value| { try value_stack.push(value.*); }, |
