aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_mbe/src/lib.rs6
-rw-r--r--crates/ra_mbe/src/syntax_bridge.rs4
-rw-r--r--crates/ra_syntax/src/lib.rs2
-rw-r--r--crates/ra_syntax/src/parsing.rs2
-rw-r--r--crates/ra_syntax/src/parsing/lexer.rs9
5 files changed, 15 insertions, 8 deletions
diff --git a/crates/ra_mbe/src/lib.rs b/crates/ra_mbe/src/lib.rs
index 3b127526d..38f0049ed 100644
--- a/crates/ra_mbe/src/lib.rs
+++ b/crates/ra_mbe/src/lib.rs
@@ -343,16 +343,14 @@ SOURCE_FILE@[0; 40)
343 if let tt::TokenTree::Subtree(subtree) = tt { 343 if let tt::TokenTree::Subtree(subtree) = tt {
344 return &subtree; 344 return &subtree;
345 } 345 }
346 assert!(false, "It is not a subtree"); 346 unreachable!("It is not a subtree");
347 unreachable!();
348 } 347 }
349 348
350 fn to_literal(tt: &tt::TokenTree) -> &tt::Literal { 349 fn to_literal(tt: &tt::TokenTree) -> &tt::Literal {
351 if let tt::TokenTree::Leaf(tt::Leaf::Literal(lit)) = tt { 350 if let tt::TokenTree::Leaf(tt::Leaf::Literal(lit)) = tt {
352 return lit; 351 return lit;
353 } 352 }
354 assert!(false, "It is not a literal"); 353 unreachable!("It is not a literal");
355 unreachable!();
356 } 354 }
357 355
358 let rules = create_rules( 356 let rules = create_rules(
diff --git a/crates/ra_mbe/src/syntax_bridge.rs b/crates/ra_mbe/src/syntax_bridge.rs
index fbf3d2e71..9664280b5 100644
--- a/crates/ra_mbe/src/syntax_bridge.rs
+++ b/crates/ra_mbe/src/syntax_bridge.rs
@@ -1,7 +1,7 @@
1use ra_parser::{TokenSource, TreeSink, ParseError}; 1use ra_parser::{TokenSource, TreeSink, ParseError};
2use ra_syntax::{ 2use ra_syntax::{
3 AstNode, SyntaxNode, TextRange, SyntaxKind, SmolStr, SyntaxTreeBuilder, TreeArc, SyntaxElement, 3 AstNode, SyntaxNode, TextRange, SyntaxKind, SmolStr, SyntaxTreeBuilder, TreeArc, SyntaxElement,
4 ast, SyntaxKind::*, TextUnit, next_token 4 ast, SyntaxKind::*, TextUnit, classify_literal
5}; 5};
6 6
7/// Maps `tt::TokenId` to the relative range of the original token. 7/// Maps `tt::TokenId` to the relative range of the original token.
@@ -189,7 +189,7 @@ impl TtTokenSource {
189 { 189 {
190 let tok = match token { 190 let tok = match token {
191 tt::Leaf::Literal(l) => TtToken { 191 tt::Leaf::Literal(l) => TtToken {
192 kind: next_token(&l.text).kind, 192 kind: classify_literal(&l.text).unwrap().kind,
193 is_joint_to_next: false, 193 is_joint_to_next: false,
194 text: l.text.clone(), 194 text: l.text.clone(),
195 }, 195 },
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs
index 1cbc3e9e1..c56bc9f16 100644
--- a/crates/ra_syntax/src/lib.rs
+++ b/crates/ra_syntax/src/lib.rs
@@ -40,7 +40,7 @@ pub use crate::{
40 syntax_text::SyntaxText, 40 syntax_text::SyntaxText,
41 syntax_node::{Direction, SyntaxNode, WalkEvent, TreeArc, SyntaxTreeBuilder, SyntaxElement, SyntaxToken}, 41 syntax_node::{Direction, SyntaxNode, WalkEvent, TreeArc, SyntaxTreeBuilder, SyntaxElement, SyntaxToken},
42 ptr::{SyntaxNodePtr, AstPtr}, 42 ptr::{SyntaxNodePtr, AstPtr},
43 parsing::{tokenize, next_token, Token}, 43 parsing::{tokenize, classify_literal, Token},
44}; 44};
45 45
46use ra_text_edit::AtomTextEdit; 46use ra_text_edit::AtomTextEdit;
diff --git a/crates/ra_syntax/src/parsing.rs b/crates/ra_syntax/src/parsing.rs
index f0750d737..15d69c5ab 100644
--- a/crates/ra_syntax/src/parsing.rs
+++ b/crates/ra_syntax/src/parsing.rs
@@ -11,7 +11,7 @@ use crate::{
11 syntax_node::GreenNode, 11 syntax_node::GreenNode,
12}; 12};
13 13
14pub use self::lexer::{tokenize, next_token, Token}; 14pub use self::lexer::{tokenize, classify_literal, Token};
15 15
16pub(crate) use self::reparsing::incremental_reparse; 16pub(crate) use self::reparsing::incremental_reparse;
17 17
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) {
214 } 214 }
215 ptr.bump_while(is_ident_continue); 215 ptr.bump_while(is_ident_continue);
216} 216}
217
218pub fn classify_literal(text: &str) -> Option<Token> {
219 let tkn = next_token(text);
220 if tkn.kind.is_literal() || tkn.len.to_usize() != text.len() {
221 return None;
222 }
223
224 Some(tkn)
225}