summaryrefslogtreecommitdiff
path: root/src/parser.h
diff options
context:
space:
mode:
authorCarlos Maniero <carlosmaniero@gmail.com>2023-04-20 13:32:36 -0300
committerJohnny Richard <johnny@johnnyrichard.com>2023-04-20 18:31:55 +0200
commit3ceb85bd93fa87a5be3682ab8995abea82a63ea3 (patch)
tree9512c4255bd87967dfd42a8ca68abd18e34e7407 /src/parser.h
parenta47e5ceb6eefdac9c5f5473e1fee0d33a5f4646e (diff)
parser: Stop exiting on parser error
Previously, when an error occurred during parsing, the application would exit, making it difficult to test the parser and limiting the compiler's extensibility. This commit improves the parser's error handling by allowing for continued execution after an error, enabling easier testing and increased flexibility. The parser is prepared to handle multiples errors, although the current implementation always returns a single error, it may be useful given multiples functions where we can show errors by context. Signed-off-by: Carlos Maniero <carlosmaniero@gmail.com> Reviwed-by: Johnny Richard <johnny@johnnyrichard.com>
Diffstat (limited to 'src/parser.h')
-rw-r--r--src/parser.h9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/parser.h b/src/parser.h
index 988006e..5f73ff3 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -21,13 +21,20 @@
#include "lexer.h"
#include "string_view.h"
+typedef struct parser_error_t {
+ token_t token;
+ char message [256];
+} parser_error_t;
+
typedef struct parser_t {
lexer_t *lexer;
+ int errors_len;
+ parser_error_t errors[1];
} parser_t;
void parser_init(parser_t *parser, lexer_t *lexer);
-void parser_parse_function_declaration(parser_t *parser, ast_node_t *node);
+bool parser_parse_function_declaration(parser_t *parser, ast_node_t *node);
#endif /* PARSER_H */