aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast
diff options
context:
space:
mode:
authorAdolfo OchagavĂ­a <[email protected]>2018-11-08 14:42:00 +0000
committerAdolfo OchagavĂ­a <[email protected]>2018-11-09 13:52:17 +0000
commit3b4c02c19e4af645fd37e8bff774b05d546dc0b6 (patch)
tree42c40e9201adf64d1c06bc1c69524f5688ee6e9f /crates/ra_syntax/src/ast
parent5a9150df9bcdaf5faed5b500c22333f1f7c99f32 (diff)
Validate string literals
Diffstat (limited to 'crates/ra_syntax/src/ast')
-rw-r--r--crates/ra_syntax/src/ast/generated.rs37
-rw-r--r--crates/ra_syntax/src/ast/mod.rs9
2 files changed, 45 insertions, 1 deletions
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs
index 5b5f71ee7..2e9ae263a 100644
--- a/crates/ra_syntax/src/ast/generated.rs
+++ b/crates/ra_syntax/src/ast/generated.rs
@@ -3236,6 +3236,43 @@ impl<'a> AstNode<'a> for Stmt<'a> {
3236 3236
3237impl<'a> Stmt<'a> {} 3237impl<'a> Stmt<'a> {}
3238 3238
3239// String
3240#[derive(Debug, Clone, Copy,)]
3241pub struct StringNode<R: TreeRoot<RaTypes> = OwnedRoot> {
3242 pub(crate) syntax: SyntaxNode<R>,
3243}
3244pub type String<'a> = StringNode<RefRoot<'a>>;
3245
3246impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<StringNode<R1>> for StringNode<R2> {
3247 fn eq(&self, other: &StringNode<R1>) -> bool { self.syntax == other.syntax }
3248}
3249impl<R: TreeRoot<RaTypes>> Eq for StringNode<R> {}
3250impl<R: TreeRoot<RaTypes>> Hash for StringNode<R> {
3251 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
3252}
3253
3254impl<'a> AstNode<'a> for String<'a> {
3255 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
3256 match syntax.kind() {
3257 STRING => Some(String { syntax }),
3258 _ => None,
3259 }
3260 }
3261 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
3262}
3263
3264impl<R: TreeRoot<RaTypes>> StringNode<R> {
3265 pub fn borrowed(&self) -> String {
3266 StringNode { syntax: self.syntax.borrowed() }
3267 }
3268 pub fn owned(&self) -> StringNode {
3269 StringNode { syntax: self.syntax.owned() }
3270 }
3271}
3272
3273
3274impl<'a> String<'a> {}
3275
3239// StructDef 3276// StructDef
3240#[derive(Debug, Clone, Copy,)] 3277#[derive(Debug, Clone, Copy,)]
3241pub struct StructDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { 3278pub struct StructDefNode<R: TreeRoot<RaTypes> = OwnedRoot> {
diff --git a/crates/ra_syntax/src/ast/mod.rs b/crates/ra_syntax/src/ast/mod.rs
index 6b0d62610..f20714ede 100644
--- a/crates/ra_syntax/src/ast/mod.rs
+++ b/crates/ra_syntax/src/ast/mod.rs
@@ -1,6 +1,7 @@
1mod generated; 1mod generated;
2 2
3use std::marker::PhantomData; 3use std::marker::PhantomData;
4use std::string::String as RustString;
4 5
5use itertools::Itertools; 6use itertools::Itertools;
6 7
@@ -76,7 +77,7 @@ pub trait DocCommentsOwner<'a>: AstNode<'a> {
76 77
77 /// Returns the textual content of a doc comment block as a single string. 78 /// Returns the textual content of a doc comment block as a single string.
78 /// That is, strips leading `///` and joins lines 79 /// That is, strips leading `///` and joins lines
79 fn doc_comment_text(self) -> String { 80 fn doc_comment_text(self) -> RustString {
80 self.doc_comments() 81 self.doc_comments()
81 .map(|comment| { 82 .map(|comment| {
82 let prefix = comment.prefix(); 83 let prefix = comment.prefix();
@@ -133,6 +134,12 @@ impl<'a> Char<'a> {
133 } 134 }
134} 135}
135 136
137impl<'a> String<'a> {
138 pub fn text(&self) -> &SmolStr {
139 &self.syntax().leaf_text().unwrap()
140 }
141}
142
136impl<'a> Comment<'a> { 143impl<'a> Comment<'a> {
137 pub fn text(&self) -> &SmolStr { 144 pub fn text(&self) -> &SmolStr {
138 self.syntax().leaf_text().unwrap() 145 self.syntax().leaf_text().unwrap()