-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Simple lexer for formatter #4922
Conversation
Current dependencies on/for this PR:
This comment was auto-generated by Graphite. |
PR Check ResultsEcosystem✅ ecosystem check detected no changes. BenchmarkLinux
Windows
|
Other, | ||
|
||
/// Returned for each character after [`TokenKind::Other`] has been returned once. | ||
Bogus, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we name this Unknown
instead?
bb0517f
to
2448287
Compare
2448287
to
5a9709d
Compare
let tokens = SimpleTokenizer::up_to(offset, code); | ||
let mut newlines = 0u32; | ||
|
||
for token in tokens.rev() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the main benefits is that we no longer repeat the same logic over and over again (and e.g. correctly handle continuation tokens)
5a9709d
to
894b045
Compare
894b045
to
f5240f7
Compare
f5240f7
to
1b58a53
Compare
1b58a53
to
6a13e21
Compare
@charliermarsh let me know if you have time to look at this PR. I'll otherwise go ahead and merge it, as there's already a lot of code depending on it |
@MichaReiser - Go for it, I won't have time for a few hours. |
Summary
This PR introduces a simple zero-allocation lexer specific for the needs of the formatter.
It supports a very limited set of tokens for optimized performance.
The main reason for introducing a lexer is that Charlie correctly pointed out that the current implementation for testing if an expression is parenthesized is not sufficient.
Having a more proper lexer will simplify testing for the right tokens.
Test Plan
cargo test
, new unit tests