aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-04-05 15:17:07 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-04-05 15:17:07 +0100
commita52e86f9a9a21313a1543823b92e82c0a30e0870 (patch)
tree35d8b8b04a8e17a162fd6b95105db34919d59507 /crates/ra_syntax
parentbe9a44e9bad262ac5e615730e540fd434f846a0e (diff)
parent7abc06bd576264cb6b7c8becdbd1a8c0e914463d (diff)
Merge #1112
1112: Fix literal support in token tree to ast item list r=matklad a=edwin0cheng This PR implements following things : 1. Expose `next_token` from `ra_parse` 2. Fix the literal conversion in `token_tree_to_ast_item_list` 3. Add test for the conversion Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/ra_syntax')
-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
3 files changed, 11 insertions, 2 deletions
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs
index e1088e296..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, 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 ad5668a65..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, 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..3ae42912c 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}