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