Normed lexer
This commit is contained in:
parent
5ebadce4f8
commit
4a8fb259dc
7 changed files with 191 additions and 158 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/31 17:58:01 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/08/31 18:03:48 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/08/31 18:25:16 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -25,43 +25,44 @@ void ts_lexer__mark_end(TSLexer *_self);
|
|||
void ts_lexer_advance_to_end(Lexer *self);
|
||||
void ts_lexer_goto(Lexer *self, Length position);
|
||||
|
||||
void ts_lexer_init(Lexer *self)
|
||||
void ts_lexer_init(Lexer *self)
|
||||
{
|
||||
static TSRange DEFAULT_RANGE = {.start_point = \
|
||||
{ .row = 0, .column = 0, }, \
|
||||
.end_point = { .row = UINT32_MAX, .column = UINT32_MAX, }, \
|
||||
.start_byte = 0, .end_byte = UINT32_MAX};
|
||||
static TSRange default_range = {.start_point = {\
|
||||
.row = 0, .column = 0, }, .end_point = {.row = UINT32_MAX, \
|
||||
.column = UINT32_MAX, }, .start_byte = 0, .end_byte = UINT32_MAX};
|
||||
|
||||
*self = (Lexer){
|
||||
.data = {
|
||||
.advance = ts_lexer__advance,
|
||||
.mark_end = ts_lexer__mark_end,
|
||||
.get_column = ts_lexer__get_column,
|
||||
.eof = ts_lexer__eof,
|
||||
.lookahead = 0,
|
||||
.result_symbol = 0, },
|
||||
.chunk = NULL, .chunk_size = 0, .chunk_start = 0, \
|
||||
.advance = ts_lexer__advance,
|
||||
.mark_end = ts_lexer__mark_end,
|
||||
.get_column = ts_lexer__get_column,
|
||||
.eof = ts_lexer__eof,
|
||||
.lookahead = 0,
|
||||
.result_symbol = 0, },
|
||||
.chunk = NULL,
|
||||
.chunk_size = 0,
|
||||
.chunk_start = 0,
|
||||
.current_position = {0, {0, 0}},
|
||||
.included_ranges = (void *)&DEFAULT_RANGE,
|
||||
.included_ranges = (void *)&default_range,
|
||||
.included_range_count = 1,
|
||||
.current_included_range_index = 0,
|
||||
};
|
||||
}
|
||||
|
||||
void ts_lexer_set_input(Lexer *self, TSInput input)
|
||||
void ts_lexer_set_input(Lexer *self, TSInput input)
|
||||
{
|
||||
self->input = input;
|
||||
ts_lexer__clear_chunk(self);
|
||||
ts_lexer_goto(self, self->current_position);
|
||||
}
|
||||
|
||||
void ts_lexer_reset(Lexer *self, Length position)
|
||||
void ts_lexer_reset(Lexer *self, Length position)
|
||||
{
|
||||
if (position.bytes != self->current_position.bytes)
|
||||
ts_lexer_goto(self, position);
|
||||
}
|
||||
|
||||
void ts_lexer_start(Lexer *self)
|
||||
void ts_lexer_start(Lexer *self)
|
||||
{
|
||||
self->token_start_position = self->current_position;
|
||||
self->token_end_position = LENGTH_UNDEFINED;
|
||||
|
|
@ -73,12 +74,13 @@ void ts_lexer_start(Lexer *self)
|
|||
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)
|
||||
if (self->current_position.bytes == 0
|
||||
&& self->data.lookahead == BYTE_ORDER_MARK)
|
||||
ts_lexer__advance(&self->data, true);
|
||||
}
|
||||
}
|
||||
|
||||
void ts_lexer_finish(Lexer *self, t_u32 *lookahead_end_byte)
|
||||
void ts_lexer_finish(Lexer *self, t_u32 *lookahead_end_byte)
|
||||
{
|
||||
if (length_is_undefined(self->token_end_position))
|
||||
ts_lexer__mark_end(&self->data);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue