summaryrefslogtreecommitdiff
path: root/src/sam_edit.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/sam_edit.zig')
-rw-r--r--src/sam_edit.zig17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/sam_edit.zig b/src/sam_edit.zig
index 8f7c961f..ea1105bd 100644
--- a/src/sam_edit.zig
+++ b/src/sam_edit.zig
@@ -111,11 +111,26 @@ pub fn waitsFor(arena: std.mem.Allocator, command: []const u8) Wait {
var ps: Parser = .{ .arena = arena, .src = src, .why = &why };
while (true) {
const c = ps.parse(0) catch
- return if (ps.open_text) .text else if (std.mem.eql(u8, why.text(), "unmatched `{'")) .group else .none;
+ return if (ps.open_text) .text else if (std.mem.eql(u8, why.text(), "unmatched `{'") or groupOpen(command)) .group else .none;
if (c == null) return if (ps.open_text) .text else .none;
}
}
+/// A `{` block not closed yet by its `}` line: a command in it that fails
+/// to parse still leaves the block to end at its `}`, so the error is that
+/// command's, not the `}`'s taken as a line of its own.
+fn groupOpen(command: []const u8) bool {
+ var depth: usize = 0;
+ var lines = std.mem.splitScalar(u8, command, '\n');
+ while (lines.next()) |raw| {
+ const line = std.mem.trim(u8, raw, " \t\r");
+ if (std.mem.eql(u8, line, "}")) {
+ depth -|= 1;
+ } else if (std.mem.endsWith(u8, line, "{")) depth += 1;
+ }
+ return depth > 0;
+}
+
pub fn needsMore(arena: std.mem.Allocator, command: []const u8) bool {
var why: Why = .{};
const src = std.fmt.allocPrint(arena, "{s}\n", .{command}) catch return false;