Merge into master my changes (#3)
* WIP * Compiling! * moved some more headers * removed src/point.h * Update * fixed some stuff
This commit is contained in:
parent
24d122dc54
commit
f51a071d03
33 changed files with 805 additions and 339 deletions
|
|
@ -33,10 +33,10 @@
|
|||
/*******************/
|
||||
|
||||
typedef struct s_parser t_parser;
|
||||
typedef struct t_parse_tree t_parse_tree;
|
||||
typedef struct t_query t_query;
|
||||
typedef struct t_query_cursor t_query_cursor;
|
||||
typedef struct t_lookahead_iterator t_lookahead_iterator;
|
||||
typedef struct s_parse_tree t_parse_tree;
|
||||
typedef struct s_query t_query;
|
||||
typedef struct s_query_cursor t_query_cursor;
|
||||
typedef struct s_lookahead_iterator t_lookahead_iterator;
|
||||
|
||||
typedef enum t_input_encoding
|
||||
{
|
||||
|
|
|
|||
23
parser/includes/error_costs.h
Normal file
23
parser/includes/error_costs.h
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* error_costs.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/30 14:26:02 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/04/30 14:26:04 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ERROR_COSTS_H
|
||||
#define ERROR_COSTS_H
|
||||
|
||||
#define ERROR_STATE 0
|
||||
#define ERROR_COST_PER_RECOVERY 500
|
||||
#define ERROR_COST_PER_MISSING_TREE 110
|
||||
#define ERROR_COST_PER_SKIPPED_TREE 100
|
||||
#define ERROR_COST_PER_SKIPPED_LINE 30
|
||||
#define ERROR_COST_PER_SKIPPED_CHAR 1
|
||||
|
||||
#endif /* ERROR_COSTS_H */
|
||||
|
|
@ -6,21 +6,52 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/23 19:51:24 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/04/24 23:03:33 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/04/30 14:28:34 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LEXER_H
|
||||
#define LEXER_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "me/types.h"
|
||||
#include "parser/api.h"
|
||||
#include "parser/parser_length.h"
|
||||
#include "parser/types/types_lexer.h"
|
||||
|
||||
#ifndef TREE_SITTER_API_H_
|
||||
typedef uint16_t t_state_id;
|
||||
typedef uint16_t t_symbol;
|
||||
typedef uint16_t t_field_id;
|
||||
typedef struct s_language t_language;
|
||||
#endif
|
||||
#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
|
||||
|
||||
typedef struct s_liblexer
|
||||
{
|
||||
t_lexer data;
|
||||
t_parse_length current_position;
|
||||
t_parse_length token_start_position;
|
||||
t_parse_length token_end_position;
|
||||
|
||||
t_parser_range *included_ranges;
|
||||
const char *chunk;
|
||||
t_parse_input input;
|
||||
t_parse_logger logger;
|
||||
|
||||
t_u32 included_range_count;
|
||||
t_u32 current_included_range_index;
|
||||
t_u32 chunk_start;
|
||||
t_u32 chunk_size;
|
||||
t_u32 lookahead_size;
|
||||
bool did_get_column;
|
||||
|
||||
char debug_buffer[TREE_SITTER_SERIALIZATION_BUFFER_SIZE];
|
||||
} t_liblexer;
|
||||
|
||||
void ts_lexer_init(t_liblexer *self);
|
||||
void ts_lexer_delete(t_liblexer *self);
|
||||
void ts_lexer_set_input(t_liblexer *self, t_parse_input input);
|
||||
void ts_lexer_reset(t_liblexer *self, t_parse_length range);
|
||||
void ts_lexer_start(t_liblexer *self);
|
||||
void ts_lexer_finish(t_liblexer *self, t_i32 *data);
|
||||
void ts_lexer_advance_to_end(t_liblexer *self);
|
||||
void ts_lexer_mark_end(t_liblexer *self);
|
||||
bool ts_lexer_set_included_ranges(t_liblexer *self,
|
||||
const t_parser_range *ranges, t_u32 count);
|
||||
t_parser_range *ts_lexer_included_ranges(const t_liblexer *self, t_u32 *count);
|
||||
|
||||
#endif /* LEXER_H */
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#define TREE_SITTER_PARSER_H_
|
||||
|
||||
#include "../parse_types.h"
|
||||
#include "./lexer.h"
|
||||
#include "parser/lexer.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef TREE_SITTER_LENGTH_H_
|
||||
#define TREE_SITTER_LENGTH_H_
|
||||
|
||||
#include "../src/point.h"
|
||||
#include "parser/point.h"
|
||||
#include "parser/api.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
|
|
|||
21
parser/includes/point.h
Normal file
21
parser/includes/point.h
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* point.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/30 14:35:22 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/04/30 14:46:18 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef POINT_H
|
||||
#define POINT_H
|
||||
|
||||
#include "parser/point/inline1.h"
|
||||
#include "parser/point/inline2.h"
|
||||
#include "parser/point/inline3.h"
|
||||
|
||||
|
||||
#endif /* POINT_H */
|
||||
50
parser/includes/point/inline1.h
Normal file
50
parser/includes/point/inline1.h
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* inline1.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/30 14:35:50 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/04/30 14:43:49 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef INLINE1_H
|
||||
#define INLINE1_H
|
||||
|
||||
#include "parser/types/types_point.h"
|
||||
|
||||
static inline t_point point__new(unsigned row, unsigned column)
|
||||
{
|
||||
t_point result = {row, column};
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline t_point point_add(t_point a, t_point b)
|
||||
{
|
||||
if (b.row > 0)
|
||||
return point__new(a.row + b.row, b.column);
|
||||
else
|
||||
return point__new(a.row, a.column + b.column);
|
||||
}
|
||||
|
||||
static inline t_point point_sub(t_point a, t_point b)
|
||||
{
|
||||
if (a.row > b.row)
|
||||
return point__new(a.row - b.row, a.column);
|
||||
else
|
||||
return point__new(0, a.column - b.column);
|
||||
}
|
||||
|
||||
static inline bool point_lte(t_point a, t_point b)
|
||||
{
|
||||
return (a.row < b.row) || (a.row == b.row && a.column <= b.column);
|
||||
}
|
||||
|
||||
static inline bool point_lt(t_point a, t_point b)
|
||||
{
|
||||
return (a.row < b.row) || (a.row == b.row && a.column < b.column);
|
||||
}
|
||||
|
||||
#endif /* INLINE1_H */
|
||||
49
parser/includes/point/inline2.h
Normal file
49
parser/includes/point/inline2.h
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* inline2.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/30 14:43:58 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/04/30 14:44:12 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef INLINE2_H
|
||||
#define INLINE2_H
|
||||
|
||||
#include "parser/types/types_point.h"
|
||||
|
||||
static inline bool point_gt(t_point a, t_point b)
|
||||
{
|
||||
return (a.row > b.row) || (a.row == b.row && a.column > b.column);
|
||||
}
|
||||
|
||||
static inline bool point_gte(t_point a, t_point b)
|
||||
{
|
||||
return (a.row > b.row) || (a.row == b.row && a.column >= b.column);
|
||||
}
|
||||
|
||||
static inline bool point_eq(t_point a, t_point b)
|
||||
{
|
||||
return a.row == b.row && a.column == b.column;
|
||||
}
|
||||
|
||||
static inline t_point point_min(t_point a, t_point b)
|
||||
{
|
||||
if (a.row < b.row || (a.row == b.row && a.column < b.column))
|
||||
return a;
|
||||
else
|
||||
return b;
|
||||
}
|
||||
|
||||
static inline t_point point_max(t_point a, t_point b)
|
||||
{
|
||||
if (a.row > b.row || (a.row == b.row && a.column > b.column))
|
||||
return a;
|
||||
else
|
||||
return b;
|
||||
}
|
||||
|
||||
#endif /* INLINE2_H */
|
||||
29
parser/includes/point/inline3.h
Normal file
29
parser/includes/point/inline3.h
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* inline3.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/30 14:44:49 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/04/30 15:04:39 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef INLINE3_H
|
||||
#define INLINE3_H
|
||||
|
||||
#include "parser/types/types_point.h"
|
||||
#include <stdint.h>
|
||||
|
||||
static inline t_point point_val_zero(void)
|
||||
{
|
||||
return ((t_point){0, 0});
|
||||
}
|
||||
|
||||
static inline t_point point_val_max(void)
|
||||
{
|
||||
return ((t_point){UINT32_MAX, UINT32_MAX});
|
||||
}
|
||||
|
||||
#endif /* INLINE3_H */
|
||||
36
parser/includes/reduce_action.h
Normal file
36
parser/includes/reduce_action.h
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* reduce_action.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/30 15:25:12 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/04/30 15:25:38 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef REDUCE_ACTION_H
|
||||
#define REDUCE_ACTION_H
|
||||
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_reduce_action.h"
|
||||
#include "parser/api.h"
|
||||
#include "parser/types/types_reduce_action.h"
|
||||
|
||||
static inline void ts_reduce_action_set_add(t_vec_reduce_action *self,
|
||||
t_reduce_action new_action)
|
||||
{
|
||||
t_reduce_action action;
|
||||
|
||||
for (t_u32 i = 0; i < self->len; i++)
|
||||
{
|
||||
action = self->buffer[i];
|
||||
if (action.symbol == new_action.symbol &&
|
||||
action.count == new_action.count)
|
||||
return;
|
||||
}
|
||||
vec_reduce_action_push(self, new_action);
|
||||
}
|
||||
|
||||
#endif /* REDUCE_ACTION_H */
|
||||
27
parser/includes/types/types_reduce_action.h
Normal file
27
parser/includes/types/types_reduce_action.h
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* types_reduce_action.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/30 15:21:59 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/04/30 15:22:18 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef TYPES_REDUCE_ACTION_H
|
||||
#define TYPES_REDUCE_ACTION_H
|
||||
|
||||
#include "me/types.h"
|
||||
#include "parser/types/types_symbol.h"
|
||||
|
||||
typedef struct s_reduce_action
|
||||
{
|
||||
t_u32 count;
|
||||
t_symbol symbol;
|
||||
t_i32 dynamic_precedence;
|
||||
t_u16 production_id;
|
||||
} t_reduce_action;
|
||||
|
||||
#endif /* TYPES_REDUCE_ACTION_H */
|
||||
Loading…
Add table
Add a link
Reference in a new issue