aboutsummaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig29
1 files changed, 24 insertions, 5 deletions
diff --git a/src/main.zig b/src/main.zig
index f350154..8797b31 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -37,6 +37,19 @@ fn write_result(
}
}
+fn write_summary(
+ writer: anytype,
+ is_tty: bool,
+ total: usize,
+ accepted: usize,
+) !void {
+ if (is_tty) {
+ try writer.print("finished {} ({} \x1b[32maccepted\x1b[0m {} \x1b[31mrejected\x1b[0m)\n", .{ total, accepted, total - accepted });
+ } else {
+ try writer.print("finished {} ({} accepted {} rejected)\n", .{ total, accepted, total - accepted });
+ }
+}
+
fn recognize(args: *RecognizeArgs, allocator: std.mem.Allocator) !void {
const stdout = std.io.getStdOut();
var bufwriter = std.io.bufferedWriter(stdout.writer());
@@ -53,6 +66,7 @@ fn recognize(args: *RecognizeArgs, allocator: std.mem.Allocator) !void {
var read_arena = std.heap.ArenaAllocator.init(allocator);
defer read_arena.deinit();
+ var number_of_accepted: usize = 0;
while (try reader.readUntilDelimiterOrEofAlloc(
read_arena.allocator(),
@@ -62,19 +76,23 @@ fn recognize(args: *RecognizeArgs, allocator: std.mem.Allocator) !void {
const trimmed = std.mem.trim(u8, buffer, &std.ascii.whitespace);
+ const accepted = try recognizer.check(
+ &args.grammar,
+ trimmed,
+ allocator
+ );
+
try write_result(
writer,
stdout.isTty(),
args.input.name,
index,
trimmed,
- try recognizer.check(
- &args.grammar,
- trimmed,
- allocator
- ));
+ accepted,
+ );
index += 1;
+ number_of_accepted += if (accepted) 1 else 0;
if (args.input.file.isTty()) {
try bufwriter.flush();
@@ -82,6 +100,7 @@ fn recognize(args: *RecognizeArgs, allocator: std.mem.Allocator) !void {
}
}
+ try write_summary(writer, stdout.isTty(), index, number_of_accepted);
try bufwriter.flush();
}