parse: add a basic function to report parse errors
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user