blob: 55fecdf1fa070d8c0fc98ff395e7a06cc44af349 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
const std = @import("std");
const zisp = @import("zisp");
const alloc = std.heap.smp_allocator;
const gstio = std.Io.Threaded.global_single_threaded.io();
pub fn main() !u8 {
var stdin_buffer: [4096]u8 = undefined;
var stdin_reader = std.Io.File.stdin().reader(gstio, &stdin_buffer);
const reader = &stdin_reader.interface;
var stdout_buffer: [4096]u8 = undefined;
var stdout_writer = std.Io.File.stdout().writer(gstio, &stdout_buffer);
const writer = &stdout_writer.interface;
var sfa = zisp.io.Parser.DefaultSfa.withFallback(alloc);
var p = try zisp.io.Parser.initWithSfa(&sfa, gstio);
while (true) {
const datum = p.run(reader) catch {
const format = "Parse error: {s}, pos: {d}, unread_char: {s}\n";
const err = p.err_msg;
const pos = stdin_reader.logicalPos();
const unread: [4]u8 =
if (p.unread_char) |c|
"0x".* ++ std.fmt.hex(c)
else
"none".*;
std.debug.print(format, .{ err, pos, unread });
return 1;
};
if (datum.eq(zisp.value.eof)) {
return 0;
}
try zisp.io.print.toWriter(writer, datum);
try writer.writeAll("\n");
try writer.flush();
}
}
|