Upodated stuff
This commit is contained in:
parent
a8b09ab55a
commit
8be7417a61
43 changed files with 812 additions and 94973 deletions
1
.clangd
1
.clangd
|
|
@ -22,6 +22,7 @@ CompileFlags: # Tweak the parse settings
|
|||
- "-I/home/nixos/shcat/stdme/output/include/"
|
||||
- "-I/home/nixos/shcat/stdme/generic_sources/header/"
|
||||
- "-I/home/nixos/shcat/includes/"
|
||||
- "-I/home/nixos/shcat/parser/include"
|
||||
- "-I/home/nixos/shcat/output/include/"
|
||||
- "-I/home/nixos/shcat/generic_sources/header/"
|
||||
- "-I/home/nixos/shcat/exec/src/arith/"
|
||||
|
|
|
|||
105
.dumper.c.
105
.dumper.c.
|
|
@ -1,105 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* dumper.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/25 22:19:52 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/06/30 17:09:31 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "gmr/constants.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "types/type_alias_sequences.h"
|
||||
#include "types/type_external_scanner_states.h"
|
||||
#include "types/type_external_scanner_symbol_map.h"
|
||||
#include "types/type_field_map_entries.h"
|
||||
#include "types/type_field_map_slices.h"
|
||||
#include "types/type_field_names.h"
|
||||
#include "types/type_lex_modes.h"
|
||||
#include "types/type_lex_normal.h"
|
||||
#include "types/type_non_terminal_alias_map.h"
|
||||
#include "types/type_parse_actions_entries.h"
|
||||
#include "types/type_parse_table.h"
|
||||
#include "types/type_primary_state_ids.h"
|
||||
#include "types/type_small_parse_table.h"
|
||||
#include "types/type_small_parse_table_map.h"
|
||||
#include "types/type_symbols_metadata.h"
|
||||
#include "types/type_symbols_names.h"
|
||||
#include "types/type_unique_symbols_map.h"
|
||||
|
||||
t_parse_table_array *create_parse_table(void);
|
||||
t_small_parse_table_array *create_small_parse_table(void);
|
||||
t_small_parse_table_map_array *create_small_parse_table_map(void);
|
||||
t_parse_actions_entries_array *create_parse_actions_entries(void);
|
||||
t_symbols_names_array *create_symbols_names(void);
|
||||
t_field_names_array *create_field_names(void);
|
||||
t_field_map_slices_array *create_field_map_slices(void);
|
||||
t_field_map_entries_array *create_field_map_entries(void);
|
||||
t_symbols_metadata_array *create_symbols_metadata(void);
|
||||
t_unique_symbols_map_array *create_unique_symbols_map(void);
|
||||
t_non_terminal_alias_map_array *create_non_terminal_alias_map(void);
|
||||
t_alias_sequences_array *create_alias_sequences(void);
|
||||
t_lex_modes_array *create_lex_modes(void);
|
||||
t_primary_state_ids_array *create_primary_state_ids(void);
|
||||
t_external_scanner_states_array *create_external_scanner_states(void);
|
||||
t_external_scanner_symbol_map_array *create_external_scanner_symbol_map(void);
|
||||
|
||||
void dump_to_file(const char *filename, void *data, size_t size)
|
||||
{
|
||||
int file = open(filename, O_CREAT | O_RDWR | O_TRUNC, 0666);
|
||||
|
||||
if (file < 0)
|
||||
return ((void)printf("[error] opening %s failed \n", filename));
|
||||
if (write(file, data, size) < size)
|
||||
printf("[error] writing to %s failed \n", filename);
|
||||
else
|
||||
printf("wrote %zu to %s!\n", size, filename);
|
||||
close(file);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
dump_to_file("./parse_table", (void *)create_parse_table(),
|
||||
sizeof(*create_parse_table()));
|
||||
dump_to_file("./small_parse_table", (void *)create_small_parse_table(),
|
||||
sizeof(*create_small_parse_table()));
|
||||
dump_to_file("./small_parse_table_map",
|
||||
(void *)create_small_parse_table_map(),
|
||||
sizeof(*create_small_parse_table_map()));
|
||||
dump_to_file("./parse_actions_entries",
|
||||
(void *)create_parse_actions_entries(),
|
||||
sizeof(*create_parse_actions_entries()));
|
||||
// dump_to_file("./symbols_names", (void *)create_symbols_names(), 0);
|
||||
// dump_to_file("./field_names", (void *)create_field_names(), 0);
|
||||
dump_to_file("./field_map_slices", (void *)create_field_map_slices(),
|
||||
sizeof(*create_field_map_slices()));
|
||||
dump_to_file("./field_map_entries", (void *)create_field_map_entries(),
|
||||
sizeof(*create_field_map_entries()));
|
||||
dump_to_file("./symbols_metadata", (void *)create_symbols_metadata(),
|
||||
sizeof(*create_symbols_metadata()));
|
||||
dump_to_file("./unique_symbols_map", (void *)create_unique_symbols_map(),
|
||||
sizeof(*create_unique_symbols_map()));
|
||||
dump_to_file("./non_terminal_alias_map",
|
||||
(void *)create_non_terminal_alias_map(),
|
||||
sizeof(*create_non_terminal_alias_map()));
|
||||
dump_to_file("./alias_sequences", (void *)create_alias_sequences(),
|
||||
sizeof(*create_alias_sequences()));
|
||||
dump_to_file("./lex_modes", (void *)create_lex_modes(),
|
||||
sizeof(*create_lex_modes()));
|
||||
dump_to_file("./primary_state_ids", (void *)create_primary_state_ids(),
|
||||
sizeof(*create_primary_state_ids()));
|
||||
dump_to_file("./external_scanner_states",
|
||||
(void *)create_external_scanner_states(),
|
||||
sizeof(*create_external_scanner_states()));
|
||||
dump_to_file("./external_scanner_symbol_map",
|
||||
(void *)create_external_scanner_symbol_map(),
|
||||
sizeof(*create_external_scanner_symbol_map()));
|
||||
}
|
||||
94726
.parser.c.
94726
.parser.c.
File diff suppressed because it is too large
Load diff
|
|
@ -14,13 +14,21 @@ src/hashmap/env/env_utils \
|
|||
src/vec/ast/ast \
|
||||
src/vec/ast/ast_functions2 \
|
||||
src/vec/ast/ast_functions3 \
|
||||
src/vec/ast/ast_sort \
|
||||
src/vec/estr/estr \
|
||||
src/vec/estr/estr_functions2 \
|
||||
src/vec/estr/estr_functions3 \
|
||||
src/vec/estr/estr_sort \
|
||||
src/vec/heredoc/heredoc \
|
||||
src/vec/heredoc/heredoc_functions2 \
|
||||
src/vec/heredoc/heredoc_functions3 \
|
||||
src/vec/heredoc/heredoc_sort \
|
||||
src/vec/pid/pid \
|
||||
src/vec/pid/pid_functions2 \
|
||||
src/vec/pid/pid_functions3 \
|
||||
src/vec/pid/pid_sort \
|
||||
src/vec/str/str \
|
||||
src/vec/str/str_functions2 \
|
||||
src/vec/str/str_functions3 \
|
||||
src/vec/str/str_sort \
|
||||
|
||||
|
|
|
|||
|
|
@ -81,3 +81,11 @@ replace.C__TYPENAME__ = "t_pid"
|
|||
replace.C__TYPEHEADER__ = '#include "me/os/os.h"'
|
||||
replace.C__PREFIX__ = "pid"
|
||||
replace.C__PREFIXUP__ = "PID"
|
||||
|
||||
[[create.vec]]
|
||||
sources_output = "src/vec/C__PREFIX__/"
|
||||
headers_output = "include/me/vec/"
|
||||
replace.C__TYPENAME__ = "t_heredoc"
|
||||
replace.C__TYPEHEADER__ = '#include "parser/inner/heredoc.h"'
|
||||
replace.C__PREFIX__ = "heredoc"
|
||||
replace.C__PREFIXUP__ = "HEREDOC"
|
||||
|
|
|
|||
123
output/include/me/vec/vec_heredoc.h
Normal file
123
output/include/me/vec/vec_heredoc.h
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* vec_heredoc.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/04 18:46:53 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 17:53:00 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef VEC_HEREDOC_H
|
||||
#define VEC_HEREDOC_H
|
||||
|
||||
#include "parser/inner/heredoc.h"
|
||||
#include "me/types.h"
|
||||
|
||||
/// @brief A function that takes two t_heredoc and compare them
|
||||
typedef bool (*t_vec_heredoc_sort_fn)(t_heredoc *, t_heredoc *);
|
||||
/// @brief A function that free an t_heredoc
|
||||
typedef void (*t_free_heredoc_item)(t_heredoc);
|
||||
|
||||
/// @brief A dynamic array of t_heredoc
|
||||
typedef struct s_vec_heredoc
|
||||
{
|
||||
t_free_heredoc_item free_func;
|
||||
t_usize len;
|
||||
t_usize capacity;
|
||||
t_heredoc *buffer;
|
||||
} t_vec_heredoc;
|
||||
|
||||
/// @brief Create a new vec_heredoc with a given capacity
|
||||
/// @param capacity The capacity of the new vec_heredoc (in terms of elements)
|
||||
/// @param free_function The function that will be used to free the elements of the vec_heredoc
|
||||
t_vec_heredoc vec_heredoc_new(t_usize capacity, t_free_heredoc_item free_function);
|
||||
/// @brief Push an element to the last position of the vec_heredoc
|
||||
/// @param vec The vec_heredoc to push the element to
|
||||
/// @param element The element to push
|
||||
t_error vec_heredoc_push(t_vec_heredoc *vec, t_heredoc element);
|
||||
|
||||
/// @brief Push an element to the first position of the vec_heredoc
|
||||
/// @param vec The vec_heredoc to push the element to
|
||||
/// @param element The element to push
|
||||
/// @note This operation is O(n)
|
||||
t_error vec_heredoc_push_front(t_vec_heredoc *vec, t_heredoc element);
|
||||
|
||||
/// @brief Get the last element from the vec_heredoc, and remove it from the vec_heredoc
|
||||
/// @param vec The vec_heredoc to get the element from
|
||||
/// @param[out] out The last element of the vec_heredoc
|
||||
/// @return true if the operation failed, false otherwise
|
||||
t_error vec_heredoc_pop(t_vec_heredoc *vec, t_heredoc *value);
|
||||
|
||||
|
||||
/// @brief Get the first element from the vec_heredoc, and remove it from the vec_heredoc
|
||||
/// @param vec The vec_heredoc to get the element from
|
||||
/// @param[out] out The first element of the vec_heredoc
|
||||
/// @return true if the operation failed, false otherwise
|
||||
/// @note This operation is O(n)
|
||||
t_error vec_heredoc_pop_front(t_vec_heredoc *vec, t_heredoc *value);
|
||||
|
||||
/// @brief Free the vector and all its elements
|
||||
/// @param vec The vec_heredoc to free
|
||||
void vec_heredoc_free(t_vec_heredoc vec);
|
||||
|
||||
/// @brief Make the vec_heredoc at least the given capacity
|
||||
/// @param vec The vec_heredoc to reserve
|
||||
/// @param wanted_capacity The minimum capacity to reserve
|
||||
/// @return true if the operation failed, false otherwise
|
||||
t_error vec_heredoc_reserve(t_vec_heredoc *vec, t_usize wanted_capacity);
|
||||
|
||||
/// @brief Run the function and returns the index of the first element that returns true
|
||||
/// @param vec The vec_heredoc to search in
|
||||
/// @param fn The function to run on each element
|
||||
/// @param[out] index The index of the first element that returns true
|
||||
t_error vec_heredoc_find(t_vec_heredoc *vec, bool (*fn)(const t_heredoc *), t_usize *index);
|
||||
|
||||
|
||||
/// @brief Run the function and returns the index of the first element that returns true, but starting at index starting_index
|
||||
/// @param vec The vec_heredoc to search in
|
||||
/// @param fn The function to run on each element
|
||||
/// @param starting_index The index to start the search from
|
||||
/// @param[out] index The index of the first element that returns true
|
||||
t_error vec_heredoc_find_starting(t_vec_heredoc *vec, bool (*fn)(const t_heredoc *), t_usize starting_index, t_usize *index);
|
||||
|
||||
/// @brief Run the function on every element of the vec_heredoc and returns if all elements returned true
|
||||
/// @param vec The vec_heredoc to search in
|
||||
/// @param fn The function to run on each element
|
||||
/// @param[out] result The result of the operation
|
||||
/// @return true if the operation failed, false otherwise
|
||||
/// @note If the vec_heredoc is empty, result will be true
|
||||
t_error vec_heredoc_all(t_vec_heredoc *vec, bool (*fn)(const t_heredoc *), bool *result);
|
||||
|
||||
/// @brief Run the function on every element of the vec_heredoc and returns if any element returned true
|
||||
/// @param vec The vec_heredoc to search in
|
||||
/// @param fn The function to run on each element
|
||||
/// @param[out] result The result of the operation
|
||||
/// @return true if the operation failed, false otherwise
|
||||
/// @note If the vec_heredoc is empty, result will be false
|
||||
t_error vec_heredoc_any(t_vec_heredoc *vec, bool (*fn)(const t_heredoc *), bool *result);
|
||||
|
||||
/// @brief Run the function on every element of the vec_heredoc
|
||||
/// @param vec The vec_heredoc to iterate over
|
||||
/// @param fn The function to run on each element
|
||||
/// @param state The state to pass to the function
|
||||
void vec_heredoc_iter(t_vec_heredoc *vec, void (*fn)(t_usize index, t_heredoc *value, void *state), void *state);
|
||||
|
||||
/// @brief Reverse the order of the elements in the vec_heredoc
|
||||
/// @param vec The vec_heredoc to reverse
|
||||
void vec_heredoc_reverse(t_vec_heredoc *vec);
|
||||
|
||||
/// @brief Sort the elements of the vec_heredoc
|
||||
/// @param vec The vec_heredoc to sort
|
||||
/// @param is_sorted The function to use to compare the elements
|
||||
void vec_heredoc_sort(t_vec_heredoc *vec, t_vec_heredoc_sort_fn is_sorted);
|
||||
|
||||
/// @brief Get a pointer to the last element of the vec_heredoc
|
||||
/// @param vec The vec_heredoc to get the element from
|
||||
/// @param[out] out A pointer to the last element of the vec_heredoc
|
||||
/// @return true if the operation failed, false otherwise
|
||||
t_error vec_heredoc_back(t_vec_heredoc *vec, t_heredoc **out);
|
||||
|
||||
#endif
|
||||
41
output/src/vec/ast/ast_sort.c
Normal file
41
output/src/vec/ast/ast_sort.c
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* best_move.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/29 20:04:33 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/01/31 14:25:00 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_ast.h"
|
||||
|
||||
void vec_ast_sort(t_vec_ast *v,
|
||||
t_vec_ast_sort_fn is_sorted_fn)
|
||||
{
|
||||
t_usize sorted_part;
|
||||
t_usize i;
|
||||
t_ast_node tmp;
|
||||
|
||||
if (v == NULL)
|
||||
return;
|
||||
sorted_part = v->len;
|
||||
while (sorted_part > 0)
|
||||
{
|
||||
i = 0;
|
||||
while (i < sorted_part - 1)
|
||||
{
|
||||
if (!is_sorted_fn(&v->buffer[i], &v->buffer[i + 1]))
|
||||
{
|
||||
tmp = v->buffer[i];
|
||||
v->buffer[i] = v->buffer[i + 1];
|
||||
v->buffer[i + 1] = tmp;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
sorted_part--;
|
||||
}
|
||||
}
|
||||
41
output/src/vec/estr/estr_sort.c
Normal file
41
output/src/vec/estr/estr_sort.c
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* best_move.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/29 20:04:33 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/01/31 14:25:00 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_estr.h"
|
||||
|
||||
void vec_estr_sort(t_vec_estr *v,
|
||||
t_vec_estr_sort_fn is_sorted_fn)
|
||||
{
|
||||
t_usize sorted_part;
|
||||
t_usize i;
|
||||
t_expandable_str tmp;
|
||||
|
||||
if (v == NULL)
|
||||
return;
|
||||
sorted_part = v->len;
|
||||
while (sorted_part > 0)
|
||||
{
|
||||
i = 0;
|
||||
while (i < sorted_part - 1)
|
||||
{
|
||||
if (!is_sorted_fn(&v->buffer[i], &v->buffer[i + 1]))
|
||||
{
|
||||
tmp = v->buffer[i];
|
||||
v->buffer[i] = v->buffer[i + 1];
|
||||
v->buffer[i + 1] = tmp;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
sorted_part--;
|
||||
}
|
||||
}
|
||||
95
output/src/vec/heredoc/heredoc.c
Normal file
95
output/src/vec/heredoc/heredoc.c
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* vec_heredoc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/05 18:46:28 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 17:54:11 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_heredoc.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
t_vec_heredoc vec_heredoc_new(t_usize capacity,
|
||||
t_free_heredoc_item free_function)
|
||||
{
|
||||
t_vec_heredoc out;
|
||||
|
||||
out = (t_vec_heredoc){0};
|
||||
out.free_func = free_function;
|
||||
out.buffer = mem_alloc_array(capacity, sizeof(t_heredoc));
|
||||
if (out.buffer)
|
||||
out.capacity = capacity;
|
||||
return (out);
|
||||
}
|
||||
|
||||
/// Return true in case of an error
|
||||
t_error vec_heredoc_push(t_vec_heredoc *vec, t_heredoc element)
|
||||
{
|
||||
if (vec == NULL)
|
||||
return (ERROR);
|
||||
vec_heredoc_reserve(vec, vec->len + 1);
|
||||
vec->buffer[vec->len] = element;
|
||||
vec->len += 1;
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
/// Return true in case of an error
|
||||
t_error vec_heredoc_reserve(t_vec_heredoc *vec, t_usize wanted_capacity)
|
||||
{
|
||||
size_t new_capacity;
|
||||
|
||||
if (vec == NULL)
|
||||
return (ERROR);
|
||||
if (wanted_capacity > vec->capacity)
|
||||
{
|
||||
new_capacity = (vec->capacity * 3) / 2 + 1;
|
||||
while (wanted_capacity > new_capacity)
|
||||
new_capacity = (new_capacity * 3) / 2 + 1;
|
||||
vec->buffer =
|
||||
mem_realloc_array(vec->buffer, new_capacity, sizeof(t_heredoc));
|
||||
vec->capacity = new_capacity;
|
||||
}
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
/// Return true if the vector is empty
|
||||
/// This function is safe to call with value being NULL
|
||||
t_error vec_heredoc_pop(t_vec_heredoc *vec, t_heredoc *value)
|
||||
{
|
||||
t_heredoc temp_value;
|
||||
t_heredoc *ptr;
|
||||
|
||||
if (vec == NULL)
|
||||
return (ERROR);
|
||||
ptr = value;
|
||||
if (vec->len == 0)
|
||||
return (ERROR);
|
||||
if (value == NULL)
|
||||
ptr = &temp_value;
|
||||
vec->len--;
|
||||
*ptr = vec->buffer[vec->len];
|
||||
mem_set_zero(&vec->buffer[vec->len], sizeof(t_heredoc));
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
/// This function is safe to call with `free_elem` being NULL
|
||||
void vec_heredoc_free(t_vec_heredoc vec)
|
||||
{
|
||||
if (vec.buffer == NULL)
|
||||
return;
|
||||
if (vec.free_func)
|
||||
{
|
||||
while (vec.len)
|
||||
{
|
||||
vec.free_func(vec.buffer[vec.len - 1]);
|
||||
vec.len--;
|
||||
}
|
||||
}
|
||||
mem_free(vec.buffer);
|
||||
}
|
||||
112
output/src/vec/heredoc/heredoc_functions2.c
Normal file
112
output/src/vec/heredoc/heredoc_functions2.c
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* vec_heredoc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/30 17:59:28 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/30 17:59:28 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_heredoc.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
t_error vec_heredoc_find(t_vec_heredoc *vec,
|
||||
bool (*fn)(const t_heredoc *), t_usize *index)
|
||||
{
|
||||
t_usize idx;
|
||||
|
||||
if (vec == NULL || fn == NULL || index == NULL)
|
||||
return (ERROR);
|
||||
idx = 0;
|
||||
while (idx < vec->len)
|
||||
{
|
||||
if (fn((const t_heredoc *)&vec->buffer[idx]))
|
||||
{
|
||||
*index = idx;
|
||||
return (NO_ERROR);
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
return (ERROR);
|
||||
}
|
||||
|
||||
t_error vec_heredoc_find_starting(t_vec_heredoc *vec,
|
||||
bool (*fn)(const t_heredoc *),
|
||||
t_usize starting_index, t_usize *index)
|
||||
{
|
||||
t_usize idx;
|
||||
|
||||
if (vec == NULL || fn == NULL || index == NULL)
|
||||
return (ERROR);
|
||||
idx = starting_index;
|
||||
while (idx < vec->len)
|
||||
{
|
||||
if (fn((const t_heredoc *)&vec->buffer[idx]))
|
||||
{
|
||||
*index = idx;
|
||||
return (NO_ERROR);
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
return (ERROR);
|
||||
}
|
||||
|
||||
t_error vec_heredoc_all(t_vec_heredoc *vec,
|
||||
bool (*fn)(const t_heredoc *), bool *result)
|
||||
{
|
||||
t_usize idx;
|
||||
|
||||
if (vec == NULL || fn == NULL || result == NULL)
|
||||
return (ERROR);
|
||||
idx = 0;
|
||||
*result = true;
|
||||
while (*result && idx < vec->len)
|
||||
{
|
||||
if (!fn((const t_heredoc *)&vec->buffer[idx]))
|
||||
*result = false;
|
||||
idx++;
|
||||
}
|
||||
return (ERROR);
|
||||
}
|
||||
|
||||
t_error vec_heredoc_any(t_vec_heredoc *vec,
|
||||
bool (*fn)(const t_heredoc *), bool *result)
|
||||
{
|
||||
t_usize idx;
|
||||
|
||||
if (vec == NULL || fn == NULL || result == NULL)
|
||||
return (ERROR);
|
||||
idx = 0;
|
||||
*result = false;
|
||||
while (*result && idx < vec->len)
|
||||
{
|
||||
if (fn((const t_heredoc *)&vec->buffer[idx]))
|
||||
*result = true;
|
||||
idx++;
|
||||
}
|
||||
return (ERROR);
|
||||
}
|
||||
|
||||
void vec_heredoc_iter(t_vec_heredoc *vec,
|
||||
void (*fn)(t_usize index, t_heredoc *value,
|
||||
void *state),
|
||||
void *state)
|
||||
{
|
||||
t_usize idx;
|
||||
|
||||
if (vec == NULL || fn == NULL)
|
||||
return;
|
||||
idx = 0;
|
||||
while (idx < vec->len)
|
||||
{
|
||||
fn(idx, &vec->buffer[idx], state);
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
84
output/src/vec/heredoc/heredoc_functions3.c
Normal file
84
output/src/vec/heredoc/heredoc_functions3.c
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* vec_heredoc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/30 17:59:28 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/30 17:59:28 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_heredoc.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
t_error vec_heredoc_push_front(t_vec_heredoc *vec,
|
||||
t_heredoc element)
|
||||
{
|
||||
t_usize i;
|
||||
|
||||
if (vec->len == 0)
|
||||
return (vec_heredoc_push(vec, element));
|
||||
i = vec->len - 1;
|
||||
if (vec->capacity < vec->len + 1 &&
|
||||
vec_heredoc_reserve(vec, 3 * vec->len / 2 + 1))
|
||||
return (ERROR);
|
||||
while (i > 0)
|
||||
{
|
||||
vec->buffer[i + 1] = vec->buffer[i];
|
||||
i--;
|
||||
}
|
||||
vec->buffer[1] = vec->buffer[0];
|
||||
vec->buffer[0] = element;
|
||||
vec->len++;
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
t_error vec_heredoc_pop_front(t_vec_heredoc *vec, t_heredoc *value)
|
||||
{
|
||||
t_usize i;
|
||||
|
||||
if (vec->len <= 1)
|
||||
return (vec_heredoc_pop(vec, value));
|
||||
i = 0;
|
||||
*value = vec->buffer[0];
|
||||
vec->len--;
|
||||
while (i < vec->len)
|
||||
{
|
||||
vec->buffer[i] = vec->buffer[i + 1];
|
||||
i++;
|
||||
}
|
||||
mem_set_zero(&vec->buffer[i], sizeof(*vec->buffer));
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
void vec_heredoc_reverse(t_vec_heredoc *vec)
|
||||
{
|
||||
t_heredoc temporary;
|
||||
t_usize i;
|
||||
|
||||
i = 0;
|
||||
while (i < vec->len / 2)
|
||||
{
|
||||
temporary = vec->buffer[vec->len - 1 - i];
|
||||
vec->buffer[vec->len - 1 - i] = vec->buffer[i];
|
||||
vec->buffer[i] = temporary;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
t_error vec_heredoc_back(t_vec_heredoc *vec, t_heredoc **out)
|
||||
{
|
||||
t_heredoc *temporary;
|
||||
|
||||
if (out == NULL)
|
||||
out = &temporary;
|
||||
if (vec->len != 0)
|
||||
return (*out = &vec->buffer[vec->len - 1], true);
|
||||
return (false);
|
||||
}
|
||||
41
output/src/vec/heredoc/heredoc_sort.c
Normal file
41
output/src/vec/heredoc/heredoc_sort.c
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* best_move.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/29 20:04:33 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/01/31 14:25:00 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_heredoc.h"
|
||||
|
||||
void vec_heredoc_sort(t_vec_heredoc *v,
|
||||
t_vec_heredoc_sort_fn is_sorted_fn)
|
||||
{
|
||||
t_usize sorted_part;
|
||||
t_usize i;
|
||||
t_heredoc tmp;
|
||||
|
||||
if (v == NULL)
|
||||
return;
|
||||
sorted_part = v->len;
|
||||
while (sorted_part > 0)
|
||||
{
|
||||
i = 0;
|
||||
while (i < sorted_part - 1)
|
||||
{
|
||||
if (!is_sorted_fn(&v->buffer[i], &v->buffer[i + 1]))
|
||||
{
|
||||
tmp = v->buffer[i];
|
||||
v->buffer[i] = v->buffer[i + 1];
|
||||
v->buffer[i + 1] = tmp;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
sorted_part--;
|
||||
}
|
||||
}
|
||||
41
output/src/vec/pid/pid_sort.c
Normal file
41
output/src/vec/pid/pid_sort.c
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* best_move.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/29 20:04:33 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/01/31 14:25:00 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_pid.h"
|
||||
|
||||
void vec_pid_sort(t_vec_pid *v,
|
||||
t_vec_pid_sort_fn is_sorted_fn)
|
||||
{
|
||||
t_usize sorted_part;
|
||||
t_usize i;
|
||||
t_pid tmp;
|
||||
|
||||
if (v == NULL)
|
||||
return;
|
||||
sorted_part = v->len;
|
||||
while (sorted_part > 0)
|
||||
{
|
||||
i = 0;
|
||||
while (i < sorted_part - 1)
|
||||
{
|
||||
if (!is_sorted_fn(&v->buffer[i], &v->buffer[i + 1]))
|
||||
{
|
||||
tmp = v->buffer[i];
|
||||
v->buffer[i] = v->buffer[i + 1];
|
||||
v->buffer[i + 1] = tmp;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
sorted_part--;
|
||||
}
|
||||
}
|
||||
41
output/src/vec/str/str_sort.c
Normal file
41
output/src/vec/str/str_sort.c
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* best_move.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/29 20:04:33 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/01/31 14:25:00 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_str.h"
|
||||
|
||||
void vec_str_sort(t_vec_str *v,
|
||||
t_vec_str_sort_fn is_sorted_fn)
|
||||
{
|
||||
t_usize sorted_part;
|
||||
t_usize i;
|
||||
t_str tmp;
|
||||
|
||||
if (v == NULL)
|
||||
return;
|
||||
sorted_part = v->len;
|
||||
while (sorted_part > 0)
|
||||
{
|
||||
i = 0;
|
||||
while (i < sorted_part - 1)
|
||||
{
|
||||
if (!is_sorted_fn(&v->buffer[i], &v->buffer[i + 1]))
|
||||
{
|
||||
tmp = v->buffer[i];
|
||||
v->buffer[i] = v->buffer[i + 1];
|
||||
v->buffer[i + 1] = tmp;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
sorted_part--;
|
||||
}
|
||||
}
|
||||
|
|
@ -33,6 +33,8 @@ parser \
|
|||
point/point_funcs1 \
|
||||
point/point_funcs2 \
|
||||
scanner \
|
||||
scanner/deserialize \
|
||||
scanner/serialize \
|
||||
stack/stack_add_link \
|
||||
stack/stack_funcs1 \
|
||||
stack/stack_funcs2 \
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* heredoc_type.h :+: :+: :+: */
|
||||
/* heredoc.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
|
|
@ -10,11 +10,10 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef HEREDOC_TYPE_H
|
||||
#define HEREDOC_TYPE_H
|
||||
#ifndef HEREDOC_H
|
||||
#define HEREDOC_H
|
||||
|
||||
#include "me/string/string.h"
|
||||
#include "me/types.h"
|
||||
|
||||
typedef struct s_heredoc t_heredoc;
|
||||
|
||||
19
parser/include/parser/inner/scanner.h
Executable file
19
parser/include/parser/inner/scanner.h
Executable file
|
|
@ -0,0 +1,19 @@
|
|||
#ifndef SCANNER_H
|
||||
#define SCANNER_H
|
||||
|
||||
#include "me/types.h"
|
||||
#include "parser/inner/heredoc.h"
|
||||
#include "me/vec/vec_heredoc.h"
|
||||
#include "parser/array.h"
|
||||
|
||||
typedef struct s_scanner t_scanner;
|
||||
|
||||
struct s_scanner
|
||||
{
|
||||
t_u8 last_glob_paren_depth;
|
||||
bool ext_was_in_double_quote;
|
||||
bool ext_saw_outside_quote;
|
||||
t_vec_heredoc heredocs;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/_inner/node.h"
|
||||
#include "parser/inner/node.h"
|
||||
|
||||
t_u32 ts_node_child_count(TSNode self)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* node_child_inner.c :+: :+: :+: */
|
||||
/* node_childinner.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/_inner/node.h"
|
||||
#include "parser/inner/node.h"
|
||||
|
||||
TSNode ts_node__child(TSNode self, t_u32 child_index, bool include_anonymous)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/_inner/node.h"
|
||||
#include "parser/inner/node.h"
|
||||
#include "parser/api.h"
|
||||
#include "parser/language.h"
|
||||
#include "parser/tree.h"
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/_inner/node.h"
|
||||
#include "parser/inner/node.h"
|
||||
#include "parser/language.h"
|
||||
#include "parser/tree.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/_inner/node.h"
|
||||
#include "parser/inner/node.h"
|
||||
#include "parser/language.h"
|
||||
#include "parser/tree.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/_inner/node.h"
|
||||
#include "parser/inner/node.h"
|
||||
#include "parser/language.h"
|
||||
#include "parser/tree.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/_inner/node.h"
|
||||
#include "parser/inner/node.h"
|
||||
#include "parser/language.h"
|
||||
#include "parser/tree.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/_inner/node.h"
|
||||
#include "parser/inner/node.h"
|
||||
#include "parser/language.h"
|
||||
#include "parser/tree.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -6,20 +6,19 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/01 14:17:17 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/01 15:11:51 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/01 18:50:23 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/char/char.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/string/string.h"
|
||||
#include "parser/inner/heredoc.h"
|
||||
#include "parser/inner/scanner.h"
|
||||
#include "me/types.h"
|
||||
#include "parser/_inner/heredoc_type.h"
|
||||
#include "parser/array.h"
|
||||
#include "parser/parser.h"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
enum e_token_type
|
||||
{
|
||||
|
|
@ -45,16 +44,6 @@ enum e_token_type
|
|||
ERROR_RECOVERY,
|
||||
};
|
||||
|
||||
typedef struct s_scanner t_scanner;
|
||||
|
||||
struct s_scanner
|
||||
{
|
||||
t_u8 last_glob_paren_depth;
|
||||
bool ext_was_in_double_quote;
|
||||
bool ext_saw_outside_quote;
|
||||
Array(t_heredoc) heredocs;
|
||||
};
|
||||
|
||||
void advance(TSLexer *lexer)
|
||||
{
|
||||
lexer->advance(lexer, false);
|
||||
|
|
@ -67,7 +56,7 @@ void skip(TSLexer *lexer)
|
|||
|
||||
bool in_error_recovery(const bool *valid_symbols)
|
||||
{
|
||||
return valid_symbols[ERROR_RECOVERY];
|
||||
return (valid_symbols[ERROR_RECOVERY]);
|
||||
}
|
||||
|
||||
void reset(t_scanner *scanner)
|
||||
|
|
@ -79,89 +68,6 @@ void reset(t_scanner *scanner)
|
|||
reset_heredoc(array_get(&scanner->heredocs, i++));
|
||||
}
|
||||
|
||||
t_u32 serialize(t_scanner *scanner, t_u8 *buffer)
|
||||
{
|
||||
t_u32 size;
|
||||
t_usize i;
|
||||
t_heredoc *heredoc;
|
||||
|
||||
size = 0;
|
||||
buffer[size++] = (char)scanner->last_glob_paren_depth;
|
||||
buffer[size++] = (char)scanner->ext_was_in_double_quote;
|
||||
buffer[size++] = (char)scanner->ext_saw_outside_quote;
|
||||
buffer[size++] = (char)scanner->heredocs.size;
|
||||
i = 0;
|
||||
while (i < scanner->heredocs.size)
|
||||
{
|
||||
heredoc = array_get(&scanner->heredocs, i);
|
||||
if (heredoc->delimiter.len + 1 + sizeof(t_usize) + size >= TREE_SITTER_SERIALIZATION_BUFFER_SIZE)
|
||||
return (0);
|
||||
buffer[size++] = (char)heredoc->is_raw;
|
||||
buffer[size++] = (char)heredoc->started;
|
||||
buffer[size++] = (char)heredoc->allows_indent;
|
||||
heredoc->delimiter.len++;
|
||||
mem_copy(&buffer[size], &heredoc->delimiter.len, sizeof(t_usize));
|
||||
size += sizeof(t_usize);
|
||||
if (heredoc->delimiter.len > 0)
|
||||
{
|
||||
mem_copy(&buffer[size], heredoc->delimiter.buf, heredoc->delimiter.len);
|
||||
size += heredoc->delimiter.len;
|
||||
}
|
||||
heredoc->delimiter.len--;
|
||||
i++;
|
||||
}
|
||||
return (size);
|
||||
}
|
||||
|
||||
void deserialize(t_scanner *scanner, const t_u8 *buffer, t_u32 length)
|
||||
{
|
||||
t_usize delim_size;
|
||||
t_u32 size;
|
||||
t_u32 heredoc_count;
|
||||
t_heredoc *heredoc;
|
||||
t_usize i;
|
||||
|
||||
if (length == 0)
|
||||
reset(scanner);
|
||||
else
|
||||
{
|
||||
size = 0;
|
||||
scanner->last_glob_paren_depth = buffer[size++];
|
||||
scanner->ext_was_in_double_quote = buffer[size++];
|
||||
scanner->ext_saw_outside_quote = buffer[size++];
|
||||
heredoc_count = (t_u8)buffer[size++];
|
||||
i = 0;
|
||||
while (i < heredoc_count)
|
||||
{
|
||||
heredoc = NULL;
|
||||
if (i < scanner->heredocs.size)
|
||||
heredoc = array_get(&scanner->heredocs, i);
|
||||
else
|
||||
{
|
||||
array_push(&scanner->heredocs, heredoc_new());
|
||||
heredoc = array_back(&scanner->heredocs);
|
||||
}
|
||||
|
||||
heredoc->is_raw = buffer[size++];
|
||||
heredoc->started = buffer[size++];
|
||||
heredoc->allows_indent = buffer[size++];
|
||||
|
||||
mem_copy(&delim_size, &buffer[size], sizeof(t_usize));
|
||||
size += sizeof(t_usize);
|
||||
string_reserve(&heredoc->delimiter, delim_size + 1);
|
||||
heredoc->delimiter.len = delim_size - 1;
|
||||
if (delim_size > 0)
|
||||
{
|
||||
mem_copy(heredoc->delimiter.buf, &buffer[size], delim_size);
|
||||
size += delim_size;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (size != length)
|
||||
me_abort("size != length");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Consume a "word" in POSIX parlance, and returns it unquoted.
|
||||
*
|
||||
|
|
@ -1095,7 +1001,7 @@ void *tree_sitter_sh_external_scanner_create()
|
|||
|
||||
scanner = mem_alloc(sizeof(*scanner));
|
||||
array_init(&scanner->heredocs);
|
||||
return scanner;
|
||||
return (scanner);
|
||||
}
|
||||
|
||||
bool tree_sitter_sh_external_scanner_scan(void *payload, TSLexer *lexer, const bool *valid_symbols)
|
||||
|
|
@ -1103,23 +1009,7 @@ bool tree_sitter_sh_external_scanner_scan(void *payload, TSLexer *lexer, const b
|
|||
t_scanner *scanner;
|
||||
|
||||
scanner = (t_scanner *)payload;
|
||||
return scan(scanner, lexer, valid_symbols);
|
||||
}
|
||||
|
||||
t_u32 tree_sitter_sh_external_scanner_serialize(void *payload, t_u8 *state)
|
||||
{
|
||||
t_scanner *scanner;
|
||||
|
||||
scanner = (t_scanner *)payload;
|
||||
return (serialize(scanner, state));
|
||||
}
|
||||
|
||||
void tree_sitter_sh_external_scanner_deserialize(void *payload, const t_u8 *state, t_u32 length)
|
||||
{
|
||||
t_scanner *scanner;
|
||||
|
||||
scanner = (t_scanner *)payload;
|
||||
deserialize(scanner, state, length);
|
||||
return (scan(scanner, lexer, valid_symbols));
|
||||
}
|
||||
|
||||
void tree_sitter_sh_external_scanner_destroy(void *payload)
|
||||
|
|
|
|||
68
parser/src/scanner/deserialize.c
Normal file
68
parser/src/scanner/deserialize.c
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* deserialize.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/01 15:06:56 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/01 15:08:47 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/types.h"
|
||||
#include "parser/inner/heredoc.h"
|
||||
#include "parser/inner/scanner.h"
|
||||
#include "parser/array.h"
|
||||
#include "parser/parser.h"
|
||||
|
||||
void reset(t_scanner *);
|
||||
|
||||
void tree_sitter_sh_external_scanner_deserialize(t_scanner *scanner, const t_u8 *buffer, t_u32 length)
|
||||
{
|
||||
t_usize delim_size;
|
||||
t_u32 size;
|
||||
t_u32 heredoc_count;
|
||||
t_heredoc *heredoc;
|
||||
t_usize i;
|
||||
|
||||
if (length == 0)
|
||||
reset(scanner);
|
||||
else
|
||||
{
|
||||
size = 0;
|
||||
scanner->last_glob_paren_depth = buffer[size++];
|
||||
scanner->ext_was_in_double_quote = buffer[size++];
|
||||
scanner->ext_saw_outside_quote = buffer[size++];
|
||||
heredoc_count = (t_u8)buffer[size++];
|
||||
i = 0;
|
||||
while (i < heredoc_count)
|
||||
{
|
||||
heredoc = NULL;
|
||||
if (i < scanner->heredocs.size)
|
||||
heredoc = array_get(&scanner->heredocs, i);
|
||||
else
|
||||
{
|
||||
array_push(&scanner->heredocs, heredoc_new());
|
||||
heredoc = array_back(&scanner->heredocs);
|
||||
}
|
||||
|
||||
heredoc->is_raw = buffer[size++];
|
||||
heredoc->started = buffer[size++];
|
||||
heredoc->allows_indent = buffer[size++];
|
||||
|
||||
mem_copy(&delim_size, &buffer[size], sizeof(t_usize));
|
||||
size += sizeof(t_usize);
|
||||
string_reserve(&heredoc->delimiter, delim_size + 1);
|
||||
heredoc->delimiter.len = delim_size - 1;
|
||||
if (delim_size > 0)
|
||||
{
|
||||
mem_copy(heredoc->delimiter.buf, &buffer[size], delim_size);
|
||||
size += delim_size;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (size != length)
|
||||
me_abort("size != length");
|
||||
}
|
||||
}
|
||||
56
parser/src/scanner/serialize.c
Normal file
56
parser/src/scanner/serialize.c
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* serialize.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/01 15:06:56 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/01 15:08:47 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/inner/scanner.h"
|
||||
#include "parser/inner/heredoc.h"
|
||||
#include "me/types.h"
|
||||
#include "parser/array.h"
|
||||
#include "parser/parser.h"
|
||||
|
||||
t_error serialize_heredocs(t_scanner *scanner, t_u8* buffer, t_u32 *size, t_usize i)
|
||||
{
|
||||
t_heredoc *heredoc;
|
||||
|
||||
heredoc = array_get(&scanner->heredocs, i);
|
||||
if (heredoc->delimiter.len + 1 + sizeof(t_usize) + (*size) >= TREE_SITTER_SERIALIZATION_BUFFER_SIZE)
|
||||
return (ERROR);
|
||||
buffer[(*size)++] = (char)heredoc->is_raw;
|
||||
buffer[(*size)++] = (char)heredoc->started;
|
||||
buffer[(*size)++] = (char)heredoc->allows_indent;
|
||||
heredoc->delimiter.len++;
|
||||
mem_copy(&buffer[(*size)], &heredoc->delimiter.len, sizeof(t_usize));
|
||||
size += sizeof(t_usize);
|
||||
if (heredoc->delimiter.len > 0)
|
||||
{
|
||||
mem_copy(&buffer[(*size)], heredoc->delimiter.buf, heredoc->delimiter.len);
|
||||
(*size) += heredoc->delimiter.len;
|
||||
}
|
||||
heredoc->delimiter.len--;
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
t_u32 tree_sitter_sh_external_scanner_serialize(t_scanner *scanner, t_u8 *buffer)
|
||||
{
|
||||
t_u32 size;
|
||||
t_usize i;
|
||||
|
||||
size = 0;
|
||||
buffer[size++] = (char)scanner->last_glob_paren_depth;
|
||||
buffer[size++] = (char)scanner->ext_was_in_double_quote;
|
||||
buffer[size++] = (char)scanner->ext_saw_outside_quote;
|
||||
buffer[size++] = (char)scanner->heredocs.size;
|
||||
i = 0;
|
||||
while (i < scanner->heredocs.size)
|
||||
if (serialize_heredocs(scanner, buffer, &size, i++))
|
||||
return (0);
|
||||
return (size);
|
||||
}
|
||||
|
|
@ -11,7 +11,7 @@
|
|||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/stack.h"
|
||||
#include "parser/_inner/stack.h"
|
||||
#include "parser/inner/stack.h"
|
||||
|
||||
// In general,
|
||||
// we preserve ambiguities until they are removed from the stack
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/stack.h"
|
||||
#include "parser/_inner/stack.h"
|
||||
#include "parser/inner/stack.h"
|
||||
|
||||
bool ts_stack_is_active(const t_stack *self, t_stack_version version)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/stack.h"
|
||||
#include "parser/_inner/stack.h"
|
||||
#include "parser/inner/stack.h"
|
||||
|
||||
t_u32 ts_stack_error_cost(const t_stack *self, t_stack_version version)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/stack.h"
|
||||
#include "parser/_inner/stack.h"
|
||||
#include "parser/inner/stack.h"
|
||||
|
||||
bool stack__subtree_is_equivalent(t_subtree left, t_subtree right)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/stack.h"
|
||||
#include "parser/_inner/stack.h"
|
||||
#include "parser/inner/stack.h"
|
||||
|
||||
t_u32 ts_stack_version_count(const t_stack *self)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/_inner/stack.h"
|
||||
#include "parser/inner/stack.h"
|
||||
#include "parser/stack.h"
|
||||
|
||||
t_stack_slice_array stack__iter(t_stack *self, t_stack_version version,
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/_inner/stack.h"
|
||||
#include "parser/inner/stack.h"
|
||||
#include "parser/stack.h"
|
||||
|
||||
t_stack *ts_stack_new(void)
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/_inner/stack.h"
|
||||
#include "parser/inner/stack.h"
|
||||
#include "parser/language.h"
|
||||
|
||||
void ts_stack_push(t_stack *self, t_stack_version version, t_subtree subtree,
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
#include "me/types.h"
|
||||
#include "parser/stack.h"
|
||||
#include "parser/_inner/stack.h"
|
||||
#include "parser/inner/stack.h"
|
||||
|
||||
bool ts_stack_merge(t_stack *self, t_stack_version version1,
|
||||
t_stack_version version2)
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/stack.h"
|
||||
#include "parser/_inner/stack.h"
|
||||
#include "parser/inner/stack.h"
|
||||
|
||||
t_stack_action pop_error_callback(void *payload,
|
||||
const t_stack_iterator *iterator)
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/_inner/stack.h"
|
||||
#include "parser/inner/stack.h"
|
||||
#include "parser/language.h"
|
||||
#include "parser/stack.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/stack.h"
|
||||
#include "parser/_inner/stack.h"
|
||||
#include "parser/inner/stack.h"
|
||||
|
||||
t_stack_action summarize_stack_callback(void *payload,
|
||||
const t_stack_iterator *iterator)
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/stack.h"
|
||||
#include "parser/_inner/stack.h"
|
||||
#include "parser/inner/stack.h"
|
||||
|
||||
void ts_stack_remove_version(t_stack *self, t_stack_version version)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue