fix: new lexer is linked to everything
This commit is contained in:
parent
d5a1ec3ca6
commit
71e58e38b8
6 changed files with 26 additions and 22 deletions
|
|
@ -41,8 +41,8 @@ static void save_state(char *stream, ssize_t i, struct lexer_context *ctx)
|
|||
ctx->remaining_chars -= i;
|
||||
ctx->end_previous_token = stream + i;
|
||||
|
||||
update_previous_token(ctx->current_token);
|
||||
update_current_token(NULL);
|
||||
update_previous_token(ctx->current_token, ctx);
|
||||
update_current_token(NULL, ctx);
|
||||
}
|
||||
|
||||
/* @return: true if a special character from the grammar was found,
|
||||
|
|
@ -182,12 +182,10 @@ void destroy_lexer_context(struct lexer_context **ctx)
|
|||
{
|
||||
if (ctx == NULL || *ctx == NULL)
|
||||
return;
|
||||
if (ctx->end_previous_token != NULL)
|
||||
free(ctx->end_previous_token);
|
||||
if (ctx->previous_token != NULL)
|
||||
free(ctx->previous_token);
|
||||
if (ctx->current_token != NULL)
|
||||
free(ctx->current_token);
|
||||
if ((*ctx)->previous_token != NULL)
|
||||
free((*ctx)->previous_token);
|
||||
if ((*ctx)->current_token != NULL)
|
||||
free((*ctx)->current_token);
|
||||
free(*ctx);
|
||||
*ctx = NULL;
|
||||
}
|
||||
|
|
@ -278,7 +276,7 @@ struct token *peek_token(struct lexer_context *ctx)
|
|||
return ctx->current_token;
|
||||
}
|
||||
|
||||
char *stream = stream_init();
|
||||
char *stream = stream_init(ctx);
|
||||
ssize_t i = 0;
|
||||
|
||||
// Usefull to know if we are inside a quote or double quote
|
||||
|
|
@ -313,7 +311,7 @@ struct token *peek_token(struct lexer_context *ctx)
|
|||
}
|
||||
|
||||
struct token *tok = new_token(stream, i);
|
||||
update_current_token(tok);
|
||||
update_current_token(tok, ctx);
|
||||
return tok;
|
||||
}
|
||||
|
||||
|
|
@ -326,7 +324,7 @@ struct token *pop_token(struct lexer_context *ctx)
|
|||
free_token(&ctx->current_token);
|
||||
return NULL;
|
||||
}
|
||||
char *stream = stream_init();
|
||||
char *stream = stream_init(ctx);
|
||||
ssize_t i = 0;
|
||||
|
||||
// Usefull to know if we are inside a quote or double quote
|
||||
|
|
@ -366,7 +364,7 @@ struct token *pop_token(struct lexer_context *ctx)
|
|||
{
|
||||
ctx->current_token = new_token(stream, i);
|
||||
}
|
||||
save_state(stream, i);
|
||||
save_state(stream, i, ctx);
|
||||
|
||||
return ctx->previous_token;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue