Skip to content

Commit e64a887

Browse files
authored
Fix deprecated tokenize->tokenizeAny in PIO assembler (#598)
1 parent 9663eaf commit e64a887

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

port/raspberrypi/rp2xxx/src/hal/pio/assembler.zig

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ fn format_compile_error(comptime message: []const u8, comptime source: []const u
9797
var line_str: []const u8 = "";
9898
var line_num: u32 = 1;
9999
var column: u32 = 0;
100-
var line_it = std.mem.tokenize(u8, source, "\n\r");
100+
var line_it = std.mem.tokenizeAny(u8, source, "\n\r");
101101
while (line_it.next()) |line| : (line_num += 1) {
102102
line_str = line_str ++ "\n" ++ line;
103103
if (line_it.index >= index) {
@@ -140,3 +140,26 @@ test "tokenizer and encoder" {
140140
test "comparison" {
141141
std.testing.refAllDecls(@import("assembler/comparison_tests.zig"));
142142
}
143+
144+
test "assemble" {
145+
// Test that the assembler can compile a simple program
146+
// this also verifies that the assemble function can be compiled
147+
_ = comptime assemble(.RP2040, ".program testprog", .{})
148+
.get_program_by_name("testprog");
149+
}
150+
151+
test "format compile error" {
152+
const result = comptime format_compile_error(
153+
"invalid instruction",
154+
".program testprog\n bad",
155+
19,
156+
);
157+
try std.testing.expectEqualStrings(
158+
\\failed to assemble PIO code:
159+
\\
160+
\\ bad
161+
\\ ^
162+
\\ invalid instruction
163+
\\
164+
, result);
165+
}

port/raspberrypi/rp2xxx/src/hal/pio/assembler/tokenizer.zig

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub fn Tokenizer(chip: Chip) type {
8787
, .{self.index});
8888

8989
var printed_cursor = false;
90-
var line_it = std.mem.tokenize(u8, self.source, "\n\r");
90+
var line_it = std.mem.tokenizeAny(u8, self.source, "\n\r");
9191
while (line_it.next()) |line| {
9292
try writer.print("{s}\n", .{line});
9393
if (!printed_cursor and line_it.index > self.index) {
@@ -2278,3 +2278,15 @@ test "tokenize.instr.comment with no whitespace" {
22782278
.delay = .{ .expression = "1" },
22792279
}, tokens.get(0));
22802280
}
2281+
2282+
test "format tokenizer" {
2283+
const test_tokenizer = Tokenizer(.RP2040).init("out 1");
2284+
const string = try std.fmt.allocPrint(std.testing.allocator, "{}", .{test_tokenizer});
2285+
defer std.testing.allocator.free(string);
2286+
try expectEqualStrings(
2287+
\\parser:
2288+
\\ index: 0
2289+
\\
2290+
\\out 1
2291+
++ "\n\x1b[30;42;1m^\x1b[0m\n", string);
2292+
}

0 commit comments

Comments
 (0)