blob: f7e752e49049772b5622630c9fc2aaa99e721366 (
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");
pub fn main() !u8 {
const alloc = std.heap.smp_allocator;
const io = std.Io.Threaded.global_single_threaded.io();
var stdin_buffer: [4096]u8 = undefined;
var stdin_reader = std.Io.File.stdin().reader(io, &stdin_buffer);
const reader = &stdin_reader.interface;
var stdout_buffer: [4096]u8 = undefined;
var stdout_writer = std.Io.File.stdout().writer(io, &stdout_buffer);
const writer = &stdout_writer.interface;
var p = try zisp.io.Parser.init(alloc, io);
defer p.deinit();
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();
}
}
|