summaryrefslogtreecommitdiff
path: root/src/syntax.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-21 17:25:52 -0300
committerGabriel Schneider <[email protected]>2026-10-22 10:03:15 -0300
commit23518c9d7c061f8a06f6632da8b64b37801b514f (patch)
tree1f9688a5c2b2c224f47dd538ffab275b1f54da5c /src/syntax.zig
parentbc3d18d27f9fc1155db7fac3946c4d38774f9e65 (diff)
downloadpardes-23518c9d7c061f8a06f6632da8b64b37801b514f.tar.gz
pardes-23518c9d7c061f8a06f6632da8b64b37801b514f.zip
zig fmt for Zig 0.17
Diffstat (limited to 'src/syntax.zig')
-rw-r--r--src/syntax.zig82
1 files changed, 41 insertions, 41 deletions
diff --git a/src/syntax.zig b/src/syntax.zig
index fa212ca7..1c09c9f3 100644
--- a/src/syntax.zig
+++ b/src/syntax.zig
@@ -214,7 +214,7 @@ fn ensure(spec: *Spec) !Selected {
const capture_styles = spec.capture_styles[0..query.captureCount()];
for (capture_styles, 0..) |*style, id| {
const name = query.captureNameForId(@intCast(id)) orelse "";
- style.* = @intFromEnum(synFor(name));
+ style.* = @backingInt(synFor(name));
if (style.* == 0) query.disableCapture(name);
}
const parser = ts.Parser.create();
@@ -965,11 +965,11 @@ test "syntax formatted locations color hidden context and preserve multiline sou
const styles = try highlightLocationRows(gpa, content, &rows);
defer gpa.free(styles);
const body = std.mem.indexOf(u8, content, "comment body").?;
- try std.testing.expectEqual(@intFromEnum(Syn.comment), styles[body]);
- try std.testing.expectEqual(@intFromEnum(Syn.none), styles[body - 1]);
+ try std.testing.expectEqual(@backingInt(Syn.comment), styles[body]);
+ try std.testing.expectEqual(@backingInt(Syn.none), styles[body - 1]);
const number = std.mem.indexOf(u8, content, "42").?;
- try std.testing.expectEqual(@intFromEnum(Syn.number), styles[number]);
- try std.testing.expectEqual(@intFromEnum(Syn.none), styles[0]);
+ try std.testing.expectEqual(@backingInt(Syn.number), styles[number]);
+ try std.testing.expectEqual(@backingInt(Syn.none), styles[0]);
}
test "syntax formatted locations separate alignment from Markdown indentation" {
@@ -985,8 +985,8 @@ test "syntax formatted locations separate alignment from Markdown indentation" {
};
const styles = try highlightLocationRows(gpa, content, &rows);
defer gpa.free(styles);
- try std.testing.expectEqual(@intFromEnum(Syn.keyword), styles[std.mem.indexOf(u8, content, "Heading").?]);
- try std.testing.expectEqual(@intFromEnum(Syn.string), styles[std.mem.indexOf(u8, content, "Code").?]);
+ try std.testing.expectEqual(@backingInt(Syn.keyword), styles[std.mem.indexOf(u8, content, "Heading").?]);
+ try std.testing.expectEqual(@backingInt(Syn.string), styles[std.mem.indexOf(u8, content, "Code").?]);
}
fn inject(styles: []u8, source: []const u8, node: ts.Node, markdown: bool) void {
const kind = node.kind();
@@ -1149,7 +1149,7 @@ pub fn highlightDiffRows(gpa: std.mem.Allocator, content: []const u8, start_raw:
.meta, .old_path, .new_path => .comment,
else => .none,
};
- if (style != .none) window.fill(at, nl - at, @intFromEnum(style));
+ if (style != .none) window.fill(at, nl - at, @backingInt(style));
}
if (nl >= content.len) break;
at = nl + 1;
@@ -1192,10 +1192,10 @@ fn paintDiffPiece(gpa: std.mem.Allocator, window: anytype, bytes: []const u8, at
for (kinds) |kind| {
const line = lines.next() orelse break;
const style: u8 = switch (kind) {
- .added => @intFromEnum(Syn.string) | diff_added,
- .removed => @intFromEnum(Syn.number) | diff_removed,
- .no_newline => @intFromEnum(Syn.comment),
- .hunk => @intFromEnum(Syn.keyword),
+ .added => @backingInt(Syn.string) | diff_added,
+ .removed => @backingInt(Syn.number) | diff_removed,
+ .no_newline => @backingInt(Syn.comment),
+ .hunk => @backingInt(Syn.keyword),
else => 0,
};
if (style != 0) window.fill(at + offset, line.len, style);
@@ -1273,8 +1273,8 @@ fn paintHunk(gpa: std.mem.Allocator, out: []u8, bytes: []const u8, kinds: []cons
.removed => @memcpy(dst, old_colors[old_at..][0..code_len]),
.added => @memcpy(dst, new_colors[new_at..][0..code_len]),
.context => @memcpy(dst, if (context_new) new_colors[new_at..][0..code_len] else old_colors[old_at..][0..code_len]),
- .no_newline => @memset(out[offset..][0..line.len], @intFromEnum(Syn.comment)),
- .hunk => @memset(out[offset..][0..line.len], @intFromEnum(Syn.keyword)),
+ .no_newline => @memset(out[offset..][0..line.len], @backingInt(Syn.comment)),
+ .hunk => @memset(out[offset..][0..line.len], @backingInt(Syn.keyword)),
else => {},
}
if (kind == .context or kind == .removed) old_at += code_len + 1;
@@ -1322,8 +1322,8 @@ test "syntax a results row is coloured by the file its location names" {
try std.testing.expectEqual(content.len, styles.len);
for (styles[0.."src/a.zig:1:1".len]) |b| try std.testing.expectEqual(@as(u8, 0), b);
const zig_kw = std.mem.indexOf(u8, content, "struct").?;
- try std.testing.expectEqual(@intFromEnum(Syn.keyword), styles[zig_kw]);
- try std.testing.expectEqual(@intFromEnum(Syn.keyword), styles[zig_kw + 5]);
+ try std.testing.expectEqual(@backingInt(Syn.keyword), styles[zig_kw]);
+ try std.testing.expectEqual(@backingInt(Syn.keyword), styles[zig_kw + 5]);
const prose = std.mem.indexOf(u8, content, "just some prose").?;
for (styles[prose .. prose + 14]) |b| try std.testing.expectEqual(@as(u8, 0), b);
const bare = std.mem.indexOf(u8, content, "src/c.zig").?;
@@ -1371,14 +1371,14 @@ test "syntax default full grammar set highlights Typst source" {
const keyword_at = std.mem.indexOf(u8, source, "let").?;
const number_at = std.mem.indexOf(u8, source, "42").?;
const string_at = std.mem.indexOf(u8, source, "\"hello\"").?;
- try std.testing.expectEqual(Syn.comment, @as(Syn, @enumFromInt(styles[comment_at])));
- try std.testing.expectEqual(Syn.keyword, @as(Syn, @enumFromInt(styles[keyword_at])));
- try std.testing.expectEqual(Syn.number, @as(Syn, @enumFromInt(styles[number_at])));
- try std.testing.expectEqual(Syn.string, @as(Syn, @enumFromInt(styles[string_at])));
+ try std.testing.expectEqual(Syn.comment, @as(Syn, @fromBackingInt(@intCast(styles[comment_at]))));
+ try std.testing.expectEqual(Syn.keyword, @as(Syn, @fromBackingInt(@intCast(styles[keyword_at]))));
+ try std.testing.expectEqual(Syn.number, @as(Syn, @fromBackingInt(@intCast(styles[number_at]))));
+ try std.testing.expectEqual(Syn.string, @as(Syn, @fromBackingInt(@intCast(styles[string_at]))));
const short_ext = try highlightFileRange(std.testing.allocator, "paper.typ", source, 0, source.len);
defer std.testing.allocator.free(short_ext);
- try std.testing.expectEqual(Syn.keyword, @as(Syn, @enumFromInt(short_ext[keyword_at])));
+ try std.testing.expectEqual(Syn.keyword, @as(Syn, @fromBackingInt(@intCast(short_ext[keyword_at]))));
}
test "syntax Typst markup constructs paint and raw blocks inject their language" {
@@ -1403,7 +1403,7 @@ test "syntax Typst markup constructs paint and raw blocks inject their language"
const synAt = struct {
fn f(s: []const u8, src: []const u8, needle: []const u8, offset: usize) Syn {
- return @enumFromInt(s[std.mem.indexOf(u8, src, needle).? + offset]);
+ return @fromBackingInt(@intCast(s[std.mem.indexOf(u8, src, needle).? + offset]));
}
}.f;
try std.testing.expectEqual(Syn.keyword, synAt(styles, source, "= Heading", 0));
@@ -1443,7 +1443,7 @@ test "syntax markdown highlights markup, injects inline spans and fenced code bl
const synAt = struct {
fn f(s: []const u8, src: []const u8, needle: []const u8, offset: usize) Syn {
- return @enumFromInt(s[std.mem.indexOf(u8, src, needle).? + offset]);
+ return @fromBackingInt(@intCast(s[std.mem.indexOf(u8, src, needle).? + offset]));
}
}.f;
try std.testing.expectEqual(Syn.keyword, synAt(styles, source, "Title", 0));
@@ -1471,8 +1471,8 @@ test "syntax inline fast path agrees with full Markdown query" {
const actual = try std.testing.allocator.alloc(u8, source.len);
defer std.testing.allocator.free(actual);
for ([_]Syn{ .none, .keyword }) |background| {
- @memset(expected, @intFromEnum(background));
- @memset(actual, @intFromEnum(background));
+ @memset(expected, @backingInt(background));
+ @memset(actual, @backingInt(background));
runQuery(expected, sel, tree, 0);
inject(actual, source, tree.rootNode(), true);
if (!std.mem.eql(u8, expected, actual)) std.debug.print("inline mismatch: {s}\n", .{source});
@@ -1511,9 +1511,9 @@ test "syntax plain Markdown keeps block styles without starting the inline parse
const source = "# Heading\n\nPlain prose.\n\n indented code\n";
const styles = try highlightFileRange(std.testing.allocator, "a.md", source, 0, source.len);
defer std.testing.allocator.free(styles);
- try std.testing.expectEqual(@intFromEnum(Syn.keyword), styles[2]);
- try std.testing.expectEqual(@intFromEnum(Syn.none), styles[std.mem.indexOf(u8, source, "Plain").?]);
- try std.testing.expectEqual(@intFromEnum(Syn.string), styles[std.mem.indexOf(u8, source, "indented").?]);
+ try std.testing.expectEqual(@backingInt(Syn.keyword), styles[2]);
+ try std.testing.expectEqual(@backingInt(Syn.none), styles[std.mem.indexOf(u8, source, "Plain").?]);
+ try std.testing.expectEqual(@backingInt(Syn.string), styles[std.mem.indexOf(u8, source, "indented").?]);
for (specs) |spec| {
if (std.mem.eql(u8, spec.name, "markdown_inline")) try std.testing.expect(spec.selected == null);
}
@@ -1544,7 +1544,7 @@ test "syntax highlightDiff colors unified diff lines by prefix" {
}
fn diffSynAt(styles: []const u8, text: []const u8, needle: []const u8, offset: usize) Syn {
- return @enumFromInt(styles[std.mem.indexOf(u8, text, needle).? + offset] & syn_bits);
+ return @fromBackingInt(@intCast(styles[std.mem.indexOf(u8, text, needle).? + offset] & syn_bits));
}
test "syntax a Zig hunk is coloured as Zig, each side parsed whole" {
@@ -1715,7 +1715,7 @@ test "syntax a hunk painted once is kept, and a long one is parsed in pieces" {
const at = std.mem.indexOf(u8, content, "+const v1000 ").?;
const window = try highlightDiff(gpa, content, at, at + 200);
defer gpa.free(window);
- try std.testing.expectEqual(Syn.number, @as(Syn, @enumFromInt(window["+const v1000 = ".len] & syn_bits)));
+ try std.testing.expectEqual(Syn.number, @as(Syn, @fromBackingInt(@intCast(window["+const v1000 = ".len] & syn_bits))));
var cached: usize = 0;
for (diff_pieces) |slot| if (slot) |piece| {
cached += 1;
@@ -1780,7 +1780,7 @@ test "syntax query filtering preserves upstream colors" {
reference.query = raw_query;
reference.capture_styles = try std.testing.allocator.alloc(u8, raw_query.captureCount());
defer std.testing.allocator.free(reference.capture_styles);
- for (reference.capture_styles, 0..) |*style, id| style.* = @intFromEnum(synFor(raw_query.captureNameForId(@intCast(id)) orelse ""));
+ for (reference.capture_styles, 0..) |*style, id| style.* = @backingInt(synFor(raw_query.captureNameForId(@intCast(id)) orelse ""));
const tree = selected.parser.parseString(source, null) orelse return error.ParseFailed;
defer tree.destroy();
var expected: [source.len]u8 = @splat(0);
@@ -1806,8 +1806,8 @@ test "syntax Zig keyword captures cover both bytes beyond line ten thousand" {
defer std.testing.allocator.free(styles);
for ([_][]const u8{ "fn", "if" }) |keyword| {
const at = std.mem.indexOf(u8, code, keyword).?;
- try std.testing.expectEqual(@intFromEnum(Syn.keyword), styles[at]);
- try std.testing.expectEqual(@intFromEnum(Syn.keyword), styles[at + 1]);
+ try std.testing.expectEqual(@backingInt(Syn.keyword), styles[at]);
+ try std.testing.expectEqual(@backingInt(Syn.keyword), styles[at + 1]);
}
}
@@ -1823,8 +1823,8 @@ test "syntax allocator switching clears default-runtime caches" {
const restored = try highlightFileRange(std.testing.allocator, "a.zig", source, 0, source.len);
defer std.testing.allocator.free(restored);
defer stop();
- try std.testing.expectEqual(@intFromEnum(Syn.keyword), restored[0]);
- try std.testing.expectEqual(@intFromEnum(Syn.keyword), restored[1]);
+ try std.testing.expectEqual(@backingInt(Syn.keyword), restored[0]);
+ try std.testing.expectEqual(@backingInt(Syn.keyword), restored[1]);
}
test "syntax location context snapshots retain omitted multiline comment scope" {
@@ -1848,8 +1848,8 @@ test "syntax location context snapshots retain omitted multiline comment scope"
const styles = try highlightLocationRows(gpa, content, &rows);
defer gpa.free(styles);
for (styles[rows[0].code_start..][0..code.len]) |style|
- try std.testing.expectEqual(@intFromEnum(Syn.comment), style);
- try std.testing.expectEqual(@intFromEnum(Syn.none), styles[0]);
+ try std.testing.expectEqual(@backingInt(Syn.comment), style);
+ try std.testing.expectEqual(@backingInt(Syn.none), styles[0]);
}
test "syntax declaration locations clear snapshots without muting ordinary context" {
@@ -1875,7 +1875,7 @@ test "syntax declaration locations clear snapshots without muting ordinary conte
const styles = try highlightLocationRows(gpa, content, &rows);
defer gpa.free(styles);
for (styles[3..][0..header.len]) |style| try std.testing.expectEqual(@as(u8, 0), style);
- try std.testing.expectEqual(@intFromEnum(Syn.number), styles[std.mem.indexOf(u8, content, "42").?]);
+ try std.testing.expectEqual(@backingInt(Syn.number), styles[std.mem.indexOf(u8, content, "42").?]);
}
test "syntax stacked addresses do not split multiline source groups" {
@@ -1895,11 +1895,11 @@ test "syntax stacked addresses do not split multiline source groups" {
};
const styles = try highlightLocationRows(gpa, content, &rows);
defer gpa.free(styles);
- try std.testing.expectEqual(@intFromEnum(Syn.comment), styles[std.mem.indexOf(u8, content, "42").?]);
- try std.testing.expectEqual(@intFromEnum(Syn.number), styles[std.mem.indexOf(u8, content, "7;").?]);
+ try std.testing.expectEqual(@backingInt(Syn.comment), styles[std.mem.indexOf(u8, content, "42").?]);
+ try std.testing.expectEqual(@backingInt(Syn.number), styles[std.mem.indexOf(u8, content, "7;").?]);
for ([_][]const u8{ "a.c:1:1", "a.c:2:1", "a.c:3:1" }) |label| {
const at = std.mem.indexOf(u8, content, label).?;
- for (styles[at..][0..label.len]) |style| try std.testing.expectEqual(@intFromEnum(Syn.none), style);
+ for (styles[at..][0..label.len]) |style| try std.testing.expectEqual(@backingInt(Syn.none), style);
}
}