diff options
Diffstat (limited to 'lib.c')
| -rw-r--r-- | lib.c | 17 |
1 files changed, 16 insertions, 1 deletions
@@ -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; |
