Previously, it was possible for references to external token states to outlive the trees to which those states belonged. Now, instead of storing references to external token states in the Stack and in the Lexer, we store references to the external token trees themselves, and we retain the trees to prevent use-after-free.
43 lines
873 B
C
43 lines
873 B
C
#ifndef RUNTIME_LEXER_H_
|
|
#define RUNTIME_LEXER_H_
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#include "tree_sitter/parser.h"
|
|
#include "tree_sitter/runtime.h"
|
|
#include "runtime/length.h"
|
|
#include "runtime/tree.h"
|
|
|
|
#define TS_DEBUG_BUFFER_SIZE 512
|
|
|
|
typedef struct {
|
|
TSLexer data;
|
|
Length current_position;
|
|
Length token_start_position;
|
|
Length token_end_position;
|
|
|
|
const char *chunk;
|
|
uint32_t chunk_start;
|
|
uint32_t chunk_size;
|
|
uint32_t lookahead_size;
|
|
|
|
TSInput input;
|
|
TSLogger logger;
|
|
char debug_buffer[TS_DEBUG_BUFFER_SIZE];
|
|
Tree *last_external_token;
|
|
} Lexer;
|
|
|
|
void ts_lexer_init(Lexer *);
|
|
void ts_lexer_set_input(Lexer *, TSInput);
|
|
void ts_lexer_reset(Lexer *, Length);
|
|
void ts_lexer_start(Lexer *);
|
|
void ts_lexer_advance_to_end(Lexer *);
|
|
void ts_lexer_set_last_external_token(Lexer *, Tree *);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif // RUNTIME_LEXER_H_
|