In 0.15.1, there is a 'Cal$ ’ waiting for me to type in and press Enter. This is what I want.
In version 0.15.2, when I press Enter for the first time, it will automatically and continuously output 'Cal$ Cal$ … "
var stdout_buf: [1024]u8 = undefined;
var stdout_writer = std.fs.File.stdout().writer(&stdout_buf);
const stdout = &stdout_writer.interface;
// ...
fn prase(line: []const u8) !void {
var lexer = Lexer.init(line);
var token = lexer.next();
while (token.type != TokenType.EOF and token.type != TokenType.ERROR) {
try stdout.print("Token: {s}, Src: {s}\n", .{@tagName(token.type), token.src orelse "N/A"});
token = lexer.next();
}
try stdout.print("Cal$ ", .{});
try stdout.flush();
}
pub fn main() !void {
var stdin_buf: [1024]u8 = undefined;
var stdin_reader = std.fs.File.stdin().reader(&stdin_buf);
const stdin = &stdin_reader.interface;
try stdout.print("Cal$ ", .{});
try stdout.flush();
while (true) {
const line = stdin.takeDelimiterExclusive('\n') catch |e| switch (e) {
error.EndOfStream => break,
else => continue,
};
try prase(line);
}
}
Forgive me for the fact that my code seems to be written incorrectly.
I still don’t understand how to correctly implement my requirements, and I don’t even know what I need to look for in the documentation.
How can I modify my code? Or where should I start? Thank you!