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

Move eat_trivia in sink #9

Open
axelkar opened this issue Jul 25, 2024 · 2 comments
Open

Move eat_trivia in sink #9

axelkar opened this issue Jul 25, 2024 · 2 comments

Comments

@axelkar
Copy link

axelkar commented Jul 25, 2024

Think about the following file in an imaginary language, where the grammar only matches an identifier and nothing else:

    foo

(No trailing newline, token list after lexing: [Whitespace, Ident])

The grammar module uses Source::next_token(), which skips trivia first and then returns the non-trivia token SyntaxKind::Ident.
Before the sink step, the event list looks like this: [Event::AddToken].
When the sink receives the AddToken event, it pops off the token at index 0 from the token list, which happens to be SyntaxKind::Whitespace. After that there is no trivia to eat (Sink::eat_trivia) and there are no more events. In the end, the CST doesn't even contain the Ident token.

I think that moving eat_trivia to before the match statement works. Even better is that it'd be after StartNode, but before AddToken so comments are added into the node.

@lunacookies
Copy link
Owner

You’re completely right, I missed that!

As you might be able to tell I’ve stopped working on the tutorial series, so I think I would rather keep everything as-is as a kind of historical archive, rather than a maintained project. If I were to fix things like this, I’d have to write up new posts explaining the issue and the fix.

I hope you understand :)

@axelkar
Copy link
Author

axelkar commented Jul 26, 2024

You’re completely right, I missed that!

As you might be able to tell I’ve stopped working on the tutorial series, so I think I would rather keep everything as-is as a kind of historical archive, rather than a maintained project. If I were to fix things like this, I’d have to write up new posts explaining the issue and the fix.

I hope you understand :)

Yeah it's all good! Thank you very much for the series! It really helped me understand rust-analyzer's parsing architecture.

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

No branches or pull requests

2 participants