mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Only allow .odin files to be parsed
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import "test"
|
||||||
|
|
||||||
add :: proc(a, b: int) -> int {
|
add :: proc(a, b: int) -> int {
|
||||||
return a + b;
|
return a + b;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,35 @@ gb_inline b32 are_strings_equal(String a, String b) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
gb_inline isize string_has_any_extension(String str) {
|
||||||
|
isize dot_pos = -1;
|
||||||
|
isize i = str.len;
|
||||||
|
b32 seen_dot = false;
|
||||||
|
while (i --> 0) {
|
||||||
|
if (str.text[i] == GB_PATH_SEPARATOR)
|
||||||
|
break;
|
||||||
|
if (str.text[i] == '.') {
|
||||||
|
dot_pos = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dot_pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
gb_inline b32 string_has_extension(String str, String ext) {
|
||||||
|
if (str.len > ext.len+1) {
|
||||||
|
u8 *s = str.text+str.len - ext.len-1;
|
||||||
|
if (s[0] == '.') {
|
||||||
|
s++;
|
||||||
|
return gb_memcompare(s, ext.text, ext.len) == 0;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Hasing
|
// Hasing
|
||||||
|
|
||||||
gb_inline u64 hashing_proc(void const *data, isize len) {
|
gb_inline u64 hashing_proc(void const *data, isize len) {
|
||||||
|
|||||||
+5
-3
@@ -1670,10 +1670,12 @@ AstNode *parse_statement_list(AstFile *f, isize *list_count_) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// void parse_file(AstFile *f, )
|
|
||||||
|
|
||||||
|
|
||||||
b32 init_ast_file(AstFile *f, String fullpath) {
|
b32 init_ast_file(AstFile *f, String fullpath) {
|
||||||
|
if (!string_has_extension(fullpath, make_string("odin"))) {
|
||||||
|
gb_printf_err("Only `.odin` files are allowed\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (init_tokenizer(&f->tokenizer, fullpath)) {
|
if (init_tokenizer(&f->tokenizer, fullpath)) {
|
||||||
gb_array_init(f->tokens, gb_heap_allocator());
|
gb_array_init(f->tokens, gb_heap_allocator());
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@@ -1804,7 +1806,7 @@ void parse_files(Parser *p, char *init_filename) {
|
|||||||
AstFile file = {};
|
AstFile file = {};
|
||||||
b32 ok = init_ast_file(&file, import_path);
|
b32 ok = init_ast_file(&file, import_path);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
gb_printf_err("Failed to parse file: %.*s", LIT(import_path));
|
gb_printf_err("Failed to parse file: %.*s\n", LIT(import_path));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
parse_file(p, &file);
|
parse_file(p, &file);
|
||||||
|
|||||||
Reference in New Issue
Block a user