feat: allow external scanners to use the logger
Co-authored-by: Amaan Qureshi <amaanq12@gmail.com>
This commit is contained in:
parent
fec6c77da8
commit
2bb20fe2fe
5 changed files with 40 additions and 0 deletions
|
|
@ -3,6 +3,7 @@
|
|||
#include "./subtree.h"
|
||||
#include "./length.h"
|
||||
#include "./unicode.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
#define LOG(message, character) \
|
||||
if (self->logger.log) { \
|
||||
|
|
@ -284,6 +285,17 @@ static bool ts_lexer__is_at_included_range_start(const TSLexer *_self) {
|
|||
}
|
||||
}
|
||||
|
||||
static void ts_lexer__log(const TSLexer *_self, const char *fmt, ...) {
|
||||
Lexer *self = (Lexer *)_self;
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
if (self->logger.log) {
|
||||
vsnprintf(self->debug_buffer, TREE_SITTER_SERIALIZATION_BUFFER_SIZE, fmt, args);
|
||||
self->logger.log(self->logger.payload, TSLogTypeLex, self->debug_buffer);
|
||||
}
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void ts_lexer_init(Lexer *self) {
|
||||
*self = (Lexer) {
|
||||
.data = {
|
||||
|
|
@ -295,6 +307,7 @@ void ts_lexer_init(Lexer *self) {
|
|||
.get_column = ts_lexer__get_column,
|
||||
.is_at_included_range_start = ts_lexer__is_at_included_range_start,
|
||||
.eof = ts_lexer__eof,
|
||||
.log = ts_lexer__log,
|
||||
.lookahead = 0,
|
||||
.result_symbol = 0,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ struct TSLexer {
|
|||
uint32_t (*get_column)(TSLexer *);
|
||||
bool (*is_at_included_range_start)(const TSLexer *);
|
||||
bool (*eof)(const TSLexer *);
|
||||
void (*log)(const TSLexer *, const char *, ...);
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue