Skip to content

Commit f755e00

Browse files
committed
fix erroneous duplicate field error
1 parent 28fcb75 commit f755e00

4 files changed

Lines changed: 198 additions & 152 deletions

File tree

src/html.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
pub const Ast = @import("html/Ast.zig");
22
pub const Tokenizer = @import("html/Tokenizer.zig");
3+
pub const max_size = 4 * 1024 * 1024 * 1024;

src/html/Ast.zig

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const Ast = @This();
33
const std = @import("std");
44
const Tokenizer = @import("Tokenizer.zig");
55

6-
const log = std.log.scoped(.ast);
6+
const log = std.log.scoped(.@"html/ast");
77

88
const TagNameMap = std.StaticStringMapWithEql(
99
void,
@@ -24,6 +24,11 @@ const rawtext_names = TagNameMap.initComptime(.{
2424
.{ "noscript", {} },
2525
});
2626

27+
const unsupported_names = TagNameMap.initComptime(.{
28+
.{ "plaintext", {} },
29+
.{ "listing", {} },
30+
});
31+
2732
const Node = struct {
2833
tag: enum {
2934
root,
@@ -79,6 +84,7 @@ const Error = struct {
7984
missing_end_tag,
8085
erroneous_end_tag,
8186
duplicate_attribute_name,
87+
deprecated_and_unsupported,
8288
},
8389
},
8490
span: Tokenizer.Span,
@@ -198,8 +204,13 @@ pub fn init(gpa: std.mem.Allocator, src: []const u8) error{OutOfMemory}!Ast {
198204
tokenizer.gotoRcData(name);
199205
} else if (rawtext_names.has(name)) {
200206
tokenizer.gotoRawText(name);
201-
} else if (std.ascii.eqlIgnoreCase("plaintext", name)) {
202-
tokenizer.gotoPlainText();
207+
} else if (unsupported_names.has(name)) {
208+
try errors.append(.{
209+
.tag = .{
210+
.ast = .deprecated_and_unsupported,
211+
},
212+
.span = tag.name,
213+
});
203214
}
204215

205216
// check for duplicated attrs
@@ -216,7 +227,7 @@ pub fn init(gpa: std.mem.Allocator, src: []const u8) error{OutOfMemory}!Ast {
216227
.tag => break,
217228
.parse_error => {},
218229
.attr => |attr| {
219-
const attr_name = attr.name_raw.slice(tag_src);
230+
const attr_name = attr.name.slice(tag_src);
220231
log.debug("attr_name = '{s}'", .{attr_name});
221232
const gop = try seen_attrs.getOrPut(attr_name);
222233
if (gop.found_existing) {
@@ -225,8 +236,8 @@ pub fn init(gpa: std.mem.Allocator, src: []const u8) error{OutOfMemory}!Ast {
225236
.ast = .duplicate_attribute_name,
226237
},
227238
.span = .{
228-
.start = attr.name_raw.start + tag.span.start,
229-
.end = attr.name_raw.end + tag.span.start,
239+
.start = attr.name.start + tag.span.start,
240+
.end = attr.name.end + tag.span.start,
230241
},
231242
});
232243
}
@@ -515,12 +526,12 @@ pub fn render(ast: Ast, src: []const u8, w: anytype) !void {
515526

516527
.doctype => {
517528
last_rbracket = current.open.end;
518-
const maybe_name_raw, const maybe_extra = blk: {
529+
const maybe_name, const maybe_extra = blk: {
519530
var tt: Tokenizer = .{};
520531
const tag = current.open.slice(src);
521532
log.debug("doctype tag: {s} {any}", .{ tag, current });
522533
const dt = tt.next(tag).?.doctype;
523-
const maybe_name_raw: ?[]const u8 = if (dt.name_raw) |name|
534+
const maybe_name: ?[]const u8 = if (dt.name) |name|
524535
name.slice(tag)
525536
else
526537
null;
@@ -529,10 +540,10 @@ pub fn render(ast: Ast, src: []const u8, w: anytype) !void {
529540
else
530541
null;
531542

532-
break :blk .{ maybe_name_raw, maybe_extra };
543+
break :blk .{ maybe_name, maybe_extra };
533544
};
534545

535-
if (maybe_name_raw) |n| {
546+
if (maybe_name) |n| {
536547
try w.print("<!DOCTYPE {s}", .{n});
537548
} else {
538549
try w.print("<!DOCTYPE", .{});
@@ -584,9 +595,9 @@ pub fn render(ast: Ast, src: []const u8, w: anytype) !void {
584595
try w.print(" ", .{});
585596
}
586597
try w.print("{s}", .{
587-
attr.name_raw.slice(tag_src),
598+
attr.name.slice(tag_src),
588599
});
589-
if (attr.value_raw) |val| {
600+
if (attr.value) |val| {
590601
const q = switch (val.quote) {
591602
.none => "",
592603
.single => "'",

0 commit comments

Comments
 (0)