From: momoyon Date: Thu, 17 Apr 2025 09:19:30 +0000 (+0500) Subject: [main.c] Store lines info in Lexer. X-Git-Url: https://www.git.momoyon.org/?a=commitdiff_plain;h=eeb94355472b5f70d2ac81f034d1dd379db55e3d;p=lang.git [main.c] Store lines info in Lexer. --- diff --git a/main.c b/main.c index 129ca75..eb39343 100644 --- a/main.c +++ b/main.c @@ -202,12 +202,24 @@ typedef struct { /// NOTE: Lexer +typedef struct { + size_t offset; + size_t count; +} Line; + +typedef struct { + Line *items; + size_t count; + size_t capacity; +} Lines; + typedef struct { // NOTE: src gets data from a heap allocated string!!! String_view src; size_t cur; size_t bol; // Beginning of Line size_t line; + Lines lines; const char *filename; } Lexer; @@ -1101,6 +1113,11 @@ void consume_comment(Lexer *l, String_view *sv_out, Location *loc_out) { void left_trim(Lexer *l) { while (!eof(l) && isspace(current_char(l))) { if (current_char(l) == '\n' || (current_char(l) == '\r' && next_char(l) == '\n')) { + Line line = { + .offset = l->bol, + .count = col(l), + }; + da_append(l->lines, line); l->line += 1; l->bol = l->cur + 1; } @@ -1504,17 +1521,6 @@ int main(int argc, char **argv) { Tokens tokens = lex(&l); - log_info("Lexer.col: %d, ", col(&l)); - log_info("Lexer.bol: %d, ", l.bol); - log_info("Lexer.cur: %d, ", l.cur); - log_info("Lexer.line: %d, ", l.line); - - sv_print_range(l.src, stdout, 0, 2); - printf("\n"); - - return 0; - - if (dump_tokens) { for (size_t i = 0; i < tokens.count; ++i) { print_token(stdout, tokens.items[i]);