diff options
Diffstat (limited to 'src/sam_edit.zig')
| -rw-r--r-- | src/sam_edit.zig | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/sam_edit.zig b/src/sam_edit.zig index 679823da..29dec726 100644 --- a/src/sam_edit.zig +++ b/src/sam_edit.zig @@ -390,7 +390,11 @@ const Exec = struct { fn address(ex: *Exec, expr: ?[]const u8, dot: Range) Failure!Range { const e = expr orelse return dot; var a: addr_lang.Addr = .{ .text = ex.text, .lim = null, .expr = e }; - const r = a.address(dot) orelse return fail(ex.why, "{s}", .{a.err}); + // A miss names the pattern that missed, not the whole Edit line. + const r = a.address(dot) orelse return if (std.mem.eql(u8, a.err, addr_lang.e_no_match)) + fail(ex.why, "no match for regexp {s}", .{e}) + else + fail(ex.why, "{s}", .{a.err}); if (a.i < e.len) return fail(ex.why, "bad address syntax", .{}); if (r.q0 > r.q1) return fail(ex.why, "addresses out of order", .{}); return r; @@ -537,7 +541,10 @@ const Exec = struct { did = true; if (!c.global) break; } - if (!did and ex.nest == 0) return fail(ex.why, "no substitution", .{}); + if (!did and ex.nest == 0) return if (r.q0 == r.q1) + fail(ex.why, "no substitution: dot is empty", .{}) + else + fail(ex.why, "no substitution", .{}); return r; } @@ -679,8 +686,9 @@ test "an Edit that fails halfway changes nothing, and says why in acme's words" var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator); defer arena_state.deinit(); for ([_][2][]const u8{ - .{ ",x/foo/c/bar/\n/nomatch/d", "no match for regexp" }, + .{ ",x/foo/c/bar/\n/nomatch/d", "no match for regexp /nomatch/" }, .{ ",s/zzz/y/", "no substitution" }, + .{ "s/foo/y/", "no substitution: dot is empty" }, .{ "k", "unknown command k" }, .{ ",x/a/{\na/1/\ni/2/\n}", "changes out of sequence" }, .{ "}", "right brace with no left brace" }, |
