Skip to content

Add end of token coord #527

@99991

Description

@99991

It would be nice to know where a node ends. For the start of a token, we have node.coord. Similarly, it would be nice if we also had node.endcoord. The reason why I want this feature is that it would enable precisely underlined error messages like GCC has:

main.c: In function ‘main’:
main.c:2:13: warning: initialization of ‘int’ from ‘char *’ makes integer from pointer without a cast [-Wint-conversion]
    2 |     int x = "asdf";
      |             ^~~~~~

Here is where the coord is parameter is retrieved from yacc:

def _token_coord(self, p, token_idx):

yacc defines e.g. lineno here:

return getattr(self.slice[n], 'lineno', 0)

I am not sure if the end position can be obtained from yacc. In case this is not possible, here is a hacky idea: Find the end position by scanning backwards from the next token until a non-whitespace character is found.

I do not have the time to implement this right now, but I thought I should start a discussion here in case someone has a better idea.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions