Add get_column method to lexer

This commit is contained in:
Max Brunsfeld 2017-12-19 17:54:15 -08:00
parent e016561887
commit fcff16cb86
2 changed files with 7 additions and 0 deletions

View file

@ -24,6 +24,7 @@ typedef struct {
typedef struct {
void (*advance)(void *, bool);
void (*mark_end)(void *);
uint32_t (*get_column)(void *);
int32_t lookahead;
TSSymbol result_symbol;
} TSLexer;

View file

@ -91,6 +91,11 @@ static void ts_lexer__mark_end(void *payload) {
self->token_end_position = self->current_position;
}
static uint32_t ts_lexer__get_column(void *payload) {
Lexer *self = (Lexer *)payload;
return self->current_position.extent.column;
}
/*
* The lexer's advance method is stored as a struct field so that generated
* parsers can call it without needing to be linked against this library.
@ -101,6 +106,7 @@ void ts_lexer_init(Lexer *self) {
.data = {
.advance = ts_lexer__advance,
.mark_end = ts_lexer__mark_end,
.get_column = ts_lexer__get_column,
.lookahead = 0,
.result_symbol = 0,
},