-
Notifications
You must be signed in to change notification settings - Fork 638
Description
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:
pycparser/pycparser/plyparser.py
Line 55 in f740995
| def _token_coord(self, p, token_idx): |
yacc defines e.g. lineno here:
pycparser/pycparser/ply/yacc.py
Line 258 in f740995
| 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.