update: add load

This commit is contained in:
Lucas F. 2026-01-03 20:13:59 -03:00
parent 510dec9113
commit bbab647430
3 changed files with 88 additions and 11 deletions

View file

@ -18,6 +18,11 @@ pub const NodeType = enum {
url,
cycle,
firstof,
load,
};
pub const LoadNode = struct {
libraries: []const []const u8,
};
pub const AutoescapeNode = struct {
@ -141,6 +146,7 @@ pub const Node = struct {
url: ?UrlNode = null,
cycle: ?CycleNode = null,
firstof: ?FirstOfNode = null,
load: ?LoadNode = null,
pub fn deinit(self: Node, allocator: std.mem.Allocator) void {
switch (self.type) {
@ -225,6 +231,10 @@ pub const Node = struct {
for (fo.values) |v| allocator.free(v);
allocator.free(fo.values);
},
.load => if (self.load) |l| {
for (l.libraries) |lib| allocator.free(lib);
allocator.free(l.libraries);
},
}
}
};
@ -1396,7 +1406,6 @@ pub const Parser = struct {
const value = std.mem.trim(u8, args[start..i], " \t\r\n\"'");
try values.append(allocator, try allocator.dupe(u8, value));
}
allocator.free(node.tag.?.name);
@ -1414,6 +1423,40 @@ pub const Parser = struct {
continue;
}
if (std.mem.eql(u8, tag_name, "load")) {
const args = node.tag.?.args;
var libraries = std.ArrayList([]const u8){};
defer libraries.deinit(allocator);
var i: usize = 0;
while (i < args.len) {
while (i < args.len and std.ascii.isWhitespace(args[i])) : (i += 1) {}
if (i >= args.len) break;
const start = i;
while (i < args.len and !std.ascii.isWhitespace(args[i])) : (i += 1) {}
const lib_name = args[start..i];
try libraries.append(allocator, try allocator.dupe(u8, lib_name));
}
allocator.free(node.tag.?.name);
allocator.free(node.tag.?.args);
std.debug.print("3.0 - na real sou um load\n", .{});
std.debug.print("===================================\n", .{});
try list.append(allocator, Node{
.type = .load,
.load = .{
.libraries = try libraries.toOwnedSlice(allocator),
},
});
continue;
}
// Para tags normais
std.debug.print("===================================\n", .{});
try list.append(allocator, node);