aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/jq/execute.zig
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-01-31 15:53:23 +0900
committernsfisis <nsfisis@gmail.com>2026-01-31 15:57:48 +0900
commit7712c1d10ec45349c1cd6e66281b7d602350065d (patch)
tree92208e7fb1955fd9847d91affa25ec096012ab9b /src/jq/execute.zig
parent617ddc62aa4d3153850362526069b85bfaf5e59e (diff)
downloadzgjq-7712c1d10ec45349c1cd6e66281b7d602350065d.tar.gz
zgjq-7712c1d10ec45349c1cd6e66281b7d602350065d.tar.zst
zgjq-7712c1d10ec45349c1cd6e66281b7d602350065d.zip
implement slice expression
Diffstat (limited to 'src/jq/execute.zig')
-rw-r--r--src/jq/execute.zig24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/jq/execute.zig b/src/jq/execute.zig
index 3096be2..9fa410f 100644
--- a/src/jq/execute.zig
+++ b/src/jq/execute.zig
@@ -273,6 +273,30 @@ pub const Runtime = struct {
key.deinit(self.allocator);
try self.values.push(result);
},
+ .slice => {
+ std.debug.assert(self.values.ensureSize(3));
+
+ const base = self.values.pop();
+ const to = self.values.pop();
+ const from = self.values.pop();
+ const result = try jv.ops.slice(self.allocator, base, from, to);
+ base.deinit(self.allocator);
+ to.deinit(self.allocator);
+ from.deinit(self.allocator);
+ try self.values.push(result);
+ },
+ .slice_opt => {
+ std.debug.assert(self.values.ensureSize(3));
+
+ const base = self.values.pop();
+ const to = self.values.pop();
+ const from = self.values.pop();
+ const result = jv.ops.slice(self.allocator, base, from, to) catch jv.Value.null;
+ base.deinit(self.allocator);
+ to.deinit(self.allocator);
+ from.deinit(self.allocator);
+ try self.values.push(result);
+ },
.add => {
std.debug.assert(self.values.ensureSize(3));