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

Issue with whitespaces and byteoffset #75

Closed
bnjjj opened this issue Oct 1, 2021 · 4 comments
Closed

Issue with whitespaces and byteoffset #75

bnjjj opened this issue Oct 1, 2021 · 4 comments
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@bnjjj
Copy link
Contributor

bnjjj commented Oct 1, 2021

I try to use miette with a parser, if the node parsed is of type error then I use miette to render the error. I have an issue because in miette it seems you're skipping '\n' and whitespaces into the source code. Then when I try to specify my SourceSpan thanks to the byte position it doesn't work at all because it the byte position with whitespaces and in your code you use the source_code string without any whitespaces.

How can I do this correctly ?

example of my code:

let err = ParsingError {
	bad_bit: (node.start_byte(), node.end_byte()).into(), // ISSUE HERE
	src: src.to_string(),
};
@zkat zkat added bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed labels Oct 1, 2021
@zkat
Copy link
Owner

zkat commented Oct 1, 2021

Oh this is a pretty good bug. So what you're trying to do is point at the newline whitespace itself?

@jmackie
Copy link

jmackie commented Oct 1, 2021

Don't mind me, just passing through, but I noticed:

bad_bit: (node.start_byte(), node.end_byte()).into(), // ISSUE HERE

Should that not be...

bad_bit: (node.start_byte(), node.end_byte() - node.start_byte()).into(),

As the convert impl says (start, len)?

@zkat
Copy link
Owner

zkat commented Oct 1, 2021

oh yeah. That'd do it. Spans in miette are (offset, len), not (start, end), for some good reasons :)

@bnjjj
Copy link
Contributor Author

bnjjj commented Oct 1, 2021

Ok it's better now ! Thanks a lot ! My prediction about the bug with whitespaces was wrong. Sorry for this. I made a pr to have less confusion next time

@bnjjj bnjjj closed this as completed Oct 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants