frontend: compile: use new opaque lexer interface
This commit is contained in:
@@ -22,25 +22,27 @@ static int compile_file(const char *path)
|
||||
}
|
||||
|
||||
struct ivy_file *src = ivy_file_from_fp(fp);
|
||||
struct ivy_lexer lex;
|
||||
if (ivy_lexer_init(&lex) != IVY_OK) {
|
||||
struct ivy_lexer *lex;
|
||||
if (ivy_lexer_create(&lex) != IVY_OK) {
|
||||
b_err("failed to initialise Ivy lexer");
|
||||
ivy_file_close(src);
|
||||
return -1;
|
||||
}
|
||||
|
||||
lex.lex_source = &src->f_base;
|
||||
ivy_lexer_set_source(lex, &src->f_base);
|
||||
enum ivy_status status = IVY_OK;
|
||||
|
||||
while (true) {
|
||||
struct ivy_token *tok = ivy_lexer_read(&lex);
|
||||
if (lex.lex_status == IVY_ERR_EOF) {
|
||||
struct ivy_token *tok = ivy_lexer_read(lex);
|
||||
status = ivy_lexer_get_status(lex);
|
||||
if (status == IVY_ERR_EOF) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (lex.lex_status != IVY_OK) {
|
||||
if (status != IVY_OK) {
|
||||
b_err("failed to parse '%s'", path);
|
||||
b_i("reason: lex error (%s)",
|
||||
ivy_status_to_string(lex.lex_status));
|
||||
ivy_status_to_string(ivy_lexer_get_status(lex)));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -100,10 +102,9 @@ static int compile_file(const char *path)
|
||||
b_fputs("[reset]\n", stdout);
|
||||
}
|
||||
|
||||
int r = (lex.lex_status == IVY_OK || lex.lex_status == IVY_ERR_EOF) ? 0
|
||||
: -1;
|
||||
int r = (status == IVY_OK || status == IVY_ERR_EOF) ? 0 : -1;
|
||||
ivy_file_close(src);
|
||||
ivy_lexer_finish(&lex);
|
||||
ivy_lexer_destroy(lex);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user