Updated parser
This commit is contained in:
parent
66a0625382
commit
bdc062b33a
1248 changed files with 93128 additions and 102788 deletions
|
|
@ -6,41 +6,44 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/24 23:01:45 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/02 14:37:53 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/06/29 21:11:19 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef PARSE_TYPES_H
|
||||
# define PARSE_TYPES_H
|
||||
#define PARSE_TYPES_H
|
||||
|
||||
# include <stdbool.h>
|
||||
# include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
# include "me/types.h"
|
||||
# include "parser/types/types_char_range.h"
|
||||
# include "parser/types/types_field_id.h"
|
||||
# include "parser/types/types_field_map_entry.h"
|
||||
# include "parser/types/types_field_map_slice.h"
|
||||
# include "parser/types/types_language.h"
|
||||
# include "parser/types/types_lex_modes.h"
|
||||
# include "parser/types/types_lexer.h"
|
||||
# include "parser/types/types_lexer_state.h"
|
||||
# include "parser/types/types_parse_action_entry.h"
|
||||
# include "parser/types/types_parse_action_type.h"
|
||||
# include "parser/types/types_parse_actions.h"
|
||||
# include "parser/types/types_parser_range.h"
|
||||
# include "parser/types/types_point.h"
|
||||
# include "parser/types/types_scanner.h"
|
||||
# include "parser/types/types_state_id.h"
|
||||
# include "parser/types/types_symbol.h"
|
||||
# include "parser/types/types_symbol_metadata.h"
|
||||
#include "./nsrc/api.h"
|
||||
#include "./nsrc/lexer.h"
|
||||
#include "./nsrc/parser.h"
|
||||
#include "me/types.h"
|
||||
|
||||
#include "parser/types/types_lexer_state.h"
|
||||
|
||||
typedef TSSymbolMetadata t_symbol_metadata;
|
||||
typedef TSSymbol t_symbol;
|
||||
typedef TSStateId t_state_id;
|
||||
typedef TSFieldId t_field_id;
|
||||
typedef TSLexer t_lexer;
|
||||
typedef TSFieldMapSlice t_field_map_slice;
|
||||
typedef TSFieldMapEntry t_field_map_entry;
|
||||
typedef TSParseActionEntry t_parse_action_entry;
|
||||
typedef TSLexMode t_lex_modes;
|
||||
typedef TSCharacterRange t_char_range;
|
||||
|
||||
#define ActionTypeShift TSParseActionTypeShift
|
||||
#define ActionTypeReduce TSParseActionTypeReduce
|
||||
#define ActionTypeRecover TSParseActionTypeRecover
|
||||
#define ActionTypeAccept TSParseActionTypeAccept
|
||||
|
||||
#ifndef inline
|
||||
#define inline __inline__
|
||||
# define inline __inline__
|
||||
#endif
|
||||
|
||||
static inline bool lex_skip(t_state_id state_value, t_lexer *lexer,
|
||||
t_lexer_state *s)
|
||||
static inline bool lex_skip(t_state_id state_value, t_lexer *lexer, t_lexer_state *s)
|
||||
{
|
||||
(void)(lexer);
|
||||
s->skip = true;
|
||||
|
|
@ -48,16 +51,14 @@ static inline bool lex_skip(t_state_id state_value, t_lexer *lexer,
|
|||
return (true);
|
||||
};
|
||||
|
||||
static inline bool lex_advance(t_state_id state_value, t_lexer *lexer,
|
||||
t_lexer_state *s)
|
||||
static inline bool lex_advance(t_state_id state_value, t_lexer *lexer, t_lexer_state *s)
|
||||
{
|
||||
(void)(lexer);
|
||||
s->state = state_value;
|
||||
return (true);
|
||||
};
|
||||
|
||||
static inline bool lex_accept_token(t_symbol symbol_value, t_lexer *lexer,
|
||||
t_lexer_state *s)
|
||||
static inline bool lex_accept_token(t_symbol symbol_value, t_lexer *lexer, t_lexer_state *s)
|
||||
{
|
||||
s->result = true;
|
||||
lexer->result_symbol = symbol_value;
|
||||
|
|
@ -65,15 +66,14 @@ static inline bool lex_accept_token(t_symbol symbol_value, t_lexer *lexer,
|
|||
return (true);
|
||||
};
|
||||
|
||||
static inline bool lex_end_state(t_lexer *lexer, t_lexer_state *s)
|
||||
static inline bool lex_end_state(t_lexer *lexer, t_lexer_state *s)
|
||||
{
|
||||
(void)(lexer);
|
||||
(void)(s);
|
||||
return (false);
|
||||
};
|
||||
|
||||
static inline t_field_map_entry fmap_entry(t_field_id field_id,
|
||||
uint8_t child_index, bool inherited)
|
||||
static inline t_field_map_entry fmap_entry(t_field_id field_id, uint8_t child_index, bool inherited)
|
||||
{
|
||||
return ((t_field_map_entry){
|
||||
.field_id = field_id,
|
||||
|
|
@ -82,7 +82,7 @@ static inline t_field_map_entry fmap_entry(t_field_id field_id,
|
|||
});
|
||||
};
|
||||
|
||||
static inline t_field_map_slice fmap_slice(t_u16 index, t_u16 length)
|
||||
static inline t_field_map_slice fmap_slice(t_u16 index, t_u16 length)
|
||||
{
|
||||
return ((t_field_map_slice){
|
||||
.index = index,
|
||||
|
|
@ -90,8 +90,7 @@ static inline t_field_map_slice fmap_slice(t_u16 index, t_u16 length)
|
|||
});
|
||||
};
|
||||
|
||||
static inline t_symbol_metadata sym_metadata(bool visible, bool named,
|
||||
bool supertype)
|
||||
static inline t_symbol_metadata sym_metadata(bool visible, bool named, bool supertype)
|
||||
{
|
||||
return ((t_symbol_metadata){
|
||||
.visible = visible,
|
||||
|
|
@ -100,13 +99,12 @@ static inline t_symbol_metadata sym_metadata(bool visible, bool named,
|
|||
});
|
||||
};
|
||||
|
||||
static inline t_parse_action_entry entry(uint8_t count, bool reusable)
|
||||
static inline t_parse_action_entry entry(uint8_t count, bool reusable)
|
||||
{
|
||||
return ((t_parse_action_entry){.entry = {.count = count,
|
||||
.reusable = reusable}});
|
||||
return ((t_parse_action_entry){.entry = {.count = count, .reusable = reusable}});
|
||||
};
|
||||
|
||||
static inline t_parse_action_entry shift(t_state_id state_value)
|
||||
static inline t_parse_action_entry shift(t_state_id state_value)
|
||||
{
|
||||
return ((t_parse_action_entry){{.shift = {
|
||||
.type = ActionTypeShift,
|
||||
|
|
@ -114,22 +112,19 @@ static inline t_parse_action_entry shift(t_state_id state_value)
|
|||
}}});
|
||||
};
|
||||
|
||||
static inline t_parse_action_entry shift_repeat(t_state_id state_value)
|
||||
static inline t_parse_action_entry shift_repeat(t_state_id state_value)
|
||||
{
|
||||
return ((t_parse_action_entry){{.shift = {.type = ActionTypeShift,
|
||||
.state = (state_value), .repetition = true}}});
|
||||
return ((t_parse_action_entry){{.shift = {.type = ActionTypeShift, .state = (state_value), .repetition = true}}});
|
||||
};
|
||||
|
||||
static inline t_parse_action_entry shift_extra(void)
|
||||
static inline t_parse_action_entry shift_extra(void)
|
||||
{
|
||||
return ((t_parse_action_entry){{.shift = {.type = ActionTypeShift,
|
||||
.extra = true}}});
|
||||
return ((t_parse_action_entry){{.shift = {.type = ActionTypeShift, .extra = true}}});
|
||||
};
|
||||
|
||||
static inline t_parse_action_entry reduce(
|
||||
static inline t_parse_action_entry reduce(
|
||||
|
||||
t_symbol symbol, uint8_t child_count, int16_t dynamic_precedence,
|
||||
t_u16 production_id)
|
||||
t_symbol symbol, uint8_t child_count, int16_t dynamic_precedence, t_u16 production_id)
|
||||
{
|
||||
return ((t_parse_action_entry){{.reduce = {
|
||||
.type = ActionTypeReduce,
|
||||
|
|
@ -140,25 +135,25 @@ static inline t_parse_action_entry reduce(
|
|||
}}});
|
||||
};
|
||||
|
||||
static inline t_parse_action_entry recover(void)
|
||||
static inline t_parse_action_entry recover(void)
|
||||
{
|
||||
return ((t_parse_action_entry){{.type = ActionTypeRecover}});
|
||||
};
|
||||
|
||||
static inline t_parse_action_entry accept(void)
|
||||
static inline t_parse_action_entry accept(void)
|
||||
{
|
||||
return ((t_parse_action_entry){{.type = ActionTypeAccept}});
|
||||
};
|
||||
|
||||
static inline bool set_contains(t_char_range *ranges, t_u32 len,
|
||||
int32_t lookahead)
|
||||
/*
|
||||
static inline bool set_contains(t_char_range *ranges, t_u32 len, int32_t lookahead)
|
||||
{
|
||||
t_u32 index = 0;
|
||||
t_u32 size = len - index;
|
||||
while (size > 1)
|
||||
{
|
||||
t_u32 half_size = size / 2;
|
||||
t_u32 mid_index = index + half_size;
|
||||
t_u32 half_size = size / 2;
|
||||
t_u32 mid_index = index + half_size;
|
||||
t_char_range *range = &ranges[mid_index];
|
||||
if (lookahead >= range->start && lookahead <= range->end)
|
||||
{
|
||||
|
|
@ -173,9 +168,9 @@ static inline bool set_contains(t_char_range *ranges, t_u32 len,
|
|||
t_char_range *range = &ranges[index];
|
||||
return (lookahead >= range->start && lookahead <= range->end);
|
||||
};
|
||||
*/
|
||||
|
||||
static inline bool advance_map_inner(t_u32 *map, t_u32 elems, t_lexer *l,
|
||||
t_lexer_state *s)
|
||||
static inline bool advance_map_inner(t_u32 *map, t_u32 elems, t_lexer *l, t_lexer_state *s)
|
||||
{
|
||||
t_u32 i;
|
||||
|
||||
|
|
@ -193,8 +188,7 @@ static inline bool advance_map_inner(t_u32 *map, t_u32 elems, t_lexer *l,
|
|||
return (false);
|
||||
};
|
||||
|
||||
static inline t_lex_modes lex_mode_external(t_u16 lex_state,
|
||||
t_u16 ext_lex_state)
|
||||
static inline t_lex_modes lex_mode_external(t_u16 lex_state, t_u16 ext_lex_state)
|
||||
{
|
||||
return ((t_lex_modes){
|
||||
.lex_state = lex_state,
|
||||
|
|
@ -202,19 +196,19 @@ static inline t_lex_modes lex_mode_external(t_u16 lex_state,
|
|||
});
|
||||
};
|
||||
|
||||
static inline t_lex_modes lex_mode_normal(t_u16 lex_state)
|
||||
static inline t_lex_modes lex_mode_normal(t_u16 lex_state)
|
||||
{
|
||||
return ((t_lex_modes){
|
||||
.lex_state = lex_state,
|
||||
});
|
||||
};
|
||||
|
||||
static inline t_u16 actions(t_u16 val)
|
||||
static inline t_u16 actions(t_u16 val)
|
||||
{
|
||||
return (val);
|
||||
};
|
||||
|
||||
static inline t_u16 state(t_u16 val)
|
||||
static inline t_u16 state(t_u16 val)
|
||||
{
|
||||
return (val);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue