aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/jq
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-01-25 18:16:24 +0900
committernsfisis <nsfisis@gmail.com>2026-01-25 18:16:24 +0900
commit11ff1132c8116aef2296cc6ebd3c40b5e7e7b43f (patch)
tree72d5f22d96e2430fe943ede11dc76c9c8dab3517 /src/jq
parent48d9ec8aef4c3e7f3574346a6cf6a1fa3d725561 (diff)
downloadzgjq-11ff1132c8116aef2296cc6ebd3c40b5e7e7b43f.tar.gz
zgjq-11ff1132c8116aef2296cc6ebd3c40b5e7e7b43f.tar.zst
zgjq-11ff1132c8116aef2296cc6ebd3c40b5e7e7b43f.zip
implement string literals
Diffstat (limited to 'src/jq')
-rw-r--r--src/jq/compile.zig7
-rw-r--r--src/jq/parse.zig8
2 files changed, 14 insertions, 1 deletions
diff --git a/src/jq/compile.zig b/src/jq/compile.zig
index fb2a691..78512b9 100644
--- a/src/jq/compile.zig
+++ b/src/jq/compile.zig
@@ -57,7 +57,12 @@ pub const Instr = union(Opcode) {
pub fn deinit(self: Self, allocator: std.mem.Allocator) void {
switch (self) {
.object_key => |key| allocator.free(key),
- .literal => |value| allocator.destroy(value),
+ .literal => |value| {
+ if (value.* == .string) {
+ allocator.free(value.string);
+ }
+ allocator.destroy(value);
+ },
else => {},
}
}
diff --git a/src/jq/parse.zig b/src/jq/parse.zig
index 5df1d14..d197c26 100644
--- a/src/jq/parse.zig
+++ b/src/jq/parse.zig
@@ -352,6 +352,14 @@ fn parsePrimary(allocator: std.mem.Allocator, parse_allocator: std.mem.Allocator
number_node.* = .{ .literal = number_value };
return number_node;
},
+ .string => |s| {
+ _ = try tokens.next();
+ const string_value = try allocator.create(jv.Value);
+ string_value.* = .{ .string = try allocator.dupe(u8, s) };
+ const string_node = try parse_allocator.create(Ast);
+ string_node.* = .{ .literal = string_value };
+ return string_node;
+ },
.dot => {
_ = try tokens.next();
const ast = try parse_allocator.create(Ast);