diff --git a/src/astgen.zig b/src/astgen.zig index ac58529ea2b5c0ab539cd7a989ccf179fde9a5f1..d5fca81c84dda1144715e27267f833834ec5d7dc 100644 --- a/src/astgen.zig +++ b/src/astgen.zig @@ -19,12 +19,12 @@ pub const Value = union(enum) { pub const Element = struct { name: string, attrs: []const Attr, - children: []const Value, + children: Body, }; pub const Attr = struct { key: string, - value: string, + value: union(enum) { string: string, body: Body }, }; pub const Block = struct { @@ -103,10 +103,17 @@ const Parser = struct { pub fn doAttr(comptime self: *Parser) Attr { const k = self.eat(.word); self.eatSymbol("="); + const body = self.doChildren(); + if (body.len > 0) { + return Attr{ + .key = k, + .value = .{ .body = body }, + }; + } const v = self.eat(.string); return Attr{ .key = k, - .value = v, + .value = .{ .string = v }, }; } diff --git a/src/lib.zig b/src/lib.zig index 87340096043ecfab7ebb7e8c9253dfc35bbe0881..4519d552bfb2e186fdb2753d81dd91682b1ed105 100644 --- a/src/lib.zig +++ b/src/lib.zig @@ -34,8 +34,15 @@ fn do(writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype try writer.writeAll("<"); try writer.writeAll(v.name); - for (v.attrs) |it| { - try writer.print(" {s}=\"{}\"", .{ it.key, std.zig.fmtEscapes(it.value[1 .. it.value.len - 1]) }); + inline for (v.attrs) |it| { + switch (comptime it.value) { + .string => try writer.print(" {s}=\"{}\"", .{ it.key, std.zig.fmtEscapes(it.value.string[1 .. it.value.string.len - 1]) }), + .body => { + try writer.print(" {s}=\"", .{it.key}); + try do(alloc, writer, astgen.Value{ .body = it.value.body }, data, ctx, indent, flag1); + try writer.print("\"", .{}); + }, + } } if (v.children.len == 0) {