From ace81f6267daf9580f365270b7779decf0a7093d Mon Sep 17 00:00:00 2001 From: Andrew Helwer Date: Wed, 13 Oct 2021 15:47:53 -0400 Subject: [PATCH] Don't log when counting codepoints --- lib/src/lexer.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/lib/src/lexer.c b/lib/src/lexer.c index c94a80b4..e72297fe 100644 --- a/lib/src/lexer.c +++ b/lib/src/lexer.c @@ -152,18 +152,8 @@ static void ts_lexer_goto(Lexer *self, Length position) { } } -// Advance to the next character in the source code, retrieving a new -// chunk of source code if needed. -static void ts_lexer__advance(TSLexer *_self, bool skip) { - Lexer *self = (Lexer *)_self; - if (!self->chunk) return; - - if (skip) { - LOG("skip", self->data.lookahead); - } else { - LOG("consume", self->data.lookahead); - } - +// Intended to be called only from functions below that control logging. +static void ts_lexer__do_advance(Lexer *self, bool skip) { if (self->lookahead_size) { self->current_position.bytes += self->lookahead_size; if (self->data.lookahead == '\n') { @@ -205,6 +195,27 @@ static void ts_lexer__advance(TSLexer *_self, bool skip) { } } +// Advance to the next character in the source code, retrieving a new +// chunk of source code if needed. +static void ts_lexer__advance(TSLexer *_self, bool skip) { + Lexer *self = (Lexer *)_self; + if (!self->chunk) return; + + if (skip) { + LOG("skip", self->data.lookahead); + } else { + LOG("consume", self->data.lookahead); + } + + ts_lexer__do_advance(self, skip); +} + +// Advance without logging. +static void ts_lexer__advance_no_log(Lexer *self, bool skip) { + if (!self->chunk) return; + ts_lexer__do_advance(self, skip); +} + // Mark that a token match has completed. This can be called multiple // times if a longer match is found later. static void ts_lexer__mark_end(TSLexer *_self) { @@ -247,7 +258,7 @@ static uint32_t ts_lexer__get_column(TSLexer *_self) { uint32_t result = 0; ts_lexer__get_lookahead(self); while (self->current_position.bytes < goal_byte && !ts_lexer__eof(_self)) { - ts_lexer__advance(_self, false); + ts_lexer__advance_no_log(self, false); result++; }