From 32a251aa9645de070727a6ec91490d3e9219ec7c Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Fri, 9 Oct 2026 14:01:20 +0200 Subject: rename z framework to zeroscript --- src/z/html/Attribute.zig | 45 ------------ src/z/html/Document.zig | 11 --- src/z/html/Fragment.zig | 15 ---- src/z/html/Tag.zig | 53 --------------- src/z/html/element.zig | 30 -------- src/z/html/parser.zig | 174 ----------------------------------------------- src/z/html/root.zig | 6 -- 7 files changed, 334 deletions(-) delete mode 100644 src/z/html/Attribute.zig delete mode 100644 src/z/html/Document.zig delete mode 100644 src/z/html/Fragment.zig delete mode 100644 src/z/html/Tag.zig delete mode 100644 src/z/html/element.zig delete mode 100644 src/z/html/parser.zig delete mode 100644 src/z/html/root.zig (limited to 'src/z/html') diff --git a/src/z/html/Attribute.zig b/src/z/html/Attribute.zig deleted file mode 100644 index 1db49a0..0000000 --- a/src/z/html/Attribute.zig +++ /dev/null @@ -1,45 +0,0 @@ -const std = @import("std"); - -const Self = @This(); - -name: []const u8, -value: []const u8, - -pub fn from(attributes: anytype) []const Self { - const T = @TypeOf(attributes); - const info = @typeInfo(T); - - if (info != .@"struct") { - @compileError("struct needed"); - } - - const fields = info.@"struct".fields; - - var attrs: []const Self = &.{}; - - for (fields) |field| { - const name = field.name; - const value = @field(attributes, name); - - const next_attr: []const Self = &.{.{ .name = name, .value = value }}; - attrs = attrs ++ next_attr; - } - - return attrs; -} - -pub fn format(self: *const Self, writer: *std.Io.Writer) !void { - try writer.writeAll(self.name); - try writer.writeAll("=\""); - - var value: []const u8 = self.value; - - while (std.mem.findScalar(u8, value, '"')) |index| { - try writer.writeAll(value[0..index]); - try writer.writeAll("""); - value = value[index + 1..]; - } - - try writer.writeAll(value); - try writer.writeByte('"'); -} diff --git a/src/z/html/Document.zig b/src/z/html/Document.zig deleted file mode 100644 index b1122e1..0000000 --- a/src/z/html/Document.zig +++ /dev/null @@ -1,11 +0,0 @@ -const std = @import("std"); - -const Element = @import("root.zig").Element; - -const Self = @This(); - -root: Element, - -pub fn format(self: Self, writer: *std.Io.Writer) !void { - try writer.print("{f}", .{self.root}); -} diff --git a/src/z/html/Fragment.zig b/src/z/html/Fragment.zig deleted file mode 100644 index d05ad4a..0000000 --- a/src/z/html/Fragment.zig +++ /dev/null @@ -1,15 +0,0 @@ -const std = @import("std"); -const mod = @import("root.zig"); -const Element = mod.Element; - -const Self = @This(); - -elements: []const Element, - -pub fn format(self: *const Self, writer: *std.Io.Writer) !void { - for (self.elements) |element| { - try element.format(writer); - } -} - -pub const parse = mod.parser.fragment; diff --git a/src/z/html/Tag.zig b/src/z/html/Tag.zig deleted file mode 100644 index 90b5641..0000000 --- a/src/z/html/Tag.zig +++ /dev/null @@ -1,53 +0,0 @@ -const std = @import("std"); -const ctutils = @import("ctutils"); - -const mod = @import("root.zig"); -const Attribute = mod.Attribute; -const Element = mod.Element; - -const Self = @This(); - -pub const Content = union(enum) { - children: []const Element, - void: void, -}; - -name: []const u8, -attributes: []const Attribute, -content: Content, - -pub fn tag(name: []const u8, attributes: anytype, children: []const Element) Self { - return .{ - .name = name, - .attributes = Attribute.from(attributes), - .content = .{ .children = children }, - }; -} - -pub fn @"void"(name: []const u8, attributes: anytype) Self { - return .{ - .name = name, - .attributes = Attribute.from(attributes), - .content = .void, - }; -} - -pub fn format(self: *const Self, writer: *std.Io.Writer) !void { - try writer.writeByte('<'); - try writer.writeAll(self.name); - - for (self.attributes) |attribute| { - try writer.writeByte(' '); - try attribute.format(writer); - } - - try writer.writeByte('>'); - - switch (self.content) { - .children => |children| { - for (children) |child| try child.format(writer); - try writer.print("", .{self.name}); - }, - .void => {}, - } -} diff --git a/src/z/html/element.zig b/src/z/html/element.zig deleted file mode 100644 index 739eb0b..0000000 --- a/src/z/html/element.zig +++ /dev/null @@ -1,30 +0,0 @@ -const std = @import("std"); -const mod = @import("root.zig"); -const Attribute = mod.Attribute; -const Tag = mod.Tag; - -pub const Element = union(enum) { - const Self = @This(); - - tag: Tag, - string: []const u8, - - pub fn node(name: []const u8, attributes: anytype, children: []const Element) Self { - return .{ .tag = .tag(name, attributes, children) }; - } - - pub fn @"void"(name: []const u8, attribute: anytype) Self { - return .{ .tag = .void(name, attribute) }; - } - - pub fn text(content: []const u8) Self { - return .{ .string = content }; - } - - pub fn format(self: *const Self, writer: *std.Io.Writer) !void { - try switch (self.*) { - .string => |content| writer.writeAll(content), - .tag => |n| n.format(writer), - }; - } -}; diff --git a/src/z/html/parser.zig b/src/z/html/parser.zig deleted file mode 100644 index 38b28bb..0000000 --- a/src/z/html/parser.zig +++ /dev/null @@ -1,174 +0,0 @@ -const std = @import("std"); -const mod = @import("root.zig"); -const Element = mod.Element; -const Attribute = mod.Attribute; -const Tag = mod.Tag; -const Fragment = mod.Fragment; - -const tag_name: []const u8 = std.ascii.letters ++ .{ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-' }; -const void_elements: std.StaticStringMap(void) = .initComptime(.{ - .{"area"}, - .{"base"}, - .{"br"}, - .{"col"}, - .{"embed"}, - .{"hr"}, - .{"img"}, - .{"input"}, - .{"link"}, - .{"meta"}, - .{"param"}, - .{"source"}, - .{"track"}, - .{"wbr"}, -}); - -pub fn fragment(buffer: []const u8) Fragment { - @setEvalBranchQuota(buffer.len * 1000); - var elements: []const Element = &.{}; - var buf = buffer; - - while (buf.len > 0) { - const e, buf = element(buf); - elements = elements ++ .{e}; - } - - return .{ .elements = elements }; -} - -pub fn element(buffer: []const u8) struct { Element, []const u8 } { - if (buffer.len == 0) @panic("EOB, expected element"); - - switch (buffer[0]) { - '<' => { - const t, const b = tag(buffer); - return .{ .{ .tag = t }, b }; - }, - else => { - const t, const b = text(buffer); - return .{ .{ .string = t }, b }; - }, - } -} - -pub fn tag(buffer: []const u8) struct { Tag, []const u8 } { - if (buffer.len == 0) @panic("EOB, expected tag"); - - if (buffer[0] != '<') @panic("expected '<'"); - - var buf: []const u8 = buffer[1..]; - - const name = name: { - const index = std.mem.findNone(u8, buf, tag_name) orelse @panic("uncosed tag"); - defer buf = buf[index..]; - break :name buf[0..index]; - }; - - buf = std.mem.trimStart(u8, buf, &std.ascii.whitespace); - - var attributes: []const Attribute = &.{}; - - while (buf.len > 0 and buf[0] != '>') { - buf = std.mem.trimStart(u8, buf, &std.ascii.whitespace); - const attr, buf = attribute(buf); - attributes = attributes ++ .{attr}; - } - - if (buf.len == 0 or buf[0] != '>') @panic("expected tag-close"); - - buf = buf[1..]; - - if (void_elements.has(name)) { - return .{.{ - .name = name, - .attributes = attributes, - .content = .void, - }}; - } - - var children: []const Element = &.{}; - - buf = std.mem.trimStart(u8, buf, &std.ascii.whitespace); - - const closing = std.fmt.comptimePrint("", .{name}); - - while (buf.len > 0 and !std.mem.startsWith(u8, buf, closing)) { - const child, buf = element(buf); - children = children ++ .{child}; - buf = std.mem.trimStart(u8, buf, &std.ascii.whitespace); - } - - if (!std.mem.startsWith(u8, buf, closing)) @panic("expected closing-tag"); - - buf = buf[closing.len..]; - - return .{ - .{ - .name = name, - .attributes = attributes, - .content = .{ .children = children }, - }, - buf, - }; -} - -pub fn text(buffer: []const u8) struct { []const u8, []const u8 } { - const index = std.mem.findScalar(u8, buffer, '<') orelse buffer.len; - return .{ - std.mem.trim(u8, buffer[0..index], &std.ascii.whitespace), - buffer[index..], - }; -} - -pub fn attribute(buffer: []const u8) struct { Attribute, []const u8 } { - var buf = buffer; - - const name = name: { - const index = std.mem.findAny( - u8, - buf, - ">=\"'" ++ std.ascii.whitespace, - ) orelse @panic("EOB, expected attr-value"); - defer buf = buf[index..]; - break :name buf[0..index]; - }; - - if (name.len == 0) @panic("expected attr-name"); - - buf = std.mem.trimStart(u8, buf, &std.ascii.whitespace); - - if (buf.len == 0 or buf[0] == '>') { - return .{ .{ .name = name, .value = "" }, buf }; - } - - if (buf[0] != '=') @panic("expected attr-eql"); - - buf = std.mem.trimStart(u8, buf[1..], &std.ascii.whitespace); - - const delim = switch (buf[0]) { - '"' => "\"", - '\'' => "'", - else => std.ascii.whitespace ++ "=\"'<>`", - }; - - if (delim.len == 1) { - buf = buf[1..]; - } - - const value = value: { - const index = std.mem.findAny(u8, buf, delim) orelse if (delim.len == 1) - @panic("unclosed attr-value") - else - buf.len; - defer buf = buf[index + @intFromBool(delim.len == 1) ..]; - break :value buf[0..index]; - }; - - return .{ - .{ - .name = name, - .value = value, - }, - buf, - }; -} diff --git a/src/z/html/root.zig b/src/z/html/root.zig deleted file mode 100644 index 7bf91e8..0000000 --- a/src/z/html/root.zig +++ /dev/null @@ -1,6 +0,0 @@ -pub const Attribute = @import("Attribute.zig"); -pub const Tag = @import("Tag.zig"); -pub const Element = @import("element.zig").Element; -pub const Document = @import("Document.zig"); -pub const Fragment = @import("Fragment.zig"); -pub const parser = @import("parser.zig"); -- cgit v1.2.3-70-g09d2