From e7209226624adb853194e19a307f20bc127316de Mon Sep 17 00:00:00 2001 From: joshvera Date: Thu, 12 Nov 2015 12:24:05 -0500 Subject: [PATCH] Add source info to TSLexer --- include/tree_sitter/parser.h | 4 ++++ include/tree_sitter/runtime.h | 7 +++++++ src/runtime/lexer.c | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/include/tree_sitter/parser.h b/include/tree_sitter/parser.h index bb29a627..9aa4939f 100644 --- a/include/tree_sitter/parser.h +++ b/include/tree_sitter/parser.h @@ -38,6 +38,10 @@ typedef struct TSLexer { TSLength token_end_position; TSLength token_start_position; + TSSourceInfo current_source_info; + TSSourceInfo token_end_source_info; + TSSourceInfo token_start_source_info; + size_t lookahead_size; int32_t lookahead; diff --git a/include/tree_sitter/runtime.h b/include/tree_sitter/runtime.h index 1143ad0e..c358f437 100644 --- a/include/tree_sitter/runtime.h +++ b/include/tree_sitter/runtime.h @@ -35,9 +35,16 @@ typedef struct { size_t chars_removed; } TSInputEdit; +typedef struct { + size_t line; + size_t column; +} TSSourceInfo; + typedef struct { const void *data; TSLength offset; + TSSourceInfo start; + TSSourceInfo end; } TSNode; typedef unsigned short TSSymbol; diff --git a/src/runtime/lexer.c b/src/runtime/lexer.c index b2b21819..e2b67610 100644 --- a/src/runtime/lexer.c +++ b/src/runtime/lexer.c @@ -53,6 +53,10 @@ static void ts_lexer__start(TSLexer *self, TSStateId lex_state) { static void ts_lexer__start_token(TSLexer *self) { DEBUG("start_token chars:%lu", self->current_position.chars); self->token_start_position = self->current_position; + + DEBUG("start_token line:%lu", self->current_source_info.line); + DEBUG("start_token column:%lu", self->current_source_info.column); + self->token_start_source_info = self->current_source_info; } static bool ts_lexer__advance(TSLexer *self, TSStateId state) {