The position that the invalid token was found at is printed

This commit is contained in:
Mikkel Hjortshoej
2017-09-25 21:42:23 +02:00
parent 572ac616c1
commit 67ac551a2f
+6 -3
View File
@@ -4663,7 +4663,7 @@ Array<AstNode *> parse_stmt_list(AstFile *f) {
} }
ParseFileError init_ast_file(AstFile *f, String fullpath) { ParseFileError init_ast_file(AstFile *f, String fullpath, TokenPos *err_pos) {
f->fullpath = string_trim_whitespace(fullpath); // Just in case f->fullpath = string_trim_whitespace(fullpath); // Just in case
if (!string_has_extension(f->fullpath, str_lit("odin"))) { if (!string_has_extension(f->fullpath, str_lit("odin"))) {
return ParseFile_WrongExtension; return ParseFile_WrongExtension;
@@ -4689,6 +4689,8 @@ ParseFileError init_ast_file(AstFile *f, String fullpath) {
for (;;) { for (;;) {
Token token = tokenizer_get_token(&f->tokenizer); Token token = tokenizer_get_token(&f->tokenizer);
if (token.kind == Token_Invalid) { if (token.kind == Token_Invalid) {
err_pos->line = token.pos.line;
err_pos->column = token.pos.column;
return ParseFile_InvalidToken; return ParseFile_InvalidToken;
} }
array_add(&f->tokens, token); array_add(&f->tokens, token);
@@ -4967,7 +4969,8 @@ ParseFileError parse_import(Parser *p, ImportedFile imported_file) {
file->is_global_scope = true; file->is_global_scope = true;
} }
ParseFileError err = init_ast_file(file, import_path); TokenPos err_pos = {0};
ParseFileError err = init_ast_file(file, import_path, &err_pos);
if (err != ParseFile_None) { if (err != ParseFile_None) {
if (err == ParseFile_EmptyFile) { if (err == ParseFile_EmptyFile) {
@@ -4996,7 +4999,7 @@ ParseFileError parse_import(Parser *p, ImportedFile imported_file) {
gb_printf_err("File cannot be found (`%.*s`)", LIT(import_path)); gb_printf_err("File cannot be found (`%.*s`)", LIT(import_path));
break; break;
case ParseFile_InvalidToken: case ParseFile_InvalidToken:
gb_printf_err("Invalid token found in file"); gb_printf_err("Invalid token found in file at (%td:%td)", err_pos.line, err_pos.column);
break; break;
} }
gb_printf_err("\n"); gb_printf_err("\n");