Tree-sitter: get_column causes infinite loop

Created on 5 Jan 2020  路  4Comments  路  Source: tree-sitter/tree-sitter

I tried get_column but it didn't work as I expected.
So I just put lexer->get_column(lexer); at the beginning of scan function to check the behavior.

bool tree_sitter_cham_external_scanner_scan(
    void *payload,
    TSLexer *lexer,
    const bool *valid_symbols)
{

  lexer->get_column(lexer);

But then for every input it never stops and gives any result neither.
My tree-sitter-cli version is 0.16.2.

bug

Most helpful comment

Interesting. Note that lexer->eof is a function though, so with that code, get_column will never be called.

Try this:

bool tree_sitter_cham_external_scanner_scan(
    void *payload,
    TSLexer *lexer,
    const bool *valid_symbols)
{
  if(!lexer->eof(lexer)) {
    lexer->get_column(lexer);
  }

  // ...
}

All 4 comments

Issue-Label Bot is automatically applying the label bug to this issue, with a confidence of 0.89. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

I think I figure out when it happens.
It happens when the lexer reaches EOF.

bool tree_sitter_cham_external_scanner_scan(
    void *payload,
    TSLexer *lexer,
    const bool *valid_symbols)
{
  if(!lexer->eof) {
    lexer->get_column(lexer);
  }

After I put a guard before get_column call, it worked well.

Interesting. Note that lexer->eof is a function though, so with that code, get_column will never be called.

Try this:

bool tree_sitter_cham_external_scanner_scan(
    void *payload,
    TSLexer *lexer,
    const bool *valid_symbols)
{
  if(!lexer->eof(lexer)) {
    lexer->get_column(lexer);
  }

  // ...
}

@maxbrunsfeld I've checked it and it's working. If my guess is right, then I think this is a common mistake for beginners and it would be better to document.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

calixteman picture calixteman  路  4Comments

francisdb picture francisdb  路  3Comments

movermeyer picture movermeyer  路  3Comments

Astrantia picture Astrantia  路  5Comments

char0n picture char0n  路  3Comments