update: fixed expansion stuff
This commit is contained in:
parent
01c8e7cf2c
commit
3287b6a2a7
10 changed files with 133 additions and 16 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/02 19:04:32 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/10/03 22:43:27 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/10/05 13:06:17 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -21,6 +21,10 @@ void push_token_and_create_new(\
|
|||
t_vec_token *tokens, t_token *tok, enum e_token ttype, t_const_str s);
|
||||
void push_token_and_set_new(\
|
||||
t_vec_token *tokens, t_token *tok, enum e_token ttype, t_const_str s);
|
||||
void push_token_and_create_new_chr(\
|
||||
t_vec_token *tokens, t_token *tok, enum e_token ttype, char c);
|
||||
void push_token_and_set_new_chr(\
|
||||
t_vec_token *tokens, t_token *tok, enum e_token ttype, char c);
|
||||
|
||||
t_error _parse_dquote_inner(t_token dquote, t_vec_token *append)
|
||||
{
|
||||
|
|
@ -46,8 +50,10 @@ t_error _parse_dquote_inner(t_token dquote, t_vec_token *append)
|
|||
}
|
||||
string_push_char(&ctok.string, c);
|
||||
}
|
||||
else if (c == '$')
|
||||
push_token_and_create_new(&out.subtokens, &ctok, TOK_DOLLAR, "$");
|
||||
else if ('$')
|
||||
push_token_and_create_new(&out.subtokens, &ctok, TOK_DOLLAR, "$");
|
||||
else if (!(me_isalnum(c) || c == '_'))
|
||||
push_token_and_create_new_chr(&out.subtokens, &ctok, TOK_NALPHANUM, c);
|
||||
else
|
||||
{
|
||||
if (ctok.type == TOK_NONE)
|
||||
|
|
|
|||
|
|
@ -6,15 +6,25 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/02 19:04:32 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/10/03 22:50:40 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/10/05 13:19:33 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/str/str.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_token.h"
|
||||
#include "parser/passes.h"
|
||||
#include "parser/token.h"
|
||||
|
||||
bool _can_be_varname(t_token *tok)
|
||||
{
|
||||
if (tok->type == TOK_DOLLAR)
|
||||
return (true);
|
||||
if (tok->type != TOK_NALPHANUM)
|
||||
return (false);
|
||||
return (str_find_chr("!?#*-", tok->string.buf[0]) != NULL);
|
||||
}
|
||||
|
||||
/// This is a sample pass
|
||||
///
|
||||
/// There is a few rules the rest of the tokenizer machinery assumes
|
||||
|
|
@ -38,8 +48,8 @@ t_error ts_fold_expension(t_vec_token input, t_vec_token *output)
|
|||
if (i + 1 >= input.len)
|
||||
vec_token_push(&out, token_clone(&input.buffer[i]));
|
||||
else if (input.buffer[i].type == TOK_DOLLAR \
|
||||
&& (input.buffer[i + 1].type == TOK_DOLLAR \
|
||||
|| input.buffer[i + 1].type == TOK_NQUOTE))
|
||||
&& (input.buffer[i + 1].type == TOK_NQUOTE \
|
||||
|| _can_be_varname(&input.buffer[i+1])))
|
||||
{
|
||||
tmp = token_clone(&input.buffer[++i]);
|
||||
tmp.type= TOK_EXPENSION;
|
||||
|
|
|
|||
55
parser/src/passes/fold_no_quote.c
Normal file
55
parser/src/passes/fold_no_quote.c
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* fold_no_quote.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/02 19:04:32 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/10/05 13:19:50 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/string/string.h"
|
||||
#include "parser/passes.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_token.h"
|
||||
#include "parser/token.h"
|
||||
|
||||
/// This is a sample pass
|
||||
///
|
||||
/// There is a few rules the rest of the tokenizer machinery assumes
|
||||
/// theses function follows:
|
||||
/// - the input vec WILL be freed when the function return, even in
|
||||
/// case of error
|
||||
/// - the output vector isn't populated if the function returns an error,
|
||||
/// thus it shouldn't be freed in case of error
|
||||
/// - the output tokens may not be direct copy of the input tokens,
|
||||
/// but need to be cloned (different allocations for stuff)
|
||||
|
||||
t_error ts_fold_no_quote(t_vec_token input, t_vec_token *output)
|
||||
{
|
||||
t_vec_token out;
|
||||
t_usize i;
|
||||
t_usize j;
|
||||
t_token tmp;
|
||||
|
||||
i = 0;
|
||||
out = vec_token_new(input.len, token_free);
|
||||
while (i < input.len)
|
||||
{
|
||||
if (token_is_noquote(input.buffer[i].type))
|
||||
{
|
||||
j = 0;
|
||||
tmp = token_new(TOK_NQUOTE);
|
||||
while (i + j < input.len && token_is_noquote(input.buffer[i + j].type))
|
||||
string_push(&tmp.string, input.buffer[i + j++].string.buf);
|
||||
vec_token_push(&out, tmp);
|
||||
i += j;
|
||||
}
|
||||
else
|
||||
vec_token_push(&out, token_clone(&input.buffer[i++]));
|
||||
}
|
||||
vec_token_free(input);
|
||||
return (*output = out, NO_ERROR);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue