From 1ea0238e538dc332b23698d54c02d8bd037f58bb Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 5 Apr 2019 18:45:19 +0800 Subject: Add classify_literal and undo expose next_token --- crates/ra_syntax/src/parsing/lexer.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'crates/ra_syntax/src/parsing') diff --git a/crates/ra_syntax/src/parsing/lexer.rs b/crates/ra_syntax/src/parsing/lexer.rs index 36e841609..e75f3aae0 100644 --- a/crates/ra_syntax/src/parsing/lexer.rs +++ b/crates/ra_syntax/src/parsing/lexer.rs @@ -214,3 +214,12 @@ fn scan_literal_suffix(ptr: &mut Ptr) { } ptr.bump_while(is_ident_continue); } + +pub fn classify_literal(text: &str) -> Option { + let tkn = next_token(text); + if tkn.kind.is_literal() || tkn.len.to_usize() != text.len() { + return None; + } + + Some(tkn) +} -- cgit v1.2.3 From 7abc06bd576264cb6b7c8becdbd1a8c0e914463d Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 5 Apr 2019 20:58:24 +0800 Subject: Add proper test for literals and fixed typo bug --- crates/ra_syntax/src/parsing/lexer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_syntax/src/parsing') diff --git a/crates/ra_syntax/src/parsing/lexer.rs b/crates/ra_syntax/src/parsing/lexer.rs index e75f3aae0..3ae42912c 100644 --- a/crates/ra_syntax/src/parsing/lexer.rs +++ b/crates/ra_syntax/src/parsing/lexer.rs @@ -217,7 +217,7 @@ fn scan_literal_suffix(ptr: &mut Ptr) { pub fn classify_literal(text: &str) -> Option { let tkn = next_token(text); - if tkn.kind.is_literal() || tkn.len.to_usize() != text.len() { + if !tkn.kind.is_literal() || tkn.len.to_usize() != text.len() { return None; } -- cgit v1.2.3