Skip to content

Commit 1594f14

Browse files
Merge pull request #399 from karlseguin/generate
Tweak generate.Tuple and generate.Union
2 parents 00d332c + fafd8c4 commit 1594f14

File tree

18 files changed

+213
-447
lines changed

18 files changed

+213
-447
lines changed

src/apiweb.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ pub const Interfaces = generate.Tuple(.{
4242
URL.Interfaces,
4343
Iterators.Interfaces,
4444
XMLSerializer.Interfaces,
45-
});
45+
}){};
4646

4747
pub const UserContext = @import("user_context.zig").UserContext;

src/browser/dump.zig

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ fn isVoid(elem: *parser.Element) !bool {
123123
fn writeEscapedTextNode(writer: anytype, value: []const u8) !void {
124124
var v = value;
125125
while (v.len > 0) {
126-
const index = std.mem.indexOfAnyPos(u8, v, 0, &.{'&', '<', '>'}) orelse {
126+
const index = std.mem.indexOfAnyPos(u8, v, 0, &.{ '&', '<', '>' }) orelse {
127127
return writer.writeAll(v);
128128
};
129129
try writer.writeAll(v[0..index]);
@@ -133,14 +133,14 @@ fn writeEscapedTextNode(writer: anytype, value: []const u8) !void {
133133
'>' => try writer.writeAll("&gt;"),
134134
else => unreachable,
135135
}
136-
v = v[index+1..];
136+
v = v[index + 1 ..];
137137
}
138138
}
139139

140140
fn writeEscapedAttributeValue(writer: anytype, value: []const u8) !void {
141141
var v = value;
142142
while (v.len > 0) {
143-
const index = std.mem.indexOfAnyPos(u8, v, 0, &.{'&', '<', '>', '"'}) orelse {
143+
const index = std.mem.indexOfAnyPos(u8, v, 0, &.{ '&', '<', '>', '"' }) orelse {
144144
return writer.writeAll(v);
145145
};
146146
try writer.writeAll(v[0..index]);
@@ -151,44 +151,46 @@ fn writeEscapedAttributeValue(writer: anytype, value: []const u8) !void {
151151
'"' => try writer.writeAll("&quot;"),
152152
else => unreachable,
153153
}
154-
v = v[index+1..];
154+
v = v[index + 1 ..];
155155
}
156156
}
157157

158158
const testing = std.testing;
159159
test "dump.writeHTML" {
160160
try testWriteHTML(
161161
"<div id=\"content\">Over 9000!</div>",
162-
"<div id=\"content\">Over 9000!</div>"
162+
"<div id=\"content\">Over 9000!</div>",
163163
);
164164

165165
try testWriteHTML(
166166
"<root><!-- a comment --></root>",
167-
"<root><!-- a comment --></root>"
167+
"<root><!-- a comment --></root>",
168168
);
169169

170170
try testWriteHTML(
171171
"<p>&lt; &gt; &amp;</p>",
172-
"<p>&lt; &gt; &amp;</p>"
172+
"<p>&lt; &gt; &amp;</p>",
173173
);
174174

175175
try testWriteHTML(
176176
"<p id=\"&quot;&gt;&lt;&amp;&quot;''\">wat?</p>",
177-
"<p id='\">&lt;&amp;&quot;&#39;&apos;'>wat?</p>"
177+
"<p id='\">&lt;&amp;&quot;&#39;&apos;'>wat?</p>",
178178
);
179179

180180
try testWriteFullHTML(
181181
\\<!DOCTYPE html>
182182
\\<html><head><title>It's over what?</title><meta name="a" value="b">
183183
\\</head><body>9000</body></html>
184184
\\
185-
,
186-
"<html><title>It's over what?</title><meta name=a value=\"b\">\n<body>9000"
187-
);
185+
, "<html><title>It's over what?</title><meta name=a value=\"b\">\n<body>9000");
188186
}
189187

190-
fn testWriteHTML(comptime expected: []const u8, src: []const u8) !void {
191-
return testWriteFullHTML("<!DOCTYPE html>\n<html><head></head><body>" ++ expected ++ "</body></html>\n", src);
188+
fn testWriteHTML(comptime expected_body: []const u8, src: []const u8) !void {
189+
const expected =
190+
"<!DOCTYPE html>\n<html><head></head><body>" ++
191+
expected_body ++
192+
"</body></html>\n";
193+
return testWriteFullHTML(expected, src);
192194
}
193195

194196
fn testWriteFullHTML(comptime expected: []const u8, src: []const u8) !void {

src/dom/character_data.zig

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ const std = @import("std");
2121
const jsruntime = @import("jsruntime");
2222
const Case = jsruntime.test_utils.Case;
2323
const checkCases = jsruntime.test_utils.checkCases;
24-
const generate = @import("../generate.zig");
2524

2625
const parser = @import("netsurf");
2726

@@ -32,12 +31,12 @@ const ProcessingInstruction = @import("processing_instruction.zig").ProcessingIn
3231
const HTMLElem = @import("../html/elements.zig");
3332

3433
// CharacterData interfaces
35-
pub const Interfaces = generate.Tuple(.{
34+
pub const Interfaces = .{
3635
Comment,
3736
Text.Text,
3837
Text.Interfaces,
3938
ProcessingInstruction,
40-
});
39+
};
4140

4241
// CharacterData implementation
4342
pub const CharacterData = struct {

src/dom/dom.zig

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
// You should have received a copy of the GNU Affero General Public License
1717
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1818

19-
const generate = @import("../generate.zig");
20-
2119
const DOMException = @import("exceptions.zig").DOMException;
2220
const EventTarget = @import("event_target.zig").EventTarget;
2321
const DOMImplementation = @import("implementation.zig").DOMImplementation;
@@ -27,7 +25,7 @@ const NodeList = @import("nodelist.zig");
2725
const Nod = @import("node.zig");
2826
const MutationObserver = @import("mutation_observer.zig");
2927

30-
pub const Interfaces = generate.Tuple(.{
28+
pub const Interfaces = .{
3129
DOMException,
3230
EventTarget,
3331
DOMImplementation,
@@ -37,4 +35,4 @@ pub const Interfaces = generate.Tuple(.{
3735
Nod.Node,
3836
Nod.Interfaces,
3937
MutationObserver.Interfaces,
40-
});
38+
};

src/dom/mutation_observer.zig

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,13 @@ const CallbackResult = jsruntime.CallbackResult;
2626
const Case = jsruntime.test_utils.Case;
2727
const checkCases = jsruntime.test_utils.checkCases;
2828

29-
const generate = @import("../generate.zig");
30-
3129
const NodeList = @import("nodelist.zig").NodeList;
3230

33-
pub const Interfaces = generate.Tuple(.{
31+
pub const Interfaces = .{
3432
MutationObserver,
3533
MutationRecord,
3634
MutationRecords,
37-
});
35+
};
3836

3937
const Walker = @import("../dom/walker.zig").WalkerChildren;
4038

src/dom/node.zig

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const HTML = @import("../html/html.zig");
4747
const HTMLElem = @import("../html/elements.zig");
4848

4949
// Node interfaces
50-
pub const Interfaces = generate.Tuple(.{
50+
pub const Interfaces = .{
5151
Attr,
5252
CData.CharacterData,
5353
CData.Interfaces,
@@ -57,12 +57,10 @@ pub const Interfaces = generate.Tuple(.{
5757
DocumentFragment,
5858
HTMLCollection,
5959
HTMLCollectionIterator,
60-
6160
HTML.Interfaces,
62-
});
63-
const Generated = generate.Union.compile(Interfaces);
64-
pub const Union = Generated._union;
65-
pub const Tags = Generated._enum;
61+
};
62+
63+
pub const Union = generate.Union(Interfaces);
6664

6765
// Node implementation
6866
pub const Node = struct {

src/dom/nodelist.zig

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const Callback = jsruntime.Callback;
2525
const CallbackResult = jsruntime.CallbackResult;
2626
const Case = jsruntime.test_utils.Case;
2727
const checkCases = jsruntime.test_utils.checkCases;
28-
const generate = @import("../generate.zig");
2928

3029
const NodeUnion = @import("node.zig").Union;
3130
const Node = @import("node.zig").Node;
@@ -36,10 +35,10 @@ const log = std.log.scoped(.nodelist);
3635

3736
const DOMException = @import("exceptions.zig").DOMException;
3837

39-
pub const Interfaces = generate.Tuple(.{
38+
pub const Interfaces = .{
4039
NodeListIterator,
4140
NodeList,
42-
});
41+
};
4342

4443
pub const NodeListIterator = struct {
4544
pub const mem_guarantied = true;

src/dom/text.zig

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ const std = @import("std");
2121
const jsruntime = @import("jsruntime");
2222
const Case = jsruntime.test_utils.Case;
2323
const checkCases = jsruntime.test_utils.checkCases;
24-
const generate = @import("../generate.zig");
2524

2625
const parser = @import("netsurf");
2726

@@ -31,9 +30,9 @@ const CDATASection = @import("cdata_section.zig").CDATASection;
3130
const UserContext = @import("../user_context.zig").UserContext;
3231

3332
// Text interfaces
34-
pub const Interfaces = generate.Tuple(.{
33+
pub const Interfaces = .{
3534
CDATASection,
36-
});
35+
};
3736

3837
pub const Text = struct {
3938
pub const Self = parser.Text;

src/events/event.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ const ProgressEvent = @import("../xhr/progress_event.zig").ProgressEvent;
3737
const log = std.log.scoped(.events);
3838

3939
// Event interfaces
40-
pub const Interfaces = generate.Tuple(.{
40+
pub const Interfaces = .{
4141
Event,
4242
ProgressEvent,
43-
});
44-
const Generated = generate.Union.compile(Interfaces);
45-
pub const Union = Generated._union;
43+
};
44+
45+
pub const Union = generate.Union(Interfaces);
4646

4747
// https://dom.spec.whatwg.org/#event
4848
pub const Event = struct {

0 commit comments

Comments
 (0)