Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add end of token coord #527

Open
99991 opened this issue Feb 14, 2024 · 0 comments
Open

Add end of token coord #527

99991 opened this issue Feb 14, 2024 · 0 comments

Comments

@99991
Copy link

99991 commented Feb 14, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant