update: add verbatim
This commit is contained in:
parent
0192ad0b64
commit
b7550e9b01
3 changed files with 89 additions and 1 deletions
|
|
@ -340,6 +340,52 @@ pub const Parser = struct {
|
|||
return error.UnclosedBlock;
|
||||
}
|
||||
|
||||
fn parseVerbatim(self: *Parser, allocator: std.mem.Allocator) !Node {
|
||||
const start = self.pos;
|
||||
|
||||
var depth: usize = 1;
|
||||
|
||||
while (self.pos < self.template.len and depth > 0) {
|
||||
if (self.peek(2)) |p| {
|
||||
if (std.mem.eql(u8, p, "{%")) {
|
||||
self.advance(2);
|
||||
self.skipWhitespace();
|
||||
|
||||
const content_start = self.pos;
|
||||
while (self.pos < self.template.len and !std.mem.eql(u8, self.peek(2) orelse "", "%}")) : (self.advance(1)) {}
|
||||
|
||||
if (self.pos + 2 > self.template.len or !std.mem.eql(u8, self.template[self.pos .. self.pos + 2], "%}")) {
|
||||
return error.UnclosedTag;
|
||||
}
|
||||
|
||||
const inner = std.mem.trim(u8, self.template[content_start..self.pos], " \t\r\n");
|
||||
|
||||
if (std.mem.eql(u8, inner, "verbatim")) {
|
||||
depth += 1;
|
||||
} else if (std.mem.eql(u8, inner, "endverbatim")) {
|
||||
depth -= 1;
|
||||
if (depth == 0) {
|
||||
// Copia até o início da tag endverbatim
|
||||
const content_end = content_start - 3; // retrocede "{% "
|
||||
const content = try allocator.dupe(u8, self.template[start..content_end]);
|
||||
self.advance(2); // consome %}
|
||||
return Node{
|
||||
.type = .text,
|
||||
.text = .{ .content = content },
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
self.advance(2);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
self.advance(1);
|
||||
}
|
||||
|
||||
return error.UnclosedVerbatim;
|
||||
}
|
||||
|
||||
fn parseSpacelessBlock(self: *Parser, allocator: std.mem.Allocator, raw_open: []const u8) !Node {
|
||||
var body = std.ArrayList(Node){};
|
||||
defer body.deinit(allocator);
|
||||
|
|
@ -525,6 +571,7 @@ pub const Parser = struct {
|
|||
|
||||
return error.UnclosedBlock;
|
||||
}
|
||||
|
||||
fn parseWithBlock(self: *Parser, allocator: std.mem.Allocator, assignments: []const Assignment, raw_open: []const u8) !Node {
|
||||
std.debug.print("Vou verificar se sou bloco with\n", .{});
|
||||
var body = std.ArrayList(Node){};
|
||||
|
|
@ -1164,6 +1211,18 @@ pub const Parser = struct {
|
|||
continue;
|
||||
}
|
||||
|
||||
if (std.mem.eql(u8, tag_name, "verbatim")) {
|
||||
allocator.free(node.tag.?.name);
|
||||
allocator.free(node.tag.?.args);
|
||||
|
||||
std.debug.print("3.0 - na real sou um verbatim\n", .{});
|
||||
std.debug.print("===================================\n", .{});
|
||||
|
||||
const verbatim_node = try self.parseVerbatim(allocator);
|
||||
try list.append(allocator, verbatim_node);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Para tags normais
|
||||
std.debug.print("===================================\n", .{});
|
||||
try list.append(allocator, node);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue