From a192af9ad467d728ae1457c11de41e64efac3f16 Mon Sep 17 00:00:00 2001 From: Maix0 Date: Wed, 1 May 2024 21:19:14 +0200 Subject: [PATCH] Updates... --- includes/app/node.h | 2 +- includes/minishell.h | 2 +- parser/src/api.h | 1112 ++++++------ parser/src/combined.c | 2420 ++++++++++++++------------- parser/src/scanner.c | 18 +- sources/ft_exit.c | 2 +- sources/main.c | 24 +- sources/node/node.c | 20 +- stdme/.envrc | 1 - stdme/Makefile | 12 +- stdme/src/fs/putnbr_fd.c | 6 +- stdme/src/string/str_find_rev_chr.c | 4 +- 12 files changed, 1836 insertions(+), 1787 deletions(-) delete mode 100644 stdme/.envrc diff --git a/includes/app/node.h b/includes/app/node.h index 2cf7efd3..7d884d6a 100644 --- a/includes/app/node.h +++ b/includes/app/node.h @@ -28,7 +28,7 @@ typedef struct s_node struct s_node *childs; } t_node; -t_node build_node(TSNode curr, t_const_str input); +t_node build_node(t_parse_node curr, t_const_str input); t_str node_getstr(t_node *node); void free_node(t_node t); diff --git a/includes/minishell.h b/includes/minishell.h index c35111dd..9238fda0 100644 --- a/includes/minishell.h +++ b/includes/minishell.h @@ -32,7 +32,7 @@ typedef struct s_parser { - TSParser *parser; + t_first_parser *parser; } t_parser; typedef struct s_utils diff --git a/parser/src/api.h b/parser/src/api.h index 6b498bd4..743b4457 100644 --- a/parser/src/api.h +++ b/parser/src/api.h @@ -2,12 +2,12 @@ #define TREE_SITTER_ARRAY_H_ #include +#include +#include #include #include #include #include -#include -#include #define ts_builtin_sym_error_repeat (ts_builtin_sym_error - 1) #define LANGUAGE_VERSION_WITH_PRIMARY_STATES 14 @@ -28,157 +28,15 @@ #define MAX_ITERATOR_COUNT 64 #define TS_MAX_INLINE_TREE_LENGTH UINT8_MAX #define TS_MAX_TREE_POOL_SIZE 32 -#define ts_builtin_sym_error ((TSSymbol) - 1) +#define ts_builtin_sym_error ((t_symbol)-1) #define ts_builtin_sym_end 0 #define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024 -#define POINT_ZERO ((TSPoint){0, 0}) -#define POINT_MAX ((TSPoint){UINT32_MAX, UINT32_MAX}) +#define POINT_ZERO ((t_point){0, 0}) +#define POINT_MAX ((t_point){UINT32_MAX, UINT32_MAX}) #define TS_TREE_STATE_NONE USHRT_MAX -#define NULL_SUBTREE ((Subtree){.ptr = NULL}) -#define STACK_VERSION_NONE ((StackVersion) - 1) -#define TS_DECODE_ERROR (-1) - -// Get a subtree's children, which are allocated immediately before the -// tree's own heap data. -#define ts_subtree_children(self) \ - ((self).data.is_inline \ - ? NULL \ - : (Subtree *)((self).ptr) - (self).ptr->child_count) - -typedef uint16_t TSStateId; -typedef uint16_t TSSymbol; -typedef uint16_t TSFieldId; -typedef struct TSLanguage TSLanguage; -typedef struct TSParser TSParser; -typedef struct TSTree TSTree; -typedef struct TSQuery TSQuery; -typedef struct TSQueryCursor TSQueryCursor; -typedef struct TSLookaheadIterator TSLookaheadIterator; - -typedef struct TSPoint -{ - uint32_t row; - uint32_t column; -} TSPoint; - -typedef struct -{ - uint32_t bytes; - TSPoint extent; -} Length; - -typedef enum TSInputEncoding -{ - TSInputEncodingUTF8, - TSInputEncodingUTF16, -} TSInputEncoding; - -typedef enum TSSymbolType -{ - TSSymbolTypeRegular, - TSSymbolTypeAnonymous, - TSSymbolTypeAuxiliary, -} TSSymbolType; - - -typedef struct TSRange -{ - TSPoint start_point; - TSPoint end_point; - uint32_t start_byte; - uint32_t end_byte; -} TSRange; - -typedef struct TSInput -{ - void *payload; - const char *(*read)(void *payload, uint32_t byte_index, TSPoint position, - uint32_t *bytes_read); - TSInputEncoding encoding; -} TSInput; - -typedef enum TSLogType -{ - TSLogTypeParse, - TSLogTypeLex, -} TSLogType; - -typedef struct TSLogger -{ - void *payload; - void (*log)(void *payload, TSLogType log_type, const char *buffer); -} TSLogger; - -typedef struct TSInputEdit -{ - uint32_t start_byte; - uint32_t old_end_byte; - uint32_t new_end_byte; - TSPoint start_point; - TSPoint old_end_point; - TSPoint new_end_point; -} TSInputEdit; - -typedef struct TSNode -{ - uint32_t context[4]; - const void *id; - const TSTree *tree; -} TSNode; - -typedef struct TSTreeCursor -{ - const void *tree; - const void *id; - uint32_t context[3]; -} TSTreeCursor; - -typedef struct TSQueryCapture -{ - TSNode node; - uint32_t index; -} TSQueryCapture; - -typedef enum TSQuantifier -{ - TSQuantifierZero = 0, // must match the array initialization value - TSQuantifierZeroOrOne, - TSQuantifierZeroOrMore, - TSQuantifierOne, - TSQuantifierOneOrMore, -} TSQuantifier; - -typedef struct TSQueryMatch -{ - uint32_t id; - uint16_t pattern_index; - uint16_t capture_count; - const TSQueryCapture *captures; -} TSQueryMatch; - -typedef enum TSQueryPredicateStepType -{ - TSQueryPredicateStepTypeDone, - TSQueryPredicateStepTypeCapture, - TSQueryPredicateStepTypeString, -} TSQueryPredicateStepType; - -typedef struct TSQueryPredicateStep -{ - TSQueryPredicateStepType type; - uint32_t value_id; -} TSQueryPredicateStep; - -typedef enum TSQueryError -{ - TSQueryErrorNone = 0, - TSQueryErrorSyntax, - TSQueryErrorNodeType, - TSQueryErrorField, - TSQueryErrorCapture, - TSQueryErrorStructure, - TSQueryErrorLanguage, -} TSQueryError; +#define NULL_SUBTREE ((t_subtree){.ptr = NULL}) +#define STACK_VERSION_NONE ((t_stack_version)-1) +#define TS_DECODE_ERROR (-1) #define Array(T) \ struct \ @@ -322,6 +180,157 @@ typedef enum TSQueryError array_insert(self, _index, value); \ } while (0) + +// Get a subtree's children, which are allocated immediately before the +// tree's own heap data. +#define ts_subtree_children(self) \ + ((self).data.is_inline \ + ? NULL \ + : (t_subtree *)((self).ptr) - (self).ptr->child_count) + +typedef uint16_t t_state_id; +typedef uint16_t t_symbol; +typedef uint16_t t_field_id; +typedef struct s_language t_language; +typedef struct s_first_parser t_first_parser; +typedef struct s_first_tree t_first_tree; +typedef struct s_parse_query t_parse_query; +typedef struct s_query_cursor t_query_cursor; +typedef struct s_lookahead_iterator t_lookahead_iterator; + +typedef struct s_point +{ + uint32_t row; + uint32_t column; +} t_point; + +typedef struct s_length +{ + uint32_t bytes; + t_point extent; +} t_length; + +typedef enum e_input_encoding +{ + TSInputEncodingUTF8, + TSInputEncodingUTF16, +} t_input_encoding; + +typedef enum e_symbol_type +{ + TSSymbolTypeRegular, + TSSymbolTypeAnonymous, + TSSymbolTypeAuxiliary, +} t_symbol_type; + +typedef struct s_parse_range +{ + t_point start_point; + t_point end_point; + uint32_t start_byte; + uint32_t end_byte; +} t_parse_range; + +typedef struct s_parse_input +{ + void *payload; + const char *(*read)(void *payload, uint32_t byte_index, t_point position, + uint32_t *bytes_read); + t_input_encoding encoding; +} t_parse_input; + +typedef enum e_log_type +{ + TSLogTypeParse, + TSLogTypeLex, +} t_log_type; + +typedef struct s_parse_logger +{ + void *payload; + void (*log)(void *payload, t_log_type log_type, const char *buffer); +} t_parse_logger; + +typedef struct s_input_edit +{ + uint32_t start_byte; + uint32_t old_end_byte; + uint32_t new_end_byte; + t_point start_point; + t_point old_end_point; + t_point new_end_point; +} t_input_edit; + +typedef struct s_parse_node +{ + uint32_t context[4]; + const void *id; + const t_first_tree *tree; +} t_parse_node; + +typedef struct s_tree_cursor_entry +{ + const union t_subtree *subtree; + t_length position; + uint32_t child_index; + uint32_t structural_child_index; + uint32_t descendant_index; +} t_tree_cursor_entry; + +typedef struct s_tree_cursor +{ + const t_first_tree *tree; + Array(t_tree_cursor_entry) stack; + t_symbol root_alias_symbol; +} t_tree_cursor; + +typedef struct s_query_capture +{ + t_parse_node node; + uint32_t index; +} t_query_capture; + +typedef enum e_quantifier +{ + TSQuantifierZero = 0, // must match the array initialization value + TSQuantifierZeroOrOne, + TSQuantifierZeroOrMore, + TSQuantifierOne, + TSQuantifierOneOrMore, +} t_quantifier; + +typedef struct s_query_match +{ + uint32_t id; + uint16_t pattern_index; + uint16_t capture_count; + const t_query_capture *captures; +} t_query_match; + +typedef enum e_query_predicate_step_type +{ + TSQueryPredicateStepTypeDone, + TSQueryPredicateStepTypeCapture, + TSQueryPredicateStepTypeString, +} t_query_predicate_step_type; + +typedef struct s_query_predicate_step +{ + t_query_predicate_step_type type; + uint32_t value_id; +} t_query_predicate_step; + +typedef enum e_query_error +{ + TSQueryErrorNone = 0, + TSQueryErrorSyntax, + TSQueryErrorNodeType, + TSQueryErrorField, + TSQueryErrorCapture, + TSQueryErrorStructure, + TSQueryErrorLanguage, +} t_query_error; + // Private typedef Array(void) Array; @@ -529,11 +538,11 @@ typedef struct // // The idea behind the layout of this struct is that the `is_inline` // bit will fall exactly into the same location as the least significant -// bit of the pointer in `Subtree` or `MutableSubtree`, respectively. +// bit of the pointer in `t_subtree` or `t_mutable_subtree`, respectively. // Because of alignment, for any valid pointer this will be 0, giving // us the opportunity to make use of this bit to signify whether to use // the pointer or the inline struct. -typedef struct SubtreeInlineData SubtreeInlineData; +typedef struct s_subtree_inline_data t_subtree_inline_data; #define SUBTREE_BITS \ bool visible : 1; \ @@ -553,7 +562,7 @@ typedef struct SubtreeInlineData SubtreeInlineData; #if TS_BIG_ENDIAN # if TS_PTR_SIZE == 32 -struct SubtreeInlineData +struct s_subtree_inline_data { uint16_t parse_state; uint8_t symbol; @@ -565,7 +574,7 @@ struct SubtreeInlineData # else -struct SubtreeInlineData +struct s_subtree_inline_data { SUBTREE_SIZE uint16_t parse_state; @@ -578,7 +587,7 @@ struct SubtreeInlineData # endif #else -struct SubtreeInlineData +struct s_subtree_inline_data { bool is_inline : 1; SUBTREE_BITS @@ -592,24 +601,21 @@ struct SubtreeInlineData #undef SUBTREE_BITS #undef SUBTREE_SIZE - - - // 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 +typedef struct s_subtree_heap_data { volatile uint32_t ref_count; - Length padding; - Length size; + t_length padding; + t_length size; uint32_t lookahead_bytes; uint32_t error_cost; uint32_t child_count; - TSSymbol symbol; - TSStateId parse_state; + t_symbol symbol; + t_state_id parse_state; bool visible : 1; bool named : 1; @@ -635,8 +641,8 @@ typedef struct uint16_t production_id; struct { - TSSymbol symbol; - TSStateId parse_state; + t_symbol symbol; + t_state_id parse_state; } first_leaf; }; @@ -648,239 +654,223 @@ typedef struct // ts_builtin_sym_error`) int32_t lookahead_char; }; -} SubtreeHeapData; +} t_subtree_heap_data; // The fundamental building block of a syntax tree. -typedef union { - SubtreeInlineData data; - const SubtreeHeapData *ptr; -} Subtree; +typedef union t_subtree { + t_subtree_inline_data data; + const t_subtree_heap_data *ptr; +} t_subtree; -// Like Subtree, but mutable. -typedef union { - SubtreeInlineData data; - SubtreeHeapData *ptr; -} MutableSubtree; +// Like t_subtree, but mutable. +typedef union t_mutable_subtree { + t_subtree_inline_data data; + t_subtree_heap_data *ptr; +} t_mutable_subtree; -typedef Array(Subtree) SubtreeArray; -typedef Array(MutableSubtree) MutableSubtreeArray; +typedef Array(t_subtree) t_subtree_array; +typedef Array(t_mutable_subtree) t_mutable_subtree_array; typedef struct { - MutableSubtreeArray free_trees; - MutableSubtreeArray tree_stack; -} SubtreePool; + t_mutable_subtree_array free_trees; + t_mutable_subtree_array tree_stack; +} t_subtree_pool; -typedef Array(TSRange) TSRangeArray; +typedef Array(t_parse_range) t_range_array; -typedef struct -{ - const Subtree *subtree; - Length position; - uint32_t child_index; - uint32_t structural_child_index; - uint32_t descendant_index; -} TreeCursorEntry; - -typedef struct -{ - const TSTree *tree; - Array(TreeCursorEntry) stack; - TSSymbol root_alias_symbol; -} TreeCursor; - -typedef union { +typedef union t_parse_action { struct { - uint8_t type; - TSStateId state; - bool extra; - bool repetition; + uint8_t type; + t_state_id state; + bool extra; + bool repetition; } shift; struct { uint8_t type; uint8_t child_count; - TSSymbol symbol; + t_symbol symbol; int16_t dynamic_precedence; uint16_t production_id; } reduce; uint8_t type; -} TSParseAction; +} t_parse_action; -void ts_range_array_get_changed_ranges(const TSRange *old_ranges, - unsigned old_range_count, - const TSRange *new_ranges, - unsigned new_range_count, - TSRangeArray *differences); +void ts_range_array_get_changed_ranges(const t_parse_range *old_ranges, + unsigned old_range_count, + const t_parse_range *new_ranges, + unsigned new_range_count, + t_range_array *differences); -bool ts_range_array_intersects(const TSRangeArray *self, unsigned start_index, +bool ts_range_array_intersects(const t_range_array *self, unsigned start_index, uint32_t start_byte, uint32_t end_byte); unsigned ts_subtree_get_changed_ranges( - const Subtree *old_tree, const Subtree *new_tree, TreeCursor *cursor1, - TreeCursor *cursor2, const TSLanguage *language, - const TSRangeArray *included_range_differences, TSRange **ranges); + const t_subtree *old_tree, const t_subtree *new_tree, + t_tree_cursor *cursor1, t_tree_cursor *cursor2, const t_language *language, + const t_range_array *included_range_differences, t_parse_range **ranges); -typedef struct +typedef struct s_table_entry { - const TSParseAction *actions; - uint32_t action_count; - bool is_reusable; -} TableEntry; + const t_parse_action *actions; + uint32_t action_count; + bool is_reusable; +} t_table_entry; -typedef struct +typedef struct s_lookahead_iterator { - const TSLanguage *language; + const t_language *language; const uint16_t *data; const uint16_t *group_end; - TSStateId state; + t_state_id state; uint16_t table_value; uint16_t section_index; uint16_t group_count; bool is_small_state; - const TSParseAction *actions; - TSSymbol symbol; - TSStateId next_state; - uint16_t action_count; -} LookaheadIterator; + const t_parse_action *actions; + t_symbol symbol; + t_state_id next_state; + uint16_t action_count; +} t_lookahead_iterator; -typedef struct +typedef struct s_symbol_metadata { bool visible; bool named; bool supertype; -} TSSymbolMetadata; +} t_symbol_metadata; -typedef enum +typedef enum e_parse_action_type { TSParseActionTypeShift, TSParseActionTypeReduce, TSParseActionTypeAccept, TSParseActionTypeRecover, -} TSParseActionType; +} t_parse_action_type; -typedef union { - TSParseAction action; +typedef union t_parse_action_entry { + t_parse_action action; struct { uint8_t count; bool reusable; } entry; -} TSParseActionEntry; +} t_parse_action_entry; -typedef struct +typedef struct s_field_map_entry { - TSFieldId field_id; - uint8_t child_index; - bool inherited; -} TSFieldMapEntry; + t_field_id field_id; + uint8_t child_index; + bool inherited; +} t_field_map_entry; -typedef struct +typedef struct s_field_map_slice { uint16_t index; uint16_t length; -} TSFieldMapSlice; +} t_field_map_slice; -typedef struct TSLexer TSLexer; +typedef struct s_lexer_data t_lexer_data; -struct TSLexer +struct s_lexer_data { int32_t lookahead; - TSSymbol result_symbol; - void (*advance)(TSLexer *, bool); - void (*mark_end)(TSLexer *); - uint32_t (*get_column)(TSLexer *); - bool (*is_at_included_range_start)(const TSLexer *); - bool (*eof)(const TSLexer *); + t_symbol result_symbol; + void (*advance)(t_lexer_data *, bool); + void (*mark_end)(t_lexer_data *); + uint32_t (*get_column)(t_lexer_data *); + bool (*is_at_included_range_start)(const t_lexer_data *); + bool (*eof)(const t_lexer_data *); }; -typedef struct +typedef struct s_lex_mode { uint16_t lex_state; uint16_t external_lex_state; -} TSLexMode; +} t_lex_mode; -typedef struct +typedef struct s_char_range { int32_t start; int32_t end; -} TSCharacterRange; +} t_char_range; -struct TSLanguage +struct s_language { - uint32_t version; - uint32_t symbol_count; - uint32_t alias_count; - uint32_t token_count; - uint32_t external_token_count; - uint32_t state_count; - uint32_t large_state_count; - uint32_t production_id_count; - uint32_t field_count; - uint16_t max_alias_sequence_length; - const uint16_t *parse_table; - const uint16_t *small_parse_table; - const uint32_t *small_parse_table_map; - const TSParseActionEntry *parse_actions; - const char *const *symbol_names; - const char *const *field_names; - const TSFieldMapSlice *field_map_slices; - const TSFieldMapEntry *field_map_entries; - const TSSymbolMetadata *symbol_metadata; - const TSSymbol *public_symbol_map; - const uint16_t *alias_map; - const TSSymbol *alias_sequences; - const TSLexMode *lex_modes; - bool (*lex_fn)(TSLexer *, TSStateId); - bool (*keyword_lex_fn)(TSLexer *, TSStateId); - TSSymbol keyword_capture_token; + uint32_t version; + uint32_t symbol_count; + uint32_t alias_count; + uint32_t token_count; + uint32_t external_token_count; + uint32_t state_count; + uint32_t large_state_count; + uint32_t production_id_count; + uint32_t field_count; + uint16_t max_alias_sequence_length; + const uint16_t *parse_table; + const uint16_t *small_parse_table; + const uint32_t *small_parse_table_map; + const t_parse_action_entry *parse_actions; + const char *const *symbol_names; + const char *const *field_names; + const t_field_map_slice *field_map_slices; + const t_field_map_entry *field_map_entries; + const t_symbol_metadata *symbol_metadata; + const t_symbol *public_symbol_map; + const uint16_t *alias_map; + const t_symbol *alias_sequences; + const t_lex_mode *lex_modes; + bool (*lex_fn)(t_lexer_data *, t_state_id); + bool (*keyword_lex_fn)(t_lexer_data *, t_state_id); + t_symbol keyword_capture_token; struct { const bool *states; - const TSSymbol *symbol_map; + const t_symbol *symbol_map; void *(*create)(void); void (*destroy)(void *); - bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist); + bool (*scan)(void *, t_lexer_data *, const bool *symbol_whitelist); unsigned (*serialize)(void *, char *); void (*deserialize)(void *, const char *, unsigned); } external_scanner; - const TSStateId *primary_state_ids; + const t_state_id *primary_state_ids; }; -void ts_language_table_entry(const TSLanguage *, TSStateId, TSSymbol, - TableEntry *); +void ts_language_table_entry(const t_language *, t_state_id, t_symbol, + t_table_entry *); -TSSymbolMetadata ts_language_symbol_metadata(const TSLanguage *, TSSymbol); +t_symbol_metadata ts_language_symbol_metadata(const t_language *, t_symbol); -TSSymbol ts_language_public_symbol(const TSLanguage *, TSSymbol); +t_symbol ts_language_public_symbol(const t_language *, t_symbol); -TSStateId ts_language_next_state(const TSLanguage *self, TSStateId state, - TSSymbol symbol); +t_state_id ts_language_next_state(const t_language *self, t_state_id state, + t_symbol symbol); -static inline bool ts_language_is_symbol_external(const TSLanguage *self, - TSSymbol symbol) +static inline bool ts_language_is_symbol_external(const t_language *self, + t_symbol symbol) { return 0 < symbol && symbol < self->external_token_count + 1; } -static inline const TSParseAction *ts_language_actions(const TSLanguage *self, - TSStateId state, - TSSymbol symbol, - uint32_t *count) +static inline const t_parse_action *ts_language_actions(const t_language *self, + t_state_id state, + t_symbol symbol, + uint32_t *count) { - TableEntry entry; + t_table_entry entry; ts_language_table_entry(self, state, symbol, &entry); *count = entry.action_count; return entry.actions; } -static inline bool ts_language_has_reduce_action(const TSLanguage *self, - TSStateId state, - TSSymbol symbol) +static inline bool ts_language_has_reduce_action(const t_language *self, + t_state_id state, + t_symbol symbol) { - TableEntry entry; + t_table_entry entry; ts_language_table_entry(self, state, symbol, &entry); return entry.action_count > 0 && entry.actions[0].type == TSParseActionTypeReduce; @@ -893,8 +883,8 @@ static inline bool ts_language_has_reduce_action(const TSLanguage *self, // For 'large' parse states, this is a direct lookup. For 'small' parse // states, this requires searching through the symbol groups to find // the given symbol. -static inline uint16_t ts_language_lookup(const TSLanguage *self, - TSStateId state, TSSymbol symbol) +static inline uint16_t ts_language_lookup(const t_language *self, + t_state_id state, t_symbol symbol) { if (state >= self->large_state_count) { @@ -920,8 +910,8 @@ static inline uint16_t ts_language_lookup(const TSLanguage *self, } } -static inline bool ts_language_has_actions(const TSLanguage *self, - TSStateId state, TSSymbol symbol) +static inline bool ts_language_has_actions(const t_language *self, + t_state_id state, t_symbol symbol) { return ts_language_lookup(self, state, symbol) != 0; } @@ -932,8 +922,8 @@ static inline bool ts_language_has_actions(const TSLanguage *self, // all possible symbols and checking the parse table for each one. // For 'small' parse states, this exploits the structure of the // table to only visit the valid symbols. -static inline LookaheadIterator ts_language_lookaheads(const TSLanguage *self, - TSStateId state) +static inline t_lookahead_iterator ts_language_lookaheads( + const t_language *self, t_state_id state) { bool is_small_state = state >= self->large_state_count; const uint16_t *data; @@ -951,7 +941,7 @@ static inline LookaheadIterator ts_language_lookaheads(const TSLanguage *self, { data = &self->parse_table[state * self->symbol_count] - 1; } - return (LookaheadIterator){ + return (t_lookahead_iterator){ .language = self, .data = data, .group_end = group_end, @@ -962,7 +952,7 @@ static inline LookaheadIterator ts_language_lookaheads(const TSLanguage *self, }; } -static inline bool ts_lookahead_iterator__next(LookaheadIterator *self) +static inline bool ts_lookahead_iterator__next(t_lookahead_iterator *self) { // For small parse states, valid symbols are listed explicitly, // grouped by their value. There's no need to look up the actions @@ -1005,10 +995,10 @@ static inline bool ts_lookahead_iterator__next(LookaheadIterator *self) // either represents a list of actions or a successor state. if (self->symbol < self->language->token_count) { - const TSParseActionEntry *entry = + const t_parse_action_entry *entry = &self->language->parse_actions[self->table_value]; self->action_count = entry->entry.count; - self->actions = (const TSParseAction *)(entry + 1); + self->actions = (const t_parse_action *)(entry + 1); self->next_state = 0; } else @@ -1022,8 +1012,8 @@ static inline bool ts_lookahead_iterator__next(LookaheadIterator *self) // Whether the state is a "primary state". If this returns false, it indicates // that there exists another state that behaves identically to this one with // respect to query analysis. -static inline bool ts_language_state_is_primary(const TSLanguage *self, - TSStateId state) +static inline bool ts_language_state_is_primary(const t_language *self, + t_state_id state) { if (self->version >= LANGUAGE_VERSION_WITH_PRIMARY_STATES) { @@ -1036,7 +1026,7 @@ static inline bool ts_language_state_is_primary(const TSLanguage *self, } static inline const bool *ts_language_enabled_external_tokens( - const TSLanguage *self, unsigned external_scanner_state) + const t_language *self, unsigned external_scanner_state) { if (external_scanner_state == 0) { @@ -1049,7 +1039,7 @@ static inline const bool *ts_language_enabled_external_tokens( } } -static inline const TSSymbol *ts_language_alias_sequence(const TSLanguage *self, +static inline const t_symbol *ts_language_alias_sequence(const t_language *self, uint32_t production_id) { return production_id @@ -1058,7 +1048,7 @@ static inline const TSSymbol *ts_language_alias_sequence(const TSLanguage *self, : NULL; } -static inline TSSymbol ts_language_alias_at(const TSLanguage *self, +static inline t_symbol ts_language_alias_at(const t_language *self, uint32_t production_id, uint32_t child_index) { @@ -1069,10 +1059,10 @@ static inline TSSymbol ts_language_alias_at(const TSLanguage *self, : 0; } -static inline void ts_language_field_map(const TSLanguage *self, - uint32_t production_id, - const TSFieldMapEntry **start, - const TSFieldMapEntry **end) +static inline void ts_language_field_map(const t_language *self, + uint32_t production_id, + const t_field_map_entry **start, + const t_field_map_entry **end) { if (self->field_count == 0) { @@ -1081,15 +1071,15 @@ static inline void ts_language_field_map(const TSLanguage *self, return; } - TSFieldMapSlice slice = self->field_map_slices[production_id]; + t_field_map_slice slice = self->field_map_slices[production_id]; *start = &self->field_map_entries[slice.index]; *end = &self->field_map_entries[slice.index] + slice.length; } -static inline void ts_language_aliases_for_symbol(const TSLanguage *self, - TSSymbol original_symbol, - const TSSymbol **start, - const TSSymbol **end) +static inline void ts_language_aliases_for_symbol(const t_language *self, + t_symbol original_symbol, + const t_symbol **start, + const t_symbol **end) { *start = &self->public_symbol_map[original_symbol]; *end = *start + 1; @@ -1097,7 +1087,7 @@ static inline void ts_language_aliases_for_symbol(const TSLanguage *self, unsigned idx = 0; for (;;) { - TSSymbol symbol = self->alias_map[idx++]; + t_symbol symbol = self->alias_map[idx++]; if (symbol == 0 || symbol > original_symbol) break; uint16_t count = self->alias_map[idx++]; @@ -1111,45 +1101,45 @@ static inline void ts_language_aliases_for_symbol(const TSLanguage *self, } } -static const Length LENGTH_UNDEFINED = {0, {0, 1}}; -static const Length LENGTH_MAX = {UINT32_MAX, {UINT32_MAX, UINT32_MAX}}; +static const t_length LENGTH_UNDEFINED = {0, {0, 1}}; +static const t_length LENGTH_MAX = {UINT32_MAX, {UINT32_MAX, UINT32_MAX}}; -static TSPoint point_add(TSPoint a, TSPoint b); -static TSPoint point_sub(TSPoint a, TSPoint b); +static t_point point_add(t_point a, t_point b); +static t_point point_sub(t_point a, t_point b); -static inline bool length_is_undefined(Length length) +static inline bool length_is_undefined(t_length length) { return length.bytes == 0 && length.extent.column != 0; } -static inline Length length_min(Length len1, Length len2) +static inline t_length length_min(t_length len1, t_length len2) { return (len1.bytes < len2.bytes) ? len1 : len2; } -static inline Length length_add(Length len1, Length len2) +static inline t_length length_add(t_length len1, t_length len2) { - Length result; + t_length result; result.bytes = len1.bytes + len2.bytes; result.extent = point_add(len1.extent, len2.extent); return result; } -static inline Length length_sub(Length len1, Length len2) +static inline t_length length_sub(t_length len1, t_length len2) { - Length result; + t_length result; result.bytes = len1.bytes - len2.bytes; result.extent = point_sub(len1.extent, len2.extent); return result; } -static inline Length length_zero(void) +static inline t_length length_zero(void) { - Length result = {0, {0, 0}}; + t_length result = {0, {0, 0}}; return result; } -static inline Length length_saturating_sub(Length len1, Length len2) +static inline t_length length_saturating_sub(t_length len1, t_length len2) { if (len1.bytes > len2.bytes) { @@ -1161,17 +1151,17 @@ static inline Length length_saturating_sub(Length len1, Length len2) } } -typedef struct +typedef struct s_lexer { - TSLexer data; - Length current_position; - Length token_start_position; - Length token_end_position; + t_lexer_data data; + t_length current_position; + t_length token_start_position; + t_length token_end_position; - TSRange *included_ranges; - const char *chunk; - TSInput input; - TSLogger logger; + t_parse_range *included_ranges; + const char *chunk; + t_parse_input input; + t_parse_logger logger; uint32_t included_range_count; uint32_t current_included_range_index; @@ -1181,30 +1171,30 @@ typedef struct bool did_get_column; char debug_buffer[TREE_SITTER_SERIALIZATION_BUFFER_SIZE]; -} Lexer; +} t_lexer; -void ts_lexer_init(Lexer *); -void ts_lexer_delete(Lexer *); -void ts_lexer_set_input(Lexer *, TSInput); -void ts_lexer_reset(Lexer *, Length); -void ts_lexer_start(Lexer *); -void ts_lexer_finish(Lexer *, uint32_t *); -void ts_lexer_advance_to_end(Lexer *); -void ts_lexer_mark_end(Lexer *); -bool ts_lexer_set_included_ranges(Lexer *self, const TSRange *ranges, - uint32_t count); -TSRange *ts_lexer_included_ranges(const Lexer *self, uint32_t *count); +void ts_lexer_init(t_lexer *); +void ts_lexer_delete(t_lexer *); +void ts_lexer_set_input(t_lexer *, t_parse_input); +void ts_lexer_reset(t_lexer *, t_length); +void ts_lexer_start(t_lexer *); +void ts_lexer_finish(t_lexer *, uint32_t *); +void ts_lexer_advance_to_end(t_lexer *); +void ts_lexer_mark_end(t_lexer *); +bool ts_lexer_set_included_ranges(t_lexer *self, const t_parse_range *ranges, + uint32_t count); +t_parse_range *ts_lexer_included_ranges(const t_lexer *self, uint32_t *count); -static inline bool set_contains(TSCharacterRange *ranges, uint32_t len, +static inline bool set_contains(t_char_range *ranges, uint32_t len, int32_t lookahead) { uint32_t index = 0; uint32_t size = len - index; while (size > 1) { - uint32_t half_size = size / 2; - uint32_t mid_index = index + half_size; - TSCharacterRange *range = &ranges[mid_index]; + uint32_t half_size = size / 2; + uint32_t mid_index = index + half_size; + t_char_range *range = &ranges[mid_index]; if (lookahead >= range->start && lookahead <= range->end) { return true; @@ -1215,17 +1205,17 @@ static inline bool set_contains(TSCharacterRange *ranges, uint32_t len, } size -= half_size; } - TSCharacterRange *range = &ranges[index]; + t_char_range *range = &ranges[index]; return (lookahead >= range->start && lookahead <= range->end); } -static inline TSPoint point__new(unsigned row, unsigned column) +static inline t_point point__new(unsigned row, unsigned column) { - TSPoint result = {row, column}; + t_point result = {row, column}; return result; } -static inline TSPoint point_add(TSPoint a, TSPoint b) +static inline t_point point_add(t_point a, t_point b) { if (b.row > 0) return point__new(a.row + b.row, b.column); @@ -1233,7 +1223,7 @@ static inline TSPoint point_add(TSPoint a, TSPoint b) return point__new(a.row, a.column + b.column); } -static inline TSPoint point_sub(TSPoint a, TSPoint b) +static inline t_point point_sub(t_point a, t_point b) { if (a.row > b.row) return point__new(a.row - b.row, a.column); @@ -1241,32 +1231,32 @@ static inline TSPoint point_sub(TSPoint a, TSPoint b) return point__new(0, a.column - b.column); } -static inline bool point_lte(TSPoint a, TSPoint b) +static inline bool point_lte(t_point a, t_point b) { return (a.row < b.row) || (a.row == b.row && a.column <= b.column); } -static inline bool point_lt(TSPoint a, TSPoint b) +static inline bool point_lt(t_point a, t_point b) { return (a.row < b.row) || (a.row == b.row && a.column < b.column); } -static inline bool point_gt(TSPoint a, TSPoint b) +static inline bool point_gt(t_point a, t_point b) { return (a.row > b.row) || (a.row == b.row && a.column > b.column); } -static inline bool point_gte(TSPoint a, TSPoint b) +static inline bool point_gte(t_point a, t_point b) { return (a.row > b.row) || (a.row == b.row && a.column >= b.column); } -static inline bool point_eq(TSPoint a, TSPoint b) +static inline bool point_eq(t_point a, t_point b) { return a.row == b.row && a.column == b.column; } -static inline TSPoint point_min(TSPoint a, TSPoint b) +static inline t_point point_min(t_point a, t_point b) { if (a.row < b.row || (a.row == b.row && a.column < b.column)) return a; @@ -1274,7 +1264,7 @@ static inline TSPoint point_min(TSPoint a, TSPoint b) return b; } -static inline TSPoint point_max(TSPoint a, TSPoint b) +static inline t_point point_max(t_point a, t_point b) { if (a.row > b.row || (a.row == b.row && a.column > b.column)) return a; @@ -1282,22 +1272,22 @@ static inline TSPoint point_max(TSPoint a, TSPoint b) return b; } -typedef struct +typedef struct s_reduce_action { uint32_t count; - TSSymbol symbol; + t_symbol symbol; int dynamic_precedence; unsigned short production_id; -} ReduceAction; +} t_reduce_action; -typedef Array(ReduceAction) ReduceActionSet; +typedef Array(t_reduce_action) t_reduce_action_set; -static inline void ts_reduce_action_set_add(ReduceActionSet *self, - ReduceAction new_action) +static inline void ts_reduce_action_set_add(t_reduce_action_set *self, + t_reduce_action new_action) { for (uint32_t i = 0; i < self->size; i++) { - ReduceAction action = self->contents[i]; + t_reduce_action action = self->contents[i]; if (action.symbol == new_action.symbol && action.count == new_action.count) return; @@ -1305,59 +1295,58 @@ static inline void ts_reduce_action_set_add(ReduceActionSet *self, array_push(self, new_action); } -typedef struct +typedef struct s_stack_entry { - Subtree tree; - uint32_t child_index; - uint32_t byte_offset; -} StackEntry; + t_subtree tree; + uint32_t child_index; + uint32_t byte_offset; +} t_stack_entry; -typedef struct +typedef struct s_reusable_node { - Array(StackEntry) stack; - Subtree last_external_token; -} ReusableNode; + Array(t_stack_entry) stack; + t_subtree last_external_token; +} t_reusable_node; -static inline ReusableNode reusable_node_new(void) +static inline t_reusable_node reusable_node_new(void) { - return (ReusableNode){array_new(), NULL_SUBTREE}; + return (t_reusable_node){array_new(), NULL_SUBTREE}; } -static inline void reusable_node_clear(ReusableNode *self) +static inline void reusable_node_clear(t_reusable_node *self) { array_clear(&self->stack); self->last_external_token = NULL_SUBTREE; } -static inline Subtree reusable_node_tree(ReusableNode *self) +static inline t_subtree reusable_node_tree(t_reusable_node *self) { return self->stack.size > 0 ? self->stack.contents[self->stack.size - 1].tree : NULL_SUBTREE; } -static inline uint32_t reusable_node_byte_offset(ReusableNode *self) +static inline uint32_t reusable_node_byte_offset(t_reusable_node *self) { return self->stack.size > 0 ? self->stack.contents[self->stack.size - 1].byte_offset : UINT32_MAX; } -static inline void reusable_node_delete(ReusableNode *self) +static inline void reusable_node_delete(t_reusable_node *self) { array_delete(&self->stack); } +static inline uint32_t ts_subtree_total_bytes(t_subtree self); +static inline bool ts_subtree_has_external_tokens(t_subtree self); +t_subtree ts_subtree_last_external_token(t_subtree self); +static inline uint32_t ts_subtree_child_count(t_subtree self); -static inline uint32_t ts_subtree_total_bytes(Subtree self); -static inline bool ts_subtree_has_external_tokens(Subtree self); -Subtree ts_subtree_last_external_token(Subtree self); -static inline uint32_t ts_subtree_child_count(Subtree self); - -static inline void reusable_node_advance(ReusableNode *self) +static inline void reusable_node_advance(t_reusable_node *self) { - StackEntry last_entry = *array_back(&self->stack); - uint32_t byte_offset = + t_stack_entry last_entry = *array_back(&self->stack); + uint32_t byte_offset = last_entry.byte_offset + ts_subtree_total_bytes(last_entry.tree); if (ts_subtree_has_external_tokens(last_entry.tree)) { @@ -1365,31 +1354,31 @@ static inline void reusable_node_advance(ReusableNode *self) ts_subtree_last_external_token(last_entry.tree); } - Subtree tree; - uint32_t next_index; + t_subtree tree; + uint32_t next_index; do { - StackEntry popped_entry = array_pop(&self->stack); + t_stack_entry popped_entry = array_pop(&self->stack); next_index = popped_entry.child_index + 1; if (self->stack.size == 0) return; tree = array_back(&self->stack)->tree; } while (ts_subtree_child_count(tree) <= next_index); - array_push(&self->stack, ((StackEntry){ + array_push(&self->stack, ((t_stack_entry){ .tree = ts_subtree_children(tree)[next_index], .child_index = next_index, .byte_offset = byte_offset, })); } -static inline bool reusable_node_descend(ReusableNode *self) +static inline bool reusable_node_descend(t_reusable_node *self) { - StackEntry last_entry = *array_back(&self->stack); + t_stack_entry last_entry = *array_back(&self->stack); if (ts_subtree_child_count(last_entry.tree) > 0) { array_push(&self->stack, - ((StackEntry){ + ((t_stack_entry){ .tree = ts_subtree_children(last_entry.tree)[0], .child_index = 0, .byte_offset = last_entry.byte_offset, @@ -1402,7 +1391,7 @@ static inline bool reusable_node_descend(ReusableNode *self) } } -static inline void reusable_node_advance_past_leaf(ReusableNode *self) +static inline void reusable_node_advance_past_leaf(t_reusable_node *self) { while (reusable_node_descend(self)) { @@ -1410,10 +1399,10 @@ static inline void reusable_node_advance_past_leaf(ReusableNode *self) reusable_node_advance(self); } -static inline void reusable_node_reset(ReusableNode *self, Subtree tree) +static inline void reusable_node_reset(t_reusable_node *self, t_subtree tree) { reusable_node_clear(self); - array_push(&self->stack, ((StackEntry){ + array_push(&self->stack, ((t_stack_entry){ .tree = tree, .child_index = 0, .byte_offset = 0, @@ -1428,120 +1417,121 @@ static inline void reusable_node_reset(ReusableNode *self, Subtree tree) } } -typedef struct Stack Stack; +typedef struct s_stack t_stack; -typedef unsigned StackVersion; +typedef unsigned t_stack_version; -typedef struct +typedef struct s_stack_slice { - SubtreeArray subtrees; - StackVersion version; -} StackSlice; -typedef Array(StackSlice) StackSliceArray; + t_subtree_array subtrees; + t_stack_version version; +} t_stack_slice; +typedef Array(t_stack_slice) t_stack_slice_array; -typedef struct +typedef struct s_stack_summary_entry { - Length position; - unsigned depth; - TSStateId state; -} StackSummaryEntry; -typedef Array(StackSummaryEntry) StackSummary; + t_length position; + unsigned depth; + t_state_id state; +} t_stack_summary_entry; +typedef Array(t_stack_summary_entry) t_stack_summary; // Create a stack. -Stack *ts_stack_new(SubtreePool *); +t_stack *ts_stack_new(t_subtree_pool *); // Release the memory reserved for a given stack. -void ts_stack_delete(Stack *); +void ts_stack_delete(t_stack *); // Get the stack's current number of versions. -uint32_t ts_stack_version_count(const Stack *); +uint32_t ts_stack_version_count(const t_stack *); // Get the state at the top of the given version of the stack. If the stack is // empty, this returns the initial state, 0. -TSStateId ts_stack_state(const Stack *, StackVersion); +t_state_id ts_stack_state(const t_stack *, t_stack_version); // Get the last external token associated with a given version of the stack. -Subtree ts_stack_last_external_token(const Stack *, StackVersion); +t_subtree ts_stack_last_external_token(const t_stack *, t_stack_version); // Set the last external token associated with a given version of the stack. -void ts_stack_set_last_external_token(Stack *, StackVersion, Subtree); +void ts_stack_set_last_external_token(t_stack *, t_stack_version, t_subtree); // Get the position of the given version of the stack within the document. -Length ts_stack_position(const Stack *, StackVersion); +t_length ts_stack_position(const t_stack *, t_stack_version); // Push a tree and state onto the given version of the stack. // -// This transfers ownership of the tree to the Stack. Callers that +// This transfers ownership of the tree to the t_stack. Callers that // need to retain ownership of the tree for their own purposes should // first retain the tree. -void ts_stack_push(Stack *, StackVersion, Subtree, bool, TSStateId); +void ts_stack_push(t_stack *, t_stack_version, t_subtree, bool, t_state_id); // Pop the given number of entries from the given version of the stack. This // operation can increase the number of stack versions by revealing multiple // versions which had previously been merged. It returns an array that // specifies the index of each revealed version and the trees that were // removed from that version. -StackSliceArray ts_stack_pop_count(Stack *, StackVersion, uint32_t count); +t_stack_slice_array ts_stack_pop_count(t_stack *, t_stack_version, + uint32_t count); // Remove an error at the top of the given version of the stack. -SubtreeArray ts_stack_pop_error(Stack *, StackVersion); +t_subtree_array ts_stack_pop_error(t_stack *, t_stack_version); // Remove any pending trees from the top of the given version of the stack. -StackSliceArray ts_stack_pop_pending(Stack *, StackVersion); +t_stack_slice_array ts_stack_pop_pending(t_stack *, t_stack_version); // Remove any all trees from the given version of the stack. -StackSliceArray ts_stack_pop_all(Stack *, StackVersion); +t_stack_slice_array ts_stack_pop_all(t_stack *, t_stack_version); // Get the maximum number of tree nodes reachable from this version of the stack // since the last error was detected. -unsigned ts_stack_node_count_since_error(const Stack *, StackVersion); +unsigned ts_stack_node_count_since_error(const t_stack *, t_stack_version); -int ts_stack_dynamic_precedence(Stack *, StackVersion); +int ts_stack_dynamic_precedence(t_stack *, t_stack_version); -bool ts_stack_has_advanced_since_error(const Stack *, StackVersion); +bool ts_stack_has_advanced_since_error(const t_stack *, t_stack_version); // Compute a summary of all the parse states near the top of the given // version of the stack and store the summary for later retrieval. -void ts_stack_record_summary(Stack *, StackVersion, unsigned max_depth); +void ts_stack_record_summary(t_stack *, t_stack_version, unsigned max_depth); // Retrieve a summary of all the parse states near the top of the // given version of the stack. -StackSummary *ts_stack_get_summary(Stack *, StackVersion); +t_stack_summary *ts_stack_get_summary(t_stack *, t_stack_version); // Get the total cost of all errors on the given version of the stack. -unsigned ts_stack_error_cost(const Stack *, StackVersion version); +unsigned ts_stack_error_cost(const t_stack *, t_stack_version version); // Merge the given two stack versions if possible, returning true // if they were successfully merged and false otherwise. -bool ts_stack_merge(Stack *, StackVersion, StackVersion); +bool ts_stack_merge(t_stack *, t_stack_version, t_stack_version); // Determine whether the given two stack versions can be merged. -bool ts_stack_can_merge(Stack *, StackVersion, StackVersion); +bool ts_stack_can_merge(t_stack *, t_stack_version, t_stack_version); -Subtree ts_stack_resume(Stack *, StackVersion); +t_subtree ts_stack_resume(t_stack *, t_stack_version); -void ts_stack_pause(Stack *, StackVersion, Subtree); +void ts_stack_pause(t_stack *, t_stack_version, t_subtree); -void ts_stack_halt(Stack *, StackVersion); +void ts_stack_halt(t_stack *, t_stack_version); -bool ts_stack_is_active(const Stack *, StackVersion); +bool ts_stack_is_active(const t_stack *, t_stack_version); -bool ts_stack_is_paused(const Stack *, StackVersion); +bool ts_stack_is_paused(const t_stack *, t_stack_version); -bool ts_stack_is_halted(const Stack *, StackVersion); +bool ts_stack_is_halted(const t_stack *, t_stack_version); -void ts_stack_renumber_version(Stack *, StackVersion, StackVersion); +void ts_stack_renumber_version(t_stack *, t_stack_version, t_stack_version); -void ts_stack_swap_versions(Stack *, StackVersion, StackVersion); +void ts_stack_swap_versions(t_stack *, t_stack_version, t_stack_version); -StackVersion ts_stack_copy_version(Stack *, StackVersion); +t_stack_version ts_stack_copy_version(t_stack *, t_stack_version); // Remove the given version from the stack. -void ts_stack_remove_version(Stack *, StackVersion); +void ts_stack_remove_version(t_stack *, t_stack_version); -void ts_stack_clear(Stack *); +void ts_stack_clear(t_stack *); -typedef void (*StackIterateCallback)(void *, TSStateId, uint32_t); +typedef void (*StackIterateCallback)(void *, t_state_id, uint32_t); void ts_external_scanner_state_init(ExternalScannerState *, const char *, unsigned); @@ -1550,76 +1540,80 @@ bool ts_external_scanner_state_eq(const ExternalScannerState *self, const char *, unsigned); void ts_external_scanner_state_delete(ExternalScannerState *self); -void ts_subtree_array_copy(SubtreeArray, SubtreeArray *); -void ts_subtree_array_clear(SubtreePool *, SubtreeArray *); -void ts_subtree_array_delete(SubtreePool *, SubtreeArray *); -void ts_subtree_array_remove_trailing_extras(SubtreeArray *, SubtreeArray *); -void ts_subtree_array_reverse(SubtreeArray *); +void ts_subtree_array_copy(t_subtree_array, t_subtree_array *); +void ts_subtree_array_clear(t_subtree_pool *, t_subtree_array *); +void ts_subtree_array_delete(t_subtree_pool *, t_subtree_array *); +void ts_subtree_array_remove_trailing_extras(t_subtree_array *, + t_subtree_array *); +void ts_subtree_array_reverse(t_subtree_array *); -SubtreePool ts_subtree_pool_new(uint32_t capacity); -void ts_subtree_pool_delete(SubtreePool *); +t_subtree_pool ts_subtree_pool_new(uint32_t capacity); +void ts_subtree_pool_delete(t_subtree_pool *); -Subtree ts_subtree_new_leaf(SubtreePool *, TSSymbol, Length, Length, uint32_t, - TSStateId, bool, bool, bool, const TSLanguage *); -Subtree ts_subtree_new_error(SubtreePool *, int32_t, Length, Length, uint32_t, - TSStateId, const TSLanguage *); -MutableSubtree ts_subtree_new_node(TSSymbol, SubtreeArray *, unsigned, - const TSLanguage *); -Subtree ts_subtree_new_error_node(SubtreeArray *, bool, const TSLanguage *); -Subtree ts_subtree_new_missing_leaf(SubtreePool *, TSSymbol, Length, uint32_t, - const TSLanguage *); -MutableSubtree ts_subtree_make_mut(SubtreePool *, Subtree); -void ts_subtree_retain(Subtree); -void ts_subtree_release(SubtreePool *, Subtree); -int ts_subtree_compare(Subtree, Subtree, SubtreePool *); -void ts_subtree_set_symbol(MutableSubtree *, TSSymbol, const TSLanguage *); -void ts_subtree_summarize(MutableSubtree, const Subtree *, uint32_t, - const TSLanguage *); -void ts_subtree_summarize_children(MutableSubtree, const TSLanguage *); -void ts_subtree_balance(Subtree, SubtreePool *, const TSLanguage *); -Subtree ts_subtree_edit(Subtree, const TSInputEdit *edit, SubtreePool *); -char *ts_subtree_string(Subtree, TSSymbol, bool, const TSLanguage *, - bool include_all); -Subtree ts_subtree_last_external_token(Subtree); -const ExternalScannerState *ts_subtree_external_scanner_state(Subtree self); -bool ts_subtree_external_scanner_state_eq(Subtree, Subtree); +t_subtree ts_subtree_new_leaf(t_subtree_pool *, t_symbol, t_length, t_length, + uint32_t, t_state_id, bool, bool, bool, + const t_language *); +t_subtree ts_subtree_new_error(t_subtree_pool *, int32_t, t_length, t_length, + uint32_t, t_state_id, const t_language *); +t_mutable_subtree ts_subtree_new_node(t_symbol, t_subtree_array *, unsigned, + const t_language *); +t_subtree ts_subtree_new_error_node(t_subtree_array *, bool, + const t_language *); +t_subtree ts_subtree_new_missing_leaf(t_subtree_pool *, t_symbol, t_length, + uint32_t, const t_language *); +t_mutable_subtree ts_subtree_make_mut(t_subtree_pool *, t_subtree); +void ts_subtree_retain(t_subtree); +void ts_subtree_release(t_subtree_pool *, t_subtree); +int ts_subtree_compare(t_subtree, t_subtree, t_subtree_pool *); +void ts_subtree_set_symbol(t_mutable_subtree *, t_symbol, const t_language *); +void ts_subtree_summarize(t_mutable_subtree, const t_subtree *, uint32_t, + const t_language *); +void ts_subtree_summarize_children(t_mutable_subtree, const t_language *); +void ts_subtree_balance(t_subtree, t_subtree_pool *, const t_language *); +t_subtree ts_subtree_edit(t_subtree, const t_input_edit *edit, + t_subtree_pool *); +char *ts_subtree_string(t_subtree, t_symbol, bool, const t_language *, + bool include_all); +t_subtree ts_subtree_last_external_token(t_subtree); +const ExternalScannerState *ts_subtree_external_scanner_state(t_subtree self); +bool ts_subtree_external_scanner_state_eq(t_subtree, t_subtree); #define SUBTREE_GET(self, name) \ ((self).data.is_inline ? (self).data.name : (self).ptr->name) -static inline TSSymbol ts_subtree_symbol(Subtree self) +static inline t_symbol ts_subtree_symbol(t_subtree self) { return SUBTREE_GET(self, symbol); } -static inline bool ts_subtree_visible(Subtree self) +static inline bool ts_subtree_visible(t_subtree self) { return SUBTREE_GET(self, visible); } -static inline bool ts_subtree_named(Subtree self) +static inline bool ts_subtree_named(t_subtree self) { return SUBTREE_GET(self, named); } -static inline bool ts_subtree_extra(Subtree self) +static inline bool ts_subtree_extra(t_subtree self) { return SUBTREE_GET(self, extra); } -static inline bool ts_subtree_has_changes(Subtree self) +static inline bool ts_subtree_has_changes(t_subtree self) { return SUBTREE_GET(self, has_changes); } -static inline bool ts_subtree_missing(Subtree self) +static inline bool ts_subtree_missing(t_subtree self) { return SUBTREE_GET(self, is_missing); } -static inline bool ts_subtree_is_keyword(Subtree self) +static inline bool ts_subtree_is_keyword(t_subtree self) { return SUBTREE_GET(self, is_keyword); } -static inline TSStateId ts_subtree_parse_state(Subtree self) +static inline t_state_id ts_subtree_parse_state(t_subtree self) { return SUBTREE_GET(self, parse_state); } -static inline uint32_t ts_subtree_lookahead_bytes(Subtree self) +static inline uint32_t ts_subtree_lookahead_bytes(t_subtree self) { return SUBTREE_GET(self, lookahead_bytes); } @@ -1630,12 +1624,10 @@ static inline uint32_t ts_subtree_lookahead_bytes(Subtree self) // number of children. static inline size_t ts_subtree_alloc_size(uint32_t child_count) { - return child_count * sizeof(Subtree) + sizeof(SubtreeHeapData); + return child_count * sizeof(t_subtree) + sizeof(t_subtree_heap_data); } - - -static inline void ts_subtree_set_extra(MutableSubtree *self, bool is_extra) +static inline void ts_subtree_set_extra(t_mutable_subtree *self, bool is_extra) { if (self->data.is_inline) { @@ -1647,7 +1639,7 @@ static inline void ts_subtree_set_extra(MutableSubtree *self, bool is_extra) } } -static inline TSSymbol ts_subtree_leaf_symbol(Subtree self) +static inline t_symbol ts_subtree_leaf_symbol(t_subtree self) { if (self.data.is_inline) return self.data.symbol; @@ -1656,7 +1648,7 @@ static inline TSSymbol ts_subtree_leaf_symbol(Subtree self) return self.ptr->first_leaf.symbol; } -static inline TSStateId ts_subtree_leaf_parse_state(Subtree self) +static inline t_state_id ts_subtree_leaf_parse_state(t_subtree self) { if (self.data.is_inline) return self.data.parse_state; @@ -1665,12 +1657,12 @@ static inline TSStateId ts_subtree_leaf_parse_state(Subtree self) return self.ptr->first_leaf.parse_state; } -static inline Length ts_subtree_padding(Subtree self) +static inline t_length ts_subtree_padding(t_subtree self) { if (self.data.is_inline) { - Length result = {self.data.padding_bytes, - {self.data.padding_rows, self.data.padding_columns}}; + t_length result = {self.data.padding_bytes, + {self.data.padding_rows, self.data.padding_columns}}; return result; } else @@ -1679,11 +1671,11 @@ static inline Length ts_subtree_padding(Subtree self) } } -static inline Length ts_subtree_size(Subtree self) +static inline t_length ts_subtree_size(t_subtree self) { if (self.data.is_inline) { - Length result = {self.data.size_bytes, {0, self.data.size_bytes}}; + t_length result = {self.data.size_bytes, {0, self.data.size_bytes}}; return result; } else @@ -1692,41 +1684,41 @@ static inline Length ts_subtree_size(Subtree self) } } -static inline Length ts_subtree_total_size(Subtree self) +static inline t_length ts_subtree_total_size(t_subtree self) { return length_add(ts_subtree_padding(self), ts_subtree_size(self)); } -static inline uint32_t ts_subtree_total_bytes(Subtree self) +static inline uint32_t ts_subtree_total_bytes(t_subtree self) { return ts_subtree_total_size(self).bytes; } -static inline uint32_t ts_subtree_child_count(Subtree self) +static inline uint32_t ts_subtree_child_count(t_subtree self) { return self.data.is_inline ? 0 : self.ptr->child_count; } -static inline uint32_t ts_subtree_repeat_depth(Subtree self) +static inline uint32_t ts_subtree_repeat_depth(t_subtree self) { return self.data.is_inline ? 0 : self.ptr->repeat_depth; } -static inline uint32_t ts_subtree_is_repetition(Subtree self) +static inline uint32_t ts_subtree_is_repetition(t_subtree self) { return self.data.is_inline ? 0 : !self.ptr->named && !self.ptr->visible && self.ptr->child_count != 0; } -static inline uint32_t ts_subtree_visible_descendant_count(Subtree self) +static inline uint32_t ts_subtree_visible_descendant_count(t_subtree self) { return (self.data.is_inline || self.ptr->child_count == 0) ? 0 : self.ptr->visible_descendant_count; } -static inline uint32_t ts_subtree_visible_child_count(Subtree self) +static inline uint32_t ts_subtree_visible_child_count(t_subtree self) { if (ts_subtree_child_count(self) > 0) { @@ -1738,7 +1730,7 @@ static inline uint32_t ts_subtree_visible_child_count(Subtree self) } } -static inline uint32_t ts_subtree_error_cost(Subtree self) +static inline uint32_t ts_subtree_error_cost(t_subtree self) { if (ts_subtree_missing(self)) { @@ -1750,14 +1742,14 @@ static inline uint32_t ts_subtree_error_cost(Subtree self) } } -static inline int32_t ts_subtree_dynamic_precedence(Subtree self) +static inline int32_t ts_subtree_dynamic_precedence(t_subtree self) { return (self.data.is_inline || self.ptr->child_count == 0) ? 0 : self.ptr->dynamic_precedence; } -static inline uint16_t ts_subtree_production_id(Subtree self) +static inline uint16_t ts_subtree_production_id(t_subtree self) { if (ts_subtree_child_count(self) > 0) { @@ -1769,107 +1761,109 @@ static inline uint16_t ts_subtree_production_id(Subtree self) } } -static inline bool ts_subtree_fragile_left(Subtree self) +static inline bool ts_subtree_fragile_left(t_subtree self) { return self.data.is_inline ? false : self.ptr->fragile_left; } -static inline bool ts_subtree_fragile_right(Subtree self) +static inline bool ts_subtree_fragile_right(t_subtree self) { return self.data.is_inline ? false : self.ptr->fragile_right; } -static inline bool ts_subtree_has_external_tokens(Subtree self) +static inline bool ts_subtree_has_external_tokens(t_subtree self) { return self.data.is_inline ? false : self.ptr->has_external_tokens; } -static inline bool ts_subtree_has_external_scanner_state_change(Subtree self) +static inline bool ts_subtree_has_external_scanner_state_change(t_subtree self) { return self.data.is_inline ? false : self.ptr->has_external_scanner_state_change; } -static inline bool ts_subtree_depends_on_column(Subtree self) +static inline bool ts_subtree_depends_on_column(t_subtree self) { return self.data.is_inline ? false : self.ptr->depends_on_column; } -static inline bool ts_subtree_is_fragile(Subtree self) +static inline bool ts_subtree_is_fragile(t_subtree self) { return self.data.is_inline ? false : (self.ptr->fragile_left || self.ptr->fragile_right); } -static inline bool ts_subtree_is_error(Subtree self) +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(Subtree self) +static inline bool ts_subtree_is_eof(t_subtree self) { return ts_subtree_symbol(self) == ts_builtin_sym_end; } -static inline Subtree ts_subtree_from_mut(MutableSubtree self) +static inline t_subtree ts_subtree_from_mut(t_mutable_subtree self) { - Subtree result; + t_subtree result; result.data = self.data; return result; } -static inline MutableSubtree ts_subtree_to_mut_unsafe(Subtree self) +static inline t_mutable_subtree ts_subtree_to_mut_unsafe(t_subtree self) { - MutableSubtree result; + t_mutable_subtree result; result.data = self.data; return result; } -typedef enum +typedef enum e_tree_cursor_step { TreeCursorStepNone, TreeCursorStepHidden, TreeCursorStepVisible, -} TreeCursorStep; +} t_tree_cursor_step; -void ts_tree_cursor_init(TreeCursor *, TSNode); -void ts_tree_cursor_current_status(const TSTreeCursor *, TSFieldId *, bool *, - bool *, bool *, TSSymbol *, unsigned *); +void ts_tree_cursor_init(t_tree_cursor *, t_parse_node); +void ts_tree_cursor_current_status(const t_tree_cursor *, t_field_id *, bool *, + bool *, bool *, t_symbol *, unsigned *); -TreeCursorStep ts_tree_cursor_goto_first_child_internal(TSTreeCursor *); -TreeCursorStep ts_tree_cursor_goto_next_sibling_internal(TSTreeCursor *); +t_tree_cursor_step ts_tree_cursor_goto_first_child_internal(t_tree_cursor *); +t_tree_cursor_step ts_tree_cursor_goto_next_sibling_internal(t_tree_cursor *); -static inline Subtree ts_tree_cursor_current_subtree(const TSTreeCursor *_self) +static inline t_subtree ts_tree_cursor_current_subtree( + const t_tree_cursor *_self) { - const TreeCursor *self = (const TreeCursor *)_self; - TreeCursorEntry *last_entry = array_back(&self->stack); + const t_tree_cursor *self = (const t_tree_cursor *)_self; + t_tree_cursor_entry *last_entry = array_back(&self->stack); return *last_entry->subtree; } -TSNode ts_tree_cursor_parent_node(const TSTreeCursor *); +t_parse_node ts_tree_cursor_parent_node(const t_tree_cursor *); -typedef struct +typedef struct s_parent_cache_entry { - const Subtree *child; - const Subtree *parent; - Length position; - TSSymbol alias_symbol; -} ParentCacheEntry; + const t_subtree *child; + const t_subtree *parent; + t_length position; + t_symbol alias_symbol; +} t_parent_cache_entry; -struct TSTree +struct s_first_tree { - Subtree root; - const TSLanguage *language; - TSRange *included_ranges; + t_subtree root; + const t_language *language; + t_parse_range *included_ranges; unsigned included_range_count; }; -TSTree *ts_tree_new(Subtree root, const TSLanguage *language, const TSRange *, - unsigned); -TSNode ts_node_new(const TSTree *, const Subtree *, Length, TSSymbol); +t_first_tree *ts_tree_new(t_subtree root, const t_language *language, + const t_parse_range *, unsigned); +t_parse_node ts_node_new(const t_first_tree *, const t_subtree *, t_length, + t_symbol); -typedef uint64_t TSClock; -typedef uint64_t TSDuration; +typedef uint64_t t_parser_clock; +typedef uint64_t t_parser_duration; #endif // TREE_SITTER_TREE_H_ \ No newline at end of file diff --git a/parser/src/combined.c b/parser/src/combined.c index 3d650f8f..66156619 100644 --- a/parser/src/combined.c +++ b/parser/src/combined.c @@ -1,26 +1,28 @@ #include "./api.h" -uint32_t ts_node_end_byte(TSNode self); -TSNode ts_node_parent(TSNode self); -bool ts_node_is_null(TSNode self); -uint32_t ts_node_child_count(TSNode self); -TSNode ts_tree_root_node(const TSTree *self); -TSNode ts_node_child_containing_descendant(TSNode self, TSNode subnode); -void ts_parser_reset(TSParser *self); -bool ts_parser_set_language(TSParser *self, const TSLanguage *language); -void ts_query_delete(TSQuery *self); -void ts_tree_cursor_delete(TSTreeCursor *_self); -void ts_tree_cursor_reset(TSTreeCursor *_self, TSNode node); -bool ts_tree_cursor_goto_parent(TSTreeCursor *_self); -TSNode ts_tree_cursor_current_node(const TSTreeCursor *_self); +uint32_t ts_node_end_byte(t_parse_node self); +t_parse_node ts_node_parent(t_parse_node self); +bool ts_node_is_null(t_parse_node self); +uint32_t ts_node_child_count(t_parse_node self); +t_parse_node ts_tree_root_node(const t_first_tree *self); +t_parse_node ts_node_child_containing_descendant(t_parse_node self, + t_parse_node subnode); +void ts_parser_reset(t_first_parser *self); +bool ts_parser_set_language(t_first_parser *self, const t_language *language); +void ts_query_delete(t_parse_query *self); +void ts_tree_cursor_delete(t_tree_cursor *_self); +void ts_tree_cursor_reset(t_tree_cursor *_self, t_parse_node node); +bool ts_tree_cursor_goto_parent(t_tree_cursor *_self); +t_parse_node ts_tree_cursor_current_node(const t_tree_cursor *_self); // #define DEBUG_GET_CHANGED_RANGES -static void ts_range_array_add(TSRangeArray *self, Length start, Length end) +static void ts_range_array_add(t_range_array *self, t_length start, + t_length end) { if (self->size > 0) { - TSRange *last_range = array_back(self); + t_parse_range *last_range = array_back(self); if (start.bytes <= last_range->end_byte) { last_range->end_byte = end.bytes; @@ -31,17 +33,18 @@ static void ts_range_array_add(TSRangeArray *self, Length start, Length end) if (start.bytes < end.bytes) { - TSRange range = {start.extent, end.extent, start.bytes, end.bytes}; + t_parse_range range = {start.extent, end.extent, start.bytes, + end.bytes}; array_push(self, range); } } -bool ts_range_array_intersects(const TSRangeArray *self, unsigned start_index, +bool ts_range_array_intersects(const t_range_array *self, unsigned start_index, uint32_t start_byte, uint32_t end_byte) { for (unsigned i = start_index; i < self->size; i++) { - TSRange *range = &self->contents[i]; + t_parse_range *range = &self->contents[i]; if (range->end_byte > start_byte) { if (range->start_byte >= end_byte) @@ -52,49 +55,49 @@ bool ts_range_array_intersects(const TSRangeArray *self, unsigned start_index, return false; } -void ts_range_array_get_changed_ranges(const TSRange *old_ranges, - unsigned old_range_count, - const TSRange *new_ranges, - unsigned new_range_count, - TSRangeArray *differences) +void ts_range_array_get_changed_ranges(const t_parse_range *old_ranges, + unsigned old_range_count, + const t_parse_range *new_ranges, + unsigned new_range_count, + t_range_array *differences) { unsigned new_index = 0; unsigned old_index = 0; - Length current_position = length_zero(); + t_length current_position = length_zero(); bool in_old_range = false; bool in_new_range = false; while (old_index < old_range_count || new_index < new_range_count) { - const TSRange *old_range = &old_ranges[old_index]; - const TSRange *new_range = &new_ranges[new_index]; + const t_parse_range *old_range = &old_ranges[old_index]; + const t_parse_range *new_range = &new_ranges[new_index]; - Length next_old_position; + t_length next_old_position; if (in_old_range) { next_old_position = - (Length){old_range->end_byte, old_range->end_point}; + (t_length){old_range->end_byte, old_range->end_point}; } else if (old_index < old_range_count) { next_old_position = - (Length){old_range->start_byte, old_range->start_point}; + (t_length){old_range->start_byte, old_range->start_point}; } else { next_old_position = LENGTH_MAX; } - Length next_new_position; + t_length next_new_position; if (in_new_range) { next_new_position = - (Length){new_range->end_byte, new_range->end_point}; + (t_length){new_range->end_byte, new_range->end_point}; } else if (new_index < new_range_count) { next_new_position = - (Length){new_range->start_byte, new_range->start_point}; + (t_length){new_range->start_byte, new_range->start_point}; } else { @@ -145,17 +148,17 @@ void ts_range_array_get_changed_ranges(const TSRange *old_ranges, typedef struct { - TreeCursor cursor; - const TSLanguage *language; + t_tree_cursor cursor; + const t_language *language; unsigned visible_depth; bool in_padding; } Iterator; -static Iterator iterator_new(TreeCursor *cursor, const Subtree *tree, - const TSLanguage *language) +static Iterator iterator_new(t_tree_cursor *cursor, const t_subtree *tree, + const t_language *language) { array_clear(&cursor->stack); - array_push(&cursor->stack, ((TreeCursorEntry){ + array_push(&cursor->stack, ((t_tree_cursor_entry){ .subtree = tree, .position = length_zero(), .child_index = 0, @@ -174,9 +177,9 @@ static bool iterator_done(Iterator *self) return self->cursor.stack.size == 0; } -static Length iterator_start_position(Iterator *self) +static t_length iterator_start_position(Iterator *self) { - TreeCursorEntry entry = *array_back(&self->cursor.stack); + t_tree_cursor_entry entry = *array_back(&self->cursor.stack); if (self->in_padding) { return entry.position; @@ -187,10 +190,10 @@ static Length iterator_start_position(Iterator *self) } } -static Length iterator_end_position(Iterator *self) +static t_length iterator_end_position(Iterator *self) { - TreeCursorEntry entry = *array_back(&self->cursor.stack); - Length result = + t_tree_cursor_entry entry = *array_back(&self->cursor.stack); + t_length result = length_add(entry.position, ts_subtree_padding(*entry.subtree)); if (self->in_padding) { @@ -204,12 +207,12 @@ static Length iterator_end_position(Iterator *self) static bool iterator_tree_is_visible(const Iterator *self) { - TreeCursorEntry entry = *array_back(&self->cursor.stack); + t_tree_cursor_entry entry = *array_back(&self->cursor.stack); if (ts_subtree_visible(*entry.subtree)) return true; if (self->cursor.stack.size > 1) { - Subtree parent = + t_subtree parent = *self->cursor.stack.contents[self->cursor.stack.size - 2].subtree; return ts_language_alias_at(self->language, parent.ptr->production_id, entry.structural_child_index) != 0; @@ -217,8 +220,8 @@ static bool iterator_tree_is_visible(const Iterator *self) return false; } -static void iterator_get_visible_state(const Iterator *self, Subtree *tree, - TSSymbol *alias_symbol, +static void iterator_get_visible_state(const Iterator *self, t_subtree *tree, + t_symbol *alias_symbol, uint32_t *start_byte) { uint32_t i = self->cursor.stack.size - 1; @@ -232,11 +235,12 @@ static void iterator_get_visible_state(const Iterator *self, Subtree *tree, for (; i + 1 > 0; i--) { - TreeCursorEntry entry = self->cursor.stack.contents[i]; + t_tree_cursor_entry entry = self->cursor.stack.contents[i]; if (i > 0) { - const Subtree *parent = self->cursor.stack.contents[i - 1].subtree; + const t_subtree *parent = + self->cursor.stack.contents[i - 1].subtree; *alias_symbol = ts_language_alias_at(self->language, parent->ptr->production_id, entry.structural_child_index); @@ -271,22 +275,22 @@ static bool iterator_descend(Iterator *self, uint32_t goal_position) do { did_descend = false; - TreeCursorEntry entry = *array_back(&self->cursor.stack); - Length position = entry.position; - uint32_t structural_child_index = 0; + t_tree_cursor_entry entry = *array_back(&self->cursor.stack); + t_length position = entry.position; + uint32_t structural_child_index = 0; for (uint32_t i = 0, n = ts_subtree_child_count(*entry.subtree); i < n; i++) { - const Subtree *child = &ts_subtree_children(*entry.subtree)[i]; - Length child_left = + const t_subtree *child = &ts_subtree_children(*entry.subtree)[i]; + t_length child_left = length_add(position, ts_subtree_padding(*child)); - Length child_right = + t_length child_right = length_add(child_left, ts_subtree_size(*child)); if (child_right.bytes > goal_position) { array_push(&self->cursor.stack, - ((TreeCursorEntry){ + ((t_tree_cursor_entry){ .subtree = child, .position = position, .child_index = i, @@ -339,24 +343,24 @@ static void iterator_advance(Iterator *self) { if (iterator_tree_is_visible(self)) self->visible_depth--; - TreeCursorEntry entry = array_pop(&self->cursor.stack); + t_tree_cursor_entry entry = array_pop(&self->cursor.stack); if (iterator_done(self)) return; - const Subtree *parent = array_back(&self->cursor.stack)->subtree; - uint32_t child_index = entry.child_index + 1; + const t_subtree *parent = array_back(&self->cursor.stack)->subtree; + uint32_t child_index = entry.child_index + 1; if (ts_subtree_child_count(*parent) > child_index) { - Length position = length_add(entry.position, - ts_subtree_total_size(*entry.subtree)); + t_length position = length_add( + entry.position, ts_subtree_total_size(*entry.subtree)); uint32_t structural_child_index = entry.structural_child_index; if (!ts_subtree_extra(*entry.subtree)) structural_child_index++; - const Subtree *next_child = + const t_subtree *next_child = &ts_subtree_children(*parent)[child_index]; array_push(&self->cursor.stack, - ((TreeCursorEntry){ + ((t_tree_cursor_entry){ .subtree = next_child, .position = position, .child_index = child_index, @@ -393,12 +397,12 @@ typedef enum static IteratorComparison iterator_compare(const Iterator *old_iter, const Iterator *new_iter) { - Subtree old_tree = NULL_SUBTREE; - Subtree new_tree = NULL_SUBTREE; - uint32_t old_start = 0; - uint32_t new_start = 0; - TSSymbol old_alias_symbol = 0; - TSSymbol new_alias_symbol = 0; + t_subtree old_tree = NULL_SUBTREE; + t_subtree new_tree = NULL_SUBTREE; + uint32_t old_start = 0; + uint32_t new_start = 0; + t_symbol old_alias_symbol = 0; + t_symbol new_alias_symbol = 0; iterator_get_visible_state(old_iter, &old_tree, &old_alias_symbol, &old_start); iterator_get_visible_state(new_iter, &new_tree, &new_alias_symbol, @@ -435,10 +439,10 @@ static IteratorComparison iterator_compare(const Iterator *old_iter, #ifdef DEBUG_GET_CHANGED_RANGES static inline void iterator_print_state(Iterator *self) { - TreeCursorEntry entry = *array_back(&self->cursor.stack); - TSPoint start = iterator_start_position(self).extent; - TSPoint end = iterator_end_position(self).extent; - const char *name = ts_language_symbol_name( + t_tree_cursor_entry entry = *array_back(&self->cursor.stack); + t_point start = iterator_start_position(self).extent; + t_point end = iterator_end_position(self).extent; + const char *name = ts_language_symbol_name( self->language, ts_subtree_symbol(*entry.subtree)); printf("(%-25s %s\t depth:%u [%u, %u] - [%u, %u])", name, self->in_padding ? "(p)" : " ", self->visible_depth, start.row + 1, @@ -447,19 +451,19 @@ static inline void iterator_print_state(Iterator *self) #endif unsigned ts_subtree_get_changed_ranges( - const Subtree *old_tree, const Subtree *new_tree, TreeCursor *cursor1, - TreeCursor *cursor2, const TSLanguage *language, - const TSRangeArray *included_range_differences, TSRange **ranges) + const t_subtree *old_tree, const t_subtree *new_tree, + t_tree_cursor *cursor1, t_tree_cursor *cursor2, const t_language *language, + const t_range_array *included_range_differences, t_parse_range **ranges) { - TSRangeArray results = array_new(); + t_range_array results = array_new(); Iterator old_iter = iterator_new(cursor1, old_tree, language); Iterator new_iter = iterator_new(cursor2, new_tree, language); unsigned included_range_difference_index = 0; - Length position = iterator_start_position(&old_iter); - Length next_position = iterator_start_position(&new_iter); + t_length position = iterator_start_position(&old_iter); + t_length next_position = iterator_start_position(&new_iter); if (position.bytes < next_position.bytes) { ts_range_array_add(&results, position, next_position); @@ -573,7 +577,7 @@ unsigned ts_subtree_get_changed_ranges( while (included_range_difference_index < included_range_differences->size) { - const TSRange *range = + const t_parse_range *range = &included_range_differences ->contents[included_range_difference_index]; if (range->end_byte <= position.bytes) @@ -587,8 +591,8 @@ unsigned ts_subtree_get_changed_ranges( } } while (!iterator_done(&old_iter) && !iterator_done(&new_iter)); - Length old_size = ts_subtree_total_size(*old_tree); - Length new_size = ts_subtree_total_size(*new_tree); + t_length old_size = ts_subtree_total_size(*old_tree); + t_length new_size = ts_subtree_total_size(*new_tree); if (old_size.bytes < new_size.bytes) { ts_range_array_add(&results, old_size, new_size); @@ -604,38 +608,38 @@ unsigned ts_subtree_get_changed_ranges( return results.size; } -const TSLanguage *ts_language_copy(const TSLanguage *self) +const t_language *ts_language_copy(const t_language *self) { return self; } -void ts_language_delete(const TSLanguage *self) +void ts_language_delete(const t_language *self) { (void)(self); } -uint32_t ts_language_symbol_count(const TSLanguage *self) +uint32_t ts_language_symbol_count(const t_language *self) { return self->symbol_count + self->alias_count; } -uint32_t ts_language_state_count(const TSLanguage *self) +uint32_t ts_language_state_count(const t_language *self) { return self->state_count; } -uint32_t ts_language_version(const TSLanguage *self) +uint32_t ts_language_version(const t_language *self) { return self->version; } -uint32_t ts_language_field_count(const TSLanguage *self) +uint32_t ts_language_field_count(const t_language *self) { return self->field_count; } -void ts_language_table_entry(const TSLanguage *self, TSStateId state, - TSSymbol symbol, TableEntry *result) +void ts_language_table_entry(const t_language *self, t_state_id state, + t_symbol symbol, t_table_entry *result) { if (symbol == ts_builtin_sym_error || symbol == ts_builtin_sym_error_repeat) { @@ -647,23 +651,23 @@ void ts_language_table_entry(const TSLanguage *self, TSStateId state, { assert(symbol < self->token_count); uint32_t action_index = ts_language_lookup(self, state, symbol); - const TSParseActionEntry *entry = &self->parse_actions[action_index]; + const t_parse_action_entry *entry = &self->parse_actions[action_index]; result->action_count = entry->entry.count; result->is_reusable = entry->entry.reusable; - result->actions = (const TSParseAction *)(entry + 1); + result->actions = (const t_parse_action *)(entry + 1); } } -TSSymbolMetadata ts_language_symbol_metadata(const TSLanguage *self, - TSSymbol symbol) +t_symbol_metadata ts_language_symbol_metadata(const t_language *self, + t_symbol symbol) { if (symbol == ts_builtin_sym_error) { - return (TSSymbolMetadata){.visible = true, .named = true}; + return (t_symbol_metadata){.visible = true, .named = true}; } else if (symbol == ts_builtin_sym_error_repeat) { - return (TSSymbolMetadata){.visible = false, .named = false}; + return (t_symbol_metadata){.visible = false, .named = false}; } else { @@ -671,15 +675,15 @@ TSSymbolMetadata ts_language_symbol_metadata(const TSLanguage *self, } } -TSSymbol ts_language_public_symbol(const TSLanguage *self, TSSymbol symbol) +t_symbol ts_language_public_symbol(const t_language *self, t_symbol symbol) { if (symbol == ts_builtin_sym_error) return symbol; return self->public_symbol_map[symbol]; } -TSStateId ts_language_next_state(const TSLanguage *self, TSStateId state, - TSSymbol symbol) +t_state_id ts_language_next_state(const t_language *self, t_state_id state, + t_symbol symbol) { if (symbol == ts_builtin_sym_error || symbol == ts_builtin_sym_error_repeat) { @@ -687,12 +691,12 @@ TSStateId ts_language_next_state(const TSLanguage *self, TSStateId state, } else if (symbol < self->token_count) { - uint32_t count; - const TSParseAction *actions = + uint32_t count; + const t_parse_action *actions = ts_language_actions(self, state, symbol, &count); if (count > 0) { - TSParseAction action = actions[count - 1]; + t_parse_action action = actions[count - 1]; if (action.type == TSParseActionTypeShift) { return action.shift.extra ? state : action.shift.state; @@ -706,7 +710,7 @@ TSStateId ts_language_next_state(const TSLanguage *self, TSStateId state, } } -const char *ts_language_symbol_name(const TSLanguage *self, TSSymbol symbol) +const char *ts_language_symbol_name(const t_language *self, t_symbol symbol) { if (symbol == ts_builtin_sym_error) { @@ -726,15 +730,15 @@ const char *ts_language_symbol_name(const TSLanguage *self, TSSymbol symbol) } } -TSSymbol ts_language_symbol_for_name(const TSLanguage *self, const char *string, +t_symbol ts_language_symbol_for_name(const t_language *self, const char *string, uint32_t length, bool is_named) { if (!strncmp(string, "ERROR", length)) return ts_builtin_sym_error; uint16_t count = (uint16_t)ts_language_symbol_count(self); - for (TSSymbol i = 0; i < count; i++) + for (t_symbol i = 0; i < count; i++) { - TSSymbolMetadata metadata = ts_language_symbol_metadata(self, i); + t_symbol_metadata metadata = ts_language_symbol_metadata(self, i); if ((!metadata.visible && !metadata.supertype) || metadata.named != is_named) continue; @@ -747,9 +751,9 @@ TSSymbol ts_language_symbol_for_name(const TSLanguage *self, const char *string, return 0; } -TSSymbolType ts_language_symbol_type(const TSLanguage *self, TSSymbol symbol) +t_symbol_type ts_language_symbol_type(const t_language *self, t_symbol symbol) { - TSSymbolMetadata metadata = ts_language_symbol_metadata(self, symbol); + t_symbol_metadata metadata = ts_language_symbol_metadata(self, symbol); if (metadata.named && metadata.visible) { return TSSymbolTypeRegular; @@ -764,7 +768,7 @@ TSSymbolType ts_language_symbol_type(const TSLanguage *self, TSSymbol symbol) } } -const char *ts_language_field_name_for_id(const TSLanguage *self, TSFieldId id) +const char *ts_language_field_name_for_id(const t_language *self, t_field_id id) { uint32_t count = ts_language_field_count(self); if (count && id <= count) @@ -777,11 +781,11 @@ const char *ts_language_field_name_for_id(const TSLanguage *self, TSFieldId id) } } -TSFieldId ts_language_field_id_for_name(const TSLanguage *self, - const char *name, uint32_t name_length) +t_field_id ts_language_field_id_for_name(const t_language *self, + const char *name, uint32_t name_length) { uint16_t count = (uint16_t)ts_language_field_count(self); - for (TSSymbol i = 1; i < count + 1; i++) + for (t_symbol i = 1; i < count + 1; i++) { switch (strncmp(name, self->field_names[i], name_length)) { @@ -798,94 +802,94 @@ TSFieldId ts_language_field_id_for_name(const TSLanguage *self, return 0; } -TSLookaheadIterator *ts_lookahead_iterator_new(const TSLanguage *self, - TSStateId state) +t_lookahead_iterator *ts_lookahead_iterator_new(const t_language *self, + t_state_id state) { if (state >= self->state_count) return NULL; - LookaheadIterator *iterator = malloc(sizeof(LookaheadIterator)); + t_lookahead_iterator *iterator = malloc(sizeof(t_lookahead_iterator)); *iterator = ts_language_lookaheads(self, state); - return (TSLookaheadIterator *)iterator; + return (t_lookahead_iterator *)iterator; } -void ts_lookahead_iterator_delete(TSLookaheadIterator *self) +void ts_lookahead_iterator_delete(t_lookahead_iterator *self) { free(self); } -bool ts_lookahead_iterator_reset_state(TSLookaheadIterator *self, - TSStateId state) +bool ts_lookahead_iterator_reset_state(t_lookahead_iterator *self, + t_state_id state) { - LookaheadIterator *iterator = (LookaheadIterator *)self; + t_lookahead_iterator *iterator = (t_lookahead_iterator *)self; if (state >= iterator->language->state_count) return false; *iterator = ts_language_lookaheads(iterator->language, state); return true; } -const TSLanguage *ts_lookahead_iterator_language( - const TSLookaheadIterator *self) +const t_language *ts_lookahead_iterator_language( + const t_lookahead_iterator *self) { - const LookaheadIterator *iterator = (const LookaheadIterator *)self; + const t_lookahead_iterator *iterator = (const t_lookahead_iterator *)self; return iterator->language; } -bool ts_lookahead_iterator_reset(TSLookaheadIterator *self, - const TSLanguage *language, TSStateId state) +bool ts_lookahead_iterator_reset(t_lookahead_iterator *self, + const t_language *language, t_state_id state) { if (state >= language->state_count) return false; - LookaheadIterator *iterator = (LookaheadIterator *)self; + t_lookahead_iterator *iterator = (t_lookahead_iterator *)self; *iterator = ts_language_lookaheads(language, state); return true; } -bool ts_lookahead_iterator_next(TSLookaheadIterator *self) +bool ts_lookahead_iterator_next(t_lookahead_iterator *self) { - LookaheadIterator *iterator = (LookaheadIterator *)self; + t_lookahead_iterator *iterator = (t_lookahead_iterator *)self; return ts_lookahead_iterator__next(iterator); } -TSSymbol ts_lookahead_iterator_current_symbol(const TSLookaheadIterator *self) +t_symbol ts_lookahead_iterator_current_symbol(const t_lookahead_iterator *self) { - const LookaheadIterator *iterator = (const LookaheadIterator *)self; + const t_lookahead_iterator *iterator = (const t_lookahead_iterator *)self; return iterator->symbol; } const char *ts_lookahead_iterator_current_symbol_name( - const TSLookaheadIterator *self) + const t_lookahead_iterator *self) { - const LookaheadIterator *iterator = (const LookaheadIterator *)self; + const t_lookahead_iterator *iterator = (const t_lookahead_iterator *)self; return ts_language_symbol_name(iterator->language, iterator->symbol); } static const int32_t BYTE_ORDER_MARK = 0xFEFF; -static const TSRange DEFAULT_RANGE = {.start_point = - { - .row = 0, - .column = 0, - }, - .end_point = - { - .row = UINT32_MAX, - .column = UINT32_MAX, - }, - .start_byte = 0, - .end_byte = UINT32_MAX}; +static const t_parse_range DEFAULT_RANGE = {.start_point = + { + .row = 0, + .column = 0, + }, + .end_point = + { + .row = UINT32_MAX, + .column = UINT32_MAX, + }, + .start_byte = 0, + .end_byte = UINT32_MAX}; // Check if the lexer has reached EOF. This state is stored // by setting the lexer's `current_included_range_index` such that // it has consumed all of its available ranges. -static bool ts_lexer__eof(const TSLexer *_self) +static bool ts_lexer__eof(const t_lexer_data *_self) { - Lexer *self = (Lexer *)_self; + t_lexer *self = (t_lexer *)_self; return self->current_included_range_index == self->included_range_count; } // Clear the currently stored chunk of source code, because the lexer's // position has changed. -static void ts_lexer__clear_chunk(Lexer *self) +static void ts_lexer__clear_chunk(t_lexer *self) { self->chunk = NULL; self->chunk_size = 0; @@ -894,7 +898,7 @@ static void ts_lexer__clear_chunk(Lexer *self) // Call the lexer's input callback to obtain a new chunk of source code // for the current position. -static void ts_lexer__get_chunk(Lexer *self) +static void ts_lexer__get_chunk(t_lexer *self) { self->chunk_start = self->current_position.bytes; self->chunk = @@ -909,18 +913,18 @@ static void ts_lexer__get_chunk(Lexer *self) uint32_t ascii_decode(const uint8_t *chunk, uint32_t size, int32_t *codepoint) { - (void)(size); - *(uint8_t *)codepoint = *chunk; - return (1); + (void)(size); + *(uint8_t *)codepoint = *chunk; + return (1); } typedef uint32_t (*UnicodeDecodeFunction)(const uint8_t *chunk, uint32_t size, - int32_t *codepoint); + int32_t *codepoint); // Decode the next unicode character in the current chunk of source code. // This assumes that the lexer has already retrieved a chunk of source // code that spans the current position. -static void ts_lexer__get_lookahead(Lexer *self) +static void ts_lexer__get_lookahead(t_lexer *self) { uint32_t position_in_chunk = self->current_position.bytes - self->chunk_start; @@ -954,7 +958,7 @@ static void ts_lexer__get_lookahead(Lexer *self) } } -static void ts_lexer_goto(Lexer *self, Length position) +static void ts_lexer_goto(t_lexer *self, t_length position) { self->current_position = position; @@ -962,13 +966,13 @@ static void ts_lexer_goto(Lexer *self, Length position) bool found_included_range = false; for (unsigned i = 0; i < self->included_range_count; i++) { - TSRange *included_range = &self->included_ranges[i]; + t_parse_range *included_range = &self->included_ranges[i]; if (included_range->end_byte > self->current_position.bytes && included_range->end_byte > included_range->start_byte) { if (included_range->start_byte >= self->current_position.bytes) { - self->current_position = (Length){ + self->current_position = (t_length){ .bytes = included_range->start_byte, .extent = included_range->start_point, }; @@ -1000,9 +1004,9 @@ static void ts_lexer_goto(Lexer *self, Length position) else { self->current_included_range_index = self->included_range_count; - TSRange *last_included_range = + t_parse_range *last_included_range = &self->included_ranges[self->included_range_count - 1]; - self->current_position = (Length){ + self->current_position = (t_length){ .bytes = last_included_range->end_byte, .extent = last_included_range->end_point, }; @@ -1013,7 +1017,7 @@ static void ts_lexer_goto(Lexer *self, Length position) } // Intended to be called only from functions that control logging. -static void ts_lexer__do_advance(Lexer *self, bool skip) +static void ts_lexer__do_advance(t_lexer *self, bool skip) { if (self->lookahead_size) { @@ -1029,7 +1033,7 @@ static void ts_lexer__do_advance(Lexer *self, bool skip) } } - const TSRange *current_range = + const t_parse_range *current_range = &self->included_ranges[self->current_included_range_index]; while (self->current_position.bytes >= current_range->end_byte || current_range->end_byte == current_range->start_byte) @@ -1041,7 +1045,7 @@ static void ts_lexer__do_advance(Lexer *self, bool skip) if (self->current_included_range_index < self->included_range_count) { current_range++; - self->current_position = (Length){ + self->current_position = (t_length){ current_range->start_byte, current_range->start_point, }; @@ -1076,9 +1080,9 @@ static void ts_lexer__do_advance(Lexer *self, bool skip) // Advance to the next character in the source code, retrieving a new // chunk of source code if needed. -static void ts_lexer__advance(TSLexer *_self, bool skip) +static void ts_lexer__advance(t_lexer_data *_self, bool skip) { - Lexer *self = (Lexer *)_self; + t_lexer *self = (t_lexer *)_self; if (!self->chunk) return; @@ -1094,21 +1098,21 @@ static void ts_lexer__advance(TSLexer *_self, bool skip) // Mark that a token match has completed. This can be called multiple // times if a longer match is found later. -static void ts_lexer__mark_end(TSLexer *_self) +static void ts_lexer__mark_end(t_lexer_data *_self) { - Lexer *self = (Lexer *)_self; + t_lexer *self = (t_lexer *)_self; if (!ts_lexer__eof(&self->data)) { // If the lexer is right at the beginning of included range, // then the token should be considered to end at the *end* of the // previous included range, rather than here. - TSRange *current_included_range = + t_parse_range *current_included_range = &self->included_ranges[self->current_included_range_index]; if (self->current_included_range_index > 0 && self->current_position.bytes == current_included_range->start_byte) { - TSRange *previous_included_range = current_included_range - 1; - self->token_end_position = (Length){ + t_parse_range *previous_included_range = current_included_range - 1; + self->token_end_position = (t_length){ previous_included_range->end_byte, previous_included_range->end_point, }; @@ -1118,9 +1122,9 @@ static void ts_lexer__mark_end(TSLexer *_self) self->token_end_position = self->current_position; } -static uint32_t ts_lexer__get_column(TSLexer *_self) +static uint32_t ts_lexer__get_column(t_lexer_data *_self) { - Lexer *self = (Lexer *)_self; + t_lexer *self = (t_lexer *)_self; uint32_t goal_byte = self->current_position.bytes; @@ -1152,12 +1156,12 @@ static uint32_t ts_lexer__get_column(TSLexer *_self) // Is the lexer at a boundary between two disjoint included ranges of // source code? This is exposed as an API because some languages' external // scanners need to perform custom actions at these boundaries. -static bool ts_lexer__is_at_included_range_start(const TSLexer *_self) +static bool ts_lexer__is_at_included_range_start(const t_lexer_data *_self) { - const Lexer *self = (const Lexer *)_self; + const t_lexer *self = (const t_lexer *)_self; if (self->current_included_range_index < self->included_range_count) { - TSRange *current_range = + t_parse_range *current_range = &self->included_ranges[self->current_included_range_index]; return self->current_position.bytes == current_range->start_byte; } @@ -1167,9 +1171,9 @@ static bool ts_lexer__is_at_included_range_start(const TSLexer *_self) } } -void ts_lexer_init(Lexer *self) +void ts_lexer_init(t_lexer *self) { - *self = (Lexer){ + *self = (t_lexer){ .data = { // The lexer's methods are stored as struct fields so that @@ -1198,12 +1202,12 @@ void ts_lexer_init(Lexer *self) ts_lexer_set_included_ranges(self, NULL, 0); } -void ts_lexer_delete(Lexer *self) +void ts_lexer_delete(t_lexer *self) { free(self->included_ranges); } -void ts_lexer_set_input(Lexer *self, TSInput input) +void ts_lexer_set_input(t_lexer *self, t_parse_input input) { self->input = input; ts_lexer__clear_chunk(self); @@ -1212,7 +1216,7 @@ void ts_lexer_set_input(Lexer *self, TSInput input) // Move the lexer to the given position. This doesn't do any work // if the parser is already at the given position. -void ts_lexer_reset(Lexer *self, Length position) +void ts_lexer_reset(t_lexer *self, t_length position) { if (position.bytes != self->current_position.bytes) { @@ -1220,7 +1224,7 @@ void ts_lexer_reset(Lexer *self, Length position) } } -void ts_lexer_start(Lexer *self) +void ts_lexer_start(t_lexer *self) { self->token_start_position = self->current_position; self->token_end_position = LENGTH_UNDEFINED; @@ -1238,7 +1242,7 @@ void ts_lexer_start(Lexer *self) } } -void ts_lexer_finish(Lexer *self, uint32_t *lookahead_end_byte) +void ts_lexer_finish(t_lexer *self, uint32_t *lookahead_end_byte) { if (length_is_undefined(self->token_end_position)) { @@ -1271,7 +1275,7 @@ void ts_lexer_finish(Lexer *self, uint32_t *lookahead_end_byte) } } -void ts_lexer_advance_to_end(Lexer *self) +void ts_lexer_advance_to_end(t_lexer *self) { while (self->chunk) { @@ -1279,12 +1283,12 @@ void ts_lexer_advance_to_end(Lexer *self) } } -void ts_lexer_mark_end(Lexer *self) +void ts_lexer_mark_end(t_lexer *self) { ts_lexer__mark_end(&self->data); } -bool ts_lexer_set_included_ranges(Lexer *self, const TSRange *ranges, +bool ts_lexer_set_included_ranges(t_lexer *self, const t_parse_range *ranges, uint32_t count) { if (count == 0 || !ranges) @@ -1297,7 +1301,7 @@ bool ts_lexer_set_included_ranges(Lexer *self, const TSRange *ranges, uint32_t previous_byte = 0; for (unsigned i = 0; i < count; i++) { - const TSRange *range = &ranges[i]; + const t_parse_range *range = &ranges[i]; if (range->start_byte < previous_byte || range->end_byte < range->start_byte) return false; @@ -1305,7 +1309,7 @@ bool ts_lexer_set_included_ranges(Lexer *self, const TSRange *ranges, } } - size_t size = count * sizeof(TSRange); + size_t size = count * sizeof(t_parse_range); self->included_ranges = realloc(self->included_ranges, size); memcpy(self->included_ranges, ranges, size); self->included_range_count = count; @@ -1313,7 +1317,7 @@ bool ts_lexer_set_included_ranges(Lexer *self, const TSRange *ranges, return true; } -TSRange *ts_lexer_included_ranges(const Lexer *self, uint32_t *count) +t_parse_range *ts_lexer_included_ranges(const t_lexer *self, uint32_t *count) { *count = self->included_range_count; return self->included_ranges; @@ -1323,64 +1327,65 @@ TSRange *ts_lexer_included_ranges(const Lexer *self, uint32_t *count) typedef struct { - Subtree parent; - const TSTree *tree; - Length position; - uint32_t child_index; - uint32_t structural_child_index; - const TSSymbol *alias_sequence; + t_subtree parent; + const t_first_tree *tree; + t_length position; + uint32_t child_index; + uint32_t structural_child_index; + const t_symbol *alias_sequence; } NodeChildIterator; -// TSNode - constructors +// t_parse_node - constructors -TSNode ts_node_new(const TSTree *tree, const Subtree *subtree, Length position, - TSSymbol alias) +t_parse_node ts_node_new(const t_first_tree *tree, const t_subtree *subtree, + t_length position, t_symbol alias) { - return (TSNode){ + return (t_parse_node){ {position.bytes, position.extent.row, position.extent.column, alias}, subtree, tree, }; } -static inline TSNode ts_node__null(void) +static inline t_parse_node ts_node__null(void) { return ts_node_new(NULL, NULL, length_zero(), 0); } -// TSNode - accessors +// t_parse_node - accessors -uint32_t ts_node_start_byte(TSNode self) +uint32_t ts_node_start_byte(t_parse_node self) { return self.context[0]; } -TSPoint ts_node_start_point(TSNode self) +t_point ts_node_start_point(t_parse_node self) { - return (TSPoint){self.context[1], self.context[2]}; + return (t_point){self.context[1], self.context[2]}; } -static inline uint32_t ts_node__alias(const TSNode *self) +static inline uint32_t ts_node__alias(const t_parse_node *self) { return self->context[3]; } -static inline Subtree ts_node__subtree(TSNode self) +static inline t_subtree ts_node__subtree(t_parse_node self) { - return *(const Subtree *)self.id; + return *(const t_subtree *)self.id; } // NodeChildIterator -static inline NodeChildIterator ts_node_iterate_children(const TSNode *node) +static inline NodeChildIterator ts_node_iterate_children( + const t_parse_node *node) { - Subtree subtree = ts_node__subtree(*node); + t_subtree subtree = ts_node__subtree(*node); if (ts_subtree_child_count(subtree) == 0) { return (NodeChildIterator){ NULL_SUBTREE, node->tree, length_zero(), 0, 0, NULL}; } - const TSSymbol *alias_sequence = ts_language_alias_sequence( + const t_symbol *alias_sequence = ts_language_alias_sequence( node->tree->language, subtree.ptr->production_id); return (NodeChildIterator){ .tree = node->tree, @@ -1398,13 +1403,13 @@ static inline bool ts_node_child_iterator_done(NodeChildIterator *self) } static inline bool ts_node_child_iterator_next(NodeChildIterator *self, - TSNode *result) + t_parse_node *result) { if (!self->parent.ptr || ts_node_child_iterator_done(self)) return false; - const Subtree *child = + const t_subtree *child = &ts_subtree_children(self->parent)[self->child_index]; - TSSymbol alias_symbol = 0; + t_symbol alias_symbol = 0; if (!ts_subtree_extra(*child)) { if (self->alias_sequence) @@ -1423,18 +1428,19 @@ static inline bool ts_node_child_iterator_next(NodeChildIterator *self, return true; } -// TSNode - private +// t_parse_node - private -static inline bool ts_node__is_relevant(TSNode self, bool include_anonymous) +static inline bool ts_node__is_relevant(t_parse_node self, + bool include_anonymous) { - Subtree tree = ts_node__subtree(self); + t_subtree tree = ts_node__subtree(self); if (include_anonymous) { return ts_subtree_visible(tree) || ts_node__alias(&self); } else { - TSSymbol alias = ts_node__alias(&self); + t_symbol alias = ts_node__alias(&self); if (alias) { return ts_language_symbol_metadata(self.tree->language, alias) @@ -1447,10 +1453,10 @@ static inline bool ts_node__is_relevant(TSNode self, bool include_anonymous) } } -static inline uint32_t ts_node__relevant_child_count(TSNode self, - bool include_anonymous) +static inline uint32_t ts_node__relevant_child_count(t_parse_node self, + bool include_anonymous) { - Subtree tree = ts_node__subtree(self); + t_subtree tree = ts_node__subtree(self); if (ts_subtree_child_count(tree) > 0) { if (include_anonymous) @@ -1468,17 +1474,18 @@ static inline uint32_t ts_node__relevant_child_count(TSNode self, } } -static inline TSNode ts_node__child(TSNode self, uint32_t child_index, - bool include_anonymous) +static inline t_parse_node ts_node__child(t_parse_node self, + uint32_t child_index, + bool include_anonymous) { - TSNode result = self; - bool did_descend = true; + t_parse_node result = self; + bool did_descend = true; while (did_descend) { did_descend = false; - TSNode child; + t_parse_node child; uint32_t index = 0; NodeChildIterator iterator = ts_node_iterate_children(&result); while (ts_node_child_iterator_next(&iterator, &child)) @@ -1511,12 +1518,12 @@ static inline TSNode ts_node__child(TSNode self, uint32_t child_index, return ts_node__null(); } -static bool ts_subtree_has_trailing_empty_descendant(Subtree self, - Subtree other) +static bool ts_subtree_has_trailing_empty_descendant(t_subtree self, + t_subtree other) { for (unsigned i = ts_subtree_child_count(self) - 1; i + 1 > 0; i--) { - Subtree child = ts_subtree_children(self)[i]; + t_subtree child = ts_subtree_children(self)[i]; if (ts_subtree_total_bytes(child) > 0) break; if (child.ptr == other.ptr || @@ -1528,23 +1535,24 @@ static bool ts_subtree_has_trailing_empty_descendant(Subtree self, return false; } -static inline TSNode ts_node__prev_sibling(TSNode self, bool include_anonymous) +static inline t_parse_node ts_node__prev_sibling(t_parse_node self, + bool include_anonymous) { - Subtree self_subtree = ts_node__subtree(self); - bool self_is_empty = ts_subtree_total_bytes(self_subtree) == 0; - uint32_t target_end_byte = ts_node_end_byte(self); + t_subtree self_subtree = ts_node__subtree(self); + bool self_is_empty = ts_subtree_total_bytes(self_subtree) == 0; + uint32_t target_end_byte = ts_node_end_byte(self); - TSNode node = ts_node_parent(self); - TSNode earlier_node = ts_node__null(); - bool earlier_node_is_relevant = false; + t_parse_node node = ts_node_parent(self); + t_parse_node earlier_node = ts_node__null(); + bool earlier_node_is_relevant = false; while (!ts_node_is_null(node)) { - TSNode earlier_child = ts_node__null(); - bool earlier_child_is_relevant = false; - bool found_child_containing_target = false; + t_parse_node earlier_child = ts_node__null(); + bool earlier_child_is_relevant = false; + bool found_child_containing_target = false; - TSNode child; + t_parse_node child; NodeChildIterator iterator = ts_node_iterate_children(&node); while (ts_node_child_iterator_next(&iterator, &child)) { @@ -1609,21 +1617,22 @@ static inline TSNode ts_node__prev_sibling(TSNode self, bool include_anonymous) return ts_node__null(); } -static inline TSNode ts_node__next_sibling(TSNode self, bool include_anonymous) +static inline t_parse_node ts_node__next_sibling(t_parse_node self, + bool include_anonymous) { uint32_t target_end_byte = ts_node_end_byte(self); - TSNode node = ts_node_parent(self); - TSNode later_node = ts_node__null(); - bool later_node_is_relevant = false; + t_parse_node node = ts_node_parent(self); + t_parse_node later_node = ts_node__null(); + bool later_node_is_relevant = false; while (!ts_node_is_null(node)) { - TSNode later_child = ts_node__null(); - bool later_child_is_relevant = false; - TSNode child_containing_target = ts_node__null(); + t_parse_node later_child = ts_node__null(); + bool later_child_is_relevant = false; + t_parse_node child_containing_target = ts_node__null(); - TSNode child; + t_parse_node child; NodeChildIterator iterator = ts_node_iterate_children(&node); while (ts_node_child_iterator_next(&iterator, &child)) { @@ -1681,17 +1690,18 @@ static inline TSNode ts_node__next_sibling(TSNode self, bool include_anonymous) return ts_node__null(); } -static inline TSNode ts_node__first_child_for_byte(TSNode self, uint32_t goal, - bool include_anonymous) +static inline t_parse_node ts_node__first_child_for_byte(t_parse_node self, + uint32_t goal, + bool include_anonymous) { - TSNode node = self; - bool did_descend = true; + t_parse_node node = self; + bool did_descend = true; while (did_descend) { did_descend = false; - TSNode child; + t_parse_node child; NodeChildIterator iterator = ts_node_iterate_children(&node); while (ts_node_child_iterator_next(&iterator, &child)) { @@ -1714,20 +1724,19 @@ static inline TSNode ts_node__first_child_for_byte(TSNode self, uint32_t goal, return ts_node__null(); } -static inline TSNode ts_node__descendant_for_byte_range(TSNode self, - uint32_t range_start, - uint32_t range_end, - bool include_anonymous) +static inline t_parse_node ts_node__descendant_for_byte_range( + t_parse_node self, uint32_t range_start, uint32_t range_end, + bool include_anonymous) { - TSNode node = self; - TSNode last_visible_node = self; + t_parse_node node = self; + t_parse_node last_visible_node = self; bool did_descend = true; while (did_descend) { did_descend = false; - TSNode child; + t_parse_node child; NodeChildIterator iterator = ts_node_iterate_children(&node); while (ts_node_child_iterator_next(&iterator, &child)) { @@ -1758,24 +1767,23 @@ static inline TSNode ts_node__descendant_for_byte_range(TSNode self, return last_visible_node; } -static inline TSNode ts_node__descendant_for_point_range(TSNode self, - TSPoint range_start, - TSPoint range_end, - bool include_anonymous) +static inline t_parse_node ts_node__descendant_for_point_range( + t_parse_node self, t_point range_start, t_point range_end, + bool include_anonymous) { - TSNode node = self; - TSNode last_visible_node = self; + t_parse_node node = self; + t_parse_node last_visible_node = self; bool did_descend = true; while (did_descend) { did_descend = false; - TSNode child; + t_parse_node child; NodeChildIterator iterator = ts_node_iterate_children(&node); while (ts_node_child_iterator_next(&iterator, &child)) { - TSPoint node_end = iterator.position.extent; + t_point node_end = iterator.position.extent; // The end of this node must extend far enough forward to touch // the end of the range and exceed the start of the range. @@ -1802,117 +1810,117 @@ static inline TSNode ts_node__descendant_for_point_range(TSNode self, return last_visible_node; } -// TSNode - public +// t_parse_node - public -uint32_t ts_node_end_byte(TSNode self) +uint32_t ts_node_end_byte(t_parse_node self) { return ts_node_start_byte(self) + ts_subtree_size(ts_node__subtree(self)).bytes; } -TSPoint ts_node_end_point(TSNode self) +t_point ts_node_end_point(t_parse_node self) { return point_add(ts_node_start_point(self), ts_subtree_size(ts_node__subtree(self)).extent); } -TSSymbol ts_node_symbol(TSNode self) +t_symbol ts_node_symbol(t_parse_node self) { - TSSymbol symbol = ts_node__alias(&self); + t_symbol symbol = ts_node__alias(&self); if (!symbol) symbol = ts_subtree_symbol(ts_node__subtree(self)); return ts_language_public_symbol(self.tree->language, symbol); } -const char *ts_node_type(TSNode self) +const char *ts_node_type(t_parse_node self) { - TSSymbol symbol = ts_node__alias(&self); + t_symbol symbol = ts_node__alias(&self); if (!symbol) symbol = ts_subtree_symbol(ts_node__subtree(self)); return ts_language_symbol_name(self.tree->language, symbol); } -const TSLanguage *ts_node_language(TSNode self) +const t_language *ts_node_language(t_parse_node self) { return self.tree->language; } -TSSymbol ts_node_grammar_symbol(TSNode self) +t_symbol ts_node_grammar_symbol(t_parse_node self) { return ts_subtree_symbol(ts_node__subtree(self)); } -const char *ts_node_grammar_type(TSNode self) +const char *ts_node_grammar_type(t_parse_node self) { - TSSymbol symbol = ts_subtree_symbol(ts_node__subtree(self)); + t_symbol symbol = ts_subtree_symbol(ts_node__subtree(self)); return ts_language_symbol_name(self.tree->language, symbol); } -char *ts_node_string(TSNode self) +char *ts_node_string(t_parse_node self) { - TSSymbol alias_symbol = ts_node__alias(&self); + t_symbol alias_symbol = ts_node__alias(&self); return ts_subtree_string( ts_node__subtree(self), alias_symbol, ts_language_symbol_metadata(self.tree->language, alias_symbol).visible, self.tree->language, false); } -bool ts_node_eq(TSNode self, TSNode other) +bool ts_node_eq(t_parse_node self, t_parse_node other) { return self.tree == other.tree && self.id == other.id; } -bool ts_node_is_null(TSNode self) +bool ts_node_is_null(t_parse_node self) { return self.id == 0; } -bool ts_node_is_extra(TSNode self) +bool ts_node_is_extra(t_parse_node self) { return ts_subtree_extra(ts_node__subtree(self)); } -bool ts_node_is_named(TSNode self) +bool ts_node_is_named(t_parse_node self) { - TSSymbol alias = ts_node__alias(&self); + t_symbol alias = ts_node__alias(&self); return alias ? ts_language_symbol_metadata(self.tree->language, alias).named : ts_subtree_named(ts_node__subtree(self)); } -bool ts_node_is_missing(TSNode self) +bool ts_node_is_missing(t_parse_node self) { return ts_subtree_missing(ts_node__subtree(self)); } -bool ts_node_has_changes(TSNode self) +bool ts_node_has_changes(t_parse_node self) { return ts_subtree_has_changes(ts_node__subtree(self)); } -bool ts_node_has_error(TSNode self) +bool ts_node_has_error(t_parse_node self) { return ts_subtree_error_cost(ts_node__subtree(self)) > 0; } -bool ts_node_is_error(TSNode self) +bool ts_node_is_error(t_parse_node self) { - TSSymbol symbol = ts_node_symbol(self); + t_symbol symbol = ts_node_symbol(self); return symbol == ts_builtin_sym_error; } -uint32_t ts_node_descendant_count(TSNode self) +uint32_t ts_node_descendant_count(t_parse_node self) { return ts_subtree_visible_descendant_count(ts_node__subtree(self)) + 1; } -TSStateId ts_node_parse_state(TSNode self) +t_state_id ts_node_parse_state(t_parse_node self) { return ts_subtree_parse_state(ts_node__subtree(self)); } -TSStateId ts_node_next_parse_state(TSNode self) +t_state_id ts_node_next_parse_state(t_parse_node self) { - const TSLanguage *language = self.tree->language; + const t_language *language = self.tree->language; uint16_t state = ts_node_parse_state(self); if (state == TS_TREE_STATE_NONE) { @@ -1922,15 +1930,16 @@ TSStateId ts_node_next_parse_state(TSNode self) return ts_language_next_state(language, state, symbol); } -TSNode ts_node_parent(TSNode self) +t_parse_node ts_node_parent(t_parse_node self) { - TSNode node = ts_tree_root_node(self.tree); + t_parse_node node = ts_tree_root_node(self.tree); if (node.id == self.id) return ts_node__null(); while (true) { - TSNode next_node = ts_node_child_containing_descendant(node, self); + t_parse_node next_node = + ts_node_child_containing_descendant(node, self); if (ts_node_is_null(next_node)) break; node = next_node; @@ -1939,7 +1948,8 @@ TSNode ts_node_parent(TSNode self) return node; } -TSNode ts_node_child_containing_descendant(TSNode self, TSNode subnode) +t_parse_node ts_node_child_containing_descendant(t_parse_node self, + t_parse_node subnode) { uint32_t start_byte = ts_node_start_byte(subnode); uint32_t end_byte = ts_node_end_byte(subnode); @@ -1961,23 +1971,23 @@ TSNode ts_node_child_containing_descendant(TSNode self, TSNode subnode) return self; } -TSNode ts_node_child(TSNode self, uint32_t child_index) +t_parse_node ts_node_child(t_parse_node self, uint32_t child_index) { return ts_node__child(self, child_index, true); } -TSNode ts_node_named_child(TSNode self, uint32_t child_index) +t_parse_node ts_node_named_child(t_parse_node self, uint32_t child_index) { return ts_node__child(self, child_index, false); } -TSNode ts_node_child_by_field_id(TSNode self, TSFieldId field_id) +t_parse_node ts_node_child_by_field_id(t_parse_node self, t_field_id field_id) { recur: if (!field_id || ts_node_child_count(self) == 0) return ts_node__null(); - const TSFieldMapEntry *field_map, *field_map_end; + const t_field_map_entry *field_map, *field_map_end; ts_language_field_map(self.tree->language, ts_node__subtree(self).ptr->production_id, &field_map, &field_map_end); @@ -1999,7 +2009,7 @@ recur: return ts_node__null(); } - TSNode child; + t_parse_node child; NodeChildIterator iterator = ts_node_iterate_children(&self); while (ts_node_child_iterator_next(&iterator, &child)) { @@ -2025,7 +2035,8 @@ recur: // the field, continue searching subsequent children. else { - TSNode result = ts_node_child_by_field_id(child, field_id); + t_parse_node result = + ts_node_child_by_field_id(child, field_id); if (result.id) return result; field_map++; @@ -2060,9 +2071,9 @@ recur: } static inline const char *ts_node__field_name_from_language( - TSNode self, uint32_t structural_child_index) + t_parse_node self, uint32_t structural_child_index) { - const TSFieldMapEntry *field_map, *field_map_end; + const t_field_map_entry *field_map, *field_map_end; ts_language_field_map(self.tree->language, ts_node__subtree(self).ptr->production_id, &field_map, &field_map_end); @@ -2077,17 +2088,18 @@ static inline const char *ts_node__field_name_from_language( return NULL; } -const char *ts_node_field_name_for_child(TSNode self, uint32_t child_index) +const char *ts_node_field_name_for_child(t_parse_node self, + uint32_t child_index) { - TSNode result = self; - bool did_descend = true; - const char *inherited_field_name = NULL; + t_parse_node result = self; + bool did_descend = true; + const char *inherited_field_name = NULL; while (did_descend) { did_descend = false; - TSNode child; + t_parse_node child; uint32_t index = 0; NodeChildIterator iterator = ts_node_iterate_children(&result); while (ts_node_child_iterator_next(&iterator, &child)) @@ -2133,17 +2145,17 @@ const char *ts_node_field_name_for_child(TSNode self, uint32_t child_index) return NULL; } -TSNode ts_node_child_by_field_name(TSNode self, const char *name, - uint32_t name_length) +t_parse_node ts_node_child_by_field_name(t_parse_node self, const char *name, + uint32_t name_length) { - TSFieldId field_id = + t_field_id field_id = ts_language_field_id_for_name(self.tree->language, name, name_length); return ts_node_child_by_field_id(self, field_id); } -uint32_t ts_node_child_count(TSNode self) +uint32_t ts_node_child_count(t_parse_node self) { - Subtree tree = ts_node__subtree(self); + t_subtree tree = ts_node__subtree(self); if (ts_subtree_child_count(tree) > 0) { return tree.ptr->visible_child_count; @@ -2154,9 +2166,9 @@ uint32_t ts_node_child_count(TSNode self) } } -uint32_t ts_node_named_child_count(TSNode self) +uint32_t ts_node_named_child_count(t_parse_node self) { - Subtree tree = ts_node__subtree(self); + t_subtree tree = ts_node__subtree(self); if (ts_subtree_child_count(tree) > 0) { return tree.ptr->named_child_count; @@ -2167,64 +2179,67 @@ uint32_t ts_node_named_child_count(TSNode self) } } -TSNode ts_node_next_sibling(TSNode self) +t_parse_node ts_node_next_sibling(t_parse_node self) { return ts_node__next_sibling(self, true); } -TSNode ts_node_next_named_sibling(TSNode self) +t_parse_node ts_node_next_named_sibling(t_parse_node self) { return ts_node__next_sibling(self, false); } -TSNode ts_node_prev_sibling(TSNode self) +t_parse_node ts_node_prev_sibling(t_parse_node self) { return ts_node__prev_sibling(self, true); } -TSNode ts_node_prev_named_sibling(TSNode self) +t_parse_node ts_node_prev_named_sibling(t_parse_node self) { return ts_node__prev_sibling(self, false); } -TSNode ts_node_first_child_for_byte(TSNode self, uint32_t byte) +t_parse_node ts_node_first_child_for_byte(t_parse_node self, uint32_t byte) { return ts_node__first_child_for_byte(self, byte, true); } -TSNode ts_node_first_named_child_for_byte(TSNode self, uint32_t byte) +t_parse_node ts_node_first_named_child_for_byte(t_parse_node self, + uint32_t byte) { return ts_node__first_child_for_byte(self, byte, false); } -TSNode ts_node_descendant_for_byte_range(TSNode self, uint32_t start, - uint32_t end) +t_parse_node ts_node_descendant_for_byte_range(t_parse_node self, + uint32_t start, uint32_t end) { return ts_node__descendant_for_byte_range(self, start, end, true); } -TSNode ts_node_named_descendant_for_byte_range(TSNode self, uint32_t start, - uint32_t end) +t_parse_node ts_node_named_descendant_for_byte_range(t_parse_node self, + uint32_t start, + uint32_t end) { return ts_node__descendant_for_byte_range(self, start, end, false); } -TSNode ts_node_descendant_for_point_range(TSNode self, TSPoint start, - TSPoint end) +t_parse_node ts_node_descendant_for_point_range(t_parse_node self, + t_point start, t_point end) { return ts_node__descendant_for_point_range(self, start, end, true); } -TSNode ts_node_named_descendant_for_point_range(TSNode self, TSPoint start, - TSPoint end) +t_parse_node ts_node_named_descendant_for_point_range(t_parse_node self, + t_point start, + t_point end) { return ts_node__descendant_for_point_range(self, start, end, false); } -void ts_node_edit(TSNode *self, const TSInputEdit *edit) +void ts_node_edit(t_parse_node *self, const t_input_edit *edit) { uint32_t start_byte = ts_node_start_byte(*self); - TSPoint start_point = ts_node_start_point(*self); + t_point start_point = ts_node_start_point(*self); if (start_byte >= edit->old_end_byte) { @@ -2255,32 +2270,32 @@ static const unsigned OP_COUNT_PER_TIMEOUT_CHECK = 100; typedef struct { - Subtree token; - Subtree last_external_token; - uint32_t byte_index; + t_subtree token; + t_subtree last_external_token; + uint32_t byte_index; } TokenCache; -struct TSParser +struct s_first_parser { - Lexer lexer; - Stack *stack; - SubtreePool tree_pool; - const TSLanguage *language; - ReduceActionSet reduce_actions; - Subtree finished_tree; - SubtreeArray trailing_extras; - SubtreeArray trailing_extras2; - SubtreeArray scratch_trees; + t_lexer lexer; + t_stack *stack; + t_subtree_pool tree_pool; + const t_language *language; + t_reduce_action_set reduce_actions; + t_subtree finished_tree; + t_subtree_array trailing_extras; + t_subtree_array trailing_extras2; + t_subtree_array scratch_trees; TokenCache token_cache; - ReusableNode reusable_node; + t_reusable_node reusable_node; void *external_scanner_payload; - TSClock end_clock; - TSDuration timeout_duration; + t_parser_clock end_clock; + t_parser_duration timeout_duration; unsigned accept_count; unsigned operation_count; const volatile size_t *cancellation_flag; - Subtree old_tree; - TSRangeArray included_range_differences; + t_subtree old_tree; + t_range_array included_range_differences; unsigned included_range_difference_index; bool has_scanner_error; }; @@ -2311,7 +2326,7 @@ typedef struct // StringInput static const char *ts_string_input_read(void *_self, uint32_t byte, - TSPoint point, uint32_t *length) + t_point point, uint32_t *length) { (void)point; TSStringInput *self = (TSStringInput *)_self; @@ -2329,15 +2344,15 @@ static const char *ts_string_input_read(void *_self, uint32_t byte, // Parser - Private -static bool ts_parser__breakdown_top_of_stack(TSParser *self, - StackVersion version) +static bool ts_parser__breakdown_top_of_stack(t_first_parser *self, + t_stack_version version) { bool did_break_down = false; bool pending = false; do { - StackSliceArray pop = ts_stack_pop_pending(self->stack, version); + t_stack_slice_array pop = ts_stack_pop_pending(self->stack, version); if (!pop.size) break; @@ -2345,13 +2360,13 @@ static bool ts_parser__breakdown_top_of_stack(TSParser *self, pending = false; for (uint32_t i = 0; i < pop.size; i++) { - StackSlice slice = pop.contents[i]; - TSStateId state = ts_stack_state(self->stack, slice.version); - Subtree parent = *array_front(&slice.subtrees); + t_stack_slice slice = pop.contents[i]; + t_state_id state = ts_stack_state(self->stack, slice.version); + t_subtree parent = *array_front(&slice.subtrees); for (uint32_t j = 0, n = ts_subtree_child_count(parent); j < n; j++) { - Subtree child = ts_subtree_children(parent)[j]; + t_subtree child = ts_subtree_children(parent)[j]; pending = ts_subtree_child_count(child) > 0; if (ts_subtree_is_error(child)) @@ -2371,7 +2386,7 @@ static bool ts_parser__breakdown_top_of_stack(TSParser *self, for (uint32_t j = 1; j < slice.subtrees.size; j++) { - Subtree tree = slice.subtrees.contents[j]; + t_subtree tree = slice.subtrees.contents[j]; ts_stack_push(self->stack, slice.version, tree, false, state); } @@ -2383,12 +2398,13 @@ static bool ts_parser__breakdown_top_of_stack(TSParser *self, return did_break_down; } -static void ts_parser__breakdown_lookahead(TSParser *self, Subtree *lookahead, - TSStateId state, - ReusableNode *reusable_node) +static void ts_parser__breakdown_lookahead(t_first_parser *self, + t_subtree *lookahead, + t_state_id state, + t_reusable_node *reusable_node) { - bool did_descend = false; - Subtree tree = reusable_node_tree(reusable_node); + bool did_descend = false; + t_subtree tree = reusable_node_tree(reusable_node); while (ts_subtree_child_count(tree) > 0 && ts_subtree_parse_state(tree) != state) { @@ -2405,7 +2421,7 @@ static void ts_parser__breakdown_lookahead(TSParser *self, Subtree *lookahead, } } -static ErrorComparison ts_parser__compare_versions(TSParser *self, +static ErrorComparison ts_parser__compare_versions(t_first_parser *self, ErrorStatus a, ErrorStatus b) { (void)self; @@ -2464,8 +2480,8 @@ static ErrorComparison ts_parser__compare_versions(TSParser *self, return ErrorComparisonNone; } -static ErrorStatus ts_parser__version_status(TSParser *self, - StackVersion version) +static ErrorStatus ts_parser__version_status(t_first_parser *self, + t_stack_version version) { unsigned cost = ts_stack_error_cost(self->stack, version); bool is_paused = ts_stack_is_paused(self->stack, version); @@ -2479,8 +2495,8 @@ static ErrorStatus ts_parser__version_status(TSParser *self, is_paused || ts_stack_state(self->stack, version) == ERROR_STATE}; } -static bool ts_parser__better_version_exists(TSParser *self, - StackVersion version, +static bool ts_parser__better_version_exists(t_first_parser *self, + t_stack_version version, bool is_in_error, unsigned cost) { if (self->finished_tree.ptr && @@ -2489,7 +2505,7 @@ static bool ts_parser__better_version_exists(TSParser *self, return true; } - Length position = ts_stack_position(self->stack, version); + t_length position = ts_stack_position(self->stack, version); ErrorStatus status = { .cost = cost, .is_in_error = is_in_error, @@ -2497,7 +2513,7 @@ static bool ts_parser__better_version_exists(TSParser *self, .node_count = ts_stack_node_count_since_error(self->stack, version), }; - for (StackVersion i = 0, n = ts_stack_version_count(self->stack); i < n; + for (t_stack_version i = 0, n = ts_stack_version_count(self->stack); i < n; i++) { if (i == version || !ts_stack_is_active(self->stack, i) || @@ -2520,19 +2536,21 @@ static bool ts_parser__better_version_exists(TSParser *self, return false; } -static bool ts_parser__call_main_lex_fn(TSParser *self, TSLexMode lex_mode) +static bool ts_parser__call_main_lex_fn(t_first_parser *self, + t_lex_mode lex_mode) { return self->language->lex_fn(&self->lexer.data, lex_mode.lex_state); } -static bool ts_parser__call_keyword_lex_fn(TSParser *self, TSLexMode lex_mode) +static bool ts_parser__call_keyword_lex_fn(t_first_parser *self, + t_lex_mode lex_mode) { - (void)(lex_mode); + (void)(lex_mode); return self->language->keyword_lex_fn(&self->lexer.data, 0); } -static void ts_parser__external_scanner_create(TSParser *self) +static void ts_parser__external_scanner_create(t_first_parser *self) { if (self->language && self->language->external_scanner.states) { @@ -2544,7 +2562,7 @@ static void ts_parser__external_scanner_create(TSParser *self) } } -static void ts_parser__external_scanner_destroy(TSParser *self) +static void ts_parser__external_scanner_destroy(t_first_parser *self) { if (self->language && self->external_scanner_payload && self->language->external_scanner.destroy) @@ -2555,7 +2573,7 @@ static void ts_parser__external_scanner_destroy(TSParser *self) self->external_scanner_payload = NULL; } -static unsigned ts_parser__external_scanner_serialize(TSParser *self) +static unsigned ts_parser__external_scanner_serialize(t_first_parser *self) { uint32_t length = self->language->external_scanner.serialize( @@ -2564,8 +2582,8 @@ static unsigned ts_parser__external_scanner_serialize(TSParser *self) return length; } -static void ts_parser__external_scanner_deserialize(TSParser *self, - Subtree external_token) +static void ts_parser__external_scanner_deserialize(t_first_parser *self, + t_subtree external_token) { const char *data = NULL; uint32_t length = 0; @@ -2580,8 +2598,8 @@ static void ts_parser__external_scanner_deserialize(TSParser *self, data, length); } -static bool ts_parser__external_scanner_scan(TSParser *self, - TSStateId external_lex_state) +static bool ts_parser__external_scanner_scan(t_first_parser *self, + t_state_id external_lex_state) { const bool *valid_external_tokens = @@ -2591,14 +2609,14 @@ static bool ts_parser__external_scanner_scan(TSParser *self, valid_external_tokens); } -static bool ts_parser__can_reuse_first_leaf(TSParser *self, TSStateId state, - Subtree tree, - TableEntry *table_entry) +static bool ts_parser__can_reuse_first_leaf(t_first_parser *self, + t_state_id state, t_subtree tree, + t_table_entry *table_entry) { - TSLexMode current_lex_mode = self->language->lex_modes[state]; - TSSymbol leaf_symbol = ts_subtree_leaf_symbol(tree); - TSStateId leaf_state = ts_subtree_leaf_parse_state(tree); - TSLexMode leaf_lex_mode = self->language->lex_modes[leaf_state]; + t_lex_mode current_lex_mode = self->language->lex_modes[state]; + t_symbol leaf_symbol = ts_subtree_leaf_symbol(tree); + t_state_id leaf_state = ts_subtree_leaf_parse_state(tree); + t_lex_mode leaf_lex_mode = self->language->lex_modes[leaf_state]; // At the end of a non-terminal extra node, the lexer normally returns // NULL, which indicates that the parser should look for a reduce action @@ -2610,7 +2628,7 @@ static bool ts_parser__can_reuse_first_leaf(TSParser *self, TSStateId state, // If the token was created in a state with the same set of lookaheads, it // is reusable. if (table_entry->action_count > 0 && - memcmp(&leaf_lex_mode, ¤t_lex_mode, sizeof(TSLexMode)) == 0 && + memcmp(&leaf_lex_mode, ¤t_lex_mode, sizeof(t_lex_mode)) == 0 && (leaf_symbol != self->language->keyword_capture_token || (!ts_subtree_is_keyword(tree) && ts_subtree_parse_state(tree) == state))) @@ -2625,31 +2643,32 @@ static bool ts_parser__can_reuse_first_leaf(TSParser *self, TSStateId state, return current_lex_mode.external_lex_state == 0 && table_entry->is_reusable; } -const ExternalScannerState *ts_subtree_external_scanner_state(Subtree self) { - static const ExternalScannerState empty_state = {{.short_data = {0}}, .length = 0}; - if ( - self.ptr && - !self.data.is_inline && - self.ptr->has_external_tokens && - self.ptr->child_count == 0 - ) { - return &self.ptr->external_scanner_state; - } else { - return &empty_state; - } +const ExternalScannerState *ts_subtree_external_scanner_state(t_subtree self) +{ + static const ExternalScannerState empty_state = {{.short_data = {0}}, + .length = 0}; + if (self.ptr && !self.data.is_inline && self.ptr->has_external_tokens && + self.ptr->child_count == 0) + { + return &self.ptr->external_scanner_state; + } + else + { + return &empty_state; + } } -static Subtree ts_parser__lex(TSParser *self, StackVersion version, - TSStateId parse_state) +static t_subtree ts_parser__lex(t_first_parser *self, t_stack_version version, + t_state_id parse_state) { - TSLexMode lex_mode = self->language->lex_modes[parse_state]; + t_lex_mode lex_mode = self->language->lex_modes[parse_state]; if (lex_mode.lex_state == (uint16_t)-1) { return NULL_SUBTREE; } - const Length start_position = ts_stack_position(self->stack, version); - const Subtree external_token = + const t_length start_position = ts_stack_position(self->stack, version); + const t_subtree external_token = ts_stack_last_external_token(self->stack, version); bool found_external_token = false; @@ -2657,8 +2676,8 @@ static Subtree ts_parser__lex(TSParser *self, StackVersion version, bool skipped_error = false; bool called_get_column = false; int32_t first_error_character = 0; - Length error_start_position = length_zero(); - Length error_end_position = length_zero(); + t_length error_start_position = length_zero(); + t_length error_end_position = length_zero(); uint32_t lookahead_end_byte = 0; uint32_t external_scanner_state_len = 0; bool external_scanner_state_changed = false; @@ -2666,8 +2685,8 @@ static Subtree ts_parser__lex(TSParser *self, StackVersion version, for (;;) { - bool found_token = false; - Length current_position = self->lexer.current_position; + bool found_token = false; + t_length current_position = self->lexer.current_position; if (lex_mode.external_lex_state != 0) { @@ -2754,11 +2773,11 @@ static Subtree ts_parser__lex(TSParser *self, StackVersion version, error_end_position = self->lexer.current_position; } - Subtree result; + t_subtree result; if (skipped_error) { - Length padding = length_sub(error_start_position, start_position); - Length size = length_sub(error_end_position, error_start_position); + t_length padding = length_sub(error_start_position, start_position); + t_length size = length_sub(error_end_position, error_start_position); uint32_t lookahead_bytes = lookahead_end_byte - error_end_position.bytes; result = ts_subtree_new_error(&self->tree_pool, first_error_character, @@ -2768,10 +2787,10 @@ static Subtree ts_parser__lex(TSParser *self, StackVersion version, else { bool is_keyword = false; - TSSymbol symbol = self->lexer.data.result_symbol; - Length padding = + t_symbol symbol = self->lexer.data.result_symbol; + t_length padding = length_sub(self->lexer.token_start_position, start_position); - Length size = length_sub(self->lexer.token_end_position, + t_length size = length_sub(self->lexer.token_end_position, self->lexer.token_start_position); uint32_t lookahead_bytes = lookahead_end_byte - self->lexer.token_end_position.bytes; @@ -2804,7 +2823,7 @@ static Subtree ts_parser__lex(TSParser *self, StackVersion version, if (found_external_token) { - MutableSubtree mut_result = ts_subtree_to_mut_unsafe(result); + t_mutable_subtree mut_result = ts_subtree_to_mut_unsafe(result); ts_external_scanner_state_init( &mut_result.ptr->external_scanner_state, self->lexer.debug_buffer, external_scanner_state_len); @@ -2815,10 +2834,10 @@ static Subtree ts_parser__lex(TSParser *self, StackVersion version, return result; } -static Subtree ts_parser__get_cached_token(TSParser *self, TSStateId state, - size_t position, - Subtree last_external_token, - TableEntry *table_entry) +static t_subtree ts_parser__get_cached_token(t_first_parser *self, + t_state_id state, size_t position, + t_subtree last_external_token, + t_table_entry *table_entry) { TokenCache *cache = &self->token_cache; if (cache->token.ptr && cache->byte_index == position && @@ -2837,9 +2856,10 @@ static Subtree ts_parser__get_cached_token(TSParser *self, TSStateId state, return NULL_SUBTREE; } -static void ts_parser__set_cached_token(TSParser *self, uint32_t byte_index, - Subtree last_external_token, - Subtree token) +static void ts_parser__set_cached_token(t_first_parser *self, + uint32_t byte_index, + t_subtree last_external_token, + t_subtree token) { TokenCache *cache = &self->token_cache; if (token.ptr) @@ -2855,7 +2875,7 @@ static void ts_parser__set_cached_token(TSParser *self, uint32_t byte_index, cache->last_external_token = last_external_token; } -static bool ts_parser__has_included_range_difference(const TSParser *self, +static bool ts_parser__has_included_range_difference(const t_first_parser *self, uint32_t start_position, uint32_t end_position) { @@ -2864,12 +2884,13 @@ static bool ts_parser__has_included_range_difference(const TSParser *self, start_position, end_position); } -static Subtree ts_parser__reuse_node(TSParser *self, StackVersion version, - TSStateId *state, uint32_t position, - Subtree last_external_token, - TableEntry *table_entry) +static t_subtree ts_parser__reuse_node(t_first_parser *self, + t_stack_version version, + t_state_id *state, uint32_t position, + t_subtree last_external_token, + t_table_entry *table_entry) { - Subtree result; + t_subtree result; while ((result = reusable_node_tree(&self->reusable_node)).ptr) { uint32_t byte_offset = reusable_node_byte_offset(&self->reusable_node); @@ -2938,7 +2959,7 @@ static Subtree ts_parser__reuse_node(TSParser *self, StackVersion version, continue; } - TSSymbol leaf_symbol = ts_subtree_leaf_symbol(result); + t_symbol leaf_symbol = ts_subtree_leaf_symbol(result); ts_language_table_entry(self->language, *state, leaf_symbol, table_entry); if (!ts_parser__can_reuse_first_leaf(self, *state, result, table_entry)) @@ -2958,7 +2979,8 @@ static Subtree ts_parser__reuse_node(TSParser *self, StackVersion version, // The decision is based on the trees' error costs (if any), their dynamic // precedence, and finally, as a default, by a recursive comparison of the // trees' symbols. -static bool ts_parser__select_tree(TSParser *self, Subtree left, Subtree right) +static bool ts_parser__select_tree(t_first_parser *self, t_subtree left, + t_subtree right) { if (!left.ptr) return true; @@ -3005,8 +3027,8 @@ static bool ts_parser__select_tree(TSParser *self, Subtree left, Subtree right) // Determine if a given tree's children should be replaced by an alternative // array of children. -static bool ts_parser__select_children(TSParser *self, Subtree left, - const SubtreeArray *children) +static bool ts_parser__select_children(t_first_parser *self, t_subtree left, + const t_subtree_array *children) { array_assign(&self->scratch_trees, children); @@ -3014,21 +3036,21 @@ static bool ts_parser__select_children(TSParser *self, Subtree left, // not perform any allocation except for possibly growing the array to make // room for its own heap data. The scratch tree is never explicitly // released, so the same 'scratch trees' array can be reused again later. - MutableSubtree scratch_tree = ts_subtree_new_node( + t_mutable_subtree scratch_tree = ts_subtree_new_node( ts_subtree_symbol(left), &self->scratch_trees, 0, self->language); return ts_parser__select_tree(self, left, ts_subtree_from_mut(scratch_tree)); } -static void ts_parser__shift(TSParser *self, StackVersion version, - TSStateId state, Subtree lookahead, bool extra) +static void ts_parser__shift(t_first_parser *self, t_stack_version version, + t_state_id state, t_subtree lookahead, bool extra) { - bool is_leaf = ts_subtree_child_count(lookahead) == 0; - Subtree subtree_to_push = lookahead; + bool is_leaf = ts_subtree_child_count(lookahead) == 0; + t_subtree subtree_to_push = lookahead; if (extra != ts_subtree_extra(lookahead) && is_leaf) { - MutableSubtree result = + t_mutable_subtree result = ts_subtree_make_mut(&self->tree_pool, lookahead); ts_subtree_set_extra(&result, extra); subtree_to_push = ts_subtree_from_mut(result); @@ -3043,11 +3065,10 @@ static void ts_parser__shift(TSParser *self, StackVersion version, } } -static StackVersion ts_parser__reduce(TSParser *self, StackVersion version, - TSSymbol symbol, uint32_t count, - int dynamic_precedence, - uint16_t production_id, bool is_fragile, - bool end_of_non_terminal_extra) +static t_stack_version ts_parser__reduce( + t_first_parser *self, t_stack_version version, t_symbol symbol, + uint32_t count, int dynamic_precedence, uint16_t production_id, + bool is_fragile, bool end_of_non_terminal_extra) { uint32_t initial_version_count = ts_stack_version_count(self->stack); @@ -3056,12 +3077,12 @@ static StackVersion ts_parser__reduce(TSParser *self, StackVersion version, // path back through the stack. For each path, create a new parent node to // contain the popped children, and push it onto the stack in place of the // children. - StackSliceArray pop = ts_stack_pop_count(self->stack, version, count); - uint32_t removed_version_count = 0; + t_stack_slice_array pop = ts_stack_pop_count(self->stack, version, count); + uint32_t removed_version_count = 0; for (uint32_t i = 0; i < pop.size; i++) { - StackSlice slice = pop.contents[i]; - StackVersion slice_version = slice.version - removed_version_count; + t_stack_slice slice = pop.contents[i]; + t_stack_version slice_version = slice.version - removed_version_count; // This is where new versions are added to the parse stack. The versions // will all be sorted and truncated at the end of the outer parsing @@ -3074,7 +3095,7 @@ static StackVersion ts_parser__reduce(TSParser *self, StackVersion version, removed_version_count++; while (i + 1 < pop.size) { - StackSlice next_slice = pop.contents[i + 1]; + t_stack_slice next_slice = pop.contents[i + 1]; if (next_slice.version != slice.version) break; ts_subtree_array_delete(&self->tree_pool, &next_slice.subtrees); @@ -3086,11 +3107,11 @@ static StackVersion ts_parser__reduce(TSParser *self, StackVersion version, // Extra tokens on top of the stack should not be included in this new // parent node. They will be re-pushed onto the stack after the parent // node is created and pushed. - SubtreeArray children = slice.subtrees; + t_subtree_array children = slice.subtrees; ts_subtree_array_remove_trailing_extras(&children, &self->trailing_extras); - MutableSubtree parent = ts_subtree_new_node( + t_mutable_subtree parent = ts_subtree_new_node( symbol, &children, production_id, self->language); // This pop operation may have caused multiple stack versions to @@ -3099,12 +3120,12 @@ static StackVersion ts_parser__reduce(TSParser *self, StackVersion version, // children, and delete the rest of the tree arrays. while (i + 1 < pop.size) { - StackSlice next_slice = pop.contents[i + 1]; + t_stack_slice next_slice = pop.contents[i + 1]; if (next_slice.version != slice.version) break; i++; - SubtreeArray next_slice_children = next_slice.subtrees; + t_subtree_array next_slice_children = next_slice.subtrees; ts_subtree_array_remove_trailing_extras(&next_slice_children, &self->trailing_extras2); @@ -3126,8 +3147,8 @@ static StackVersion ts_parser__reduce(TSParser *self, StackVersion version, } } - TSStateId state = ts_stack_state(self->stack, slice_version); - TSStateId next_state = + t_state_id state = ts_stack_state(self->stack, slice_version); + t_state_id next_state = ts_language_next_state(self->language, state, symbol); if (end_of_non_terminal_extra && next_state == state) { @@ -3155,7 +3176,7 @@ static StackVersion ts_parser__reduce(TSParser *self, StackVersion version, self->trailing_extras.contents[j], false, next_state); } - for (StackVersion j = 0; j < slice_version; j++) + for (t_stack_version j = 0; j < slice_version; j++) { if (j == version) continue; @@ -3173,26 +3194,26 @@ static StackVersion ts_parser__reduce(TSParser *self, StackVersion version, : STACK_VERSION_NONE; } -static void ts_parser__accept(TSParser *self, StackVersion version, - Subtree lookahead) +static void ts_parser__accept(t_first_parser *self, t_stack_version version, + t_subtree lookahead) { assert(ts_subtree_is_eof(lookahead)); ts_stack_push(self->stack, version, lookahead, false, 1); - StackSliceArray pop = ts_stack_pop_all(self->stack, version); + t_stack_slice_array pop = ts_stack_pop_all(self->stack, version); for (uint32_t i = 0; i < pop.size; i++) { - SubtreeArray trees = pop.contents[i].subtrees; + t_subtree_array trees = pop.contents[i].subtrees; - Subtree root = NULL_SUBTREE; + t_subtree root = NULL_SUBTREE; for (uint32_t j = trees.size - 1; j + 1 > 0; j--) { - Subtree tree = trees.contents[j]; + t_subtree tree = trees.contents[j]; if (!ts_subtree_extra(tree)) { assert(!tree.data.is_inline); - uint32_t child_count = ts_subtree_child_count(tree); - const Subtree *children = ts_subtree_children(tree); + uint32_t child_count = ts_subtree_child_count(tree); + const t_subtree *children = ts_subtree_children(tree); for (uint32_t k = 0; k < child_count; k++) { ts_subtree_retain(children[k]); @@ -3232,12 +3253,13 @@ static void ts_parser__accept(TSParser *self, StackVersion version, } static bool ts_parser__do_all_potential_reductions( - TSParser *self, StackVersion starting_version, TSSymbol lookahead_symbol) + t_first_parser *self, t_stack_version starting_version, + t_symbol lookahead_symbol) { uint32_t initial_version_count = ts_stack_version_count(self->stack); - bool can_shift_lookahead_symbol = false; - StackVersion version = starting_version; + bool can_shift_lookahead_symbol = false; + t_stack_version version = starting_version; for (unsigned i = 0; true; i++) { uint32_t version_count = ts_stack_version_count(self->stack); @@ -3245,7 +3267,7 @@ static bool ts_parser__do_all_potential_reductions( break; bool merged = false; - for (StackVersion j = initial_version_count; j < version; j++) + for (t_stack_version j = initial_version_count; j < version; j++) { if (ts_stack_merge(self->stack, j, version)) { @@ -3256,11 +3278,11 @@ static bool ts_parser__do_all_potential_reductions( if (merged) continue; - TSStateId state = ts_stack_state(self->stack, version); - bool has_shift_action = false; + t_state_id state = ts_stack_state(self->stack, version); + bool has_shift_action = false; array_clear(&self->reduce_actions); - TSSymbol first_symbol, end_symbol; + t_symbol first_symbol, end_symbol; if (lookahead_symbol != 0) { first_symbol = lookahead_symbol; @@ -3272,13 +3294,13 @@ static bool ts_parser__do_all_potential_reductions( end_symbol = self->language->token_count; } - for (TSSymbol symbol = first_symbol; symbol < end_symbol; symbol++) + for (t_symbol symbol = first_symbol; symbol < end_symbol; symbol++) { - TableEntry entry; + t_table_entry entry; ts_language_table_entry(self->language, state, symbol, &entry); for (uint32_t j = 0; j < entry.action_count; j++) { - TSParseAction action = entry.actions[j]; + t_parse_action action = entry.actions[j]; switch (action.type) { case TSParseActionTypeShift: @@ -3290,7 +3312,7 @@ static bool ts_parser__do_all_potential_reductions( if (action.reduce.child_count > 0) ts_reduce_action_set_add( &self->reduce_actions, - (ReduceAction){ + (t_reduce_action){ .symbol = action.reduce.symbol, .count = action.reduce.child_count, .dynamic_precedence = @@ -3304,10 +3326,10 @@ static bool ts_parser__do_all_potential_reductions( } } - StackVersion reduction_version = STACK_VERSION_NONE; + t_stack_version reduction_version = STACK_VERSION_NONE; for (uint32_t j = 0; j < self->reduce_actions.size; j++) { - ReduceAction action = self->reduce_actions.contents[j]; + t_reduce_action action = self->reduce_actions.contents[j]; reduction_version = ts_parser__reduce( self, version, action.symbol, action.count, @@ -3342,15 +3364,16 @@ static bool ts_parser__do_all_potential_reductions( return can_shift_lookahead_symbol; } -static bool ts_parser__recover_to_state(TSParser *self, StackVersion version, - unsigned depth, TSStateId goal_state) +static bool ts_parser__recover_to_state(t_first_parser *self, + t_stack_version version, unsigned depth, + t_state_id goal_state) { - StackSliceArray pop = ts_stack_pop_count(self->stack, version, depth); - StackVersion previous_version = STACK_VERSION_NONE; + t_stack_slice_array pop = ts_stack_pop_count(self->stack, version, depth); + t_stack_version previous_version = STACK_VERSION_NONE; for (unsigned i = 0; i < pop.size; i++) { - StackSlice slice = pop.contents[i]; + t_stack_slice slice = pop.contents[i]; if (slice.version == previous_version) { @@ -3367,13 +3390,13 @@ static bool ts_parser__recover_to_state(TSParser *self, StackVersion version, continue; } - SubtreeArray error_trees = + t_subtree_array error_trees = ts_stack_pop_error(self->stack, slice.version); if (error_trees.size > 0) { assert(error_trees.size == 1); - Subtree error_tree = error_trees.contents[0]; - uint32_t error_child_count = ts_subtree_child_count(error_tree); + t_subtree error_tree = error_trees.contents[0]; + uint32_t error_child_count = ts_subtree_child_count(error_tree); if (error_child_count > 0) { array_splice(&slice.subtrees, 0, 0, error_child_count, @@ -3391,8 +3414,8 @@ static bool ts_parser__recover_to_state(TSParser *self, StackVersion version, if (slice.subtrees.size > 0) { - Subtree error = ts_subtree_new_error_node(&slice.subtrees, true, - self->language); + t_subtree error = ts_subtree_new_error_node(&slice.subtrees, true, + self->language); ts_stack_push(self->stack, slice.version, error, false, goal_state); } else @@ -3402,7 +3425,7 @@ static bool ts_parser__recover_to_state(TSParser *self, StackVersion version, for (unsigned j = 0; j < self->trailing_extras.size; j++) { - Subtree tree = self->trailing_extras.contents[j]; + t_subtree tree = self->trailing_extras.contents[j]; ts_stack_push(self->stack, slice.version, tree, false, goal_state); } @@ -3412,14 +3435,14 @@ static bool ts_parser__recover_to_state(TSParser *self, StackVersion version, return previous_version != STACK_VERSION_NONE; } -static void ts_parser__recover(TSParser *self, StackVersion version, - Subtree lookahead) +static void ts_parser__recover(t_first_parser *self, t_stack_version version, + t_subtree lookahead) { - bool did_recover = false; - unsigned previous_version_count = ts_stack_version_count(self->stack); - Length position = ts_stack_position(self->stack, version); - StackSummary *summary = ts_stack_get_summary(self->stack, version); - unsigned node_count_since_error = + bool did_recover = false; + unsigned previous_version_count = ts_stack_version_count(self->stack); + t_length position = ts_stack_position(self->stack, version); + t_stack_summary *summary = ts_stack_get_summary(self->stack, version); + unsigned node_count_since_error = ts_stack_node_count_since_error(self->stack, version); unsigned current_error_cost = ts_stack_error_cost(self->stack, version); @@ -3442,7 +3465,7 @@ static void ts_parser__recover(TSParser *self, StackVersion version, { for (unsigned i = 0; i < summary->size; i++) { - StackSummaryEntry entry = summary->contents[i]; + t_stack_summary_entry entry = summary->contents[i]; if (entry.state == ERROR_STATE) continue; @@ -3529,8 +3552,8 @@ static void ts_parser__recover(TSParser *self, StackVersion version, // wrap everything in an ERROR node and terminate. if (ts_subtree_is_eof(lookahead)) { - SubtreeArray children = array_new(); - Subtree parent = + t_subtree_array children = array_new(); + t_subtree parent = ts_subtree_new_error_node(&children, false, self->language); ts_stack_push(self->stack, version, parent, false, 1); ts_parser__accept(self, version, lookahead); @@ -3553,23 +3576,23 @@ static void ts_parser__recover(TSParser *self, StackVersion version, // If the current lookahead token is an extra token, mark it as extra. This // means it won't be counted in error cost calculations. - unsigned n; - const TSParseAction *actions = ts_language_actions( + unsigned n; + const t_parse_action *actions = ts_language_actions( self->language, 1, ts_subtree_symbol(lookahead), &n); if (n > 0 && actions[n - 1].type == TSParseActionTypeShift && actions[n - 1].shift.extra) { - MutableSubtree mutable_lookahead = + t_mutable_subtree mutable_lookahead = ts_subtree_make_mut(&self->tree_pool, lookahead); ts_subtree_set_extra(&mutable_lookahead, true); lookahead = ts_subtree_from_mut(mutable_lookahead); } // Wrap the lookahead token in an ERROR. - SubtreeArray children = array_new(); + t_subtree_array children = array_new(); array_reserve(&children, 1); array_push(&children, lookahead); - MutableSubtree error_repeat = ts_subtree_new_node( + t_mutable_subtree error_repeat = ts_subtree_new_node( ts_builtin_sym_error_repeat, &children, 0, self->language); // If other tokens have already been skipped, so there is already an ERROR @@ -3577,7 +3600,7 @@ static void ts_parser__recover(TSParser *self, StackVersion version, // two ERRORs together into one larger ERROR. if (node_count_since_error > 0) { - StackSliceArray pop = ts_stack_pop_count(self->stack, version, 1); + t_stack_slice_array pop = ts_stack_pop_count(self->stack, version, 1); // TODO: Figure out how to make this condition occur. // See https://github.com/atom/atom/issues/18450#issuecomment-439579778 @@ -3617,8 +3640,9 @@ static void ts_parser__recover(TSParser *self, StackVersion version, } } -static void ts_parser__handle_error(TSParser *self, StackVersion version, - Subtree lookahead) +static void ts_parser__handle_error(t_first_parser *self, + t_stack_version version, + t_subtree lookahead) { uint32_t previous_version_count = ts_stack_version_count(self->stack); @@ -3627,21 +3651,21 @@ static void ts_parser__handle_error(TSParser *self, StackVersion version, // find a token that would have allowed a reduction to take place. ts_parser__do_all_potential_reductions(self, version, 0); uint32_t version_count = ts_stack_version_count(self->stack); - Length position = ts_stack_position(self->stack, version); + t_length position = ts_stack_position(self->stack, version); // Push a discontinuity onto the stack. Merge all of the stack versions that // were created in the previous step. bool did_insert_missing_token = false; - for (StackVersion v = version; v < version_count;) + for (t_stack_version v = version; v < version_count;) { if (!did_insert_missing_token) { - TSStateId state = ts_stack_state(self->stack, v); - for (TSSymbol missing_symbol = 1; + t_state_id state = ts_stack_state(self->stack, v); + for (t_symbol missing_symbol = 1; missing_symbol < (uint16_t)self->language->token_count; missing_symbol++) { - TSStateId state_after_missing_symbol = ts_language_next_state( + t_state_id state_after_missing_symbol = ts_language_next_state( self->language, state, missing_symbol); if (state_after_missing_symbol == 0 || state_after_missing_symbol == state) @@ -3659,15 +3683,15 @@ static void ts_parser__handle_error(TSParser *self, StackVersion version, // assigned to position it within the next included range. ts_lexer_reset(&self->lexer, position); ts_lexer_mark_end(&self->lexer); - Length padding = + t_length padding = length_sub(self->lexer.token_end_position, position); uint32_t lookahead_bytes = ts_subtree_total_bytes(lookahead) + ts_subtree_lookahead_bytes(lookahead); - StackVersion version_with_missing_tree = + t_stack_version version_with_missing_tree = ts_stack_copy_version(self->stack, v); - Subtree missing_tree = ts_subtree_new_missing_leaf( + t_subtree missing_tree = ts_subtree_new_missing_leaf( &self->tree_pool, missing_symbol, padding, lookahead_bytes, self->language); ts_stack_push(self->stack, version_with_missing_tree, @@ -3712,17 +3736,17 @@ static void ts_parser__handle_error(TSParser *self, StackVersion version, ts_parser__recover(self, version, lookahead); } -static bool ts_parser__advance(TSParser *self, StackVersion version, +static bool ts_parser__advance(t_first_parser *self, t_stack_version version, bool allow_node_reuse) { - TSStateId state = ts_stack_state(self->stack, version); - uint32_t position = ts_stack_position(self->stack, version).bytes; - Subtree last_external_token = + t_state_id state = ts_stack_state(self->stack, version); + uint32_t position = ts_stack_position(self->stack, version).bytes; + t_subtree last_external_token = ts_stack_last_external_token(self->stack, version); - bool did_reuse = true; - Subtree lookahead = NULL_SUBTREE; - TableEntry table_entry = {.action_count = 0}; + bool did_reuse = true; + t_subtree lookahead = NULL_SUBTREE; + t_table_entry table_entry = {.action_count = 0}; // If possible, reuse a node from the previous syntax tree. if (allow_node_reuse) @@ -3782,17 +3806,17 @@ static bool ts_parser__advance(TSParser *self, StackVersion version, // an ambiguous state. REDUCE actions always create a new stack // version, whereas SHIFT actions update the existing stack version // and terminate this loop. - StackVersion last_reduction_version = STACK_VERSION_NONE; + t_stack_version last_reduction_version = STACK_VERSION_NONE; for (uint32_t i = 0; i < table_entry.action_count; i++) { - TSParseAction action = table_entry.actions[i]; + t_parse_action action = table_entry.actions[i]; switch (action.type) { case TSParseActionTypeShift: { if (action.shift.repetition) break; - TSStateId next_state; + t_state_id next_state; if (action.shift.extra) { next_state = state; @@ -3818,9 +3842,9 @@ static bool ts_parser__advance(TSParser *self, StackVersion version, } case TSParseActionTypeReduce: { - bool is_fragile = table_entry.action_count > 1; - bool end_of_non_terminal_extra = lookahead.ptr == NULL; - StackVersion reduction_version = ts_parser__reduce( + bool is_fragile = table_entry.action_count > 1; + bool end_of_non_terminal_extra = lookahead.ptr == NULL; + t_stack_version reduction_version = ts_parser__reduce( self, version, action.reduce.symbol, action.reduce.child_count, action.reduce.dynamic_precedence, action.reduce.production_id, is_fragile, @@ -3902,7 +3926,7 @@ static bool ts_parser__advance(TSParser *self, StackVersion version, if (table_entry.action_count > 0) { - MutableSubtree mutable_lookahead = + t_mutable_subtree mutable_lookahead = ts_subtree_make_mut(&self->tree_pool, lookahead); ts_subtree_set_symbol(&mutable_lookahead, self->language->keyword_capture_token, @@ -3945,11 +3969,11 @@ static bool ts_parser__advance(TSParser *self, StackVersion version, } } -static unsigned ts_parser__condense_stack(TSParser *self) +static unsigned ts_parser__condense_stack(t_first_parser *self) { bool made_changes = false; unsigned min_error_cost = UINT_MAX; - for (StackVersion i = 0; i < ts_stack_version_count(self->stack); i++) + for (t_stack_version i = 0; i < ts_stack_version_count(self->stack); i++) { // Prune any versions that have been marked for removal. if (ts_stack_is_halted(self->stack, i)) @@ -3970,7 +3994,7 @@ static unsigned ts_parser__condense_stack(TSParser *self) // Examine each pair of stack versions, removing any versions that // are clearly worse than another version. Ensure that the versions // are ordered from most promising to least promising. - for (StackVersion j = 0; j < i; j++) + for (t_stack_version j = 0; j < i; j++) { ErrorStatus status_j = ts_parser__version_status(self, j); @@ -4030,8 +4054,8 @@ static unsigned ts_parser__condense_stack(TSParser *self) if (ts_stack_version_count(self->stack) > 0) { bool has_unpaused_version = false; - for (StackVersion i = 0, n = ts_stack_version_count(self->stack); i < n; - i++) + for (t_stack_version i = 0, n = ts_stack_version_count(self->stack); + i < n; i++) { if (ts_stack_is_paused(self->stack, i)) { @@ -4039,7 +4063,7 @@ static unsigned ts_parser__condense_stack(TSParser *self) self->accept_count < MAX_VERSION_COUNT) { min_error_cost = ts_stack_error_cost(self->stack, i); - Subtree lookahead = ts_stack_resume(self->stack, i); + t_subtree lookahead = ts_stack_resume(self->stack, i); ts_parser__handle_error(self, i, lookahead); has_unpaused_version = true; } @@ -4061,7 +4085,7 @@ static unsigned ts_parser__condense_stack(TSParser *self) return min_error_cost; } -static bool ts_parser_has_outstanding_parse(TSParser *self) +static bool ts_parser_has_outstanding_parse(t_first_parser *self) { return (self->external_scanner_payload || ts_stack_state(self->stack, 0) != 1 || @@ -4070,9 +4094,9 @@ static bool ts_parser_has_outstanding_parse(TSParser *self) // Parser - Public -TSParser *ts_parser_new(void) +t_first_parser *ts_parser_new(void) { - TSParser *self = calloc(1, sizeof(TSParser)); + t_first_parser *self = calloc(1, sizeof(t_first_parser)); ts_lexer_init(&self->lexer); array_init(&self->reduce_actions); array_reserve(&self->reduce_actions, 4); @@ -4088,13 +4112,13 @@ TSParser *ts_parser_new(void) self->end_clock = 0; self->operation_count = 0; self->old_tree = NULL_SUBTREE; - self->included_range_differences = (TSRangeArray)array_new(); + self->included_range_differences = (t_range_array)array_new(); self->included_range_difference_index = 0; ts_parser__set_cached_token(self, 0, NULL_SUBTREE, NULL_SUBTREE); return self; } -void ts_parser_delete(TSParser *self) +void ts_parser_delete(t_first_parser *self) { if (!self) return; @@ -4124,12 +4148,12 @@ void ts_parser_delete(TSParser *self) free(self); } -const TSLanguage *ts_parser_language(const TSParser *self) +const t_language *ts_parser_language(const t_first_parser *self) { return self->language; } -bool ts_parser_set_language(TSParser *self, const TSLanguage *language) +bool ts_parser_set_language(t_first_parser *self, const t_language *language) { ts_parser_reset(self); ts_language_delete(self->language); @@ -4139,56 +4163,57 @@ bool ts_parser_set_language(TSParser *self, const TSLanguage *language) return true; } -TSLogger ts_parser_logger(const TSParser *self) +t_parse_logger ts_parser_logger(const t_first_parser *self) { return self->lexer.logger; } -void ts_parser_set_logger(TSParser *self, TSLogger logger) +void ts_parser_set_logger(t_first_parser *self, t_parse_logger logger) { self->lexer.logger = logger; } -void ts_parser_print_dot_graphs(TSParser *self, int fd) +void ts_parser_print_dot_graphs(t_first_parser *self, int fd) { (void)(self); (void)(fd); } -const size_t *ts_parser_cancellation_flag(const TSParser *self) +const size_t *ts_parser_cancellation_flag(const t_first_parser *self) { return (const size_t *)self->cancellation_flag; } -void ts_parser_set_cancellation_flag(TSParser *self, const size_t *flag) +void ts_parser_set_cancellation_flag(t_first_parser *self, const size_t *flag) { self->cancellation_flag = (const volatile size_t *)flag; } -uint64_t ts_parser_timeout_micros(const TSParser *self) +uint64_t ts_parser_timeout_micros(const t_first_parser *self) { - (void)(self); + (void)(self); return 0; } -void ts_parser_set_timeout_micros(TSParser *self, uint64_t timeout_micros) +void ts_parser_set_timeout_micros(t_first_parser *self, uint64_t timeout_micros) { - (void)(timeout_micros); + (void)(timeout_micros); self->timeout_duration = 0; } -bool ts_parser_set_included_ranges(TSParser *self, const TSRange *ranges, - uint32_t count) +bool ts_parser_set_included_ranges(t_first_parser *self, + const t_parse_range *ranges, uint32_t count) { return ts_lexer_set_included_ranges(&self->lexer, ranges, count); } -const TSRange *ts_parser_included_ranges(const TSParser *self, uint32_t *count) +const t_parse_range *ts_parser_included_ranges(const t_first_parser *self, + uint32_t *count) { return ts_lexer_included_ranges(&self->lexer, count); } -void ts_parser_reset(TSParser *self) +void ts_parser_reset(t_first_parser *self) { ts_parser__external_scanner_destroy(self); if (self->old_tree.ptr) @@ -4210,9 +4235,10 @@ void ts_parser_reset(TSParser *self) self->has_scanner_error = false; } -TSTree *ts_parser_parse(TSParser *self, const TSTree *old_tree, TSInput input) +t_first_tree *ts_parser_parse(t_first_parser *self, + const t_first_tree *old_tree, t_parse_input input) { - TSTree *result = NULL; + t_first_tree *result = NULL; if (!self->language || !input.read) return NULL; @@ -4250,9 +4276,9 @@ TSTree *ts_parser_parse(TSParser *self, const TSTree *old_tree, TSInput input) uint32_t position = 0, last_position = 0, version_count = 0; do { - for (StackVersion version = 0; + for (t_stack_version version = 0; version_count = ts_stack_version_count(self->stack), - version < version_count; + version < version_count; version++) { bool allow_node_reuse = version_count == 1; @@ -4295,7 +4321,7 @@ TSTree *ts_parser_parse(TSParser *self, const TSTree *old_tree, TSInput input) while (self->included_range_difference_index < self->included_range_differences.size) { - TSRange *range = + t_parse_range *range = &self->included_range_differences .contents[self->included_range_difference_index]; if (range->end_byte <= position) @@ -4322,24 +4348,29 @@ exit: return result; } -TSTree *ts_parser_parse_string_encoding(TSParser *self, const TSTree *old_tree, - const char *string, uint32_t length, - TSInputEncoding encoding); +t_first_tree *ts_parser_parse_string_encoding(t_first_parser *self, + const t_first_tree *old_tree, + const char *string, + uint32_t length, + t_input_encoding encoding); -TSTree *ts_parser_parse_string(TSParser *self, const TSTree *old_tree, - const char *string, uint32_t length) +t_first_tree *ts_parser_parse_string(t_first_parser *self, + const t_first_tree *old_tree, + const char *string, uint32_t length) { return ts_parser_parse_string_encoding(self, old_tree, string, length, TSInputEncodingUTF8); } -TSTree *ts_parser_parse_string_encoding(TSParser *self, const TSTree *old_tree, - const char *string, uint32_t length, - TSInputEncoding encoding) +t_first_tree *ts_parser_parse_string_encoding(t_first_parser *self, + const t_first_tree *old_tree, + const char *string, + uint32_t length, + t_input_encoding encoding) { TSStringInput input = {string, length}; return ts_parser_parse(self, old_tree, - (TSInput){ + (t_parse_input){ &input, ts_string_input_read, encoding, @@ -4416,22 +4447,22 @@ typedef struct */ typedef struct { - TSSymbol symbol; - TSSymbol supertype_symbol; - TSFieldId field; - uint16_t capture_ids[MAX_STEP_CAPTURE_COUNT]; - uint16_t depth; - uint16_t alternative_index; - uint16_t negated_field_list_id; - bool is_named : 1; - bool is_immediate : 1; - bool is_last_child : 1; - bool is_pass_through : 1; - bool is_dead_end : 1; - bool alternative_is_immediate : 1; - bool contains_captures : 1; - bool root_pattern_guaranteed : 1; - bool parent_pattern_guaranteed : 1; + t_symbol symbol; + t_symbol supertype_symbol; + t_field_id field; + uint16_t capture_ids[MAX_STEP_CAPTURE_COUNT]; + uint16_t depth; + uint16_t alternative_index; + uint16_t negated_field_list_id; + bool is_named : 1; + bool is_immediate : 1; + bool is_last_child : 1; + bool is_pass_through : 1; + bool is_dead_end : 1; + bool alternative_is_immediate : 1; + bool contains_captures : 1; + bool root_pattern_guaranteed : 1; + bool parent_pattern_guaranteed : 1; } QueryStep; /* @@ -4496,7 +4527,7 @@ typedef struct /* * QueryState - The state of an in-progress match of a particular pattern - * in a query. While executing, a `TSQueryCursor` must keep track of a number + * in a query. While executing, a `t_query_cursor` must keep track of a number * of possible in-progress matches. Each of those possible matches is * represented as one of these states. Fields: * - `id` - A numeric id that is exposed to the public API. This allows the @@ -4533,7 +4564,7 @@ typedef struct bool needs_parent : 1; } QueryState; -typedef Array(TSQueryCapture) CaptureList; +typedef Array(t_query_capture) CaptureList; /* * CaptureListPool - A collection of *lists* of captures. Each query state needs @@ -4562,11 +4593,11 @@ typedef struct */ typedef struct { - TSStateId parse_state; - TSSymbol parent_symbol; - uint16_t child_index; - TSFieldId field_id : 15; - bool done : 1; + t_state_id parse_state; + t_symbol parent_symbol; + uint16_t child_index; + t_field_id field_id : 15; + bool done : 1; } AnalysisStateEntry; typedef struct @@ -4574,7 +4605,7 @@ typedef struct AnalysisStateEntry stack[MAX_ANALYSIS_STATE_DEPTH]; uint16_t depth; uint16_t step_index; - TSSymbol root_symbol; + t_symbol root_symbol; } AnalysisState; typedef Array(AnalysisState *) AnalysisStateSet; @@ -4586,7 +4617,7 @@ typedef struct AnalysisStateSet deeper_states; AnalysisStateSet state_pool; Array(uint16_t) final_step_indices; - Array(TSSymbol) finished_parent_symbols; + Array(t_symbol) finished_parent_symbols; bool did_abort; } QueryAnalysis; @@ -4598,16 +4629,16 @@ typedef struct */ typedef struct { - TSStateId state; - uint16_t production_id; - uint8_t child_index : 7; - bool done : 1; + t_state_id state; + uint16_t production_id; + uint8_t child_index : 7; + bool done : 1; } AnalysisSubgraphNode; typedef struct { - TSSymbol symbol; - Array(TSStateId) start_states; + t_symbol symbol; + Array(t_state_id) start_states; Array(AnalysisSubgraphNode) nodes; } AnalysisSubgraph; @@ -4620,38 +4651,38 @@ typedef Array(AnalysisSubgraph) AnalysisSubgraphArray; */ typedef struct { - TSStateId *contents; + t_state_id *contents; } StatePredecessorMap; /* - * TSQuery - A tree query, compiled from a string of S-expressions. The query - * itself is immutable. The mutable state used in the process of executing the - * query is stored in a `TSQueryCursor`. + * t_parse_query - A tree query, compiled from a string of S-expressions. The + * query itself is immutable. The mutable state used in the process of executing + * the query is stored in a `t_query_cursor`. */ -struct TSQuery +struct s_parse_query { SymbolTable captures; SymbolTable predicate_values; Array(CaptureQuantifiers) capture_quantifiers; Array(QueryStep) steps; Array(PatternEntry) pattern_map; - Array(TSQueryPredicateStep) predicate_steps; + Array(t_query_predicate_step) predicate_steps; Array(QueryPattern) patterns; Array(StepOffset) step_offsets; - Array(TSFieldId) negated_fields; + Array(t_field_id) negated_fields; Array(char) string_buffer; - Array(TSSymbol) repeat_symbols_with_rootless_patterns; - const TSLanguage *language; + Array(t_symbol) repeat_symbols_with_rootless_patterns; + const t_language *language; uint16_t wildcard_root_pattern_count; }; /* - * TSQueryCursor - A stateful struct used to execute a query on a tree. + * t_query_cursor - A stateful struct used to execute a query on a tree. */ -struct TSQueryCursor +struct s_query_cursor { - const TSQuery *query; - TSTreeCursor cursor; + const t_parse_query *query; + t_tree_cursor cursor; Array(QueryState) states; Array(QueryState) finished_states; CaptureListPool capture_list_pool; @@ -4659,8 +4690,8 @@ struct TSQueryCursor uint32_t max_start_depth; uint32_t start_byte; uint32_t end_byte; - TSPoint start_point; - TSPoint end_point; + t_point start_point; + t_point end_point; uint32_t next_state_id; bool on_visible_node; bool ascending; @@ -4668,10 +4699,10 @@ struct TSQueryCursor bool did_exceed_match_limit; }; -static const TSQueryError PARENT_DONE = -1; -static const uint16_t PATTERN_DONE_MARKER = UINT16_MAX; -static const uint16_t NONE = UINT16_MAX; -static const TSSymbol WILDCARD_SYMBOL = 0; +static const t_query_error PARENT_DONE = -1; +static const uint16_t PATTERN_DONE_MARKER = UINT16_MAX; +static const uint16_t NONE = UINT16_MAX; +static const t_symbol WILDCARD_SYMBOL = 0; /********** * Stream @@ -4863,7 +4894,7 @@ static void capture_list_pool_release(CaptureListPool *self, uint16_t id) * Quantifiers **************/ -static TSQuantifier quantifier_mul(TSQuantifier left, TSQuantifier right) +static t_quantifier quantifier_mul(t_quantifier left, t_quantifier right) { switch (left) { @@ -4914,7 +4945,7 @@ static TSQuantifier quantifier_mul(TSQuantifier left, TSQuantifier right) // covered above! } -static TSQuantifier quantifier_join(TSQuantifier left, TSQuantifier right) +static t_quantifier quantifier_join(t_quantifier left, t_quantifier right) { switch (left) { @@ -4978,7 +5009,7 @@ static TSQuantifier quantifier_join(TSQuantifier left, TSQuantifier right) // covered above! } -static TSQuantifier quantifier_add(TSQuantifier left, TSQuantifier right) +static t_quantifier quantifier_add(t_quantifier left, t_quantifier right) { switch (left) { @@ -5056,16 +5087,16 @@ static void capture_quantifiers_replace(CaptureQuantifiers *self, } // Return capture quantifier for the given capture id -static TSQuantifier capture_quantifier_for_id(const CaptureQuantifiers *self, +static t_quantifier capture_quantifier_for_id(const CaptureQuantifiers *self, uint16_t id) { return (self->size <= id) ? TSQuantifierZero - : (TSQuantifier)*array_get(self, id); + : (t_quantifier)*array_get(self, id); } // Add the given quantifier to the current value for id static void capture_quantifiers_add_for_id(CaptureQuantifiers *self, - uint16_t id, TSQuantifier quantifier) + uint16_t id, t_quantifier quantifier) { if (self->size <= id) { @@ -5073,7 +5104,7 @@ static void capture_quantifiers_add_for_id(CaptureQuantifiers *self, } uint8_t *own_quantifier = array_get(self, id); *own_quantifier = - (uint8_t)quantifier_add((TSQuantifier)*own_quantifier, quantifier); + (uint8_t)quantifier_add((t_quantifier)*own_quantifier, quantifier); } // Point-wise add the given quantifiers to the current values @@ -5088,20 +5119,20 @@ static void capture_quantifiers_add_all(CaptureQuantifiers *self, { uint8_t *quantifier = array_get(quantifiers, id); uint8_t *own_quantifier = array_get(self, id); - *own_quantifier = (uint8_t)quantifier_add((TSQuantifier)*own_quantifier, - (TSQuantifier)*quantifier); + *own_quantifier = (uint8_t)quantifier_add((t_quantifier)*own_quantifier, + (t_quantifier)*quantifier); } } // Join the given quantifier with the current values static void capture_quantifiers_mul(CaptureQuantifiers *self, - TSQuantifier quantifier) + t_quantifier quantifier) { for (uint16_t id = 0; id < (uint16_t)self->size; id++) { uint8_t *own_quantifier = array_get(self, id); *own_quantifier = - (uint8_t)quantifier_mul((TSQuantifier)*own_quantifier, quantifier); + (uint8_t)quantifier_mul((t_quantifier)*own_quantifier, quantifier); } } @@ -5119,13 +5150,13 @@ static void capture_quantifiers_join_all(CaptureQuantifiers *self, uint8_t *quantifier = array_get(quantifiers, id); uint8_t *own_quantifier = array_get(self, id); *own_quantifier = (uint8_t)quantifier_join( - (TSQuantifier)*own_quantifier, (TSQuantifier)*quantifier); + (t_quantifier)*own_quantifier, (t_quantifier)*quantifier); } for (uint32_t id = quantifiers->size; id < self->size; id++) { uint8_t *own_quantifier = array_get(self, id); *own_quantifier = (uint8_t)quantifier_join( - (TSQuantifier)*own_quantifier, TSQuantifierZero); + (t_quantifier)*own_quantifier, TSQuantifierZero); } } @@ -5189,7 +5220,7 @@ static uint16_t symbol_table_insert_name(SymbolTable *self, const char *name, * QueryStep ************/ -static QueryStep query_step__new(TSSymbol symbol, uint16_t depth, +static QueryStep query_step__new(t_symbol symbol, uint16_t depth, bool is_immediate) { QueryStep step = { @@ -5251,12 +5282,12 @@ static void query_step__remove_capture(QueryStep *self, uint16_t capture_id) **********************/ static inline StatePredecessorMap state_predecessor_map_new( - const TSLanguage *language) + const t_language *language) { return (StatePredecessorMap){ .contents = calloc((size_t)language->state_count * (MAX_STATE_PREDECESSOR_COUNT + 1), - sizeof(TSStateId)), + sizeof(t_state_id)), }; } @@ -5266,11 +5297,11 @@ static inline void state_predecessor_map_delete(StatePredecessorMap *self) } static inline void state_predecessor_map_add(StatePredecessorMap *self, - TSStateId state, - TSStateId predecessor) + t_state_id state, + t_state_id predecessor) { - size_t index = (size_t)state * (MAX_STATE_PREDECESSOR_COUNT + 1); - TSStateId *count = &self->contents[index]; + size_t index = (size_t)state * (MAX_STATE_PREDECESSOR_COUNT + 1); + t_state_id *count = &self->contents[index]; if (*count == 0 || (*count < MAX_STATE_PREDECESSOR_COUNT && self->contents[index + *count] != predecessor)) { @@ -5279,8 +5310,8 @@ static inline void state_predecessor_map_add(StatePredecessorMap *self, } } -static inline const TSStateId *state_predecessor_map_get( - const StatePredecessorMap *self, TSStateId state, unsigned *count) +static inline const t_state_id *state_predecessor_map_get( + const StatePredecessorMap *self, t_state_id state, unsigned *count) { size_t index = (size_t)state * (MAX_STATE_PREDECESSOR_COUNT + 1); *count = self->contents[index]; @@ -5296,7 +5327,7 @@ static unsigned analysis_state__recursion_depth(const AnalysisState *self) unsigned result = 0; for (unsigned i = 0; i < self->depth; i++) { - TSSymbol symbol = self->stack[i].parent_symbol; + t_symbol symbol = self->stack[i].parent_symbol; for (unsigned j = 0; j < i; j++) { if (self->stack[j].parent_symbol == symbol) @@ -5364,7 +5395,7 @@ static inline AnalysisStateEntry *analysis_state__top(AnalysisState *self) } static inline bool analysis_state__has_supertype(AnalysisState *self, - TSSymbol symbol) + t_symbol symbol) { for (unsigned i = 0; i < self->depth; i++) { @@ -5512,7 +5543,7 @@ static inline int analysis_subgraph_node__compare( * Query *********/ -// The `pattern_map` contains a mapping from TSSymbol values to indices in the +// The `pattern_map` contains a mapping from t_symbol values to indices in the // `steps` array. For a given syntax node, the `pattern_map` makes it possible // to quickly find the starting steps of all of the patterns whose root matches // that node. Each entry has two fields: a `pattern_index`, which identifies one @@ -5526,9 +5557,9 @@ static inline int analysis_subgraph_node__compare( // This returns `true` if the symbol is present and `false` otherwise. // If the symbol is not present `*result` is set to the index where the // symbol should be inserted. -static inline bool ts_query__pattern_map_search(const TSQuery *self, - TSSymbol needle, - uint32_t *result) +static inline bool ts_query__pattern_map_search(const t_parse_query *self, + t_symbol needle, + uint32_t *result) { uint32_t base_index = self->wildcard_root_pattern_count; uint32_t size = self->pattern_map.size - base_index; @@ -5541,7 +5572,7 @@ static inline bool ts_query__pattern_map_search(const TSQuery *self, { uint32_t half_size = size / 2; uint32_t mid_index = base_index + half_size; - TSSymbol mid_symbol = + t_symbol mid_symbol = self->steps .contents[self->pattern_map.contents[mid_index].step_index] .symbol; @@ -5550,7 +5581,7 @@ static inline bool ts_query__pattern_map_search(const TSQuery *self, size -= half_size; } - TSSymbol symbol = + t_symbol symbol = self->steps.contents[self->pattern_map.contents[base_index].step_index] .symbol; @@ -5572,8 +5603,9 @@ static inline bool ts_query__pattern_map_search(const TSQuery *self, // Insert a new pattern's start index into the pattern map, maintaining // the pattern map's ordering invariant. -static inline void ts_query__pattern_map_insert(TSQuery *self, TSSymbol symbol, - PatternEntry new_entry) +static inline void ts_query__pattern_map_insert(t_parse_query *self, + t_symbol symbol, + PatternEntry new_entry) { uint32_t index; ts_query__pattern_map_search(self, symbol, &index); @@ -5601,7 +5633,7 @@ static inline void ts_query__pattern_map_insert(TSQuery *self, TSSymbol symbol, // Walk the subgraph for this non-terminal, tracking all of the possible // sequences of progress within the pattern. -static void ts_query__perform_analysis(TSQuery *self, +static void ts_query__perform_analysis(t_parse_query *self, const AnalysisSubgraphArray *subgraphs, QueryAnalysis *analysis) { @@ -5710,11 +5742,11 @@ static void ts_query__perform_analysis(TSQuery *self, } } - const TSStateId parse_state = + const t_state_id parse_state = analysis_state__top(state)->parse_state; - const TSSymbol parent_symbol = + const t_symbol parent_symbol = analysis_state__top(state)->parent_symbol; - const TSFieldId parent_field_id = + const t_field_id parent_field_id = analysis_state__top(state)->field_id; const unsigned child_index = analysis_state__top(state)->child_index; @@ -5731,11 +5763,11 @@ static void ts_query__perform_analysis(TSQuery *self, // Follow every possible path in the parse table, but only visit // states that are part of the subgraph for the current symbol. - LookaheadIterator lookahead_iterator = + t_lookahead_iterator lookahead_iterator = ts_language_lookaheads(self->language, parse_state); while (ts_lookahead_iterator__next(&lookahead_iterator)) { - TSSymbol sym = lookahead_iterator.symbol; + t_symbol sym = lookahead_iterator.symbol; AnalysisSubgraphNode successor = { .state = parse_state, @@ -5743,7 +5775,7 @@ static void ts_query__perform_analysis(TSQuery *self, }; if (lookahead_iterator.action_count) { - const TSParseAction *action = + const t_parse_action *action = &lookahead_iterator .actions[lookahead_iterator.action_count - 1]; if (action->type == TSParseActionTypeShift) @@ -5783,17 +5815,17 @@ static void ts_query__perform_analysis(TSQuery *self, // Use the subgraph to determine what alias and field will // eventually be applied to this child node. - TSSymbol alias = ts_language_alias_at( + t_symbol alias = ts_language_alias_at( self->language, node->production_id, child_index); - TSSymbol visible_symbol = + t_symbol visible_symbol = alias ? alias : self->language->symbol_metadata[sym].visible ? self->language->public_symbol_map[sym] : 0; - TSFieldId field_id = parent_field_id; + t_field_id field_id = parent_field_id; if (!field_id) { - const TSFieldMapEntry *field_map, *field_map_end; + const t_field_map_entry *field_map, *field_map_end; ts_language_field_map(self->language, node->production_id, &field_map, &field_map_end); @@ -5992,7 +6024,8 @@ static void ts_query__perform_analysis(TSQuery *self, } } -static bool ts_query__analyze_patterns(TSQuery *self, unsigned *error_offset) +static bool ts_query__analyze_patterns(t_parse_query *self, + unsigned *error_offset) { Array(uint16_t) non_rooted_pattern_start_steps = array_new(); for (unsigned i = 0; i < self->pattern_map.size; i++) @@ -6062,11 +6095,11 @@ static bool ts_query__analyze_patterns(TSQuery *self, unsigned *error_offset) for (unsigned i = 0; i < parent_step_indices.size; i++) { uint32_t parent_step_index = parent_step_indices.contents[i]; - TSSymbol parent_symbol = self->steps.contents[parent_step_index].symbol; + t_symbol parent_symbol = self->steps.contents[parent_step_index].symbol; AnalysisSubgraph subgraph = {.symbol = parent_symbol}; array_insert_sorted_by(&subgraphs, .symbol, subgraph); } - for (TSSymbol sym = (uint16_t)self->language->token_count; + for (t_symbol sym = (uint16_t)self->language->token_count; sym < (uint16_t)self->language->symbol_count; sym++) { if (!ts_language_symbol_metadata(self->language, sym).visible) @@ -6084,11 +6117,11 @@ static bool ts_query__analyze_patterns(TSQuery *self, unsigned *error_offset) // 3) A list of predecessor states for each state. StatePredecessorMap predecessor_map = state_predecessor_map_new(self->language); - for (TSStateId state = 1; state < (uint16_t)self->language->state_count; + for (t_state_id state = 1; state < (uint16_t)self->language->state_count; state++) { - unsigned subgraph_index, exists; - LookaheadIterator lookahead_iterator = + unsigned subgraph_index, exists; + t_lookahead_iterator lookahead_iterator = ts_language_lookaheads(self->language, state); while (ts_lookahead_iterator__next(&lookahead_iterator)) { @@ -6096,15 +6129,15 @@ static bool ts_query__analyze_patterns(TSQuery *self, unsigned *error_offset) { for (unsigned i = 0; i < lookahead_iterator.action_count; i++) { - const TSParseAction *action = + const t_parse_action *action = &lookahead_iterator.actions[i]; if (action->type == TSParseActionTypeReduce) { - const TSSymbol *aliases, *aliases_end; + const t_symbol *aliases, *aliases_end; ts_language_aliases_for_symbol(self->language, action->reduce.symbol, &aliases, &aliases_end); - for (const TSSymbol *symbol = aliases; + for (const t_symbol *symbol = aliases; symbol < aliases_end; symbol++) { array_search_sorted_by(&subgraphs, .symbol, *symbol, @@ -6134,7 +6167,7 @@ static bool ts_query__analyze_patterns(TSQuery *self, unsigned *error_offset) else if (action->type == TSParseActionTypeShift && !action->shift.extra) { - TSStateId next_state = action->shift.state; + t_state_id next_state = action->shift.state; state_predecessor_map_add(&predecessor_map, next_state, state); } @@ -6149,11 +6182,11 @@ static bool ts_query__analyze_patterns(TSQuery *self, unsigned *error_offset) } if (ts_language_state_is_primary(self->language, state)) { - const TSSymbol *aliases, *aliases_end; + const t_symbol *aliases, *aliases_end; ts_language_aliases_for_symbol(self->language, lookahead_iterator.symbol, &aliases, &aliases_end); - for (const TSSymbol *symbol = aliases; symbol < aliases_end; + for (const t_symbol *symbol = aliases; symbol < aliases_end; symbol++) { array_search_sorted_by(&subgraphs, .symbol, *symbol, @@ -6191,8 +6224,8 @@ static bool ts_query__analyze_patterns(TSQuery *self, unsigned *error_offset) AnalysisSubgraphNode node = array_pop(&next_nodes); if (node.child_index > 1) { - unsigned predecessor_count; - const TSStateId *predecessors = state_predecessor_map_get( + unsigned predecessor_count; + const t_state_id *predecessors = state_predecessor_map_get( &predecessor_map, node.state, &predecessor_count); for (unsigned j = 0; j < predecessor_count; j++) { @@ -6248,7 +6281,7 @@ static bool ts_query__analyze_patterns(TSQuery *self, unsigned *error_offset) { uint16_t parent_step_index = parent_step_indices.contents[i]; uint16_t parent_depth = self->steps.contents[parent_step_index].depth; - TSSymbol parent_symbol = self->steps.contents[parent_step_index].symbol; + t_symbol parent_symbol = self->steps.contents[parent_step_index].symbol; if (parent_symbol == ts_builtin_sym_error) continue; @@ -6277,7 +6310,7 @@ static bool ts_query__analyze_patterns(TSQuery *self, unsigned *error_offset) &analysis.state_pool); for (unsigned j = 0; j < subgraph->start_states.size; j++) { - TSStateId parse_state = subgraph->start_states.contents[j]; + t_state_id parse_state = subgraph->start_states.contents[j]; analysis_state_set__push( &analysis.states, &analysis.state_pool, &((AnalysisState){ @@ -6374,7 +6407,7 @@ static bool ts_query__analyze_patterns(TSQuery *self, unsigned *error_offset) end = start + pattern->predicate_steps.length, j = start; j < end; j++) { - TSQueryPredicateStep *step = &self->predicate_steps.contents[j]; + t_query_predicate_step *step = &self->predicate_steps.contents[j]; if (step->type == TSQueryPredicateStepTypeCapture) { uint16_t value_id = step->value_id; @@ -6493,14 +6526,14 @@ static bool ts_query__analyze_patterns(TSQuery *self, unsigned *error_offset) for (unsigned j = 0; j < subgraphs.size; j++) { AnalysisSubgraph *subgraph = &subgraphs.contents[j]; - TSSymbolMetadata metadata = + t_symbol_metadata metadata = ts_language_symbol_metadata(self->language, subgraph->symbol); if (metadata.visible || metadata.named) continue; for (uint32_t k = 0; k < subgraph->start_states.size; k++) { - TSStateId parse_state = subgraph->start_states.contents[k]; + t_state_id parse_state = subgraph->start_states.contents[k]; analysis_state_set__push( &analysis.states, &analysis.state_pool, &((AnalysisState){ @@ -6537,7 +6570,7 @@ static bool ts_query__analyze_patterns(TSQuery *self, unsigned *error_offset) for (unsigned k = 0; k < analysis.finished_parent_symbols.size; k++) { - TSSymbol symbol = analysis.finished_parent_symbols.contents[k]; + t_symbol symbol = analysis.finished_parent_symbols.contents[k]; array_insert_sorted_by(&self->repeat_symbols_with_rootless_patterns, , symbol); } @@ -6551,7 +6584,7 @@ static bool ts_query__analyze_patterns(TSQuery *self, unsigned *error_offset) for (unsigned i = 0; i < self->repeat_symbols_with_rootless_patterns.size; i++) { - TSSymbol symbol = + t_symbol symbol = self->repeat_symbols_with_rootless_patterns.contents[i]; printf(" %u, %s\n", symbol, ts_language_symbol_name(self->language, symbol)); @@ -6577,9 +6610,10 @@ static bool ts_query__analyze_patterns(TSQuery *self, unsigned *error_offset) return all_patterns_are_valid; } -static void ts_query__add_negated_fields(TSQuery *self, uint16_t step_index, - TSFieldId *field_ids, - uint16_t field_count) +static void ts_query__add_negated_fields(t_parse_query *self, + uint16_t step_index, + t_field_id *field_ids, + uint16_t field_count) { QueryStep *step = &self->steps.contents[step_index]; @@ -6591,7 +6625,7 @@ static void ts_query__add_negated_fields(TSQuery *self, uint16_t step_index, unsigned start_i = 0; for (unsigned i = 0; i < self->negated_fields.size; i++) { - TSFieldId existing_field_id = self->negated_fields.contents[i]; + t_field_id existing_field_id = self->negated_fields.contents[i]; // At each zero value, terminate the match attempt. If we've exactly // matched the new field list, then reuse this index. Otherwise, @@ -6632,8 +6666,8 @@ static void ts_query__add_negated_fields(TSQuery *self, uint16_t step_index, array_push(&self->negated_fields, 0); } -static TSQueryError ts_query__parse_string_literal(TSQuery *self, - Stream *stream) +static t_query_error ts_query__parse_string_literal(t_parse_query *self, + Stream *stream) { const char *string_start = stream->input; if (stream->next != '"') @@ -6707,7 +6741,8 @@ static TSQueryError ts_query__parse_string_literal(TSQuery *self, // a higher level of abstraction, such as the Rust/JavaScript bindings. They // can contain '@'-prefixed capture names, double-quoted strings, and bare // symbols, which also represent strings. -static TSQueryError ts_query__parse_predicate(TSQuery *self, Stream *stream) +static t_query_error ts_query__parse_predicate(t_parse_query *self, + Stream *stream) { if (!stream_is_ident_start(stream)) return TSQueryErrorSyntax; @@ -6717,7 +6752,7 @@ static TSQueryError ts_query__parse_predicate(TSQuery *self, Stream *stream) uint16_t id = symbol_table_insert_name(&self->predicate_values, predicate_name, length); array_push(&self->predicate_steps, - ((TSQueryPredicateStep){ + ((t_query_predicate_step){ .type = TSQueryPredicateStepTypeString, .value_id = id, })); @@ -6730,7 +6765,7 @@ static TSQueryError ts_query__parse_predicate(TSQuery *self, Stream *stream) stream_advance(stream); stream_skip_whitespace(stream); array_push(&self->predicate_steps, - ((TSQueryPredicateStep){ + ((t_query_predicate_step){ .type = TSQueryPredicateStepTypeDone, .value_id = 0, })); @@ -6759,7 +6794,7 @@ static TSQueryError ts_query__parse_predicate(TSQuery *self, Stream *stream) } array_push(&self->predicate_steps, - ((TSQueryPredicateStep){ + ((t_query_predicate_step){ .type = TSQueryPredicateStepTypeCapture, .value_id = capture_id, })); @@ -6768,14 +6803,14 @@ static TSQueryError ts_query__parse_predicate(TSQuery *self, Stream *stream) // Parse a string literal else if (stream->next == '"') { - TSQueryError e = ts_query__parse_string_literal(self, stream); + t_query_error e = ts_query__parse_string_literal(self, stream); if (e) return e; uint16_t query_id = symbol_table_insert_name( &self->predicate_values, self->string_buffer.contents, self->string_buffer.size); array_push(&self->predicate_steps, - ((TSQueryPredicateStep){ + ((t_query_predicate_step){ .type = TSQueryPredicateStepTypeString, .value_id = query_id, })); @@ -6790,7 +6825,7 @@ static TSQueryError ts_query__parse_predicate(TSQuery *self, Stream *stream) uint16_t query_id = symbol_table_insert_name( &self->predicate_values, symbol_start, symbol_length); array_push(&self->predicate_steps, - ((TSQueryPredicateStep){ + ((t_query_predicate_step){ .type = TSQueryPredicateStepTypeString, .value_id = query_id, })); @@ -6814,8 +6849,8 @@ static TSQueryError ts_query__parse_predicate(TSQuery *self, Stream *stream) // The caller is responsible for passing in a dedicated CaptureQuantifiers. // These should not be shared between different calls to // ts_query__parse_pattern! -static TSQueryError ts_query__parse_pattern( - TSQuery *self, Stream *stream, uint32_t depth, bool is_immediate, +static t_query_error ts_query__parse_pattern( + t_parse_query *self, Stream *stream, uint32_t depth, bool is_immediate, CaptureQuantifiers *capture_quantifiers) { if (stream->next == 0) @@ -6849,8 +6884,8 @@ static TSQueryError ts_query__parse_pattern( capture_quantifiers_new(); for (;;) { - uint32_t start_index = self->steps.size; - TSQueryError e = ts_query__parse_pattern( + uint32_t start_index = self->steps.size; + t_query_error e = ts_query__parse_pattern( self, stream, depth, is_immediate, &branch_capture_quantifiers); if (e == PARENT_DONE) @@ -6928,7 +6963,7 @@ static TSQueryError ts_query__parse_pattern( stream_advance(stream); stream_skip_whitespace(stream); } - TSQueryError e = ts_query__parse_pattern( + t_query_error e = ts_query__parse_pattern( self, stream, depth, child_is_immediate, &child_capture_quantifiers); if (e == PARENT_DONE) @@ -6965,7 +7000,7 @@ static TSQueryError ts_query__parse_pattern( // Otherwise, this parenthesis is the start of a named node. else { - TSSymbol symbol; + t_symbol symbol; // Parse a normal node name if (stream_is_ident_start(stream)) @@ -7039,7 +7074,7 @@ static TSQueryError ts_query__parse_pattern( bool child_is_immediate = false; uint16_t last_child_step_index = 0; uint16_t negated_field_count = 0; - TSFieldId negated_field_ids[MAX_NEGATED_FIELD_COUNT]; + t_field_id negated_field_ids[MAX_NEGATED_FIELD_COUNT]; CaptureQuantifiers child_capture_quantifiers = capture_quantifiers_new(); for (;;) @@ -7059,7 +7094,7 @@ static TSQueryError ts_query__parse_pattern( uint32_t length = (uint32_t)(stream->input - field_name); stream_skip_whitespace(stream); - TSFieldId field_id = ts_language_field_id_for_name( + t_field_id field_id = ts_language_field_id_for_name( self->language, field_name, length); if (!field_id) { @@ -7086,8 +7121,8 @@ static TSQueryError ts_query__parse_pattern( stream_skip_whitespace(stream); } - uint16_t step_index = self->steps.size; - TSQueryError e = ts_query__parse_pattern( + uint16_t step_index = self->steps.size; + t_query_error e = ts_query__parse_pattern( self, stream, depth + 1, child_is_immediate, &child_capture_quantifiers); if (e == PARENT_DONE) @@ -7149,13 +7184,13 @@ static TSQueryError ts_query__parse_pattern( // Parse a double-quoted anonymous leaf node expression else if (stream->next == '"') { - const char *string_start = stream->input; - TSQueryError e = ts_query__parse_string_literal(self, stream); + const char *string_start = stream->input; + t_query_error e = ts_query__parse_string_literal(self, stream); if (e) return e; // Add a step for the node - TSSymbol symbol = ts_language_symbol_for_name( + t_symbol symbol = ts_language_symbol_for_name( self->language, self->string_buffer.contents, self->string_buffer.size, false); if (!symbol) @@ -7186,7 +7221,7 @@ static TSQueryError ts_query__parse_pattern( // Parse the pattern CaptureQuantifiers field_capture_quantifiers = capture_quantifiers_new(); - TSQueryError e = ts_query__parse_pattern( + t_query_error e = ts_query__parse_pattern( self, stream, depth, is_immediate, &field_capture_quantifiers); if (e) { @@ -7197,7 +7232,7 @@ static TSQueryError ts_query__parse_pattern( } // Add the field name to the first step of the pattern - TSFieldId field_id = + t_field_id field_id = ts_language_field_id_for_name(self->language, field_name, length); if (!field_id) { @@ -7236,7 +7271,7 @@ static TSQueryError ts_query__parse_pattern( stream_skip_whitespace(stream); // Parse suffixes modifiers for this pattern - TSQuantifier quantifier = TSQuantifierOne; + t_quantifier quantifier = TSQuantifierOne; for (;;) { // Parse the one-or-more operator. @@ -7348,13 +7383,13 @@ static TSQueryError ts_query__parse_pattern( return 0; } -TSQuery *ts_query_new(const TSLanguage *language, const char *source, - uint32_t source_len, uint32_t *error_offset, - TSQueryError *error_type) +t_parse_query *ts_query_new(const t_language *language, const char *source, + uint32_t source_len, uint32_t *error_offset, + t_query_error *error_type) { - TSQuery *self = malloc(sizeof(TSQuery)); - *self = (TSQuery){ + t_parse_query *self = malloc(sizeof(t_parse_query)); + *self = (t_parse_query){ .steps = array_new(), .pattern_map = array_new(), .captures = symbol_table_new(), @@ -7497,7 +7532,7 @@ TSQuery *ts_query_new(const TSLanguage *language, const char *source, return self; } -void ts_query_delete(TSQuery *self) +void ts_query_delete(t_parse_query *self) { if (self) { @@ -7524,44 +7559,44 @@ void ts_query_delete(TSQuery *self) } } -uint32_t ts_query_pattern_count(const TSQuery *self) +uint32_t ts_query_pattern_count(const t_parse_query *self) { return self->patterns.size; } -uint32_t ts_query_capture_count(const TSQuery *self) +uint32_t ts_query_capture_count(const t_parse_query *self) { return self->captures.slices.size; } -uint32_t ts_query_string_count(const TSQuery *self) +uint32_t ts_query_string_count(const t_parse_query *self) { return self->predicate_values.slices.size; } -const char *ts_query_capture_name_for_id(const TSQuery *self, uint32_t index, - uint32_t *length) +const char *ts_query_capture_name_for_id(const t_parse_query *self, + uint32_t index, uint32_t *length) { return symbol_table_name_for_id(&self->captures, index, length); } -TSQuantifier ts_query_capture_quantifier_for_id(const TSQuery *self, - uint32_t pattern_index, - uint32_t capture_index) +t_quantifier ts_query_capture_quantifier_for_id(const t_parse_query *self, + uint32_t pattern_index, + uint32_t capture_index) { CaptureQuantifiers *capture_quantifiers = array_get(&self->capture_quantifiers, pattern_index); return capture_quantifier_for_id(capture_quantifiers, capture_index); } -const char *ts_query_string_value_for_id(const TSQuery *self, uint32_t index, - uint32_t *length) +const char *ts_query_string_value_for_id(const t_parse_query *self, + uint32_t index, uint32_t *length) { return symbol_table_name_for_id(&self->predicate_values, index, length); } -const TSQueryPredicateStep *ts_query_predicates_for_pattern( - const TSQuery *self, uint32_t pattern_index, uint32_t *step_count) +const t_query_predicate_step *ts_query_predicates_for_pattern( + const t_parse_query *self, uint32_t pattern_index, uint32_t *step_count) { Slice slice = self->patterns.contents[pattern_index].predicate_steps; *step_count = slice.length; @@ -7572,13 +7607,14 @@ const TSQueryPredicateStep *ts_query_predicates_for_pattern( return &self->predicate_steps.contents[slice.offset]; } -uint32_t ts_query_start_byte_for_pattern(const TSQuery *self, - uint32_t pattern_index) +uint32_t ts_query_start_byte_for_pattern(const t_parse_query *self, + uint32_t pattern_index) { return self->patterns.contents[pattern_index].start_byte; } -bool ts_query_is_pattern_rooted(const TSQuery *self, uint32_t pattern_index) +bool ts_query_is_pattern_rooted(const t_parse_query *self, + uint32_t pattern_index) { for (unsigned i = 0; i < self->pattern_map.size; i++) { @@ -7592,7 +7628,8 @@ bool ts_query_is_pattern_rooted(const TSQuery *self, uint32_t pattern_index) return true; } -bool ts_query_is_pattern_non_local(const TSQuery *self, uint32_t pattern_index) +bool ts_query_is_pattern_non_local(const t_parse_query *self, + uint32_t pattern_index) { if (pattern_index < self->patterns.size) { @@ -7604,8 +7641,8 @@ bool ts_query_is_pattern_non_local(const TSQuery *self, uint32_t pattern_index) } } -bool ts_query_is_pattern_guaranteed_at_step(const TSQuery *self, - uint32_t byte_offset) +bool ts_query_is_pattern_guaranteed_at_step(const t_parse_query *self, + uint32_t byte_offset) { uint32_t step_index = UINT32_MAX; for (unsigned i = 0; i < self->step_offsets.size; i++) @@ -7625,7 +7662,7 @@ bool ts_query_is_pattern_guaranteed_at_step(const TSQuery *self, } } -bool ts_query__step_is_fallible(const TSQuery *self, uint16_t step_index) +bool ts_query__step_is_fallible(const t_parse_query *self, uint16_t step_index) { assert((uint32_t)step_index + 1 < self->steps.size); QueryStep *step = &self->steps.contents[step_index]; @@ -7635,7 +7672,8 @@ bool ts_query__step_is_fallible(const TSQuery *self, uint16_t step_index) !next_step->parent_pattern_guaranteed); } -void ts_query_disable_capture(TSQuery *self, const char *name, uint32_t length) +void ts_query_disable_capture(t_parse_query *self, const char *name, + uint32_t length) { // Remove capture information for any pattern step that previously // captured with the given name. @@ -7650,7 +7688,7 @@ void ts_query_disable_capture(TSQuery *self, const char *name, uint32_t length) } } -void ts_query_disable_pattern(TSQuery *self, uint32_t pattern_index) +void ts_query_disable_pattern(t_parse_query *self, uint32_t pattern_index) { // Remove the given pattern from the pattern map. Its steps will still // be in the `steps` array, but they will never be read. @@ -7669,10 +7707,10 @@ void ts_query_disable_pattern(TSQuery *self, uint32_t pattern_index) * QueryCursor ***************/ -TSQueryCursor *ts_query_cursor_new(void) +t_query_cursor *ts_query_cursor_new(void) { - TSQueryCursor *self = malloc(sizeof(TSQueryCursor)); - *self = (TSQueryCursor){ + t_query_cursor *self = malloc(sizeof(t_query_cursor)); + *self = (t_query_cursor){ .did_exceed_match_limit = false, .ascending = false, .halted = false, @@ -7690,7 +7728,7 @@ TSQueryCursor *ts_query_cursor_new(void) return self; } -void ts_query_cursor_delete(TSQueryCursor *self) +void ts_query_cursor_delete(t_query_cursor *self) { array_delete(&self->states); array_delete(&self->finished_states); @@ -7699,17 +7737,17 @@ void ts_query_cursor_delete(TSQueryCursor *self) free(self); } -bool ts_query_cursor_did_exceed_match_limit(const TSQueryCursor *self) +bool ts_query_cursor_did_exceed_match_limit(const t_query_cursor *self) { return self->did_exceed_match_limit; } -uint32_t ts_query_cursor_match_limit(const TSQueryCursor *self) +uint32_t ts_query_cursor_match_limit(const t_query_cursor *self) { return self->capture_list_pool.max_capture_list_count; } -void ts_query_cursor_set_match_limit(TSQueryCursor *self, uint32_t limit) +void ts_query_cursor_set_match_limit(t_query_cursor *self, uint32_t limit) { self->capture_list_pool.max_capture_list_count = limit; } @@ -7720,8 +7758,8 @@ void ts_query_cursor_set_match_limit(TSQueryCursor *self, uint32_t limit) # define LOG(...) #endif -void ts_query_cursor_exec(TSQueryCursor *self, const TSQuery *query, - TSNode node) +void ts_query_cursor_exec(t_query_cursor *self, const t_parse_query *query, + t_parse_node node) { if (query) { @@ -7775,7 +7813,7 @@ void ts_query_cursor_exec(TSQueryCursor *self, const TSQuery *query, self->did_exceed_match_limit = false; } -void ts_query_cursor_set_byte_range(TSQueryCursor *self, uint32_t start_byte, +void ts_query_cursor_set_byte_range(t_query_cursor *self, uint32_t start_byte, uint32_t end_byte) { if (end_byte == 0) @@ -7786,8 +7824,8 @@ void ts_query_cursor_set_byte_range(TSQueryCursor *self, uint32_t start_byte, self->end_byte = end_byte; } -void ts_query_cursor_set_point_range(TSQueryCursor *self, TSPoint start_point, - TSPoint end_point) +void ts_query_cursor_set_point_range(t_query_cursor *self, t_point start_point, + t_point end_point) { if (end_point.row == 0 && end_point.column == 0) { @@ -7800,7 +7838,7 @@ void ts_query_cursor_set_point_range(TSQueryCursor *self, TSPoint start_point, // Search through all of the in-progress states, and find the captured // node that occurs earliest in the document. static bool ts_query_cursor__first_in_progress_capture( - TSQueryCursor *self, uint32_t *state_index, uint32_t *byte_offset, + t_query_cursor *self, uint32_t *state_index, uint32_t *byte_offset, uint32_t *pattern_index, bool *root_pattern_guaranteed) { bool result = false; @@ -7820,7 +7858,8 @@ static bool ts_query_cursor__first_in_progress_capture( continue; } - TSNode node = captures->contents[state->consumed_capture_count].node; + t_parse_node node = + captures->contents[state->consumed_capture_count].node; if (ts_node_end_byte(node) <= self->start_byte || point_lte(ts_node_end_point(node), self->start_point)) { @@ -7854,7 +7893,7 @@ static bool ts_query_cursor__first_in_progress_capture( } // Determine which node is first in a depth-first traversal -int ts_query_cursor__compare_nodes(TSNode left, TSNode right) +int ts_query_cursor__compare_nodes(t_parse_node left, t_parse_node right) { if (left.id != right.id) { @@ -7875,11 +7914,11 @@ int ts_query_cursor__compare_nodes(TSNode left, TSNode right) } // Determine if either state contains a superset of the other state's captures. -void ts_query_cursor__compare_captures(TSQueryCursor *self, - QueryState *left_state, - QueryState *right_state, - bool *left_contains_right, - bool *right_contains_left) +void ts_query_cursor__compare_captures(t_query_cursor *self, + QueryState *left_state, + QueryState *right_state, + bool *left_contains_right, + bool *right_contains_left) { const CaptureList *left_captures = capture_list_pool_get( &self->capture_list_pool, left_state->capture_list_id); @@ -7894,8 +7933,8 @@ void ts_query_cursor__compare_captures(TSQueryCursor *self, { if (j < right_captures->size) { - TSQueryCapture *left = &left_captures->contents[i]; - TSQueryCapture *right = &right_captures->contents[j]; + t_query_capture *left = &left_captures->contents[i]; + t_query_capture *right = &right_captures->contents[j]; if (left->node.id == right->node.id && left->index == right->index) { @@ -7941,7 +7980,7 @@ void ts_query_cursor__compare_captures(TSQueryCursor *self, } } -static void ts_query_cursor__add_state(TSQueryCursor *self, +static void ts_query_cursor__add_state(t_query_cursor *self, const PatternEntry *pattern) { QueryStep *step = &self->query->steps.contents[pattern->step_index]; @@ -8008,7 +8047,7 @@ static void ts_query_cursor__add_state(TSQueryCursor *self, // the pool, this will steal the capture list from another existing state, and // mark that other state as 'dead'. static CaptureList *ts_query_cursor__prepare_to_capture( - TSQueryCursor *self, QueryState *state, unsigned state_index_to_preserve) + t_query_cursor *self, QueryState *state, unsigned state_index_to_preserve) { if (state->capture_list_id == NONE) { @@ -8048,8 +8087,8 @@ static CaptureList *ts_query_cursor__prepare_to_capture( state->capture_list_id); } -static void ts_query_cursor__capture(TSQueryCursor *self, QueryState *state, - QueryStep *step, TSNode node) +static void ts_query_cursor__capture(t_query_cursor *self, QueryState *state, + QueryStep *step, t_parse_node node) { if (state->dead) return; @@ -8066,7 +8105,7 @@ static void ts_query_cursor__capture(TSQueryCursor *self, QueryState *state, uint16_t capture_id = step->capture_ids[j]; if (step->capture_ids[j] == NONE) break; - array_push(capture_list, ((TSQueryCapture){node, capture_id})); + array_push(capture_list, ((t_query_capture){node, capture_id})); LOG(" capture node. type:%s, pattern:%u, capture_id:%u, " "capture_count:%u\n", ts_node_type(node), state->pattern_index, capture_id, @@ -8077,8 +8116,8 @@ static void ts_query_cursor__capture(TSQueryCursor *self, QueryState *state, // Duplicate the given state and insert the newly-created state immediately // after the given state in the `states` array. Ensures that the given state // reference is still valid, even if the states array is reallocated. -static QueryState *ts_query_cursor__copy_state(TSQueryCursor *self, - QueryState **state_ref) +static QueryState *ts_query_cursor__copy_state(t_query_cursor *self, + QueryState **state_ref) { const QueryState *state = *state_ref; uint32_t state_index = (uint32_t)(state - self->states.contents); @@ -8102,7 +8141,7 @@ static QueryState *ts_query_cursor__copy_state(TSQueryCursor *self, return &self->states.contents[state_index + 1]; } -static inline bool ts_query_cursor__should_descend(TSQueryCursor *self, +static inline bool ts_query_cursor__should_descend(t_query_cursor *self, bool node_intersects_range) { @@ -8140,7 +8179,7 @@ static inline bool ts_query_cursor__should_descend(TSQueryCursor *self, // Avoid descending into repetition nodes unless we have already // determined that this query can match rootless patterns inside // of this type of repetition node. - Subtree subtree = ts_tree_cursor_current_subtree(&self->cursor); + t_subtree subtree = ts_tree_cursor_current_subtree(&self->cursor); if (ts_subtree_is_repetition(subtree)) { bool exists; @@ -8161,7 +8200,7 @@ static inline bool ts_query_cursor__should_descend(TSQueryCursor *self, // If one or more patterns finish, return `true` and store their states in the // `finished_states` array. Multiple patterns can finish on the same node. If // there are no more matches, return `false`. -static inline bool ts_query_cursor__advance(TSQueryCursor *self, +static inline bool ts_query_cursor__advance(t_query_cursor *self, bool stop_on_definite_step) { bool did_match = false; @@ -8267,9 +8306,10 @@ static inline bool ts_query_cursor__advance(TSQueryCursor *self, else { // Get the properties of the current node. - TSNode node = ts_tree_cursor_current_node(&self->cursor); - TSNode parent_node = ts_tree_cursor_parent_node(&self->cursor); - bool parent_precedes_range = + t_parse_node node = ts_tree_cursor_current_node(&self->cursor); + t_parse_node parent_node = + ts_tree_cursor_parent_node(&self->cursor); + bool parent_precedes_range = !ts_node_is_null(parent_node) && (ts_node_end_byte(parent_node) <= self->start_byte || point_lte(ts_node_end_point(parent_node), self->start_point)); @@ -8292,14 +8332,14 @@ static inline bool ts_query_cursor__advance(TSQueryCursor *self, if (self->on_visible_node) { - TSSymbol symbol = ts_node_symbol(node); - bool is_named = ts_node_is_named(node); - bool has_later_siblings; - bool has_later_named_siblings; - bool can_have_later_siblings_with_this_field; - TSFieldId field_id = 0; - TSSymbol supertypes[8] = {0}; - unsigned supertype_count = 8; + t_symbol symbol = ts_node_symbol(node); + bool is_named = ts_node_is_named(node); + bool has_later_siblings; + bool has_later_named_siblings; + bool can_have_later_siblings_with_this_field; + t_field_id field_id = 0; + t_symbol supertypes[8] = {0}; + unsigned supertype_count = 8; ts_tree_cursor_current_status( &self->cursor, &field_id, &has_later_siblings, &has_later_named_siblings, @@ -8450,12 +8490,12 @@ static inline bool ts_query_cursor__advance(TSQueryCursor *self, if (step->negated_field_list_id) { - TSFieldId *negated_field_ids = + t_field_id *negated_field_ids = &self->query->negated_fields .contents[step->negated_field_list_id]; for (;;) { - TSFieldId negated_field_id = *negated_field_ids; + t_field_id negated_field_id = *negated_field_ids; if (negated_field_id) { negated_field_ids++; @@ -8517,7 +8557,7 @@ static inline bool ts_query_cursor__advance(TSQueryCursor *self, // capture the parent node if necessary. if (state->needs_parent) { - TSNode parent = + t_parse_node parent = ts_tree_cursor_parent_node(&self->cursor); if (ts_node_is_null(parent)) { @@ -8760,7 +8800,7 @@ static inline bool ts_query_cursor__advance(TSQueryCursor *self, } } -bool ts_query_cursor_next_match(TSQueryCursor *self, TSQueryMatch *match) +bool ts_query_cursor_next_match(t_query_cursor *self, t_query_match *match) { if (self->finished_states.size == 0) { @@ -8784,7 +8824,7 @@ bool ts_query_cursor_next_match(TSQueryCursor *self, TSQueryMatch *match) return true; } -void ts_query_cursor_remove_match(TSQueryCursor *self, uint32_t match_id) +void ts_query_cursor_remove_match(t_query_cursor *self, uint32_t match_id) { for (unsigned i = 0; i < self->finished_states.size; i++) { @@ -8813,7 +8853,7 @@ void ts_query_cursor_remove_match(TSQueryCursor *self, uint32_t match_id) } } -bool ts_query_cursor_next_capture(TSQueryCursor *self, TSQueryMatch *match, +bool ts_query_cursor_next_capture(t_query_cursor *self, t_query_match *match, uint32_t *capture_index) { // The goal here is to return captures in order, even though they may not @@ -8851,7 +8891,7 @@ bool ts_query_cursor_next_capture(TSQueryCursor *self, TSQueryMatch *match, continue; } - TSNode node = + t_parse_node node = captures->contents[state->consumed_capture_count].node; bool node_precedes_range = @@ -8934,8 +8974,8 @@ bool ts_query_cursor_next_capture(TSQueryCursor *self, TSQueryMatch *match, } } -void ts_query_cursor_set_max_start_depth(TSQueryCursor *self, - uint32_t max_start_depth) +void ts_query_cursor_set_max_start_depth(t_query_cursor *self, + uint32_t max_start_depth) { self->max_start_depth = max_start_depth; } @@ -8947,14 +8987,14 @@ typedef struct StackNode StackNode; typedef struct { StackNode *node; - Subtree subtree; + t_subtree subtree; bool is_pending; } StackLink; struct StackNode { - TSStateId state; - Length position; + t_state_id state; + t_length position; StackLink links[MAX_LINK_COUNT]; short unsigned int link_count; uint32_t ref_count; @@ -8965,10 +9005,10 @@ struct StackNode typedef struct { - StackNode *node; - SubtreeArray subtrees; - uint32_t subtree_count; - bool is_pending; + StackNode *node; + t_subtree_array subtrees; + uint32_t subtree_count; + bool is_pending; } StackIterator; typedef Array(StackNode *) StackNodeArray; @@ -8982,22 +9022,22 @@ typedef enum typedef struct { - StackNode *node; - StackSummary *summary; - unsigned node_count_at_last_error; - Subtree last_external_token; - Subtree lookahead_when_paused; - StackStatus status; + StackNode *node; + t_stack_summary *summary; + unsigned node_count_at_last_error; + t_subtree last_external_token; + t_subtree lookahead_when_paused; + StackStatus status; } StackHead; -struct Stack +struct s_stack { Array(StackHead) heads; - StackSliceArray slices; + t_stack_slice_array slices; Array(StackIterator) iterators; - StackNodeArray node_pool; - StackNode *base_node; - SubtreePool *subtree_pool; + StackNodeArray node_pool; + StackNode *base_node; + t_subtree_pool *subtree_pool; }; typedef unsigned StackAction; @@ -9020,7 +9060,7 @@ static void stack_node_retain(StackNode *self) } static void stack_node_release(StackNode *self, StackNodeArray *pool, - SubtreePool *subtree_pool) + t_subtree_pool *subtree_pool) { recur: assert(self->ref_count != 0); @@ -9062,7 +9102,7 @@ recur: /// Get the number of nodes in the subtree, for the purpose of measuring /// how much progress has been made by a given version of the stack. -static uint32_t stack__subtree_node_count(Subtree subtree) +static uint32_t stack__subtree_node_count(t_subtree subtree) { uint32_t count = ts_subtree_visible_descendant_count(subtree); if (ts_subtree_visible(subtree)) @@ -9077,8 +9117,8 @@ static uint32_t stack__subtree_node_count(Subtree subtree) return count; } -static StackNode *stack_node_new(StackNode *previous_node, Subtree subtree, - bool is_pending, TSStateId state, +static StackNode *stack_node_new(StackNode *previous_node, t_subtree subtree, + bool is_pending, t_state_id state, StackNodeArray *pool) { StackNode *node = @@ -9117,7 +9157,7 @@ static StackNode *stack_node_new(StackNode *previous_node, Subtree subtree, return node; } -static bool stack__subtree_is_equivalent(Subtree left, Subtree right) +static bool stack__subtree_is_equivalent(t_subtree left, t_subtree right) { if (left.ptr == right.ptr) return true; @@ -9140,7 +9180,7 @@ static bool stack__subtree_is_equivalent(Subtree left, Subtree right) } static void stack_node_add_link(StackNode *self, StackLink link, - SubtreePool *subtree_pool) + t_subtree_pool *subtree_pool) { if (link.node == self) return; @@ -9218,7 +9258,7 @@ static void stack_node_add_link(StackNode *self, StackLink link, } static void stack_head_delete(StackHead *self, StackNodeArray *pool, - SubtreePool *subtree_pool) + t_subtree_pool *subtree_pool) { if (self->node) { @@ -9239,9 +9279,9 @@ static void stack_head_delete(StackHead *self, StackNodeArray *pool, } } -static StackVersion ts_stack__add_version(Stack *self, - StackVersion original_version, - StackNode *node) +static t_stack_version ts_stack__add_version(t_stack *self, + t_stack_version original_version, + StackNode *node) { StackHead head = { .node = node, @@ -9256,31 +9296,32 @@ static StackVersion ts_stack__add_version(Stack *self, stack_node_retain(node); if (head.last_external_token.ptr) ts_subtree_retain(head.last_external_token); - return (StackVersion)(self->heads.size - 1); + return (t_stack_version)(self->heads.size - 1); } -static void ts_stack__add_slice(Stack *self, StackVersion original_version, - StackNode *node, SubtreeArray *subtrees) +static void ts_stack__add_slice(t_stack *self, t_stack_version original_version, + StackNode *node, t_subtree_array *subtrees) { for (uint32_t i = self->slices.size - 1; i + 1 > 0; i--) { - StackVersion version = self->slices.contents[i].version; + t_stack_version version = self->slices.contents[i].version; if (self->heads.contents[version].node == node) { - StackSlice slice = {*subtrees, version}; + t_stack_slice slice = {*subtrees, version}; array_insert(&self->slices, i + 1, slice); return; } } - StackVersion version = ts_stack__add_version(self, original_version, node); - StackSlice slice = {*subtrees, version}; + t_stack_version version = + ts_stack__add_version(self, original_version, node); + t_stack_slice slice = {*subtrees, version}; array_push(&self->slices, slice); } -static StackSliceArray stack__iter(Stack *self, StackVersion version, - StackCallback callback, void *payload, - int goal_subtree_count) +static t_stack_slice_array stack__iter(t_stack *self, t_stack_version version, + StackCallback callback, void *payload, + int goal_subtree_count) { array_clear(&self->slices); array_clear(&self->iterators); @@ -9299,7 +9340,7 @@ static StackSliceArray stack__iter(Stack *self, StackVersion version, include_subtrees = true; array_reserve(&new_iterator.subtrees, (uint32_t)ts_subtree_alloc_size(goal_subtree_count) / - sizeof(Subtree)); + sizeof(t_subtree)); } array_push(&self->iterators, new_iterator); @@ -9318,7 +9359,7 @@ static StackSliceArray stack__iter(Stack *self, StackVersion version, if (should_pop) { - SubtreeArray subtrees = iterator->subtrees; + t_subtree_array subtrees = iterator->subtrees; if (!should_stop) { ts_subtree_array_copy(subtrees, &subtrees); @@ -9391,9 +9432,9 @@ static StackSliceArray stack__iter(Stack *self, StackVersion version, return self->slices; } -Stack *ts_stack_new(SubtreePool *subtree_pool) +t_stack *ts_stack_new(t_subtree_pool *subtree_pool) { - Stack *self = calloc(1, sizeof(Stack)); + t_stack *self = calloc(1, sizeof(t_stack)); array_init(&self->heads); array_init(&self->slices); @@ -9412,7 +9453,7 @@ Stack *ts_stack_new(SubtreePool *subtree_pool) return self; } -void ts_stack_delete(Stack *self) +void ts_stack_delete(t_stack *self) { if (self->slices.contents) array_delete(&self->slices); @@ -9435,28 +9476,29 @@ void ts_stack_delete(Stack *self) free(self); } -uint32_t ts_stack_version_count(const Stack *self) +uint32_t ts_stack_version_count(const t_stack *self) { return self->heads.size; } -TSStateId ts_stack_state(const Stack *self, StackVersion version) +t_state_id ts_stack_state(const t_stack *self, t_stack_version version) { return array_get(&self->heads, version)->node->state; } -Length ts_stack_position(const Stack *self, StackVersion version) +t_length ts_stack_position(const t_stack *self, t_stack_version version) { return array_get(&self->heads, version)->node->position; } -Subtree ts_stack_last_external_token(const Stack *self, StackVersion version) +t_subtree ts_stack_last_external_token(const t_stack *self, + t_stack_version version) { return array_get(&self->heads, version)->last_external_token; } -void ts_stack_set_last_external_token(Stack *self, StackVersion version, - Subtree token) +void ts_stack_set_last_external_token(t_stack *self, t_stack_version version, + t_subtree token) { StackHead *head = array_get(&self->heads, version); if (token.ptr) @@ -9466,7 +9508,7 @@ void ts_stack_set_last_external_token(Stack *self, StackVersion version, head->last_external_token = token; } -unsigned ts_stack_error_cost(const Stack *self, StackVersion version) +unsigned ts_stack_error_cost(const t_stack *self, t_stack_version version) { StackHead *head = array_get(&self->heads, version); unsigned result = head->node->error_cost; @@ -9478,8 +9520,8 @@ unsigned ts_stack_error_cost(const Stack *self, StackVersion version) return result; } -unsigned ts_stack_node_count_since_error(const Stack *self, - StackVersion version) +unsigned ts_stack_node_count_since_error(const t_stack *self, + t_stack_version version) { StackHead *head = array_get(&self->heads, version); if (head->node->node_count < head->node_count_at_last_error) @@ -9489,8 +9531,8 @@ unsigned ts_stack_node_count_since_error(const Stack *self, return head->node->node_count - head->node_count_at_last_error; } -void ts_stack_push(Stack *self, StackVersion version, Subtree subtree, - bool pending, TSStateId state) +void ts_stack_push(t_stack *self, t_stack_version version, t_subtree subtree, + bool pending, t_state_id state) { StackHead *head = array_get(&self->heads, version); StackNode *new_node = @@ -9514,8 +9556,8 @@ static inline StackAction pop_count_callback(void *payload, } } -StackSliceArray ts_stack_pop_count(Stack *self, StackVersion version, - uint32_t count) +t_stack_slice_array ts_stack_pop_count(t_stack *self, t_stack_version version, + uint32_t count) { return stack__iter(self, version, pop_count_callback, &count, (int)count); } @@ -9541,9 +9583,9 @@ static inline StackAction pop_pending_callback(void *payload, } } -StackSliceArray ts_stack_pop_pending(Stack *self, StackVersion version) +t_stack_slice_array ts_stack_pop_pending(t_stack *self, t_stack_version version) { - StackSliceArray pop = + t_stack_slice_array pop = stack__iter(self, version, pop_pending_callback, NULL, 0); if (pop.size > 0) { @@ -9576,7 +9618,7 @@ static inline StackAction pop_error_callback(void *payload, } } -SubtreeArray ts_stack_pop_error(Stack *self, StackVersion version) +t_subtree_array ts_stack_pop_error(t_stack *self, t_stack_version version) { StackNode *node = array_get(&self->heads, version)->node; for (unsigned i = 0; i < node->link_count; i++) @@ -9584,8 +9626,8 @@ SubtreeArray ts_stack_pop_error(Stack *self, StackVersion version) if (node->links[i].subtree.ptr && ts_subtree_is_error(node->links[i].subtree)) { - bool found_error = false; - StackSliceArray pop = + bool found_error = false; + t_stack_slice_array pop = stack__iter(self, version, pop_error_callback, &found_error, 1); if (pop.size > 0) { @@ -9597,7 +9639,7 @@ SubtreeArray ts_stack_pop_error(Stack *self, StackVersion version) break; } } - return (SubtreeArray){.size = 0}; + return (t_subtree_array){.size = 0}; } static inline StackAction pop_all_callback(void *payload, @@ -9607,34 +9649,34 @@ static inline StackAction pop_all_callback(void *payload, return iterator->node->link_count == 0 ? StackActionPop : StackActionNone; } -StackSliceArray ts_stack_pop_all(Stack *self, StackVersion version) +t_stack_slice_array ts_stack_pop_all(t_stack *self, t_stack_version version) { return stack__iter(self, version, pop_all_callback, NULL, 0); } typedef struct { - StackSummary *summary; - unsigned max_depth; + t_stack_summary *summary; + unsigned max_depth; } SummarizeStackSession; static inline StackAction summarize_stack_callback( void *payload, const StackIterator *iterator) { SummarizeStackSession *session = payload; - TSStateId state = iterator->node->state; + t_state_id state = iterator->node->state; unsigned depth = iterator->subtree_count; if (depth > session->max_depth) return StackActionStop; for (unsigned i = session->summary->size - 1; i + 1 > 0; i--) { - StackSummaryEntry entry = session->summary->contents[i]; + t_stack_summary_entry entry = session->summary->contents[i]; if (entry.depth < depth) break; if (entry.depth == depth && entry.state == state) return StackActionNone; } - array_push(session->summary, ((StackSummaryEntry){ + array_push(session->summary, ((t_stack_summary_entry){ .position = iterator->node->position, .depth = depth, .state = state, @@ -9642,10 +9684,10 @@ static inline StackAction summarize_stack_callback( return StackActionNone; } -void ts_stack_record_summary(Stack *self, StackVersion version, +void ts_stack_record_summary(t_stack *self, t_stack_version version, unsigned max_depth) { - SummarizeStackSession session = {.summary = malloc(sizeof(StackSummary)), + SummarizeStackSession session = {.summary = malloc(sizeof(t_stack_summary)), .max_depth = max_depth}; array_init(session.summary); stack__iter(self, version, summarize_stack_callback, &session, -1); @@ -9658,17 +9700,18 @@ void ts_stack_record_summary(Stack *self, StackVersion version, head->summary = session.summary; } -StackSummary *ts_stack_get_summary(Stack *self, StackVersion version) +t_stack_summary *ts_stack_get_summary(t_stack *self, t_stack_version version) { return array_get(&self->heads, version)->summary; } -int ts_stack_dynamic_precedence(Stack *self, StackVersion version) +int ts_stack_dynamic_precedence(t_stack *self, t_stack_version version) { return array_get(&self->heads, version)->node->dynamic_precedence; } -bool ts_stack_has_advanced_since_error(const Stack *self, StackVersion version) +bool ts_stack_has_advanced_since_error(const t_stack *self, + t_stack_version version) { const StackHead *head = array_get(&self->heads, version); const StackNode *node = head->node; @@ -9678,7 +9721,7 @@ bool ts_stack_has_advanced_since_error(const Stack *self, StackVersion version) { if (node->link_count > 0) { - Subtree subtree = node->links[0].subtree; + t_subtree subtree = node->links[0].subtree; if (subtree.ptr) { if (ts_subtree_total_bytes(subtree) > 0) @@ -9698,14 +9741,15 @@ bool ts_stack_has_advanced_since_error(const Stack *self, StackVersion version) return false; } -void ts_stack_remove_version(Stack *self, StackVersion version) +void ts_stack_remove_version(t_stack *self, t_stack_version version) { stack_head_delete(array_get(&self->heads, version), &self->node_pool, self->subtree_pool); array_erase(&self->heads, version); } -void ts_stack_renumber_version(Stack *self, StackVersion v1, StackVersion v2) +void ts_stack_renumber_version(t_stack *self, t_stack_version v1, + t_stack_version v2) { if (v1 == v2) return; @@ -9723,14 +9767,15 @@ void ts_stack_renumber_version(Stack *self, StackVersion v1, StackVersion v2) array_erase(&self->heads, v1); } -void ts_stack_swap_versions(Stack *self, StackVersion v1, StackVersion v2) +void ts_stack_swap_versions(t_stack *self, t_stack_version v1, + t_stack_version v2) { StackHead temporary_head = self->heads.contents[v1]; self->heads.contents[v1] = self->heads.contents[v2]; self->heads.contents[v2] = temporary_head; } -StackVersion ts_stack_copy_version(Stack *self, StackVersion version) +t_stack_version ts_stack_copy_version(t_stack *self, t_stack_version version) { assert(version < self->heads.size); array_push(&self->heads, self->heads.contents[version]); @@ -9742,7 +9787,8 @@ StackVersion ts_stack_copy_version(Stack *self, StackVersion version) return self->heads.size - 1; } -bool ts_stack_merge(Stack *self, StackVersion version1, StackVersion version2) +bool ts_stack_merge(t_stack *self, t_stack_version version1, + t_stack_version version2) { if (!ts_stack_can_merge(self, version1, version2)) return false; @@ -9761,8 +9807,8 @@ bool ts_stack_merge(Stack *self, StackVersion version1, StackVersion version2) return true; } -bool ts_stack_can_merge(Stack *self, StackVersion version1, - StackVersion version2) +bool ts_stack_can_merge(t_stack *self, t_stack_version version1, + t_stack_version version2) { StackHead *head1 = &self->heads.contents[version1]; StackHead *head2 = &self->heads.contents[version2]; @@ -9775,12 +9821,12 @@ bool ts_stack_can_merge(Stack *self, StackVersion version1, head2->last_external_token); } -void ts_stack_halt(Stack *self, StackVersion version) +void ts_stack_halt(t_stack *self, t_stack_version version) { array_get(&self->heads, version)->status = StackStatusHalted; } -void ts_stack_pause(Stack *self, StackVersion version, Subtree lookahead) +void ts_stack_pause(t_stack *self, t_stack_version version, t_subtree lookahead) { StackHead *head = array_get(&self->heads, version); head->status = StackStatusPaused; @@ -9788,32 +9834,32 @@ void ts_stack_pause(Stack *self, StackVersion version, Subtree lookahead) head->node_count_at_last_error = head->node->node_count; } -bool ts_stack_is_active(const Stack *self, StackVersion version) +bool ts_stack_is_active(const t_stack *self, t_stack_version version) { return array_get(&self->heads, version)->status == StackStatusActive; } -bool ts_stack_is_halted(const Stack *self, StackVersion version) +bool ts_stack_is_halted(const t_stack *self, t_stack_version version) { return array_get(&self->heads, version)->status == StackStatusHalted; } -bool ts_stack_is_paused(const Stack *self, StackVersion version) +bool ts_stack_is_paused(const t_stack *self, t_stack_version version) { return array_get(&self->heads, version)->status == StackStatusPaused; } -Subtree ts_stack_resume(Stack *self, StackVersion version) +t_subtree ts_stack_resume(t_stack *self, t_stack_version version) { StackHead *head = array_get(&self->heads, version); assert(head->status == StackStatusPaused); - Subtree result = head->lookahead_when_paused; + t_subtree result = head->lookahead_when_paused; head->status = StackStatusActive; head->lookahead_when_paused = NULL_SUBTREE; return result; } -void ts_stack_clear(Stack *self) +void ts_stack_clear(t_stack *self) { stack_node_retain(self->base_node); for (uint32_t i = 0; i < self->heads.size; i++) @@ -9830,19 +9876,20 @@ void ts_stack_clear(Stack *self) })); } -bool ts_stack_print_dot_graph(Stack *self, const TSLanguage *language, void *f) +bool ts_stack_print_dot_graph(t_stack *self, const t_language *language, + void *f) { (void)(self); (void)(language); (void)(f); - return (false); + return (false); } typedef struct { - Length start; - Length old_end; - Length new_end; + t_length start; + t_length old_end; + t_length new_end; } Edit; // ExternalScannerState @@ -9901,17 +9948,17 @@ bool ts_external_scanner_state_eq(const ExternalScannerState *self, memcmp(ts_external_scanner_state_data(self), buffer, length) == 0; } -// SubtreeArray +// t_subtree_array -void ts_subtree_array_copy(SubtreeArray self, SubtreeArray *dest) +void ts_subtree_array_copy(t_subtree_array self, t_subtree_array *dest) { dest->size = self.size; dest->capacity = self.capacity; dest->contents = self.contents; if (self.capacity > 0) { - dest->contents = calloc(self.capacity, sizeof(Subtree)); - memcpy(dest->contents, self.contents, self.size * sizeof(Subtree)); + dest->contents = calloc(self.capacity, sizeof(t_subtree)); + memcpy(dest->contents, self.contents, self.size * sizeof(t_subtree)); for (uint32_t i = 0; i < self.size; i++) { ts_subtree_retain(dest->contents[i]); @@ -9919,7 +9966,7 @@ void ts_subtree_array_copy(SubtreeArray self, SubtreeArray *dest) } } -void ts_subtree_array_clear(SubtreePool *pool, SubtreeArray *self) +void ts_subtree_array_clear(t_subtree_pool *pool, t_subtree_array *self) { for (uint32_t i = 0; i < self->size; i++) { @@ -9928,19 +9975,19 @@ void ts_subtree_array_clear(SubtreePool *pool, SubtreeArray *self) array_clear(self); } -void ts_subtree_array_delete(SubtreePool *pool, SubtreeArray *self) +void ts_subtree_array_delete(t_subtree_pool *pool, t_subtree_array *self) { ts_subtree_array_clear(pool, self); array_delete(self); } -void ts_subtree_array_remove_trailing_extras(SubtreeArray *self, - SubtreeArray *destination) +void ts_subtree_array_remove_trailing_extras(t_subtree_array *self, + t_subtree_array *destination) { array_clear(destination); while (self->size > 0) { - Subtree last = self->contents[self->size - 1]; + t_subtree last = self->contents[self->size - 1]; if (ts_subtree_extra(last)) { self->size--; @@ -9954,27 +10001,27 @@ void ts_subtree_array_remove_trailing_extras(SubtreeArray *self, ts_subtree_array_reverse(destination); } -void ts_subtree_array_reverse(SubtreeArray *self) +void ts_subtree_array_reverse(t_subtree_array *self) { for (uint32_t i = 0, limit = self->size / 2; i < limit; i++) { - size_t reverse_index = self->size - 1 - i; - Subtree swap = self->contents[i]; + size_t reverse_index = self->size - 1 - i; + t_subtree swap = self->contents[i]; self->contents[i] = self->contents[reverse_index]; self->contents[reverse_index] = swap; } } -// SubtreePool +// t_subtree_pool -SubtreePool ts_subtree_pool_new(uint32_t capacity) +t_subtree_pool ts_subtree_pool_new(uint32_t capacity) { - SubtreePool self = {array_new(), array_new()}; + t_subtree_pool self = {array_new(), array_new()}; array_reserve(&self.free_trees, capacity); return self; } -void ts_subtree_pool_delete(SubtreePool *self) +void ts_subtree_pool_delete(t_subtree_pool *self) { if (self->free_trees.contents) { @@ -9988,7 +10035,7 @@ void ts_subtree_pool_delete(SubtreePool *self) array_delete(&self->tree_stack); } -static SubtreeHeapData *ts_subtree_pool_allocate(SubtreePool *self) +static t_subtree_heap_data *ts_subtree_pool_allocate(t_subtree_pool *self) { if (self->free_trees.size > 0) { @@ -9996,16 +10043,17 @@ static SubtreeHeapData *ts_subtree_pool_allocate(SubtreePool *self) } else { - return malloc(sizeof(SubtreeHeapData)); + return malloc(sizeof(t_subtree_heap_data)); } } -static void ts_subtree_pool_free(SubtreePool *self, SubtreeHeapData *tree) +static void ts_subtree_pool_free(t_subtree_pool *self, + t_subtree_heap_data *tree) { if (self->free_trees.capacity > 0 && self->free_trees.size + 1 <= TS_MAX_TREE_POOL_SIZE) { - array_push(&self->free_trees, (MutableSubtree){.ptr = tree}); + array_push(&self->free_trees, (t_mutable_subtree){.ptr = tree}); } else { @@ -10013,9 +10061,9 @@ static void ts_subtree_pool_free(SubtreePool *self, SubtreeHeapData *tree) } } -// Subtree +// t_subtree -static inline bool ts_subtree_can_inline(Length padding, Length size, +static inline bool ts_subtree_can_inline(t_length padding, t_length size, uint32_t lookahead_bytes) { return padding.bytes < TS_MAX_INLINE_TREE_LENGTH && @@ -10026,21 +10074,21 @@ static inline bool ts_subtree_can_inline(Length padding, Length size, lookahead_bytes < 16; } -Subtree ts_subtree_new_leaf(SubtreePool *pool, TSSymbol symbol, Length padding, - Length size, uint32_t lookahead_bytes, - TSStateId parse_state, bool has_external_tokens, - bool depends_on_column, bool is_keyword, - const TSLanguage *language) +t_subtree ts_subtree_new_leaf(t_subtree_pool *pool, t_symbol symbol, + t_length padding, t_length size, + uint32_t lookahead_bytes, t_state_id parse_state, + bool has_external_tokens, bool depends_on_column, + bool is_keyword, const t_language *language) { - TSSymbolMetadata metadata = ts_language_symbol_metadata(language, symbol); - bool extra = symbol == ts_builtin_sym_end; + t_symbol_metadata metadata = ts_language_symbol_metadata(language, symbol); + bool extra = symbol == ts_builtin_sym_end; bool is_inline = (symbol <= UINT8_MAX && !has_external_tokens && ts_subtree_can_inline(padding, size, lookahead_bytes)); if (is_inline) { - return (Subtree){{ + return (t_subtree){{ .parse_state = parse_state, .symbol = symbol, .padding_bytes = padding.bytes, @@ -10059,8 +10107,8 @@ Subtree ts_subtree_new_leaf(SubtreePool *pool, TSSymbol symbol, Length padding, } else { - SubtreeHeapData *data = ts_subtree_pool_allocate(pool); - *data = (SubtreeHeapData){ + t_subtree_heap_data *data = ts_subtree_pool_allocate(pool); + *data = (t_subtree_heap_data){ .ref_count = 1, .padding = padding, .size = size, @@ -10081,14 +10129,14 @@ Subtree ts_subtree_new_leaf(SubtreePool *pool, TSSymbol symbol, Length padding, .is_missing = false, .is_keyword = is_keyword, {{.first_leaf = {.symbol = 0, .parse_state = 0}}}}; - return (Subtree){.ptr = data}; + return (t_subtree){.ptr = data}; } } -void ts_subtree_set_symbol(MutableSubtree *self, TSSymbol symbol, - const TSLanguage *language) +void ts_subtree_set_symbol(t_mutable_subtree *self, t_symbol symbol, + const t_language *language) { - TSSymbolMetadata metadata = ts_language_symbol_metadata(language, symbol); + t_symbol_metadata metadata = ts_language_symbol_metadata(language, symbol); if (self->data.is_inline) { assert(symbol < UINT8_MAX); @@ -10104,15 +10152,15 @@ void ts_subtree_set_symbol(MutableSubtree *self, TSSymbol symbol, } } -Subtree ts_subtree_new_error(SubtreePool *pool, int32_t lookahead_char, - Length padding, Length size, - uint32_t bytes_scanned, TSStateId parse_state, - const TSLanguage *language) +t_subtree ts_subtree_new_error(t_subtree_pool *pool, int32_t lookahead_char, + t_length padding, t_length size, + uint32_t bytes_scanned, t_state_id parse_state, + const t_language *language) { - Subtree result = ts_subtree_new_leaf(pool, ts_builtin_sym_error, padding, - size, bytes_scanned, parse_state, - false, false, false, language); - SubtreeHeapData *data = (SubtreeHeapData *)result.ptr; + t_subtree result = ts_subtree_new_leaf(pool, ts_builtin_sym_error, padding, + size, bytes_scanned, parse_state, + false, false, false, language); + t_subtree_heap_data *data = (t_subtree_heap_data *)result.ptr; data->fragile_left = true; data->fragile_right = true; data->lookahead_char = lookahead_char; @@ -10120,14 +10168,14 @@ Subtree ts_subtree_new_error(SubtreePool *pool, int32_t lookahead_char, } // Clone a subtree. -MutableSubtree ts_subtree_clone(Subtree self) +t_mutable_subtree ts_subtree_clone(t_subtree self) { - size_t alloc_size = ts_subtree_alloc_size(self.ptr->child_count); - Subtree *new_children = malloc(alloc_size); - Subtree *old_children = ts_subtree_children(self); + size_t alloc_size = ts_subtree_alloc_size(self.ptr->child_count); + t_subtree *new_children = malloc(alloc_size); + t_subtree *old_children = ts_subtree_children(self); memcpy(new_children, old_children, alloc_size); - SubtreeHeapData *result = - (SubtreeHeapData *)&new_children[self.ptr->child_count]; + t_subtree_heap_data *result = + (t_subtree_heap_data *)&new_children[self.ptr->child_count]; if (self.ptr->child_count > 0) { for (uint32_t i = 0; i < self.ptr->child_count; i++) @@ -10141,7 +10189,7 @@ MutableSubtree ts_subtree_clone(Subtree self) ts_external_scanner_state_copy(&self.ptr->external_scanner_state); } result->ref_count = 1; - return (MutableSubtree){.ptr = result}; + return (t_mutable_subtree){.ptr = result}; } // Get mutable version of a subtree. @@ -10149,37 +10197,37 @@ MutableSubtree ts_subtree_clone(Subtree self) // This takes ownership of the subtree. If the subtree has only one owner, // this will directly convert it into a mutable version. Otherwise, it will // perform a copy. -MutableSubtree ts_subtree_make_mut(SubtreePool *pool, Subtree self) +t_mutable_subtree ts_subtree_make_mut(t_subtree_pool *pool, t_subtree self) { if (self.data.is_inline) - return (MutableSubtree){self.data}; + return (t_mutable_subtree){self.data}; if (self.ptr->ref_count == 1) return ts_subtree_to_mut_unsafe(self); - MutableSubtree result = ts_subtree_clone(self); + t_mutable_subtree result = ts_subtree_clone(self); ts_subtree_release(pool, self); return result; } -static void ts_subtree__compress(MutableSubtree self, unsigned count, - const TSLanguage *language, - MutableSubtreeArray *stack) +static void ts_subtree__compress(t_mutable_subtree self, unsigned count, + const t_language *language, + t_mutable_subtree_array *stack) { unsigned initial_stack_size = stack->size; - MutableSubtree tree = self; - TSSymbol symbol = tree.ptr->symbol; + t_mutable_subtree tree = self; + t_symbol symbol = tree.ptr->symbol; for (unsigned i = 0; i < count; i++) { if (tree.ptr->ref_count > 1 || tree.ptr->child_count < 2) break; - MutableSubtree child = + t_mutable_subtree child = ts_subtree_to_mut_unsafe(ts_subtree_children(tree)[0]); if (child.data.is_inline || child.ptr->child_count < 2 || child.ptr->ref_count > 1 || child.ptr->symbol != symbol) break; - MutableSubtree grandchild = + t_mutable_subtree grandchild = ts_subtree_to_mut_unsafe(ts_subtree_children(child)[0]); if (grandchild.data.is_inline || grandchild.ptr->child_count < 2 || grandchild.ptr->ref_count > 1 || grandchild.ptr->symbol != symbol) @@ -10197,9 +10245,9 @@ static void ts_subtree__compress(MutableSubtree self, unsigned count, while (stack->size > initial_stack_size) { tree = array_pop(stack); - MutableSubtree child = + t_mutable_subtree child = ts_subtree_to_mut_unsafe(ts_subtree_children(tree)[0]); - MutableSubtree grandchild = ts_subtree_to_mut_unsafe( + t_mutable_subtree grandchild = ts_subtree_to_mut_unsafe( ts_subtree_children(child)[child.ptr->child_count - 1]); ts_subtree_summarize_children(grandchild, language); ts_subtree_summarize_children(child, language); @@ -10207,8 +10255,8 @@ static void ts_subtree__compress(MutableSubtree self, unsigned count, } } -void ts_subtree_balance(Subtree self, SubtreePool *pool, - const TSLanguage *language) +void ts_subtree_balance(t_subtree self, t_subtree_pool *pool, + const t_language *language) { array_clear(&pool->tree_stack); @@ -10219,12 +10267,12 @@ void ts_subtree_balance(Subtree self, SubtreePool *pool, while (pool->tree_stack.size > 0) { - MutableSubtree tree = array_pop(&pool->tree_stack); + t_mutable_subtree tree = array_pop(&pool->tree_stack); if (tree.ptr->repeat_depth > 0) { - Subtree child1 = ts_subtree_children(tree)[0]; - Subtree child2 = + t_subtree child1 = ts_subtree_children(tree)[0]; + t_subtree child2 = ts_subtree_children(tree)[tree.ptr->child_count - 1]; long repeat_delta = (long)ts_subtree_repeat_depth(child1) - (long)ts_subtree_repeat_depth(child2); @@ -10241,7 +10289,7 @@ void ts_subtree_balance(Subtree self, SubtreePool *pool, for (uint32_t i = 0; i < tree.ptr->child_count; i++) { - Subtree child = ts_subtree_children(tree)[i]; + t_subtree child = ts_subtree_children(tree)[i]; if (ts_subtree_child_count(child) > 0 && child.ptr->ref_count == 1) { array_push(&pool->tree_stack, ts_subtree_to_mut_unsafe(child)); @@ -10251,8 +10299,8 @@ void ts_subtree_balance(Subtree self, SubtreePool *pool, } // Assign all of the node's properties that depend on its children. -void ts_subtree_summarize_children(MutableSubtree self, - const TSLanguage *language) +void ts_subtree_summarize_children(t_mutable_subtree self, + const t_language *language) { assert(!self.data.is_inline); @@ -10267,14 +10315,14 @@ void ts_subtree_summarize_children(MutableSubtree self, self.ptr->dynamic_precedence = 0; uint32_t structural_index = 0; - const TSSymbol *alias_sequence = + const t_symbol *alias_sequence = ts_language_alias_sequence(language, self.ptr->production_id); uint32_t lookahead_end_byte = 0; - const Subtree *children = ts_subtree_children(self); + const t_subtree *children = ts_subtree_children(self); for (uint32_t i = 0; i < self.ptr->child_count; i++) { - Subtree child = children[i]; + t_subtree child = children[i]; if (self.ptr->size.extent.row == 0 && ts_subtree_depends_on_column(child)) @@ -10386,8 +10434,8 @@ void ts_subtree_summarize_children(MutableSubtree self, if (self.ptr->child_count > 0) { - Subtree first_child = children[0]; - Subtree last_child = children[self.ptr->child_count - 1]; + t_subtree first_child = children[0]; + t_subtree last_child = children[self.ptr->child_count - 1]; self.ptr->first_leaf.symbol = ts_subtree_leaf_symbol(first_child); self.ptr->first_leaf.parse_state = @@ -10420,25 +10468,27 @@ void ts_subtree_summarize_children(MutableSubtree self, // Create a new parent node with the given children. // // This takes ownership of the children array. -MutableSubtree ts_subtree_new_node(TSSymbol symbol, SubtreeArray *children, - unsigned production_id, - const TSLanguage *language) +t_mutable_subtree ts_subtree_new_node(t_symbol symbol, + t_subtree_array *children, + unsigned production_id, + const t_language *language) { - TSSymbolMetadata metadata = ts_language_symbol_metadata(language, symbol); - bool fragile = + t_symbol_metadata metadata = ts_language_symbol_metadata(language, symbol); + bool fragile = symbol == ts_builtin_sym_error || symbol == ts_builtin_sym_error_repeat; // Allocate the node's data at the end of the array of children. size_t new_byte_size = ts_subtree_alloc_size(children->size); - if (children->capacity * sizeof(Subtree) < new_byte_size) + if (children->capacity * sizeof(t_subtree) < new_byte_size) { children->contents = realloc(children->contents, new_byte_size); - children->capacity = (uint32_t)(new_byte_size / sizeof(Subtree)); + children->capacity = (uint32_t)(new_byte_size / sizeof(t_subtree)); } - SubtreeHeapData *data = - (SubtreeHeapData *)&children->contents[children->size]; + t_subtree_heap_data *data = + (t_subtree_heap_data *)&children->contents[children->size]; - *data = (SubtreeHeapData){.ref_count = 1, + *data = + (t_subtree_heap_data){.ref_count = 1, .symbol = symbol, .child_count = children->size, .visible = metadata.visible, @@ -10453,7 +10503,7 @@ MutableSubtree ts_subtree_new_node(TSSymbol symbol, SubtreeArray *children, .production_id = production_id, .first_leaf = {.symbol = 0, .parse_state = 0}, }}}; - MutableSubtree result = {.ptr = data}; + t_mutable_subtree result = {.ptr = data}; ts_subtree_summarize_children(result, language); return result; } @@ -10462,10 +10512,10 @@ MutableSubtree ts_subtree_new_node(TSSymbol symbol, SubtreeArray *children, // // This node is treated as 'extra'. Its children are prevented from having // having any effect on the parse state. -Subtree ts_subtree_new_error_node(SubtreeArray *children, bool extra, - const TSLanguage *language) +t_subtree ts_subtree_new_error_node(t_subtree_array *children, bool extra, + const t_language *language) { - MutableSubtree result = + t_mutable_subtree result = ts_subtree_new_node(ts_builtin_sym_error, children, 0, language); result.ptr->extra = extra; return ts_subtree_from_mut(result); @@ -10475,11 +10525,12 @@ Subtree ts_subtree_new_error_node(SubtreeArray *children, bool extra, // // This node is treated as 'extra'. Its children are prevented from having // having any effect on the parse state. -Subtree ts_subtree_new_missing_leaf(SubtreePool *pool, TSSymbol symbol, - Length padding, uint32_t lookahead_bytes, - const TSLanguage *language) +t_subtree ts_subtree_new_missing_leaf(t_subtree_pool *pool, t_symbol symbol, + t_length padding, + uint32_t lookahead_bytes, + const t_language *language) { - Subtree result = + t_subtree result = ts_subtree_new_leaf(pool, symbol, padding, length_zero(), lookahead_bytes, 0, false, false, false, language); if (result.data.is_inline) @@ -10488,12 +10539,12 @@ Subtree ts_subtree_new_missing_leaf(SubtreePool *pool, TSSymbol symbol, } else { - ((SubtreeHeapData *)result.ptr)->is_missing = true; + ((t_subtree_heap_data *)result.ptr)->is_missing = true; } return result; } -void ts_subtree_retain(Subtree self) +void ts_subtree_retain(t_subtree self) { if (self.data.is_inline) return; @@ -10502,7 +10553,7 @@ void ts_subtree_retain(Subtree self) assert(self.ptr->ref_count != 0); } -void ts_subtree_release(SubtreePool *pool, Subtree self) +void ts_subtree_release(t_subtree_pool *pool, t_subtree self) { if (self.data.is_inline) return; @@ -10516,13 +10567,13 @@ void ts_subtree_release(SubtreePool *pool, Subtree self) while (pool->tree_stack.size > 0) { - MutableSubtree tree = array_pop(&pool->tree_stack); + t_mutable_subtree tree = array_pop(&pool->tree_stack); if (tree.ptr->child_count > 0) { - Subtree *children = ts_subtree_children(tree); + t_subtree *children = ts_subtree_children(tree); for (uint32_t i = 0; i < tree.ptr->child_count; i++) { - Subtree child = children[i]; + t_subtree child = children[i]; if (child.data.is_inline) continue; assert(child.ptr->ref_count > 0); @@ -10546,7 +10597,7 @@ void ts_subtree_release(SubtreePool *pool, Subtree self) } } -int ts_subtree_compare(Subtree left, Subtree right, SubtreePool *pool) +int ts_subtree_compare(t_subtree left, t_subtree right, t_subtree_pool *pool) { array_push(&pool->tree_stack, ts_subtree_to_mut_unsafe(left)); array_push(&pool->tree_stack, ts_subtree_to_mut_unsafe(right)); @@ -10573,8 +10624,8 @@ int ts_subtree_compare(Subtree left, Subtree right, SubtreePool *pool) for (uint32_t i = ts_subtree_child_count(left); i > 0; i--) { - Subtree left_child = ts_subtree_children(left)[i - 1]; - Subtree right_child = ts_subtree_children(right)[i - 1]; + t_subtree left_child = ts_subtree_children(left)[i - 1]; + t_subtree right_child = ts_subtree_children(right)[i - 1]; array_push(&pool->tree_stack, ts_subtree_to_mut_unsafe(left_child)); array_push(&pool->tree_stack, ts_subtree_to_mut_unsafe(right_child)); @@ -10584,7 +10635,7 @@ int ts_subtree_compare(Subtree left, Subtree right, SubtreePool *pool) return 0; } -static inline void ts_subtree_set_has_changes(MutableSubtree *self) +static inline void ts_subtree_set_has_changes(t_mutable_subtree *self) { if (self->data.is_inline) { @@ -10596,13 +10647,13 @@ static inline void ts_subtree_set_has_changes(MutableSubtree *self) } } -Subtree ts_subtree_edit(Subtree self, const TSInputEdit *input_edit, - SubtreePool *pool) +t_subtree ts_subtree_edit(t_subtree self, const t_input_edit *input_edit, + t_subtree_pool *pool) { typedef struct { - Subtree *tree; - Edit edit; + t_subtree *tree; + Edit edit; } EditEntry; Array(EditEntry) stack = array_new(); @@ -10629,9 +10680,9 @@ Subtree ts_subtree_edit(Subtree self, const TSInputEdit *input_edit, bool is_pure_insertion = edit.old_end.bytes == edit.start.bytes; bool invalidate_first_row = ts_subtree_depends_on_column(*entry.tree); - Length size = ts_subtree_size(*entry.tree); - Length padding = ts_subtree_padding(*entry.tree); - Length total_size = length_add(padding, size); + t_length size = ts_subtree_size(*entry.tree); + t_length padding = ts_subtree_padding(*entry.tree); + t_length total_size = length_add(padding, size); uint32_t lookahead_bytes = ts_subtree_lookahead_bytes(*entry.tree); uint32_t end_byte = total_size.bytes + lookahead_bytes; if (edit.start.bytes > end_byte || @@ -10673,7 +10724,7 @@ Subtree ts_subtree_edit(Subtree self, const TSInputEdit *input_edit, length_saturating_sub(total_size, edit.old_end)); } - MutableSubtree result = ts_subtree_make_mut(pool, *entry.tree); + t_mutable_subtree result = ts_subtree_make_mut(pool, *entry.tree); if (result.data.is_inline) { @@ -10686,7 +10737,7 @@ Subtree ts_subtree_edit(Subtree self, const TSInputEdit *input_edit, } else { - SubtreeHeapData *data = ts_subtree_pool_allocate(pool); + t_subtree_heap_data *data = ts_subtree_pool_allocate(pool); data->ref_count = 1; data->padding = padding; data->size = size; @@ -10717,12 +10768,12 @@ Subtree ts_subtree_edit(Subtree self, const TSInputEdit *input_edit, ts_subtree_set_has_changes(&result); *entry.tree = ts_subtree_from_mut(result); - Length child_left, child_right = length_zero(); + t_length child_left, child_right = length_zero(); for (uint32_t i = 0, n = ts_subtree_child_count(*entry.tree); i < n; i++) { - Subtree *child = &ts_subtree_children(*entry.tree)[i]; - Length child_size = ts_subtree_total_size(*child); + t_subtree *child = &ts_subtree_children(*entry.tree)[i]; + t_length child_size = ts_subtree_total_size(*child); child_left = child_right; child_right = length_add(child_left, child_size); @@ -10780,7 +10831,7 @@ Subtree ts_subtree_edit(Subtree self, const TSInputEdit *input_edit, return self; } -Subtree ts_subtree_last_external_token(Subtree tree) +t_subtree ts_subtree_last_external_token(t_subtree tree) { if (!ts_subtree_has_external_tokens(tree)) return NULL_SUBTREE; @@ -10788,7 +10839,7 @@ Subtree ts_subtree_last_external_token(Subtree tree) { for (uint32_t i = tree.ptr->child_count - 1; i + 1 > 0; i--) { - Subtree child = ts_subtree_children(tree)[i]; + t_subtree child = ts_subtree_children(tree)[i]; if (ts_subtree_has_external_tokens(child)) { tree = child; @@ -10802,23 +10853,23 @@ Subtree ts_subtree_last_external_token(Subtree tree) static const char *const ROOT_FIELD = "__ROOT__"; static size_t ts_subtree__write_to_string( - Subtree self, char *string, size_t limit, const TSLanguage *language, - bool include_all, TSSymbol alias_symbol, bool alias_is_named, + t_subtree self, char *string, size_t limit, const t_language *language, + bool include_all, t_symbol alias_symbol, bool alias_is_named, const char *field_name) { - (void)(self); - (void)(string); - (void)(limit); - (void)(language); - (void)(include_all); - (void)(alias_symbol); - (void)(alias_is_named); - (void)(field_name); - return (0); + (void)(self); + (void)(string); + (void)(limit); + (void)(language); + (void)(include_all); + (void)(alias_symbol); + (void)(alias_is_named); + (void)(field_name); + return (0); } -char *ts_subtree_string(Subtree self, TSSymbol alias_symbol, - bool alias_is_named, const TSLanguage *language, +char *ts_subtree_string(t_subtree self, t_symbol alias_symbol, + bool alias_is_named, const t_language *language, bool include_all) { char scratch_string[1]; @@ -10832,9 +10883,9 @@ char *ts_subtree_string(Subtree self, TSSymbol alias_symbol, return result; } -void ts_subtree__print_dot_graph(const Subtree *self, uint32_t start_offset, - const TSLanguage *language, - TSSymbol alias_symbol, void *f) +void ts_subtree__print_dot_graph(const t_subtree *self, uint32_t start_offset, + const t_language *language, + t_symbol alias_symbol, void *f) { (void)(self); (void)(start_offset); @@ -10843,7 +10894,7 @@ void ts_subtree__print_dot_graph(const Subtree *self, uint32_t start_offset, (void)(f); } -bool ts_subtree_external_scanner_state_eq(Subtree self, Subtree other) +bool ts_subtree_external_scanner_state_eq(t_subtree self, t_subtree other) { const ExternalScannerState *state_self = ts_subtree_external_scanner_state(self); @@ -10854,33 +10905,34 @@ bool ts_subtree_external_scanner_state_eq(Subtree self, Subtree other) state_other->length); } -TSTree *ts_tree_new(Subtree root, const TSLanguage *language, - const TSRange *included_ranges, - unsigned included_range_count) +t_first_tree *ts_tree_new(t_subtree root, const t_language *language, + const t_parse_range *included_ranges, + unsigned included_range_count) { - TSTree *result = malloc(sizeof(TSTree)); + t_first_tree *result = malloc(sizeof(t_first_tree)); result->root = root; result->language = ts_language_copy(language); - result->included_ranges = calloc(included_range_count, sizeof(TSRange)); + result->included_ranges = + calloc(included_range_count, sizeof(t_parse_range)); memcpy(result->included_ranges, included_ranges, - included_range_count * sizeof(TSRange)); + included_range_count * sizeof(t_parse_range)); result->included_range_count = included_range_count; return result; } -TSTree *ts_tree_copy(const TSTree *self) +t_first_tree *ts_tree_copy(const t_first_tree *self) { ts_subtree_retain(self->root); return ts_tree_new(self->root, self->language, self->included_ranges, self->included_range_count); } -void ts_tree_delete(TSTree *self) +void ts_tree_delete(t_first_tree *self) { if (!self) return; - SubtreePool pool = ts_subtree_pool_new(0); + t_subtree_pool pool = ts_subtree_pool_new(0); ts_subtree_release(&pool, self->root); ts_subtree_pool_delete(&pool); ts_language_delete(self->language); @@ -10888,29 +10940,30 @@ void ts_tree_delete(TSTree *self) free(self); } -TSNode ts_tree_root_node(const TSTree *self) +t_parse_node ts_tree_root_node(const t_first_tree *self) { return ts_node_new(self, &self->root, ts_subtree_padding(self->root), 0); } -TSNode ts_tree_root_node_with_offset(const TSTree *self, uint32_t offset_bytes, - TSPoint offset_extent) +t_parse_node ts_tree_root_node_with_offset(const t_first_tree *self, + uint32_t offset_bytes, + t_point offset_extent) { - Length offset = {offset_bytes, offset_extent}; + t_length offset = {offset_bytes, offset_extent}; return ts_node_new(self, &self->root, length_add(offset, ts_subtree_padding(self->root)), 0); } -const TSLanguage *ts_tree_language(const TSTree *self) +const t_language *ts_tree_language(const t_first_tree *self) { return self->language; } -void ts_tree_edit(TSTree *self, const TSInputEdit *edit) +void ts_tree_edit(t_first_tree *self, const t_input_edit *edit) { for (unsigned i = 0; i < self->included_range_count; i++) { - TSRange *range = &self->included_ranges[i]; + t_parse_range *range = &self->included_ranges[i]; if (range->end_byte >= edit->old_end_byte) { if (range->end_byte != UINT32_MAX) @@ -10952,35 +11005,38 @@ void ts_tree_edit(TSTree *self, const TSInputEdit *edit) } } - SubtreePool pool = ts_subtree_pool_new(0); + t_subtree_pool pool = ts_subtree_pool_new(0); self->root = ts_subtree_edit(self->root, edit, &pool); ts_subtree_pool_delete(&pool); } -TSRange *ts_tree_included_ranges(const TSTree *self, uint32_t *length) +t_parse_range *ts_tree_included_ranges(const t_first_tree *self, + uint32_t *length) { *length = self->included_range_count; - TSRange *ranges = calloc(self->included_range_count, sizeof(TSRange)); + t_parse_range *ranges = + calloc(self->included_range_count, sizeof(t_parse_range)); memcpy(ranges, self->included_ranges, - self->included_range_count * sizeof(TSRange)); + self->included_range_count * sizeof(t_parse_range)); return ranges; } -TSRange *ts_tree_get_changed_ranges(const TSTree *old_tree, - const TSTree *new_tree, uint32_t *length) +t_parse_range *ts_tree_get_changed_ranges(const t_first_tree *old_tree, + const t_first_tree *new_tree, + uint32_t *length) { - TreeCursor cursor1 = {NULL, array_new(), 0}; - TreeCursor cursor2 = {NULL, array_new(), 0}; + t_tree_cursor cursor1 = {NULL, array_new(), 0}; + t_tree_cursor cursor2 = {NULL, array_new(), 0}; ts_tree_cursor_init(&cursor1, ts_tree_root_node(old_tree)); ts_tree_cursor_init(&cursor2, ts_tree_root_node(new_tree)); - TSRangeArray included_range_differences = array_new(); + t_range_array included_range_differences = array_new(); ts_range_array_get_changed_ranges( old_tree->included_ranges, old_tree->included_range_count, new_tree->included_ranges, new_tree->included_range_count, &included_range_differences); - TSRange *result; + t_parse_range *result; *length = ts_subtree_get_changed_ranges( &old_tree->root, &new_tree->root, &cursor1, &cursor2, old_tree->language, &included_range_differences, &result); @@ -11006,7 +11062,7 @@ int _ts_dup(HANDLE handle) return _open_osfhandle((intptr_t)dup_handle, 0); } -void ts_tree_print_dot_graph(const TSTree *self, int fd) +void ts_tree_print_dot_graph(const t_first_tree *self, int fd) { FILE *file = _fdopen(_ts_dup((HANDLE)_get_osfhandle(fd)), "a"); ts_subtree_print_dot_graph(self->root, self->language, file); @@ -11022,7 +11078,7 @@ int _ts_dup(int file_descriptor) return dup(file_descriptor); } -void ts_tree_print_dot_graph(const TSTree *self, int file_descriptor) +void ts_tree_print_dot_graph(const t_first_tree *self, int file_descriptor) { (void)(self); (void)(file_descriptor); @@ -11032,28 +11088,28 @@ void ts_tree_print_dot_graph(const TSTree *self, int file_descriptor) typedef struct { - Subtree parent; - const TSTree *tree; - Length position; - uint32_t child_index; - uint32_t structural_child_index; - uint32_t descendant_index; - const TSSymbol *alias_sequence; + t_subtree parent; + const t_first_tree *tree; + t_length position; + uint32_t child_index; + uint32_t structural_child_index; + uint32_t descendant_index; + const t_symbol *alias_sequence; } CursorChildIterator; // CursorChildIterator -static inline bool ts_tree_cursor_is_entry_visible(const TreeCursor *self, - uint32_t index) +static inline bool ts_tree_cursor_is_entry_visible(const t_tree_cursor *self, + uint32_t index) { - TreeCursorEntry *entry = &self->stack.contents[index]; + t_tree_cursor_entry *entry = &self->stack.contents[index]; if (index == 0 || ts_subtree_visible(*entry->subtree)) { return true; } else if (!ts_subtree_extra(*entry->subtree)) { - TreeCursorEntry *parent_entry = &self->stack.contents[index - 1]; + t_tree_cursor_entry *parent_entry = &self->stack.contents[index - 1]; return ts_language_alias_at(self->tree->language, parent_entry->subtree->ptr->production_id, entry->structural_child_index); @@ -11065,15 +11121,15 @@ static inline bool ts_tree_cursor_is_entry_visible(const TreeCursor *self, } static inline CursorChildIterator ts_tree_cursor_iterate_children( - const TreeCursor *self) + const t_tree_cursor *self) { - TreeCursorEntry *last_entry = array_back(&self->stack); + t_tree_cursor_entry *last_entry = array_back(&self->stack); if (ts_subtree_child_count(*last_entry->subtree) == 0) { return (CursorChildIterator){ NULL_SUBTREE, self->tree, length_zero(), 0, 0, 0, NULL}; } - const TSSymbol *alias_sequence = ts_language_alias_sequence( + const t_symbol *alias_sequence = ts_language_alias_sequence( self->tree->language, last_entry->subtree->ptr->production_id); uint32_t descendant_index = last_entry->descendant_index; @@ -11093,15 +11149,14 @@ static inline CursorChildIterator ts_tree_cursor_iterate_children( }; } -static inline bool ts_tree_cursor_child_iterator_next(CursorChildIterator *self, - TreeCursorEntry *result, - bool *visible) +static inline bool ts_tree_cursor_child_iterator_next( + CursorChildIterator *self, t_tree_cursor_entry *result, bool *visible) { if (!self->parent.ptr || self->child_index == self->parent.ptr->child_count) return false; - const Subtree *child = + const t_subtree *child = &ts_subtree_children(self->parent)[self->child_index]; - *result = (TreeCursorEntry){ + *result = (t_tree_cursor_entry){ .subtree = child, .position = self->position, .child_index = self->child_index, @@ -11130,7 +11185,7 @@ static inline bool ts_tree_cursor_child_iterator_next(CursorChildIterator *self, if (self->child_index < self->parent.ptr->child_count) { - Subtree next_child = + t_subtree next_child = ts_subtree_children(self->parent)[self->child_index]; self->position = length_add(self->position, ts_subtree_padding(next_child)); @@ -11143,14 +11198,14 @@ static inline bool ts_tree_cursor_child_iterator_next(CursorChildIterator *self, // can only be computed if `b` has zero rows. Otherwise, this function // returns `LENGTH_UNDEFINED`, and the caller needs to recompute // the position some other way. -static inline Length length_backtrack(Length a, Length b) +static inline t_length length_backtrack(t_length a, t_length b) { if (length_is_undefined(a) || b.extent.row != 0) { return LENGTH_UNDEFINED; } - Length result; + t_length result; result.bytes = a.bytes - b.bytes; result.extent.row = a.extent.row; result.extent.column = a.extent.column - b.extent.column; @@ -11158,15 +11213,15 @@ static inline Length length_backtrack(Length a, Length b) } static inline bool ts_tree_cursor_child_iterator_previous( - CursorChildIterator *self, TreeCursorEntry *result, bool *visible) + CursorChildIterator *self, t_tree_cursor_entry *result, bool *visible) { // this is mostly a reverse `ts_tree_cursor_child_iterator_next` taking into // account unsigned underflow if (!self->parent.ptr || (int8_t)self->child_index == -1) return false; - const Subtree *child = + const t_subtree *child = &ts_subtree_children(self->parent)[self->child_index]; - *result = (TreeCursorEntry){ + *result = (t_tree_cursor_entry){ .subtree = child, .position = self->position, .child_index = self->child_index, @@ -11187,36 +11242,36 @@ static inline bool ts_tree_cursor_child_iterator_previous( // unsigned can underflow so compare it to child_count if (self->child_index < self->parent.ptr->child_count) { - Subtree previous_child = + t_subtree previous_child = ts_subtree_children(self->parent)[self->child_index]; - Length size = ts_subtree_size(previous_child); + t_length size = ts_subtree_size(previous_child); self->position = length_backtrack(self->position, size); } return true; } -// TSTreeCursor - lifecycle +// t_tree_cursor - lifecycle -TSTreeCursor ts_tree_cursor_new(TSNode node) +t_tree_cursor ts_tree_cursor_new(t_parse_node node) { - TSTreeCursor self = {NULL, NULL, {0, 0, 0}}; - ts_tree_cursor_init((TreeCursor *)&self, node); + t_tree_cursor self = {NULL, {0, 0, 0}, 0}; + ts_tree_cursor_init((t_tree_cursor *)&self, node); return self; } -void ts_tree_cursor_reset(TSTreeCursor *_self, TSNode node) +void ts_tree_cursor_reset(t_tree_cursor *_self, t_parse_node node) { - ts_tree_cursor_init((TreeCursor *)_self, node); + ts_tree_cursor_init((t_tree_cursor *)_self, node); } -void ts_tree_cursor_init(TreeCursor *self, TSNode node) +void ts_tree_cursor_init(t_tree_cursor *self, t_parse_node node) { self->tree = node.tree; self->root_alias_symbol = node.context[3]; array_clear(&self->stack); - array_push(&self->stack, ((TreeCursorEntry){ - .subtree = (const Subtree *)node.id, + array_push(&self->stack, ((t_tree_cursor_entry){ + .subtree = (const t_subtree *)node.id, .position = {ts_node_start_byte(node), ts_node_start_point(node)}, .child_index = 0, @@ -11225,19 +11280,20 @@ void ts_tree_cursor_init(TreeCursor *self, TSNode node) })); } -void ts_tree_cursor_delete(TSTreeCursor *_self) +void ts_tree_cursor_delete(t_tree_cursor *_self) { - TreeCursor *self = (TreeCursor *)_self; + t_tree_cursor *self = (t_tree_cursor *)_self; array_delete(&self->stack); } -// TSTreeCursor - walking the tree +// t_tree_cursor - walking the tree -TreeCursorStep ts_tree_cursor_goto_first_child_internal(TSTreeCursor *_self) +t_tree_cursor_step ts_tree_cursor_goto_first_child_internal( + t_tree_cursor *_self) { - TreeCursor *self = (TreeCursor *)_self; + t_tree_cursor *self = (t_tree_cursor *)_self; bool visible; - TreeCursorEntry entry; + t_tree_cursor_entry entry; CursorChildIterator iterator = ts_tree_cursor_iterate_children(self); while (ts_tree_cursor_child_iterator_next(&iterator, &entry, &visible)) { @@ -11255,7 +11311,7 @@ TreeCursorStep ts_tree_cursor_goto_first_child_internal(TSTreeCursor *_self) return TreeCursorStepNone; } -bool ts_tree_cursor_goto_first_child(TSTreeCursor *self) +bool ts_tree_cursor_goto_first_child(t_tree_cursor *self) { for (;;) { @@ -11272,17 +11328,17 @@ bool ts_tree_cursor_goto_first_child(TSTreeCursor *self) return false; } -TreeCursorStep ts_tree_cursor_goto_last_child_internal(TSTreeCursor *_self) +t_tree_cursor_step ts_tree_cursor_goto_last_child_internal(t_tree_cursor *_self) { - TreeCursor *self = (TreeCursor *)_self; + t_tree_cursor *self = (t_tree_cursor *)_self; bool visible; - TreeCursorEntry entry; + t_tree_cursor_entry entry; CursorChildIterator iterator = ts_tree_cursor_iterate_children(self); if (!iterator.parent.ptr || iterator.parent.ptr->child_count == 0) return TreeCursorStepNone; - TreeCursorEntry last_entry = {0}; - TreeCursorStep last_step = TreeCursorStepNone; + t_tree_cursor_entry last_entry = {0}; + t_tree_cursor_step last_step = TreeCursorStepNone; while (ts_tree_cursor_child_iterator_next(&iterator, &entry, &visible)) { if (visible) @@ -11305,7 +11361,7 @@ TreeCursorStep ts_tree_cursor_goto_last_child_internal(TSTreeCursor *_self) return TreeCursorStepNone; } -bool ts_tree_cursor_goto_last_child(TSTreeCursor *self) +bool ts_tree_cursor_goto_last_child(t_tree_cursor *self) { for (;;) { @@ -11323,11 +11379,11 @@ bool ts_tree_cursor_goto_last_child(TSTreeCursor *self) } static inline int64_t ts_tree_cursor_goto_first_child_for_byte_and_point( - TSTreeCursor *_self, uint32_t goal_byte, TSPoint goal_point) + t_tree_cursor *_self, uint32_t goal_byte, t_point goal_point) { - TreeCursor *self = (TreeCursor *)_self; - uint32_t initial_size = self->stack.size; - uint32_t visible_child_index = 0; + t_tree_cursor *self = (t_tree_cursor *)_self; + uint32_t initial_size = self->stack.size; + uint32_t visible_child_index = 0; bool did_descend; do @@ -11335,11 +11391,11 @@ static inline int64_t ts_tree_cursor_goto_first_child_for_byte_and_point( did_descend = false; bool visible; - TreeCursorEntry entry; + t_tree_cursor_entry entry; CursorChildIterator iterator = ts_tree_cursor_iterate_children(self); while (ts_tree_cursor_child_iterator_next(&iterator, &entry, &visible)) { - Length entry_end = + t_length entry_end = length_add(entry.position, ts_subtree_size(*entry.subtree)); bool at_goal = entry_end.bytes >= goal_byte && point_gte(entry_end.extent, goal_point); @@ -11374,30 +11430,30 @@ static inline int64_t ts_tree_cursor_goto_first_child_for_byte_and_point( return -1; } -int64_t ts_tree_cursor_goto_first_child_for_byte(TSTreeCursor *self, - uint32_t goal_byte) +int64_t ts_tree_cursor_goto_first_child_for_byte(t_tree_cursor *self, + uint32_t goal_byte) { return ts_tree_cursor_goto_first_child_for_byte_and_point(self, goal_byte, POINT_ZERO); } -int64_t ts_tree_cursor_goto_first_child_for_point(TSTreeCursor *self, - TSPoint goal_point) +int64_t ts_tree_cursor_goto_first_child_for_point(t_tree_cursor *self, + t_point goal_point) { return ts_tree_cursor_goto_first_child_for_byte_and_point(self, 0, goal_point); } -TreeCursorStep ts_tree_cursor_goto_sibling_internal( - TSTreeCursor *_self, - bool (*advance)(CursorChildIterator *, TreeCursorEntry *, bool *)) +t_tree_cursor_step ts_tree_cursor_goto_sibling_internal( + t_tree_cursor *_self, + bool (*advance)(CursorChildIterator *, t_tree_cursor_entry *, bool *)) { - TreeCursor *self = (TreeCursor *)_self; - uint32_t initial_size = self->stack.size; + t_tree_cursor *self = (t_tree_cursor *)_self; + uint32_t initial_size = self->stack.size; while (self->stack.size > 1) { - TreeCursorEntry entry = array_pop(&self->stack); + t_tree_cursor_entry entry = array_pop(&self->stack); CursorChildIterator iterator = ts_tree_cursor_iterate_children(self); iterator.child_index = entry.child_index; iterator.structural_child_index = entry.structural_child_index; @@ -11429,13 +11485,14 @@ TreeCursorStep ts_tree_cursor_goto_sibling_internal( return TreeCursorStepNone; } -TreeCursorStep ts_tree_cursor_goto_next_sibling_internal(TSTreeCursor *_self) +t_tree_cursor_step ts_tree_cursor_goto_next_sibling_internal( + t_tree_cursor *_self) { return ts_tree_cursor_goto_sibling_internal( _self, ts_tree_cursor_child_iterator_next); } -bool ts_tree_cursor_goto_next_sibling(TSTreeCursor *self) +bool ts_tree_cursor_goto_next_sibling(t_tree_cursor *self) { switch (ts_tree_cursor_goto_next_sibling_internal(self)) { @@ -11449,15 +11506,15 @@ bool ts_tree_cursor_goto_next_sibling(TSTreeCursor *self) } } -TreeCursorStep ts_tree_cursor_goto_previous_sibling_internal( - TSTreeCursor *_self) +t_tree_cursor_step ts_tree_cursor_goto_previous_sibling_internal( + t_tree_cursor *_self) { // since subtracting across row loses column information, we may have to // restore it - TreeCursor *self = (TreeCursor *)_self; + t_tree_cursor *self = (t_tree_cursor *)_self; // for that, save current position before traversing - TreeCursorStep step = ts_tree_cursor_goto_sibling_internal( + t_tree_cursor_step step = ts_tree_cursor_goto_sibling_internal( _self, ts_tree_cursor_child_iterator_previous); if (step == TreeCursorStepNone) return step; @@ -11467,10 +11524,11 @@ TreeCursorStep ts_tree_cursor_goto_previous_sibling_internal( return step; // restore position from the parent node - const TreeCursorEntry *parent = &self->stack.contents[self->stack.size - 2]; - Length position = parent->position; - uint32_t child_index = array_back(&self->stack)->child_index; - const Subtree *children = ts_subtree_children((*(parent->subtree))); + const t_tree_cursor_entry *parent = + &self->stack.contents[self->stack.size - 2]; + t_length position = parent->position; + uint32_t child_index = array_back(&self->stack)->child_index; + const t_subtree *children = ts_subtree_children((*(parent->subtree))); if (child_index > 0) { @@ -11490,7 +11548,7 @@ TreeCursorStep ts_tree_cursor_goto_previous_sibling_internal( return step; } -bool ts_tree_cursor_goto_previous_sibling(TSTreeCursor *self) +bool ts_tree_cursor_goto_previous_sibling(t_tree_cursor *self) { switch (ts_tree_cursor_goto_previous_sibling_internal(self)) { @@ -11504,9 +11562,9 @@ bool ts_tree_cursor_goto_previous_sibling(TSTreeCursor *self) } } -bool ts_tree_cursor_goto_parent(TSTreeCursor *_self) +bool ts_tree_cursor_goto_parent(t_tree_cursor *_self) { - TreeCursor *self = (TreeCursor *)_self; + t_tree_cursor *self = (t_tree_cursor *)_self; for (unsigned i = self->stack.size - 2; i + 1 > 0; i--) { if (ts_tree_cursor_is_entry_visible(self, i)) @@ -11518,17 +11576,17 @@ bool ts_tree_cursor_goto_parent(TSTreeCursor *_self) return false; } -void ts_tree_cursor_goto_descendant(TSTreeCursor *_self, - uint32_t goal_descendant_index) +void ts_tree_cursor_goto_descendant(t_tree_cursor *_self, + uint32_t goal_descendant_index) { - TreeCursor *self = (TreeCursor *)_self; + t_tree_cursor *self = (t_tree_cursor *)_self; // Ascend to the lowest ancestor that contains the goal node. for (;;) { - uint32_t i = self->stack.size - 1; - TreeCursorEntry *entry = &self->stack.contents[i]; - uint32_t next_descendant_index = + uint32_t i = self->stack.size - 1; + t_tree_cursor_entry *entry = &self->stack.contents[i]; + uint32_t next_descendant_index = entry->descendant_index + (ts_tree_cursor_is_entry_visible(self, i) ? 1 : 0) + ts_subtree_visible_descendant_count(*entry->subtree); @@ -11553,7 +11611,7 @@ void ts_tree_cursor_goto_descendant(TSTreeCursor *_self, { did_descend = false; bool visible; - TreeCursorEntry entry; + t_tree_cursor_entry entry; CursorChildIterator iterator = ts_tree_cursor_iterate_children(self); if (iterator.descendant_index > goal_descendant_index) { @@ -11579,21 +11637,21 @@ void ts_tree_cursor_goto_descendant(TSTreeCursor *_self, } while (did_descend); } -uint32_t ts_tree_cursor_current_descendant_index(const TSTreeCursor *_self) +uint32_t ts_tree_cursor_current_descendant_index(const t_tree_cursor *_self) { - const TreeCursor *self = (const TreeCursor *)_self; - TreeCursorEntry *last_entry = array_back(&self->stack); + const t_tree_cursor *self = (const t_tree_cursor *)_self; + t_tree_cursor_entry *last_entry = array_back(&self->stack); return last_entry->descendant_index; } -TSNode ts_tree_cursor_current_node(const TSTreeCursor *_self) +t_parse_node ts_tree_cursor_current_node(const t_tree_cursor *_self) { - const TreeCursor *self = (const TreeCursor *)_self; - TreeCursorEntry *last_entry = array_back(&self->stack); - TSSymbol alias_symbol = self->root_alias_symbol; + const t_tree_cursor *self = (const t_tree_cursor *)_self; + t_tree_cursor_entry *last_entry = array_back(&self->stack); + t_symbol alias_symbol = self->root_alias_symbol; if (self->stack.size > 1 && !ts_subtree_extra(*last_entry->subtree)) { - TreeCursorEntry *parent_entry = + t_tree_cursor_entry *parent_entry = &self->stack.contents[self->stack.size - 2]; alias_symbol = ts_language_alias_at( self->tree->language, parent_entry->subtree->ptr->production_id, @@ -11606,13 +11664,13 @@ TSNode ts_tree_cursor_current_node(const TSTreeCursor *_self) // Private - Get various facts about the current node that are needed // when executing tree queries. void ts_tree_cursor_current_status( - const TSTreeCursor *_self, TSFieldId *field_id, bool *has_later_siblings, + const t_tree_cursor *_self, t_field_id *field_id, bool *has_later_siblings, bool *has_later_named_siblings, - bool *can_have_later_siblings_with_this_field, TSSymbol *supertypes, + bool *can_have_later_siblings_with_this_field, t_symbol *supertypes, unsigned *supertype_count) { - const TreeCursor *self = (const TreeCursor *)_self; - unsigned max_supertypes = *supertype_count; + const t_tree_cursor *self = (const t_tree_cursor *)_self; + unsigned max_supertypes = *supertype_count; *field_id = 0; *supertype_count = 0; *has_later_siblings = false; @@ -11623,10 +11681,10 @@ void ts_tree_cursor_current_status( // because fields can refer to nodes through invisible *wrapper* nodes, for (unsigned i = self->stack.size - 1; i > 0; i--) { - TreeCursorEntry *entry = &self->stack.contents[i]; - TreeCursorEntry *parent_entry = &self->stack.contents[i - 1]; + t_tree_cursor_entry *entry = &self->stack.contents[i]; + t_tree_cursor_entry *parent_entry = &self->stack.contents[i - 1]; - const TSSymbol *alias_sequence = ts_language_alias_sequence( + const t_symbol *alias_sequence = ts_language_alias_sequence( self->tree->language, parent_entry->subtree->ptr->production_id); #define subtree_symbol(subtree, structural_child_index) \ @@ -11636,9 +11694,9 @@ void ts_tree_cursor_current_status( : ts_subtree_symbol(subtree)) // Stop walking up when a visible ancestor is found. - TSSymbol entry_symbol = + t_symbol entry_symbol = subtree_symbol(*entry->subtree, entry->structural_child_index); - TSSymbolMetadata entry_metadata = + t_symbol_metadata entry_metadata = ts_language_symbol_metadata(self->tree->language, entry_symbol); if (i != self->stack.size - 1 && entry_metadata.visible) break; @@ -11659,11 +11717,12 @@ void ts_tree_cursor_current_status( structural_child_index++; for (unsigned j = entry->child_index + 1; j < sibling_count; j++) { - Subtree sibling = + t_subtree sibling = ts_subtree_children(*parent_entry->subtree)[j]; - TSSymbolMetadata sibling_metadata = ts_language_symbol_metadata( - self->tree->language, - subtree_symbol(sibling, structural_child_index)); + t_symbol_metadata sibling_metadata = + ts_language_symbol_metadata( + self->tree->language, + subtree_symbol(sibling, structural_child_index)); if (sibling_metadata.visible) { *has_later_siblings = true; @@ -11695,7 +11754,7 @@ void ts_tree_cursor_current_status( if (!ts_subtree_extra(*entry->subtree)) { - const TSFieldMapEntry *field_map, *field_map_end; + const t_field_map_entry *field_map, *field_map_end; ts_language_field_map(self->tree->language, parent_entry->subtree->ptr->production_id, &field_map, &field_map_end); @@ -11703,7 +11762,7 @@ void ts_tree_cursor_current_status( // Look for a field name associated with the current node. if (!*field_id) { - for (const TSFieldMapEntry *map = field_map; + for (const t_field_map_entry *map = field_map; map < field_map_end; map++) { if (!map->inherited && @@ -11719,7 +11778,7 @@ void ts_tree_cursor_current_status( // same field name. if (*field_id) { - for (const TSFieldMapEntry *map = field_map; + for (const t_field_map_entry *map = field_map; map < field_map_end; map++) { if (map->field_id == *field_id && @@ -11734,10 +11793,10 @@ void ts_tree_cursor_current_status( } } -uint32_t ts_tree_cursor_current_depth(const TSTreeCursor *_self) +uint32_t ts_tree_cursor_current_depth(const t_tree_cursor *_self) { - const TreeCursor *self = (const TreeCursor *)_self; - uint32_t depth = 0; + const t_tree_cursor *self = (const t_tree_cursor *)_self; + uint32_t depth = 0; for (unsigned i = 1; i < self->stack.size; i++) { if (ts_tree_cursor_is_entry_visible(self, i)) @@ -11748,17 +11807,17 @@ uint32_t ts_tree_cursor_current_depth(const TSTreeCursor *_self) return depth; } -TSNode ts_tree_cursor_parent_node(const TSTreeCursor *_self) +t_parse_node ts_tree_cursor_parent_node(const t_tree_cursor *_self) { - const TreeCursor *self = (const TreeCursor *)_self; + const t_tree_cursor *self = (const t_tree_cursor *)_self; for (int i = (int)self->stack.size - 2; i >= 0; i--) { - TreeCursorEntry *entry = &self->stack.contents[i]; - bool is_visible = true; - TSSymbol alias_symbol = 0; + t_tree_cursor_entry *entry = &self->stack.contents[i]; + bool is_visible = true; + t_symbol alias_symbol = 0; if (i > 0) { - TreeCursorEntry *parent_entry = &self->stack.contents[i - 1]; + t_tree_cursor_entry *parent_entry = &self->stack.contents[i - 1]; alias_symbol = ts_language_alias_at( self->tree->language, parent_entry->subtree->ptr->production_id, entry->structural_child_index); @@ -11774,15 +11833,15 @@ TSNode ts_tree_cursor_parent_node(const TSTreeCursor *_self) return ts_node_new(NULL, NULL, length_zero(), 0); } -TSFieldId ts_tree_cursor_current_field_id(const TSTreeCursor *_self) +t_field_id ts_tree_cursor_current_field_id(const t_tree_cursor *_self) { - const TreeCursor *self = (const TreeCursor *)_self; + const t_tree_cursor *self = (const t_tree_cursor *)_self; // Walk up the tree, visiting the current node and its invisible ancestors. for (unsigned i = self->stack.size - 1; i > 0; i--) { - TreeCursorEntry *entry = &self->stack.contents[i]; - TreeCursorEntry *parent_entry = &self->stack.contents[i - 1]; + t_tree_cursor_entry *entry = &self->stack.contents[i]; + t_tree_cursor_entry *parent_entry = &self->stack.contents[i - 1]; // Stop walking up when another visible node is found. if (i != self->stack.size - 1 && @@ -11792,11 +11851,12 @@ TSFieldId ts_tree_cursor_current_field_id(const TSTreeCursor *_self) if (ts_subtree_extra(*entry->subtree)) break; - const TSFieldMapEntry *field_map, *field_map_end; + const t_field_map_entry *field_map, *field_map_end; ts_language_field_map(self->tree->language, parent_entry->subtree->ptr->production_id, &field_map, &field_map_end); - for (const TSFieldMapEntry *map = field_map; map < field_map_end; map++) + for (const t_field_map_entry *map = field_map; map < field_map_end; + map++) { if (!map->inherited && map->child_index == entry->structural_child_index) @@ -11808,12 +11868,12 @@ TSFieldId ts_tree_cursor_current_field_id(const TSTreeCursor *_self) return 0; } -const char *ts_tree_cursor_current_field_name(const TSTreeCursor *_self) +const char *ts_tree_cursor_current_field_name(const t_tree_cursor *_self) { - TSFieldId id = ts_tree_cursor_current_field_id(_self); + t_field_id id = ts_tree_cursor_current_field_id(_self); if (id) { - const TreeCursor *self = (const TreeCursor *)_self; + const t_tree_cursor *self = (const t_tree_cursor *)_self; return self->tree->language->field_names[id]; } else @@ -11822,11 +11882,11 @@ const char *ts_tree_cursor_current_field_name(const TSTreeCursor *_self) } } -TSTreeCursor ts_tree_cursor_copy(const TSTreeCursor *_cursor) +t_tree_cursor ts_tree_cursor_copy(const t_tree_cursor *_cursor) { - const TreeCursor *cursor = (const TreeCursor *)_cursor; - TSTreeCursor res = {NULL, NULL, {0, 0}}; - TreeCursor *copy = (TreeCursor *)&res; + const t_tree_cursor *cursor = (const t_tree_cursor *)_cursor; + t_tree_cursor res = {NULL, {0, 0, 0}, 0}; + t_tree_cursor *copy = (t_tree_cursor *)&res; copy->tree = cursor->tree; copy->root_alias_symbol = cursor->root_alias_symbol; array_init(©->stack); @@ -11834,10 +11894,10 @@ TSTreeCursor ts_tree_cursor_copy(const TSTreeCursor *_cursor) return res; } -void ts_tree_cursor_reset_to(TSTreeCursor *_dst, const TSTreeCursor *_src) +void ts_tree_cursor_reset_to(t_tree_cursor *_dst, const t_tree_cursor *_src) { - const TreeCursor *cursor = (const TreeCursor *)_src; - TreeCursor *copy = (TreeCursor *)_dst; + const t_tree_cursor *cursor = (const t_tree_cursor *)_src; + t_tree_cursor *copy = (t_tree_cursor *)_dst; copy->tree = cursor->tree; copy->root_alias_symbol = cursor->root_alias_symbol; array_clear(©->stack); diff --git a/parser/src/scanner.c b/parser/src/scanner.c index f5e3eb81..8c9677ac 100644 --- a/parser/src/scanner.c +++ b/parser/src/scanner.c @@ -63,9 +63,9 @@ typedef struct { Array(Heredoc) heredocs; } Scanner; -static inline void advance(TSLexer *lexer) { lexer->advance(lexer, false); } +static inline void advance(t_lexer_data *lexer) { lexer->advance(lexer, false); } -static inline void skip(TSLexer *lexer) { lexer->advance(lexer, true); } +static inline void skip(t_lexer_data *lexer) { lexer->advance(lexer, true); } static inline bool in_error_recovery(const bool *valid_symbols) { return valid_symbols[ERROR_RECOVERY]; } @@ -160,7 +160,7 @@ static void deserialize(Scanner *scanner, const char *buffer, unsigned length) { * POSIX-mandated substitution, and assumes the default value for * IFS. */ -static bool advance_word(TSLexer *lexer, String *unquoted_word) { +static bool advance_word(t_lexer_data *lexer, String *unquoted_word) { bool empty = true; int32_t quote = 0; @@ -191,7 +191,7 @@ static bool advance_word(TSLexer *lexer, String *unquoted_word) { return !empty; } -static inline bool scan_bare_dollar(TSLexer *lexer) { +static inline bool scan_bare_dollar(t_lexer_data *lexer) { while (iswspace(lexer->lookahead) && lexer->lookahead != '\n' && !lexer->eof(lexer)) { skip(lexer); } @@ -206,7 +206,7 @@ static inline bool scan_bare_dollar(TSLexer *lexer) { return false; } -static bool scan_heredoc_start(Heredoc *heredoc, TSLexer *lexer) { +static bool scan_heredoc_start(Heredoc *heredoc, t_lexer_data *lexer) { while (iswspace(lexer->lookahead)) { skip(lexer); } @@ -222,7 +222,7 @@ static bool scan_heredoc_start(Heredoc *heredoc, TSLexer *lexer) { return found_delimiter; } -static bool scan_heredoc_end_identifier(Heredoc *heredoc, TSLexer *lexer) { +static bool scan_heredoc_end_identifier(Heredoc *heredoc, t_lexer_data *lexer) { reset_string(&heredoc->current_leading_word); // Scan the first 'n' characters on this line, to see if they match the // heredoc delimiter @@ -242,7 +242,7 @@ static bool scan_heredoc_end_identifier(Heredoc *heredoc, TSLexer *lexer) { : strcmp(heredoc->current_leading_word.contents, heredoc->delimiter.contents) == 0; } -static bool scan_heredoc_content(Scanner *scanner, TSLexer *lexer, enum TokenType middle_type, +static bool scan_heredoc_content(Scanner *scanner, t_lexer_data *lexer, enum TokenType middle_type, enum TokenType end_type) { bool did_advance = false; Heredoc *heredoc = array_back(&scanner->heredocs); @@ -345,7 +345,7 @@ static bool scan_heredoc_content(Scanner *scanner, TSLexer *lexer, enum TokenTyp } } -static bool scan(Scanner *scanner, TSLexer *lexer, const bool *valid_symbols) { +static bool scan(Scanner *scanner, t_lexer_data *lexer, const bool *valid_symbols) { if (valid_symbols[CONCAT] && !in_error_recovery(valid_symbols)) { if (!(lexer->lookahead == 0 || iswspace(lexer->lookahead) || lexer->lookahead == '>' || lexer->lookahead == '<' || lexer->lookahead == ')' || lexer->lookahead == '(' || @@ -1189,7 +1189,7 @@ void *tree_sitter_bash_external_scanner_create() { return scanner; } -bool tree_sitter_bash_external_scanner_scan(void *payload, TSLexer *lexer, const bool *valid_symbols) { +bool tree_sitter_bash_external_scanner_scan(void *payload, t_lexer_data *lexer, const bool *valid_symbols) { Scanner *scanner = (Scanner *)payload; return scan(scanner, lexer, valid_symbols); } diff --git a/sources/ft_exit.c b/sources/ft_exit.c index 32468b64..cc5f8b35 100644 --- a/sources/ft_exit.c +++ b/sources/ft_exit.c @@ -12,7 +12,7 @@ #include "../includes/minishell.h" -void ts_parser_delete(TSParser *self); +void ts_parser_delete(t_first_parser *self); void ft_free(void *ptr) { diff --git a/sources/main.c b/sources/main.c index 143a1f80..bd7e0eba 100644 --- a/sources/main.c +++ b/sources/main.c @@ -15,13 +15,13 @@ #include "me/string/str_len.h" #include "parser/api.h" -TSParser *ts_parser_new(); -void ts_tree_delete(TSTree *); -TSNode ts_tree_root_node(TSTree *); -TSTree *ts_parser_parse_string(TSParser *, TSTree *oldtree, t_const_str input, +t_first_parser *ts_parser_new(); +void ts_tree_delete(t_first_tree *); +t_parse_node ts_tree_root_node(t_first_tree *); +t_first_tree *ts_parser_parse_string(t_first_parser *, t_first_tree *oldtree, t_const_str input, t_usize len); -void ts_parser_delete(TSParser *self); -void ts_parser_set_language(TSParser *self, TSLanguage *lang); +void ts_parser_delete(t_first_parser *self); +void ts_parser_set_language(t_first_parser *self, t_language *lang); void print_node_data(t_node *t, t_usize depth) { @@ -36,10 +36,10 @@ void print_node_data(t_node *t, t_usize depth) print_node_data(&t->childs[idx++], depth + 1); } -t_node parse_to_nodes(TSParser *parser, t_const_str input) +t_node parse_to_nodes(t_first_parser *parser, t_const_str input) { - TSTree *tree; - TSNode node; + t_first_tree *tree; + t_parse_node node; t_node ret; tree = ts_parser_parse_string(parser, NULL, input, str_len(input)); @@ -112,12 +112,12 @@ void ft_find_path(t_str arge[], t_utils *utils) utils->path = ft_split(PATH_FILES, ':'); } -TSLanguage *tree_sitter_bash(void); +t_language *tree_sitter_bash(void); t_parser create_myparser(void) { - TSLanguage *lang; - TSParser *parser; + t_language *lang; + t_first_parser *parser; lang = tree_sitter_bash(); parser = ts_parser_new(); diff --git a/sources/node/node.c b/sources/node/node.c index 71b2a745..bf6817fc 100644 --- a/sources/node/node.c +++ b/sources/node/node.c @@ -16,19 +16,19 @@ #include "me/string/str_l_copy.h" #include "parser/api.h" -t_node build_node(TSNode current, t_const_str input); -TSNode ts_node_child(TSNode parent, t_usize idx); -TSSymbol ts_node_symbol(TSNode self); -t_const_str ts_node_type(TSNode self); -t_u32 ts_node_start_byte(TSNode self); -t_u32 ts_node_end_byte(TSNode self); -t_u32 ts_node_child_count(TSNode self); +t_node build_node(t_parse_node current, t_const_str input); +t_parse_node ts_node_child(t_parse_node parent, t_usize idx); +t_symbol ts_node_symbol(t_parse_node self); +t_const_str ts_node_type(t_parse_node self); +t_u32 ts_node_start_byte(t_parse_node self); +t_u32 ts_node_end_byte(t_parse_node self); +t_u32 ts_node_child_count(t_parse_node self); -t_node *build_childs(TSNode parent, t_const_str input, t_usize count) +t_node *build_childs(t_parse_node parent, t_const_str input, t_usize count) { t_node *ret; t_usize idx; - TSNode child; + t_parse_node child; ret = mem_alloc_array(sizeof(*ret), count); if (ret == NULL) @@ -43,7 +43,7 @@ t_node *build_childs(TSNode parent, t_const_str input, t_usize count) return (ret); } -t_node build_node(TSNode curr, t_const_str input) +t_node build_node(t_parse_node curr, t_const_str input) { t_node out; diff --git a/stdme/.envrc b/stdme/.envrc deleted file mode 100644 index 3550a30f..00000000 --- a/stdme/.envrc +++ /dev/null @@ -1 +0,0 @@ -use flake diff --git a/stdme/Makefile b/stdme/Makefile index 59663f44..983d0811 100644 --- a/stdme/Makefile +++ b/stdme/Makefile @@ -6,7 +6,7 @@ # By: maiboyer +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/11/03 13:20:01 by maiboyer #+# #+# # -# Updated: 2024/04/28 20:00:43 by maiboyer ### ########.fr # +# Updated: 2024/05/01 20:31:58 by maiboyer ### ########.fr # # # # **************************************************************************** # @@ -52,23 +52,19 @@ all: $(NAME) $(NAME): $(TARGET) $(TARGET): $(OBJ) - @printf \\n$(COL_GRAY)Building\ Output\ $(COL_WHITE)$(COL_BOLD)%-28s$(COL_RESET)\ \ - $(NAME) + @echo -e "$(COL_GRAY) Linking\t$(COL_GREEN)$(TARGET)$(COL_RESET)" @#$(CC) $(INCLUDES) $(OBJ) $(CFLAGS) -o $(NAME) @ar rcs $(BUILD_DIR)/$(NAME) $(OBJ) - @printf $(COL_GREEN)done$(COL_RESET)\\n $(BUILD_DIR)/%.o: $(SRC_DIR)/%.c @mkdir -p $(dir $@) - @printf $(COL_GRAY)Building\ $(COL_BOLD)$(COL_WHITE)%-50s\ $(LIB_NAME)$< + @echo -e "$(COL_GRAY) Building\t$(COL_GREEN)$<$(COL_RESET)" @$(CC) $(CFLAGS) $(WERROR) $(INCLUDES) -c $< -o $@ - @printf $(COL_RESET)$(COL_GREEN)done$(COL_RESET)\\n $(BUILD_DIR)/%.o: $(GENERIC_DIR)/%.c @mkdir -p $(dir $@) - @printf $(COL_GRAY)Building\ $(COL_BOLD)$(COL_WHITE)%-50s\ $(LIB_NAME)$< + @echo -e "$(COL_GRAY) Building\t$(COL_GREEN)$<$(COL_RESET)" @$(CC) $(CFLAGS) $(WERROR) $(INCLUDES) -c $< -o $@ - @printf $(COL_RESET)$(COL_GREEN)done$(COL_RESET)\\n clean: @- $(foreach LIB,$(LIBS), \ diff --git a/stdme/src/fs/putnbr_fd.c b/stdme/src/fs/putnbr_fd.c index e1d8d5a0..e4746103 100644 --- a/stdme/src/fs/putnbr_fd.c +++ b/stdme/src/fs/putnbr_fd.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/08 12:45:06 by maiboyer #+# #+# */ -/* Updated: 2024/04/28 19:42:10 by maiboyer ### ########.fr */ +/* Updated: 2024/05/01 20:29:59 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,10 +37,10 @@ static void me_inner(t_u64 nb, t_str out, t_usize *idx) void me_putnbr_fd(t_i32 n, t_file file) { t_usize idx; - t_u64 nb; + t_i64 nb; char out[15]; - nb = (t_u64)n; + nb = (t_i64)n; idx = 0; if (nb < 0) { diff --git a/stdme/src/string/str_find_rev_chr.c b/stdme/src/string/str_find_rev_chr.c index 7454a6e6..3072f26b 100644 --- a/stdme/src/string/str_find_rev_chr.c +++ b/stdme/src/string/str_find_rev_chr.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/04 17:29:13 by maiboyer #+# #+# */ -/* Updated: 2024/04/28 19:42:46 by maiboyer ### ########.fr */ +/* Updated: 2024/05/01 20:30:38 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,7 +15,7 @@ char *str_find_rev_chr(t_const_str str, char chr) { - t_usize index; + t_isize index; if (str == NULL) return (NULL);