aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-04-09 22:35:05 +0100
committerAleksey Kladov <[email protected]>2020-04-09 22:42:01 +0100
commit30084a56a5731343bd4cec727646a6c55900234f (patch)
treecca4821454502279317323fbc63dccdb9c68c5b9 /crates/ra_syntax/src/ast.rs
parent00ec0c10669307bc752812f535f96e121338d688 (diff)
Simpler acessors for keywords
Diffstat (limited to 'crates/ra_syntax/src/ast.rs')
-rw-r--r--crates/ra_syntax/src/ast.rs6
1 files changed, 5 insertions, 1 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs
index cb701f7f6..1ee60e74c 100644
--- a/crates/ra_syntax/src/ast.rs
+++ b/crates/ra_syntax/src/ast.rs
@@ -80,7 +80,7 @@ impl<N: AstNode> Iterator for AstChildren<N> {
80} 80}
81 81
82mod support { 82mod support {
83 use super::{AstChildren, AstNode, AstToken, SyntaxNode}; 83 use super::{AstChildren, AstNode, AstToken, SyntaxKind, SyntaxNode, SyntaxToken};
84 84
85 pub(super) fn child<N: AstNode>(parent: &SyntaxNode) -> Option<N> { 85 pub(super) fn child<N: AstNode>(parent: &SyntaxNode) -> Option<N> {
86 parent.children().find_map(N::cast) 86 parent.children().find_map(N::cast)
@@ -93,6 +93,10 @@ mod support {
93 pub(super) fn token<T: AstToken>(parent: &SyntaxNode) -> Option<T> { 93 pub(super) fn token<T: AstToken>(parent: &SyntaxNode) -> Option<T> {
94 parent.children_with_tokens().filter_map(|it| it.into_token()).find_map(T::cast) 94 parent.children_with_tokens().filter_map(|it| it.into_token()).find_map(T::cast)
95 } 95 }
96
97 pub(super) fn token2(parent: &SyntaxNode, kind: SyntaxKind) -> Option<SyntaxToken> {
98 parent.children_with_tokens().filter_map(|it| it.into_token()).find(|it| it.kind() == kind)
99 }
96} 100}
97 101
98#[test] 102#[test]