aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/parse.c
diff options
context:
space:
mode:
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c38
1 files changed, 38 insertions, 0 deletions
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)
{