gdb: merge error handling from different expression parsers

Many (all?) of the expression parsers implement yyerror to handle
parser errors, and all of these functions are basically identical.

This commit adds a new parser_state::parse_error() function, which
implements the common error handling code, this function can then be
called from all the different yyerror functions.

The benefit of this is that (in a future commit) I can improve the
error output, and all the expression parsers will benefit.

This commit is pure refactoring though, and so, there should be no
user visible changes after this commit.

Approved-By: John Baldwin <jhb@FreeBSD.org>
This commit is contained in:
Andrew Burgess
2024-01-02 14:02:44 +00:00
parent c9f1e0dfc8
commit e89496f42a
9 changed files with 23 additions and 25 deletions

View File

@@ -244,6 +244,17 @@ parser_state::push_dollar (struct stoken str)
(create_internalvar (copy.c_str () + 1));
}
/* See parser-defs.h. */
void
parser_state::parse_error (const char *msg)
{
if (this->prev_lexptr)
this->lexptr = this->prev_lexptr;
error (_("A %s in expression, near `%s'."), msg, this->lexptr);
}
const char *