Skip to content

Commit

Permalink
Macro: Fix lexing of 4..log
Browse files Browse the repository at this point in the history
Use same rules for .slint and macro.

The test is `cargo test -p test-driver-rust` without the `build-time`
feature (but that feature is enabled in the CI and that's why CI didn't
catch this)
  • Loading branch information
ogoffart committed Aug 19, 2024
1 parent 7295126 commit cb72e48
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion api/rs/macros/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,21 @@ fn fill_token_vec(stream: impl Iterator<Item = TokenTree>, vec: &mut Vec<parser:
}
';' => SyntaxKind::Semicolon,
'!' => SyntaxKind::Bang,
'.' => SyntaxKind::Dot,
'.' => {
// `4..log` is lexed as `4 . . log` in rust, but should be `4. . log` in slint
if let Some(last) = vec.last_mut() {
if last.kind == SyntaxKind::NumberLiteral
&& are_token_touching(prev_span, p.span()).unwrap_or(false)
&& !last.text.contains('.')
&& !last.text.ends_with(char::is_alphabetic)
{
last.text = format!("{}.", last.text).into();
prev_span = span;
continue;
}
}
SyntaxKind::Dot
}
'+' => SyntaxKind::Plus,
'-' => {
if let Some(last) = vec.last_mut() {
Expand Down

0 comments on commit cb72e48

Please sign in to comment.