From fe1b1dd7d9edde081c4c95facc19e801863beaff Mon Sep 17 00:00:00 2001 From: Phil Ellison Date: Sun, 28 Jul 2019 19:52:30 +0100 Subject: More direct failing test --- crates/ra_syntax/src/parsing/lexer.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'crates/ra_syntax') diff --git a/crates/ra_syntax/src/parsing/lexer.rs b/crates/ra_syntax/src/parsing/lexer.rs index 2a4343b0a..f75e321c3 100644 --- a/crates/ra_syntax/src/parsing/lexer.rs +++ b/crates/ra_syntax/src/parsing/lexer.rs @@ -145,3 +145,16 @@ pub fn classify_literal(text: &str) -> Option { }; Some(Token { kind, len: TextUnit::from_usize(t.len) }) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn lex_float_literal() { + assert_eq!( + tokenize("42f64")[0], + Token { kind: FLOAT_NUMBER, len: TextUnit::from_usize(5)} + ); + } +} \ No newline at end of file -- cgit v1.2.3 From 578bc05ca41e095c61c64bdef255760c26736a11 Mon Sep 17 00:00:00 2001 From: Phil Ellison Date: Sun, 28 Jul 2019 20:25:06 +0100 Subject: Add issue link and trailing newline --- crates/ra_syntax/src/parsing/lexer.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'crates/ra_syntax') diff --git a/crates/ra_syntax/src/parsing/lexer.rs b/crates/ra_syntax/src/parsing/lexer.rs index f75e321c3..45ef88ac0 100644 --- a/crates/ra_syntax/src/parsing/lexer.rs +++ b/crates/ra_syntax/src/parsing/lexer.rs @@ -150,6 +150,7 @@ pub fn classify_literal(text: &str) -> Option { mod tests { use super::*; + // https://github.com/rust-analyzer/rust-analyzer/issues/1592 #[test] fn lex_float_literal() { assert_eq!( @@ -157,4 +158,4 @@ mod tests { Token { kind: FLOAT_NUMBER, len: TextUnit::from_usize(5)} ); } -} \ No newline at end of file +} -- cgit v1.2.3 From 4fd7ad908b6e7cee0ee7853fcf29fb5a38a19aa2 Mon Sep 17 00:00:00 2001 From: Phil Ellison Date: Sun, 28 Jul 2019 20:47:44 +0100 Subject: Add special case for f32 and f43 suffices on Literal.kind --- crates/ra_syntax/src/ast/expr_extensions.rs | 24 +++++++++++++++++++++--- crates/ra_syntax/src/parsing/lexer.rs | 14 -------------- 2 files changed, 21 insertions(+), 17 deletions(-) (limited to 'crates/ra_syntax') diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs index f9190d877..745dece98 100644 --- a/crates/ra_syntax/src/ast/expr_extensions.rs +++ b/crates/ra_syntax/src/ast/expr_extensions.rs @@ -239,16 +239,34 @@ impl ast::Literal { pub fn kind(&self) -> LiteralKind { match self.token().kind() { INT_NUMBER => { - let allowed_suffix_list = [ + let int_suffix_list = [ "isize", "i128", "i64", "i32", "i16", "i8", "usize", "u128", "u64", "u32", "u16", "u8", ]; + + // The lexer treats e.g. `1f64` as an integer literal. See + // https://github.com/rust-analyzer/rust-analyzer/issues/1592 + // and the comments on the linked PR. + let float_suffix_list = [ + "f32", "f64" + ]; + let text = self.token().text().to_string(); - let suffix = allowed_suffix_list + + let float_suffix = float_suffix_list .iter() .find(|&s| text.ends_with(s)) .map(|&suf| SmolStr::new(suf)); - LiteralKind::IntNumber { suffix } + + if float_suffix.is_some() { + LiteralKind::FloatNumber { suffix: float_suffix } + } else { + let suffix = int_suffix_list + .iter() + .find(|&s| text.ends_with(s)) + .map(|&suf| SmolStr::new(suf)); + LiteralKind::IntNumber { suffix } + } } FLOAT_NUMBER => { let allowed_suffix_list = ["f64", "f32"]; diff --git a/crates/ra_syntax/src/parsing/lexer.rs b/crates/ra_syntax/src/parsing/lexer.rs index 45ef88ac0..2a4343b0a 100644 --- a/crates/ra_syntax/src/parsing/lexer.rs +++ b/crates/ra_syntax/src/parsing/lexer.rs @@ -145,17 +145,3 @@ pub fn classify_literal(text: &str) -> Option { }; Some(Token { kind, len: TextUnit::from_usize(t.len) }) } - -#[cfg(test)] -mod tests { - use super::*; - - // https://github.com/rust-analyzer/rust-analyzer/issues/1592 - #[test] - fn lex_float_literal() { - assert_eq!( - tokenize("42f64")[0], - Token { kind: FLOAT_NUMBER, len: TextUnit::from_usize(5)} - ); - } -} -- cgit v1.2.3 From fab8e9bb8a2657d397a5d52595a83d428dcbd7b8 Mon Sep 17 00:00:00 2001 From: Phil Ellison Date: Sun, 28 Jul 2019 20:54:37 +0100 Subject: cargo format --- crates/ra_syntax/src/ast/expr_extensions.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'crates/ra_syntax') diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs index 745dece98..8284f1b25 100644 --- a/crates/ra_syntax/src/ast/expr_extensions.rs +++ b/crates/ra_syntax/src/ast/expr_extensions.rs @@ -247,9 +247,7 @@ impl ast::Literal { // The lexer treats e.g. `1f64` as an integer literal. See // https://github.com/rust-analyzer/rust-analyzer/issues/1592 // and the comments on the linked PR. - let float_suffix_list = [ - "f32", "f64" - ]; + let float_suffix_list = ["f32", "f64"]; let text = self.token().text().to_string(); -- cgit v1.2.3