diff options
Diffstat (limited to 'crates/ra_syntax/src/ast/make.rs')
-rw-r--r-- | crates/ra_syntax/src/ast/make.rs | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs index eef45090d..4a79d0dec 100644 --- a/crates/ra_syntax/src/ast/make.rs +++ b/crates/ra_syntax/src/ast/make.rs | |||
@@ -2,7 +2,7 @@ | |||
2 | //! of smaller pieces. | 2 | //! of smaller pieces. |
3 | use itertools::Itertools; | 3 | use itertools::Itertools; |
4 | 4 | ||
5 | use crate::{algo, ast, AstNode, SourceFile}; | 5 | use crate::{algo, ast, AstNode, SourceFile, SyntaxKind, SyntaxToken}; |
6 | 6 | ||
7 | pub fn name(text: &str) -> ast::Name { | 7 | pub fn name(text: &str) -> ast::Name { |
8 | ast_from_text(&format!("mod {};", text)) | 8 | ast_from_text(&format!("mod {};", text)) |
@@ -181,28 +181,28 @@ pub fn let_stmt(pattern: ast::Pat, initializer: Option<ast::Expr>) -> ast::LetSt | |||
181 | ast_from_text(&format!("fn f() {{ {} }}", text)) | 181 | ast_from_text(&format!("fn f() {{ {} }}", text)) |
182 | } | 182 | } |
183 | 183 | ||
184 | pub fn token(kind: SyntaxKind) -> SyntaxToken { | ||
185 | tokens::SOURCE_FILE | ||
186 | .tree() | ||
187 | .syntax() | ||
188 | .descendants_with_tokens() | ||
189 | .filter_map(|it| it.into_token()) | ||
190 | .find(|it| it.kind() == kind) | ||
191 | .unwrap_or_else(|| panic!("unhandled token: {:?}", kind)) | ||
192 | } | ||
193 | |||
184 | fn ast_from_text<N: AstNode>(text: &str) -> N { | 194 | fn ast_from_text<N: AstNode>(text: &str) -> N { |
185 | let parse = SourceFile::parse(text); | 195 | let parse = SourceFile::parse(text); |
186 | parse.tree().syntax().descendants().find_map(N::cast).unwrap() | 196 | parse.tree().syntax().descendants().find_map(N::cast).unwrap() |
187 | } | 197 | } |
188 | 198 | ||
189 | pub mod tokens { | 199 | pub mod tokens { |
190 | use crate::{AstNode, Parse, SourceFile, SyntaxKind, SyntaxKind::*, SyntaxToken, T}; | 200 | use crate::{AstNode, Parse, SourceFile, SyntaxKind::*, SyntaxToken, T}; |
191 | use once_cell::sync::Lazy; | 201 | use once_cell::sync::Lazy; |
192 | 202 | ||
193 | static SOURCE_FILE: Lazy<Parse<SourceFile>> = | 203 | pub(super) static SOURCE_FILE: Lazy<Parse<SourceFile>> = |
194 | Lazy::new(|| SourceFile::parse("const C: () = (1 != 1, 2 == 2)\n;")); | 204 | Lazy::new(|| SourceFile::parse("const C: () = (1 != 1, 2 == 2)\n;")); |
195 | 205 | ||
196 | pub fn op(op: SyntaxKind) -> SyntaxToken { | ||
197 | SOURCE_FILE | ||
198 | .tree() | ||
199 | .syntax() | ||
200 | .descendants_with_tokens() | ||
201 | .filter_map(|it| it.into_token()) | ||
202 | .find(|it| it.kind() == op) | ||
203 | .unwrap() | ||
204 | } | ||
205 | |||
206 | pub fn comma() -> SyntaxToken { | 206 | pub fn comma() -> SyntaxToken { |
207 | SOURCE_FILE | 207 | SOURCE_FILE |
208 | .tree() | 208 | .tree() |