diff --git a/parser/includes/parser_length.h b/parser/includes/parser_length.h index 5a9137d8..d47b11de 100644 --- a/parser/includes/parser_length.h +++ b/parser/includes/parser_length.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 #include diff --git a/parser/includes/point.h b/parser/includes/point.h new file mode 100644 index 00000000..f315dd73 --- /dev/null +++ b/parser/includes/point.h @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* point.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: maiboyer +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 */ diff --git a/parser/includes/point/inline1.h b/parser/includes/point/inline1.h new file mode 100644 index 00000000..746241a8 --- /dev/null +++ b/parser/includes/point/inline1.h @@ -0,0 +1,50 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* inline1.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: maiboyer +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 */ diff --git a/parser/includes/point/inline2.h b/parser/includes/point/inline2.h new file mode 100644 index 00000000..8d0e455e --- /dev/null +++ b/parser/includes/point/inline2.h @@ -0,0 +1,49 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* inline2.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: maiboyer +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 */ diff --git a/parser/includes/point/inline3.h b/parser/includes/point/inline3.h new file mode 100644 index 00000000..5d68736b --- /dev/null +++ b/parser/includes/point/inline3.h @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* inline3.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: maiboyer +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 + +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 */ diff --git a/parser/src/point.h b/parser/src/point.h deleted file mode 100644 index ce1d9ed5..00000000 --- a/parser/src/point.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef TREE_SITTER_POINT_H_ -#define TREE_SITTER_POINT_H_ - -#include "parser/api.h" - -#define POINT_ZERO ((t_point) {0, 0}) -#define POINT_MAX ((t_point) {UINT32_MAX, UINT32_MAX}) - -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); -} - -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 diff --git a/parser/src/tree.c b/parser/src/tree.c index 0b033126..6122ea08 100644 --- a/parser/src/tree.c +++ b/parser/src/tree.c @@ -66,7 +66,7 @@ void ts_tree_edit(t_parse_tree *self, const t_input_edit *edit) { ); if (range->end_byte < edit->new_end_byte) { range->end_byte = UINT32_MAX; - range->end_point = POINT_MAX; + range->end_point = point_val_max(); } } } else if (range->end_byte > edit->start_byte) { @@ -81,7 +81,7 @@ void ts_tree_edit(t_parse_tree *self, const t_input_edit *edit) { ); if (range->start_byte < edit->new_end_byte) { range->start_byte = UINT32_MAX; - range->start_point = POINT_MAX; + range->start_point = point_val_max(); } } else if (range->start_byte > edit->start_byte) { range->start_byte = edit->start_byte; diff --git a/parser/src/tree_cursor.c b/parser/src/tree_cursor.c index 7f7b129a..e863c961 100644 --- a/parser/src/tree_cursor.c +++ b/parser/src/tree_cursor.c @@ -299,7 +299,7 @@ static inline t_i64 ts_tree_cursor_goto_first_child_for_byte_and_point( } t_i64 ts_tree_cursor_goto_first_child_for_byte(t_parse_tree_cursor *self, t_u32 goal_byte) { - return ts_tree_cursor_goto_first_child_for_byte_and_point(self, goal_byte, POINT_ZERO); + return ts_tree_cursor_goto_first_child_for_byte_and_point(self, goal_byte, point_val_zero()); } t_i64 ts_tree_cursor_goto_first_child_for_point(t_parse_tree_cursor *self, t_point goal_point) {