fix: fixed the script kiddy
This commit is contained in:
parent
cd87c06903
commit
9f55be8a7c
286 changed files with 0 additions and 37434 deletions
|
|
@ -1,91 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* api.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/22 13:54:54 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/19 16:45:08 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef API_H
|
||||
#define API_H
|
||||
|
||||
#include "me/types.h"
|
||||
#include "parser/inner/length_inner.h"
|
||||
#include "parser/inner/point_inner.h"
|
||||
#include "parser/inner/subtree_inner.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
|
||||
|
||||
#define TREE_SITTER_LANGUAGE_VERSION 14
|
||||
#define TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION 13
|
||||
|
||||
t_tree *ts_tree_copy(const t_tree *self);
|
||||
void ts_tree_delete(t_tree *self);
|
||||
t_node ts_tree_root_node(const t_tree *self);
|
||||
t_node ts_tree_root_node_with_offset(const t_tree *self, t_u32 offset_bytes, t_point offset_extent);
|
||||
const t_language *ts_tree_language(const t_tree *self);
|
||||
|
||||
t_const_str ts_node_type(t_node self);
|
||||
t_symbol ts_node_symbol(t_node self);
|
||||
const t_language *ts_node_language(t_node self);
|
||||
t_symbol ts_node_grammar_symbol(t_node self);
|
||||
t_u32 ts_node_start_byte(t_node self);
|
||||
t_point ts_node_start_point(t_node self);
|
||||
t_u32 ts_node_end_byte(t_node self);
|
||||
t_point ts_node_end_point(t_node self);
|
||||
char *ts_node_string(t_node self);
|
||||
bool ts_node_is_null(t_node self);
|
||||
bool ts_node_is_named(t_node self);
|
||||
bool ts_node_is_missing(t_node self);
|
||||
bool ts_node_is_extra(t_node self);
|
||||
bool ts_node_has_changes(t_node self);
|
||||
bool ts_node_has_error(t_node self);
|
||||
bool ts_node_is_error(t_node self);
|
||||
t_state_id ts_node_parse_state(t_node self);
|
||||
t_state_id ts_node_next_parse_state(t_node self);
|
||||
t_node ts_node_parent(t_node self);
|
||||
t_node ts_node_child_containing_descendant(t_node self, t_node descendant);
|
||||
t_node ts_node_child(t_node self, t_u32 child_index);
|
||||
t_const_str ts_node_field_name_for_child(t_node self, t_u32 child_index);
|
||||
t_field_id ts_node_field_id_for_child(t_node self, t_u32 child_index);
|
||||
t_u32 ts_node_child_count(t_node self);
|
||||
t_node ts_node_named_child(t_node self, t_u32 child_index);
|
||||
t_u32 ts_node_named_child_count(t_node self);
|
||||
t_node ts_node_child_by_field_name(t_node self, t_const_str name, t_u32 name_length);
|
||||
t_node ts_node_child_by_field_id(t_node self, t_field_id field_id);
|
||||
t_node ts_node_next_sibling(t_node self);
|
||||
t_node ts_node_prev_sibling(t_node self);
|
||||
t_node ts_node_next_named_sibling(t_node self);
|
||||
t_node ts_node_prev_named_sibling(t_node self);
|
||||
t_node ts_node_first_child_for_byte(t_node self, t_u32 byte);
|
||||
t_node ts_node_first_named_child_for_byte(t_node self, t_u32 byte);
|
||||
t_u32 ts_node_descendant_count(t_node self);
|
||||
t_node ts_node_descendant_for_byte_range(t_node self, t_u32 start, t_u32 end);
|
||||
t_node ts_node_descendant_for_point_range(t_node self, t_point start, t_point end);
|
||||
t_node ts_node_named_descendant_for_byte_range(t_node self, t_u32 start, t_u32 end);
|
||||
t_node ts_node_named_descendant_for_point_range(t_node self, t_point start, t_point end);
|
||||
bool ts_node_eq(t_node self, t_node other);
|
||||
|
||||
const t_language *ts_language_copy(const t_language *self);
|
||||
void ts_language_delete(const t_language *self);
|
||||
t_u32 ts_language_symbol_count(const t_language *self);
|
||||
t_u32 ts_language_state_count(const t_language *self);
|
||||
t_const_str ts_language_symbol_name(const t_language *self, t_symbol symbol);
|
||||
t_symbol ts_language_symbol_for_name(const t_language *self, t_const_str string, t_u32 length, bool is_named);
|
||||
t_u32 ts_language_field_count(const t_language *self);
|
||||
t_const_str ts_language_field_name_for_id(const t_language *self, t_field_id id);
|
||||
t_field_id ts_language_field_id_for_name(const t_language *self, t_const_str name, t_u32 name_length);
|
||||
t_symbol_type ts_language_symbol_type(const t_language *self, t_symbol symbol);
|
||||
t_u32 ts_language_version(const t_language *self);
|
||||
t_state_id ts_language_next_state(const t_language *self, t_state_id state, t_symbol symbol);
|
||||
|
||||
#endif // TREE_SITTER_API_H_
|
||||
|
|
@ -1,275 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* array.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/31 12:03:22 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/02 21:15:05 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef TREE_SITTER_ARRAY_H_
|
||||
#define TREE_SITTER_ARRAY_H_
|
||||
|
||||
#include "me/types.h"
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "me/mem/mem.h"
|
||||
|
||||
#define Array(T) \
|
||||
struct \
|
||||
{ \
|
||||
T *contents; \
|
||||
t_u32 size; \
|
||||
t_u32 capacity; \
|
||||
}
|
||||
|
||||
/// Initialize an array.
|
||||
#define array_init(self) ((self)->size = 0, (self)->capacity = 0, (self)->contents = NULL)
|
||||
|
||||
/// Create an empty array.
|
||||
#define array_new() {NULL, 0, 0}
|
||||
|
||||
/// Get a pointer to the element at a given `index` in the array.
|
||||
#define array_get(self, _index) (assert((t_u32)(_index) < (self)->size), &(self)->contents[_index])
|
||||
|
||||
/// Get a pointer to the first element in the array.
|
||||
#define array_front(self) array_get(self, 0)
|
||||
|
||||
/// Get a pointer to the last element in the array.
|
||||
#define array_back(self) array_get(self, (self)->size - 1)
|
||||
|
||||
/// Clear the array, setting its size to zero. Note that this does not free any
|
||||
/// memory allocated for the array's contents.
|
||||
#define array_clear(self) ((self)->size = 0)
|
||||
|
||||
/// Reserve `new_capacity` elements of space in the array. If `new_capacity` is
|
||||
/// less than the array's current capacity, this function has no effect.
|
||||
#define array_reserve(self, new_capacity) _array__reserve((Array *)(self), array_elem_size(self), new_capacity)
|
||||
|
||||
/// Free any memory allocated for this array. Note that this does not free any
|
||||
/// memory allocated for the array's contents.
|
||||
#define array_delete(self) _array__delete((Array *)(self))
|
||||
|
||||
/// Push a new `element` onto the end of the array.
|
||||
#define array_push(self, element) (_array__grow((Array *)(self), 1, array_elem_size(self)), (self)->contents[(self)->size++] = (element))
|
||||
|
||||
/// Increase the array's size by `count` elements.
|
||||
/// New elements are zero-initialized.
|
||||
#define array_grow_by(self, count) \
|
||||
do \
|
||||
{ \
|
||||
if ((count) == 0) \
|
||||
break; \
|
||||
_array__grow((Array *)(self), count, array_elem_size(self)); \
|
||||
memset((self)->contents + (self)->size, 0, (count) * array_elem_size(self)); \
|
||||
(self)->size += (count); \
|
||||
} while (0)
|
||||
|
||||
/// Append all elements from one array to the end of another.
|
||||
#define array_push_all(self, other) array_extend((self), (other)->size, (other)->contents)
|
||||
|
||||
/// Append `count` elements to the end of the array, reading their values from the
|
||||
/// `contents` pointer.
|
||||
#define array_extend(self, count, contents) _array__splice((Array *)(self), array_elem_size(self), (self)->size, 0, count, contents)
|
||||
|
||||
/// Remove `old_count` elements from the array starting at the given `index`. At
|
||||
/// the same index, insert `new_count` new elements, reading their values from the
|
||||
/// `new_contents` pointer.
|
||||
#define array_splice(self, _index, old_count, new_count, new_contents) \
|
||||
_array__splice((Array *)(self), array_elem_size(self), _index, old_count, new_count, new_contents)
|
||||
|
||||
/// Insert one `element` into the array at the given `index`.
|
||||
#define array_insert(self, _index, element) _array__splice((Array *)(self), array_elem_size(self), _index, 0, 1, &(element))
|
||||
|
||||
/// Remove one element from the array at the given `index`.
|
||||
#define array_erase(self, _index) _array__erase((Array *)(self), array_elem_size(self), _index)
|
||||
|
||||
/// Pop the last element off the array, returning the element by value.
|
||||
#define array_pop(self) ((self)->contents[--(self)->size])
|
||||
|
||||
/// Assign the contents of one array to another, reallocating if necessary.
|
||||
#define array_assign(self, other) _array__assign((Array *)(self), (const Array *)(other), array_elem_size(self))
|
||||
|
||||
/// Swap one array with another
|
||||
#define array_swap(self, other) _array__swap((Array *)(self), (Array *)(other))
|
||||
|
||||
/// Get the size of the array contents
|
||||
#define array_elem_size(self) (sizeof *(self)->contents)
|
||||
|
||||
/// Search a sorted array for a given `needle` value, using the given `compare`
|
||||
/// callback to determine the order.
|
||||
///
|
||||
/// If an existing element is found to be equal to `needle`, then the `index`
|
||||
/// out-parameter is set to the existing value's index, and the `exists`
|
||||
/// out-parameter is set to true. Otherwise, `index` is set to an index where
|
||||
/// `needle` should be inserted in order to preserve the sorting, and `exists`
|
||||
/// is set to false.
|
||||
#define array_search_sorted_with(self, compare, needle, _index, _exists) _array__search_sorted(self, 0, compare, , needle, _index, _exists)
|
||||
|
||||
/// Search a sorted array for a given `needle` value, using integer comparisons
|
||||
/// of a given struct field (specified with a leading dot) to determine the order.
|
||||
///
|
||||
/// See also `array_search_sorted_with`.
|
||||
#define array_search_sorted_by(self, field, needle, _index, _exists) \
|
||||
_array__search_sorted(self, 0, _compare_int, field, needle, _index, _exists)
|
||||
|
||||
/// Insert a given `value` into a sorted array, using the given `compare`
|
||||
/// callback to determine the order.
|
||||
#define array_insert_sorted_with(self, compare, value) \
|
||||
do \
|
||||
{ \
|
||||
t_u32 _index, _exists; \
|
||||
array_search_sorted_with(self, compare, &(value), &_index, &_exists); \
|
||||
if (!_exists) \
|
||||
array_insert(self, _index, value); \
|
||||
} while (0)
|
||||
|
||||
/// Insert a given `value` into a sorted array, using integer comparisons of
|
||||
/// a given struct field (specified with a leading dot) to determine the order.
|
||||
///
|
||||
/// See also `array_search_sorted_by`.
|
||||
#define array_insert_sorted_by(self, field, value) \
|
||||
do \
|
||||
{ \
|
||||
t_u32 _index, _exists; \
|
||||
array_search_sorted_by(self, field, (value)field, &_index, &_exists); \
|
||||
if (!_exists) \
|
||||
array_insert(self, _index, value); \
|
||||
} while (0)
|
||||
|
||||
// Private
|
||||
|
||||
typedef Array(void) Array;
|
||||
|
||||
/// This is not what you're looking for, see `array_delete`.
|
||||
static inline void _array__delete(Array *self)
|
||||
{
|
||||
if (self->contents)
|
||||
{
|
||||
mem_free(self->contents);
|
||||
self->contents = NULL;
|
||||
self->size = 0;
|
||||
self->capacity = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// This is not what you're looking for, see `array_erase`.
|
||||
static inline void _array__erase(Array *self, size_t element_size, t_u32 index)
|
||||
{
|
||||
assert(index < self->size);
|
||||
char *contents = (char *)self->contents;
|
||||
memmove(contents + index * element_size, contents + (index + 1) * element_size, (self->size - index - 1) * element_size);
|
||||
self->size--;
|
||||
}
|
||||
|
||||
/// This is not what you're looking for, see `array_reserve`.
|
||||
static inline void _array__reserve(Array *self, size_t element_size, t_u32 new_capacity)
|
||||
{
|
||||
if (new_capacity > self->capacity)
|
||||
{
|
||||
if (self->contents)
|
||||
{
|
||||
self->contents = mem_realloc(self->contents, new_capacity * element_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
self->contents = mem_alloc(new_capacity * element_size);
|
||||
}
|
||||
self->capacity = new_capacity;
|
||||
}
|
||||
}
|
||||
|
||||
/// This is not what you're looking for, see `array_assign`.
|
||||
static inline void _array__assign(Array *self, const Array *other, size_t element_size)
|
||||
{
|
||||
_array__reserve(self, element_size, other->size);
|
||||
self->size = other->size;
|
||||
mem_copy(self->contents, other->contents, self->size * element_size);
|
||||
}
|
||||
|
||||
/// This is not what you're looking for, see `array_swap`.
|
||||
static inline void _array__swap(Array *self, Array *other)
|
||||
{
|
||||
Array swap = *other;
|
||||
*other = *self;
|
||||
*self = swap;
|
||||
}
|
||||
|
||||
/// This is not what you're looking for, see `array_push` or `array_grow_by`.
|
||||
static inline void _array__grow(Array *self, t_u32 count, size_t element_size)
|
||||
{
|
||||
t_u32 new_size = self->size + count;
|
||||
if (new_size > self->capacity)
|
||||
{
|
||||
t_u32 new_capacity = self->capacity * 2;
|
||||
if (new_capacity < 8)
|
||||
new_capacity = 8;
|
||||
if (new_capacity < new_size)
|
||||
new_capacity = new_size;
|
||||
_array__reserve(self, element_size, new_capacity);
|
||||
}
|
||||
}
|
||||
|
||||
/// This is not what you're looking for, see `array_splice`.
|
||||
static inline void _array__splice(Array *self, size_t element_size, t_u32 index, t_u32 old_count, t_u32 new_count, const void *elements)
|
||||
{
|
||||
char *contents;
|
||||
t_u32 new_size;
|
||||
t_u32 old_end;
|
||||
t_u32 new_end;
|
||||
|
||||
new_size = self->size + new_count - old_count;
|
||||
old_end = index + old_count;
|
||||
new_end = index + new_count;
|
||||
_array__reserve(self, element_size, new_size);
|
||||
contents = (char *)self->contents;
|
||||
if (self->size > old_end)
|
||||
mem_move(contents + new_end * element_size, contents + old_end * element_size, (self->size - old_end) * element_size);
|
||||
if (new_count > 0)
|
||||
{
|
||||
if (elements)
|
||||
mem_copy((contents + index * element_size), elements, new_count * element_size);
|
||||
else
|
||||
mem_set_zero((contents + index * element_size), new_count * element_size);
|
||||
}
|
||||
self->size += new_count - old_count;
|
||||
}
|
||||
|
||||
/// A binary search routine, based on Rust's `std::slice::binary_search_by`.
|
||||
/// This is not what you're looking for, see `array_search_sorted_with` or `array_search_sorted_by`.
|
||||
#define _array__search_sorted(self, start, compare, suffix, needle, _index, _exists) \
|
||||
do \
|
||||
{ \
|
||||
*(_index) = start; \
|
||||
*(_exists) = false; \
|
||||
t_u32 size = (self)->size - *(_index); \
|
||||
if (size == 0) \
|
||||
break; \
|
||||
int comparison; \
|
||||
while (size > 1) \
|
||||
{ \
|
||||
t_u32 half_size = size / 2; \
|
||||
t_u32 mid_index = *(_index) + half_size; \
|
||||
comparison = compare(&((self)->contents[mid_index] suffix), (needle)); \
|
||||
if (comparison <= 0) \
|
||||
*(_index) = mid_index; \
|
||||
size -= half_size; \
|
||||
} \
|
||||
comparison = compare(&((self)->contents[*(_index)] suffix), (needle)); \
|
||||
if (comparison == 0) \
|
||||
*(_exists) = true; \
|
||||
else if (comparison < 0) \
|
||||
*(_index) += 1; \
|
||||
} while (0)
|
||||
|
||||
/// Helper macro for the `_sorted_by` routines below. This takes the left (existing)
|
||||
/// parameter by reference in order to work with the generic sorting function above.
|
||||
#define _compare_int(a, b) ((int)*(a) - (int)(b))
|
||||
|
||||
#endif // TREE_SITTER_ARRAY_H_
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* external_scanner_state.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/24 13:56:34 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/19 16:54:04 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef EXTERNAL_SCANNER_STATE_H
|
||||
#define EXTERNAL_SCANNER_STATE_H
|
||||
|
||||
#include "me/types.h"
|
||||
|
||||
struct s_external_scanner_state
|
||||
{
|
||||
char *long_data;
|
||||
t_u32 length;
|
||||
};
|
||||
|
||||
typedef struct s_external_scanner_state t_external_scanner_state;
|
||||
typedef struct s_subtree_data t_subtree_data;
|
||||
typedef t_subtree_data *t_subtree;
|
||||
|
||||
bool ts_external_scanner_state_eq(const t_external_scanner_state *self, const t_u8 *buffer, t_u32 length);
|
||||
bool ts_subtree_external_scanner_state_eq(t_subtree self, t_subtree other);
|
||||
const t_external_scanner_state *ts_subtree_external_scanner_state(t_subtree self);
|
||||
const t_u8 *ts_external_scanner_state_data(const t_external_scanner_state *self);
|
||||
t_external_scanner_state ts_external_scanner_state_copy(const t_external_scanner_state *self);
|
||||
void ts_external_scanner_state_delete(t_external_scanner_state *self);
|
||||
void ts_external_scanner_state_init(t_external_scanner_state *self, const t_u8 *data, t_u32 length);
|
||||
|
||||
#endif /* EXTERNAL_SCANNER_STATE_H */
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* length_inner.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/02 20:03:42 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/19 19:34:50 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LENGTH_INNER_H
|
||||
# define LENGTH_INNER_H
|
||||
|
||||
# include "me/types.h"
|
||||
# include "parser/inner/point_inner.h"
|
||||
|
||||
typedef struct s_length t_length;
|
||||
|
||||
struct s_length
|
||||
{
|
||||
t_u32 bytes;
|
||||
t_point extent;
|
||||
};
|
||||
|
||||
t_length length_add(t_length len1, t_length len2);
|
||||
t_length length_min(t_length len1, t_length len2);
|
||||
t_length length_saturating_sub(t_length len1, t_length len2);
|
||||
t_length length_sub(t_length len1, t_length len2);
|
||||
t_length length_zero(void);
|
||||
bool length_is_undefined(t_length length);
|
||||
|
||||
#endif /* LENGTH_INNER_H */
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* node.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/31 17:04:59 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/19 19:35:40 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef NODE_H
|
||||
# define NODE_H
|
||||
|
||||
# include "me/types.h"
|
||||
# include "parser/length.h"
|
||||
# include "parser/subtree.h"
|
||||
|
||||
typedef struct s_node_child_iterator NodeChildIterator;
|
||||
struct s_node_child_iterator
|
||||
{
|
||||
t_subtree parent;
|
||||
const t_tree *tree;
|
||||
t_length position;
|
||||
t_u32 child_index;
|
||||
t_u32 structural_child_index;
|
||||
const t_symbol *alias_sequence;
|
||||
};
|
||||
|
||||
NodeChildIterator ts_node_iterate_children(const t_node *node);
|
||||
t_field_id ts_node__field_id_from_language(t_node self, t_u32 structural_child_index);
|
||||
t_node ts_node__child(t_node self, t_u32 child_index, bool include_anonymous);
|
||||
t_node ts_node__null(void);
|
||||
bool ts_node__is_relevant(t_node self, bool include_anonymous);
|
||||
bool ts_node_child_iterator_done(NodeChildIterator *self);
|
||||
bool ts_node_child_iterator_next(NodeChildIterator *self, t_node *result);
|
||||
t_const_str ts_node__field_name_from_language(t_node self, t_u32 structural_child_index);
|
||||
t_u32 ts_node__relevant_child_count(t_node self, bool include_anonymous);
|
||||
t_subtree ts_node__subtree(t_node self);
|
||||
t_u32 ts_node__alias(const t_node *self);
|
||||
|
||||
#endif /* NODE_H */
|
||||
|
|
@ -1,139 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parser_inner.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/10 13:56:47 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/19 22:10:08 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef PARSER_INNER_H
|
||||
#define PARSER_INNER_H
|
||||
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_reduce_action.h"
|
||||
#include "me/vec/vec_subtree.h"
|
||||
#include "parser/api.h"
|
||||
#include "parser/array.h"
|
||||
#include "parser/language.h"
|
||||
#include "parser/length.h"
|
||||
#include "parser/lexer.h"
|
||||
#include "parser/reduce_action.h"
|
||||
#include "parser/inner/stack_inner.h"
|
||||
#include "parser/subtree.h"
|
||||
#include "parser/tree.h"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define MAX_VERSION_COUNT 40
|
||||
#define MAX_VERSION_COUNT_OVERFLOW 60
|
||||
#define MAX_SUMMARY_DEPTH 1
|
||||
#define MAX_COST_DIFFERENCE 16 * ERROR_COST_PER_SKIPPED_TREE
|
||||
|
||||
typedef enum e_error_comparison t_error_comparison;
|
||||
typedef struct s_error_status t_error_status;
|
||||
typedef struct s_string_input t_string_input;
|
||||
typedef struct s_parser t_parser;
|
||||
|
||||
struct s_parser
|
||||
{
|
||||
t_lexer lexer;
|
||||
t_stack *stack;
|
||||
const t_language *language;
|
||||
t_vec_reduce_action reduce_actions;
|
||||
t_subtree finished_tree;
|
||||
t_vec_subtree trailing_extras;
|
||||
t_vec_subtree trailing_extras2;
|
||||
t_vec_subtree scratch_trees;
|
||||
void *external_scanner_payload;
|
||||
t_u32 accept_count;
|
||||
t_u32 operation_count;
|
||||
bool has_scanner_error;
|
||||
};
|
||||
|
||||
struct s_error_status
|
||||
{
|
||||
t_u32 cost;
|
||||
t_u32 node_count;
|
||||
int dynamic_precedence;
|
||||
bool is_in_error;
|
||||
};
|
||||
|
||||
enum e_error_comparison
|
||||
{
|
||||
|
||||
ECTakeLeft,
|
||||
ECPreferLeft,
|
||||
ECNone,
|
||||
ECPreferRight,
|
||||
ECTakeRight,
|
||||
};
|
||||
|
||||
struct s_string_input
|
||||
{
|
||||
const t_u8 *string;
|
||||
t_u32 length;
|
||||
};
|
||||
|
||||
struct s_parser_advance_state
|
||||
{
|
||||
TSParseAction action;
|
||||
TableEntry table_entry;
|
||||
bool end_of_non_terminal_extra;
|
||||
bool is_fragile;
|
||||
bool needs_lex;
|
||||
t_stack_version last_reduction_version;
|
||||
t_stack_version reduction_version;
|
||||
t_state_id next_state;
|
||||
t_state_id state;
|
||||
t_subtree lookahead;
|
||||
t_subtree mutable_lookahead;
|
||||
t_u32 i;
|
||||
};
|
||||
|
||||
struct s_parser_parse_state
|
||||
{
|
||||
t_tree *result;
|
||||
t_u32 position;
|
||||
t_u32 last_position;
|
||||
t_u32 version_count;
|
||||
t_stack_version version;
|
||||
t_u32 min_error_cost;
|
||||
bool first;
|
||||
};
|
||||
|
||||
t_parser *ts_parser_new(t_language *language);
|
||||
t_tree *ts_parser_parse(t_parser *self, t_input input);
|
||||
t_tree *ts_parser_parse_string(t_parser *self, t_const_str string, t_u32 length);
|
||||
bool _parse_condition(t_parser *self, t_u32 *version_count, t_stack_version *version);
|
||||
bool ts_parser__advance(t_parser *self, t_stack_version version);
|
||||
bool ts_parser__better_version_exists(t_parser *self, t_stack_version version, bool is_in_error, t_u32 cost);
|
||||
bool ts_parser__breakdown_top_of_stack(t_parser *self, t_stack_version version);
|
||||
bool ts_parser__do_all_potential_reductions(t_parser *self, t_stack_version starting_version, t_symbol lookahead_symbol);
|
||||
bool ts_parser__external_scanner_scan(t_parser *self, t_state_id external_lex_state);
|
||||
bool ts_parser__recover_to_state(t_parser *self, t_stack_version version, t_u32 depth, t_state_id goal_state);
|
||||
bool ts_parser__select_children(t_parser *self, t_subtree left, const t_vec_subtree *children);
|
||||
bool ts_parser__select_tree(t_parser *self, t_subtree left, t_subtree right);
|
||||
bool ts_parser_has_outstanding_parse(t_parser *self);
|
||||
const t_u8 *ts_string_input_read(void *_self, t_u32 byte, t_point point, t_u32 *length);
|
||||
t_error_comparison ts_parser__compare_versions(t_parser *self, t_error_status a, t_error_status b);
|
||||
t_error_status ts_parser__version_status(t_parser *self, t_stack_version version);
|
||||
t_stack_version ts_parser__reduce(t_parser *self, t_stack_version version, t_symbol symbol, t_u32 count, int dynamic_precedence, t_u16 production_id, bool is_fragile, bool end_of_non_terminal_extra);
|
||||
t_subtree ts_parser__lex(t_parser *self, t_stack_version version, t_state_id parse_state);
|
||||
t_u32 ts_parser__condense_stack(t_parser *self);
|
||||
t_u32 ts_parser__external_scanner_serialize(t_parser *self);
|
||||
void ts_parser__accept(t_parser *self, t_stack_version version, t_subtree lookahead);
|
||||
void ts_parser__external_scanner_create(t_parser *self);
|
||||
void ts_parser__external_scanner_deserialize(t_parser *self, t_subtree external_token);
|
||||
void ts_parser__external_scanner_destroy(t_parser *self);
|
||||
void ts_parser__handle_error(t_parser *self, t_stack_version version, t_subtree lookahead);
|
||||
void ts_parser__recover(t_parser *self, t_stack_version version, t_subtree lookahead);
|
||||
void ts_parser__shift(t_parser *self, t_stack_version version, t_state_id state, t_subtree lookahead, bool extra);
|
||||
void ts_parser_delete(t_parser *self);
|
||||
void ts_parser_reset(t_parser *self);
|
||||
|
||||
#endif /* PARSER_INNER_H */
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* point_inner.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/02 20:05:43 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/19 16:38:38 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef POINT_INNER_H
|
||||
#define POINT_INNER_H
|
||||
|
||||
#include "me/types.h"
|
||||
|
||||
typedef struct s_point t_point;
|
||||
|
||||
struct s_point
|
||||
{
|
||||
t_u32 row;
|
||||
t_u32 column;
|
||||
};
|
||||
|
||||
t_point point__new(t_u32 row, t_u32 column);
|
||||
t_point point_add(t_point a, t_point b);
|
||||
t_point point_max(t_point a, t_point b);
|
||||
t_point point_min(t_point a, t_point b);
|
||||
t_point point_sub(t_point a, t_point b);
|
||||
bool point_eq(t_point a, t_point b);
|
||||
bool point_gt(t_point a, t_point b);
|
||||
bool point_gte(t_point a, t_point b);
|
||||
bool point_lt(t_point a, t_point b);
|
||||
bool point_lte(t_point a, t_point b);
|
||||
|
||||
|
||||
#endif /* POINT_INNER_H */
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ptypes.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/02 20:08:11 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/19 16:45:06 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef PTYPES_H
|
||||
#define PTYPES_H
|
||||
|
||||
#include "me/types.h"
|
||||
#include "parser/inner/length_inner.h"
|
||||
#include "parser/inner/point_inner.h"
|
||||
|
||||
typedef t_u16 t_state_id;
|
||||
typedef t_u16 t_symbol;
|
||||
typedef t_u16 t_field_id;
|
||||
typedef struct s_language t_language;
|
||||
typedef struct s_parser t_parser;
|
||||
typedef struct s_tree t_tree;
|
||||
|
||||
typedef enum e_symbol_type
|
||||
{
|
||||
t_symbol_typeRegular,
|
||||
t_symbol_typeAnonymous,
|
||||
t_symbol_typeAuxiliary,
|
||||
} t_symbol_type;
|
||||
|
||||
typedef struct s_srange
|
||||
{
|
||||
t_point start_point;
|
||||
t_point end_point;
|
||||
t_u32 start_byte;
|
||||
t_u32 end_byte;
|
||||
} t_range;
|
||||
|
||||
typedef struct s_input
|
||||
{
|
||||
void *payload;
|
||||
const t_u8 *(*read)(void *payload, t_u32 byte_index, t_point position, t_u32 *bytes_read);
|
||||
} t_input;
|
||||
|
||||
typedef struct s_node
|
||||
{
|
||||
t_u32 start_byte;
|
||||
t_u32 start_row;
|
||||
t_u32 start_col;
|
||||
t_u32 alias;
|
||||
const void *id;
|
||||
const t_tree *tree;
|
||||
} t_node;
|
||||
|
||||
#endif /* PTYPES_H */
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* reduce_action_inner.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/06 16:56:42 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/06 16:57:13 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef REDUCE_ACTION_INNER_H
|
||||
#define REDUCE_ACTION_INNER_H
|
||||
|
||||
#include "me/types.h"
|
||||
#include "parser/inner/ptypes.h"
|
||||
|
||||
struct s_reduce_action
|
||||
{
|
||||
t_u32 count;
|
||||
t_symbol symbol;
|
||||
int dynamic_precedence;
|
||||
t_u16 production_id;
|
||||
};
|
||||
typedef struct s_reduce_action t_reduce_action;
|
||||
|
||||
#endif /* REDUCE_ACTION_INNER_H */
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* scanner_inner.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/10 13:57:11 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/15 20:26:31 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef SCANNER_INNER_H
|
||||
#define SCANNER_INNER_H
|
||||
|
||||
#include "me/char/char.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/string/string.h"
|
||||
#include "me/types.h"
|
||||
#include "parser/lexer.h"
|
||||
#include "parser/parser.h"
|
||||
|
||||
typedef struct s_heredoc t_heredoc;
|
||||
typedef struct s_scanner t_scanner;
|
||||
|
||||
enum e_token_type
|
||||
{
|
||||
FILE_DESCRIPTOR,
|
||||
EMPTY_VALUE,
|
||||
CONCAT,
|
||||
VARIABLE_NAME,
|
||||
REGEX,
|
||||
EXPANSION_WORD,
|
||||
EXTGLOB_PATTERN,
|
||||
BARE_DOLLAR,
|
||||
IMMEDIATE_DOUBLE_HASH,
|
||||
NEWLINE,
|
||||
OPENING_PAREN,
|
||||
ERROR_RECOVERY,
|
||||
};
|
||||
|
||||
struct s_scanner
|
||||
{
|
||||
t_u8 last_glob_paren_depth;
|
||||
bool ext_was_in_double_quote;
|
||||
bool ext_saw_outside_quote;
|
||||
};
|
||||
|
||||
|
||||
#endif /* SCANNER_INNER_H */
|
||||
|
|
@ -1,193 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* stack_inner.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/31 16:37:50 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/19 18:23:03 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STACK_INNER_H
|
||||
#define STACK_INNER_H
|
||||
|
||||
#include "me/types.h"
|
||||
#include "parser/inner/length_inner.h"
|
||||
#include "parser/subtree.h"
|
||||
|
||||
#define MAX_LINK_COUNT 8
|
||||
#define MAX_NODE_POOL_SIZE 50
|
||||
#define MAX_ITERATOR_COUNT 64
|
||||
#define STACK_VERSION_NONE -1
|
||||
|
||||
typedef struct s_stack t_stack;
|
||||
typedef t_u32 t_stack_version;
|
||||
typedef struct s_stack_slice t_stack_slice;
|
||||
typedef struct s_stack_summary_entry t_stack_summary_entry;
|
||||
typedef Array(t_stack_slice) t_stack_slice_array;
|
||||
typedef Array(t_stack_summary_entry) t_stack_summary;
|
||||
|
||||
typedef enum e_stack_status t_stack_status;
|
||||
typedef struct s_stack_head t_stack_head;
|
||||
typedef struct s_stack_iterator t_stack_iterator;
|
||||
typedef struct s_stack_link t_stack_link;
|
||||
typedef struct s_stack_node t_stack_node;
|
||||
typedef struct s_summarize_stack_session t_summarize_stack_session;
|
||||
typedef t_u32 t_stack_action;
|
||||
|
||||
typedef t_stack_action (*t_stack_callback)(void *,
|
||||
const t_stack_iterator *);
|
||||
|
||||
struct s_stack_link
|
||||
{
|
||||
t_stack_node *node;
|
||||
t_subtree subtree;
|
||||
bool is_pending;
|
||||
};
|
||||
|
||||
struct s_stack_node
|
||||
{
|
||||
t_state_id state;
|
||||
t_length position;
|
||||
t_stack_link links[MAX_LINK_COUNT];
|
||||
t_u16 link_count;
|
||||
t_u32 ref_count;
|
||||
t_u32 error_cost;
|
||||
t_u32 node_count;
|
||||
int dynamic_precedence;
|
||||
};
|
||||
|
||||
struct s_stack_iterator
|
||||
{
|
||||
t_stack_node *node;
|
||||
t_vec_subtree subtrees;
|
||||
t_u32 subtree_count;
|
||||
bool is_pending;
|
||||
};
|
||||
|
||||
enum e_stack_status
|
||||
{
|
||||
SStatusActive,
|
||||
SStatusPaused,
|
||||
SStatusHalted,
|
||||
};
|
||||
|
||||
struct s_stack_head
|
||||
{
|
||||
t_stack_node *node;
|
||||
t_stack_summary *summary;
|
||||
t_u32 node_count_at_last_error;
|
||||
t_subtree last_external_token;
|
||||
t_subtree lookahead_when_paused;
|
||||
t_stack_status status;
|
||||
};
|
||||
|
||||
struct s_stack
|
||||
{
|
||||
Array(t_stack_head) heads;
|
||||
t_stack_slice_array slices;
|
||||
Array(t_stack_iterator) iterators;
|
||||
t_stack_node *base_node;
|
||||
};
|
||||
|
||||
enum e_stack_action
|
||||
{
|
||||
SActionNone,
|
||||
SActionStop = 1,
|
||||
SActionPop = 2,
|
||||
};
|
||||
|
||||
struct s_summarize_stack_session
|
||||
{
|
||||
t_stack_summary *summary;
|
||||
t_u32 max_depth;
|
||||
};
|
||||
|
||||
struct s_stack_slice
|
||||
{
|
||||
t_vec_subtree subtrees;
|
||||
t_stack_version version;
|
||||
};
|
||||
|
||||
struct s_stack_summary_entry
|
||||
{
|
||||
t_length position;
|
||||
t_u32 depth;
|
||||
t_state_id state;
|
||||
};
|
||||
|
||||
struct s_stack_push_arg
|
||||
{
|
||||
t_stack_version version;
|
||||
t_subtree subtree;
|
||||
bool pending;
|
||||
t_state_id state;
|
||||
};
|
||||
|
||||
struct s_stack_iter_args
|
||||
{
|
||||
t_stack_version version;
|
||||
t_stack_callback callback;
|
||||
void *payload;
|
||||
int goal_subtree_count;
|
||||
};
|
||||
|
||||
struct s_stack_iter_indexes
|
||||
{
|
||||
t_usize i;
|
||||
t_usize j;
|
||||
t_usize size;
|
||||
};
|
||||
|
||||
|
||||
t_length ts_stack_position(const t_stack *self, t_stack_version version);
|
||||
t_state_id ts_stack_state(const t_stack *self, t_stack_version version);
|
||||
bool stack__subtree_is_equivalent(t_subtree left, t_subtree right);
|
||||
bool ts_stack_can_merge(t_stack *self, t_stack_version version1, t_stack_version version2);
|
||||
bool ts_stack_has_advanced_since_error(const t_stack *self, t_stack_version version);
|
||||
bool ts_stack_is_active(const t_stack *self, t_stack_version version);
|
||||
bool ts_stack_is_halted(const t_stack *self, t_stack_version version);
|
||||
bool ts_stack_is_paused(const t_stack *self, t_stack_version version);
|
||||
bool ts_stack_merge(t_stack *self, t_stack_version version1, t_stack_version version2);
|
||||
int ts_stack_dynamic_precedence(t_stack *self, t_stack_version version);
|
||||
t_stack *ts_stack_new(void);
|
||||
t_stack_action pop_all_callback(void *payload, const t_stack_iterator *iterator);
|
||||
t_stack_action pop_count_callback(void *payload, const t_stack_iterator *iterator);
|
||||
t_stack_action pop_error_callback(void *payload, const t_stack_iterator *iterator);
|
||||
t_stack_action pop_pending_callback(void *payload, const t_stack_iterator *iterator);
|
||||
t_stack_action summarize_stack_callback(void *payload, const t_stack_iterator *iterator);
|
||||
t_stack_node *stack_node_new(t_stack_node *previous_node, t_subtree subtree, bool is_pending, t_state_id state);
|
||||
t_stack_slice_array stack__iter(t_stack *self, struct s_stack_iter_args args);
|
||||
t_stack_slice_array ts_stack_pop_all(t_stack *self, t_stack_version version);
|
||||
t_stack_slice_array ts_stack_pop_count(t_stack *self, t_stack_version version, t_u32 count);
|
||||
t_stack_slice_array ts_stack_pop_pending(t_stack *self, t_stack_version version);
|
||||
t_stack_summary *ts_stack_get_summary(t_stack *self, t_stack_version version);
|
||||
t_stack_version ts_stack__add_version(t_stack *self, t_stack_version original_version, t_stack_node *node);
|
||||
t_stack_version ts_stack_copy_version(t_stack *self, t_stack_version version);
|
||||
t_subtree ts_stack_last_external_token(const t_stack *self, t_stack_version version);
|
||||
t_subtree ts_stack_resume(t_stack *self, t_stack_version version);
|
||||
t_u32 stack__subtree_node_count(t_subtree subtree);
|
||||
t_u32 ts_stack_error_cost(const t_stack *self, t_stack_version version);
|
||||
t_u32 ts_stack_node_count_since_error(const t_stack *self, t_stack_version version);
|
||||
t_u32 ts_stack_version_count(const t_stack *self);
|
||||
t_vec_subtree ts_stack_pop_error(t_stack *self, t_stack_version version);
|
||||
void stack_head_delete(t_stack_head *self);
|
||||
void stack_node_add_link(t_stack_node *self, t_stack_link link);
|
||||
void stack_node_release(t_stack_node *self);
|
||||
void stack_node_retain(t_stack_node *self);
|
||||
void ts_stack__add_slice(t_stack *self, t_stack_version original_version, t_stack_node *node, t_vec_subtree *subtrees);
|
||||
void ts_stack_clear(t_stack *self);
|
||||
void ts_stack_delete(t_stack *self);
|
||||
void ts_stack_halt(t_stack *self, t_stack_version version);
|
||||
void ts_stack_pause(t_stack *self, t_stack_version version, t_subtree lookahead);
|
||||
void ts_stack_push(t_stack *self, struct s_stack_push_arg args);
|
||||
void ts_stack_record_summary(t_stack *self, t_stack_version version, t_u32 max_depth);
|
||||
void ts_stack_remove_version(t_stack *self, t_stack_version version);
|
||||
void ts_stack_renumber_version(t_stack *self, t_stack_version v1, t_stack_version v2);
|
||||
void ts_stack_set_last_external_token(t_stack *self, t_stack_version version, t_subtree token);
|
||||
void ts_stack_swap_versions(t_stack *self, t_stack_version v1, t_stack_version v2);
|
||||
|
||||
|
||||
#endif /* STACK_INNER_H */
|
||||
|
|
@ -1,117 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* subtree_inner.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/02 20:01:50 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/14 14:30:56 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef SUBTREE_INNER_H
|
||||
#define SUBTREE_INNER_H
|
||||
|
||||
#include "me/types.h"
|
||||
#include "parser/external_scanner_state.h"
|
||||
#include "parser/inner/length_inner.h"
|
||||
#include "parser/inner/ptypes.h"
|
||||
|
||||
// A heap-allocated representation of a subtree.
|
||||
//
|
||||
// This representation is used for parent nodes, external tokens,
|
||||
// errors, and other leaf nodes whose data is too large to fit into
|
||||
// the inline representation.
|
||||
typedef struct s_subtree_data t_subtree_data;
|
||||
|
||||
struct s_subtree_data
|
||||
{
|
||||
t_u32 ref_count;
|
||||
t_length padding;
|
||||
t_length size;
|
||||
t_u32 lookahead_bytes;
|
||||
t_u32 error_cost;
|
||||
t_u32 child_count;
|
||||
t_symbol symbol;
|
||||
t_state_id parse_state;
|
||||
|
||||
bool visible;
|
||||
bool named;
|
||||
bool extra;
|
||||
bool fragile_left;
|
||||
bool fragile_right;
|
||||
bool has_changes;
|
||||
bool has_external_tokens;
|
||||
bool has_external_scanner_state_change;
|
||||
bool depends_on_column;
|
||||
bool is_missing;
|
||||
bool is_keyword;
|
||||
|
||||
union {
|
||||
// Non-terminal subtrees (`child_count > 0`)
|
||||
struct
|
||||
{
|
||||
t_u32 visible_child_count;
|
||||
t_u32 named_child_count;
|
||||
t_u32 visible_descendant_count;
|
||||
t_i32 dynamic_precedence;
|
||||
t_u16 repeat_depth;
|
||||
t_u16 production_id;
|
||||
struct
|
||||
{
|
||||
t_symbol symbol;
|
||||
t_state_id parse_state;
|
||||
} first_leaf;
|
||||
};
|
||||
|
||||
// External terminal subtrees (`child_count == 0 && has_external_tokens`)
|
||||
t_external_scanner_state external_scanner_state;
|
||||
|
||||
// Error terminal subtrees (`child_count == 0 && symbol == ts_builtin_sym_error`)
|
||||
t_i32 lookahead_char;
|
||||
};
|
||||
};
|
||||
|
||||
// The fundamental building block of a syntax tree.
|
||||
typedef t_subtree_data *t_subtree;
|
||||
|
||||
typedef struct s_subtree_new_leaf_args t_st_newleaf_args;
|
||||
typedef struct s_subtree_new_error_args t_st_newerr_args;
|
||||
|
||||
struct s_subtree_new_leaf_args
|
||||
{
|
||||
t_symbol symbol;
|
||||
t_length padding;
|
||||
t_length size;
|
||||
t_u32 lookahead_bytes;
|
||||
t_state_id parse_state;
|
||||
bool has_external_tokens;
|
||||
bool depends_on_column;
|
||||
bool is_keyword;
|
||||
const t_language *language;
|
||||
};
|
||||
|
||||
struct s_subtree_new_error_args
|
||||
{
|
||||
t_i32 lookahead_char;
|
||||
t_length padding;
|
||||
t_length size;
|
||||
t_u32 bytes_scanned;
|
||||
t_state_id parse_state;
|
||||
const t_language *language;
|
||||
};
|
||||
|
||||
struct s_summarize_state
|
||||
{
|
||||
t_u32 structural_index;
|
||||
const t_symbol *alias_sequence;
|
||||
t_u32 lookahead_end_byte;
|
||||
t_subtree *children;
|
||||
t_subtree child;
|
||||
t_u32 child_lookahead_end_byte;
|
||||
t_u32 grandchild_count;
|
||||
t_usize i;
|
||||
};
|
||||
|
||||
#endif /* SUBTREE_INNER_H */
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* input.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/31 12:03:19 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/08/31 12:03:29 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef INPUT_H
|
||||
#define INPUT_H
|
||||
|
||||
#include "me/types.h"
|
||||
|
||||
#define TS_DECODE_ERROR -1i
|
||||
|
||||
typedef t_u32 (*UnicodeDecodeFunction)(const t_u8 *string, t_u32 length, t_i32 *code_point);
|
||||
|
||||
t_u32 ts_decode_ascii(const t_u8 *string, t_u32 length, t_i32 *code_point);
|
||||
|
||||
#endif // INPUT_H
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* language.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/31 12:03:18 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/19 16:54:21 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LANGUAGE_H
|
||||
#define LANGUAGE_H
|
||||
|
||||
#include "parser/parser.h"
|
||||
#include "me/types.h"
|
||||
|
||||
#define ts_builtin_sym_error_repeat (ts_builtin_sym_error - 1)
|
||||
|
||||
#define LANGUAGE_VERSION_WITH_PRIMARY_STATES 14
|
||||
#define LANGUAGE_VERSION_USABLE_VIA_WASM 13
|
||||
|
||||
struct s_table_entry
|
||||
{
|
||||
const TSParseAction *actions;
|
||||
t_u32 action_count;
|
||||
bool is_reusable;
|
||||
};
|
||||
|
||||
typedef struct s_table_entry TableEntry;
|
||||
|
||||
void ts_language_table_entry(const t_language *, t_state_id, t_symbol, TableEntry *);
|
||||
t_symbol_metadata ts_language_symbol_metadata(const t_language *, t_symbol);
|
||||
t_symbol ts_language_public_symbol(const t_language *, t_symbol);
|
||||
t_state_id ts_language_next_state(const t_language *self, t_state_id state, t_symbol symbol);
|
||||
bool ts_language_is_symbol_external(const t_language *self, t_symbol symbol);
|
||||
const TSParseAction *ts_language_actions(const t_language *self, t_state_id state, t_symbol symbol, t_u32 *count);
|
||||
bool ts_language_has_reduce_action(const t_language *self, t_state_id state, t_symbol symbol);
|
||||
t_u16 ts_language_lookup(const t_language *self, t_state_id state, t_symbol symbol);
|
||||
bool ts_language_has_actions(const t_language *self, t_state_id state, t_symbol symbol);
|
||||
const bool *ts_language_enabled_external_tokens(const t_language *self, t_u32 external_scanner_state);
|
||||
const t_symbol *ts_language_alias_sequence(const t_language *self, t_u32 production_id);
|
||||
t_symbol ts_language_alias_at(const t_language *self, t_u32 production_id, t_u32 child_index);
|
||||
void ts_language_field_map(const t_language *self, t_u32 production_id, const TSFieldMapEntry **start, const TSFieldMapEntry **end);
|
||||
void ts_language_aliases_for_symbol(const t_language *self, t_symbol original_symbol, const t_symbol **start, const t_symbol **end);
|
||||
|
||||
#endif // LANGUAGE_H
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* length.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/31 12:03:16 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/19 16:36:07 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LENGTH_H
|
||||
#define LENGTH_H
|
||||
|
||||
#include "parser/inner/length_inner.h"
|
||||
|
||||
static const t_length LENGTH_UNDEFINED = {0, {0, 1}};
|
||||
static const t_length LENGTH_MAX = {UINT32_MAX, {UINT32_MAX, UINT32_MAX}};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* lexer.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/31 12:03:15 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/19 16:52:25 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LEXER_H
|
||||
#define LEXER_H
|
||||
|
||||
#include "parser/api.h"
|
||||
#include "parser/length.h"
|
||||
#include "parser/parser.h"
|
||||
#include "me/types.h"
|
||||
|
||||
typedef struct s_lexer t_lexer;
|
||||
|
||||
struct s_lexer
|
||||
{
|
||||
struct s_lexer_functions funcs;
|
||||
t_length current_position;
|
||||
t_length token_start_position;
|
||||
t_length token_end_position;
|
||||
t_range *included_ranges;
|
||||
const t_u8 *chunk;
|
||||
t_input input;
|
||||
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;
|
||||
t_u8 debug_buffer[TREE_SITTER_SERIALIZATION_BUFFER_SIZE];
|
||||
};
|
||||
|
||||
|
||||
void ts_lexer_init(t_lexer *self);
|
||||
void ts_lexer_delete(t_lexer *self);
|
||||
void ts_lexer_set_input(t_lexer *self, t_input input);
|
||||
void ts_lexer_reset(t_lexer *self, t_length length);
|
||||
void ts_lexer_start(t_lexer *self);
|
||||
void ts_lexer_finish(t_lexer *self, t_u32 *lookahead);
|
||||
void ts_lexer_advance_to_end(t_lexer *self);
|
||||
void ts_lexer_mark_end(t_lexer *self);
|
||||
bool ts_lexer_set_included_ranges(t_lexer *self, const t_range *ranges, t_u32 count);
|
||||
t_range *ts_lexer_included_ranges(const t_lexer *self, t_u32 *count);
|
||||
|
||||
#endif // LEXER_H
|
||||
|
|
@ -1,278 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parser.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/31 12:03:13 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/19 16:57:51 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef PARSER_H
|
||||
#define PARSER_H
|
||||
|
||||
#include "me/types.h"
|
||||
|
||||
#define ts_builtin_sym_error ((t_symbol)-1)
|
||||
#define ts_builtin_sym_end 0
|
||||
#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
|
||||
|
||||
typedef t_u16 t_state_id;
|
||||
typedef t_u16 t_symbol;
|
||||
typedef t_u16 t_field_id;
|
||||
typedef struct s_language t_language;
|
||||
typedef struct s_lexer t_lexer;
|
||||
|
||||
typedef struct s_field_map_entry
|
||||
{
|
||||
t_field_id field_id;
|
||||
t_u8 child_index;
|
||||
bool inherited;
|
||||
} TSFieldMapEntry;
|
||||
|
||||
typedef struct s_field_map_slice
|
||||
{
|
||||
t_u16 index;
|
||||
t_u16 length;
|
||||
} TSFieldMapSlice;
|
||||
|
||||
typedef struct s_symbol_metadata
|
||||
{
|
||||
bool visible;
|
||||
bool named;
|
||||
bool supertype;
|
||||
} t_symbol_metadata;
|
||||
|
||||
struct s_lexer_functions
|
||||
{
|
||||
t_i32 lookahead;
|
||||
t_symbol result_symbol;
|
||||
void (*advance)(t_lexer *, bool);
|
||||
void (*mark_end)(t_lexer *);
|
||||
t_u32 (*get_column)(t_lexer *);
|
||||
bool (*eof)(const t_lexer *);
|
||||
};
|
||||
|
||||
typedef enum e_parse_action_type
|
||||
{
|
||||
TSParseActionTypeShift,
|
||||
TSParseActionTypeReduce,
|
||||
TSParseActionTypeAccept,
|
||||
TSParseActionTypeRecover,
|
||||
} TSParseActionType;
|
||||
|
||||
typedef union u_parse_action {
|
||||
struct s_parse_action_shift
|
||||
{
|
||||
t_u8 type;
|
||||
t_state_id state;
|
||||
bool extra;
|
||||
bool repetition;
|
||||
} shift;
|
||||
struct s_parse_action_reduce
|
||||
{
|
||||
t_u8 type;
|
||||
t_u8 child_count;
|
||||
t_symbol symbol;
|
||||
t_i16 dynamic_precedence;
|
||||
t_u16 production_id;
|
||||
} reduce;
|
||||
t_u8 type;
|
||||
} TSParseAction;
|
||||
|
||||
typedef struct s_lex_mode
|
||||
{
|
||||
t_u16 lex_state;
|
||||
t_u16 external_lex_state;
|
||||
} TSLexMode;
|
||||
|
||||
typedef union u_parse_action_entry {
|
||||
TSParseAction action;
|
||||
struct s_parse_action_entry_inner
|
||||
{
|
||||
t_u8 count;
|
||||
bool reusable;
|
||||
} entry;
|
||||
} TSParseActionEntry;
|
||||
|
||||
typedef struct s_character_range
|
||||
{
|
||||
t_i32 start;
|
||||
t_i32 end;
|
||||
} TSCharacterRange;
|
||||
|
||||
struct s_language
|
||||
{
|
||||
t_u32 version;
|
||||
t_u32 symbol_count;
|
||||
t_u32 alias_count;
|
||||
t_u32 token_count;
|
||||
t_u32 external_token_count;
|
||||
t_u32 state_count;
|
||||
t_u32 large_state_count;
|
||||
t_u32 production_id_count;
|
||||
t_u32 field_count;
|
||||
t_u16 max_alias_sequence_length;
|
||||
const t_u16 *parse_table;
|
||||
const t_u16 *small_parse_table;
|
||||
const t_u32 *small_parse_table_map;
|
||||
const TSParseActionEntry *parse_actions;
|
||||
t_const_str const *symbol_names;
|
||||
t_const_str const *field_names;
|
||||
const TSFieldMapSlice *field_map_slices;
|
||||
const TSFieldMapEntry *field_map_entries;
|
||||
const t_symbol_metadata *symbol_metadata;
|
||||
const t_symbol *public_symbol_map;
|
||||
const t_u16 *alias_map;
|
||||
const t_symbol *alias_sequences;
|
||||
const TSLexMode *lex_modes;
|
||||
bool (*lex_fn)(t_lexer *, t_state_id);
|
||||
bool (*keyword_lex_fn)(t_lexer *, t_state_id);
|
||||
t_symbol keyword_capture_token;
|
||||
struct ExternalScannerDefinition
|
||||
{
|
||||
const bool *states;
|
||||
const t_symbol *symbol_map;
|
||||
void *(*create)(void);
|
||||
void (*destroy)(void *);
|
||||
bool (*scan)(void *, t_lexer *, const bool *symbol_whitelist);
|
||||
t_u32 (*serialize)(void *, t_u8 *);
|
||||
void (*deserialize)(void *, const t_u8 *, t_u32);
|
||||
} external_scanner;
|
||||
const t_state_id *primary_state_ids;
|
||||
};
|
||||
|
||||
static inline bool set_contains(TSCharacterRange *ranges, t_u32 len, t_i32 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;
|
||||
TSCharacterRange *range = &ranges[mid_index];
|
||||
if (lookahead >= range->start && lookahead <= range->end)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (lookahead > range->end)
|
||||
{
|
||||
index = mid_index;
|
||||
}
|
||||
size -= half_size;
|
||||
}
|
||||
TSCharacterRange *range = &ranges[index];
|
||||
return (lookahead >= range->start && lookahead <= range->end);
|
||||
}
|
||||
|
||||
/*
|
||||
* Lexer Macros
|
||||
*/
|
||||
|
||||
#define UNUSED __attribute__((unused))
|
||||
|
||||
#define START_LEXER() \
|
||||
bool result = false; \
|
||||
bool skip = false; \
|
||||
UNUSED \
|
||||
bool eof = false; \
|
||||
t_i32 lookahead; \
|
||||
goto start; \
|
||||
next_state: \
|
||||
lexer->funcs.advance((void *)lexer, skip); \
|
||||
start: \
|
||||
skip = false; \
|
||||
lookahead = lexer->funcs.lookahead;
|
||||
|
||||
#define ADVANCE(state_value) \
|
||||
{ \
|
||||
state = state_value; \
|
||||
goto next_state; \
|
||||
}
|
||||
|
||||
#define ADVANCE_MAP(...) \
|
||||
{ \
|
||||
static const t_u16 map[] = {__VA_ARGS__}; \
|
||||
for (t_u32 i = 0; i < sizeof(map) / sizeof(map[0]); i += 2) \
|
||||
{ \
|
||||
if (map[i] == lookahead) \
|
||||
{ \
|
||||
state = map[i + 1]; \
|
||||
goto next_state; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
#define SKIP(state_value) \
|
||||
{ \
|
||||
skip = true; \
|
||||
state = state_value; \
|
||||
goto next_state; \
|
||||
}
|
||||
|
||||
#define ACCEPT_TOKEN(symbol_value) \
|
||||
result = true; \
|
||||
lexer->funcs.result_symbol = symbol_value; \
|
||||
lexer->funcs.mark_end((void *)lexer);
|
||||
|
||||
#define END_STATE() return result;
|
||||
|
||||
/*
|
||||
* Parse Table Macros
|
||||
*/
|
||||
|
||||
#define SMALL_STATE(id) ((id)-LARGE_STATE_COUNT)
|
||||
|
||||
#define STATE(id) id
|
||||
|
||||
#define ACTIONS(id) id
|
||||
|
||||
#define SHIFT(state_value) \
|
||||
{ \
|
||||
{ \
|
||||
.shift = {.type = TSParseActionTypeShift, .state = (state_value) } \
|
||||
} \
|
||||
}
|
||||
|
||||
#define SHIFT_REPEAT(state_value) \
|
||||
{ \
|
||||
{ \
|
||||
.shift = {.type = TSParseActionTypeShift, .state = (state_value), .repetition = true } \
|
||||
} \
|
||||
}
|
||||
|
||||
#define SHIFT_EXTRA() \
|
||||
{ \
|
||||
{ \
|
||||
.shift = {.type = TSParseActionTypeShift, .extra = true } \
|
||||
} \
|
||||
}
|
||||
|
||||
#define REDUCE(symbol_name, children, precedence, prod_id) \
|
||||
{ \
|
||||
{ \
|
||||
.reduce = {.type = TSParseActionTypeReduce, \
|
||||
.symbol = symbol_name, \
|
||||
.child_count = children, \
|
||||
.dynamic_precedence = precedence, \
|
||||
.production_id = prod_id}, \
|
||||
} \
|
||||
}
|
||||
|
||||
#define RECOVER() \
|
||||
{ \
|
||||
{ \
|
||||
.type = TSParseActionTypeRecover \
|
||||
} \
|
||||
}
|
||||
|
||||
#define ACCEPT_INPUT() \
|
||||
{ \
|
||||
{ \
|
||||
.type = TSParseActionTypeAccept \
|
||||
} \
|
||||
}
|
||||
|
||||
#endif // PARSER_H
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* point.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/31 12:03:10 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/08/31 12:03:29 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef POINT_H
|
||||
#define POINT_H
|
||||
|
||||
#include "parser/api.h"
|
||||
#include "me/types.h"
|
||||
|
||||
#define POINT_ZERO ((t_point){0, 0})
|
||||
#define POINT_MAX ((t_point){UINT32_MAX, UINT32_MAX})
|
||||
|
||||
t_point point_max(t_point a, t_point b);
|
||||
t_point point_min(t_point a, t_point b);
|
||||
t_point point__new(t_u32 row, t_u32 column);
|
||||
t_point point_add(t_point a, t_point b);
|
||||
t_point point_sub(t_point a, t_point b);
|
||||
bool point_lte(t_point a, t_point b);
|
||||
bool point_lt(t_point a, t_point b);
|
||||
bool point_gte(t_point a, t_point b);
|
||||
bool point_gt(t_point a, t_point b);
|
||||
bool point_eq(t_point a, t_point b);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* reduce_action.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/31 12:03:09 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/06 17:08:38 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef REDUCE_ACTION_H
|
||||
#define REDUCE_ACTION_H
|
||||
|
||||
#include "me/types.h"
|
||||
#include "parser/api.h"
|
||||
#include "parser/array.h"
|
||||
#include "parser/inner/reduce_action_inner.h"
|
||||
#include "me/vec/vec_reduce_action.h"
|
||||
|
||||
typedef t_vec_reduce_action t_vec_reduce_action;
|
||||
|
||||
void ts_reduce_action_set_add(t_vec_reduce_action *self, t_reduce_action new_action);
|
||||
|
||||
#endif // REDUCE_ACTION_H
|
||||
|
|
@ -1,216 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* subtree.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/31 12:03:06 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/19 16:37:37 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef SUBTREE_H
|
||||
#define SUBTREE_H
|
||||
|
||||
#include "me/types.h"
|
||||
#include "parser/api.h"
|
||||
#include "parser/array.h"
|
||||
#include "parser/external_scanner_state.h"
|
||||
#include "parser/length.h"
|
||||
#include "parser/parser.h"
|
||||
#include <limits.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define TS_TREE_STATE_NONE USHRT_MAX
|
||||
#define NULL_SUBTREE ((t_subtree)NULL)
|
||||
|
||||
#include "me/vec/vec_subtree.h"
|
||||
#include "parser/inner/subtree_inner.h"
|
||||
|
||||
typedef t_vec_subtree t_vec_subtree;
|
||||
|
||||
bool _subtree_compress_inner(t_subtree *tree, t_symbol symbol, t_vec_subtree *stack);
|
||||
int subtree_compare_func(t_subtree left, t_subtree right);
|
||||
int ts_subtree_compare(t_subtree left, t_subtree right);
|
||||
struct s_summarize_state _init_sumnarize_state(t_subtree self, const t_language *language);
|
||||
t_subtree ts_subtree_clone(t_subtree self);
|
||||
t_subtree ts_subtree_ensure_owner(t_subtree self);
|
||||
t_subtree ts_subtree_last_external_token(t_subtree tree);
|
||||
t_subtree ts_subtree_new_error(t_st_newerr_args args);
|
||||
t_subtree ts_subtree_new_error_node(t_vec_subtree *children, bool extra, const t_language *language);
|
||||
t_subtree ts_subtree_new_leaf(t_st_newleaf_args args);
|
||||
t_subtree ts_subtree_new_missing_leaf(t_symbol symbol, t_length padding, t_u32 lookahead_bytes, const t_language *language);
|
||||
t_subtree ts_subtree_new_node(t_symbol symbol, t_vec_subtree *children, t_u32 production_id, const t_language *language);
|
||||
void _subtree_balance_inner(const t_language *language, t_vec_subtree *tree_stack);
|
||||
void _subtree_balance_repush(t_vec_subtree *tree_stack, t_subtree tree);
|
||||
void _subtree_release_inner(t_vec_subtree *to_free);
|
||||
void _sumarize_end(t_subtree self, t_subtree *children);
|
||||
void _summarize_loop_inner1(t_subtree self, const t_language *language, struct s_summarize_state *s);
|
||||
void _summarize_loop_inner2(t_subtree self, const t_language *language, struct s_summarize_state *s);
|
||||
void _summarize_loop_inner3(t_subtree self, const t_language *language, struct s_summarize_state *s);
|
||||
void _summarize_loop_inner4(t_subtree self, const t_language *language, struct s_summarize_state *s);
|
||||
void ts_subtree__compress(t_subtree self, t_u32 count, const t_language *language, t_vec_subtree *stack);
|
||||
void ts_subtree_array_clear(t_vec_subtree *self);
|
||||
void ts_subtree_array_copy(t_vec_subtree self, t_vec_subtree *dest);
|
||||
void ts_subtree_array_delete(t_vec_subtree *self);
|
||||
void ts_subtree_array_remove_trailing_extras(t_vec_subtree *self, t_vec_subtree *destination);
|
||||
void ts_subtree_balance(t_subtree self, const t_language *language);
|
||||
void ts_subtree_release(t_subtree self);
|
||||
void ts_subtree_set_symbol(t_subtree *self, t_symbol symbol, const t_language *language);
|
||||
void ts_subtree_summarize_children(t_subtree self, const t_language *language);
|
||||
|
||||
static inline t_symbol ts_subtree_symbol(t_subtree self)
|
||||
{
|
||||
return ((self)->symbol);
|
||||
}
|
||||
static inline bool ts_subtree_visible(t_subtree self)
|
||||
{
|
||||
return ((self)->visible);
|
||||
}
|
||||
static inline bool ts_subtree_named(t_subtree self)
|
||||
{
|
||||
return ((self)->named);
|
||||
}
|
||||
static inline bool ts_subtree_extra(t_subtree self)
|
||||
{
|
||||
return ((self)->extra);
|
||||
}
|
||||
static inline bool ts_subtree_has_changes(t_subtree self)
|
||||
{
|
||||
return ((self)->has_changes);
|
||||
}
|
||||
static inline bool ts_subtree_missing(t_subtree self)
|
||||
{
|
||||
return ((self)->is_missing);
|
||||
}
|
||||
static inline bool ts_subtree_is_keyword(t_subtree self)
|
||||
{
|
||||
return ((self)->is_keyword);
|
||||
}
|
||||
static inline t_state_id ts_subtree_parse_state(t_subtree self)
|
||||
{
|
||||
return ((self)->parse_state);
|
||||
}
|
||||
static inline t_u32 ts_subtree_lookahead_bytes(t_subtree self)
|
||||
{
|
||||
return ((self)->lookahead_bytes);
|
||||
}
|
||||
|
||||
// Get the size needed to store a heap-allocated subtree with the given
|
||||
// number of children.
|
||||
static inline size_t ts_subtree_alloc_size(t_u32 child_count)
|
||||
{
|
||||
return child_count * sizeof(t_subtree) + sizeof(t_subtree_data);
|
||||
}
|
||||
|
||||
// Get a subtree's children, which are allocated immediately before the
|
||||
// tree's own heap data.
|
||||
static inline t_subtree *ts_subtree_children(t_subtree self)
|
||||
{
|
||||
return ((t_subtree *)((self)) - (self)->child_count);
|
||||
}
|
||||
|
||||
static inline void ts_subtree_set_extra(t_subtree *self, bool is_extra)
|
||||
{
|
||||
(*self)->extra = is_extra;
|
||||
}
|
||||
|
||||
static inline t_symbol ts_subtree_leaf_symbol(t_subtree self)
|
||||
{
|
||||
if (self->child_count == 0)
|
||||
return self->symbol;
|
||||
return self->first_leaf.symbol;
|
||||
}
|
||||
|
||||
static inline t_state_id ts_subtree_leaf_parse_state(t_subtree self)
|
||||
{
|
||||
if (self->child_count == 0)
|
||||
return self->parse_state;
|
||||
return self->first_leaf.parse_state;
|
||||
}
|
||||
|
||||
static inline t_length ts_subtree_padding(t_subtree self)
|
||||
{
|
||||
return self->padding;
|
||||
}
|
||||
|
||||
static inline t_length ts_subtree_size(t_subtree self)
|
||||
{
|
||||
return self->size;
|
||||
}
|
||||
|
||||
static inline t_length ts_subtree_total_size(t_subtree self)
|
||||
{
|
||||
return (length_add(ts_subtree_padding(self), ts_subtree_size(self)));
|
||||
}
|
||||
|
||||
static inline t_u32 ts_subtree_total_bytes(t_subtree self)
|
||||
{
|
||||
return (ts_subtree_total_size(self).bytes);
|
||||
}
|
||||
|
||||
static inline t_u32 ts_subtree_child_count(t_subtree self)
|
||||
{
|
||||
return (self->child_count);
|
||||
}
|
||||
|
||||
static inline t_u32 ts_subtree_repeat_depth(t_subtree self)
|
||||
{
|
||||
return (self->repeat_depth);
|
||||
}
|
||||
|
||||
static inline t_u32 ts_subtree_visible_descendant_count(t_subtree self)
|
||||
{
|
||||
return ((self->child_count == 0) ? 0 : self->visible_descendant_count);
|
||||
}
|
||||
|
||||
static inline t_u32 ts_subtree_error_cost(t_subtree self)
|
||||
{
|
||||
if (ts_subtree_missing(self))
|
||||
return (ERROR_COST_PER_MISSING_TREE + ERROR_COST_PER_RECOVERY);
|
||||
else
|
||||
return (self->error_cost);
|
||||
}
|
||||
|
||||
static inline t_i32 ts_subtree_dynamic_precedence(t_subtree self)
|
||||
{
|
||||
return ((self->child_count == 0) ? 0 : self->dynamic_precedence);
|
||||
}
|
||||
|
||||
static inline bool ts_subtree_fragile_left(t_subtree self)
|
||||
{
|
||||
return (self->fragile_left);
|
||||
}
|
||||
|
||||
static inline bool ts_subtree_fragile_right(t_subtree self)
|
||||
{
|
||||
return (self->fragile_right);
|
||||
}
|
||||
|
||||
static inline bool ts_subtree_has_external_tokens(t_subtree self)
|
||||
{
|
||||
return (self->has_external_tokens);
|
||||
}
|
||||
|
||||
static inline bool ts_subtree_has_external_scanner_state_change(t_subtree self)
|
||||
{
|
||||
return (self->has_external_scanner_state_change);
|
||||
}
|
||||
|
||||
static inline bool ts_subtree_depends_on_column(t_subtree self)
|
||||
{
|
||||
return (self->depends_on_column);
|
||||
}
|
||||
|
||||
static inline bool ts_subtree_is_error(t_subtree self)
|
||||
{
|
||||
return (ts_subtree_symbol(self) == ts_builtin_sym_error);
|
||||
}
|
||||
|
||||
static inline bool ts_subtree_is_eof(t_subtree self)
|
||||
{
|
||||
return (ts_subtree_symbol(self) == ts_builtin_sym_end);
|
||||
}
|
||||
#endif // SUBTREE_H
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tree.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/31 12:03:04 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/02 20:18:46 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef TREE_H
|
||||
#define TREE_H
|
||||
|
||||
#include "me/types.h"
|
||||
#include "parser/subtree.h"
|
||||
|
||||
struct s_tree
|
||||
{
|
||||
t_subtree root;
|
||||
const t_language *language;
|
||||
};
|
||||
|
||||
t_tree *ts_tree_new(t_subtree root, const t_language *language);
|
||||
t_node ts_node_new(const t_tree *, const t_subtree *, t_length, t_symbol);
|
||||
|
||||
#endif // TREE_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue