From e64ffa0c27e7c27d88736bb111c4fee9ca0afb78 Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Tue, 19 Sep 2023 16:40:28 +0200 Subject: [PATCH] 0.11: run zig fmt --- src/generate.zig | 2 +- src/html/document.zig | 8 +-- src/html/elements.zig | 120 +++++++++++++++++++++--------------------- src/parser.zig | 12 ++--- 4 files changed, 71 insertions(+), 71 deletions(-) diff --git a/src/generate.zig b/src/generate.zig index d5e7fe1d..321c967b 100644 --- a/src/generate.zig +++ b/src/generate.zig @@ -103,7 +103,7 @@ pub const Union = struct { // third iteration to generate union type var union_fields: [members_nb]std.builtin.Type.UnionField = undefined; done = 0; - for (tuple_members) |member, i| { + for (tuple_members, 0..) |member, i| { const member_T = @field(tuple, member.name); const member_info = @typeInfo(member_T); if (member_info == .Union) { diff --git a/src/html/document.zig b/src/html/document.zig index 41b6003b..929cfcd8 100644 --- a/src/html/document.zig +++ b/src/html/document.zig @@ -24,10 +24,10 @@ pub const HTMLDocument = struct { pub fn _getElementById(self: *parser.DocumentHTML, id: []u8) ?*parser.HTMLElement { const body_html = parser.documentHTMLBody(self); - const body_dom = @ptrCast(*parser.Element, body_html); - const doc_dom = @ptrCast(*parser.Document, self); + const body_dom = @as(*parser.Element, @ptrCast(body_html)); + const doc_dom = @as(*parser.Document, @ptrCast(self)); const elem_dom = Document.getElementById(doc_dom, body_dom, id); - return @ptrCast(*parser.HTMLElement, elem_dom); + return @as(*parser.HTMLElement, @ptrCast(elem_dom)); } pub fn _createElement(self: *parser.DocumentHTML, tag_name: []const u8) E.HTMLElements { @@ -63,7 +63,7 @@ pub fn testExecFn( const tags = comptime parser.Tag.all(); const elements = comptime parser.Tag.allElements(); var createElements: [(tags.len - 1) * 3]Case = undefined; - inline for (tags) |tag, i| { + inline for (tags, 0..) |tag, i| { if (tag == .undef) { continue; } diff --git a/src/html/elements.zig b/src/html/elements.zig index a0a38209..ba9f9653 100644 --- a/src/html/elements.zig +++ b/src/html/elements.zig @@ -457,65 +457,65 @@ pub const HTMLVideoElement = struct { pub fn ElementToHTMLElementInterface(elem: *parser.Element) HTMLElements { const tag = parser.nodeTag(parser.elementNode(elem)); return switch (tag) { - .a => .{ .HTMLAnchorElement = @ptrCast(*parser.Anchor, elem) }, - .area => .{ .HTMLAreaElement = @ptrCast(*parser.Area, elem) }, - .audio => .{ .HTMLAudioElement = @ptrCast(*parser.Audio, elem) }, - .br => .{ .HTMLBRElement = @ptrCast(*parser.BR, elem) }, - .base => .{ .HTMLBaseElement = @ptrCast(*parser.Base, elem) }, - .body => .{ .HTMLBodyElement = @ptrCast(*parser.Body, elem) }, - .button => .{ .HTMLButtonElement = @ptrCast(*parser.Button, elem) }, - .canvas => .{ .HTMLCanvasElement = @ptrCast(*parser.Canvas, elem) }, - .dl => .{ .HTMLDListElement = @ptrCast(*parser.DList, elem) }, - .data => .{ .HTMLDataElement = @ptrCast(*parser.Data, elem) }, - .dialog => .{ .HTMLDialogElement = @ptrCast(*parser.Dialog, elem) }, - .div => .{ .HTMLDivElement = @ptrCast(*parser.Div, elem) }, - .embed => .{ .HTMLEmbedElement = @ptrCast(*parser.Embed, elem) }, - .fieldset => .{ .HTMLFieldSetElement = @ptrCast(*parser.FieldSet, elem) }, - .form => .{ .HTMLFormElement = @ptrCast(*parser.Form, elem) }, - .frameset => .{ .HTMLFrameSetElement = @ptrCast(*parser.FrameSet, elem) }, - .hr => .{ .HTMLHRElement = @ptrCast(*parser.HR, elem) }, - .head => .{ .HTMLHeadElement = @ptrCast(*parser.Head, elem) }, - .h1, .h2, .h3, .h4, .h5, .h6 => .{ .HTMLHeadingElement = @ptrCast(*parser.Heading, elem) }, - .html => .{ .HTMLHtmlElement = @ptrCast(*parser.Html, elem) }, - .iframe => .{ .HTMLIFrameElement = @ptrCast(*parser.IFrame, elem) }, - .img => .{ .HTMLImageElement = @ptrCast(*parser.Image, elem) }, - .input => .{ .HTMLInputElement = @ptrCast(*parser.Input, elem) }, - .li => .{ .HTMLLIElement = @ptrCast(*parser.LI, elem) }, - .label => .{ .HTMLLabelElement = @ptrCast(*parser.Label, elem) }, - .legend => .{ .HTMLLegendElement = @ptrCast(*parser.Legend, elem) }, - .link => .{ .HTMLLinkElement = @ptrCast(*parser.Link, elem) }, - .map => .{ .HTMLMapElement = @ptrCast(*parser.Map, elem) }, - .meta => .{ .HTMLMetaElement = @ptrCast(*parser.Meta, elem) }, - .meter => .{ .HTMLMeterElement = @ptrCast(*parser.Meter, elem) }, - .ins, .del => .{ .HTMLModElement = @ptrCast(*parser.Mod, elem) }, - .ol => .{ .HTMLOListElement = @ptrCast(*parser.OList, elem) }, - .object => .{ .HTMLObjectElement = @ptrCast(*parser.Object, elem) }, - .optgroup => .{ .HTMLOptGroupElement = @ptrCast(*parser.OptGroup, elem) }, - .option => .{ .HTMLOptionElement = @ptrCast(*parser.Option, elem) }, - .output => .{ .HTMLOutputElement = @ptrCast(*parser.Output, elem) }, - .p => .{ .HTMLParagraphElement = @ptrCast(*parser.Paragraph, elem) }, - .picture => .{ .HTMLPictureElement = @ptrCast(*parser.Picture, elem) }, - .pre => .{ .HTMLPreElement = @ptrCast(*parser.Pre, elem) }, - .progress => .{ .HTMLProgressElement = @ptrCast(*parser.Progress, elem) }, - .blockquote, .q => .{ .HTMLQuoteElement = @ptrCast(*parser.Quote, elem) }, - .script => .{ .HTMLScriptElement = @ptrCast(*parser.Script, elem) }, - .select => .{ .HTMLSelectElement = @ptrCast(*parser.Select, elem) }, - .source => .{ .HTMLSourceElement = @ptrCast(*parser.Source, elem) }, - .span => .{ .HTMLSpanElement = @ptrCast(*parser.Span, elem) }, - .style => .{ .HTMLStyleElement = @ptrCast(*parser.Style, elem) }, - .table => .{ .HTMLTableElement = @ptrCast(*parser.Table, elem) }, - .caption => .{ .HTMLTableCaptionElement = @ptrCast(*parser.TableCaption, elem) }, - .th, .td => .{ .HTMLTableCellElement = @ptrCast(*parser.TableCell, elem) }, - .col => .{ .HTMLTableColElement = @ptrCast(*parser.TableCol, elem) }, - .tr => .{ .HTMLTableRowElement = @ptrCast(*parser.TableRow, elem) }, - .thead, .tbody, .tfoot => .{ .HTMLTableSectionElement = @ptrCast(*parser.TableSection, elem) }, - .template => .{ .HTMLTemplateElement = @ptrCast(*parser.Template, elem) }, - .textarea => .{ .HTMLTextAreaElement = @ptrCast(*parser.TextArea, elem) }, - .time => .{ .HTMLTimeElement = @ptrCast(*parser.Time, elem) }, - .title => .{ .HTMLTitleElement = @ptrCast(*parser.Title, elem) }, - .track => .{ .HTMLTrackElement = @ptrCast(*parser.Track, elem) }, - .ul => .{ .HTMLUListElement = @ptrCast(*parser.UList, elem) }, - .video => .{ .HTMLVideoElement = @ptrCast(*parser.Video, elem) }, - .undef => .{ .HTMLUnknownElement = @ptrCast(*parser.Unknown, elem) }, + .a => .{ .HTMLAnchorElement = @as(*parser.Anchor, @ptrCast(elem)) }, + .area => .{ .HTMLAreaElement = @as(*parser.Area, @ptrCast(elem)) }, + .audio => .{ .HTMLAudioElement = @as(*parser.Audio, @ptrCast(elem)) }, + .br => .{ .HTMLBRElement = @as(*parser.BR, @ptrCast(elem)) }, + .base => .{ .HTMLBaseElement = @as(*parser.Base, @ptrCast(elem)) }, + .body => .{ .HTMLBodyElement = @as(*parser.Body, @ptrCast(elem)) }, + .button => .{ .HTMLButtonElement = @as(*parser.Button, @ptrCast(elem)) }, + .canvas => .{ .HTMLCanvasElement = @as(*parser.Canvas, @ptrCast(elem)) }, + .dl => .{ .HTMLDListElement = @as(*parser.DList, @ptrCast(elem)) }, + .data => .{ .HTMLDataElement = @as(*parser.Data, @ptrCast(elem)) }, + .dialog => .{ .HTMLDialogElement = @as(*parser.Dialog, @ptrCast(elem)) }, + .div => .{ .HTMLDivElement = @as(*parser.Div, @ptrCast(elem)) }, + .embed => .{ .HTMLEmbedElement = @as(*parser.Embed, @ptrCast(elem)) }, + .fieldset => .{ .HTMLFieldSetElement = @as(*parser.FieldSet, @ptrCast(elem)) }, + .form => .{ .HTMLFormElement = @as(*parser.Form, @ptrCast(elem)) }, + .frameset => .{ .HTMLFrameSetElement = @as(*parser.FrameSet, @ptrCast(elem)) }, + .hr => .{ .HTMLHRElement = @as(*parser.HR, @ptrCast(elem)) }, + .head => .{ .HTMLHeadElement = @as(*parser.Head, @ptrCast(elem)) }, + .h1, .h2, .h3, .h4, .h5, .h6 => .{ .HTMLHeadingElement = @as(*parser.Heading, @ptrCast(elem)) }, + .html => .{ .HTMLHtmlElement = @as(*parser.Html, @ptrCast(elem)) }, + .iframe => .{ .HTMLIFrameElement = @as(*parser.IFrame, @ptrCast(elem)) }, + .img => .{ .HTMLImageElement = @as(*parser.Image, @ptrCast(elem)) }, + .input => .{ .HTMLInputElement = @as(*parser.Input, @ptrCast(elem)) }, + .li => .{ .HTMLLIElement = @as(*parser.LI, @ptrCast(elem)) }, + .label => .{ .HTMLLabelElement = @as(*parser.Label, @ptrCast(elem)) }, + .legend => .{ .HTMLLegendElement = @as(*parser.Legend, @ptrCast(elem)) }, + .link => .{ .HTMLLinkElement = @as(*parser.Link, @ptrCast(elem)) }, + .map => .{ .HTMLMapElement = @as(*parser.Map, @ptrCast(elem)) }, + .meta => .{ .HTMLMetaElement = @as(*parser.Meta, @ptrCast(elem)) }, + .meter => .{ .HTMLMeterElement = @as(*parser.Meter, @ptrCast(elem)) }, + .ins, .del => .{ .HTMLModElement = @as(*parser.Mod, @ptrCast(elem)) }, + .ol => .{ .HTMLOListElement = @as(*parser.OList, @ptrCast(elem)) }, + .object => .{ .HTMLObjectElement = @as(*parser.Object, @ptrCast(elem)) }, + .optgroup => .{ .HTMLOptGroupElement = @as(*parser.OptGroup, @ptrCast(elem)) }, + .option => .{ .HTMLOptionElement = @as(*parser.Option, @ptrCast(elem)) }, + .output => .{ .HTMLOutputElement = @as(*parser.Output, @ptrCast(elem)) }, + .p => .{ .HTMLParagraphElement = @as(*parser.Paragraph, @ptrCast(elem)) }, + .picture => .{ .HTMLPictureElement = @as(*parser.Picture, @ptrCast(elem)) }, + .pre => .{ .HTMLPreElement = @as(*parser.Pre, @ptrCast(elem)) }, + .progress => .{ .HTMLProgressElement = @as(*parser.Progress, @ptrCast(elem)) }, + .blockquote, .q => .{ .HTMLQuoteElement = @as(*parser.Quote, @ptrCast(elem)) }, + .script => .{ .HTMLScriptElement = @as(*parser.Script, @ptrCast(elem)) }, + .select => .{ .HTMLSelectElement = @as(*parser.Select, @ptrCast(elem)) }, + .source => .{ .HTMLSourceElement = @as(*parser.Source, @ptrCast(elem)) }, + .span => .{ .HTMLSpanElement = @as(*parser.Span, @ptrCast(elem)) }, + .style => .{ .HTMLStyleElement = @as(*parser.Style, @ptrCast(elem)) }, + .table => .{ .HTMLTableElement = @as(*parser.Table, @ptrCast(elem)) }, + .caption => .{ .HTMLTableCaptionElement = @as(*parser.TableCaption, @ptrCast(elem)) }, + .th, .td => .{ .HTMLTableCellElement = @as(*parser.TableCell, @ptrCast(elem)) }, + .col => .{ .HTMLTableColElement = @as(*parser.TableCol, @ptrCast(elem)) }, + .tr => .{ .HTMLTableRowElement = @as(*parser.TableRow, @ptrCast(elem)) }, + .thead, .tbody, .tfoot => .{ .HTMLTableSectionElement = @as(*parser.TableSection, @ptrCast(elem)) }, + .template => .{ .HTMLTemplateElement = @as(*parser.Template, @ptrCast(elem)) }, + .textarea => .{ .HTMLTextAreaElement = @as(*parser.TextArea, @ptrCast(elem)) }, + .time => .{ .HTMLTimeElement = @as(*parser.Time, @ptrCast(elem)) }, + .title => .{ .HTMLTitleElement = @as(*parser.Title, @ptrCast(elem)) }, + .track => .{ .HTMLTrackElement = @as(*parser.Track, @ptrCast(elem)) }, + .ul => .{ .HTMLUListElement = @as(*parser.UList, @ptrCast(elem)) }, + .video => .{ .HTMLVideoElement = @as(*parser.Video, @ptrCast(elem)) }, + .undef => .{ .HTMLUnknownElement = @as(*parser.Unknown, @ptrCast(elem)) }, }; } diff --git a/src/parser.zig b/src/parser.zig index 3b180e0e..8a3586bd 100644 --- a/src/parser.zig +++ b/src/parser.zig @@ -85,8 +85,8 @@ pub const Tag = enum(u8) { comptime { const info = @typeInfo(Tag).Enum; comptime var l: [info.fields.len]Tag = undefined; - inline for (info.fields) |field, i| { - l[i] = @intToEnum(Tag, field.value); + inline for (info.fields, 0..) |field, i| { + l[i] = @as(Tag, @enumFromInt(field.value)); } return &l; } @@ -96,7 +96,7 @@ pub const Tag = enum(u8) { comptime { const tags = all(); var names: [tags.len][]const u8 = undefined; - inline for (tags) |tag, i| { + inline for (tags, 0..) |tag, i| { names[i] = tag.elementName(); } return &names; @@ -106,7 +106,7 @@ pub const Tag = enum(u8) { fn upperName(comptime name: []const u8) []const u8 { comptime { var upper_name: [name.len]u8 = undefined; - for (name) |char, i| { + for (name, 0..) |char, i| { var to_upper = false; if (i == 0) { to_upper = true; @@ -188,7 +188,7 @@ pub inline fn nodeTag(node: *Node) Tag { if (val > 256) { val = 0; } - return @intToEnum(Tag, val); + return @as(Tag, @enumFromInt(val)); } pub const nodeWalker = (fn (node: ?*Node, _: ?*anyopaque) callconv(.C) Action); @@ -199,7 +199,7 @@ pub inline fn nodeName(node: *Node) [*c]const u8 { } pub inline fn nodeType(node: *Node) NodeType { - return @intToEnum(NodeType, node.*.type); + return @as(NodeType, @enumFromInt(node.*.type)); } pub inline fn nodeWalk(node: *Node, comptime walker: nodeWalker) !void {