WIP
This commit is contained in:
parent
54cefca53f
commit
019d25174c
24 changed files with 388 additions and 363 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/28 18:35:22 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/04/28 18:53:13 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/04/30 13:02:06 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# #
|
||||
# Updated: 2024/04/29 14:31:52 by maiboyer ### ########.fr #
|
||||
# Updated: 2024/04/30 13:35:56 by maiboyer ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ NAME = libgmr.a
|
|||
LIB_NAME ?=
|
||||
TARGET = $(BUILD_DIR)/$(NAME)
|
||||
CC = cc
|
||||
CFLAGS = -Wall -Wextra -Werror -g3 -MMD -I./includes -I../includes -I../output/include
|
||||
CFLAGS = -Wall -Wextra -Werror -MMD -I./includes -I../includes -I../output/include
|
||||
|
||||
include ./Filelist.mk
|
||||
|
||||
|
|
|
|||
|
|
@ -36,13 +36,13 @@ typedef struct s_parser t_parser;
|
|||
typedef struct t_parse_tree t_parse_tree;
|
||||
typedef struct t_query t_query;
|
||||
typedef struct t_query_cursor t_query_cursor;
|
||||
typedef struct TSLookaheadIterator TSLookaheadIterator;
|
||||
typedef struct t_lookahead_iterator t_lookahead_iterator;
|
||||
|
||||
typedef enum TSInputEncoding
|
||||
typedef enum t_input_encoding
|
||||
{
|
||||
TSInputEncodingUTF8,
|
||||
TSInputEncodingUTF16,
|
||||
} TSInputEncoding;
|
||||
InputEncoding8,
|
||||
InputEncoding16,
|
||||
} t_input_encoding;
|
||||
|
||||
typedef enum t_symbol_type
|
||||
{
|
||||
|
|
@ -51,25 +51,25 @@ typedef enum t_symbol_type
|
|||
SymbolTypeAuxiliary,
|
||||
} t_symbol_type;
|
||||
|
||||
typedef struct TSInput
|
||||
typedef struct t_parse_input
|
||||
{
|
||||
void *payload;
|
||||
const char *(*read)(void *payload, t_u32 byte_index, t_point position,
|
||||
t_u32 *bytes_read);
|
||||
TSInputEncoding encoding;
|
||||
} TSInput;
|
||||
t_input_encoding encoding;
|
||||
} t_parse_input;
|
||||
|
||||
typedef enum TSLogType
|
||||
typedef enum t_parse_log_type
|
||||
{
|
||||
TSLogTypeParse,
|
||||
TSLogTypeLex,
|
||||
} TSLogType;
|
||||
LogTypeParse,
|
||||
LogTypeLex,
|
||||
} t_parse_log_type;
|
||||
|
||||
typedef struct TSLogger
|
||||
typedef struct t_parse_logger
|
||||
{
|
||||
void *payload;
|
||||
void (*log)(void *payload, TSLogType log_type, const char *buffer);
|
||||
} TSLogger;
|
||||
void (*log)(void *payload, t_parse_log_type log_type, const char *buffer);
|
||||
} t_parse_logger;
|
||||
|
||||
typedef struct t_input_edit
|
||||
{
|
||||
|
|
@ -101,14 +101,14 @@ typedef struct t_queryCapture
|
|||
t_u32 index;
|
||||
} t_queryCapture;
|
||||
|
||||
typedef enum TSQuantifier
|
||||
typedef enum t_parse_quantifier
|
||||
{
|
||||
TSQuantifierZero = 0, // must match the array initialization value
|
||||
TSQuantifierZeroOrOne,
|
||||
TSQuantifierZeroOrMore,
|
||||
TSQuantifierOne,
|
||||
TSQuantifierOneOrMore,
|
||||
} TSQuantifier;
|
||||
ParseQuantifierZero = 0, // must match the array initialization value
|
||||
ParseQuantifierZeroOrOne,
|
||||
ParseQuantifierZeroOrMore,
|
||||
ParseQuantifierOne,
|
||||
ParseQuantifierOneOrMore,
|
||||
} t_parse_quantifier;
|
||||
|
||||
typedef struct t_query_match
|
||||
{
|
||||
|
|
@ -221,7 +221,7 @@ const t_parser_range *ts_parser_included_ranges(const t_parser *self,
|
|||
a
|
||||
* way that exactly matches the source code changes.
|
||||
*
|
||||
* The [`TSInput`] parameter lets you specify how to read the text. It has
|
||||
* The [`t_parse_input`] parameter lets you specify how to read the text. It has
|
||||
the
|
||||
* following three fields:
|
||||
* 1. [`read`]: A function to retrieve a chunk of text at a given byte
|
||||
|
|
@ -237,7 +237,7 @@ const t_parser_range *ts_parser_included_ranges(const t_parser *self,
|
|||
invocation
|
||||
* of the [`read`] function.
|
||||
* 3. [`encoding`]: An indication of how the text is encoded. Either
|
||||
* `TSInputEncodingUTF8` or `TSInputEncodingUTF16`.
|
||||
* `InputEncoding8` or `InputEncoding16`.
|
||||
*
|
||||
* This function returns a syntax tree on success, and `NULL` on failure.
|
||||
There
|
||||
|
|
@ -259,13 +259,13 @@ const t_parser_range *ts_parser_included_ranges(const t_parser *self,
|
|||
with
|
||||
* the same arguments.
|
||||
*
|
||||
* [`read`]: TSInput::read
|
||||
* [`payload`]: TSInput::payload
|
||||
* [`encoding`]: TSInput::encoding
|
||||
* [`bytes_read`]: TSInput::read
|
||||
* [`read`]: t_parse_input::read
|
||||
* [`payload`]: t_parse_input::payload
|
||||
* [`encoding`]: t_parse_input::encoding
|
||||
* [`bytes_read`]: t_parse_input::read
|
||||
*/
|
||||
t_parse_tree *ts_parser_parse(t_parser *self, const t_parse_tree *old_tree,
|
||||
TSInput input);
|
||||
t_parse_input input);
|
||||
|
||||
/**
|
||||
* Use the parser to parse some source code stored in one contiguous buffer.
|
||||
|
|
@ -286,7 +286,7 @@ t_parse_tree *ts_parser_parse_string(t_parser *self,
|
|||
t_parse_tree *ts_parser_parse_string_encoding(t_parser *self,
|
||||
const t_parse_tree *old_tree,
|
||||
const char *string, t_u32 length,
|
||||
TSInputEncoding encoding);
|
||||
t_input_encoding encoding);
|
||||
|
||||
/**
|
||||
* Instruct the parser to start the next parse from the beginning.
|
||||
|
|
@ -334,12 +334,12 @@ const size_t *ts_parser_cancellation_flag(const t_parser *self);
|
|||
* was previously assigned, the caller is responsible for releasing any
|
||||
* memory owned by the previous logger.
|
||||
*/
|
||||
void ts_parser_set_logger(t_parser *self, TSLogger logger);
|
||||
void ts_parser_set_logger(t_parser *self, t_parse_logger logger);
|
||||
|
||||
/**
|
||||
* Get the parser's current logger.
|
||||
*/
|
||||
TSLogger ts_parser_logger(const t_parser *self);
|
||||
t_parse_logger ts_parser_logger(const t_parser *self);
|
||||
|
||||
/**
|
||||
* Set the file descriptor to which the parser should write debugging graphs
|
||||
|
|
@ -888,7 +888,7 @@ const char *ts_query_capture_name_for_id(const t_query *self, t_u32 index,
|
|||
* with a numeric id based on the order that it appeared in the query's
|
||||
* source.
|
||||
*/
|
||||
TSQuantifier ts_query_capture_quantifier_for_id(const t_query *self,
|
||||
t_parse_quantifier ts_query_capture_quantifier_for_id(const t_query *self,
|
||||
t_u32 pattern_index,
|
||||
t_u32 capture_index);
|
||||
|
||||
|
|
@ -1110,13 +1110,13 @@ t_state_id ts_language_next_state(const t_language *self, t_state_id state,
|
|||
* lookahead iterator created on the previous non-extra leaf node may be
|
||||
* appropriate.
|
||||
*/
|
||||
TSLookaheadIterator *ts_lookahead_iterator_new(const t_language *self,
|
||||
t_lookahead_iterator *ts_lookahead_iterator_new(const t_language *self,
|
||||
t_state_id state);
|
||||
|
||||
/**
|
||||
* Delete a lookahead iterator freeing all the memory used.
|
||||
*/
|
||||
void ts_lookahead_iterator_delete(TSLookaheadIterator *self);
|
||||
void ts_lookahead_iterator_delete(t_lookahead_iterator *self);
|
||||
|
||||
/**
|
||||
* Reset the lookahead iterator to another state.
|
||||
|
|
@ -1124,7 +1124,7 @@ void ts_lookahead_iterator_delete(TSLookaheadIterator *self);
|
|||
* This returns `true` if the iterator was reset to the given state and
|
||||
* `false` otherwise.
|
||||
*/
|
||||
bool ts_lookahead_iterator_reset_state(TSLookaheadIterator *self,
|
||||
bool ts_lookahead_iterator_reset_state(t_lookahead_iterator *self,
|
||||
t_state_id state);
|
||||
|
||||
/**
|
||||
|
|
@ -1133,33 +1133,33 @@ bool ts_lookahead_iterator_reset_state(TSLookaheadIterator *self,
|
|||
* This returns `true` if the language was set successfully and `false`
|
||||
* otherwise.
|
||||
*/
|
||||
bool ts_lookahead_iterator_reset(TSLookaheadIterator *self,
|
||||
bool ts_lookahead_iterator_reset(t_lookahead_iterator *self,
|
||||
const t_language *language, t_state_id state);
|
||||
|
||||
/**
|
||||
* Get the current language of the lookahead iterator.
|
||||
*/
|
||||
const t_language *ts_lookahead_iterator_language(
|
||||
const TSLookaheadIterator *self);
|
||||
const t_lookahead_iterator *self);
|
||||
|
||||
/**
|
||||
* Advance the lookahead iterator to the next symbol.
|
||||
*
|
||||
* This returns `true` if there is a new symbol and `false` otherwise.
|
||||
*/
|
||||
bool ts_lookahead_iterator_next(TSLookaheadIterator *self);
|
||||
bool ts_lookahead_iterator_next(t_lookahead_iterator *self);
|
||||
|
||||
/**
|
||||
* Get the current symbol of the lookahead iterator;
|
||||
*/
|
||||
t_symbol ts_lookahead_iterator_current_symbol(const TSLookaheadIterator *self);
|
||||
t_symbol ts_lookahead_iterator_current_symbol(const t_lookahead_iterator *self);
|
||||
|
||||
/**
|
||||
* Get the current symbol type of the lookahead iterator as a null
|
||||
* terminated string.
|
||||
*/
|
||||
const char *ts_lookahead_iterator_current_symbol_name(
|
||||
const TSLookaheadIterator *self);
|
||||
const t_lookahead_iterator *self);
|
||||
|
||||
/**********************************/
|
||||
/* Section - Global Configuration */
|
||||
|
|
|
|||
64
parser/includes/parser_length.h
Normal file
64
parser/includes/parser_length.h
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
#ifndef TREE_SITTER_LENGTH_H_
|
||||
#define TREE_SITTER_LENGTH_H_
|
||||
|
||||
#include "../src/point.h"
|
||||
#include "parser/api.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct s_parse_length
|
||||
{
|
||||
t_u32 bytes;
|
||||
t_point extent;
|
||||
} t_parse_length;
|
||||
|
||||
static const t_parse_length LENGTH_UNDEFINED = {0, {0, 1}};
|
||||
static const t_parse_length LENGTH_MAX = {UINT32_MAX, {UINT32_MAX, UINT32_MAX}};
|
||||
|
||||
static inline bool length_is_undefined(t_parse_length length)
|
||||
{
|
||||
return (length.bytes == 0 && length.extent.column != 0);
|
||||
}
|
||||
|
||||
static inline t_parse_length length_min(t_parse_length len1,
|
||||
t_parse_length len2)
|
||||
{
|
||||
if (len1.bytes < len2.bytes)
|
||||
return (len1);
|
||||
else
|
||||
return (len2);
|
||||
}
|
||||
|
||||
static inline t_parse_length length_add(t_parse_length len1,
|
||||
t_parse_length len2)
|
||||
{
|
||||
t_parse_length result;
|
||||
result.bytes = len1.bytes + len2.bytes;
|
||||
result.extent = point_add(len1.extent, len2.extent);
|
||||
return (result);
|
||||
}
|
||||
|
||||
static inline t_parse_length length_sub(t_parse_length len1,
|
||||
t_parse_length len2)
|
||||
{
|
||||
t_parse_length result;
|
||||
result.bytes = len1.bytes - len2.bytes;
|
||||
result.extent = point_sub(len1.extent, len2.extent);
|
||||
return (result);
|
||||
}
|
||||
|
||||
static inline t_parse_length length_zero(void)
|
||||
{
|
||||
return ((t_parse_length){0, {0, 0}});
|
||||
}
|
||||
|
||||
static inline t_parse_length length_saturating_sub(t_parse_length len1,
|
||||
t_parse_length len2)
|
||||
{
|
||||
if (len1.bytes > len2.bytes)
|
||||
return (length_sub(len1, len2));
|
||||
else
|
||||
return (length_zero());
|
||||
}
|
||||
|
||||
#endif
|
||||
26
parser/includes/types/types_scanner_ctx.h
Normal file
26
parser/includes/types/types_scanner_ctx.h
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* types_scanner_ctx.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/30 13:41:02 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/04/30 13:41:29 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef TYPES_SCANNER_CTX_H
|
||||
#define TYPES_SCANNER_CTX_H
|
||||
|
||||
#include "me/types.h"
|
||||
|
||||
typedef struct s_scanner_ctx
|
||||
{
|
||||
t_u8 last_glob_paren_depth;
|
||||
bool ext_was_in_double_quote;
|
||||
bool ext_saw_outside_quote;
|
||||
// Array(t_heredoc) heredocs;
|
||||
} t_scanner_ctx;
|
||||
|
||||
#endif /* TYPES_SCANNER_CTX_H */
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
|
||||
// Determine endian and pointer size based on known defines.
|
||||
// TS_BIG_ENDIAN and TS_PTR_SIZE can be set as -D compiler arguments
|
||||
// to override this.
|
||||
|
||||
#if !defined(TS_BIG_ENDIAN)
|
||||
#if (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) \
|
||||
|| (defined( __APPLE_CC__) && (defined(__ppc__) || defined(__ppc64__)))
|
||||
#define TS_BIG_ENDIAN 1
|
||||
#else
|
||||
#define TS_BIG_ENDIAN 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(TS_PTR_SIZE)
|
||||
#if UINTPTR_MAX == 0xFFFFFFFF
|
||||
#define TS_PTR_SIZE 32
|
||||
#else
|
||||
#define TS_PTR_SIZE 64
|
||||
#endif
|
||||
#endif
|
||||
|
|
@ -169,47 +169,47 @@ t_field_id ts_language_field_id_for_name(
|
|||
return 0;
|
||||
}
|
||||
|
||||
TSLookaheadIterator *ts_lookahead_iterator_new(const t_language *self, t_state_id 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));
|
||||
*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, t_state_id state) {
|
||||
bool ts_lookahead_iterator_reset_state(t_lookahead_iterator * self, t_state_id state) {
|
||||
LookaheadIterator *iterator = (LookaheadIterator *)self;
|
||||
if (state >= iterator->language->state_count) return false;
|
||||
*iterator = ts_language_lookaheads(iterator->language, state);
|
||||
return true;
|
||||
}
|
||||
|
||||
const t_language *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;
|
||||
return iterator->language;
|
||||
}
|
||||
|
||||
bool ts_lookahead_iterator_reset(TSLookaheadIterator *self, const t_language *language, t_state_id 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;
|
||||
*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;
|
||||
return ts_lookahead_iterator__next(iterator);
|
||||
}
|
||||
|
||||
t_symbol 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;
|
||||
return iterator->symbol;
|
||||
}
|
||||
|
||||
const char *ts_lookahead_iterator_current_symbol_name(const TSLookaheadIterator *self) {
|
||||
const char *ts_lookahead_iterator_current_symbol_name(const t_lookahead_iterator *self) {
|
||||
const LookaheadIterator *iterator = (const LookaheadIterator *)self;
|
||||
return ts_language_symbol_name(iterator->language, iterator->symbol);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,52 +0,0 @@
|
|||
#ifndef TREE_SITTER_LENGTH_H_
|
||||
#define TREE_SITTER_LENGTH_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include "./point.h"
|
||||
#include "parser/api.h"
|
||||
|
||||
typedef struct {
|
||||
t_u32 bytes;
|
||||
t_point extent;
|
||||
} Length;
|
||||
|
||||
static const Length LENGTH_UNDEFINED = {0, {0, 1}};
|
||||
static const Length LENGTH_MAX = {UINT32_MAX, {UINT32_MAX, UINT32_MAX}};
|
||||
|
||||
static inline bool length_is_undefined(Length length) {
|
||||
return length.bytes == 0 && length.extent.column != 0;
|
||||
}
|
||||
|
||||
static inline Length length_min(Length len1, Length len2) {
|
||||
return (len1.bytes < len2.bytes) ? len1 : len2;
|
||||
}
|
||||
|
||||
static inline Length length_add(Length len1, Length len2) {
|
||||
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) {
|
||||
Length result;
|
||||
result.bytes = len1.bytes - len2.bytes;
|
||||
result.extent = point_sub(len1.extent, len2.extent);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline Length length_zero(void) {
|
||||
Length result = {0, {0, 0}};
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline Length length_saturating_sub(Length len1, Length len2) {
|
||||
if (len1.bytes > len2.bytes) {
|
||||
return length_sub(len1, len2);
|
||||
} else {
|
||||
return length_zero();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
#include "./lexer.h"
|
||||
#include "./length.h"
|
||||
#include "parser/parser_length.h"
|
||||
#include "./subtree.h"
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
|
@ -12,7 +12,7 @@
|
|||
" character:'%c'" \
|
||||
: message " character:%d", \
|
||||
character); \
|
||||
self->logger.log(self->logger.payload, TSLogTypeLex, \
|
||||
self->logger.log(self->logger.payload, LogTypeLex, \
|
||||
self->debug_buffer); \
|
||||
}
|
||||
|
||||
|
|
@ -113,7 +113,7 @@ static void ts_lexer__get_lookahead(t_liblexer *self)
|
|||
}
|
||||
}
|
||||
|
||||
static void ts_lexer_goto(t_liblexer *self, Length position)
|
||||
static void ts_lexer_goto(t_liblexer *self, t_parse_length position)
|
||||
{
|
||||
self->current_position = position;
|
||||
|
||||
|
|
@ -127,7 +127,7 @@ static void ts_lexer_goto(t_liblexer *self, Length position)
|
|||
{
|
||||
if (included_range->start_byte >= self->current_position.bytes)
|
||||
{
|
||||
self->current_position = (Length){
|
||||
self->current_position = (t_parse_length){
|
||||
.bytes = included_range->start_byte,
|
||||
.extent = included_range->start_point,
|
||||
};
|
||||
|
|
@ -161,7 +161,7 @@ static void ts_lexer_goto(t_liblexer *self, Length position)
|
|||
self->current_included_range_index = self->included_range_count;
|
||||
t_parser_range *last_included_range =
|
||||
&self->included_ranges[self->included_range_count - 1];
|
||||
self->current_position = (Length){
|
||||
self->current_position = (t_parse_length){
|
||||
.bytes = last_included_range->end_byte,
|
||||
.extent = last_included_range->end_point,
|
||||
};
|
||||
|
|
@ -200,7 +200,7 @@ static void ts_lexer__do_advance(t_liblexer *self, bool skip)
|
|||
if (self->current_included_range_index < self->included_range_count)
|
||||
{
|
||||
current_range++;
|
||||
self->current_position = (Length){
|
||||
self->current_position = (t_parse_length){
|
||||
current_range->start_byte,
|
||||
current_range->start_point,
|
||||
};
|
||||
|
|
@ -260,7 +260,7 @@ static void ts_lexer__mark_end(t_lexer *_self)
|
|||
{
|
||||
t_parser_range *previous_included_range =
|
||||
current_included_range - 1;
|
||||
self->token_end_position = (Length){
|
||||
self->token_end_position = (t_parse_length){
|
||||
previous_included_range->end_byte,
|
||||
previous_included_range->end_point,
|
||||
};
|
||||
|
|
@ -355,7 +355,7 @@ void ts_lexer_delete(t_liblexer *self)
|
|||
free(self->included_ranges);
|
||||
}
|
||||
|
||||
void ts_lexer_set_input(t_liblexer *self, TSInput input)
|
||||
void ts_lexer_set_input(t_liblexer *self, t_parse_input input)
|
||||
{
|
||||
self->input = input;
|
||||
ts_lexer__clear_chunk(self);
|
||||
|
|
@ -364,7 +364,7 @@ void ts_lexer_set_input(t_liblexer *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(t_liblexer *self, Length position)
|
||||
void ts_lexer_reset(t_liblexer *self, t_parse_length position)
|
||||
{
|
||||
if (position.bytes != self->current_position.bytes)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
#ifndef TREE_SITTER_LEXER_H_
|
||||
#define TREE_SITTER_LEXER_H_
|
||||
|
||||
#include "./length.h"
|
||||
#include "parser/parser_length.h"
|
||||
#include "./parser.h"
|
||||
#include "./subtree.h"
|
||||
#include "parser/api.h"
|
||||
|
|
@ -26,14 +26,14 @@
|
|||
typedef struct s_liblexer
|
||||
{
|
||||
t_lexer data;
|
||||
Length current_position;
|
||||
Length token_start_position;
|
||||
Length token_end_position;
|
||||
t_parse_length current_position;
|
||||
t_parse_length token_start_position;
|
||||
t_parse_length token_end_position;
|
||||
|
||||
t_parser_range *included_ranges;
|
||||
const char *chunk;
|
||||
TSInput input;
|
||||
TSLogger logger;
|
||||
t_parse_input input;
|
||||
t_parse_logger logger;
|
||||
|
||||
t_u32 included_range_count;
|
||||
t_u32 current_included_range_index;
|
||||
|
|
@ -47,8 +47,8 @@ typedef struct s_liblexer
|
|||
|
||||
void ts_lexer_init(t_liblexer *);
|
||||
void ts_lexer_delete(t_liblexer *);
|
||||
void ts_lexer_set_input(t_liblexer *, TSInput);
|
||||
void ts_lexer_reset(t_liblexer *, Length);
|
||||
void ts_lexer_set_input(t_liblexer *, t_parse_input);
|
||||
void ts_lexer_reset(t_liblexer *, t_parse_length);
|
||||
void ts_lexer_start(t_liblexer *);
|
||||
void ts_lexer_finish(t_liblexer *, t_i32 *);
|
||||
void ts_lexer_advance_to_end(t_liblexer *);
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ typedef struct
|
|||
{
|
||||
Subtree parent;
|
||||
const t_parse_tree *tree;
|
||||
Length position;
|
||||
t_parse_length position;
|
||||
t_u32 child_index;
|
||||
t_u32 structural_child_index;
|
||||
const t_symbol *alias_sequence;
|
||||
|
|
@ -16,7 +16,7 @@ typedef struct
|
|||
// t_parse_node - constructors
|
||||
|
||||
t_parse_node ts_node_new(const t_parse_tree *tree, const Subtree *subtree,
|
||||
Length position, t_symbol alias)
|
||||
t_parse_length position, t_symbol alias)
|
||||
{
|
||||
return (t_parse_node){
|
||||
{position.bytes, position.extent.row, position.extent.column, alias},
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#include "./array.h"
|
||||
#include "./error_costs.h"
|
||||
#include "./language.h"
|
||||
#include "./length.h"
|
||||
#include "parser/parser_length.h"
|
||||
#include "./lexer.h"
|
||||
#include "./reduce_action.h"
|
||||
#include "./reusable_node.h"
|
||||
|
|
@ -185,7 +185,7 @@ static void ts_parser__log(t_parser *self)
|
|||
{
|
||||
if (self->lexer.logger.log)
|
||||
{
|
||||
self->lexer.logger.log(self->lexer.logger.payload, TSLogTypeParse,
|
||||
self->lexer.logger.log(self->lexer.logger.payload, LogTypeParse,
|
||||
self->lexer.debug_buffer);
|
||||
}
|
||||
|
||||
|
|
@ -367,7 +367,7 @@ static bool ts_parser__better_version_exists(t_parser *self,
|
|||
return true;
|
||||
}
|
||||
|
||||
Length position = ts_stack_position(self->stack, version);
|
||||
t_parse_length position = ts_stack_position(self->stack, version);
|
||||
t_error_status status = {
|
||||
.cost = cost,
|
||||
.is_in_error = is_in_error,
|
||||
|
|
@ -506,7 +506,7 @@ static Subtree ts_parser__lex(t_parser *self, StackVersion version,
|
|||
return NULL_SUBTREE;
|
||||
}
|
||||
|
||||
const Length start_position = ts_stack_position(self->stack, version);
|
||||
const t_parse_length start_position = ts_stack_position(self->stack, version);
|
||||
const Subtree external_token =
|
||||
ts_stack_last_external_token(self->stack, version);
|
||||
|
||||
|
|
@ -515,8 +515,8 @@ static Subtree ts_parser__lex(t_parser *self, StackVersion version,
|
|||
bool skipped_error = false;
|
||||
bool called_get_column = false;
|
||||
t_i32 first_error_character = 0;
|
||||
Length error_start_position = length_zero();
|
||||
Length error_end_position = length_zero();
|
||||
t_parse_length error_start_position = length_zero();
|
||||
t_parse_length error_end_position = length_zero();
|
||||
t_i32 lookahead_end_byte = 0;
|
||||
t_i32 external_scanner_state_len = 0;
|
||||
bool external_scanner_state_changed = false;
|
||||
|
|
@ -525,7 +525,7 @@ static Subtree ts_parser__lex(t_parser *self, StackVersion version,
|
|||
for (;;)
|
||||
{
|
||||
bool found_token = false;
|
||||
Length current_position = self->lexer.current_position;
|
||||
t_parse_length current_position = self->lexer.current_position;
|
||||
|
||||
if (lex_mode.external_lex_state != 0)
|
||||
{
|
||||
|
|
@ -626,8 +626,8 @@ static Subtree ts_parser__lex(t_parser *self, StackVersion version,
|
|||
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_parse_length padding = length_sub(error_start_position, start_position);
|
||||
t_parse_length size = length_sub(error_end_position, error_start_position);
|
||||
t_u32 lookahead_bytes =
|
||||
lookahead_end_byte - error_end_position.bytes;
|
||||
result = ts_subtree_new_error(&self->tree_pool, first_error_character,
|
||||
|
|
@ -638,9 +638,9 @@ static Subtree ts_parser__lex(t_parser *self, StackVersion version,
|
|||
{
|
||||
bool is_keyword = false;
|
||||
t_symbol symbol = self->lexer.data.result_symbol;
|
||||
Length padding =
|
||||
t_parse_length padding =
|
||||
length_sub(self->lexer.token_start_position, start_position);
|
||||
Length size = length_sub(self->lexer.token_end_position,
|
||||
t_parse_length size = length_sub(self->lexer.token_end_position,
|
||||
self->lexer.token_start_position);
|
||||
t_u32 lookahead_bytes =
|
||||
lookahead_end_byte - self->lexer.token_end_position.bytes;
|
||||
|
|
@ -1300,7 +1300,7 @@ static void ts_parser__recover(t_parser *self, StackVersion version,
|
|||
{
|
||||
bool did_recover = false;
|
||||
unsigned previous_version_count = ts_stack_version_count(self->stack);
|
||||
Length position = ts_stack_position(self->stack, version);
|
||||
t_parse_length position = ts_stack_position(self->stack, version);
|
||||
StackSummary *summary = ts_stack_get_summary(self->stack, version);
|
||||
unsigned node_count_since_error =
|
||||
ts_stack_node_count_since_error(self->stack, version);
|
||||
|
|
@ -1515,7 +1515,7 @@ static void ts_parser__handle_error(t_parser *self, StackVersion version,
|
|||
// find a token that would have allowed a reduction to take place.
|
||||
ts_parser__do_all_potential_reductions(self, version, 0);
|
||||
t_u32 version_count = ts_stack_version_count(self->stack);
|
||||
Length position = ts_stack_position(self->stack, version);
|
||||
t_parse_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.
|
||||
|
|
@ -1547,7 +1547,7 @@ static void ts_parser__handle_error(t_parser *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_parse_length padding =
|
||||
length_sub(self->lexer.token_end_position, position);
|
||||
t_u32 lookahead_bytes =
|
||||
ts_subtree_total_bytes(lookahead) +
|
||||
|
|
@ -2053,12 +2053,12 @@ bool ts_parser_set_language(t_parser *self, const t_language *language)
|
|||
return true;
|
||||
}
|
||||
|
||||
TSLogger ts_parser_logger(const t_parser *self)
|
||||
t_parse_logger ts_parser_logger(const t_parser *self)
|
||||
{
|
||||
return self->lexer.logger;
|
||||
}
|
||||
|
||||
void ts_parser_set_logger(t_parser *self, TSLogger logger)
|
||||
void ts_parser_set_logger(t_parser *self, t_parse_logger logger)
|
||||
{
|
||||
self->lexer.logger = logger;
|
||||
}
|
||||
|
|
@ -2141,7 +2141,7 @@ void ts_parser_reset(t_parser *self)
|
|||
self->has_scanner_error = false;
|
||||
}
|
||||
|
||||
t_parse_tree *ts_parser_parse(t_parser *self, const t_parse_tree *old_tree, TSInput input)
|
||||
t_parse_tree *ts_parser_parse(t_parser *self, const t_parse_tree *old_tree, t_parse_input input)
|
||||
{
|
||||
t_parse_tree *result = NULL;
|
||||
old_tree = NULL;
|
||||
|
|
@ -2258,16 +2258,16 @@ t_parse_tree *ts_parser_parse_string(t_parser *self, const t_parse_tree *old_tre
|
|||
const char *string, t_u32 length)
|
||||
{
|
||||
return ts_parser_parse_string_encoding(self, old_tree, string, length,
|
||||
TSInputEncodingUTF8);
|
||||
InputEncoding8);
|
||||
}
|
||||
|
||||
t_parse_tree *ts_parser_parse_string_encoding(t_parser *self, const t_parse_tree *old_tree,
|
||||
const char *string, t_u32 length,
|
||||
TSInputEncoding encoding)
|
||||
t_input_encoding encoding)
|
||||
{
|
||||
t_string_input input = {string, length};
|
||||
return ts_parser_parse(self, old_tree,
|
||||
(TSInput){
|
||||
(t_parse_input){
|
||||
&input,
|
||||
ts_string_inpt_read,
|
||||
encoding,
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
#include "array.h"
|
||||
#include "parser.h"
|
||||
#include "parser/types/types_lexer.h"
|
||||
#include "parser/types/types_scanner.h"
|
||||
#include "parser/types/types_scanner_ctx.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <wctype.h>
|
||||
|
||||
#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
|
||||
|
||||
|
|
@ -65,14 +65,6 @@ static inline t_heredoc heredoc_new(void)
|
|||
});
|
||||
}
|
||||
|
||||
typedef struct s_scanner
|
||||
{
|
||||
t_u8 last_glob_paren_depth;
|
||||
bool ext_was_in_double_quote;
|
||||
bool ext_saw_outside_quote;
|
||||
Array(t_heredoc) heredocs;
|
||||
} t_scanner;
|
||||
|
||||
static inline void advance(t_lexer *lexer)
|
||||
{
|
||||
lexer->advance(lexer, false);
|
||||
|
|
@ -119,8 +111,8 @@ static inline void reset(t_scanner *scanner)
|
|||
|
||||
static unsigned serialize(t_scanner *scanner, char *buffer)
|
||||
{
|
||||
t_u32 size;
|
||||
t_u32 i;
|
||||
t_u32 size;
|
||||
t_u32 i;
|
||||
t_heredoc *heredoc;
|
||||
|
||||
size = 0;
|
||||
|
|
@ -153,10 +145,10 @@ static unsigned serialize(t_scanner *scanner, char *buffer)
|
|||
|
||||
static void deserialize(t_scanner *scanner, const char *buffer, unsigned length)
|
||||
{
|
||||
t_u32 size;
|
||||
t_u32 heredoc_count;
|
||||
t_u32 size;
|
||||
t_u32 heredoc_count;
|
||||
t_heredoc *heredoc;
|
||||
t_u32 i;
|
||||
t_u32 i;
|
||||
|
||||
size = 0;
|
||||
if (length == 0)
|
||||
|
|
@ -205,7 +197,7 @@ static void deserialize(t_scanner *scanner, const char *buffer, unsigned length)
|
|||
*/
|
||||
static bool advance_word(t_lexer *lexer, t_string *unquoted_word)
|
||||
{
|
||||
bool empty;
|
||||
bool empty;
|
||||
t_i32 quote;
|
||||
|
||||
quote = 0;
|
||||
|
|
@ -449,11 +441,11 @@ static bool regex_scan(t_scanner *scanner, t_lexer *lexer,
|
|||
{
|
||||
typedef struct
|
||||
{
|
||||
bool done;
|
||||
bool advanced_once;
|
||||
bool found_non_alnumdollarunderdash;
|
||||
bool last_was_escape;
|
||||
bool in_single_quote;
|
||||
bool done;
|
||||
bool advanced_once;
|
||||
bool found_non_alnumdollarunderdash;
|
||||
bool last_was_escape;
|
||||
bool in_single_quote;
|
||||
t_u32 paren_depth;
|
||||
t_u32 bracket_depth;
|
||||
t_u32 brace_depth;
|
||||
|
|
@ -793,8 +785,8 @@ static bool extglob_pattern_scan(t_scanner *scanner, t_lexer *lexer,
|
|||
|
||||
typedef struct
|
||||
{
|
||||
bool done;
|
||||
bool saw_non_alphadot;
|
||||
bool done;
|
||||
bool saw_non_alphadot;
|
||||
t_u32 paren_depth;
|
||||
t_u32 bracket_depth;
|
||||
t_u32 brace_depth;
|
||||
|
|
@ -1027,7 +1019,7 @@ static bool expansion_word_scan(t_scanner *scanner, t_lexer *lexer,
|
|||
advance(lexer);
|
||||
}
|
||||
}
|
||||
return (false);
|
||||
return (false);
|
||||
}
|
||||
|
||||
static bool brace_start_scan(t_scanner *scanner, t_lexer *lexer,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
#include "./subtree.h"
|
||||
#include "./array.h"
|
||||
#include "./stack.h"
|
||||
#include "./length.h"
|
||||
#include "parser/parser_length.h"
|
||||
#include <assert.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
|
|
@ -28,7 +28,7 @@ typedef struct {
|
|||
|
||||
struct StackNode {
|
||||
t_state_id state;
|
||||
Length position;
|
||||
t_parse_length position;
|
||||
StackLink links[MAX_LINK_COUNT];
|
||||
short unsigned int link_count;
|
||||
t_u32 ref_count;
|
||||
|
|
@ -464,7 +464,7 @@ t_state_id ts_stack_state(const Stack *self, StackVersion version) {
|
|||
return array_get(&self->heads, version)->node->state;
|
||||
}
|
||||
|
||||
Length ts_stack_position(const Stack *self, StackVersion version) {
|
||||
t_parse_length ts_stack_position(const Stack *self, StackVersion version) {
|
||||
return array_get(&self->heads, version)->node->position;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ typedef struct {
|
|||
typedef Array(StackSlice) StackSliceArray;
|
||||
|
||||
typedef struct {
|
||||
Length position;
|
||||
t_parse_length position;
|
||||
unsigned depth;
|
||||
t_state_id state;
|
||||
} StackSummaryEntry;
|
||||
|
|
@ -48,7 +48,7 @@ Subtree ts_stack_last_external_token(const Stack *, StackVersion);
|
|||
void ts_stack_set_last_external_token(Stack *, StackVersion, Subtree );
|
||||
|
||||
// Get the position of the given version of the stack within the document.
|
||||
Length ts_stack_position(const Stack *, StackVersion);
|
||||
t_parse_length ts_stack_position(const Stack *, StackVersion);
|
||||
|
||||
// Push a tree and state onto the given version of the stack.
|
||||
//
|
||||
|
|
|
|||
|
|
@ -9,15 +9,15 @@
|
|||
|
||||
#include "./error_costs.h"
|
||||
#include "./language.h"
|
||||
#include "./length.h"
|
||||
#include "parser/parser_length.h"
|
||||
#include "./subtree.h"
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Length start;
|
||||
Length old_end;
|
||||
Length new_end;
|
||||
t_parse_length start;
|
||||
t_parse_length old_end;
|
||||
t_parse_length new_end;
|
||||
} Edit;
|
||||
|
||||
#define TS_MAX_INLINE_TREE_LENGTH UINT8_MAX
|
||||
|
|
@ -193,7 +193,7 @@ static void ts_subtree_pool_free(SubtreePool *self, SubtreeHeapData *tree)
|
|||
|
||||
// Subtree
|
||||
|
||||
static inline bool ts_subtree_can_inline(Length padding, Length size,
|
||||
static inline bool ts_subtree_can_inline(t_parse_length padding, t_parse_length size,
|
||||
t_u32 lookahead_bytes)
|
||||
{
|
||||
return padding.bytes < TS_MAX_INLINE_TREE_LENGTH &&
|
||||
|
|
@ -204,8 +204,8 @@ static inline bool ts_subtree_can_inline(Length padding, Length size,
|
|||
lookahead_bytes < 16;
|
||||
}
|
||||
|
||||
Subtree ts_subtree_new_leaf(SubtreePool *pool, t_symbol symbol, Length padding,
|
||||
Length size, t_u32 lookahead_bytes,
|
||||
Subtree ts_subtree_new_leaf(SubtreePool *pool, t_symbol symbol, t_parse_length padding,
|
||||
t_parse_length size, t_u32 lookahead_bytes,
|
||||
t_state_id parse_state, bool has_external_tokens,
|
||||
bool depends_on_column, bool is_keyword,
|
||||
const t_language *language)
|
||||
|
|
@ -283,7 +283,7 @@ void ts_subtree_set_symbol(MutableSubtree *self, t_symbol symbol,
|
|||
}
|
||||
|
||||
Subtree ts_subtree_new_error(SubtreePool *pool, t_i32 lookahead_char,
|
||||
Length padding, Length size,
|
||||
t_parse_length padding, t_parse_length size,
|
||||
t_u32 bytes_scanned, t_state_id parse_state,
|
||||
const t_language *language)
|
||||
{
|
||||
|
|
@ -654,7 +654,7 @@ 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, t_symbol symbol,
|
||||
Length padding, t_u32 lookahead_bytes,
|
||||
t_parse_length padding, t_u32 lookahead_bytes,
|
||||
const t_language *language)
|
||||
{
|
||||
Subtree result =
|
||||
|
|
@ -807,9 +807,9 @@ Subtree ts_subtree_edit(Subtree self, const t_input_edit *inpt_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_parse_length size = ts_subtree_size(*entry.tree);
|
||||
t_parse_length padding = ts_subtree_padding(*entry.tree);
|
||||
t_parse_length total_size = length_add(padding, size);
|
||||
t_u32 lookahead_bytes = ts_subtree_lookahead_bytes(*entry.tree);
|
||||
t_u32 end_byte = total_size.bytes + lookahead_bytes;
|
||||
if (edit.start.bytes > end_byte ||
|
||||
|
|
@ -895,12 +895,12 @@ Subtree ts_subtree_edit(Subtree self, const t_input_edit *inpt_edit,
|
|||
ts_subtree_set_has_changes(&result);
|
||||
*entry.tree = ts_subtree_from_mut(result);
|
||||
|
||||
Length child_left, child_right = length_zero();
|
||||
t_parse_length child_left, child_right = length_zero();
|
||||
for (t_u32 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_parse_length child_size = ts_subtree_total_size(*child);
|
||||
child_left = child_right;
|
||||
child_right = length_add(child_left, child_size);
|
||||
|
||||
|
|
|
|||
|
|
@ -6,8 +6,7 @@
|
|||
|
||||
#include "./array.h"
|
||||
#include "./error_costs.h"
|
||||
#include "./host.h"
|
||||
#include "./length.h"
|
||||
#include "parser/parser_length.h"
|
||||
#include "./parser.h"
|
||||
#include "parser/api.h"
|
||||
#include <limits.h>
|
||||
|
|
@ -75,8 +74,8 @@ struct s_subtree_inline_data
|
|||
typedef struct
|
||||
{
|
||||
volatile t_u32 ref_count;
|
||||
Length padding;
|
||||
Length size;
|
||||
t_parse_length padding;
|
||||
t_parse_length size;
|
||||
t_u32 lookahead_bytes;
|
||||
t_u32 error_cost;
|
||||
t_u32 child_count;
|
||||
|
|
@ -159,14 +158,14 @@ void ts_subtree_array_reverse(SubtreeArray *);
|
|||
SubtreePool ts_subtree_pool_new(t_u32 capacity);
|
||||
void ts_subtree_pool_delete(SubtreePool *);
|
||||
|
||||
Subtree ts_subtree_new_leaf(SubtreePool *, t_symbol, Length, Length, t_u32,
|
||||
Subtree ts_subtree_new_leaf(SubtreePool *, t_symbol, t_parse_length, t_parse_length, t_u32,
|
||||
t_state_id, bool, bool, bool, const t_language *);
|
||||
Subtree ts_subtree_new_error(SubtreePool *, t_i32, Length, Length, t_u32,
|
||||
Subtree ts_subtree_new_error(SubtreePool *, t_i32, t_parse_length, t_parse_length, t_u32,
|
||||
t_state_id, const t_language *);
|
||||
MutableSubtree ts_subtree_new_node(t_symbol, SubtreeArray *, unsigned,
|
||||
const t_language *);
|
||||
Subtree ts_subtree_new_error_node(SubtreeArray *, bool, const t_language *);
|
||||
Subtree ts_subtree_new_missing_leaf(SubtreePool *, t_symbol, Length, t_u32,
|
||||
Subtree ts_subtree_new_missing_leaf(SubtreePool *, t_symbol, t_parse_length, t_u32,
|
||||
const t_language *);
|
||||
MutableSubtree ts_subtree_make_mut(SubtreePool *, Subtree);
|
||||
void ts_subtree_retain(Subtree);
|
||||
|
|
@ -271,11 +270,11 @@ static inline t_state_id 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_parse_length ts_subtree_padding(Subtree self)
|
||||
{
|
||||
if (self.data.is_inline)
|
||||
{
|
||||
Length result = {self.data.padding_bytes,
|
||||
t_parse_length result = {self.data.padding_bytes,
|
||||
{self.data.padding_rows, self.data.padding_columns}};
|
||||
return result;
|
||||
}
|
||||
|
|
@ -285,11 +284,11 @@ static inline Length ts_subtree_padding(Subtree self)
|
|||
}
|
||||
}
|
||||
|
||||
static inline Length ts_subtree_size(Subtree self)
|
||||
static inline t_parse_length ts_subtree_size(Subtree self)
|
||||
{
|
||||
if (self.data.is_inline)
|
||||
{
|
||||
Length result = {self.data.size_bytes, {0, self.data.size_bytes}};
|
||||
t_parse_length result = {self.data.size_bytes, {0, self.data.size_bytes}};
|
||||
return result;
|
||||
}
|
||||
else
|
||||
|
|
@ -298,7 +297,7 @@ static inline Length ts_subtree_size(Subtree self)
|
|||
}
|
||||
}
|
||||
|
||||
static inline Length ts_subtree_total_size(Subtree self)
|
||||
static inline t_parse_length ts_subtree_total_size(Subtree self)
|
||||
{
|
||||
return length_add(ts_subtree_padding(self), ts_subtree_size(self));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
#include "parser/api.h"
|
||||
#include "./array.h"
|
||||
|
||||
#include "./length.h"
|
||||
#include "parser/parser_length.h"
|
||||
#include "./subtree.h"
|
||||
#include "./tree_cursor.h"
|
||||
#include "./tree.h"
|
||||
|
|
@ -46,7 +46,7 @@ t_parse_node ts_tree_root_node_with_offset(
|
|||
t_u32 offset_bytes,
|
||||
t_point offset_extent
|
||||
) {
|
||||
Length offset = {offset_bytes, offset_extent};
|
||||
t_parse_length offset = {offset_bytes, offset_extent};
|
||||
return ts_node_new(self, &self->root, length_add(offset, ts_subtree_padding(self->root)), 0);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ extern "C" {
|
|||
typedef struct {
|
||||
const Subtree *child;
|
||||
const Subtree *parent;
|
||||
Length position;
|
||||
t_parse_length position;
|
||||
t_symbol alias_symbol;
|
||||
} ParentCacheEntry;
|
||||
|
||||
|
|
@ -22,7 +22,7 @@ struct t_parse_tree {
|
|||
};
|
||||
|
||||
t_parse_tree *ts_tree_new(Subtree root, const t_language *language, const t_parser_range *, unsigned);
|
||||
t_parse_node ts_node_new(const t_parse_tree *, const Subtree *, Length, t_symbol);
|
||||
t_parse_node ts_node_new(const t_parse_tree *, const Subtree *, t_parse_length, t_symbol);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
typedef struct {
|
||||
Subtree parent;
|
||||
const t_parse_tree *tree;
|
||||
Length position;
|
||||
t_parse_length position;
|
||||
t_u32 child_index;
|
||||
t_u32 structural_child_index;
|
||||
t_u32 descendant_index;
|
||||
|
|
@ -101,12 +101,12 @@ static inline bool ts_tree_cursor_child_iterator_next(
|
|||
// 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_parse_length length_backtrack(t_parse_length a, t_parse_length b) {
|
||||
if (length_is_undefined(a) || b.extent.row != 0) {
|
||||
return LENGTH_UNDEFINED;
|
||||
}
|
||||
|
||||
Length result;
|
||||
t_parse_length result;
|
||||
result.bytes = a.bytes - b.bytes;
|
||||
result.extent.row = a.extent.row;
|
||||
result.extent.column = a.extent.column - b.extent.column;
|
||||
|
|
@ -141,7 +141,7 @@ 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 = ts_subtree_children(self->parent)[self->child_index];
|
||||
Length size = ts_subtree_size(previous_child);
|
||||
t_parse_length size = ts_subtree_size(previous_child);
|
||||
self->position = length_backtrack(self->position, size);
|
||||
}
|
||||
|
||||
|
|
@ -273,7 +273,7 @@ static inline t_i64 ts_tree_cursor_goto_first_child_for_byte_and_point(
|
|||
TreeCursorEntry entry;
|
||||
CursorChildIterator iterator = ts_tree_cursor_iterate_children(self);
|
||||
while (ts_tree_cursor_child_iterator_next(&iterator, &entry, &visible)) {
|
||||
Length entry_end = length_add(entry.position, ts_subtree_size(*entry.subtree));
|
||||
t_parse_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);
|
||||
t_u32 visible_child_count = ts_subtree_visible_child_count(*entry.subtree);
|
||||
if (at_goal) {
|
||||
|
|
@ -374,7 +374,7 @@ TreeCursorStep ts_tree_cursor_goto_previous_sibling_internal(t_parse_tree_cursor
|
|||
|
||||
// restore position from the parent node
|
||||
const TreeCursorEntry *parent = &self->stack.contents[self->stack.size - 2];
|
||||
Length position = parent->position;
|
||||
t_parse_length position = parent->position;
|
||||
t_u32 child_index = array_back(&self->stack)->child_index;
|
||||
const Subtree *children = ts_subtree_children((*(parent->subtree)));
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
typedef struct {
|
||||
const Subtree *subtree;
|
||||
Length position;
|
||||
t_parse_length position;
|
||||
t_u32 child_index;
|
||||
t_u32 structural_child_index;
|
||||
t_u32 descendant_index;
|
||||
|
|
|
|||
267
sources/main.c
267
sources/main.c
|
|
@ -6,105 +6,113 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */
|
||||
/* Updated: 2024/04/29 13:29:01 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/04/30 13:02:39 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/minishell.h"
|
||||
|
||||
t_i32 ft_check_type_operators(t_str operators) {
|
||||
if (operators == NULL)
|
||||
printf("End of input");
|
||||
else if (ft_strcmp(operators, ">") == 0)
|
||||
printf("Have to redirect in the file\n");
|
||||
else if (ft_strcmp(operators, ">>") == 0)
|
||||
printf("Have to redirect at the end of the file after\n");
|
||||
else if (ft_strcmp(operators, ">&") == 0)
|
||||
printf("Have to redirect the stdout in the file\n");
|
||||
else if (ft_strcmp(operators, "<") == 0)
|
||||
printf("Have to redirect at the end of the file before\n");
|
||||
else if (ft_strcmp(operators, "<<") == 0)
|
||||
printf("Have to redirect at the end of the file after\n");
|
||||
else if (ft_strcmp(operators, "<&") == 0)
|
||||
printf("Have to redirect the stdout in the file\n");
|
||||
else if (ft_strcmp(operators, ";") == 0)
|
||||
printf("Have to execute one more command\n");
|
||||
else if (ft_strcmp(operators, ";") == 0)
|
||||
printf("Have to execute one more command\n");
|
||||
else if (ft_strcmp(operators, "|") == 0)
|
||||
printf("I have to pipe a operators !\n");
|
||||
else if (ft_strcmp(operators, "||") == 0)
|
||||
printf("Or something\n");
|
||||
else if (ft_strcmp(operators, "&&") == 0)
|
||||
printf("Only if the first has exit status 0\n");
|
||||
else if (ft_strcmp(operators, "&") == 0)
|
||||
printf("Parreil mais chelou\n");
|
||||
else
|
||||
return (0);
|
||||
return (1);
|
||||
t_i32 ft_check_type_operators(t_str operators)
|
||||
{
|
||||
if (operators == NULL)
|
||||
printf("End of input");
|
||||
else if (ft_strcmp(operators, ">") == 0)
|
||||
printf("Have to redirect in the file\n");
|
||||
else if (ft_strcmp(operators, ">>") == 0)
|
||||
printf("Have to redirect at the end of the file after\n");
|
||||
else if (ft_strcmp(operators, ">&") == 0)
|
||||
printf("Have to redirect the stdout in the file\n");
|
||||
else if (ft_strcmp(operators, "<") == 0)
|
||||
printf("Have to redirect at the end of the file before\n");
|
||||
else if (ft_strcmp(operators, "<<") == 0)
|
||||
printf("Have to redirect at the end of the file after\n");
|
||||
else if (ft_strcmp(operators, "<&") == 0)
|
||||
printf("Have to redirect the stdout in the file\n");
|
||||
else if (ft_strcmp(operators, ";") == 0)
|
||||
printf("Have to execute one more command\n");
|
||||
else if (ft_strcmp(operators, ";") == 0)
|
||||
printf("Have to execute one more command\n");
|
||||
else if (ft_strcmp(operators, "|") == 0)
|
||||
printf("I have to pipe a operators !\n");
|
||||
else if (ft_strcmp(operators, "||") == 0)
|
||||
printf("Or something\n");
|
||||
else if (ft_strcmp(operators, "&&") == 0)
|
||||
printf("Only if the first has exit status 0\n");
|
||||
else if (ft_strcmp(operators, "&") == 0)
|
||||
printf("Parreil mais chelou\n");
|
||||
else
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
|
||||
void ft_check(t_utils *shcat, char **input) {
|
||||
t_usize i;
|
||||
t_usize prev_i;
|
||||
void ft_check(t_utils *shcat, char **input)
|
||||
{
|
||||
t_usize i;
|
||||
t_usize prev_i;
|
||||
|
||||
i = 0;
|
||||
prev_i = 0;
|
||||
while (input[i] != NULL) {
|
||||
while (ft_check_type_operators(input[i]) == 1)
|
||||
i++;
|
||||
if (ft_strcmp(input[i], "exit") == 0)
|
||||
ft_exit(shcat, 0);
|
||||
else if (ft_strcmp(input[i], "pwd") == 0)
|
||||
ft_pwd();
|
||||
else if (ft_strcmp(input[i], "echo") == 0)
|
||||
ft_echo("ECHO MAIS PAS ARG BORDEL !\n", "flag");
|
||||
else
|
||||
ft_other_cmd(shcat, i, prev_i);
|
||||
prev_i = i;
|
||||
i++;
|
||||
}
|
||||
i = 0;
|
||||
prev_i = 0;
|
||||
while (input[i] != NULL)
|
||||
{
|
||||
while (ft_check_type_operators(input[i]) == 1)
|
||||
i++;
|
||||
if (ft_strcmp(input[i], "exit") == 0)
|
||||
ft_exit(shcat, 0);
|
||||
else if (ft_strcmp(input[i], "pwd") == 0)
|
||||
ft_pwd();
|
||||
else if (ft_strcmp(input[i], "echo") == 0)
|
||||
ft_echo("ECHO MAIS PAS ARG BORDEL !\n", "flag");
|
||||
else
|
||||
ft_other_cmd(shcat, i, prev_i);
|
||||
prev_i = i;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void ft_take_args(t_utils *shcat) {
|
||||
t_i32 i;
|
||||
void ft_take_args(t_utils *shcat)
|
||||
{
|
||||
t_i32 i;
|
||||
|
||||
i = 0;
|
||||
while (1) {
|
||||
shcat->str_input = readline((t_const_str)shcat->name_shell);
|
||||
if (!shcat->str_input)
|
||||
ft_exit(shcat, 0);
|
||||
shcat->strs_input = ft_split(shcat->str_input, ' ');
|
||||
if (!shcat->strs_input)
|
||||
exit(1);
|
||||
ft_check(shcat, shcat->strs_input);
|
||||
add_history(shcat->str_input);
|
||||
ft_free_strs(shcat->strs_input);
|
||||
free(shcat->str_input);
|
||||
i++;
|
||||
}
|
||||
i = 0;
|
||||
while (1)
|
||||
{
|
||||
shcat->str_input = readline((t_const_str)shcat->name_shell);
|
||||
if (!shcat->str_input)
|
||||
ft_exit(shcat, 0);
|
||||
shcat->strs_input = ft_split(shcat->str_input, ' ');
|
||||
if (!shcat->strs_input)
|
||||
exit(1);
|
||||
ft_check(shcat, shcat->strs_input);
|
||||
add_history(shcat->str_input);
|
||||
ft_free_strs(shcat->strs_input);
|
||||
free(shcat->str_input);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void ft_init_arge(t_str arge[], t_utils *utils) {
|
||||
size_t i;
|
||||
char *temp;
|
||||
void ft_init_arge(t_str arge[], t_utils *utils)
|
||||
{
|
||||
size_t i;
|
||||
char *temp;
|
||||
|
||||
i = 0;
|
||||
temp = NULL;
|
||||
while (arge[i] != NULL) {
|
||||
if (arge[i][0] == 'P' && arge[i][1] == 'A' && arge[i][2] == 'T' &&
|
||||
arge[i][3] == 'H' && arge[i][4] == '=') {
|
||||
temp = ft_strdup(arge[i] + 5);
|
||||
if (!temp)
|
||||
ft_exit(utils, 1);
|
||||
else
|
||||
utils->path = ft_split(temp, ':');
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (temp != NULL)
|
||||
free(temp);
|
||||
i = 0;
|
||||
temp = NULL;
|
||||
while (arge[i] != NULL)
|
||||
{
|
||||
if (arge[i][0] == 'P' && arge[i][1] == 'A' && arge[i][2] == 'T' &&
|
||||
arge[i][3] == 'H' && arge[i][4] == '=')
|
||||
{
|
||||
temp = ft_strdup(arge[i] + 5);
|
||||
if (!temp)
|
||||
ft_exit(utils, 1);
|
||||
else
|
||||
utils->path = ft_split(temp, ':');
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (temp != NULL)
|
||||
free(temp);
|
||||
}
|
||||
|
||||
#include "app/node.h"
|
||||
|
|
@ -112,58 +120,67 @@ void ft_init_arge(t_str arge[], t_utils *utils) {
|
|||
#include "parser/api.h"
|
||||
#include "parser/parser.h"
|
||||
|
||||
TSLanguage *tree_sitter_bash(void);
|
||||
t_language *tree_sitter_bash(void);
|
||||
|
||||
t_node parse_to_nodes(TSParser *parser, t_const_str input) {
|
||||
TSTree *tree;
|
||||
TSNode node;
|
||||
t_node ret;
|
||||
t_node parse_to_nodes(t_parser *parser, t_const_str input)
|
||||
{
|
||||
t_parse_tree *tree;
|
||||
t_parse_node node;
|
||||
t_node ret;
|
||||
|
||||
tree = ts_parser_parse_string(parser, NULL, input, str_len(input));
|
||||
node = ts_tree_root_node(tree);
|
||||
ret = build_node(node, input);
|
||||
ts_tree_delete(tree);
|
||||
return (ret);
|
||||
tree = ts_parser_parse_string(parser, NULL, input, str_len(input));
|
||||
node = ts_tree_root_node(tree);
|
||||
ret = build_node(node, input);
|
||||
ts_tree_delete(tree);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
void print_node_data(t_node *t, t_usize depth) {
|
||||
t_usize idx;
|
||||
void print_node_data(t_node *t, t_usize depth)
|
||||
{
|
||||
t_usize idx;
|
||||
|
||||
idx = 0;
|
||||
while (idx++ < depth)
|
||||
printf("\t");
|
||||
idx = 0;
|
||||
printf("%s = %s\n", t->kind_str, node_getstr(t));
|
||||
while (idx < t->childs_count)
|
||||
print_node_data(&t->childs[idx++], depth + 1);
|
||||
idx = 0;
|
||||
while (idx++ < depth)
|
||||
printf("\t");
|
||||
idx = 0;
|
||||
printf("%s = %s\n", t->kind_str, node_getstr(t));
|
||||
while (idx < t->childs_count)
|
||||
print_node_data(&t->childs[idx++], depth + 1);
|
||||
}
|
||||
|
||||
typedef struct s_myparser {
|
||||
TSParser *parser;
|
||||
typedef struct s_myparser
|
||||
{
|
||||
t_parser *parser;
|
||||
} t_myparser;
|
||||
|
||||
t_myparser create_myparser(void) {
|
||||
TSLanguage *lang;
|
||||
TSParser *parser;
|
||||
t_myparser create_myparser(void)
|
||||
{
|
||||
t_language *lang;
|
||||
t_parser *parser;
|
||||
|
||||
lang = tree_sitter_bash();
|
||||
parser = ts_parser_new();
|
||||
ts_parser_set_language(parser, lang);
|
||||
return ((t_myparser){.parser = parser});
|
||||
lang = tree_sitter_bash();
|
||||
parser = ts_parser_new();
|
||||
ts_parser_set_language(parser, lang);
|
||||
return ((t_myparser){.parser = parser});
|
||||
}
|
||||
|
||||
void free_myparser(t_myparser self) { ts_parser_delete(self.parser); }
|
||||
|
||||
t_node parse_string(t_myparser *parser, t_const_str input) {
|
||||
return (parse_to_nodes(parser->parser, input));
|
||||
void free_myparser(t_myparser self)
|
||||
{
|
||||
ts_parser_delete(self.parser);
|
||||
}
|
||||
|
||||
t_i32 main() {
|
||||
t_myparser parser;
|
||||
t_node node;
|
||||
|
||||
parser = create_myparser();
|
||||
node = parse_string(&parser, "banane \"$VAR\"'truc'");
|
||||
print_node_data(&node, 0);
|
||||
free_node(node);
|
||||
t_node parse_string(t_myparser *parser, t_const_str input)
|
||||
{
|
||||
return (parse_to_nodes(parser->parser, input));
|
||||
}
|
||||
|
||||
t_i32 main()
|
||||
{
|
||||
t_myparser parser;
|
||||
t_node node;
|
||||
|
||||
parser = create_myparser();
|
||||
node = parse_string(&parser, "banane \"$VAR\"'truc'");
|
||||
print_node_data(&node, 0);
|
||||
free_node(node);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,13 +16,13 @@
|
|||
#include "me/string/str_l_copy.h"
|
||||
#include "parser/api.h"
|
||||
|
||||
t_node build_node(TSNode curr, t_const_str input);
|
||||
t_node build_node(t_parse_node curr, t_const_str input);
|
||||
|
||||
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)
|
||||
|
|
@ -37,7 +37,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;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue