aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-03-09 08:43:07 +0000
committerGitHub <[email protected]>2020-03-09 08:43:07 +0000
commit0363c9495a6a07db276dce4c67fa35fbfc20153c (patch)
tree0a98e2b4659d0d0f4df98f41613c6da90e19551f /crates/ra_syntax
parent7ac99aad28a36e7cdb27edcb319d7f540dbd8471 (diff)
parente7206467d57c555f1ca1fee6acc0461d7579f4f7 (diff)
Merge #3518
3518: Add parse_to_token_tree r=matklad a=edwin0cheng This PR introduce a function for parsing `&str` to `tt::TokenTree`: ```rust // Convert a string to a `TokenTree` pub fn parse_to_token_tree(text: &str) -> Option<(tt::Subtree, TokenMap)> { ```` Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r--crates/ra_syntax/src/ast/make.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs
index 53d6fa562..ae8829807 100644
--- a/crates/ra_syntax/src/ast/make.rs
+++ b/crates/ra_syntax/src/ast/make.rs
@@ -267,6 +267,12 @@ pub mod tokens {
267 sf.syntax().first_child_or_token().unwrap().into_token().unwrap() 267 sf.syntax().first_child_or_token().unwrap().into_token().unwrap()
268 } 268 }
269 269
270 pub fn doc_comment(text: &str) -> SyntaxToken {
271 assert!(!text.trim().is_empty());
272 let sf = SourceFile::parse(text).ok().unwrap();
273 sf.syntax().first_child_or_token().unwrap().into_token().unwrap()
274 }
275
270 pub fn literal(text: &str) -> SyntaxToken { 276 pub fn literal(text: &str) -> SyntaxToken {
271 assert_eq!(text.trim(), text); 277 assert_eq!(text.trim(), text);
272 let lit: ast::Literal = super::ast_from_text(&format!("fn f() {{ let _ = {}; }}", text)); 278 let lit: ast::Literal = super::ast_from_text(&format!("fn f() {{ let _ = {}; }}", text));