gravity
gravity copied to clipboard
Line numbers in error messages are wrong
I introduced different syntax errors in a running code. The resulting error messages are always larger than the line in question. Subsequent detected errors did not conform to equally offset numbers.
How to debug a Gravity script?
Hi @bardo84, can you please post an example?
Repro steps
Test.gravity
func main() {
System.print("Run Tests!")
error
}
Run
gravity Test.gravity
Expected
Error reported in file "Test.gravity" on line 3 character 2
Actual
SEMANTIC ERROR on 0 (5,2): Identifier error not found.
Should the '0' value be the file name?
FYI: Windows 11 running VS 2022 Version 17.4.3
Thanks @mwasplund, I see that you closed your pull request? That means that it was not ready to be applied?
Should the '0' value be the file name?
'0' is the fileID, the user is responsible to save the filename associated to each fileID. See comment in https://github.com/marcobambini/gravity/blob/971337cc01877d62972e42cab5099379c5b97f12/src/cli/gravity.c#L64 to get more information about to use the fileID.
Yes, it appears that in some cases when calling is_newline the current offset is pointing to the actual current token and in some cases it is already pointing to next. Still working out why this is the case.
I think that a good starting point to investigate is the is_newline
function in gravity_lexer.c
https://github.com/marcobambini/gravity/blob/971337cc01877d62972e42cab5099379c5b97f12/src/compiler/gravity_lexer.c#L76
That was were I was looking, I had updated the checks in that method to use PEEK_NEXT instead of PEEK_CURRENT. This resolved a lot of issues where the LF was getting missed and then double counted. However, it appears that in some cases the caller is "peeking" in which case the next char is actually current... I sent an update to pass in the exact next and next2 characters to the is_newline call. Not the prettiest, but it is working. Let me know if you see a cleaner way to achieve the difference in state between calls.