summaryrefslogtreecommitdiff
path: root/src/config.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.zig')
-rw-r--r--src/config.zig14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/config.zig b/src/config.zig
index 53def6a1..7908774b 100644
--- a/src/config.zig
+++ b/src/config.zig
@@ -2030,14 +2030,21 @@ test {
/// The docs in docs/typ name words, keys and tags; each must still be here.
const doc_typ = struct {
- /// The string argument of every `name("...")` call in a source.
+ /// The leading string arguments of every `name("...", "...")` call in a
+ /// source: one for word, key and tag, each of them for keys.
fn calls(gpa: std.mem.Allocator, source: []const u8, comptime name: []const u8, out: *std.ArrayList([]const u8)) !void {
var at: usize = 0;
while (std.mem.indexOfPos(u8, source, at, name ++ "(\"")) |i| {
at = i + name.len + 2;
if (i > 0 and (std.ascii.isAlphanumeric(source[i - 1]) or source[i - 1] == '-')) continue;
- const end = std.mem.indexOfScalarPos(u8, source, at, '"') orelse return error.Unterminated;
- try out.append(gpa, source[at..end]);
+ while (true) {
+ const end = std.mem.indexOfScalarPos(u8, source, at, '"') orelse return error.Unterminated;
+ try out.append(gpa, source[at..end]);
+ at = end + 1;
+ while (at < source.len and (source[at] == ',' or source[at] == ' ')) at += 1;
+ if (at >= source.len or source[at] != '"') break;
+ at += 1;
+ }
}
}
@@ -2139,6 +2146,7 @@ test "docs/typ names only words, keys and default tags that exist" {
while (try it.next(io)) |entry| if (entry.kind == .file and std.mem.endsWith(u8, entry.name, ".typ")) {
const source = try dir.readFileAlloc(io, entry.name, gpa, .limited(1 << 20));
inline for (.{ "word", "key", "tag" }, &found) |name, *list| try doc_typ.calls(gpa, source, name, list);
+ try doc_typ.calls(gpa, source, "keys", &found[1]); // alternatives, each a key
};
inline for (.{ "word", "key", "tag" }, found) |name, list| {
try std.testing.expect(list.items.len >= 5);