diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2026-04-18 20:21:10 +0200 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2026-04-18 20:21:10 +0200 |
| commit | 8c5214df39ab82c3d42ccd492d8699f8a5aadb0a (patch) | |
| tree | 3ca338fffd31620470a898fd900c7a5f12188c5a /src/title.zig | |
| parent | 9b47b7ee8b80bf427116b4d2cf42e6f3c9d8be62 (diff) | |
feat(ast): test errors
Diffstat (limited to 'src/title.zig')
| -rw-r--r-- | src/title.zig | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/title.zig b/src/title.zig index 88848e5..d9b5612 100644 --- a/src/title.zig +++ b/src/title.zig @@ -5,10 +5,10 @@ const Lexer = @import("lexer/Lexer.zig"); const Element = @import("dom/Element.zig"); const paragraph = @import("paragraph.zig"); -pub const Error = paragraph.Error || Lexer.Error; +pub const Error = error{InvalidTitleContent} || paragraph.Error || Lexer.Error; pub fn parse(alloc: Allocator, l: *Lexer) Error!Element { - const v = (try l.next(alloc)).?; + var v = (try l.next(alloc)).?; var el = try Element.init(alloc, .content, switch (v.content.items.len) { 1 => "h1", 2 => "h2", @@ -19,5 +19,8 @@ pub fn parse(alloc: Allocator, l: *Lexer) Error!Element { else => unreachable, }); try el.appendContent(try paragraph.parseContent(alloc, l)); + v = (try l.next(alloc)) orelse return el; + if (!v.kind.isDelimiter()) return Error.InvalidTitleContent; + v.deinit(); return el; } |
