7 #define LOG(message, character) \
8 if (self->logger.log) { \
11 TREE_SITTER_SERIALIZATION_BUFFER_SIZE, \
12 32 <= character && character < 127 ? \
13 message " character:'%c'" : \
14 message " character:%d", \
18 self->logger.payload, \
44 return self->current_included_range_index ==
self->included_range_count;
52 self->chunk_start = 0;
58 self->chunk_start =
self->current_position.bytes;
59 self->chunk =
self->input.read(
61 self->current_position.bytes,
62 self->current_position.extent,
65 if (!self->chunk_size) {
66 self->current_included_range_index =
self->included_range_count;
75 uint32_t position_in_chunk =
self->current_position.bytes -
self->chunk_start;
79 self->lookahead_size = 1;
80 self->data.lookahead =
'\0';
96 size = self->chunk_size;
101 self->lookahead_size = 1;
106 self->current_position = position;
107 bool found_included_range =
false;
110 for (
unsigned i = 0;
i <
self->included_range_count;
i++) {
111 TSRange *included_range = &
self->included_ranges[
i];
114 self->current_position = (
Length) {
120 self->current_included_range_index =
i;
121 found_included_range =
true;
126 if (found_included_range) {
130 position.
bytes < self->chunk_start ||
131 position.
bytes >= self->chunk_start + self->chunk_size
136 self->lookahead_size = 0;
137 self->data.lookahead =
'\0';
143 self->current_included_range_index =
self->included_range_count;
144 TSRange *last_included_range = &
self->included_ranges[
self->included_range_count - 1];
145 self->current_position = (
Length) {
146 .bytes = last_included_range->
end_byte,
147 .extent = last_included_range->
end_point,
150 self->lookahead_size = 1;
151 self->data.lookahead =
'\0';
157 if (self->lookahead_size) {
158 self->current_position.bytes +=
self->lookahead_size;
159 if (self->data.lookahead ==
'\n') {
160 self->current_position.extent.row++;
161 self->current_position.extent.column = 0;
163 self->current_position.extent.column +=
self->lookahead_size;
168 if (self->current_included_range_index < self->included_range_count) {
169 current_range = &
self->included_ranges[
self->current_included_range_index];
170 if (self->current_position.bytes == current_range->
end_byte) {
171 self->current_included_range_index++;
172 if (self->current_included_range_index < self->included_range_count) {
174 self->current_position = (
Length) {
179 current_range =
NULL;
184 if (
skip)
self->token_start_position =
self->current_position;
187 if (self->current_position.bytes >= self->chunk_start + self->chunk_size) {
193 self->data.lookahead =
'\0';
194 self->lookahead_size = 1;
202 if (!self->chunk)
return;
205 LOG(
"skip", self->data.lookahead);
207 LOG(
"consume", self->data.lookahead);
221 TSRange *current_included_range = &
self->included_ranges[
222 self->current_included_range_index
225 self->current_included_range_index > 0 &&
226 self->current_position.bytes == current_included_range->
start_byte
228 TSRange *previous_included_range = current_included_range - 1;
229 self->token_end_position = (
Length) {
236 self->token_end_position =
self->current_position;
242 uint32_t goal_byte =
self->current_position.bytes;
244 self->did_get_column =
true;
245 self->current_position.bytes -=
self->current_position.extent.column;
246 self->current_position.extent.column = 0;
248 if (self->current_position.bytes < self->chunk_start) {
254 while (self->current_position.bytes < goal_byte && !
ts_lexer__eof(_self) && self->chunk) {
267 if (self->current_included_range_index < self->included_range_count) {
268 TSRange *current_range = &
self->included_ranges[
self->current_included_range_index];
269 return self->current_position.bytes == current_range->
start_byte;
292 .current_position = {0, {0, 0}},
297 .included_ranges =
NULL,
298 .included_range_count = 0,
299 .current_included_range_index = 0,
305 ts_free(self->included_ranges);
317 if (position.
bytes != self->current_position.bytes) {
323 self->token_start_position =
self->current_position;
325 self->data.result_symbol = 0;
326 self->did_get_column =
false;
331 self->current_position.bytes == 0 &&
342 uint32_t current_lookahead_end_byte =
self->current_position.bytes + 1;
349 current_lookahead_end_byte++;
352 if (current_lookahead_end_byte > *lookahead_end_byte) {
353 *lookahead_end_byte = current_lookahead_end_byte;
358 while (self->chunk) {
372 if (
count == 0 || !ranges) {
377 for (
unsigned i = 0;
i <
count;
i++) {
380 range->start_byte < previous_byte ||
383 previous_byte =
range->end_byte;
390 self->included_range_count =
count;
396 *
count =
self->included_range_count;
397 return self->included_ranges;
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
int(* decode)(const ut8 *, ebc_command_t *cmd)
void skip(file *in, unsigned n)
static const Length LENGTH_UNDEFINED
static bool length_is_undefined(Length length)
static uint32_t ts_lexer__get_column(TSLexer *_self)
void ts_lexer_reset(Lexer *self, Length position)
void ts_lexer_finish(Lexer *self, uint32_t *lookahead_end_byte)
static bool ts_lexer__eof(const TSLexer *_self)
static bool ts_lexer__is_at_included_range_start(const TSLexer *_self)
void ts_lexer_mark_end(Lexer *self)
static void ts_lexer__get_lookahead(Lexer *self)
void ts_lexer_set_input(Lexer *self, TSInput input)
static void ts_lexer__mark_end(TSLexer *_self)
void ts_lexer_delete(Lexer *self)
static const int32_t BYTE_ORDER_MARK
void ts_lexer_advance_to_end(Lexer *self)
void ts_lexer_start(Lexer *self)
#define LOG(message, character)
void ts_lexer_init(Lexer *self)
static void ts_lexer__clear_chunk(Lexer *self)
static void ts_lexer__get_chunk(Lexer *self)
static void ts_lexer_goto(Lexer *self, Length position)
static void ts_lexer__advance(TSLexer *_self, bool skip)
TSRange * ts_lexer_included_ranges(const Lexer *self, uint32_t *count)
static void ts_lexer__do_advance(Lexer *self, bool skip)
static const TSRange DEFAULT_RANGE
bool ts_lexer_set_included_ranges(Lexer *self, const TSRange *ranges, uint32_t count)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static const int32_t TS_DECODE_ERROR
static uint32_t ts_decode_utf16(const uint8_t *string, uint32_t length, int32_t *code_point)
static uint32_t ts_decode_utf8(const uint8_t *string, uint32_t length, int32_t *code_point)
uint32_t(* UnicodeDecodeFunction)(const uint8_t *string, uint32_t length, int32_t *code_point)
static bool input(void *ud, zip_uint8_t *data, zip_uint64_t length)