From 058bf8deb90c21c3d318df79af173a2b527de439 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 10 Sep 2019 14:51:41 -0300 Subject: [PATCH] add push and list commands --- src/main.zig | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main.zig b/src/main.zig index c0af701..1c7acaf 100644 --- a/src/main.zig +++ b/src/main.zig @@ -43,6 +43,7 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { defer lang.deinit(); while (true) { + lang.reset(); try stdout.print("> "); var buffer = try std.Buffer.init(allocator, ""[0..]); @@ -51,19 +52,20 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { return err; }; + if (std.mem.eql(u8, line, "push")) { + try file.seekTo(0); + try printer.printList(cmds, stream); + continue; + } else if (std.mem.eql(u8, line, "list")) { + try printer.printList(cmds, stream); + continue; + } + var cmds_parsed = lang.parse(line) catch |err| { std.debug.warn("repl: error while parsing: {}\n", err); continue; }; try cmds.append(cmds_parsed.at(0)); - - lang.reset(); - - // TODO save the line to scri_file? or should we have a special `push` - // to do so? - - try file.seekTo(0); - try printer.printList(cmds, stream); } }