WIP parser norminettation

This commit is contained in:
Maieul BOYER 2024-04-29 15:38:44 +02:00
parent 16f49181b5
commit ff4b0c471f
No known key found for this signature in database
44 changed files with 1130 additions and 265 deletions

View file

@ -6,11 +6,11 @@
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# #
# Updated: 2024/04/28 20:00:24 by maiboyer ### ########.fr #
# Updated: 2024/04/29 14:31:52 by maiboyer ### ########.fr #
# #
# **************************************************************************** #
BUILD_DIR = ./build
BUILD_DIR = ../build
SRC_DIR = ./
BONUS_FLAGS =
@ -18,7 +18,7 @@ NAME = libgmr.a
LIB_NAME ?=
TARGET = $(BUILD_DIR)/$(NAME)
CC = cc
CFLAGS = -Wall -Wextra -Werror -g3 -MMD -I./includes
CFLAGS = -Wall -Wextra -Werror -g3 -MMD -I./includes -I../includes -I../output/include
include ./Filelist.mk

View file

@ -5,6 +5,8 @@
#include <stdint.h>
#include <stdlib.h>
#include "me/vec/vec_parser_range.h"
/****************************/
/* Section - ABI Versioning */
/****************************/
@ -51,24 +53,10 @@ typedef enum TSSymbolType
TSSymbolTypeAuxiliary,
} TSSymbolType;
typedef struct TSPoint
{
uint32_t row;
uint32_t column;
} TSPoint;
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,
const char *(*read)(void *payload, uint32_t byte_index, t_point position,
uint32_t *bytes_read);
TSInputEncoding encoding;
} TSInput;
@ -90,9 +78,9 @@ 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;
t_point start_point;
t_point old_end_point;
t_point new_end_point;
} TSInputEdit;
typedef struct TSNode
@ -210,7 +198,7 @@ bool ts_parser_set_language(TSParser *self, const TSLanguage *language);
* will not be assigned, and this function will return `false`. On success,
* this function returns `true`
*/
bool ts_parser_set_included_ranges(TSParser *self, const TSRange *ranges,
bool ts_parser_set_included_ranges(TSParser *self, const t_parser_range *ranges,
uint32_t count);
/**
@ -220,7 +208,8 @@ bool ts_parser_set_included_ranges(TSParser *self, const TSRange *ranges,
* it or write to it. The length of the array will be written to the given
* `count` pointer.
*/
const TSRange *ts_parser_included_ranges(const TSParser *self, uint32_t *count);
const t_parser_range *ts_parser_included_ranges(const TSParser *self,
uint32_t *count);
/**
* Use the parser to parse some source code and create a syntax tree.
@ -387,7 +376,7 @@ TSNode ts_tree_root_node(const TSTree *self);
* shifted forward by the given offset.
*/
TSNode ts_tree_root_node_with_offset(const TSTree *self, uint32_t offset_bytes,
TSPoint offset_extent);
t_point offset_extent);
/**
* Get the language that was used to parse the syntax tree.
@ -399,7 +388,7 @@ const TSLanguage *ts_tree_language(const TSTree *self);
*
* The returned pointer must be freed by the caller.
*/
TSRange *ts_tree_included_ranges(const TSTree *self, uint32_t *length);
t_parser_range *ts_tree_included_ranges(const TSTree *self, uint32_t *length);
/**
* Edit the syntax tree to keep it in sync with source code that has been
@ -425,8 +414,9 @@ void ts_tree_edit(TSTree *self, const TSInputEdit *edit);
* responsible for freeing it using `free`. The length of the array will be
* written to the given `length` pointer.
*/
TSRange *ts_tree_get_changed_ranges(const TSTree *old_tree,
const TSTree *new_tree, uint32_t *length);
t_parser_range *ts_tree_get_changed_ranges(const TSTree *old_tree,
const TSTree *new_tree,
uint32_t *length);
/**
* Write a DOT graph describing the syntax tree to the given file.
@ -474,7 +464,7 @@ uint32_t ts_node_start_byte(TSNode self);
/**
* Get the node's start position in terms of rows and columns.
*/
TSPoint ts_node_start_point(TSNode self);
t_point ts_node_start_point(TSNode self);
/**
* Get the node's end byte.
@ -484,7 +474,7 @@ uint32_t ts_node_end_byte(TSNode self);
/**
* Get the node's end position in terms of rows and columns.
*/
TSPoint ts_node_end_point(TSNode self);
t_point ts_node_end_point(TSNode self);
/**
* Get an S-expression representing the node as a string.
@ -629,8 +619,8 @@ uint32_t ts_node_descendant_count(TSNode self);
*/
TSNode ts_node_descendant_for_byte_range(TSNode self, uint32_t start,
uint32_t end);
TSNode ts_node_descendant_for_point_range(TSNode self, TSPoint start,
TSPoint end);
TSNode ts_node_descendant_for_point_range(TSNode self, t_point start,
t_point end);
/**
* Get the smallest named node within this node that spans the given range
@ -638,8 +628,8 @@ TSNode ts_node_descendant_for_point_range(TSNode self, TSPoint start,
*/
TSNode ts_node_named_descendant_for_byte_range(TSNode self, uint32_t start,
uint32_t end);
TSNode ts_node_named_descendant_for_point_range(TSNode self, TSPoint start,
TSPoint end);
TSNode ts_node_named_descendant_for_point_range(TSNode self, t_point start,
t_point end);
/**
* Edit the node to keep it in-sync with source code that has been edited.
@ -790,7 +780,7 @@ uint32_t ts_tree_cursor_current_depth(const TSTreeCursor *self);
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_point(TSTreeCursor *self,
TSPoint goal_point);
t_point goal_point);
TSTreeCursor ts_tree_cursor_copy(const TSTreeCursor *cursor);
@ -976,8 +966,8 @@ void ts_query_cursor_set_match_limit(TSQueryCursor *self, uint32_t limit);
*/
void ts_query_cursor_set_byte_range(TSQueryCursor *self, uint32_t start_byte,
uint32_t end_byte);
void ts_query_cursor_set_point_range(TSQueryCursor *self, TSPoint start_point,
TSPoint end_point);
void ts_query_cursor_set_point_range(TSQueryCursor *self, t_point start_point,
t_point end_point);
/**
* Advance to the next match of the currently running query.

View file

@ -9,48 +9,4 @@
#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
typedef struct s_language t_language;
typedef struct s_scanner
{
const bool *states;
const t_symbol *symbol_map;
void *(*create)(void);
void (*destroy)(void *);
bool (*scan)(void *, t_lexer *, const bool *symbol_whitelist);
unsigned (*serialize)(void *, char *);
void (*deserialize)(void *, const char *, unsigned);
} t_scanner;
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 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_modes *lex_modes;
bool (*lex_fn)(t_lexer *, t_state_id);
bool (*keyword_lex_fn)(t_lexer *, t_state_id);
t_symbol keyword_capture_token;
t_scanner external_scanner;
const t_state_id *primary_state_ids;
};
#endif // TREE_SITTER_PARSER_H_

View file

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_char_range.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 15:03:34 by maiboyer #+# #+# */
/* Updated: 2024/04/29 15:27:38 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_CHAR_RANGE_H
# define TYPES_CHAR_RANGE_H
# include "me/types.h"
typedef struct s_char_range
{
t_i32 start;
t_i32 end;
} t_char_range;
#endif /* TYPES_CHAR_RANGE_H */

View file

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_field_entry.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 14:51:21 by maiboyer #+# #+# */
/* Updated: 2024/04/29 15:35:36 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_FIELD_ENTRY_H
# define TYPES_FIELD_ENTRY_H
# include "parser/types/types_field_id.h"
typedef struct s_field_map_entry
{
t_field_id field_id;
t_u8 child_index;
bool inherited;
} t_field_map_entry;
#endif /* TYPES_FIELD_ENTRY_H */

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_field_id.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 14:44:38 by maiboyer #+# #+# */
/* Updated: 2024/04/29 14:44:44 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_FIELD_ID_H
# define TYPES_FIELD_ID_H
# include "me/types.h"
typedef t_u16 t_field_id;
#endif /* TYPES_FIELD_ID_H */

View file

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_field_map_entry.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 14:51:45 by maiboyer #+# #+# */
/* Updated: 2024/04/29 14:53:31 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_FIELD_MAP_ENTRY_H
# define TYPES_FIELD_MAP_ENTRY_H
# include "me/types.h"
# include "parser/types/types_field_id.h"
typedef struct s_field_map_entry
{
t_field_id field_id;
t_u8 child_index;
bool inherited;
} t_field_map_entry;
#endif /* TYPES_FIELD_MAP_ENTRY_H */

View file

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_field_map_slice.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 14:54:41 by maiboyer #+# #+# */
/* Updated: 2024/04/29 15:08:21 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_FIELD_MAP_SLICE_H
# define TYPES_FIELD_MAP_SLICE_H
# include "me/types.h"
typedef struct s_field_map_slice
{
t_u16 index;
t_u16 length;
} t_field_map_slice;
#endif /* TYPES_FIELD_MAP_SLICE_H */

View file

@ -0,0 +1,61 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_language.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 14:39:37 by maiboyer #+# #+# */
/* Updated: 2024/04/29 15:36:47 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_LANGUAGE_H
# define TYPES_LANGUAGE_H
# include "me/types.h"
# include "parser/types/types_field_map_entry.h"
# include "parser/types/types_field_map_slice.h"
# include "parser/types/types_lex_modes.h"
# include "parser/types/types_lexer.h"
# include "parser/types/types_parse_action_entry.h"
# include "parser/types/types_scanner.h"
# include "parser/types/types_state_id.h"
# include "parser/types/types_symbol.h"
# include "parser/types/types_symbol_metadata.h"
typedef bool (*t_lex_fn)(t_lexer *lex, t_state_id state);
typedef struct s_language
{
t_u32 version;
t_u32 symbol_count;
t_u32 alias_count;
t_u32 token_count;
t_u32 external_token_count;
t_u32 state_count;
t_u32 large_state_count;
t_u32 production_id_count;
t_u32 field_count;
t_u16 max_alias_sequence_length;
const t_u16 *parse_table;
const t_u16 *small_parse_table;
const t_u32 *small_parse_table_map;
const t_parse_action_entry *parse_actions;
const t_const_str *symbol_names;
const t_const_str *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 t_u16 *alias_map;
const t_symbol *alias_sequences;
const t_lex_modes *lex_modes;
t_lex_fn lex_fn;
t_lex_fn keyword_lex_fn;
t_symbol keyword_capture_token;
t_scanner external_scanner;
const t_state_id *primary_state_ids;
} t_language;
#endif /* TYPES_LANGUAGE_H */

View file

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_lex_modes.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 15:01:24 by maiboyer #+# #+# */
/* Updated: 2024/04/29 15:01:31 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_LEX_MODES_H
# define TYPES_LEX_MODES_H
# include "me/types.h"
typedef struct s_lex_modes
{
t_u16 lex_state;
t_u16 external_lex_state;
} t_lex_modes;
#endif /* TYPES_LEX_MODES_H */

View file

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_lexer.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 14:45:45 by maiboyer #+# #+# */
/* Updated: 2024/04/29 14:46:48 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_LEXER_H
# define TYPES_LEXER_H
# include "me/types.h"
# include "parser/types/types_symbol.h"
typedef struct s_lexer
{
t_u32 lookahead;
t_symbol result_symbol;
void (*advance)(struct s_lexer *, bool);
void (*mark_end)(struct s_lexer *);
t_u32 (*get_column)(struct s_lexer *);
bool (*is_at_included_range_start)(const struct s_lexer *);
bool (*eof)(const struct s_lexer *);
} t_lexer;
#endif /* TYPES_LEXER_H */

View file

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_lexer_state.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 14:50:20 by maiboyer #+# #+# */
/* Updated: 2024/04/29 14:51:00 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_LEXER_STATE_H
# define TYPES_LEXER_STATE_H
# include "me/types.h"
# include "parser/types/types_state_id.h"
typedef struct s_lexer_state
{
t_u32 lookahead;
t_state_id state;
bool result;
bool skip;
bool eof;
} t_lexer_state;
#endif /* TYPES_LEXER_STATE_H */

View file

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_parse_action_entry.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 15:01:57 by maiboyer #+# #+# */
/* Updated: 2024/04/29 15:03:13 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_PARSE_ACTION_ENTRY_H
# define TYPES_PARSE_ACTION_ENTRY_H
# include "me/types.h"
# include "parser/types/types_parse_actions.h"
struct s_parse_actions_entry_entry
{
t_u8 count;
bool reusable;
};
typedef union u_parse_actions_entry
{
t_parse_actions action;
struct s_parse_actions_entry_entry entry;
} t_parse_action_entry;
#endif /* TYPES_PARSE_ACTION_ENTRY_H */

View file

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_parse_action_type.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 14:57:22 by maiboyer #+# #+# */
/* Updated: 2024/04/29 14:57:32 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_PARSE_ACTION_TYPE_H
# define TYPES_PARSE_ACTION_TYPE_H
typedef enum e_parse_action_type
{
ActionTypeShift,
ActionTypeReduce,
ActionTypeAccept,
ActionTypeRecover,
} t_parse_action_type;
#endif /* TYPES_PARSE_ACTION_TYPE_H */

View file

@ -0,0 +1,44 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_parse_actions.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 14:58:36 by maiboyer #+# #+# */
/* Updated: 2024/04/29 15:00:51 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_PARSE_ACTIONS_H
# define TYPES_PARSE_ACTIONS_H
# include "me/types.h"
# include "parser/types/types_state_id.h"
# include "parser/types/types_symbol.h"
struct s_parse_action_shift
{
t_u8 type;
t_state_id state;
bool extra;
bool repetition;
};
struct s_parse_action_reduce
{
t_u8 type;
t_u8 child_count;
t_symbol symbol;
t_i16 dynamic_precedence;
t_u16 production_id;
};
typedef union u_parse_actions
{
struct s_parse_action_shift shift;
struct s_parse_action_reduce reduce;
t_u8 type;
} t_parse_actions;
#endif /* TYPES_PARSE_ACTIONS_H */

View file

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_parser_node.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 14:36:46 by maiboyer #+# #+# */
/* Updated: 2024/04/29 14:37:36 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_PARSER_NODE_H
# define TYPES_PARSER_NODE_H
# include "me/types.h"
# include "parser/types/types_parser_tree.h"
typedef struct s_parser_node
{
t_u32 context[4];
const void *id;
const t_parser_tree *tree;
} t_parser_node;
#endif /* TYPES_PARSER_NODE_H */

View file

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_parser_range.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 14:11:26 by maiboyer #+# #+# */
/* Updated: 2024/04/29 14:25:11 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_PARSER_RANGE_H
# define TYPES_PARSER_RANGE_H
# include "me/types.h"
# include "parser/types/types_point.h"
typedef struct s_parser_range
{
t_point start_point;
t_point end_point;
t_u32 start_byte;
t_u32 end_byte;
} t_parser_range;
#endif /* TYPES_PARSER_RANGE_H */

View file

@ -0,0 +1,16 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_parser_subtree.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 14:49:40 by maiboyer #+# #+# */
/* Updated: 2024/04/29 14:49:40 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_PARSER_SUBTREE_H
# define TYPES_PARSER_SUBTREE_H
#endif /* TYPES_PARSER_SUBTREE_H */

View file

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_parser_tree.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 14:37:41 by maiboyer #+# #+# */
/* Updated: 2024/04/29 14:49:20 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_PARSER_TREE_H
# define TYPES_PARSER_TREE_H
# include "me/types.h"
# include "parser/types/types_language.h"
# include "parser/types/types_parser_range.h"
# include "parser/types/types_parser_subtree.h"
typedef struct s_parser_tree
{
t_parser_subtree root;
const t_language *language;
t_parser_range *included_ranges;
t_i32 included_range_count;
} t_parser_tree;
#endif /* TYPES_PARSER_TREE_H */

View file

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_point.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 14:20:34 by maiboyer #+# #+# */
/* Updated: 2024/04/29 14:21:16 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_POINT_H
# define TYPES_POINT_H
# include "me/types.h"
typedef struct s_point
{
t_u32 row;
t_u32 column;
} t_point;
#endif /* TYPES_POINT_H */

View file

@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_scanner.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 14:42:52 by maiboyer #+# #+# */
/* Updated: 2024/04/29 15:34:21 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_SCANNER_H
# define TYPES_SCANNER_H
# include "me/types.h"
# include "parser/types/types_lexer.h"
# include "parser/types/types_symbol.h"
typedef bool (*t_scanner_scan)(void *self, t_lexer *lex,
const bool *symbol_whitelist);
typedef void *(*t_scanner_create)(void);
typedef void (*t_scanner_destroy)(void *ctx);
typedef unsigned (*t_scanner_serialize)(void *self, t_str s);
typedef void (*t_scanner_deserialize)(void *self, t_const_str s,
t_u32 len);
typedef struct s_scanner
{
const bool *states;
const t_symbol *symbol_map;
t_scanner_create create;
t_scanner_destroy destroy;
t_scanner_scan scan;
t_scanner_serialize serialize;
t_scanner_deserialize deserialize;
} t_scanner;
#endif /* TYPES_SCANNER_H */

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_state_id.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 14:44:15 by maiboyer #+# #+# */
/* Updated: 2024/04/29 14:44:47 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_STATE_ID_H
# define TYPES_STATE_ID_H
# include "me/types.h"
typedef t_u16 t_state_id;
#endif /* TYPES_STATE_ID_H */

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_symbol.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 14:43:33 by maiboyer #+# #+# */
/* Updated: 2024/04/29 14:44:50 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_SYMBOL_H
# define TYPES_SYMBOL_H
# include "me/types.h"
typedef t_u16 t_symbol;
#endif /* TYPES_SYMBOL_H */

View file

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_symbol_metadata.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 14:55:57 by maiboyer #+# #+# */
/* Updated: 2024/04/29 14:56:04 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_SYMBOL_METADATA_H
# define TYPES_SYMBOL_METADATA_H
# include "me/types.h"
typedef struct s_symbol_metadata
{
bool visible;
bool named;
bool supertype;
} t_symbol_metadata;
#endif /* TYPES_SYMBOL_METADATA_H */

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/24 23:01:45 by maiboyer #+# #+# */
/* Updated: 2024/04/26 18:05:40 by maiboyer ### ########.fr */
/* Updated: 2024/04/29 15:26:51 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,34 +16,27 @@
#include <stdbool.h>
#include <stdint.h>
typedef uint16_t t_state_id;
typedef uint16_t t_symbol;
typedef uint16_t t_field_id;
typedef struct s_lexer t_lexer;
#define ts_builtin_sym_end 0
#define ts_builtin_sym_error -1
struct s_lexer
{
int32_t lookahead;
t_symbol result_symbol;
void (*advance)(t_lexer *, bool);
void (*mark_end)(t_lexer *);
uint32_t (*get_column)(t_lexer *);
bool (*is_at_included_range_start)(const t_lexer *);
bool (*eof)(const t_lexer *);
};
typedef struct s_lexer_state
{
int32_t lookahead;
t_state_id state;
bool result;
bool skip;
bool eof;
} t_lexer_state;
#include "me/types.h"
#include "parser/types/types_field_id.h"
#include "parser/types/types_field_map_entry.h"
#include "parser/types/types_field_map_slice.h"
#include "parser/types/types_language.h"
#include "parser/types/types_lex_modes.h"
#include "parser/types/types_lexer.h"
#include "parser/types/types_lexer_state.h"
#include "parser/types/types_parse_action_entry.h"
#include "parser/types/types_parse_action_type.h"
#include "parser/types/types_parse_actions.h"
#include "parser/types/types_parser_range.h"
#include "parser/types/types_point.h"
#include "parser/types/types_scanner.h"
#include "parser/types/types_state_id.h"
#include "parser/types/types_symbol.h"
#include "parser/types/types_symbol_metadata.h"
#include "parser/types/types_char_range.h"
static inline bool lex_skip(t_state_id state_value, t_lexer *lexer,
t_lexer_state *s)
@ -78,13 +71,6 @@ static inline bool lex_end_state(t_lexer *lexer, t_lexer_state *s)
return (false);
};
typedef struct
{
t_field_id field_id;
uint8_t child_index;
bool inherited;
} t_field_map_entry;
static inline t_field_map_entry fmap_entry(t_field_id field_id,
uint8_t child_index, bool inherited)
{
@ -95,13 +81,7 @@ static inline t_field_map_entry fmap_entry(t_field_id field_id,
});
};
typedef struct
{
uint16_t index;
uint16_t length;
} t_field_map_slice;
static inline t_field_map_slice fmap_slice(uint16_t index, uint16_t length)
static inline t_field_map_slice fmap_slice(t_u16 index, t_u16 length)
{
return ((t_field_map_slice){
.index = index,
@ -109,15 +89,8 @@ static inline t_field_map_slice fmap_slice(uint16_t index, uint16_t length)
});
};
typedef struct
{
bool visible;
bool named;
bool supertype;
} t_symbol_metadata;
static inline t_symbol_metadata sym_metadata(bool visible, bool named,
bool supertype)
bool supertype)
{
return ((t_symbol_metadata){
.visible = visible,
@ -126,48 +99,6 @@ static inline t_symbol_metadata sym_metadata(bool visible, bool named,
});
};
typedef enum
{
ActionTypeShift,
ActionTypeReduce,
ActionTypeAccept,
ActionTypeRecover,
} t_parse_action_type;
typedef union {
struct
{
uint8_t type;
t_state_id state;
bool extra;
bool repetition;
} shift;
struct
{
uint8_t type;
uint8_t child_count;
t_symbol symbol;
int16_t dynamic_precedence;
uint16_t production_id;
} reduce;
uint8_t type;
} t_parse_actions;
typedef struct
{
uint16_t lex_state;
uint16_t external_lex_state;
} t_lex_modes;
typedef union {
t_parse_actions action;
struct
{
uint8_t count;
bool reusable;
} entry;
} t_parse_action_entry;
static inline t_parse_action_entry entry(uint8_t count, bool reusable)
{
return ((t_parse_action_entry){
@ -198,7 +129,7 @@ static inline t_parse_action_entry shift_extra(void)
static inline t_parse_action_entry reduce(
t_symbol symbol, uint8_t child_count, int16_t dynamic_precedence,
uint16_t production_id)
t_u16 production_id)
{
return (
(t_parse_action_entry){{.reduce = {
@ -220,21 +151,15 @@ static inline t_parse_action_entry accept(void)
return ((t_parse_action_entry){{.type = ActionTypeAccept}});
};
typedef struct s_char_range
{
int32_t start;
int32_t end;
} t_char_range;
static inline bool set_contains(t_char_range *ranges, uint32_t len,
static inline bool set_contains(t_char_range *ranges, t_u32 len,
int32_t lookahead)
{
uint32_t index = 0;
uint32_t size = len - index;
t_u32 index = 0;
t_u32 size = len - index;
while (size > 1)
{
uint32_t half_size = size / 2;
uint32_t mid_index = index + half_size;
t_u32 half_size = size / 2;
t_u32 mid_index = index + half_size;
t_char_range *range = &ranges[mid_index];
if (lookahead >= range->start && lookahead <= range->end)
{
@ -250,16 +175,16 @@ static inline bool set_contains(t_char_range *ranges, uint32_t len,
return (lookahead >= range->start && lookahead <= range->end);
};
static inline bool advance_map_inner(uint32_t *map, uint32_t elems, t_lexer *l,
static inline bool advance_map_inner(t_u32 *map, t_u32 elems, t_lexer *l,
t_lexer_state *s)
{
uint32_t i;
t_u32 i;
(void)(l);
i = 0;
while (i < elems)
{
if (map[i] == (uint32_t)s->lookahead)
if (map[i] == (t_u32)s->lookahead)
{
s->state = map[i + 1];
return true;
@ -269,8 +194,8 @@ static inline bool advance_map_inner(uint32_t *map, uint32_t elems, t_lexer *l,
return (false);
};
static inline t_lex_modes lex_mode_external(uint16_t lex_state,
uint16_t ext_lex_state)
static inline t_lex_modes lex_mode_external(t_u16 lex_state,
t_u16 ext_lex_state)
{
return ((t_lex_modes){
.lex_state = lex_state,
@ -278,19 +203,19 @@ static inline t_lex_modes lex_mode_external(uint16_t lex_state,
});
};
static inline t_lex_modes lex_mode_normal(uint16_t lex_state)
static inline t_lex_modes lex_mode_normal(t_u16 lex_state)
{
return ((t_lex_modes){
.lex_state = lex_state,
});
};
static inline uint16_t actions(uint16_t val)
static inline t_u16 actions(t_u16 val)
{
return (val);
};
static inline uint16_t state(uint16_t val)
static inline t_u16 state(t_u16 val)
{
return (val);
};

View file

@ -1,5 +1,5 @@
#include "./language.h"
#include "api.h"
#include "parser/api.h"
#include <string.h>
const TSLanguage *ts_language_copy(const TSLanguage *self) {

View file

@ -4,11 +4,11 @@
#include <stdlib.h>
#include <stdbool.h>
#include "./point.h"
#include "api.h"
#include "parser/api.h"
typedef struct {
uint32_t bytes;
TSPoint extent;
t_point extent;
} Length;
static const Length LENGTH_UNDEFINED = {0, {0, 1}};

View file

@ -18,7 +18,7 @@
static const int32_t BYTE_ORDER_MARK = 0xFEFF;
static const TSRange DEFAULT_RANGE = {.start_point =
static const t_parser_range DEFAULT_RANGE = {.start_point =
{
.row = 0,
.column = 0,
@ -121,7 +121,7 @@ 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_parser_range *included_range = &self->included_ranges[i];
if (included_range->end_byte > self->current_position.bytes &&
included_range->end_byte > included_range->start_byte)
{
@ -159,7 +159,7 @@ static void ts_lexer_goto(Lexer *self, Length position)
else
{
self->current_included_range_index = self->included_range_count;
TSRange *last_included_range =
t_parser_range *last_included_range =
&self->included_ranges[self->included_range_count - 1];
self->current_position = (Length){
.bytes = last_included_range->end_byte,
@ -188,7 +188,7 @@ static void ts_lexer__do_advance(Lexer *self, bool skip)
}
}
const TSRange *current_range =
const t_parser_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)
@ -253,12 +253,12 @@ static void ts_lexer__mark_end(TSLexer *_self)
// 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_parser_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;
t_parser_range *previous_included_range = current_included_range - 1;
self->token_end_position = (Length){
previous_included_range->end_byte,
previous_included_range->end_point,
@ -308,7 +308,7 @@ static bool ts_lexer__is_at_included_range_start(const TSLexer *_self)
const Lexer *self = (const Lexer *)_self;
if (self->current_included_range_index < self->included_range_count)
{
TSRange *current_range =
t_parser_range *current_range =
&self->included_ranges[self->current_included_range_index];
return self->current_position.bytes == current_range->start_byte;
}
@ -434,12 +434,12 @@ void ts_lexer_mark_end(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(Lexer *self, const t_parser_range *ranges,
uint32_t count)
{
ranges = &DEFAULT_RANGE;
count = 1;
size_t size = count * sizeof(TSRange);
size_t size = count * sizeof(t_parser_range);
self->included_ranges = realloc(self->included_ranges, size);
memcpy(self->included_ranges, ranges, size);
self->included_range_count = count;
@ -447,7 +447,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_parser_range *ts_lexer_included_ranges(const Lexer *self, uint32_t *count)
{
*count = self->included_range_count;
return self->included_ranges;

View file

@ -7,7 +7,7 @@ extern "C" {
#include "./length.h"
#include "./subtree.h"
#include "api.h"
#include "parser/api.h"
#include "./parser.h"
typedef struct {
@ -16,7 +16,7 @@ typedef struct {
Length token_start_position;
Length token_end_position;
TSRange *included_ranges;
t_parser_range *included_ranges;
const char *chunk;
TSInput input;
TSLogger logger;
@ -39,8 +39,8 @@ 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);
bool ts_lexer_set_included_ranges(Lexer *self, const t_parser_range *ranges, uint32_t count);
t_parser_range *ts_lexer_included_ranges(const Lexer *self, uint32_t *count);
#ifdef __cplusplus
}

View file

@ -37,8 +37,8 @@ uint32_t ts_node_start_byte(TSNode self) {
return self.context[0];
}
TSPoint ts_node_start_point(TSNode self) {
return (TSPoint) {self.context[1], self.context[2]};
t_point ts_node_start_point(TSNode self) {
return (t_point) {self.context[1], self.context[2]};
}
static inline uint32_t ts_node__alias(const TSNode *self) {
@ -366,8 +366,8 @@ static inline TSNode ts_node__descendant_for_byte_range(
static inline TSNode ts_node__descendant_for_point_range(
TSNode self,
TSPoint range_start,
TSPoint range_end,
t_point range_start,
t_point range_end,
bool include_anonymous
) {
TSNode node = self;
@ -380,7 +380,7 @@ static inline TSNode ts_node__descendant_for_point_range(
TSNode 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.
@ -409,7 +409,7 @@ uint32_t ts_node_end_byte(TSNode 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(TSNode self) {
return point_add(ts_node_start_point(self), ts_subtree_size(ts_node__subtree(self)).extent);
}
@ -742,23 +742,23 @@ TSNode ts_node_named_descendant_for_byte_range(
TSNode ts_node_descendant_for_point_range(
TSNode self,
TSPoint start,
TSPoint end
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_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) {
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) {
start_byte = edit->new_end_byte + (start_byte - edit->old_end_byte);

View file

@ -1,5 +1,3 @@
#define _POSIX_C_SOURCE 200112L
#include "./array.h"
#include "./error_costs.h"
#include "./language.h"
@ -11,7 +9,7 @@
#include "./subtree.h"
#include "./tree.h"
#include "api.h"
#include "parser/api.h"
#include <assert.h>
#include <inttypes.h>
#include <limits.h>
@ -19,7 +17,8 @@
#include <stdio.h>
#include <time.h>
typedef Array(TSRange) ArrayRange;
#include "me/vec/vec_parser_range.h"
typedef uint64_t TSDuration;
typedef uint64_t TSClock;
@ -101,7 +100,7 @@ static const unsigned MAX_VERSION_COUNT = 6;
static const unsigned MAX_VERSION_COUNT_OVERFLOW = 4;
static const unsigned MAX_SUMMARY_DEPTH = 16;
static const unsigned MAX_COST_DIFFERENCE = 16 * ERROR_COST_PER_SKIPPED_TREE;
//static const unsigned OP_COUNT_PER_TIMEOUT_CHECK = 100;
// static const unsigned OP_COUNT_PER_TIMEOUT_CHECK = 100;
typedef struct
{
@ -132,7 +131,7 @@ struct TSParser
unsigned operation_count;
const volatile size_t *cancellation_flag;
Subtree old_tree;
ArrayRange included_range_differences;
t_vec_parser_range included_range_differences;
unsigned included_range_difference_index;
bool has_scanner_error;
};
@ -163,7 +162,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;
@ -1994,7 +1993,7 @@ TSParser *ts_parser_new(void)
self->end_clock = 0;
self->operation_count = 0;
self->old_tree = NULL_SUBTREE;
self->included_range_differences = (ArrayRange)array_new();
self->included_range_differences = vec_parser_range_new(0, NULL);
self->included_range_difference_index = 0;
ts_parser__set_cached_token(self, 0, NULL_SUBTREE, NULL_SUBTREE);
return self;
@ -2011,7 +2010,7 @@ void ts_parser_delete(TSParser *self)
{
array_delete(&self->reduce_actions);
}
if (self->included_range_differences.contents)
if (self->included_range_differences.buffer)
{
array_delete(&self->included_range_differences);
}
@ -2105,13 +2104,14 @@ void ts_parser_set_timeout_micros(TSParser *self, uint64_t timeout_micros)
self->timeout_duration = 0;
}
bool ts_parser_set_included_ranges(TSParser *self, const TSRange *ranges,
bool ts_parser_set_included_ranges(TSParser *self, const t_parser_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_parser_range *ts_parser_included_ranges(const TSParser *self,
uint32_t *count)
{
return ts_lexer_included_ranges(&self->lexer, count);
}
@ -2148,7 +2148,7 @@ TSTree *ts_parser_parse(TSParser *self, const TSTree *old_tree, TSInput input)
return NULL;
ts_lexer_set_input(&self->lexer, input);
array_clear(&self->included_range_differences);
self->included_range_differences.len = 0;
self->included_range_difference_index = 0;
if (ts_parser_has_outstanding_parse(self))
@ -2221,11 +2221,11 @@ TSTree *ts_parser_parse(TSParser *self, const TSTree *old_tree, TSInput input)
}
while (self->included_range_difference_index <
self->included_range_differences.size)
self->included_range_differences.len)
{
TSRange *range =
t_parser_range *range =
&self->included_range_differences
.contents[self->included_range_difference_index];
.buffer[self->included_range_difference_index];
if (range->end_byte <= position)
{
self->included_range_difference_index++;

View file

@ -1,58 +1,58 @@
#ifndef TREE_SITTER_POINT_H_
#define TREE_SITTER_POINT_H_
#include "api.h"
#include "parser/api.h"
#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})
static inline TSPoint point__new(unsigned row, unsigned column) {
TSPoint result = {row, column};
static inline t_point point__new(unsigned row, unsigned 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);
else
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);
else
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;
else
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;
else

View file

@ -6,7 +6,7 @@ extern "C" {
#endif
#include "./array.h"
#include "api.h"
#include "parser/api.h"
typedef struct {
uint32_t count;

View file

@ -12,7 +12,7 @@ extern "C" {
#include "./array.h"
#include "./error_costs.h"
#include "./host.h"
#include "api.h"
#include "parser/api.h"
#include "./parser.h"
#define TS_TREE_STATE_NONE USHRT_MAX

View file

@ -1,6 +1,6 @@
#define _POSIX_C_SOURCE 200112L
#include "api.h"
#include "parser/api.h"
#include "./array.h"
#include "./length.h"
@ -10,13 +10,13 @@
TSTree *ts_tree_new(
Subtree root, const TSLanguage *language,
const TSRange *included_ranges, unsigned included_range_count
const t_parser_range *included_ranges, unsigned included_range_count
) {
TSTree *result = malloc(sizeof(TSTree));
result->root = root;
result->language = ts_language_copy(language);
result->included_ranges = calloc(included_range_count, sizeof(TSRange));
memcpy(result->included_ranges, included_ranges, included_range_count * sizeof(TSRange));
result->included_ranges = calloc(included_range_count, sizeof(t_parser_range));
memcpy(result->included_ranges, included_ranges, included_range_count * sizeof(t_parser_range));
result->included_range_count = included_range_count;
return result;
}
@ -44,7 +44,7 @@ TSNode ts_tree_root_node(const TSTree *self) {
TSNode ts_tree_root_node_with_offset(
const TSTree *self,
uint32_t offset_bytes,
TSPoint offset_extent
t_point offset_extent
) {
Length offset = {offset_bytes, offset_extent};
return ts_node_new(self, &self->root, length_add(offset, ts_subtree_padding(self->root)), 0);
@ -56,7 +56,7 @@ const TSLanguage *ts_tree_language(const TSTree *self) {
void ts_tree_edit(TSTree *self, const TSInputEdit *edit) {
for (unsigned i = 0; i < self->included_range_count; i++) {
TSRange *range = &self->included_ranges[i];
t_parser_range *range = &self->included_ranges[i];
if (range->end_byte >= edit->old_end_byte) {
if (range->end_byte != UINT32_MAX) {
range->end_byte = edit->new_end_byte + (range->end_byte - edit->old_end_byte);
@ -94,10 +94,10 @@ void ts_tree_edit(TSTree *self, const TSInputEdit *edit) {
ts_subtree_pool_delete(&pool);
}
TSRange *ts_tree_included_ranges(const TSTree *self, uint32_t *length) {
t_parser_range *ts_tree_included_ranges(const TSTree *self, uint32_t *length) {
*length = self->included_range_count;
TSRange *ranges = calloc(self->included_range_count, sizeof(TSRange));
memcpy(ranges, self->included_ranges, self->included_range_count * sizeof(TSRange));
t_parser_range *ranges = calloc(self->included_range_count, sizeof(t_parser_range));
memcpy(ranges, self->included_ranges, self->included_range_count * sizeof(t_parser_range));
return ranges;
}

View file

@ -17,11 +17,11 @@ typedef struct {
struct TSTree {
Subtree root;
const TSLanguage *language;
TSRange *included_ranges;
t_parser_range *included_ranges;
unsigned included_range_count;
};
TSTree *ts_tree_new(Subtree root, const TSLanguage *language, const TSRange *, unsigned);
TSTree *ts_tree_new(Subtree root, const TSLanguage *language, const t_parser_range *, unsigned);
TSNode ts_node_new(const TSTree *, const Subtree *, Length, TSSymbol);
#ifdef __cplusplus

View file

@ -1,4 +1,4 @@
#include "api.h"
#include "parser/api.h"
#include "./tree_cursor.h"
#include "./language.h"
@ -259,7 +259,7 @@ 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_point goal_point
) {
TreeCursor *self = (TreeCursor *)_self;
uint32_t initial_size = self->stack.size;
@ -302,7 +302,7 @@ int64_t ts_tree_cursor_goto_first_child_for_byte(TSTreeCursor *self, uint32_t go
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(TSTreeCursor *self, t_point goal_point) {
return ts_tree_cursor_goto_first_child_for_byte_and_point(self, 0, goal_point);
}