aboutsummaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
authorLoris Cro <kappaloris@gmail.com>2025-06-14 00:31:29 +0200
committerGitHub <noreply@github.com>2025-06-13 22:31:29 +0000
commit180e8442af0c29924e021aed327bb4070665af65 (patch)
treea86d459db3355833525a86d0181effeac69b83d7 /src/main.zig
parenta74119ac49230a40012c0dd979e4c35eefcfd66a (diff)
downloadzig-180e8442af0c29924e021aed327bb4070665af65.tar.gz
zig-180e8442af0c29924e021aed327bb4070665af65.zip
zig init: simplify templating logic (#24170)
and also rename `advancedPrint` to `bufferedPrint` in the zig init templates These are left overs from my previous changes to zig init. The new templating system removes LITNAME because the new restrictions on package names make it redundant with NAME, and the use of underscores for marking templated identifiers lets us template variable names while still keeping zig fmt happy.
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig29
1 files changed, 11 insertions, 18 deletions
diff --git a/src/main.zig b/src/main.zig
index 3821fafb80..00954b2564 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -7290,34 +7290,27 @@ const Templates = struct {
new_line = false;
}
}
+
if (templates.strip and contents[i] == '\n') {
new_line = true;
- } else if (contents[i] == '_') {
- if (std.mem.startsWith(u8, contents[i..], "_LITNAME")) {
- try templates.buffer.appendSlice(root_name);
- i += "_LITNAME".len;
- continue;
- }
- } else if (contents[i] == '.') {
- if (std.mem.startsWith(u8, contents[i..], ".LITNAME")) {
- try templates.buffer.append('.');
+ } else if (contents[i] == '_' or contents[i] == '.') {
+ // Both '_' and '.' are allowed because depending on the context
+ // one prefix will be valid, while the other might not.
+ if (std.mem.startsWith(u8, contents[i + 1 ..], "NAME")) {
try templates.buffer.appendSlice(root_name);
- i += ".LITNAME".len;
+ i += "_NAME".len;
continue;
- } else if (std.mem.startsWith(u8, contents[i..], ".NAME")) {
- try templates.buffer.appendSlice(root_name);
- i += ".NAME".len;
- continue;
- } else if (std.mem.startsWith(u8, contents[i..], ".FINGERPRINT")) {
+ } else if (std.mem.startsWith(u8, contents[i + 1 ..], "FINGERPRINT")) {
try templates.buffer.writer().print("0x{x}", .{fingerprint.int()});
- i += ".FINGERPRINT".len;
+ i += "_FINGERPRINT".len;
continue;
- } else if (std.mem.startsWith(u8, contents[i..], ".ZIGVER")) {
+ } else if (std.mem.startsWith(u8, contents[i + 1 ..], "ZIGVER")) {
try templates.buffer.appendSlice(build_options.version);
- i += ".ZIGVER".len;
+ i += "_ZIGVER".len;
continue;
}
}
+
try templates.buffer.append(contents[i]);
i += 1;
}