From 88a73e64d81910a7ffb10c5be45f218041b18978 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 10 Sep 2019 15:44:10 -0300 Subject: [PATCH] better repl logic --- src/main.zig | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main.zig b/src/main.zig index 1c7acaf..671ed3f 100644 --- a/src/main.zig +++ b/src/main.zig @@ -39,9 +39,15 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { // TODO start a runner and keep it hot + // we keep + // - a CommandList with the full commands we have right now + // - a Command with the current last typed successful command + var lang = langs.Lang.init(allocator); defer lang.deinit(); + var current: langs.Command = undefined; + while (true) { lang.reset(); try stdout.print("> "); @@ -53,10 +59,13 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { }; if (std.mem.eql(u8, line, "push")) { - try file.seekTo(0); - try printer.printList(cmds, stream); + try cmds.append(current); continue; } else if (std.mem.eql(u8, line, "list")) { + try printer.printList(cmds, stdout); + continue; + } else if (std.mem.eql(u8, line, "save")) { + try file.seekTo(0); try printer.printList(cmds, stream); continue; } @@ -65,7 +74,7 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { std.debug.warn("repl: error while parsing: {}\n", err); continue; }; - try cmds.append(cmds_parsed.at(0)); + current = cmds_parsed.at(0); } }