From 8e929d4e369f687552db8d127b2d39947eb93983 Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Wed, 1 Jul 2020 23:51:20 +0200 Subject: cleanup: move parsing helpers to parse.c lib.c contains 2-3 helpers for parsing. Move them to parse.c. Signed-off-by: Luc Van Oostenryck --- lib.c | 38 -------------------------------------- lib.h | 4 ---- parse.c | 38 ++++++++++++++++++++++++++++++++++++++ parse.h | 2 ++ 4 files changed, 40 insertions(+), 42 deletions(-) diff --git a/lib.c b/lib.c index fd1fe6cb..f512be2e 100644 --- a/lib.c +++ b/lib.c @@ -50,44 +50,6 @@ #include "bits.h" -struct token *skip_to(struct token *token, int op) -{ - while (!match_op(token, op) && !eof_token(token)) - token = token->next; - return token; -} - -static struct token bad_token = { .pos.type = TOKEN_BAD }; -struct token *expect(struct token *token, int op, const char *where) -{ - if (!match_op(token, op)) { - if (token != &bad_token) { - bad_token.next = token; - sparse_error(token->pos, "Expected %s %s", show_special(op), where); - sparse_error(token->pos, "got %s", show_token(token)); - } - if (op == ';') - return skip_to(token, op); - return &bad_token; - } - 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; diff --git a/lib.h b/lib.h index 81253a3e..b906d503 100644 --- a/lib.h +++ b/lib.h @@ -82,10 +82,6 @@ DECLARE_PTR_LIST(string_list, char); typedef struct pseudo *pseudo_t; -struct token *skip_to(struct token *, int); -struct token *expect(struct token *, int, const char *); -void unexpected(struct token *, const char *errmsg); - #ifdef __GNUC__ #define FORMAT_ATTR(pos) __attribute__ ((__format__ (__printf__, pos, pos+1))) #define NORETURN_ATTR __attribute__ ((__noreturn__)) diff --git a/parse.c b/parse.c index 70d8b237..a9222e7c 100644 --- a/parse.c +++ b/parse.c @@ -655,6 +655,44 @@ void init_parser(int stream) } +static struct token *skip_to(struct token *token, int op) +{ + while (!match_op(token, op) && !eof_token(token)) + token = token->next; + return token; +} + +static struct token bad_token = { .pos.type = TOKEN_BAD }; +struct token *expect(struct token *token, int op, const char *where) +{ + if (!match_op(token, op)) { + if (token != &bad_token) { + bad_token.next = token; + sparse_error(token->pos, "Expected %s %s", show_special(op), where); + sparse_error(token->pos, "got %s", show_token(token)); + } + if (op == ';') + return skip_to(token, op); + return &bad_token; + } + 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. +static 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)); +} + // Add a symbol to the list of function-local symbols static void fn_local_symbol(struct symbol *sym) { diff --git a/parse.h b/parse.h index 5ac9a23b..e7ea3642 100644 --- a/parse.h +++ b/parse.h @@ -140,4 +140,6 @@ extern int inline_function(struct expression *expr, struct symbol *sym); extern void uninline(struct symbol *sym); extern void init_parser(int); +struct token *expect(struct token *, int, const char *); + #endif /* PARSE_H */ -- cgit 1.2.3-korg