gravity icon indicating copy to clipboard operation
gravity copied to clipboard

Line numbers in error messages are wrong

Open bardo84 opened this issue 2 years ago • 9 comments

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?

bardo84 avatar Aug 18 '22 14:08 bardo84

Hi @bardo84, can you please post an example?

marcobambini avatar Aug 20 '22 06:08 marcobambini

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.

mwasplund avatar Dec 26 '22 21:12 mwasplund

Should the '0' value be the file name?

mwasplund avatar Dec 26 '22 21:12 mwasplund

FYI: Windows 11 running VS 2022 Version 17.4.3

mwasplund avatar Dec 26 '22 21:12 mwasplund

Thanks @mwasplund, I see that you closed your pull request? That means that it was not ready to be applied?

marcobambini avatar Dec 27 '22 07:12 marcobambini

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.

marcobambini avatar Dec 27 '22 07:12 marcobambini

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.

mwasplund avatar Dec 27 '22 09:12 mwasplund

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

marcobambini avatar Dec 27 '22 10:12 marcobambini

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.

mwasplund avatar Dec 27 '22 16:12 mwasplund