|
12 | 12 | #include <stdio.h>
|
13 | 13 | #include <stdlib.h>
|
14 | 14 | #include <string.h>
|
15 |
| -#include <builtins/error.h> |
| 15 | +#include "../../builtins/error.h" |
16 | 16 |
|
17 | 17 | #ifdef _ONE_TEST_
|
18 | 18 | #define debug_lexer(format, args...) \
|
@@ -617,3 +617,49 @@ void lexer_free()
|
617 | 617 | // free(lexer.start);
|
618 | 618 | // free(lexer.current);
|
619 | 619 | }
|
| 620 | + |
| 621 | +/* |
| 622 | + * @function: lexer_trace |
| 623 | + * @description: Log and trace items of tokens |
| 624 | + * @arguments: FILE* file_out, char* data, Token** tokens |
| 625 | + * @return: nothing, void |
| 626 | + */ |
| 627 | +void lexer_trace(FILE* file_out, const char* data, Token** tokens) |
| 628 | +{ |
| 629 | + debug_lexer("lexer_trace"); |
| 630 | + |
| 631 | + while (tokens != NULL && *tokens != NULL) |
| 632 | + if (tokens == NULL) return; |
| 633 | + |
| 634 | + while (*tokens != NULL) |
| 635 | + { |
| 636 | + Token* t = *tokens; |
| 637 | + printf("sizeof(t) = %zu\n", sizeof t); |
| 638 | + printf("-->1\n"); |
| 639 | + printf("-->%s\n", t == NULL ? "y" : "n"); |
| 640 | + // printf("sizeof(t) = %zu\n", sizeof t); |
| 641 | + // printf("-->1\n"); |
| 642 | + // printf("-->%s\n", t == NULL ? "y" : "n"); |
| 643 | + char* t_name = token_name(t->type); |
| 644 | + printf("-->2\n"); |
| 645 | + // printf("-->2\n"); |
| 646 | + bool has1 = file_convert_index_to_rc(data, t->pos.index, &t->pos.line, &t->pos.column); |
| 647 | + printf("-->3\n"); |
| 648 | + // printf("-->3\n"); |
| 649 | + bool has2 = file_convert_index_to_rc(data, t->pos_end.index, &t->pos_end.line, &t->pos_end.column); |
| 650 | + printf("-->4\n"); |
| 651 | + // printf("-->4\n"); |
| 652 | + |
| 653 | + fprintf(file_out, "[%zu:%zu] [%zu:%zu - %zu:%zu] %s", t->pos.tokens, t->length, t->pos.line, t->pos.column, t->pos_end.line, t->pos_end.column, t_name); |
| 654 | + printf("-->5\n"); |
| 655 | + // printf("-->5\n"); |
| 656 | + |
| 657 | + if (t->value != NULL) |
| 658 | + { |
| 659 | + fprintf(file_out, ": \"%s\"", t->value); |
| 660 | + } |
| 661 | + fprintf(file_out, "\n"); |
| 662 | + if (t->type == TOKEN_EOF) break; |
| 663 | + tokens++; |
| 664 | + } |
| 665 | +} |
0 commit comments