aboutsummaryrefslogtreecommitdiff
path: root/src/content.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/content.zig')
-rw-r--r--src/content.zig28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/content.zig b/src/content.zig
index 72acbc7..68d88ad 100644
--- a/src/content.zig
+++ b/src/content.zig
@@ -2,7 +2,7 @@ const std = @import("std");
const Allocator = std.mem.Allocator;
const Token = @import("lexer/Token.zig");
const Lexer = @import("lexer/Lexer.zig");
-const Element = @import("dom/Element.zig");
+const Element = @import("Element.zig");
const parser = @import("parser.zig");
const link = @import("link.zig");
const testing = @import("testing.zig");
@@ -12,33 +12,33 @@ const doTestError = testing.doError;
pub const Error = error{ ModifierNotClosed, IllegalPlacement } || Lexer.Error || Allocator.Error;
pub fn parse(alloc: Allocator, l: *Lexer) Error!Element {
- var content = Element.initEmpty(alloc);
- errdefer content.deinit();
+ var content = try Element.Empty.init(alloc);
+ errdefer content.deinit(alloc);
const v = l.next().?;
switch (v.kind) {
.literal => {
- const el = try Element.initLitEscaped(alloc, v.content);
- try content.appendContent(el);
+ const el = try Element.Literal.init(alloc, v.content);
+ try content.content.append(alloc, el.element());
},
- .bold => try content.appendContent(try parseModifier(alloc, l, .bold, "b")),
- .italic => try content.appendContent(try parseModifier(alloc, l, .italic, "em")),
- .code => try content.appendContent(try parseModifier(alloc, l, .code, "code")),
+ .bold => try content.content.append(alloc, try parseModifier(alloc, l, .bold, "b")),
+ .italic => try content.content.append(alloc, try parseModifier(alloc, l, .italic, "em")),
+ .code => try content.content.append(alloc, try parseModifier(alloc, l, .code, "code")),
else => return Error.IllegalPlacement,
}
- return content;
+ return content.element();
}
-fn parseModifier(alloc: Allocator, l: *Lexer, knd: Token.Kind, tag: []const u8) Error!Element {
- var el = try Element.init(alloc, .content, tag);
- errdefer el.deinit();
+fn parseModifier(alloc: Allocator, l: *Lexer, knd: Token.Kind, comptime tag: []const u8) Error!Element {
+ var el = try Element.Modifier(tag).init(alloc);
+ errdefer el.deinit(alloc);
while (l.peek()) |next| {
if (next.kind == knd) {
// consuming the finisher
l.consume();
- return el;
+ return el.element();
}
if (next.kind.isDelimiter()) return Error.ModifierNotClosed;
- try el.appendContent(try parse(alloc, l));
+ try el.content.append(alloc, try parse(alloc, l));
}
return Error.ModifierNotClosed;
}