From c8b53cb4590d8d6cbfc5cbf891809ddd99e33fe5 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Sun, 3 Apr 2022 18:54:51 -0300 Subject: Add parsing for function definitions This commits also changes the structure of some existing functions. Namely, parse_* functions other than parse_next check that the type of the token to parse is correct. This allow us to use them directly in the rest of the code to consume tokens and properly produce an error if the token type is not the expected one. In the same fashion, two new functions consume_lparen and consume_rparen are implemented. They only report true/false and report errors if something went wrong. --- src/errors.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/errors.c') diff --git a/src/errors.c b/src/errors.c index e69e4f9..b93b462 100644 --- a/src/errors.c +++ b/src/errors.c @@ -8,6 +8,13 @@ static const char* error_msgs[] = { [ERR_MALFORMED_NUMBER] = "error: malformed number token", [ERR_MALFORMED_EXPR] = "error: malformed expression", [ERR_UNIMPLEMENTED] = "error: not implemented", + [ERR_NOT_A_NUMBER] = "error: expected a number", + [ERR_NOT_A_SYMBOL] = "error: expected a symbol", + [ERR_NOT_A_STRING] = "error: expected a string", + [ERR_NOT_A_TYPE] = "error: expected a type", + [ERR_NOT_A_BOOL] = "error: expected a bool", + [ERR_NOT_A_LPAREN] = "error: expected opening parentheses (lparen)", + [ERR_NOT_A_RPAREN] = "error: expected closing parentheses (rparen)", }; static Error current_error = {.value = ERR_OK}; -- cgit v1.2.1