authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-05-04 16:06:19 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-05-04 16:06:19 -07:00
logc4ea6821d39101414a44f0c2caa964fcde4a7e75
treea086bdc15703083ea732a62c18e8579755ef078e
parent9a0006c9365b60df65274b14e26d416798c1341f

let functions disambiguate whether or not theyre raw based on extra '#'


2 files changed, 4 insertions(+), 1 deletions(-)

src/astgen.zig+3
...@@ -51,6 +51,7 @@ pub const Body = []const Value;...@@ -51,6 +51,7 @@ pub const Body = []const Value;
5151
52pub const Fn = struct {52pub const Fn = struct {
53 name: string,53 name: string,
54 raw: bool,
54 args: []const []const string,55 args: []const []const string,
55};56};
5657
...@@ -145,6 +146,7 @@ const Parser = struct {...@@ -145,6 +146,7 @@ const Parser = struct {
145 }146 }
146 if (self.tryEatSymbol("{")) {147 if (self.tryEatSymbol("{")) {
147 if (self.tryEatSymbol("#")) {148 if (self.tryEatSymbol("#")) {
149 const fraw = self.tryEatSymbol("#");
148 const w = self.eat(.word);150 const w = self.eat(.word);
149 if (std.meta.stringToEnum(Block.Type, w)) |name| {151 if (std.meta.stringToEnum(Block.Type, w)) |name| {
150 const args = self.doArgs();152 const args = self.doArgs();
...@@ -174,6 +176,7 @@ const Parser = struct {...@@ -174,6 +176,7 @@ const Parser = struct {
174 }176 }
175 return Value{ .function = .{177 return Value{ .function = .{
176 .name = w,178 .name = w,
179 .raw = fraw,
177 .args = self.doArgs(),180 .args = self.doArgs(),
178 } };181 } };
179 }182 }
src/lib.zig+1-1
...@@ -171,7 +171,7 @@ inline fn do(comptime Ctx: type, alloc: std.mem.Allocator, writer: anytype, comp...@@ -171,7 +171,7 @@ inline fn do(comptime Ctx: type, alloc: std.mem.Allocator, writer: anytype, comp
171 const field_name = comptime std.fmt.comptimePrint("{d}", .{i + 2});171 const field_name = comptime std.fmt.comptimePrint("{d}", .{i + 2});
172 @field(args, field_name) = if (comptime std.mem.eql(u8, arg[0], "this")) search(arg[1..], data) else search(arg, ctx);172 @field(args, field_name) = if (comptime std.mem.eql(u8, arg[0], "this")) search(arg[1..], data) else search(arg, ctx);
173 }173 }
174 const repvalue = astgen.Value{ .replacement = .{ .arms = &.{"this"} } };174 const repvalue = astgen.Value{ .replacement = .{ .arms = &.{"this"}, .raw = v.raw } };
175 try @call(.auto, func, args);175 try @call(.auto, func, args);
176 try do(Ctx, alloc, writer, repvalue, try list.toOwnedSlice(), ctx, indent, flag1);176 try do(Ctx, alloc, writer, repvalue, try list.toOwnedSlice(), ctx, indent, flag1);
177 return;177 return;