0.11: run zig fmt

This commit is contained in:
Pierre Tachoire
2023-09-19 16:40:28 +02:00
parent 81b3aed888
commit e64ffa0c27
4 changed files with 71 additions and 71 deletions

View File

@@ -103,7 +103,7 @@ pub const Union = struct {
// third iteration to generate union type // third iteration to generate union type
var union_fields: [members_nb]std.builtin.Type.UnionField = undefined; var union_fields: [members_nb]std.builtin.Type.UnionField = undefined;
done = 0; done = 0;
for (tuple_members) |member, i| { for (tuple_members, 0..) |member, i| {
const member_T = @field(tuple, member.name); const member_T = @field(tuple, member.name);
const member_info = @typeInfo(member_T); const member_info = @typeInfo(member_T);
if (member_info == .Union) { if (member_info == .Union) {

View File

@@ -24,10 +24,10 @@ pub const HTMLDocument = struct {
pub fn _getElementById(self: *parser.DocumentHTML, id: []u8) ?*parser.HTMLElement { pub fn _getElementById(self: *parser.DocumentHTML, id: []u8) ?*parser.HTMLElement {
const body_html = parser.documentHTMLBody(self); const body_html = parser.documentHTMLBody(self);
const body_dom = @ptrCast(*parser.Element, body_html); const body_dom = @as(*parser.Element, @ptrCast(body_html));
const doc_dom = @ptrCast(*parser.Document, self); const doc_dom = @as(*parser.Document, @ptrCast(self));
const elem_dom = Document.getElementById(doc_dom, body_dom, id); 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 { 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 tags = comptime parser.Tag.all();
const elements = comptime parser.Tag.allElements(); const elements = comptime parser.Tag.allElements();
var createElements: [(tags.len - 1) * 3]Case = undefined; var createElements: [(tags.len - 1) * 3]Case = undefined;
inline for (tags) |tag, i| { inline for (tags, 0..) |tag, i| {
if (tag == .undef) { if (tag == .undef) {
continue; continue;
} }

View File

@@ -457,65 +457,65 @@ pub const HTMLVideoElement = struct {
pub fn ElementToHTMLElementInterface(elem: *parser.Element) HTMLElements { pub fn ElementToHTMLElementInterface(elem: *parser.Element) HTMLElements {
const tag = parser.nodeTag(parser.elementNode(elem)); const tag = parser.nodeTag(parser.elementNode(elem));
return switch (tag) { return switch (tag) {
.a => .{ .HTMLAnchorElement = @ptrCast(*parser.Anchor, elem) }, .a => .{ .HTMLAnchorElement = @as(*parser.Anchor, @ptrCast(elem)) },
.area => .{ .HTMLAreaElement = @ptrCast(*parser.Area, elem) }, .area => .{ .HTMLAreaElement = @as(*parser.Area, @ptrCast(elem)) },
.audio => .{ .HTMLAudioElement = @ptrCast(*parser.Audio, elem) }, .audio => .{ .HTMLAudioElement = @as(*parser.Audio, @ptrCast(elem)) },
.br => .{ .HTMLBRElement = @ptrCast(*parser.BR, elem) }, .br => .{ .HTMLBRElement = @as(*parser.BR, @ptrCast(elem)) },
.base => .{ .HTMLBaseElement = @ptrCast(*parser.Base, elem) }, .base => .{ .HTMLBaseElement = @as(*parser.Base, @ptrCast(elem)) },
.body => .{ .HTMLBodyElement = @ptrCast(*parser.Body, elem) }, .body => .{ .HTMLBodyElement = @as(*parser.Body, @ptrCast(elem)) },
.button => .{ .HTMLButtonElement = @ptrCast(*parser.Button, elem) }, .button => .{ .HTMLButtonElement = @as(*parser.Button, @ptrCast(elem)) },
.canvas => .{ .HTMLCanvasElement = @ptrCast(*parser.Canvas, elem) }, .canvas => .{ .HTMLCanvasElement = @as(*parser.Canvas, @ptrCast(elem)) },
.dl => .{ .HTMLDListElement = @ptrCast(*parser.DList, elem) }, .dl => .{ .HTMLDListElement = @as(*parser.DList, @ptrCast(elem)) },
.data => .{ .HTMLDataElement = @ptrCast(*parser.Data, elem) }, .data => .{ .HTMLDataElement = @as(*parser.Data, @ptrCast(elem)) },
.dialog => .{ .HTMLDialogElement = @ptrCast(*parser.Dialog, elem) }, .dialog => .{ .HTMLDialogElement = @as(*parser.Dialog, @ptrCast(elem)) },
.div => .{ .HTMLDivElement = @ptrCast(*parser.Div, elem) }, .div => .{ .HTMLDivElement = @as(*parser.Div, @ptrCast(elem)) },
.embed => .{ .HTMLEmbedElement = @ptrCast(*parser.Embed, elem) }, .embed => .{ .HTMLEmbedElement = @as(*parser.Embed, @ptrCast(elem)) },
.fieldset => .{ .HTMLFieldSetElement = @ptrCast(*parser.FieldSet, elem) }, .fieldset => .{ .HTMLFieldSetElement = @as(*parser.FieldSet, @ptrCast(elem)) },
.form => .{ .HTMLFormElement = @ptrCast(*parser.Form, elem) }, .form => .{ .HTMLFormElement = @as(*parser.Form, @ptrCast(elem)) },
.frameset => .{ .HTMLFrameSetElement = @ptrCast(*parser.FrameSet, elem) }, .frameset => .{ .HTMLFrameSetElement = @as(*parser.FrameSet, @ptrCast(elem)) },
.hr => .{ .HTMLHRElement = @ptrCast(*parser.HR, elem) }, .hr => .{ .HTMLHRElement = @as(*parser.HR, @ptrCast(elem)) },
.head => .{ .HTMLHeadElement = @ptrCast(*parser.Head, elem) }, .head => .{ .HTMLHeadElement = @as(*parser.Head, @ptrCast(elem)) },
.h1, .h2, .h3, .h4, .h5, .h6 => .{ .HTMLHeadingElement = @ptrCast(*parser.Heading, elem) }, .h1, .h2, .h3, .h4, .h5, .h6 => .{ .HTMLHeadingElement = @as(*parser.Heading, @ptrCast(elem)) },
.html => .{ .HTMLHtmlElement = @ptrCast(*parser.Html, elem) }, .html => .{ .HTMLHtmlElement = @as(*parser.Html, @ptrCast(elem)) },
.iframe => .{ .HTMLIFrameElement = @ptrCast(*parser.IFrame, elem) }, .iframe => .{ .HTMLIFrameElement = @as(*parser.IFrame, @ptrCast(elem)) },
.img => .{ .HTMLImageElement = @ptrCast(*parser.Image, elem) }, .img => .{ .HTMLImageElement = @as(*parser.Image, @ptrCast(elem)) },
.input => .{ .HTMLInputElement = @ptrCast(*parser.Input, elem) }, .input => .{ .HTMLInputElement = @as(*parser.Input, @ptrCast(elem)) },
.li => .{ .HTMLLIElement = @ptrCast(*parser.LI, elem) }, .li => .{ .HTMLLIElement = @as(*parser.LI, @ptrCast(elem)) },
.label => .{ .HTMLLabelElement = @ptrCast(*parser.Label, elem) }, .label => .{ .HTMLLabelElement = @as(*parser.Label, @ptrCast(elem)) },
.legend => .{ .HTMLLegendElement = @ptrCast(*parser.Legend, elem) }, .legend => .{ .HTMLLegendElement = @as(*parser.Legend, @ptrCast(elem)) },
.link => .{ .HTMLLinkElement = @ptrCast(*parser.Link, elem) }, .link => .{ .HTMLLinkElement = @as(*parser.Link, @ptrCast(elem)) },
.map => .{ .HTMLMapElement = @ptrCast(*parser.Map, elem) }, .map => .{ .HTMLMapElement = @as(*parser.Map, @ptrCast(elem)) },
.meta => .{ .HTMLMetaElement = @ptrCast(*parser.Meta, elem) }, .meta => .{ .HTMLMetaElement = @as(*parser.Meta, @ptrCast(elem)) },
.meter => .{ .HTMLMeterElement = @ptrCast(*parser.Meter, elem) }, .meter => .{ .HTMLMeterElement = @as(*parser.Meter, @ptrCast(elem)) },
.ins, .del => .{ .HTMLModElement = @ptrCast(*parser.Mod, elem) }, .ins, .del => .{ .HTMLModElement = @as(*parser.Mod, @ptrCast(elem)) },
.ol => .{ .HTMLOListElement = @ptrCast(*parser.OList, elem) }, .ol => .{ .HTMLOListElement = @as(*parser.OList, @ptrCast(elem)) },
.object => .{ .HTMLObjectElement = @ptrCast(*parser.Object, elem) }, .object => .{ .HTMLObjectElement = @as(*parser.Object, @ptrCast(elem)) },
.optgroup => .{ .HTMLOptGroupElement = @ptrCast(*parser.OptGroup, elem) }, .optgroup => .{ .HTMLOptGroupElement = @as(*parser.OptGroup, @ptrCast(elem)) },
.option => .{ .HTMLOptionElement = @ptrCast(*parser.Option, elem) }, .option => .{ .HTMLOptionElement = @as(*parser.Option, @ptrCast(elem)) },
.output => .{ .HTMLOutputElement = @ptrCast(*parser.Output, elem) }, .output => .{ .HTMLOutputElement = @as(*parser.Output, @ptrCast(elem)) },
.p => .{ .HTMLParagraphElement = @ptrCast(*parser.Paragraph, elem) }, .p => .{ .HTMLParagraphElement = @as(*parser.Paragraph, @ptrCast(elem)) },
.picture => .{ .HTMLPictureElement = @ptrCast(*parser.Picture, elem) }, .picture => .{ .HTMLPictureElement = @as(*parser.Picture, @ptrCast(elem)) },
.pre => .{ .HTMLPreElement = @ptrCast(*parser.Pre, elem) }, .pre => .{ .HTMLPreElement = @as(*parser.Pre, @ptrCast(elem)) },
.progress => .{ .HTMLProgressElement = @ptrCast(*parser.Progress, elem) }, .progress => .{ .HTMLProgressElement = @as(*parser.Progress, @ptrCast(elem)) },
.blockquote, .q => .{ .HTMLQuoteElement = @ptrCast(*parser.Quote, elem) }, .blockquote, .q => .{ .HTMLQuoteElement = @as(*parser.Quote, @ptrCast(elem)) },
.script => .{ .HTMLScriptElement = @ptrCast(*parser.Script, elem) }, .script => .{ .HTMLScriptElement = @as(*parser.Script, @ptrCast(elem)) },
.select => .{ .HTMLSelectElement = @ptrCast(*parser.Select, elem) }, .select => .{ .HTMLSelectElement = @as(*parser.Select, @ptrCast(elem)) },
.source => .{ .HTMLSourceElement = @ptrCast(*parser.Source, elem) }, .source => .{ .HTMLSourceElement = @as(*parser.Source, @ptrCast(elem)) },
.span => .{ .HTMLSpanElement = @ptrCast(*parser.Span, elem) }, .span => .{ .HTMLSpanElement = @as(*parser.Span, @ptrCast(elem)) },
.style => .{ .HTMLStyleElement = @ptrCast(*parser.Style, elem) }, .style => .{ .HTMLStyleElement = @as(*parser.Style, @ptrCast(elem)) },
.table => .{ .HTMLTableElement = @ptrCast(*parser.Table, elem) }, .table => .{ .HTMLTableElement = @as(*parser.Table, @ptrCast(elem)) },
.caption => .{ .HTMLTableCaptionElement = @ptrCast(*parser.TableCaption, elem) }, .caption => .{ .HTMLTableCaptionElement = @as(*parser.TableCaption, @ptrCast(elem)) },
.th, .td => .{ .HTMLTableCellElement = @ptrCast(*parser.TableCell, elem) }, .th, .td => .{ .HTMLTableCellElement = @as(*parser.TableCell, @ptrCast(elem)) },
.col => .{ .HTMLTableColElement = @ptrCast(*parser.TableCol, elem) }, .col => .{ .HTMLTableColElement = @as(*parser.TableCol, @ptrCast(elem)) },
.tr => .{ .HTMLTableRowElement = @ptrCast(*parser.TableRow, elem) }, .tr => .{ .HTMLTableRowElement = @as(*parser.TableRow, @ptrCast(elem)) },
.thead, .tbody, .tfoot => .{ .HTMLTableSectionElement = @ptrCast(*parser.TableSection, elem) }, .thead, .tbody, .tfoot => .{ .HTMLTableSectionElement = @as(*parser.TableSection, @ptrCast(elem)) },
.template => .{ .HTMLTemplateElement = @ptrCast(*parser.Template, elem) }, .template => .{ .HTMLTemplateElement = @as(*parser.Template, @ptrCast(elem)) },
.textarea => .{ .HTMLTextAreaElement = @ptrCast(*parser.TextArea, elem) }, .textarea => .{ .HTMLTextAreaElement = @as(*parser.TextArea, @ptrCast(elem)) },
.time => .{ .HTMLTimeElement = @ptrCast(*parser.Time, elem) }, .time => .{ .HTMLTimeElement = @as(*parser.Time, @ptrCast(elem)) },
.title => .{ .HTMLTitleElement = @ptrCast(*parser.Title, elem) }, .title => .{ .HTMLTitleElement = @as(*parser.Title, @ptrCast(elem)) },
.track => .{ .HTMLTrackElement = @ptrCast(*parser.Track, elem) }, .track => .{ .HTMLTrackElement = @as(*parser.Track, @ptrCast(elem)) },
.ul => .{ .HTMLUListElement = @ptrCast(*parser.UList, elem) }, .ul => .{ .HTMLUListElement = @as(*parser.UList, @ptrCast(elem)) },
.video => .{ .HTMLVideoElement = @ptrCast(*parser.Video, elem) }, .video => .{ .HTMLVideoElement = @as(*parser.Video, @ptrCast(elem)) },
.undef => .{ .HTMLUnknownElement = @ptrCast(*parser.Unknown, elem) }, .undef => .{ .HTMLUnknownElement = @as(*parser.Unknown, @ptrCast(elem)) },
}; };
} }

View File

@@ -85,8 +85,8 @@ pub const Tag = enum(u8) {
comptime { comptime {
const info = @typeInfo(Tag).Enum; const info = @typeInfo(Tag).Enum;
comptime var l: [info.fields.len]Tag = undefined; comptime var l: [info.fields.len]Tag = undefined;
inline for (info.fields) |field, i| { inline for (info.fields, 0..) |field, i| {
l[i] = @intToEnum(Tag, field.value); l[i] = @as(Tag, @enumFromInt(field.value));
} }
return &l; return &l;
} }
@@ -96,7 +96,7 @@ pub const Tag = enum(u8) {
comptime { comptime {
const tags = all(); const tags = all();
var names: [tags.len][]const u8 = undefined; var names: [tags.len][]const u8 = undefined;
inline for (tags) |tag, i| { inline for (tags, 0..) |tag, i| {
names[i] = tag.elementName(); names[i] = tag.elementName();
} }
return &names; return &names;
@@ -106,7 +106,7 @@ pub const Tag = enum(u8) {
fn upperName(comptime name: []const u8) []const u8 { fn upperName(comptime name: []const u8) []const u8 {
comptime { comptime {
var upper_name: [name.len]u8 = undefined; var upper_name: [name.len]u8 = undefined;
for (name) |char, i| { for (name, 0..) |char, i| {
var to_upper = false; var to_upper = false;
if (i == 0) { if (i == 0) {
to_upper = true; to_upper = true;
@@ -188,7 +188,7 @@ pub inline fn nodeTag(node: *Node) Tag {
if (val > 256) { if (val > 256) {
val = 0; val = 0;
} }
return @intToEnum(Tag, val); return @as(Tag, @enumFromInt(val));
} }
pub const nodeWalker = (fn (node: ?*Node, _: ?*anyopaque) callconv(.C) Action); 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 { 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 { pub inline fn nodeWalk(node: *Node, comptime walker: nodeWalker) !void {