parse: add a basic function to report parse errors

This commit is contained in:
2026-05-12 22:56:32 +01:00
parent 5ce780e037
commit 0cd7ca2dde
+25
View File
@@ -1,6 +1,7 @@
#include "parse.h"
#include "../ast/ast.h"
#include "../debug.h"
#include "lex.h"
#include "syntax.h"
#include "token.h"
@@ -23,8 +24,32 @@ void parse_ctx_cleanup(struct parse_ctx *ctx)
struct ast_node *parse_ctx_read_node(struct parse_ctx *ctx)
{
parse_symbol(ctx, SYM_SEMICOLON);
parse_linefeed(ctx);
struct ast_node *result = NULL;
bool ok = parse_statement(ctx, &result);
return ok ? result : NULL;
}
void report_error(struct parse_ctx *ctx, const char *format, ...)
{
ctx->p_status = BSHELL_ERR_BAD_SYNTAX;
fprintf(stderr, "PARSE: ");
va_list arg;
va_start(arg, format);
vfprintf(stderr, format, arg);
va_end(arg);
fprintf(stderr, "\n");
struct lex_token *tok = peek_token(ctx);
fprintf(stderr, " peek_token = ");
if (tok) {
print_lex_token(tok);
} else {
fprintf(stderr, " EOF\n");
}
}