aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast/tokens.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/ast/tokens.rs')
-rw-r--r--crates/ra_syntax/src/ast/tokens.rs62
1 files changed, 2 insertions, 60 deletions
diff --git a/crates/ra_syntax/src/ast/tokens.rs b/crates/ra_syntax/src/ast/tokens.rs
index 1a51b8d3b..e8320b57e 100644
--- a/crates/ra_syntax/src/ast/tokens.rs
+++ b/crates/ra_syntax/src/ast/tokens.rs
@@ -1,26 +1,10 @@
1//! There are many AstNodes, but only a few tokens, so we hand-write them here. 1//! There are many AstNodes, but only a few tokens, so we hand-write them here.
2 2
3use crate::{ 3use crate::{
4 ast::AstToken, 4 ast::{AstToken, Comment, RawString, String, Whitespace},
5 SyntaxKind::{COMMENT, RAW_STRING, STRING, WHITESPACE}, 5 TextRange, TextUnit,
6 SyntaxToken, TextRange, TextUnit,
7}; 6};
8 7
9#[derive(Debug, Clone, PartialEq, Eq, Hash)]
10pub struct Comment(SyntaxToken);
11
12impl AstToken for Comment {
13 fn cast(token: SyntaxToken) -> Option<Self> {
14 match token.kind() {
15 COMMENT => Some(Comment(token)),
16 _ => None,
17 }
18 }
19 fn syntax(&self) -> &SyntaxToken {
20 &self.0
21 }
22}
23
24impl Comment { 8impl Comment {
25 pub fn kind(&self) -> CommentKind { 9 pub fn kind(&self) -> CommentKind {
26 kind_by_prefix(self.text()) 10 kind_by_prefix(self.text())
@@ -89,20 +73,6 @@ fn prefix_by_kind(kind: CommentKind) -> &'static str {
89 unreachable!() 73 unreachable!()
90} 74}
91 75
92pub struct Whitespace(SyntaxToken);
93
94impl AstToken for Whitespace {
95 fn cast(token: SyntaxToken) -> Option<Self> {
96 match token.kind() {
97 WHITESPACE => Some(Whitespace(token)),
98 _ => None,
99 }
100 }
101 fn syntax(&self) -> &SyntaxToken {
102 &self.0
103 }
104}
105
106impl Whitespace { 76impl Whitespace {
107 pub fn spans_multiple_lines(&self) -> bool { 77 pub fn spans_multiple_lines(&self) -> bool {
108 let text = self.text(); 78 let text = self.text();
@@ -168,20 +138,6 @@ pub trait HasStringValue: HasQuotes {
168 fn value(&self) -> Option<std::string::String>; 138 fn value(&self) -> Option<std::string::String>;
169} 139}
170 140
171pub struct String(SyntaxToken);
172
173impl AstToken for String {
174 fn cast(token: SyntaxToken) -> Option<Self> {
175 match token.kind() {
176 STRING => Some(String(token)),
177 _ => None,
178 }
179 }
180 fn syntax(&self) -> &SyntaxToken {
181 &self.0
182 }
183}
184
185impl HasStringValue for String { 141impl HasStringValue for String {
186 fn value(&self) -> Option<std::string::String> { 142 fn value(&self) -> Option<std::string::String> {
187 let text = self.text().as_str(); 143 let text = self.text().as_str();
@@ -201,20 +157,6 @@ impl HasStringValue for String {
201 } 157 }
202} 158}
203 159
204pub struct RawString(SyntaxToken);
205
206impl AstToken for RawString {
207 fn cast(token: SyntaxToken) -> Option<Self> {
208 match token.kind() {
209 RAW_STRING => Some(RawString(token)),
210 _ => None,
211 }
212 }
213 fn syntax(&self) -> &SyntaxToken {
214 &self.0
215 }
216}
217
218impl HasStringValue for RawString { 160impl HasStringValue for RawString {
219 fn value(&self) -> Option<std::string::String> { 161 fn value(&self) -> Option<std::string::String> {
220 let text = self.text().as_str(); 162 let text = self.text().as_str();