update: normed lots of stuff

This commit is contained in:
maix0 2024-09-19 17:35:57 +02:00
parent 978636b6ef
commit 50a2f3d4be
118 changed files with 1145 additions and 1330 deletions

View file

@ -6,37 +6,37 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/31 18:06:07 by maiboyer #+# #+# */
/* Updated: 2024/08/31 18:23:07 by maiboyer ### ########.fr */
/* Updated: 2024/09/19 16:58:25 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/types.h"
#include "parser/lexer.h"
bool ts_lexer__eof(const TSLexer *_self);
t_u32 ts_lexer__get_column(TSLexer *_self);
void ts_lexer__advance(TSLexer *_self, bool skip);
bool ts_lexer__eof(const t_lexer *_self);
t_u32 ts_lexer__get_column(t_lexer *_self);
void ts_lexer__advance(t_lexer *_self, bool skip);
void ts_lexer__clear_chunk(t_lexer *self);
void ts_lexer__get_chunk(t_lexer *self);
void ts_lexer__get_lookahead(t_lexer *self);
void ts_lexer__mark_end(TSLexer *_self);
void ts_lexer__mark_end(t_lexer *_self);
void ts_lexer_advance_to_end(t_lexer *self);
void ts_lexer_goto(t_lexer *self, Length position);
void ts_lexer_goto(t_lexer *self, t_length position);
bool ts_lexer__do_advance_loop(t_lexer *self, const TSRange **current_range);
bool ts_lexer__do_advance_loop(t_lexer *self, const t_range **current_range);
void ts_lexer__do_advance_after_loop(t_lexer *self, bool skip,
const TSRange *cur);
const t_range *cur);
// Intended to be called only from functions that control logging.
void ts_lexer__do_advance(t_lexer *self, bool skip)
{
const TSRange *cur = \
const t_range *cur = \
&self->included_ranges[self->current_included_range_index];
if (self->lookahead_size)
{
self->current_position.bytes += self->lookahead_size;
if (self->data.lookahead == '\n')
if (self->funcs.lookahead == '\n')
{
self->current_position.extent.row++;
self->current_position.extent.column = 0;
@ -53,7 +53,7 @@ void ts_lexer__do_advance(t_lexer *self, bool skip)
// Advance to the next character in the source code, retrieving a new
// chunk of source code if needed.
void ts_lexer__advance(TSLexer *_self, bool skip)
void ts_lexer__advance(t_lexer *_self, bool skip)
{
t_lexer *self;
@ -63,14 +63,14 @@ void ts_lexer__advance(TSLexer *_self, bool skip)
ts_lexer__do_advance(self, skip);
}
bool ts_lexer__do_advance_loop(t_lexer *self, const TSRange **current_range)
bool ts_lexer__do_advance_loop(t_lexer *self, const t_range **current_range)
{
if (self->current_included_range_index < self->included_range_count)
self->current_included_range_index++;
if (self->current_included_range_index < self->included_range_count)
{
(*current_range)++;
self->current_position = (Length){
self->current_position = (t_length){
(*current_range)->start_byte,
(*current_range)->start_point,
};
@ -84,7 +84,7 @@ bool ts_lexer__do_advance_loop(t_lexer *self, const TSRange **current_range)
}
void ts_lexer__do_advance_after_loop(t_lexer *self, bool skip,
const TSRange *cur)
const t_range *cur)
{
if (skip)
self->token_start_position = self->current_position;
@ -99,7 +99,7 @@ void ts_lexer__do_advance_after_loop(t_lexer *self, bool skip,
else
{
ts_lexer__clear_chunk(self);
self->data.lookahead = '\0';
self->funcs.lookahead = '\0';
self->lookahead_size = 1;
}
}

View file

@ -13,16 +13,16 @@
#include "me/types.h"
#include "parser/lexer.h"
bool ts_lexer__eof(const TSLexer *_self);
t_u32 ts_lexer__get_column(TSLexer *_self);
void ts_lexer__advance(TSLexer *_self, bool skip);
bool ts_lexer__eof(const t_lexer *_self);
t_u32 ts_lexer__get_column(t_lexer *_self);
void ts_lexer__advance(t_lexer *_self, bool skip);
void ts_lexer__do_advance(t_lexer *self, bool skip);
void ts_lexer__clear_chunk(t_lexer *self);
void ts_lexer__get_chunk(t_lexer *self);
void ts_lexer__get_lookahead(t_lexer *self);
void ts_lexer__mark_end(TSLexer *_self);
void ts_lexer__mark_end(t_lexer *_self);
void ts_lexer_advance_to_end(t_lexer *self);
void ts_lexer_goto(t_lexer *self, Length position);
void ts_lexer_goto(t_lexer *self, t_length position);
// Clear the currently stored chunk of source code, because the lexer's
// position has changed.

View file

@ -6,28 +6,28 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/31 18:07:07 by maiboyer #+# #+# */
/* Updated: 2024/08/31 18:12:10 by maiboyer ### ########.fr */
/* Updated: 2024/09/19 16:58:53 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/types.h"
#include "parser/lexer.h"
bool ts_lexer__eof(const TSLexer *_self);
t_u32 ts_lexer__get_column(TSLexer *_self);
void ts_lexer__advance(TSLexer *_self, bool skip);
bool ts_lexer__eof(const t_lexer *_self);
t_u32 ts_lexer__get_column(t_lexer *_self);
void ts_lexer__advance(t_lexer *_self, bool skip);
void ts_lexer__do_advance(t_lexer *self, bool skip);
void ts_lexer__clear_chunk(t_lexer *self);
void ts_lexer__get_chunk(t_lexer *self);
void ts_lexer__get_lookahead(t_lexer *self);
void ts_lexer__mark_end(TSLexer *_self);
void ts_lexer__mark_end(t_lexer *_self);
void ts_lexer_advance_to_end(t_lexer *self);
void ts_lexer_goto(t_lexer *self, Length position);
void ts_lexer_goto(t_lexer *self, t_length position);
// Check if the lexer has reached EOF. This state is stored
// by setting the lexer's `current_included_range_index` such that
// it has consumed all of its available ranges.
bool ts_lexer__eof(const TSLexer *_self)
bool ts_lexer__eof(const t_lexer *_self)
{
t_lexer *self;
@ -37,14 +37,14 @@ bool ts_lexer__eof(const TSLexer *_self)
// Mark that a token match has completed. This can be called multiple
// times if a longer match is found later.
void ts_lexer__mark_end(TSLexer *_self)
void ts_lexer__mark_end(t_lexer *_self)
{
t_lexer *self;
TSRange *current_included_range;
TSRange *previous_included_range;
t_range *current_included_range;
t_range *previous_included_range;
self = (t_lexer *)_self;
if (!ts_lexer__eof(&self->data))
if (!ts_lexer__eof(self))
{
current_included_range = \
&self->included_ranges[self->current_included_range_index];
@ -52,7 +52,7 @@ void ts_lexer__mark_end(TSLexer *_self)
&& self->current_position.bytes == current_included_range->start_byte)
{
previous_included_range = current_included_range - 1;
self->token_end_position = (Length){
self->token_end_position = (t_length){
previous_included_range->end_byte,
previous_included_range->end_point,
};
@ -65,5 +65,5 @@ void ts_lexer__mark_end(TSLexer *_self)
void ts_lexer_advance_to_end(t_lexer *self)
{
while (self->chunk)
ts_lexer__advance(&self->data, false);
ts_lexer__advance(self, false);
}

View file

@ -13,18 +13,18 @@
#include "me/types.h"
#include "parser/lexer.h"
bool ts_lexer__eof(const TSLexer *_self);
t_u32 ts_lexer__get_column(TSLexer *_self);
void ts_lexer__advance(TSLexer *_self, bool skip);
bool ts_lexer__eof(const t_lexer *_self);
t_u32 ts_lexer__get_column(t_lexer *_self);
void ts_lexer__advance(t_lexer *_self, bool skip);
void ts_lexer__do_advance(t_lexer *self, bool skip);
void ts_lexer__clear_chunk(t_lexer *self);
void ts_lexer__get_chunk(t_lexer *self);
void ts_lexer__get_lookahead(t_lexer *self);
void ts_lexer__mark_end(TSLexer *_self);
void ts_lexer__mark_end(t_lexer *_self);
void ts_lexer_advance_to_end(t_lexer *self);
void ts_lexer_goto(t_lexer *self, Length position);
void ts_lexer_goto(t_lexer *self, t_length position);
t_u32 ts_lexer__get_column(TSLexer *_self)
t_u32 ts_lexer__get_column(t_lexer *_self)
{
t_lexer *self;
t_u32 goal_byte;

View file

@ -6,32 +6,32 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/31 18:08:11 by maiboyer #+# #+# */
/* Updated: 2024/08/31 18:39:32 by maiboyer ### ########.fr */
/* Updated: 2024/09/19 16:59:09 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/types.h"
#include "parser/lexer.h"
bool ts_lexer__eof(const TSLexer *_self);
t_u32 ts_lexer__get_column(TSLexer *_self);
void ts_lexer__advance(TSLexer *_self, bool skip);
bool ts_lexer__eof(const t_lexer *_self);
t_u32 ts_lexer__get_column(t_lexer *_self);
void ts_lexer__advance(t_lexer *_self, bool skip);
void ts_lexer__do_advance(t_lexer *self, bool skip);
void ts_lexer__clear_chunk(t_lexer *self);
void ts_lexer__get_chunk(t_lexer *self);
void ts_lexer__get_lookahead(t_lexer *self);
void ts_lexer__mark_end(TSLexer *_self);
void ts_lexer__mark_end(t_lexer *_self);
void ts_lexer_advance_to_end(t_lexer *self);
void ts_lexer_goto(t_lexer *self, Length position);
void ts_lexer_goto(t_lexer *self, t_length position);
void ts_lexer_goto_inside_loop(t_lexer *self, bool *found_included_range,
TSRange *included_range, t_usize i);
t_range *included_range, t_usize i);
void ts_lexer_goto_after_loop(t_lexer *self, bool found_included_range);
void ts_lexer_goto(t_lexer *self, Length position)
void ts_lexer_goto(t_lexer *self, t_length position)
{
bool found_included_range;
TSRange *included_range;
t_range *included_range;
t_u32 i;
included_range = NULL;
@ -54,11 +54,11 @@ void ts_lexer_goto(t_lexer *self, Length position)
}
void ts_lexer_goto_inside_loop(t_lexer *self, bool *found_included_range,
TSRange *included_range, t_usize i)
t_range *included_range, t_usize i)
{
if (included_range->start_byte >= self->current_position.bytes)
{
self->current_position = (Length){
self->current_position = (t_length){
.bytes = included_range->start_byte,
.extent = included_range->start_point,
};
@ -69,7 +69,7 @@ void ts_lexer_goto_inside_loop(t_lexer *self, bool *found_included_range,
void ts_lexer_goto_after_loop(t_lexer *self, bool found_included_range)
{
TSRange *last_included_range;
t_range *last_included_range;
if (found_included_range)
{
@ -78,19 +78,19 @@ void ts_lexer_goto_after_loop(t_lexer *self, bool found_included_range)
+ self->chunk_size))
ts_lexer__clear_chunk(self);
self->lookahead_size = 0;
self->data.lookahead = '\0';
self->funcs.lookahead = '\0';
}
else
{
self->current_included_range_index = self->included_range_count;
last_included_range = &self->included_ranges[self->included_range_count
- 1];
self->current_position = (Length){
self->current_position = (t_length){
.bytes = last_included_range->end_byte,
.extent = last_included_range->end_point,
};
ts_lexer__clear_chunk(self);
self->lookahead_size = 1;
self->data.lookahead = '\0';
self->funcs.lookahead = '\0';
}
}

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/31 17:58:01 by maiboyer #+# #+# */
/* Updated: 2024/08/31 18:25:16 by maiboyer ### ########.fr */
/* Updated: 2024/09/19 16:59:58 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,27 +15,27 @@
#define BYTE_ORDER_MARK 0xFEFF
bool ts_lexer__eof(const TSLexer *_self);
t_u32 ts_lexer__get_column(TSLexer *_self);
void ts_lexer__advance(TSLexer *_self, bool skip);
bool ts_lexer__eof(const t_lexer *_self);
t_u32 ts_lexer__get_column(t_lexer *_self);
void ts_lexer__advance(t_lexer *_self, bool skip);
void ts_lexer__clear_chunk(t_lexer *self);
void ts_lexer__get_chunk(t_lexer *self);
void ts_lexer__get_lookahead(t_lexer *self);
void ts_lexer__mark_end(TSLexer *_self);
void ts_lexer__mark_end(t_lexer *_self);
void ts_lexer_advance_to_end(t_lexer *self);
void ts_lexer_goto(t_lexer *self, Length position);
void ts_lexer_goto(t_lexer *self, t_length position);
void ts_lexer_init(t_lexer *self)
{
static TSRange default_range = {.start_point = {\
static t_range default_range = {.start_point = {\
.row = 0, .column = 0, }, .end_point = {.row = UINT32_MAX, \
.column = UINT32_MAX, }, .start_byte = 0, .end_byte = UINT32_MAX};
*self = (t_lexer){
.data = {
.funcs = {
.advance = ts_lexer__advance,
.mark_end = ts_lexer__mark_end,
.get_column = ts_lexer__get_column,
.get_column = NULL, //ts_lexer__get_column,
.eof = ts_lexer__eof,
.lookahead = 0,
.result_symbol = 0, },
@ -49,14 +49,14 @@ void ts_lexer_init(t_lexer *self)
};
}
void ts_lexer_set_input(t_lexer *self, TSInput input)
void ts_lexer_set_input(t_lexer *self, t_input input)
{
self->input = input;
ts_lexer__clear_chunk(self);
ts_lexer_goto(self, self->current_position);
}
void ts_lexer_reset(t_lexer *self, Length position)
void ts_lexer_reset(t_lexer *self, t_length position)
{
if (position.bytes != self->current_position.bytes)
ts_lexer_goto(self, position);
@ -66,24 +66,24 @@ void ts_lexer_start(t_lexer *self)
{
self->token_start_position = self->current_position;
self->token_end_position = LENGTH_UNDEFINED;
self->data.result_symbol = 0;
self->funcs.result_symbol = 0;
self->did_get_column = false;
if (!ts_lexer__eof(&self->data))
if (!ts_lexer__eof(self))
{
if (!self->chunk_size)
ts_lexer__get_chunk(self);
if (!self->lookahead_size)
ts_lexer__get_lookahead(self);
if (self->current_position.bytes == 0
&& self->data.lookahead == BYTE_ORDER_MARK)
ts_lexer__advance(&self->data, true);
&& self->funcs.lookahead == BYTE_ORDER_MARK)
ts_lexer__advance(self, true);
}
}
void ts_lexer_finish(t_lexer *self, t_u32 *lookahead_end_byte)
{
if (length_is_undefined(self->token_end_position))
ts_lexer__mark_end(&self->data);
ts_lexer__mark_end(self);
(void)(lookahead_end_byte);
if (self->token_end_position.bytes < self->token_start_position.bytes)
self->token_start_position = self->token_end_position;

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/31 18:09:03 by maiboyer #+# #+# */
/* Updated: 2024/08/31 18:09:03 by maiboyer ### ########.fr */
/* Updated: 2024/09/19 17:00:15 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,16 +14,16 @@
#include "parser/input.h"
#include "parser/lexer.h"
bool ts_lexer__eof(const TSLexer *_self);
t_u32 ts_lexer__get_column(TSLexer *_self);
void ts_lexer__advance(TSLexer *_self, bool skip);
bool ts_lexer__eof(const t_lexer *_self);
t_u32 ts_lexer__get_column(t_lexer *_self);
void ts_lexer__advance(t_lexer *_self, bool skip);
void ts_lexer__do_advance(t_lexer *self, bool skip);
void ts_lexer__clear_chunk(t_lexer *self);
void ts_lexer__get_chunk(t_lexer *self);
void ts_lexer__get_lookahead(t_lexer *self);
void ts_lexer__mark_end(TSLexer *_self);
void ts_lexer__mark_end(t_lexer *_self);
void ts_lexer_advance_to_end(t_lexer *self);
void ts_lexer_goto(t_lexer *self, Length position);
void ts_lexer_goto(t_lexer *self, t_length position);
void ts_lexer__get_lookahead(t_lexer *self)
{
@ -36,11 +36,11 @@ void ts_lexer__get_lookahead(t_lexer *self)
if (size == 0)
{
self->lookahead_size = 1;
self->data.lookahead = '\0';
self->funcs.lookahead = '\0';
return ;
}
chunk = (const t_u8 *)self->chunk + position_in_chunk;
self->lookahead_size = ts_decode_ascii(chunk, size, &self->data.lookahead);
if (self->data.lookahead == TS_DECODE_ERROR)
self->lookahead_size = ts_decode_ascii(chunk, size, &self->funcs.lookahead);
if (self->funcs.lookahead == TS_DECODE_ERROR)
self->lookahead_size = 1;
}