Compare commits

...

4 Commits

Author SHA1 Message Date
63dd69b01c update: removed const modifier on token value
following steps on the parsing process can change its content
2026-02-10 09:24:18 +01:00
609a644fa9 update: token is now stored as value of the token instead of null
this change is made so that it is easier to print an error message when
invalid syntax
2026-02-10 09:20:46 +01:00
3d97d6506a fix: removed putendl on malloc 2026-02-10 08:54:11 +01:00
1f0f38e42f fix: removed putendl on free 2026-02-10 08:52:24 +01:00

View File

@@ -6,7 +6,7 @@
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/02/09 18:56:41 by sede-san #+# #+# */
/* Updated: 2026/02/10 08:40:13 by sede-san ### ########.fr */
/* Updated: 2026/02/10 09:11:23 by sede-san ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,7 +15,7 @@
static t_token *tokenize(const char *line, size_t *start);
static t_token_type get_token_type(const char *str);
static t_token *token_new(t_token_type type, const char *text);
static t_token *token_new(t_token_type type, char *text);
static void token_clear(t_token *token);
static t_token *read_token(t_token_type type, const char *line, size_t *i);
static t_token *read_word(const char *line, size_t *i);
@@ -97,14 +97,13 @@ static t_token_type get_token_type(
static t_token *token_new(
t_token_type type,
const char *text)
char *text)
{
t_token *token;
token = (t_token *)malloc(sizeof(t_token));
if (token == NULL)
return (NULL);
ft_putendl("malloc");
token->type = type;
token->value = text;
if (token->type == TOKEN_WORD && token->value == NULL)
@@ -120,13 +119,8 @@ static void token_clear(
{
if (token != NULL)
{
if (token->value != NULL)
{
free(token->value);
ft_putendl("free");
}
free(token->value);
free(token);
ft_putendl("free");
}
}
@@ -135,9 +129,15 @@ static t_token *read_token(
const char *line,
size_t *i)
{
while (ft_isspace(line[*i]) || is_meta(line[*i]))
const size_t start = *i;
size_t end;
while (is_meta(line[*i]))
(*i)++;
return (token_new(type, NULL));
end = *i;
while (ft_isspace(line[*i]))
(*i)++;
return (token_new(type, ft_substr(line, start, end - start)));
}
static t_token *read_word(