From 7c9273605dc63da509f3754202bf4b042fe257fc Mon Sep 17 00:00:00 2001 From: torque Date: Fri, 31 Mar 2023 15:37:52 -0700 Subject: [PATCH] parser: segment eager and normal conversion The main difference is that regular conversion now only happens after the entire command line (including all subcommands) have been parsed. This means that a failing normal converter won't prevent subcommand eager converters from running. However, parsing errors can still preclude eager converters and subcommand parsing from happening. --- source/parser.zig | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/source/parser.zig b/source/parser.zig index 4178423..4913bc2 100644 --- a/source/parser.zig +++ b/source/parser.zig @@ -117,8 +117,7 @@ pub fn Parser(comptime command: anytype, comptime callback: anytype) type { pub fn subparse(self: *@This(), context: *UserContext, args: [][:0]u8, env: std.process.EnvMap) anyerror!void { const sliceto = try self.parse(args); try self.read_environment(env); - // try self.convert_eager(context); - try self.convert(context); + try self.convert_eager(context); inline for (@typeInfo(@TypeOf(self.intermediate)).Struct.fields) |field| { if (@field(self.intermediate, field.name) == null) { @@ -133,7 +132,7 @@ pub fn Parser(comptime command: anytype, comptime callback: anytype) type { } pub fn finish(self: *@This(), context: *UserContext) anyerror!void { - // try self.convert(context); + try self.convert(context); try callback(context, self.output); if (self.subcommand) |verb| try verb.finish(); } @@ -382,13 +381,15 @@ pub fn Parser(comptime command: anytype, comptime callback: anytype) type { } } - fn convert(self: *@This(), context: *UserContext) NoclipError!void { + fn convert_eager(self: *@This(), context: *UserContext) NoclipError!void { inline for (comptime parameters) |param| { if (comptime param.eager) { try self.convert_param(param, context); } } + } + fn convert(self: *@This(), context: *UserContext) NoclipError!void { inline for (comptime parameters) |param| { if (comptime !param.eager) { try self.convert_param(param, context);