aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/lib.c
diff options
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/lib.c b/lib.c
index 0be4548a..a05d0474 100644
--- a/lib.c
+++ b/lib.c
@@ -70,10 +70,10 @@ struct token *skip_to(struct token *token, int op)
return token;
}
+static struct token bad_token;
struct token *expect(struct token *token, int op, const char *where)
{
if (!match_op(token, op)) {
- static struct token bad_token;
if (token != &bad_token) {
bad_token.next = token;
sparse_error(token->pos, "Expected %s %s", show_special(op), where);
@@ -86,6 +86,21 @@ struct token *expect(struct token *token, int op, const char *where)
return token->next;
}
+///
+// issue an error message on new parsing errors
+// @token: the current token
+// @errmsg: the error message
+// If the current token is from a previous error, an error message
+// has already been issued, so nothing more is done.
+// Otherwise, @errmsg is displayed followed by the current token.
+void unexpected(struct token *token, const char *errmsg)
+{
+ if (token == &bad_token)
+ return;
+ sparse_error(token->pos, "%s", errmsg);
+ sparse_error(token->pos, "got %s", show_token(token));
+}
+
unsigned int hexval(unsigned int c)
{
int retval = 256;