From 2d0b6b31caff9405ae551079ca67e9f1061f9afc Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Fri, 2 Nov 2018 19:09:57 -0400 Subject: parse: Use a better reference point for incomplete expression errors This makes `bfs -not type d` complain about nothing following the `-not` rather than the `d`. --- parse.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/parse.c b/parse.c index 4103e0b..7010f05 100644 --- a/parse.c +++ b/parse.c @@ -340,6 +340,8 @@ struct parser_state { /** Whether an information option like -help or -version was passed. */ bool just_info; + /** The last non-path argument. */ + const char *last_arg; /** A "-depth"-type argument if any. */ const char *depth_arg; /** A "-prune"-type argument if any. */ @@ -462,6 +464,10 @@ static char **parser_advance(struct parser_state *state, enum token_type type, s } } + if (type != T_PATH) { + state->last_arg = *state->argv; + } + char **argv = state->argv; state->argv += argc; return argv; @@ -2707,7 +2713,7 @@ static struct expr *parse_factor(struct parser_state *state) { const char *arg = state->argv[0]; if (!arg) { - cfprintf(cerr, "%{er}error: Expression terminated prematurely after '%s'.%{rs}\n", state->argv[-1]); + cfprintf(cerr, "%{er}error: Expression terminated prematurely after '%s'.%{rs}\n", state->last_arg); return NULL; } @@ -3090,6 +3096,7 @@ struct cmdline *parse_cmdline(int argc, char *argv[]) { .warn = stdin_tty, .non_option_seen = false, .just_info = false, + .last_arg = NULL, .depth_arg = NULL, .prune_arg = NULL, }; -- cgit v1.2.3