Started load directive.

This commit is contained in:
2025-09-03 22:31:18 +02:00
parent 4924b01eac
commit 11c936ba7f
5 changed files with 89 additions and 8 deletions

View File

@@ -1,5 +1,7 @@
#import "Flat_Pool";
// #load "qpwodkqopwkd.jai";
/**
* TODO:
* if parsing
@@ -322,6 +324,26 @@ empty_block :: (state : *Parse_State, token : Token, message : string) {
record_error(state, token, final_message, false);
}
unable_to_open_file :: (state : *Parse_State, path : string, token : Token) {
builder : String_Builder;
init_string_builder(*builder,, temp);
print_to_builder(*builder, "Unable to open file '%' for reading\n\n", path);
location := generate_source_location_from_token(state, token);
indent(*builder, 1);
cyan(*builder);
print_to_builder(*builder, "%\n", print_from_source_location(location));
indent(*builder, 1);
loc := location.begin;
print_token_pointer(*builder, loc);
final_message := builder_to_string(*builder);
record_error(state, token, final_message, false);
}
error_node :: (parse_state : *Parse_State, message : string) -> *AST_Node {
node := make_node(parse_state, .Error);
node.name = copy_string(message);
@@ -624,6 +646,32 @@ directive :: (state : *Parse_State) -> *AST_Node {
if_directive.source_location = source_location;
return if_directive;
} else if state.current.ident_value == "load" {
advance(state);
if check(state, .TOKEN_STRING) {
path := state.current.string_value;
advance(state);
consume(state, .TOKEN_SEMICOLON, "Expected ';' after #load directive");
result : Compile_Result;
result.allocator = state.result.allocator;
result.environment = state.result.environment;
result.file = make_file(*result, path);
if result.file.source.count == 0 {
unable_to_open_file(state, path, state.previous);
advance_to_sync_point(state);
return null;
}
lex(*result);
for tok : result.tokens.tokens {
array_add(*state.result.tokens.tokens, tok);
}
}
}
return null;