update: made some small fixes
This commit is contained in:
parent
11898cba9b
commit
4f1a08cbe6
8 changed files with 47 additions and 17 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/02 18:41:16 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/10/02 19:22:37 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/10/03 21:32:14 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -46,7 +46,7 @@ static const struct s_ts_pass_def g_ts_passes[] = {
|
|||
{do_fuck_all, "does nothing lol"},
|
||||
};
|
||||
|
||||
t_error apply_all_passes(t_vec_token ts, t_vec_token *out)
|
||||
t_error ts_apply_passes(t_vec_token ts, t_vec_token *out)
|
||||
{
|
||||
t_usize i;
|
||||
t_vec_token next;
|
||||
|
|
@ -58,6 +58,8 @@ t_error apply_all_passes(t_vec_token ts, t_vec_token *out)
|
|||
return (vec_token_free(ts), ERROR);
|
||||
if ((g_ts_passes[i].fn)(ts, &next))
|
||||
return (me_eprintf("failed on %s token pass\n", g_ts_passes[i].name), ERROR);
|
||||
else
|
||||
me_printf("Applied '%s' pass\n", g_ts_passes[i].name);
|
||||
ts = next;
|
||||
i++;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/02 19:04:32 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/10/02 19:13:31 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/10/03 21:37:04 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,11 +15,22 @@
|
|||
#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 do_fuck_all(t_vec_token input, t_vec_token *output)
|
||||
{
|
||||
t_vec_token out;
|
||||
t_usize i;
|
||||
|
||||
i = 0;
|
||||
out = vec_token_new(input.len, token_free);
|
||||
while (i < input.len)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/30 19:39:39 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/10/02 18:02:59 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/10/03 21:31:57 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -28,8 +28,16 @@ static void push_token_and_create_new(\
|
|||
string_push(&tmp.string, s);
|
||||
vec_token_push(tokens, tmp);
|
||||
}
|
||||
static void push_token_and_set_new(\
|
||||
t_vec_token *tokens, t_token *tok, enum e_token ttype, t_const_str s)
|
||||
{
|
||||
if (tok->type != TOK_NONE)
|
||||
vec_token_push(tokens, *tok);
|
||||
*tok = token_new(ttype);
|
||||
string_push(&tok->string, s);
|
||||
}
|
||||
|
||||
void handle_quote(t_vec_token *ret, char chr, t_token *tok, char *quote)
|
||||
static void handle_quote(t_vec_token *ret, char chr, t_token *tok, char *quote)
|
||||
{
|
||||
if (chr == *quote)
|
||||
{
|
||||
|
|
@ -42,7 +50,7 @@ void handle_quote(t_vec_token *ret, char chr, t_token *tok, char *quote)
|
|||
string_push_char(&tok->string, chr);
|
||||
}
|
||||
|
||||
void handle_noquote(t_vec_token *ret, char chr, t_token *tok, char *quote)
|
||||
static void handle_noquote(t_vec_token *ret, char chr, t_token *tok, char *quote)
|
||||
{
|
||||
*quote = '\0';
|
||||
if (chr == '$')
|
||||
|
|
@ -71,15 +79,15 @@ void handle_noquote(t_vec_token *ret, char chr, t_token *tok, char *quote)
|
|||
}
|
||||
}
|
||||
|
||||
void tokenize_inner(t_vec_token *ret, char chr, t_token *tok, char *quote)
|
||||
static void tokenize_inner(t_vec_token *ret, char chr, t_token *tok, char *quote)
|
||||
{
|
||||
if (*quote == '\0')
|
||||
{
|
||||
*quote = chr;
|
||||
if (chr == '\"')
|
||||
push_token_and_create_new(ret, tok, TOK_DQUOTE, "");
|
||||
push_token_and_set_new(ret, tok, TOK_DQUOTE, "");
|
||||
else if (chr == '\'')
|
||||
push_token_and_create_new(ret, tok, TOK_SQUOTE, "");
|
||||
push_token_and_set_new(ret, tok, TOK_SQUOTE, "");
|
||||
else
|
||||
handle_noquote(ret, chr, tok, quote);
|
||||
}
|
||||
|
|
@ -89,6 +97,10 @@ void tokenize_inner(t_vec_token *ret, char chr, t_token *tok, char *quote)
|
|||
me_abort("invalid quote type");
|
||||
}
|
||||
|
||||
// This should even be wrapped with the passes function so the consumer only
|
||||
// see the last version of the tokenstream
|
||||
//
|
||||
// currently it is "Public" API though
|
||||
t_error tokenize(t_const_str s, t_vec_token *out)
|
||||
{
|
||||
t_usize i;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue