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

Line numbers in error messages are wrong #389

Open
bardo84 opened this issue Aug 18, 2022 · 9 comments · May be fixed by #401
Open

Line numbers in error messages are wrong #389

bardo84 opened this issue Aug 18, 2022 · 9 comments · May be fixed by #401

Comments

@bardo84
Copy link

bardo84 commented Aug 18, 2022

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?

@marcobambini
Copy link
Owner

Hi @bardo84, can you please post an example?

@mwasplund
Copy link

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
Copy link

Should the '0' value be the file name?

@mwasplund
Copy link

FYI: Windows 11 running VS 2022 Version 17.4.3

@mwasplund mwasplund linked a pull request Dec 27, 2022 that will close this issue
@marcobambini
Copy link
Owner

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

@marcobambini
Copy link
Owner

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

static const char *load_file (const char *file, size_t *size, uint32_t *fileid, void *xdata, bool *is_static) {
to get more information about to use the fileID.

@mwasplund
Copy link

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.

@marcobambini
Copy link
Owner

I think that a good starting point to investigate is the is_newline function in gravity_lexer.c

static inline bool is_newline (gravity_lexer_t *lexer, int c) {

@mwasplund
Copy link

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.

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

Successfully merging a pull request may close this issue.

3 participants