Update lexer snapshots with token flags#11614
Update lexer snapshots with token flags#11614dhruvmanila merged 1 commit intodhruv/parser-phase-2from
Conversation
CodSpeed Performance ReportMerging #11614 will not alter performanceComparing Summary
|
| FStringStart, | ||
| 11..13, | ||
| TokenFlags( | ||
| F_STRING, |
There was a problem hiding this comment.
what's the usage of the FStringFlag. Can't we tell that it is an FString by looking at the TokenKind?
There was a problem hiding this comment.
Yeah, good point. Currently, it's only used inside the lexer to call either lex_fstring_start or lex_string method.
There was a problem hiding this comment.
I think it's required because we represent regular string with no string kind flag set. And, prefix method would also not be able to differentiate because the flags themselves don't have access to the token kind.
There was a problem hiding this comment.
Hmm okay. I would need to check out the code to better understand it. We could move the prefix method to the Token? And could we only keep it for FStringFlags? But it's probably not that important.
68e781e to
dc0ed20
Compare
6b4c77f to
71113db
Compare
dc0ed20 to
5f634e1
Compare
71113db to
2d0d520
Compare
5f634e1 to
b422554
Compare
2d0d520 to
66953c5
Compare
|
|
||
| // Keep the current flags in sync throughout the f-string context. | ||
| self.current_flags = fstring.flags(); | ||
|
|
||
| // Check if we're at the end of the f-string. | ||
| if fstring.is_triple_quoted() { | ||
| let quote_char = fstring.quote_char(); | ||
| if self.cursor.eat_char3(quote_char, quote_char, quote_char) { | ||
| self.current_flags = fstring.flags(); | ||
| return Some(TokenKind::FStringEnd); | ||
| } | ||
| } else if self.cursor.eat_char(fstring.quote_char()) { | ||
| self.current_flags = fstring.flags(); | ||
| return Some(TokenKind::FStringEnd); |
There was a problem hiding this comment.
Set the token flags only if we know that it's FStringEnd.
|
|
||
| self.current_flags = fstring.flags(); | ||
| Some(TokenKind::FStringMiddle) |
There was a problem hiding this comment.
Set the token flags only if we know that it's FStringMiddle.
|
(I'll look at the remaining test cases in a separate PR.) |
| let mut tuple = if matches!(self.value, TokenValue::None) { | ||
| tuple.field(&self.kind) | ||
| } else { | ||
| tuple.field(&self.value) | ||
| }; | ||
| tuple = tuple.field(&self.range); |
There was a problem hiding this comment.
Nit: At least debug_map etc. mutate the state in place.
| let mut tuple = if matches!(self.value, TokenValue::None) { | |
| tuple.field(&self.kind) | |
| } else { | |
| tuple.field(&self.value) | |
| }; | |
| tuple = tuple.field(&self.range); | |
| if matches!(self.value, TokenValue::None) { | |
| tuple.field(&self.kind); | |
| } else { | |
| tuple.field(&self.value); | |
| }; | |
| tuple.field(&self.range); |
There was a problem hiding this comment.
Are you suggesting to use debug_map? I want to keep the tuple here to have minimal diff which makes it easier to verify the changes. We can explore other formats as a follow-up.
There was a problem hiding this comment.
Oh no, I'm suggesting to not use let mut tuple = tuple.field because I think it might not be necessary (it's not necessary for debug_map)
| tuple.field(&self.value) | ||
| }; | ||
| tuple = tuple.field(&self.range); | ||
| if self.flags.is_empty() { |
There was a problem hiding this comment.
Nit: Maybe
if !self.flags.is_empty() {
tuple.field(&self.flags);
}
tuple.finish()| FStringStart, | ||
| 11..13, | ||
| TokenFlags( | ||
| F_STRING, |
There was a problem hiding this comment.
Hmm okay. I would need to check out the code to better understand it. We could move the prefix method to the Token? And could we only keep it for FStringFlags? But it's probably not that important.
## Summary This PR updates the lexer test snapshots to include the `TokenFlags`. ## Test Plan Verify the snapshots.
## Summary This PR updates the lexer test snapshots to include the `TokenFlags`. ## Test Plan Verify the snapshots.
Summary
This PR updates the lexer test snapshots to include the
TokenFlags.Test Plan
Verify the snapshots.