]> www.git.momoyon.org Git - lang.git/commitdiff
[main.c] Store lines info in Lexer.
authormomoyon <ahmedsamyh10@gmail.com>
Thu, 17 Apr 2025 09:19:30 +0000 (14:19 +0500)
committermomoyon <ahmedsamyh10@gmail.com>
Thu, 17 Apr 2025 09:19:30 +0000 (14:19 +0500)
main.c

diff --git a/main.c b/main.c
index 129ca751816327ef3b567efa9bfa963da07256c6..eb39343689ec28845973c6e14bf9af7cccd4e46b 100644 (file)
--- 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]);