feat(lexer): comment handling + healthy changes

This commit is contained in:
Matteo Flebus 2026-01-21 18:43:17 +01:00
parent 03e5305b56
commit 306b13308b
4 changed files with 28 additions and 14 deletions

View file

@ -7,9 +7,9 @@
#include <stdlib.h>
#include <string.h>
#include "lexer_utils.h"
#include "../io_backend/io_backend.h"
#include "../utils/string_utils/string_utils.h"
#include "lexer_utils.h"
/* @return: true if a special character from the grammar was found,
* false otherwise.
@ -90,7 +90,6 @@ static bool update_lexing_mode(char *stream, ssize_t i,
return *lexing_mode != mode_before_update;
}
struct token *peek_token(struct lexer_context *ctx)
{
// we already created the upcoming token during the previous call to peek()
@ -99,7 +98,8 @@ struct token *peek_token(struct lexer_context *ctx)
return ctx->current_token;
}
char *stream = stream_init(ctx);
stream_init(ctx);
char *stream = ctx->end_previous_token;
ssize_t i = 0;
// Usefull to know if we are inside a quote or double quote
@ -138,7 +138,10 @@ struct token *peek_token(struct lexer_context *ctx)
if (tok->type == TOKEN_COMMENT)
{
// tok = peek_token();
// drop current stream
get_next_stream(ctx);
free_token(&tok);
tok = peek_token(ctx);
}
update_current_token(tok, ctx);
return tok;
@ -153,7 +156,8 @@ struct token *pop_token(struct lexer_context *ctx)
free_token(&ctx->current_token);
return NULL;
}
char *stream = stream_init(ctx);
stream_init(ctx);
char *stream = ctx->end_previous_token;
ssize_t i = 0;
// Usefull to know if we are inside a quote or double quote