| author | |
| committer | |
| log | 96945468b693684b72b68a9135a51ca993a284ad |
| tree | 1f0c64346099639803c420cdc89e4449258fb785 |
| parent | bbac5cad9776dec9ea2e7d110cfcd0e7381a962c |
these are for when the 'foo' variable contains html you want to print
use at your own risk2 files changed, 19 insertions(+), 5 deletions(-)
src/astgen.zig+11-2| ... | ... | @@ -10,7 +10,7 @@ pub const Value = union(enum) { |
| 10 | 10 | element: Element, |
| 11 | 11 | attr: Attr, |
| 12 | 12 | string: string, |
| 13 | replacement: []const string, | |
| 13 | replacement: Replacement, | |
| 14 | 14 | block: Block, |
| 15 | 15 | body: Body, |
| 16 | 16 | function: Fn, |
| ... | ... | @@ -27,6 +27,11 @@ pub const Attr = struct { |
| 27 | 27 | value: union(enum) { string: string, body: Body }, |
| 28 | 28 | }; |
| 29 | 29 | |
| 30 | pub const Replacement = struct { | |
| 31 | arms: []const string, | |
| 32 | raw: bool = false, | |
| 33 | }; | |
| 34 | ||
| 30 | 35 | pub const Block = struct { |
| 31 | 36 | name: Type, |
| 32 | 37 | args: []const []const string, |
| ... | ... | @@ -172,7 +177,11 @@ const Parser = struct { |
| 172 | 177 | .args = self.doArgs(), |
| 173 | 178 | } }; |
| 174 | 179 | } |
| 175 | return Value{ .replacement = self.doReplacement() }; | |
| 180 | if (self.tryEatSymbol("{")) { | |
| 181 | defer self.eatSymbol("}"); | |
| 182 | return Value{ .replacement = .{ .arms = self.doReplacement(), .raw = true } }; | |
| 183 | } | |
| 184 | return Value{ .replacement = .{ .arms = self.doReplacement() } }; | |
| 176 | 185 | } |
| 177 | 186 | return Value{ .element = self.doElement() }; |
| 178 | 187 | } |
src/lib.zig+8-3| ... | ... | @@ -72,13 +72,18 @@ fn do(comptime Ctx: type, alloc: std.mem.Allocator, writer: anytype, comptime va |
| 72 | 72 | .string => |v| { |
| 73 | 73 | try writer.writeAll(v[1 .. v.len - 1]); |
| 74 | 74 | }, |
| 75 | .replacement => |v| { | |
| 75 | .replacement => |repl| { | |
| 76 | const v = repl.arms; | |
| 76 | 77 | const x = if (comptime std.mem.eql(u8, v[0], "this")) search(v[1..], data) else search(v, ctx); |
| 77 | 78 | const TO = @TypeOf(x); |
| 78 | 79 | const TI = @typeInfo(TO); |
| 79 | 80 | |
| 80 | 81 | if (comptime std.meta.trait.isZigString(TO)) { |
| 81 | const s: []const u8 = x; | |
| 82 | if (repl.raw) { | |
| 83 | try writer.writeAll(x); | |
| 84 | return; | |
| 85 | } | |
| 86 | const s: string = x; | |
| 82 | 87 | for (s) |c| { |
| 83 | 88 | if (entityLookupBefore(&[_]u8{c})) |ent| { |
| 84 | 89 | try writer.writeAll(ent.entity); |
| ... | ... | @@ -170,7 +175,7 @@ fn do(comptime Ctx: type, alloc: std.mem.Allocator, writer: anytype, comptime va |
| 170 | 175 | const field_name = comptime std.fmt.comptimePrint("{d}", .{i + 2}); |
| 171 | 176 | @field(args, field_name) = if (comptime std.mem.eql(u8, arg[0], "this")) search(arg[1..], data) else search(arg, ctx); |
| 172 | 177 | } |
| 173 | const repvalue = astgen.Value{ .replacement = &.{"this"} }; | |
| 178 | const repvalue = astgen.Value{ .replacement = .{ .arms = &.{"this"} } }; | |
| 174 | 179 | try @call(.{}, func, args); |
| 175 | 180 | try do(Ctx, alloc, writer, repvalue, list.toOwnedSlice(), ctx, indent, flag1); |
| 176 | 181 | return; |