Ifdefs, moved semantic to check, fixed error reporting for builtins
This commit is contained in:
31
Lexing.jai
31
Lexing.jai
@@ -11,6 +11,7 @@ Lexer :: struct {
|
||||
}
|
||||
|
||||
Token_Kind :: enum {
|
||||
TOKEN_INVALID :: 0;
|
||||
TOKEN_FLOATLITERAL;
|
||||
TOKEN_INTLITERAL;
|
||||
|
||||
@@ -129,7 +130,7 @@ Token :: struct {
|
||||
// This could all be derived on demand
|
||||
line : int;
|
||||
length : int;
|
||||
column : int;
|
||||
column : int;
|
||||
index : int;
|
||||
|
||||
error : string;
|
||||
@@ -386,7 +387,12 @@ make_directive :: (lexer : *Lexer) -> *Token {
|
||||
for tok : ctx.tokens {
|
||||
lexer.ctx.tokens[it_index] = tok;
|
||||
}
|
||||
return scan_next_token(lexer);;
|
||||
return scan_next_token(lexer);
|
||||
} else if ident.ident_value == "add_define" {
|
||||
new_define := scan_next_token(lexer);
|
||||
add_define(*lexer.ctx.environment, new_define.ident_value);
|
||||
lexer.ctx.tokens.count -= 2;
|
||||
return scan_next_token(lexer);
|
||||
}
|
||||
return ident;
|
||||
}
|
||||
@@ -739,10 +745,25 @@ print_token_pointer :: (builder : *String_Builder, token : Token) {
|
||||
}
|
||||
}
|
||||
|
||||
print_from_source_location :: (builder : *String_Builder, source_location : Source_Range, indentation : int = 0) {
|
||||
print_from_source_location :: (ctx : *Compiler_Context, builder : *String_Builder, source_location : Source_Range, indentation : int = 0) {
|
||||
current := source_location.begin;
|
||||
begin := source_location.begin;
|
||||
end := source_location.end;
|
||||
|
||||
if begin.builtin {
|
||||
for i : begin.index..end.index - 1 {
|
||||
tok := ctx.tokens[i];
|
||||
text : string;
|
||||
text.data = tok.source;
|
||||
text.count = tok.length;
|
||||
print_to_builder(builder, "%", text);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
|
||||
begin_pos := 0;
|
||||
token_string : string;
|
||||
count := end.index - begin.index + end.length;
|
||||
@@ -769,12 +790,12 @@ print_from_source_location :: (builder : *String_Builder, source_location : Sour
|
||||
}
|
||||
}
|
||||
|
||||
print_from_source_location :: (source_location : Source_Range, allocator := context.allocator, indentation : int = 0) -> string {
|
||||
print_from_source_location :: (ctx : *Compiler_Context, source_location : Source_Range, allocator := context.allocator, indentation : int = 0) -> string {
|
||||
sc := get_scratch();
|
||||
defer scratch_end(sc);
|
||||
builder : String_Builder;
|
||||
init_string_builder(*builder,, sc.allocator);
|
||||
print_from_source_location(*builder, source_location,, sc.allocator);
|
||||
print_from_source_location(ctx, *builder, source_location,, sc.allocator);
|
||||
return builder_to_string(*builder,, allocator);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user